Browse code

lavfi/mptestsrc: make use of AV_OPT_TYPE_VIDEO_RATE

Signed-off-by: Paul B Mahol <onemda@gmail.com>

Paul B Mahol authored on 2013/03/26 21:23:46
Showing 1 changed files
... ...
@@ -53,18 +53,18 @@ enum test_type {
53 53
 typedef struct MPTestContext {
54 54
     const AVClass *class;
55 55
     unsigned int frame_nb;
56
-    AVRational time_base;
56
+    AVRational frame_rate;
57 57
     int64_t pts, max_pts;
58 58
     int hsub, vsub;
59
-    char *size, *rate, *duration;
59
+    char *size, *duration;
60 60
     enum test_type test;
61 61
 } MPTestContext;
62 62
 
63 63
 #define OFFSET(x) offsetof(MPTestContext, x)
64 64
 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
65 65
 static const AVOption mptestsrc_options[]= {
66
-    { "rate",     "set video rate",     OFFSET(rate),     AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, FLAGS },
67
-    { "r",        "set video rate",     OFFSET(rate),     AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, FLAGS },
66
+    { "rate",     "set video rate",     OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, 0, FLAGS },
67
+    { "r",        "set video rate",     OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, 0, FLAGS },
68 68
     { "duration", "set video duration", OFFSET(duration), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
69 69
     { "d",        "set video duration", OFFSET(duration), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS },
70 70
 
... ...
@@ -259,7 +259,6 @@ static void ring2_test(uint8_t *dst, int dst_linesize, int off)
259 259
 static av_cold int init(AVFilterContext *ctx, const char *args)
260 260
 {
261 261
     MPTestContext *test = ctx->priv;
262
-    AVRational frame_rate_q;
263 262
     int64_t duration = -1;
264 263
     int ret;
265 264
 
... ...
@@ -269,26 +268,19 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
269 269
     if ((ret = (av_set_options_string(test, args, "=", ":"))) < 0)
270 270
         return ret;
271 271
 
272
-    if ((ret = av_parse_video_rate(&frame_rate_q, test->rate)) < 0) {
273
-        av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: '%s'\n", test->rate);
274
-        return ret;
275
-    }
276
-
277 272
     if ((test->duration) && (ret = av_parse_time(&duration, test->duration, 1)) < 0) {
278 273
         av_log(ctx, AV_LOG_ERROR, "Invalid duration: '%s'\n", test->duration);
279 274
         return ret;
280 275
     }
281 276
 
282
-    test->time_base.num = frame_rate_q.den;
283
-    test->time_base.den = frame_rate_q.num;
284 277
     test->max_pts = duration >= 0 ?
285
-        av_rescale_q(duration, AV_TIME_BASE_Q, test->time_base) : -1;
278
+        av_rescale_q(duration, AV_TIME_BASE_Q, av_inv_q(test->frame_rate)) : -1;
286 279
     test->frame_nb = 0;
287 280
     test->pts = 0;
288 281
 
289 282
     av_log(ctx, AV_LOG_VERBOSE, "rate:%d/%d duration:%f\n",
290
-           frame_rate_q.num, frame_rate_q.den,
291
-           duration < 0 ? -1 : test->max_pts * av_q2d(test->time_base));
283
+           test->frame_rate.num, test->frame_rate.den,
284
+           duration < 0 ? -1 : test->max_pts * av_q2d(av_inv_q(test->frame_rate)));
292 285
     init_idct();
293 286
 
294 287
     return 0;
... ...
@@ -305,7 +297,7 @@ static int config_props(AVFilterLink *outlink)
305 305
 
306 306
     outlink->w = WIDTH;
307 307
     outlink->h = HEIGHT;
308
-    outlink->time_base = test->time_base;
308
+    outlink->time_base = av_inv_q(test->frame_rate);
309 309
 
310 310
     return 0;
311 311
 }