From f4789d04303ffd4f85dab96bd918b3cc7a431483 Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Tue, 12 May 2015 13:41:19 -0300 Subject: [PATCH] dashdemux: avoid busy-looping when waiting for new fragment When all fragments have already been downloaded on a live stream dashdemux would busy loop as the default implementation of has_next_fragment would return TRUE. Implement it to correctly signal if adaptivedemux should wait for the manifest update before trying to get new fragments. --- ext/dash/gstdashdemux.c | 14 ++++++++++++++ ext/dash/gstmpdparser.c | 15 +++++++++++++++ ext/dash/gstmpdparser.h | 1 + 3 files changed, 30 insertions(+) diff --git a/ext/dash/gstdashdemux.c b/ext/dash/gstdashdemux.c index 92fc0e5..ea6b8bb 100644 --- a/ext/dash/gstdashdemux.c +++ b/ext/dash/gstdashdemux.c @@ -205,6 +205,8 @@ static GstFlowReturn gst_dash_demux_stream_update_fragment_info (GstAdaptiveDemuxStream * stream); static GstFlowReturn gst_dash_demux_stream_seek (GstAdaptiveDemuxStream * stream, GstClockTime ts); +static gboolean +gst_dash_demux_stream_has_next_fragment (GstAdaptiveDemuxStream * stream); static GstFlowReturn gst_dash_demux_stream_advance_fragment (GstAdaptiveDemuxStream * stream); static gboolean @@ -361,6 +363,8 @@ gst_dash_demux_class_init (GstDashDemuxClass * klass) gstadaptivedemux_class->has_next_period = gst_dash_demux_has_next_period; gstadaptivedemux_class->advance_period = gst_dash_demux_advance_period; + gstadaptivedemux_class->stream_has_next_fragment = + gst_dash_demux_stream_has_next_fragment; gstadaptivedemux_class->stream_advance_fragment = gst_dash_demux_stream_advance_fragment; gstadaptivedemux_class->stream_get_fragment_waiting_time = @@ -969,6 +973,16 @@ gst_dash_demux_stream_advance_subfragment (GstAdaptiveDemuxStream * stream) return !fragment_finished; } +static gboolean +gst_dash_demux_stream_has_next_fragment (GstAdaptiveDemuxStream * stream) +{ + GstDashDemux *dashdemux = GST_DASH_DEMUX_CAST (stream->demux); + GstDashDemuxStream *dashstream = (GstDashDemuxStream *) stream; + + return gst_mpd_client_has_next_segment (dashdemux->client, + dashstream->active_stream, stream->demux->segment.rate > 0.0); +} + static GstFlowReturn gst_dash_demux_stream_advance_fragment (GstAdaptiveDemuxStream * stream) { diff --git a/ext/dash/gstmpdparser.c b/ext/dash/gstmpdparser.c index 2aa8fe9..edb53a1 100644 --- a/ext/dash/gstmpdparser.c +++ b/ext/dash/gstmpdparser.c @@ -3720,6 +3720,21 @@ gst_mpd_client_get_next_fragment (GstMpdClient * client, return TRUE; } +gboolean +gst_mpd_client_has_next_segment (GstMpdClient * client, + GstActiveStream * stream, gboolean forward) +{ + if (forward) { + if (stream->segment_index >= stream->segments->len) + return FALSE; + } else { + if (stream->segment_index < 0) + return FALSE; + } + + return TRUE; +} + GstFlowReturn gst_mpd_client_advance_segment (GstMpdClient * client, GstActiveStream * stream, gboolean forward) diff --git a/ext/dash/gstmpdparser.h b/ext/dash/gstmpdparser.h index f69740f..9f7f78b 100644 --- a/ext/dash/gstmpdparser.h +++ b/ext/dash/gstmpdparser.h @@ -534,6 +534,7 @@ GstActiveStream *gst_mpdparser_get_active_stream_by_index (GstMpdClient *client, guint gst_mpdparser_get_nb_adaptationSet (GstMpdClient *client); /* Segment */ +gboolean gst_mpd_client_has_next_segment (GstMpdClient * client, GstActiveStream * stream, gboolean forward); GstFlowReturn gst_mpd_client_advance_segment (GstMpdClient * client, GstActiveStream * stream, gboolean forward); void gst_mpd_client_seek_to_first_segment (GstMpdClient * client); -- 2.7.4