matroskademux: figure out if we have prev_size when starting up
authorTim-Philipp Müller <tim@centricular.com>
Wed, 15 Aug 2018 00:10:32 +0000 (01:10 +0100)
committerTim-Philipp Müller <tim@centricular.com>
Mon, 27 Aug 2018 21:01:21 +0000 (23:01 +0200)
This is useful to know in case someone initiates a seek or
direction change before we reach the second cluster.

gst/matroska/matroska-demux.c

index e73eb48..2c19e79 100644 (file)
@@ -4975,10 +4975,10 @@ gst_matroska_demux_parse_id (GstMatroskaDemux * demux, guint32 id,
                 goto no_tracks;
             }
           }
-          if (G_UNLIKELY (demux->common.state
-                  == GST_MATROSKA_READ_STATE_HEADER)) {
+          if (demux->common.state == GST_MATROSKA_READ_STATE_HEADER) {
             demux->common.state = GST_MATROSKA_READ_STATE_DATA;
             demux->first_cluster_offset = demux->common.offset;
+
             if (!demux->streaming &&
                 !GST_CLOCK_TIME_IS_VALID (demux->common.segment.duration)) {
               GstMatroskaIndex *last = NULL;
@@ -4999,6 +4999,22 @@ gst_matroska_demux_parse_id (GstMatroskaDemux * demux, guint32 id,
                     GST_TIME_ARGS (demux->common.segment.duration));
               }
             }
+
+            /* Peek at second cluster in order to figure out if we have cluster
+             * prev_size or not (which is never set on the first cluster for
+             * obvious reasons). This is useful in case someone initiates a
+             * seek or direction change before we reach the second cluster. */
+            if (!demux->streaming) {
+              ClusterInfo cluster = { 0, };
+
+              if (gst_matroska_demux_peek_cluster_info (demux, &cluster,
+                      demux->first_cluster_offset) && cluster.size > 0) {
+                gst_matroska_demux_peek_cluster_info (demux, &cluster,
+                    demux->first_cluster_offset + cluster.size);
+              }
+              demux->common.offset = demux->first_cluster_offset;
+            }
+
             GST_DEBUG_OBJECT (demux, "signaling no more pads");
             gst_element_no_more_pads (GST_ELEMENT (demux));
             /* send initial segment - we wait till we know the first