From: softworkz <ffmpegagent@gmail.com> To: ffmpeg-devel@ffmpeg.org Cc: Kieran Kunhya <kierank@obe.tv>, softworkz <softworkz@hotmail.com>, "Xiang, Haihao" <haihao.xiang-at-intel.com@ffmpeg.org>, Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Subject: [FFmpeg-devel] [PATCH v5 1/6] avutil/frame: Add av_frame_copy_side_data() and av_frame_remove_all_side_data() Date: Fri, 01 Jul 2022 20:48:49 +0000 Message-ID: <7656477360b1e993b0a432a13332b48c4b7fc4bc.1656708534.git.ffmpegagent@gmail.com> (raw) In-Reply-To: <pull.31.v5.ffstaging.FFmpeg.1656708534.ffmpegagent@gmail.com> From: softworkz <softworkz@hotmail.com> Signed-off-by: softworkz <softworkz@hotmail.com> Signed-off-by: Anton Khirnov <anton@khirnov.net> --- doc/APIchanges | 4 +++ libavutil/frame.c | 67 +++++++++++++++++++++++++++------------------ libavutil/frame.h | 32 ++++++++++++++++++++++ libavutil/version.h | 2 +- 4 files changed, 78 insertions(+), 27 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 20b944933a..6b5bf61d85 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -14,6 +14,10 @@ libavutil: 2021-04-27 API changes, most recent first: +2022-05-26 - xxxxxxxxx - lavu 57.28.100 - frame.h + Add av_frame_remove_all_side_data(), av_frame_copy_side_data(), + AV_FRAME_TRANSFER_SD_COPY, and AV_FRAME_TRANSFER_SD_FILTER. + 2022-06-12 - xxxxxxxxxx - lavf 59.25.100 - avio.h Add avio_vprintf(), similar to avio_printf() but allow to use it from within a function taking a variable argument list as input. diff --git a/libavutil/frame.c b/libavutil/frame.c index 4c16488c66..5d34fde904 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -271,9 +271,45 @@ FF_ENABLE_DEPRECATION_WARNINGS return AVERROR(EINVAL); } +void av_frame_remove_all_side_data(AVFrame *frame) +{ + wipe_side_data(frame); +} + +int av_frame_copy_side_data(AVFrame* dst, const AVFrame* src, int flags) +{ + for (unsigned i = 0; i < src->nb_side_data; i++) { + const AVFrameSideData *sd_src = src->side_data[i]; + AVFrameSideData *sd_dst; + if ((flags & AV_FRAME_TRANSFER_SD_FILTER) && + sd_src->type == AV_FRAME_DATA_PANSCAN && + (src->width != dst->width || src->height != dst->height)) + continue; + if (flags & AV_FRAME_TRANSFER_SD_COPY) { + sd_dst = av_frame_new_side_data(dst, sd_src->type, + sd_src->size); + if (!sd_dst) { + wipe_side_data(dst); + return AVERROR(ENOMEM); + } + memcpy(sd_dst->data, sd_src->data, sd_src->size); + } else { + AVBufferRef *ref = av_buffer_ref(sd_src->buf); + sd_dst = av_frame_new_side_data_from_buf(dst, sd_src->type, ref); + if (!sd_dst) { + av_buffer_unref(&ref); + wipe_side_data(dst); + return AVERROR(ENOMEM); + } + } + av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0); + } + return 0; +} + static int frame_copy_props(AVFrame *dst, const AVFrame *src, int force_copy) { - int ret, i; + int ret; dst->key_frame = src->key_frame; dst->pict_type = src->pict_type; @@ -309,31 +345,10 @@ static int frame_copy_props(AVFrame *dst, const AVFrame *src, int force_copy) av_dict_copy(&dst->metadata, src->metadata, 0); - for (i = 0; i < src->nb_side_data; i++) { - const AVFrameSideData *sd_src = src->side_data[i]; - AVFrameSideData *sd_dst; - if ( sd_src->type == AV_FRAME_DATA_PANSCAN - && (src->width != dst->width || src->height != dst->height)) - continue; - if (force_copy) { - sd_dst = av_frame_new_side_data(dst, sd_src->type, - sd_src->size); - if (!sd_dst) { - wipe_side_data(dst); - return AVERROR(ENOMEM); - } - memcpy(sd_dst->data, sd_src->data, sd_src->size); - } else { - AVBufferRef *ref = av_buffer_ref(sd_src->buf); - sd_dst = av_frame_new_side_data_from_buf(dst, sd_src->type, ref); - if (!sd_dst) { - av_buffer_unref(&ref); - wipe_side_data(dst); - return AVERROR(ENOMEM); - } - } - av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0); - } + if ((ret = av_frame_copy_side_data(dst, src, + (force_copy ? AV_FRAME_TRANSFER_SD_COPY : 0) | + AV_FRAME_TRANSFER_SD_FILTER) < 0)) + return ret; ret = av_buffer_replace(&dst->opaque_ref, src->opaque_ref); ret |= av_buffer_replace(&dst->private_ref, src->private_ref); diff --git a/libavutil/frame.h b/libavutil/frame.h index 33fac2054c..f72b6fae71 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -850,6 +850,30 @@ int av_frame_copy(AVFrame *dst, const AVFrame *src); */ int av_frame_copy_props(AVFrame *dst, const AVFrame *src); + +/** + * Copy side data, rather than creating new references. + */ +#define AV_FRAME_TRANSFER_SD_COPY (1 << 0) +/** + * Filter out side data that does not match dst properties. + */ +#define AV_FRAME_TRANSFER_SD_FILTER (1 << 1) + +/** + * Copy all side-data from src to dst. + * + * @param dst a frame to which the side data should be copied. + * @param src a frame from which to copy the side data. + * @param flags a combination of AV_FRAME_TRANSFER_SD_* + * + * @return 0 on success, a negative AVERROR on error. + * + * @note This function will create new references to side data buffers in src, + * unless the AV_FRAME_TRANSFER_SD_COPY flag is passed. + */ +int av_frame_copy_side_data(AVFrame* dst, const AVFrame* src, int flags); + /** * Get the buffer reference a given data plane is stored in. * @@ -901,6 +925,14 @@ AVFrameSideData *av_frame_get_side_data(const AVFrame *frame, */ void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type); +/** + * Remove and free all side data instances. + * + * @param frame from which to remove all side data. + */ +void av_frame_remove_all_side_data(AVFrame *frame); + + /** * Flags for frame cropping. diff --git a/libavutil/version.h b/libavutil/version.h index 2e9e02dda8..87178e9e9a 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,7 +79,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 57 -#define LIBAVUTIL_VERSION_MINOR 27 +#define LIBAVUTIL_VERSION_MINOR 28 #define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ -- ffmpeg-codebot _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2022-07-01 20:49 UTC|newest] Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-05-26 8:08 [FFmpeg-devel] [PATCH 0/6] Implement SEI parsing for QSV decoders ffmpegagent 2022-05-26 8:08 ` [FFmpeg-devel] [PATCH 1/6] avutil/frame: Add av_frame_copy_side_data() and av_frame_remove_all_side_data() softworkz 2022-05-27 14:35 ` Soft Works 2022-05-26 8:08 ` [FFmpeg-devel] [PATCH 2/6] avcodec/vpp_qsv: Copy side data from input to output frame softworkz 2022-05-31 9:19 ` Xiang, Haihao 2022-05-26 8:08 ` [FFmpeg-devel] [PATCH 3/6] avcodec/mpeg12dec: make mpeg_decode_user_data() accessible softworkz 2022-05-31 9:24 ` Xiang, Haihao 2022-05-26 8:08 ` [FFmpeg-devel] [PATCH 4/6] avcodec/hevcdec: make set_side_data() accessible softworkz 2022-05-31 9:38 ` Xiang, Haihao 2022-05-31 16:03 ` Soft Works 2022-05-31 9:40 ` Xiang, Haihao 2022-05-26 8:08 ` [FFmpeg-devel] [PATCH 5/6] avcodec/h264dec: make h264_export_frame_props() accessible softworkz 2022-05-26 8:08 ` [FFmpeg-devel] [PATCH 6/6] avcodec/qsvdec: Implement SEI parsing for QSV decoders softworkz 2022-06-01 5:15 ` Xiang, Haihao 2022-06-01 8:51 ` Soft Works 2022-06-01 9:06 ` [FFmpeg-devel] [PATCH v2 0/6] " ffmpegagent 2022-06-01 9:06 ` [FFmpeg-devel] [PATCH v2 1/6] avutil/frame: Add av_frame_copy_side_data() and av_frame_remove_all_side_data() softworkz 2022-06-01 9:06 ` [FFmpeg-devel] [PATCH v2 2/6] avcodec/vpp_qsv: Copy side data from input to output frame softworkz 2022-06-01 9:06 ` [FFmpeg-devel] [PATCH v2 3/6] avcodec/mpeg12dec: make mpeg_decode_user_data() accessible softworkz 2022-06-01 9:06 ` [FFmpeg-devel] [PATCH v2 4/6] avcodec/hevcdec: make set_side_data() accessible softworkz 2022-06-01 9:06 ` [FFmpeg-devel] [PATCH v2 5/6] avcodec/h264dec: make h264_export_frame_props() accessible softworkz 2022-06-01 9:06 ` [FFmpeg-devel] [PATCH v2 6/6] avcodec/qsvdec: Implement SEI parsing for QSV decoders softworkz 2022-06-01 17:20 ` Xiang, Haihao 2022-06-01 17:50 ` Soft Works 2022-06-01 18:01 ` [FFmpeg-devel] [PATCH v3 0/6] " ffmpegagent 2022-06-01 18:01 ` [FFmpeg-devel] [PATCH v3 1/6] avutil/frame: Add av_frame_copy_side_data() and av_frame_remove_all_side_data() softworkz 2022-06-24 7:01 ` Xiang, Haihao 2022-06-26 23:35 ` Soft Works 2022-06-01 18:01 ` [FFmpeg-devel] [PATCH v3 2/6] avcodec/vpp_qsv: Copy side data from input to output frame softworkz 2022-06-01 18:01 ` [FFmpeg-devel] [PATCH v3 3/6] avcodec/mpeg12dec: make mpeg_decode_user_data() accessible softworkz 2022-06-01 18:01 ` [FFmpeg-devel] [PATCH v3 4/6] avcodec/hevcdec: make set_side_data() accessible softworkz 2022-06-01 18:01 ` [FFmpeg-devel] [PATCH v3 5/6] avcodec/h264dec: make h264_export_frame_props() accessible softworkz 2022-06-01 18:01 ` [FFmpeg-devel] [PATCH v3 6/6] avcodec/qsvdec: Implement SEI parsing for QSV decoders softworkz 2022-06-26 23:41 ` [FFmpeg-devel] [PATCH v4 0/6] " ffmpegagent 2022-06-26 23:41 ` [FFmpeg-devel] [PATCH v4 1/6] avutil/frame: Add av_frame_copy_side_data() and av_frame_remove_all_side_data() softworkz 2022-06-26 23:41 ` [FFmpeg-devel] [PATCH v4 2/6] avcodec/vpp_qsv: Copy side data from input to output frame softworkz 2022-06-26 23:41 ` [FFmpeg-devel] [PATCH v4 3/6] avcodec/mpeg12dec: make mpeg_decode_user_data() accessible softworkz 2022-06-26 23:41 ` [FFmpeg-devel] [PATCH v4 4/6] avcodec/hevcdec: make set_side_data() accessible softworkz 2022-06-26 23:41 ` [FFmpeg-devel] [PATCH v4 5/6] avcodec/h264dec: make h264_export_frame_props() accessible softworkz 2022-06-26 23:41 ` [FFmpeg-devel] [PATCH v4 6/6] avcodec/qsvdec: Implement SEI parsing for QSV decoders softworkz 2022-06-28 4:16 ` Andreas Rheinhardt 2022-06-28 5:25 ` Soft Works 2022-06-27 4:18 ` [FFmpeg-devel] [PATCH v4 0/6] " Xiang, Haihao 2022-07-01 20:48 ` [FFmpeg-devel] [PATCH v5 " ffmpegagent 2022-07-01 20:48 ` softworkz [this message] 2022-07-01 20:48 ` [FFmpeg-devel] [PATCH v5 2/6] avcodec/vpp_qsv: Copy side data from input to output frame softworkz 2022-07-01 20:48 ` [FFmpeg-devel] [PATCH v5 3/6] avcodec/mpeg12dec: make mpeg_decode_user_data() accessible softworkz 2022-07-01 20:48 ` [FFmpeg-devel] [PATCH v5 4/6] avcodec/hevcdec: make set_side_data() accessible softworkz 2022-07-01 20:48 ` [FFmpeg-devel] [PATCH v5 5/6] avcodec/h264dec: make h264_export_frame_props() accessible softworkz 2022-07-01 20:48 ` [FFmpeg-devel] [PATCH v5 6/6] avcodec/qsvdec: Implement SEI parsing for QSV decoders softworkz 2022-07-19 6:55 ` [FFmpeg-devel] [PATCH v5 0/6] " Xiang, Haihao 2022-07-21 21:06 ` Soft Works 2022-07-21 21:56 ` Andreas Rheinhardt 2022-10-21 7:42 ` Soft Works 2022-10-25 4:03 ` [FFmpeg-devel] [PATCH v6 0/3] " ffmpegagent 2022-10-25 4:03 ` [FFmpeg-devel] [PATCH v6 1/3] avcodec/hevcdec: factor out ff_hevc_set_set_to_frame softworkz 2022-10-25 4:03 ` [FFmpeg-devel] [PATCH v6 2/3] avcodec/h264dec: make h264_export_frame_props() accessible softworkz 2022-10-25 4:03 ` [FFmpeg-devel] [PATCH v6 3/3] avcodec/qsvdec: Implement SEI parsing for QSV decoders softworkz 2022-11-21 2:44 ` Xiang, Haihao 2022-11-21 15:58 ` Soft Works 2022-11-22 5:41 ` Xiang, Haihao 2022-06-01 19:15 ` [FFmpeg-devel] [PATCH 0/6] " Kieran Kunhya 2022-06-01 19:46 ` Soft Works 2022-06-01 20:25 ` Kieran Kunhya 2022-06-01 21:24 ` Soft Works
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=7656477360b1e993b0a432a13332b48c4b7fc4bc.1656708534.git.ffmpegagent@gmail.com \ --to=ffmpegagent@gmail.com \ --cc=andreas.rheinhardt@outlook.com \ --cc=ffmpeg-devel@ffmpeg.org \ --cc=haihao.xiang-at-intel.com@ffmpeg.org \ --cc=kierank@obe.tv \ --cc=softworkz@hotmail.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git