[FFmpeg-cvslog] lavu/opt: allow to set sample and pixel format with av_opt_set_int()

Stefano Sabatini git at videolan.org
Sat Dec 1 19:33:59 CET 2012


ffmpeg | branch: master | Stefano Sabatini <stefasab at gmail.com> | Sat Dec  1 01:07:24 2012 +0100| [c9ff32215b433d505f251c1f212b1fa0a5e17b73] | committer: Stefano Sabatini

lavu/opt: allow to set sample and pixel format with av_opt_set_int()

This change requires the user to specify min and max value, and makes
possible to prevent the user to set AV_{SAMPLE,PIX}_FMT_NONE if
forbidden.

Add required ifdeffery in case of mixed libraries, when libavutil is
updated but not the other libraries.

This is a followup of 08d0969c1402ccec4dce44bd430128fb59d7b790.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c9ff32215b433d505f251c1f212b1fa0a5e17b73
---

 libavcodec/options_table.h |    2 +-
 libavcodec/version.h       |    2 +-
 libavdevice/dshow.c        |    2 +-
 libavdevice/version.h      |    2 +-
 libavutil/opt.c            |   31 +++++++++++++++++++++++--------
 libavutil/version.h        |    2 +-
 6 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index 411092e..1ae93c1 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -401,7 +401,7 @@ static const AVOption options[]={
 {"em", "Emergency",          0, AV_OPT_TYPE_CONST, {.i64 = AV_AUDIO_SERVICE_TYPE_EMERGENCY },         INT_MIN, INT_MAX, A|E, "audio_service_type"},
 {"vo", "Voice Over",         0, AV_OPT_TYPE_CONST, {.i64 = AV_AUDIO_SERVICE_TYPE_VOICE_OVER },        INT_MIN, INT_MAX, A|E, "audio_service_type"},
 {"ka", "Karaoke",            0, AV_OPT_TYPE_CONST, {.i64 = AV_AUDIO_SERVICE_TYPE_KARAOKE },           INT_MIN, INT_MAX, A|E, "audio_service_type"},
-{"request_sample_fmt", "sample format audio decoders should prefer", OFFSET(request_sample_fmt), AV_OPT_TYPE_SAMPLE_FMT, {.i64=AV_SAMPLE_FMT_NONE}, 0, 0, A|D, "request_sample_fmt"},
+{"request_sample_fmt", "sample format audio decoders should prefer", OFFSET(request_sample_fmt), AV_OPT_TYPE_SAMPLE_FMT, {.i64=AV_SAMPLE_FMT_NONE}, -1, AV_SAMPLE_FMT_NB-1, A|D, "request_sample_fmt"},
 {"pkt_timebase", NULL, OFFSET(pkt_timebase), AV_OPT_TYPE_RATIONAL, {.dbl = 0 }, 0, INT_MAX, 0},
 {NULL},
 };
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 2148c4f..a56e415 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -30,7 +30,7 @@
 
 #define LIBAVCODEC_VERSION_MAJOR 54
 #define LIBAVCODEC_VERSION_MINOR 78
-#define LIBAVCODEC_VERSION_MICRO 100
+#define LIBAVCODEC_VERSION_MICRO 101
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
                                                LIBAVCODEC_VERSION_MINOR, \
diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
index 26a4f15..ea01b2a 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, {.i64 = AV_PIX_FMT_NONE}, 0, 0, DEC },
+    { "pixel_format", "set video pixel format", OFFSET(pixel_format), AV_OPT_TYPE_PIXEL_FMT, {.i64 = AV_PIX_FMT_NONE}, -1, AV_PIX_FMT_NB-1, 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/libavdevice/version.h b/libavdevice/version.h
index d5d5da5..5eed4f5 100644
--- a/libavdevice/version.h
+++ b/libavdevice/version.h
@@ -29,7 +29,7 @@
 
 #define LIBAVDEVICE_VERSION_MAJOR  54
 #define LIBAVDEVICE_VERSION_MINOR   3
-#define LIBAVDEVICE_VERSION_MICRO 101
+#define LIBAVDEVICE_VERSION_MICRO 102
 
 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \
                                                LIBAVDEVICE_VERSION_MINOR, \
diff --git a/libavutil/opt.c b/libavutil/opt.c
index 930ace5..0ff45c8 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -95,6 +95,8 @@ static int write_number(void *obj, const AVOption *o, void *dst, double num, int
 
     switch (o->type) {
     case AV_OPT_TYPE_FLAGS:
+    case AV_OPT_TYPE_PIXEL_FMT:
+    case AV_OPT_TYPE_SAMPLE_FMT:
     case AV_OPT_TYPE_INT:   *(int       *)dst= llrint(num/den)*intnum; break;
     case AV_OPT_TYPE_INT64: *(int64_t   *)dst= llrint(num/den)*intnum; break;
     case AV_OPT_TYPE_FLOAT: *(float     *)dst= num*intnum/den;         break;
@@ -427,11 +429,14 @@ int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_
 }
 
 static int set_format(void *obj, const char *name, int fmt, int search_flags,
-                      enum AVOptionType type, const char *desc, int max)
+                      enum AVOptionType type, const char *desc, int nb_fmts)
 {
     void *target_obj;
     const AVOption *o = av_opt_find2(obj, name, NULL, 0,
                                      search_flags, &target_obj);
+    int min, max;
+    const AVClass *class = *(AVClass **)obj;
+
     if (!o || !target_obj)
         return AVERROR_OPTION_NOT_FOUND;
     if (o->type != type) {
@@ -440,10 +445,20 @@ static int set_format(void *obj, const char *name, int fmt, int search_flags,
         return AVERROR(EINVAL);
     }
 
-    if (fmt < -1 || fmt > max) {
+#if LIBAVUTIL_VERSION_MAJOR < 53
+    if (class->version && class->version < AV_VERSION_INT(52, 11, 100)) {
+        min = -1;
+        max = nb_fmts-1;
+    } else
+#endif
+    {
+        min = FFMIN(o->min, -1);
+        max = FFMAX(o->max, nb_fmts-1);
+    }
+    if (fmt < min || fmt > max) {
         av_log(obj, AV_LOG_ERROR,
-               "Value %d for parameter '%s' out of %s format range [-1 - %d]\n",
-               fmt, name, desc, max);
+               "Value %d for parameter '%s' out of %s format range [%d - %d]\n",
+               fmt, name, desc, min, max);
         return AVERROR(ERANGE);
     }
     *(int *)(((uint8_t *)target_obj) + o->offset) = fmt;
@@ -452,12 +467,12 @@ static int set_format(void *obj, const char *name, int fmt, int search_flags,
 
 int av_opt_set_pixel_fmt(void *obj, const char *name, enum AVPixelFormat fmt, int search_flags)
 {
-    return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_PIXEL_FMT, "pixel", AV_PIX_FMT_NB-1);
+    return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_PIXEL_FMT, "pixel", AV_PIX_FMT_NB);
 }
 
 int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, int search_flags)
 {
-    return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_SAMPLE_FMT, "sample", AV_SAMPLE_FMT_NB-1);
+    return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_SAMPLE_FMT, "sample", AV_SAMPLE_FMT_NB);
 }
 
 #if FF_API_OLD_AVOPTIONS
@@ -1179,8 +1194,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, {.i64 = AV_PIX_FMT_NONE}},
-{"sample_fmt", "set samplefmt", OFFSET(sample_fmt), AV_OPT_TYPE_SAMPLE_FMT, {.i64 = AV_SAMPLE_FMT_NONE}},
+{"pix_fmt",  "set pixfmt",     OFFSET(pix_fmt),  AV_OPT_TYPE_PIXEL_FMT, {.i64 = AV_PIX_FMT_NONE}, -1, AV_PIX_FMT_NB-1},
+{"sample_fmt", "set samplefmt", OFFSET(sample_fmt), AV_OPT_TYPE_SAMPLE_FMT, {.i64 = AV_SAMPLE_FMT_NONE}, -1, AV_SAMPLE_FMT_NB-1},
 {NULL},
 };
 
diff --git a/libavutil/version.h b/libavutil/version.h
index 9f22ff7..b46c3f2 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -75,7 +75,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  52
-#define LIBAVUTIL_VERSION_MINOR  10
+#define LIBAVUTIL_VERSION_MINOR  11
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \



More information about the ffmpeg-cvslog mailing list