[FFmpeg-devel] [PATCH] avcodec: Add AVClass to AVCodecParameters

Michael Niedermayer michael at niedermayer.cc
Tue May 10 02:07:05 CEST 2016


Allow enumeration, read and write of fields without requiring #if on versions
All other public structures can be accessed through AVOptions

TODO: add all fields to AVOption table
TODO: bump version
TODO: update APIChanges

Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
---
 libavcodec/avcodec.h |   12 ++++++++++++
 libavcodec/utils.c   |   26 ++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 3813a0a..71e7694 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3903,6 +3903,10 @@ typedef struct AVSubtitle {
  */
 typedef struct AVCodecParameters {
     /**
+     * A class for logging and AVOptions
+     */
+    AVClass *av_class;
+    /**
      * General type of the encoded data.
      */
     enum AVMediaType codec_type;
@@ -4154,6 +4158,14 @@ const AVClass *avcodec_get_frame_class(void);
 const AVClass *avcodec_get_subtitle_rect_class(void);
 
 /**
+ * Get the AVClass for AVCodecParameters. It can be used in combination with
+ * AV_OPT_SEARCH_FAKE_OBJ for examining options.
+ *
+ * @see av_opt_find().
+ */
+const AVClass *avcodec_get_parameters_class(void);
+
+/**
  * Copy the settings of the source AVCodecContext into the destination
  * AVCodecContext. The resulting destination codec context will be
  * unopened, i.e. you are required to call avcodec_open2() before you
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index e6609ef..38b6330 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -4003,12 +4003,33 @@ AVCPBProperties *ff_add_cpb_side_data(AVCodecContext *avctx)
     return props;
 }
 
+#define OFFSET(x) offsetof(AVCodecParameters,x)
+#define V AV_OPT_FLAG_VIDEO_PARAM
+#define A AV_OPT_FLAG_AUDIO_PARAM
+#define S AV_OPT_FLAG_SUBTITLE_PARAM
+#define E AV_OPT_FLAG_ENCODING_PARAM
+#define D AV_OPT_FLAG_DECODING_PARAM
+static const AVOption avcodec_parameters_options[] = {
+    {"b", "bitrate (in bits/s)", OFFSET(bit_rate), AV_OPT_TYPE_INT64, {.i64 = 0 }, 0, INT64_MAX, A|V|E|D },
+    {"pixel_format", "set pixel format", OFFSET(format), AV_OPT_TYPE_PIXEL_FMT, {.i64=AV_PIX_FMT_NONE}, -1, INT_MAX, V|E|D },
+    {"sample_fmt", "sample format", OFFSET(format), AV_OPT_TYPE_SAMPLE_FMT, {.i64=AV_SAMPLE_FMT_NONE}, -1, INT_MAX, A|E|D },
+    {"video_size", "video size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str=NULL}, 0, INT_MAX, V|E|D },
+    NULL
+};
+
+static const AVClass av_codec_parameters_class = {
+    .class_name              = "AVCodecParameters",
+    .option                  = avcodec_parameters_options,
+    .version                 = LIBAVUTIL_VERSION_INT,
+};
+
 static void codec_parameters_reset(AVCodecParameters *par)
 {
     av_freep(&par->extradata);
 
     memset(par, 0, sizeof(*par));
 
+    par->av_class            = &av_codec_parameters_class;
     par->codec_type          = AVMEDIA_TYPE_UNKNOWN;
     par->codec_id            = AV_CODEC_ID_NONE;
     par->format              = -1;
@@ -4023,6 +4044,11 @@ static void codec_parameters_reset(AVCodecParameters *par)
     par->level               = FF_LEVEL_UNKNOWN;
 }
 
+const AVClass *avcodec_get_parameters_class(void)
+{
+    return &av_codec_parameters_class;
+}
+
 AVCodecParameters *avcodec_parameters_alloc(void)
 {
     AVCodecParameters *par = av_mallocz(sizeof(*par));
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list