mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-18 14:26:43 +00:00
hlsdemux: Fallback to previous playlist when switching if the new playlist can't be fetched
This commit is contained in:
parent
f805f9e079
commit
87d10cf683
1 changed files with 26 additions and 14 deletions
|
@ -969,22 +969,24 @@ gst_hls_demux_update_playlist (GstHLSDemux * demux)
|
||||||
GST_WARNING_OBJECT (demux, "Couldn't not validate playlist encoding");
|
GST_WARNING_OBJECT (demux, "Couldn't not validate playlist encoding");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
gst_m3u8_client_update (demux->client, playlist);
|
|
||||||
return TRUE;
|
return gst_m3u8_client_update (demux->client, playlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_hls_demux_change_playlist (GstHLSDemux * demux, gboolean is_fast)
|
gst_hls_demux_change_playlist (GstHLSDemux * demux, gboolean is_fast)
|
||||||
{
|
{
|
||||||
GList *list;
|
GList *list;
|
||||||
|
GList *previous_list;
|
||||||
GstStructure *s;
|
GstStructure *s;
|
||||||
gint new_bandwidth;
|
gint new_bandwidth;
|
||||||
|
|
||||||
GST_M3U8_CLIENT_LOCK (demux->client);
|
GST_M3U8_CLIENT_LOCK (demux->client);
|
||||||
|
previous_list = demux->client->main->current_variant;
|
||||||
if (is_fast)
|
if (is_fast)
|
||||||
list = g_list_next (demux->client->main->current_variant);
|
list = g_list_next (previous_list);
|
||||||
else
|
else
|
||||||
list = g_list_previous (demux->client->main->current_variant);
|
list = g_list_previous (previous_list);
|
||||||
|
|
||||||
/* Don't do anything else if the playlist is the same */
|
/* Don't do anything else if the playlist is the same */
|
||||||
if (!list || list->data == demux->client->current) {
|
if (!list || list->data == demux->client->current) {
|
||||||
|
@ -1001,15 +1003,23 @@ gst_hls_demux_change_playlist (GstHLSDemux * demux, gboolean is_fast)
|
||||||
new_bandwidth = demux->client->current->bandwidth;
|
new_bandwidth = demux->client->current->bandwidth;
|
||||||
GST_M3U8_CLIENT_UNLOCK (demux->client);
|
GST_M3U8_CLIENT_UNLOCK (demux->client);
|
||||||
|
|
||||||
gst_hls_demux_update_playlist (demux);
|
|
||||||
GST_INFO_OBJECT (demux, "Client is %s, switching to bitrate %d",
|
GST_INFO_OBJECT (demux, "Client is %s, switching to bitrate %d",
|
||||||
is_fast ? "fast" : "slow", new_bandwidth);
|
is_fast ? "fast" : "slow", new_bandwidth);
|
||||||
|
|
||||||
s = gst_structure_new ("playlist",
|
if (gst_hls_demux_update_playlist (demux)) {
|
||||||
"uri", G_TYPE_STRING, gst_m3u8_client_get_current_uri (demux->client),
|
s = gst_structure_new ("playlist",
|
||||||
"bitrate", G_TYPE_INT, new_bandwidth, NULL);
|
"uri", G_TYPE_STRING, gst_m3u8_client_get_current_uri (demux->client),
|
||||||
gst_element_post_message (GST_ELEMENT_CAST (demux),
|
"bitrate", G_TYPE_INT, new_bandwidth, NULL);
|
||||||
gst_message_new_element (GST_OBJECT_CAST (demux), s));
|
gst_element_post_message (GST_ELEMENT_CAST (demux),
|
||||||
|
gst_message_new_element (GST_OBJECT_CAST (demux), s));
|
||||||
|
} else {
|
||||||
|
GST_INFO_OBJECT (demux, "Unable to update playlist. Switching back");
|
||||||
|
GST_M3U8_CLIENT_LOCK (demux->client);
|
||||||
|
demux->client->main->current_variant = previous_list;
|
||||||
|
GST_M3U8_CLIENT_UNLOCK (demux->client);
|
||||||
|
gst_m3u8_client_set_current (demux->client, previous_list->data);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Force typefinding since we might have changed media type */
|
/* Force typefinding since we might have changed media type */
|
||||||
demux->do_typefind = TRUE;
|
demux->do_typefind = TRUE;
|
||||||
|
@ -1072,17 +1082,19 @@ gst_hls_demux_switch_playlist (GstHLSDemux * demux)
|
||||||
/* if we are on time switch to a higher bitrate */
|
/* if we are on time switch to a higher bitrate */
|
||||||
if (diff > limit) {
|
if (diff > limit) {
|
||||||
while (diff > limit) {
|
while (diff > limit) {
|
||||||
gst_hls_demux_change_playlist (demux, TRUE);
|
if (!gst_hls_demux_change_playlist (demux, TRUE))
|
||||||
|
break;
|
||||||
diff -= limit;
|
diff -= limit;
|
||||||
}
|
}
|
||||||
demux->accumulated_delay = 0;
|
demux->accumulated_delay = 0;
|
||||||
} else if (diff < 0) {
|
} else if (diff < 0) {
|
||||||
/* if the client is too slow wait until it has accumulated a certain delay to
|
/* if the client is too slow wait until it has accumulated a certain delay
|
||||||
* switch to a lower bitrate */
|
* to switch to a lower bitrate */
|
||||||
demux->accumulated_delay -= diff;
|
demux->accumulated_delay -= diff;
|
||||||
if (demux->accumulated_delay >= limit) {
|
if (demux->accumulated_delay >= limit) {
|
||||||
while (demux->accumulated_delay >= limit) {
|
while (demux->accumulated_delay >= limit) {
|
||||||
gst_hls_demux_change_playlist (demux, FALSE);
|
if (!gst_hls_demux_change_playlist (demux, FALSE))
|
||||||
|
break;
|
||||||
demux->accumulated_delay -= limit;
|
demux->accumulated_delay -= limit;
|
||||||
}
|
}
|
||||||
demux->accumulated_delay = 0;
|
demux->accumulated_delay = 0;
|
||||||
|
|
Loading…
Reference in a new issue