[FFmpeg-devel] [PATCH] lavu/opt: change the way default pixel and sample format value is set

Stefano Sabatini stefasab at gmail.com
Sun Nov 25 16:00:20 CET 2012


Use the i64 field rather than the string value. Use a string to set a
default sample/pixel format is weird, also this is more consistent with
the rest of the API.

This is technically an API break, but hopefully there are no applications
using this feature outside of FFmpeg.

TODO: bump micro
---
 libavdevice/dshow.c |    2 +-
 libavutil/opt.c     |   10 +++++++---
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
index 3bd90b0..3e141e8 100644
--- a/libavdevice/dshow.c
+++ b/libavdevice/dshow.c
@@ -1018,7 +1018,7 @@ static int dshow_read_packet(AVFormatContext *s, AVPacket *pkt)
 #define DEC AV_OPT_FLAG_DECODING_PARAM
 static const AVOption options[] = {
     { "video_size", "set video size given a string such as 640x480 or hd720.", OFFSET(requested_width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, DEC },
-    { "pixel_format", "set video pixel format", OFFSET(pixel_format), AV_OPT_TYPE_PIXEL_FMT, {.str = NULL}, 0, 0, DEC },
+    { "pixel_format", "set video pixel format", OFFSET(pixel_format), AV_OPT_TYPE_PIXEL_FMT, {.str = AV_PIX_FMT_NONE}, 0, 0, DEC },
     { "framerate", "set video frame rate", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
     { "sample_rate", "set audio sample rate", OFFSET(sample_rate), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, DEC },
     { "sample_size", "set audio sample size", OFFSET(sample_size), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 16, DEC },
diff --git a/libavutil/opt.c b/libavutil/opt.c
index 11ffb5e..c546f8e 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -841,9 +841,13 @@ void av_opt_set_defaults2(void *s, int mask, int flags)
             break;
             case AV_OPT_TYPE_STRING:
             case AV_OPT_TYPE_IMAGE_SIZE:
+                av_opt_set(s, opt->name, opt->default_val.str, 0);
+                break;
             case AV_OPT_TYPE_PIXEL_FMT:
+                av_opt_set_pixel_fmt(s, opt->name, opt->default_val.i64, 0);
+                break;
             case AV_OPT_TYPE_SAMPLE_FMT:
-                av_opt_set(s, opt->name, opt->default_val.str, 0);
+                av_opt_set_sample_fmt(s, opt->name, opt->default_val.i64, 0);
                 break;
             case AV_OPT_TYPE_BINARY:
                 /* Cannot set default for binary */
@@ -1178,8 +1182,8 @@ static const AVOption test_options[]= {
 {"lame",     "set lame flag ", 0,                AV_OPT_TYPE_CONST,    {.i64 = TEST_FLAG_LAME}, INT_MIN,  INT_MAX, 0, "flags" },
 {"mu",       "set mu flag ",   0,                AV_OPT_TYPE_CONST,    {.i64 = TEST_FLAG_MU},   INT_MIN,  INT_MAX, 0, "flags" },
 {"size",     "set size",       OFFSET(w),        AV_OPT_TYPE_IMAGE_SIZE,{0},             0,        0                   },
-{"pix_fmt",  "set pixfmt",     OFFSET(pix_fmt),  AV_OPT_TYPE_PIXEL_FMT,{0},              0,        0                   },
-{"sample_fmt", "set samplefmt", OFFSET(sample_fmt), AV_OPT_TYPE_SAMPLE_FMT,{0},          0,        0                   },
+{"pix_fmt",  "set pixfmt",     OFFSET(pix_fmt),  AV_OPT_TYPE_PIXEL_FMT, {.i64 = AV_PIX_FMT_NONE}},
+{"sample_fmt", "set samplefmt", OFFSET(sample_fmt), AV_OPT_TYPE_SAMPLE_FMT, {.i64 = AV_SAMPLE_FMT_NONE}},
 {NULL},
 };
 
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list