[FFmpeg-devel] [PATCH v0 09/14] avcodec: add private side data set to AVCodecInternal

Jan Ekström jeebjp at gmail.com
Tue Mar 21 01:34:03 EET 2023


This allows configuring an encoder by using AVFrameSideData.
---
 libavcodec/avcodec.c  | 1 +
 libavcodec/internal.h | 7 +++++++
 libavcodec/options.c  | 5 +++++
 3 files changed, 13 insertions(+)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index c110b19e08..3faabe77d1 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -403,6 +403,7 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
     avci->nb_draining_errors = 0;
     av_frame_unref(avci->buffer_frame);
     av_packet_unref(avci->buffer_pkt);
+    av_side_data_set_wipe(&avci->side_data_set);
 
     if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME)
         ff_thread_flush(avctx);
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index f21101752d..c658e97313 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -168,6 +168,13 @@ typedef struct AVCodecInternal {
      * a boolean to describe whether context is opened or not.
      */
     unsigned int ctx_opened;
+
+    /**
+     * Set holding static side data, such as HDR10 CLL / MDCV structures.
+     * - encoding: set by user
+     * - decoding: unused
+     */
+    AVFrameSideDataSet side_data_set;
 } AVCodecInternal;
 
 /**
diff --git a/libavcodec/options.c b/libavcodec/options.c
index f8fab164fb..acd3472fde 100644
--- a/libavcodec/options.c
+++ b/libavcodec/options.c
@@ -184,12 +184,17 @@ AVCodecContext *avcodec_alloc_context3(const AVCodec *codec)
 void avcodec_free_context(AVCodecContext **pavctx)
 {
     AVCodecContext *avctx = *pavctx;
+    AVCodecInternal *avci = NULL;
 
     if (!avctx)
         return;
 
     avcodec_close(avctx);
 
+    avci = avctx->internal;
+    if (avci)
+        av_side_data_set_wipe(&avci->side_data_set);
+
     av_freep(&avctx->internal);
 
     av_freep(&avctx->extradata);
-- 
2.39.2



More information about the ffmpeg-devel mailing list