[FFmpeg-cvslog] lavu/opt: add AV_OPT_TYPE_DURATION.

Nicolas George git at videolan.org
Wed Mar 20 21:55:38 CET 2013


ffmpeg | branch: master | Nicolas George <nicolas.george at normalesup.org> | Sat Mar 16 15:25:55 2013 +0100| [8d928a9d9967b85283a0a167bdbd7168ae2f51ba] | committer: Nicolas George

lavu/opt: add AV_OPT_TYPE_DURATION.

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

 doc/APIchanges      |    3 +++
 libavutil/opt.c     |   31 ++++++++++++++++++++++++++++++-
 libavutil/opt.h     |    1 +
 libavutil/version.h |    2 +-
 4 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 41552aa..255f914 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil:     2012-10-22
 
 API changes, most recent first:
 
+2013-03-20 - xxxxxxx - lavu 52.22.100 - opt.h
+  Add AV_OPT_TYPE_DURATION value to AVOptionType enum.
+
 2013-03-17 - xxxxxx - lavu 52.20.100 - opt.h
   Add AV_OPT_TYPE_VIDEO_RATE value to AVOptionType enum.
 
diff --git a/libavutil/opt.c b/libavutil/opt.c
index 2d149da..a2cdcb4 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -77,6 +77,7 @@ static int read_number(const AVOption *o, void *dst, double *num, int *den, int6
     case AV_OPT_TYPE_PIXEL_FMT:
     case AV_OPT_TYPE_SAMPLE_FMT:
     case AV_OPT_TYPE_INT:       *intnum = *(int         *)dst;return 0;
+    case AV_OPT_TYPE_DURATION:
     case AV_OPT_TYPE_INT64:     *intnum = *(int64_t     *)dst;return 0;
     case AV_OPT_TYPE_FLOAT:     *num    = *(float       *)dst;return 0;
     case AV_OPT_TYPE_DOUBLE:    *num    = *(double      *)dst;return 0;
@@ -101,6 +102,7 @@ static int write_number(void *obj, const AVOption *o, void *dst, double num, int
     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_DURATION:
     case AV_OPT_TYPE_INT64: *(int64_t   *)dst= llrint(num/den)*intnum; break;
     case AV_OPT_TYPE_FLOAT: *(float     *)dst= num*intnum/den;         break;
     case AV_OPT_TYPE_DOUBLE:*(double    *)dst= num*intnum/den;         break;
@@ -256,7 +258,8 @@ int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
         return AVERROR_OPTION_NOT_FOUND;
     if (!val && (o->type != AV_OPT_TYPE_STRING &&
                  o->type != AV_OPT_TYPE_PIXEL_FMT && o->type != AV_OPT_TYPE_SAMPLE_FMT &&
-                 o->type != AV_OPT_TYPE_IMAGE_SIZE && o->type != AV_OPT_TYPE_VIDEO_RATE))
+                 o->type != AV_OPT_TYPE_IMAGE_SIZE && o->type != AV_OPT_TYPE_VIDEO_RATE &&
+                 o->type != AV_OPT_TYPE_DURATION))
         return AVERROR(EINVAL);
 
     dst = ((uint8_t*)target_obj) + o->offset;
@@ -319,6 +322,15 @@ int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
         }
         *(enum AVSampleFormat *)dst = ret;
         return 0;
+    case AV_OPT_TYPE_DURATION:
+        if (!val) {
+            *(int64_t *)dst = 0;
+            return 0;
+        } else {
+            if ((ret = av_parse_time(dst, val, 1)) < 0)
+                av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as duration\n", val);
+            return ret;
+        }
     }
 
     av_log(obj, AV_LOG_ERROR, "Invalid option type.\n");
@@ -556,6 +568,7 @@ int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
     const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
     uint8_t *bin, buf[128];
     int len, i, ret;
+    int64_t i64;
 
     if (!o || !target_obj || (o->offset<=0 && o->type != AV_OPT_TYPE_CONST))
         return AVERROR_OPTION_NOT_FOUND;
@@ -597,6 +610,12 @@ int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
     case AV_OPT_TYPE_SAMPLE_FMT:
         ret = snprintf(buf, sizeof(buf), "%s", (char *)av_x_if_null(av_get_sample_fmt_name(*(enum AVSampleFormat *)dst), "none"));
         break;
+    case AV_OPT_TYPE_DURATION:
+        i64 = *(int64_t *)dst;
+        ret = snprintf(buf, sizeof(buf), "%"PRIi64"d:%02d:%02d.%06d",
+                       i64 / 3600000000, (int)((i64 / 60000000) % 60),
+                       (int)((i64 / 1000000) % 60), (int)(i64 % 1000000));
+        break;
     default:
         return AVERROR(EINVAL);
     }
@@ -861,6 +880,9 @@ static void opt_list(void *obj, void *av_log_obj, const char *unit,
             case AV_OPT_TYPE_SAMPLE_FMT:
                 av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<sample_fmt>");
                 break;
+            case AV_OPT_TYPE_DURATION:
+                av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<duration>");
+                break;
             case AV_OPT_TYPE_CONST:
             default:
                 av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "");
@@ -937,6 +959,7 @@ void av_opt_set_defaults2(void *s, int mask, int flags)
             case AV_OPT_TYPE_FLAGS:
             case AV_OPT_TYPE_INT:
             case AV_OPT_TYPE_INT64:
+            case AV_OPT_TYPE_DURATION:
                 av_opt_set_int(s, opt->name, opt->default_val.i64, 0);
             break;
             case AV_OPT_TYPE_DOUBLE:
@@ -1300,6 +1323,7 @@ int av_opt_query_ranges_default(AVOptionRanges **ranges_arg, void *obj, const ch
     case AV_OPT_TYPE_SAMPLE_FMT:
     case AV_OPT_TYPE_FLOAT:
     case AV_OPT_TYPE_DOUBLE:
+    case AV_OPT_TYPE_DURATION:
         break;
     case AV_OPT_TYPE_STRING:
         range->component_min = 0;
@@ -1365,6 +1389,7 @@ typedef struct TestContext
     int w, h;
     enum AVPixelFormat pix_fmt;
     enum AVSampleFormat sample_fmt;
+    int64_t duration;
 } TestContext;
 
 #define OFFSET(x) offsetof(TestContext, x)
@@ -1386,6 +1411,7 @@ static const AVOption test_options[]= {
 {"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},
 {"video_rate", "set videorate", OFFSET(video_rate), AV_OPT_TYPE_VIDEO_RATE,  {.str = "25"}, 0,     0                   },
+{"duration", "set duration",   OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = 0}, 0, INT64_MAX},
 {NULL},
 };
 
@@ -1441,6 +1467,9 @@ int main(void)
             "video_rate=30000/1001",
             "video_rate=30/1.001",
             "video_rate=bogus",
+            "duration=bogus",
+            "duration=123.45",
+            "duration=1\\:23\\:45.67",
         };
 
         test_ctx.class = &test_class;
diff --git a/libavutil/opt.h b/libavutil/opt.h
index b36aebe..30f729e 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -231,6 +231,7 @@ enum AVOptionType{
     AV_OPT_TYPE_PIXEL_FMT  = MKBETAG('P','F','M','T'),
     AV_OPT_TYPE_SAMPLE_FMT = MKBETAG('S','F','M','T'),
     AV_OPT_TYPE_VIDEO_RATE = MKBETAG('V','R','A','T'), ///< offset must point to AVRational
+    AV_OPT_TYPE_DURATION   = MKBETAG('D','U','R',' '),
 #if FF_API_OLD_AVOPTIONS
     FF_OPT_TYPE_FLAGS = 0,
     FF_OPT_TYPE_INT,
diff --git a/libavutil/version.h b/libavutil/version.h
index 0619eb9..1c163ca 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -75,7 +75,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  52
-#define LIBAVUTIL_VERSION_MINOR  21
+#define LIBAVUTIL_VERSION_MINOR  22
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \



More information about the ffmpeg-cvslog mailing list