diff options
author | Edward Hervey <edward@centricular.com> | 2015-04-17 15:30:29 +0200 |
---|---|---|
committer | Edward Hervey <bilboed@bilboed.com> | 2015-04-17 16:21:28 +0200 |
commit | b80ae9cdcd0f7d4f26ea7d70046f29a38b72c3d8 (patch) | |
tree | 1895ec4a213f30e6a624faa958c356fed6559324 | |
parent | 89e2a5fe755b6dcf2f013ba87ac43c447da9599a (diff) | |
download | gstreamer-plugins-bad-b80ae9cdcd0f7d4f26ea7d70046f29a38b72c3d8.tar.gz |
tsdemux: Unify duration querying code
And properly use it in the SEEKING query.
Fixes seeking with gst-play
-rw-r--r-- | gst/mpegtsdemux/tsdemux.c | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/gst/mpegtsdemux/tsdemux.c b/gst/mpegtsdemux/tsdemux.c index ab9d700c5..ed83368d7 100644 --- a/gst/mpegtsdemux/tsdemux.c +++ b/gst/mpegtsdemux/tsdemux.c @@ -455,6 +455,25 @@ gst_ts_demux_get_property (GObject * object, guint prop_id, } static gboolean +gst_ts_demux_get_duration (GstTSDemux * demux, GstClockTime * dur) +{ + MpegTSBase *base = (MpegTSBase *) demux; + gboolean res = FALSE; + gint64 val; + + /* Get total size in bytes */ + if (gst_pad_peer_query_duration (base->sinkpad, GST_FORMAT_BYTES, &val)) { + /* Convert it to duration */ + *dur = + mpegts_packetizer_offset_to_ts (base->packetizer, val, + demux->program->pcr_pid); + if (GST_CLOCK_TIME_IS_VALID (*dur)) + res = TRUE; + } + return res; +} + +static gboolean gst_ts_demux_srcpad_query (GstPad * pad, GstObject * parent, GstQuery * query) { gboolean res = TRUE; @@ -472,20 +491,11 @@ gst_ts_demux_srcpad_query (GstPad * pad, GstObject * parent, GstQuery * query) gst_query_parse_duration (query, &format, NULL); if (format == GST_FORMAT_TIME) { if (!gst_pad_peer_query (base->sinkpad, query)) { - gint64 val; - - format = GST_FORMAT_BYTES; - if (!gst_pad_peer_query_duration (base->sinkpad, format, &val)) + GstClockTime dur; + if (gst_ts_demux_get_duration (demux, &dur)) + gst_query_set_duration (query, GST_FORMAT_TIME, dur); + else res = FALSE; - else { - GstClockTime dur = - mpegts_packetizer_offset_to_ts (base->packetizer, val, - demux->program->pcr_pid); - if (GST_CLOCK_TIME_IS_VALID (dur)) - gst_query_set_duration (query, GST_FORMAT_TIME, dur); - else - res = FALSE; - } } } else { GST_DEBUG_OBJECT (demux, "only query duration on TIME is supported"); @@ -521,6 +531,7 @@ gst_ts_demux_srcpad_query (GstPad * pad, GstObject * parent, GstQuery * query) { GST_DEBUG ("query seeking"); gst_query_parse_seeking (query, &format, NULL, NULL, NULL); + GST_DEBUG ("asked for format %s", gst_format_get_name (format)); if (format == GST_FORMAT_TIME) { gboolean seekable = FALSE; @@ -529,9 +540,13 @@ gst_ts_demux_srcpad_query (GstPad * pad, GstObject * parent, GstQuery * query) /* If upstream is not seekable in TIME format we use * our own values here */ - if (!seekable) - gst_query_set_seeking (query, GST_FORMAT_TIME, TRUE, 0, - demux->segment.duration); + if (!seekable) { + GstClockTime dur; + if (gst_ts_demux_get_duration (demux, &dur)) { + gst_query_set_seeking (query, GST_FORMAT_TIME, TRUE, 0, dur); + GST_DEBUG ("Gave duration: %" GST_TIME_FORMAT, GST_TIME_ARGS (dur)); + } + } } else { GST_DEBUG_OBJECT (demux, "only TIME is supported for query seeking"); res = FALSE; |