videotestsrc: do not set TIME duration when asked for another format
authorVincent Penquerc'h <vincent.penquerch@collabora.co.uk>
Fri, 10 Jan 2014 09:53:21 +0000 (09:53 +0000)
committerVincent Penquerc'h <vincent.penquerch@collabora.co.uk>
Fri, 10 Jan 2014 09:56:34 +0000 (09:56 +0000)
This fixes asserts in pipelines such as:

gst-launch-1.0 videotestsrc num-buffers=1000 ! x264enc ! h264parse ! \
   matroskamux name=mux ! filesink location=test.mkv

gst/videotestsrc/gstvideotestsrc.c

index 6b0847b3dba69f13d80c3210a7342fed45684292..a804a3cf7f017b9352359ff4675a6f0812578730 100644 (file)
@@ -783,11 +783,24 @@ gst_video_test_src_query (GstBaseSrc * bsrc, GstQuery * query)
     }
     case GST_QUERY_DURATION:{
       if (bsrc->num_buffers != -1) {
-        gint64 dur = gst_util_uint64_scale_int_round (bsrc->num_buffers
-            * GST_SECOND, src->info.fps_d, src->info.fps_n);
-        res = TRUE;
-        gst_query_set_duration (query, GST_FORMAT_TIME, dur);
-        break;
+        GstFormat format;
+
+        gst_query_parse_duration (query, &format, NULL);
+        switch (format) {
+          case GST_FORMAT_TIME:{
+            gint64 dur = gst_util_uint64_scale_int_round (bsrc->num_buffers
+                * GST_SECOND, src->info.fps_d, src->info.fps_n);
+            res = TRUE;
+            gst_query_set_duration (query, GST_FORMAT_TIME, dur);
+            break;
+          }
+          case GST_FORMAT_BYTES:
+            gst_query_set_duration (query, GST_FORMAT_BYTES,
+                bsrc->num_buffers * src->info.size);
+            break;
+          default:
+            break;
+        }
       }
       /* fall through */
     }