+static gboolean
+gst_mss_demux_src_event (GstPad * pad, GstEvent * event)
+{
+ GstMssDemux *mssdemux;
+
+ mssdemux = GST_MSS_DEMUX (GST_PAD_PARENT (pad));
+
+ switch (event->type) {
+ case GST_EVENT_SEEK:
+ {
+ gdouble rate;
+ GstFormat format;
+ GstSeekFlags flags;
+ GstSeekType start_type, stop_type;
+ gint64 start, stop;
+ GstEvent *newsegment;
+ GSList *iter;
+
+ GST_INFO_OBJECT (mssdemux, "Received GST_EVENT_SEEK");
+
+ gst_event_parse_seek (event, &rate, &format, &flags, &start_type, &start,
+ &stop_type, &stop);
+
+ if (format != GST_FORMAT_TIME)
+ return FALSE;
+
+ GST_DEBUG_OBJECT (mssdemux,
+ "seek event, rate: %f start: %" GST_TIME_FORMAT " stop: %"
+ GST_TIME_FORMAT, rate, GST_TIME_ARGS (start), GST_TIME_ARGS (stop));
+
+ if (flags & GST_SEEK_FLAG_FLUSH) {
+ GstEvent *flush = gst_event_new_flush_start ();
+ GST_DEBUG_OBJECT (mssdemux, "sending flush start");
+
+ gst_event_set_seqnum (flush, gst_event_get_seqnum (event));
+ gst_mss_demux_push_src_event (mssdemux, flush);
+ gst_event_unref (flush);
+ }
+
+ /* stop the tasks */
+ for (iter = mssdemux->streams; iter; iter = g_slist_next (iter)) {
+ GstMssDemuxStream *stream = iter->data;
+
+ gst_uri_downloader_cancel (stream->downloader);
+ gst_task_pause (stream->stream_task);
+ }
+ for (iter = mssdemux->streams; iter; iter = g_slist_next (iter)) {
+ GstMssDemuxStream *stream = iter->data;
+ g_static_rec_mutex_lock (&stream->stream_lock);
+ }
+
+ if (!gst_mss_manifest_seek (mssdemux->manifest, start)) {;
+ GST_WARNING_OBJECT (mssdemux, "Could not find seeked fragment");
+ return FALSE;
+ }
+
+ newsegment =
+ gst_event_new_new_segment (FALSE, rate, format, start, stop, start);
+ gst_event_set_seqnum (newsegment, gst_event_get_seqnum (event));
+ for (iter = mssdemux->streams; iter; iter = g_slist_next (iter)) {
+ GstMssDemuxStream *stream = iter->data;
+
+ stream->pending_newsegment = gst_event_ref (newsegment);
+ }
+ gst_event_unref (newsegment);
+
+ if (flags & GST_SEEK_FLAG_FLUSH) {
+ GstEvent *flush = gst_event_new_flush_stop ();
+ GST_DEBUG_OBJECT (mssdemux, "sending flush stop");
+
+ gst_event_set_seqnum (flush, gst_event_get_seqnum (event));
+ gst_mss_demux_push_src_event (mssdemux, flush);
+ gst_event_unref (flush);
+ }
+
+ /* restart tasks */
+ for (iter = mssdemux->streams; iter; iter = g_slist_next (iter)) {
+ GstMssDemuxStream *stream = iter->data;
+ g_static_rec_mutex_unlock (&stream->stream_lock);
+ }
+ for (iter = mssdemux->streams; iter; iter = g_slist_next (iter)) {
+ GstMssDemuxStream *stream = iter->data;
+
+ gst_task_start (stream->stream_task);
+ }
+
+ return TRUE;
+ }
+ default:
+ break;
+ }
+
+ return gst_pad_event_default (pad, event);
+}
+