diff --git a/gst/hls/gsthlsdemux.c b/gst/hls/gsthlsdemux.c index 8d6975913b..ecc6a15cc1 100644 --- a/gst/hls/gsthlsdemux.c +++ b/gst/hls/gsthlsdemux.c @@ -982,27 +982,12 @@ gst_hls_demux_update_playlist (GstHLSDemux * demux, gboolean update) static gboolean gst_hls_demux_change_playlist (GstHLSDemux * demux, guint max_bitrate) { - GList *list, *previous_variant, *current_variant; + GList *previous_variant, *current_variant; gint old_bandwidth, new_bandwidth; - GST_M3U8_CLIENT_LOCK (demux->client); - current_variant = demux->client->main->current_variant; - previous_variant = current_variant; - - /* Go to the highest possible bandwidth allowed */ - while (GST_M3U8 (current_variant->data)->bandwidth < max_bitrate) { - list = g_list_next (current_variant); - if (!list) - break; - current_variant = list; - } - - while (GST_M3U8 (current_variant->data)->bandwidth > max_bitrate) { - list = g_list_previous (current_variant); - if (!list) - break; - current_variant = list; - } + previous_variant = demux->client->main->current_variant; + current_variant = gst_m3u8_client_get_playlist_for_bitrate (demux->client, + max_bitrate); retry_failover_protection: old_bandwidth = GST_M3U8 (previous_variant->data)->bandwidth; @@ -1010,7 +995,6 @@ retry_failover_protection: /* Don't do anything else if the playlist is the same */ if (new_bandwidth == old_bandwidth) { - GST_M3U8_CLIENT_UNLOCK (demux->client); return TRUE; } diff --git a/gst/hls/m3u8.c b/gst/hls/m3u8.c index eecb467e2c..65afa8bbe6 100644 --- a/gst/hls/m3u8.c +++ b/gst/hls/m3u8.c @@ -647,3 +647,30 @@ gst_m3u8_client_is_live (GstM3U8Client * client) GST_M3U8_CLIENT_UNLOCK (client); return ret; } + +GList * +gst_m3u8_client_get_playlist_for_bitrate (GstM3U8Client * client, guint bitrate) +{ + GList *list, *current_variant; + + GST_M3U8_CLIENT_LOCK (client); + current_variant = client->main->current_variant; + + /* Go to the highest possible bandwidth allowed */ + while (GST_M3U8 (current_variant->data)->bandwidth < bitrate) { + list = g_list_next (current_variant); + if (!list) + break; + current_variant = list; + } + + while (GST_M3U8 (current_variant->data)->bandwidth > bitrate) { + list = g_list_previous (current_variant); + if (!list) + break; + current_variant = list; + } + GST_M3U8_CLIENT_UNLOCK (client); + + return current_variant; +} diff --git a/gst/hls/m3u8.h b/gst/hls/m3u8.h index a03828716a..6d608096a3 100644 --- a/gst/hls/m3u8.h +++ b/gst/hls/m3u8.h @@ -92,6 +92,8 @@ const gchar *gst_m3u8_client_get_uri(GstM3U8Client * client); const gchar *gst_m3u8_client_get_current_uri(GstM3U8Client * client); gboolean gst_m3u8_client_has_variant_playlist(GstM3U8Client * client); gboolean gst_m3u8_client_is_live(GstM3U8Client * client); +GList * gst_m3u8_client_get_playlist_for_bitrate (GstM3U8Client * client, + guint bitrate); G_END_DECLS #endif /* __M3U8_H__ */