summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault Saunier <thibault.saunier@collabora.com>2012-05-10 10:10:14 -0400
committerThibault Saunier <thibault.saunier@collabora.com>2012-05-10 14:08:11 -0400
commita8afa9755e6c6e83243624eb857094eb6f2b5397 (patch)
tree5e0a4e7682287bbcfaee14e434b44840a418e7ac
parent594d983ff9dabcda5272bef353ab084ed4a098fc (diff)
downloadgstreamer-plugins-bad-a8afa9755e6c6e83243624eb857094eb6f2b5397.tar.gz
hls: Add a way to get best playlist for a specific bitrate in M3U8Client
Make use of it in hlsdemux
-rw-r--r--gst/hls/gsthlsdemux.c24
-rw-r--r--gst/hls/m3u8.c27
-rw-r--r--gst/hls/m3u8.h2
3 files changed, 33 insertions, 20 deletions
diff --git a/gst/hls/gsthlsdemux.c b/gst/hls/gsthlsdemux.c
index 8d6975913..ecc6a15cc 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 eecb467e2..65afa8bbe 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 a03828716..6d608096a 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__ */