From 024aa47f644dc141bcf9318a283aa4a3c6b0a7d0 Mon Sep 17 00:00:00 2001 From: Arnaud Vrac Date: Fri, 24 May 2013 18:18:35 +0200 Subject: [PATCH] tsdemux: implement seeking in push mode --- gst/mpegtsdemux/mpegtsbase.c | 31 +++++++++++++++++++++++-------- gst/mpegtsdemux/tsdemux.c | 3 +-- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/gst/mpegtsdemux/mpegtsbase.c b/gst/mpegtsdemux/mpegtsbase.c index b4fa74d..e09b4ab 100644 --- a/gst/mpegtsdemux/mpegtsbase.c +++ b/gst/mpegtsdemux/mpegtsbase.c @@ -1007,6 +1007,7 @@ static gboolean mpegts_base_sink_event (GstPad * pad, GstObject * parent, GstEvent * event) { gboolean res = TRUE; + gboolean hard; MpegTSBase *base = GST_MPEGTS_BASE (parent); GST_DEBUG_OBJECT (base, "Got event %s", @@ -1040,12 +1041,12 @@ mpegts_base_sink_event (GstPad * pad, GstObject * parent, GstEvent * event) break; case GST_EVENT_FLUSH_STOP: res = GST_MPEGTS_BASE_GET_CLASS (base)->push_event (base, event); - mpegts_packetizer_flush (base->packetizer, TRUE); - mpegts_base_flush (base, TRUE); + hard = (base->mode != BASE_MODE_SEEKING); + mpegts_packetizer_flush (base->packetizer, hard); + mpegts_base_flush (base, hard); gst_segment_init (&base->segment, GST_FORMAT_UNDEFINED); base->seen_pat = FALSE; break; - /* Passthrough */ default: res = GST_MPEGTS_BASE_GET_CLASS (base)->push_event (base, event); } @@ -1340,10 +1341,24 @@ mpegts_base_handle_seek_event (MpegTSBase * base, GstPad * pad, GST_DEBUG ("upstream handled SEEK event"); return TRUE; } - /* FIXME : Actually ... it is supported, we just need to convert - * the seek event to BYTES */ - GST_ERROR ("seeking in push mode not supported"); - goto push_mode; + + /* If the subclass can seek, do that */ + if (klass->seek) { + ret = klass->seek (base, event); + if (G_UNLIKELY (ret != GST_FLOW_OK)) + GST_WARNING ("seeking failed %s", gst_flow_get_name (ret)); + else { + base->mode = BASE_MODE_SEEKING; + if (!gst_pad_push_event (base->sinkpad, gst_event_new_seek (rate, + GST_FORMAT_BYTES, flags, + GST_SEEK_TYPE_SET, base->seek_offset, + GST_SEEK_TYPE_NONE, -1))) + ret = GST_FLOW_ERROR; + base->mode = BASE_MODE_PUSHING; + } + } + + return ret == GST_FLOW_OK; } GST_DEBUG ("seek event, rate: %f start: %" GST_TIME_FORMAT @@ -1404,7 +1419,7 @@ mpegts_base_handle_seek_event (MpegTSBase * base, GstPad * pad, done: gst_pad_start_task (base->sinkpad, (GstTaskFunction) mpegts_base_loop, base, NULL); -push_mode: + GST_PAD_STREAM_UNLOCK (base->sinkpad); return ret == GST_FLOW_OK; } diff --git a/gst/mpegtsdemux/tsdemux.c b/gst/mpegtsdemux/tsdemux.c index 63a3c13..a5cf2ec 100644 --- a/gst/mpegtsdemux/tsdemux.c +++ b/gst/mpegtsdemux/tsdemux.c @@ -460,8 +460,7 @@ 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, - demux->parent.mode != BASE_MODE_PUSHING, 0, + gst_query_set_seeking (query, GST_FORMAT_TIME, TRUE, 0, demux->segment.duration); } else { GST_DEBUG_OBJECT (demux, "only TIME is supported for query seeking"); -- 2.7.4