baseparse: make seeking in DEFAULT format work if the subclass can convert for us
authorTim-Philipp Müller <tim@centricular.net>
Sun, 19 Aug 2012 16:51:00 +0000 (17:51 +0100)
committerTim-Philipp Müller <tim@centricular.net>
Sun, 19 Aug 2012 16:51:00 +0000 (17:51 +0100)
We only deal in TIME format ourselves, but if the subclass can handle
converting other formats into TIME format, we can support that too.

Fixes seeking in DEFAULT (sample) format with flacparse,
and the flacdec unit test.

libs/gst/base/gstbaseparse.c

index 5f4118f..c42d3c6 100644 (file)
@@ -3762,9 +3762,21 @@ gst_base_parse_handle_seek (GstBaseParse * parse, GstEvent * event)
       GST_TIME_FORMAT, gst_format_get_name (format), rate,
       start_type, GST_TIME_ARGS (start), stop_type, GST_TIME_ARGS (stop));
 
-  /* we can only handle TIME */
-  if (format != GST_FORMAT_TIME)
-    goto done;
+  /* we can only handle TIME, so check if subclass can convert
+   * to TIME format if it's some other format (such as DEFAULT) */
+  if (format != GST_FORMAT_TIME) {
+    if (!gst_base_parse_convert (parse, format, start, GST_FORMAT_TIME, &start)
+        || !gst_base_parse_convert (parse, format, stop, GST_FORMAT_TIME,
+            &stop))
+      goto no_convert_to_time;
+
+    GST_INFO_OBJECT (parse, "converted %s format to start time "
+        "%" GST_TIME_FORMAT " and stop time %" GST_TIME_FORMAT,
+        gst_format_get_name (format), GST_TIME_ARGS (start),
+        GST_TIME_ARGS (stop));
+
+    format = GST_FORMAT_TIME;
+  }
 
   /* no negative rates in push mode (unless upstream takes care of that, but
    * we've already tried upstream and it didn't handle the seek request) */
@@ -3985,6 +3997,13 @@ wrong_type:
     res = FALSE;
     goto done;
   }
+no_convert_to_time:
+  {
+    GST_DEBUG_OBJECT (parse, "seek in %s format was requested, but subclass "
+        "couldn't convert that into TIME format", gst_format_get_name (format));
+    res = FALSE;
+    goto done;
+  }
 convert_failed:
   {
     GST_DEBUG_OBJECT (parse, "conversion TIME to BYTES failed.");