From: Fei Wang <fei.w.wang-at-intel.com@ffmpeg.org> To: ffmpeg-devel@ffmpeg.org Cc: Fei Wang <fei.w.wang@intel.com> Subject: [FFmpeg-devel] [PATCH v1 1/4] lavu: add sub frame side data Date: Fri, 29 Apr 2022 15:59:38 +0800 Message-ID: <20220429075941.1844370-1-fei.w.wang@intel.com> (raw) Sub frame side data allows attach another AVFrame as side data into the target AVFrame. Signed-off-by: Fei Wang <fei.w.wang@intel.com> --- libavutil/Makefile | 2 ++ libavutil/frame.c | 5 ++- libavutil/frame.h | 5 +++ libavutil/sub_frame_metadata.c | 61 ++++++++++++++++++++++++++++++++++ libavutil/sub_frame_metadata.h | 35 +++++++++++++++++++ libavutil/version.h | 4 +-- 6 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 libavutil/sub_frame_metadata.c create mode 100644 libavutil/sub_frame_metadata.h diff --git a/libavutil/Makefile b/libavutil/Makefile index 81df3b0640..09333a0b48 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -88,6 +88,7 @@ HEADERS = adler32.h \ tea.h \ tx.h \ film_grain_params.h \ + sub_frame_metadata.h \ ARCH_HEADERS = bswap.h \ intmath.h \ @@ -176,6 +177,7 @@ OBJS = adler32.o \ tx_int32.o \ video_enc_params.o \ film_grain_params.o \ + sub_frame_metadata.o \ OBJS-$(CONFIG_CUDA) += hwcontext_cuda.o diff --git a/libavutil/frame.c b/libavutil/frame.c index fbb869fffa..b21a15e652 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -315,7 +315,9 @@ static int frame_copy_props(AVFrame *dst, const AVFrame *src, int force_copy) if ( sd_src->type == AV_FRAME_DATA_PANSCAN && (src->width != dst->width || src->height != dst->height)) continue; - if (force_copy) { + /* Don't copy sub frame side data, otherwise sub frame's pointers in + * dst may be invalid. */ + if (force_copy && sd_src->type != AV_FRAME_DATA_SUB_FRAME) { sd_dst = av_frame_new_side_data(dst, sd_src->type, sd_src->size); if (!sd_dst) { @@ -815,6 +817,7 @@ const char *av_frame_side_data_name(enum AVFrameSideDataType type) case AV_FRAME_DATA_DETECTION_BBOXES: return "Bounding boxes for object detection and classification"; case AV_FRAME_DATA_DOVI_RPU_BUFFER: return "Dolby Vision RPU Data"; case AV_FRAME_DATA_DOVI_METADATA: return "Dolby Vision Metadata"; + case AV_FRAME_DATA_SUB_FRAME: return "Sub frame Metadata"; } return NULL; } diff --git a/libavutil/frame.h b/libavutil/frame.h index 33fac2054c..9ae1286100 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -209,6 +209,11 @@ enum AVFrameSideDataType { * volume transform - CUVA 005.1-2021. */ AV_FRAME_DATA_DYNAMIC_HDR_VIVID, + + /** + * Sub frame of a target frame, as described by AVFrame. + */ + AV_FRAME_DATA_SUB_FRAME, }; enum AVActiveFormatDescription { diff --git a/libavutil/sub_frame_metadata.c b/libavutil/sub_frame_metadata.c new file mode 100644 index 0000000000..82ea32383f --- /dev/null +++ b/libavutil/sub_frame_metadata.c @@ -0,0 +1,61 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "sub_frame_metadata.h" + +static void sub_frame_free(void *opaque, uint8_t *data) +{ + AVFrame *frame = (AVFrame*)data; + + av_frame_free(&frame); +} + +static AVFrame *sub_frame_alloc(size_t *out_size) +{ + AVFrame *sub_frame = av_frame_alloc(); + if (!sub_frame) + return NULL; + + *out_size = sizeof(*sub_frame); + + return sub_frame; +} + +AVFrame *av_sub_frame_create_side_data(AVFrame *frame) +{ + AVBufferRef *buf; + AVFrame *sub_frame; + size_t size; + + sub_frame = sub_frame_alloc(&size); + if (!sub_frame) + return NULL; + + buf = av_buffer_create((uint8_t *)sub_frame, size, &sub_frame_free, NULL, 0); + if (!buf) { + av_frame_free(&sub_frame); + return NULL; + } + + if (!av_frame_new_side_data_from_buf(frame, AV_FRAME_DATA_SUB_FRAME, buf)) { + av_buffer_unref(&buf); + return NULL; + } + + return sub_frame; +} diff --git a/libavutil/sub_frame_metadata.h b/libavutil/sub_frame_metadata.h new file mode 100644 index 0000000000..621fb31e42 --- /dev/null +++ b/libavutil/sub_frame_metadata.h @@ -0,0 +1,35 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVUTIL_SUB_FRAME_METADATA_H +#define AVUTIL_SUB_FRAME_METADATA_H + +#include "frame.h" + +/** + * Allocate a AVFrame structure and add it to the input frame as + * the side data. The allocated AVFrame will be freed automatically + * once the buf of created side data reference count decrease to zero. + * + * @param frame The frame which side data is added to. + * + * @return The AVFrame structure to be filled by caller. + */ +AVFrame *av_sub_frame_create_side_data(AVFrame *frame); + +#endif /* AVUTIL_SUB_FRAME_METADATA_H */ diff --git a/libavutil/version.h b/libavutil/version.h index 6735c20090..dd7d20a9fa 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,8 +79,8 @@ */ #define LIBAVUTIL_VERSION_MAJOR 57 -#define LIBAVUTIL_VERSION_MINOR 24 -#define LIBAVUTIL_VERSION_MICRO 101 +#define LIBAVUTIL_VERSION_MINOR 25 +#define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ LIBAVUTIL_VERSION_MINOR, \ -- 2.25.1 _______________________________________________ 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 reply other threads:[~2022-04-29 8:06 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-04-29 7:59 Fei Wang [this message] 2022-04-29 7:59 ` [FFmpeg-devel] [PATCH v1 2/4] lavc: add sub frame options and flag Fei Wang 2022-04-29 7:59 ` [FFmpeg-devel] [PATCH v1 3/4] lavc/hevc_vaapi: enable sub frame support Fei Wang 2022-04-29 7:59 ` [FFmpeg-devel] [PATCH v1 4/4] examples: seperate vaapi_decode from hw_decode Fei Wang
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=20220429075941.1844370-1-fei.w.wang@intel.com \ --to=fei.w.wang-at-intel.com@ffmpeg.org \ --cc=fei.w.wang@intel.com \ --cc=ffmpeg-devel@ffmpeg.org \ /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