summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYouness Alaoui <youness.alaoui@collabora.co.uk>2011-08-31 03:07:48 +0000
committerSebastian Dröge <sebastian.droege@collabora.co.uk>2011-08-31 12:11:20 +0200
commit277a7d05b2674705a93047f34ddcac462821de2f (patch)
treeff6de72cb1f35369e46c43c542ef8b543fc687e2
parent917708df82b1bb50401c85bbe3d7573650ecd929 (diff)
hlsdemux: If paused, do not cache fragments until out of memory error!
We should stop the update thread in PAUSED state and avoid fetching new fragments when the queue is not empty. The queue should always be empty since we push data into a queue. Also, in totem, if we seek and pause the stream while it's buffering, then the state will stay playing for some reason, so it's best not to continue fetching fragments forever.
-rw-r--r--gst/hls/gsthlsdemux.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/gst/hls/gsthlsdemux.c b/gst/hls/gsthlsdemux.c
index 41284e483..74c6f3219 100644
--- a/gst/hls/gsthlsdemux.c
+++ b/gst/hls/gsthlsdemux.c
@@ -294,6 +294,14 @@ gst_hls_demux_change_state (GstElement * element, GstStateChange transition)
case GST_STATE_CHANGE_NULL_TO_READY:
gst_hls_demux_reset (demux, FALSE);
break;
+ case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
+ /* Start the streaming loop in paused only if we already received
+ the main playlist. It might have been stopped if we were in PAUSED
+ state and we filled our queue with enough cached fragments
+ */
+ if (gst_m3u8_client_get_uri (demux->client)[0] != '\0')
+ gst_hls_demux_start_update (demux);
+ break;
default:
break;
}
@@ -301,6 +309,9 @@ gst_hls_demux_change_state (GstElement * element, GstStateChange transition)
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
switch (transition) {
+ case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
+ gst_hls_demux_stop_update (demux);
+ break;
case GST_STATE_CHANGE_PAUSED_TO_READY:
demux->cancelled = TRUE;
gst_hls_demux_stop (demux);
@@ -716,8 +727,9 @@ gst_hls_demux_loop (GstHLSDemux * demux)
if (!gst_hls_demux_cache_fragments (demux))
goto cache_error;
- /* we can start now the updates thread */
- gst_hls_demux_start_update (demux);
+ /* we can start now the updates thread (only if on playing) */
+ if (GST_STATE (demux) == GST_STATE_PLAYING)
+ gst_hls_demux_start_update (demux);
GST_INFO_OBJECT (demux, "First fragments cached successfully");
}
@@ -725,7 +737,7 @@ gst_hls_demux_loop (GstHLSDemux * demux)
if (demux->end_of_playlist)
goto end_of_playlist;
- goto empty_queue;
+ goto pause_task;
}
buf = g_queue_pop_head (demux->queue);
@@ -783,7 +795,7 @@ error:
return;
}
-empty_queue:
+pause_task:
{
gst_task_pause (demux->task);
return;
@@ -925,14 +937,15 @@ gst_hls_demux_update_thread (GstHLSDemux * demux)
}
/* fetch the next fragment */
- if (!gst_hls_demux_get_next_fragment (demux, TRUE)) {
- if (!demux->end_of_playlist && !demux->cancelled)
- GST_ERROR_OBJECT (demux, "Could not fetch the next fragment");
- goto quit;
+ if (g_queue_is_empty (demux->queue)) {
+ if (!gst_hls_demux_get_next_fragment (demux, TRUE)) {
+ if (!demux->end_of_playlist && !demux->cancelled)
+ GST_ERROR_OBJECT (demux, "Could not fetch the next fragment");
+ goto quit;
+ }
+ /* try to switch to another bitrate if needed */
+ gst_hls_demux_switch_playlist (demux);
}
-
- /* try to switch to another bitrate if needed */
- gst_hls_demux_switch_playlist (demux);
}
quit: