]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/cbs: add an AVClass to CodedBitstreamType for option handling
authorJames Almer <jamrial@gmail.com>
Sun, 15 Nov 2020 21:55:38 +0000 (18:55 -0300)
committerJames Almer <jamrial@gmail.com>
Mon, 4 Jan 2021 19:28:29 +0000 (16:28 -0300)
So unit parsing may be configured with caller set options.

Signed-off-by: James Almer <jamrial@gmail.com>
libavcodec/cbs.c
libavcodec/cbs_internal.h

index e7025cce07863439e4ff46ff38ba6ba3c6cff40d..d7efac5b930d05010fd4b919271cf6c2bb26e548 100644 (file)
@@ -23,6 +23,7 @@
 #include "libavutil/avassert.h"
 #include "libavutil/buffer.h"
 #include "libavutil/common.h"
+#include "libavutil/opt.h"
 
 #include "cbs.h"
 #include "cbs_internal.h"
@@ -101,6 +102,10 @@ int ff_cbs_init(CodedBitstreamContext **ctx_ptr,
             av_freep(&ctx);
             return AVERROR(ENOMEM);
         }
+        if (type->priv_class) {
+            *(const AVClass **)ctx->priv_data = type->priv_class;
+            av_opt_set_defaults(ctx->priv_data);
+        }
     }
 
     ctx->decompose_unit_types = NULL;
@@ -129,6 +134,10 @@ void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
         ctx->codec->close(ctx);
 
     av_freep(&ctx->write_buffer);
+
+    if (ctx->codec->priv_class && ctx->priv_data)
+        av_opt_free(ctx->priv_data);
+
     av_freep(&ctx->priv_data);
     av_freep(ctx_ptr);
 }
index faa847aad36f4991a2d95bbcaf826a581b52f536..a392880036ed15f454239602ecd225dbd30a6a59 100644 (file)
@@ -86,6 +86,12 @@ typedef const struct CodedBitstreamUnitTypeDescriptor {
 typedef struct CodedBitstreamType {
     enum AVCodecID codec_id;
 
+    // A class for the private data, used to declare private AVOptions.
+    // This field is NULL for types that do not declare any options.
+    // If this field is non-NULL, the first member of the filter private data
+    // must be a pointer to AVClass.
+    const AVClass *priv_class;
+
     size_t priv_data_size;
 
     // List of unit type descriptors for this codec.