hlsdemux: avoid using g_list_append for creating segments list

Use g_list_prepend and reverse it at the end to skip traversing the
same list for every new segment
This commit is contained in:
Thiago Santos 2015-01-07 09:21:33 -03:00
parent cd6069f5af
commit c79e8a78ac

View file

@ -487,8 +487,7 @@ gst_m3u8_update (GstM3U8Client * client, GstM3U8 * self, gchar * data,
if (offset != -1) { if (offset != -1) {
file->offset = offset; file->offset = offset;
} else { } else {
GstM3U8MediaFile *prev = GstM3U8MediaFile *prev = self->files ? self->files->data : NULL;
self->files ? g_list_last (self->files)->data : NULL;
if (!prev) { if (!prev) {
offset = 0; offset = 0;
@ -508,7 +507,7 @@ gst_m3u8_update (GstM3U8Client * client, GstM3U8 * self, gchar * data,
title = NULL; title = NULL;
discontinuity = FALSE; discontinuity = FALSE;
size = offset = -1; size = offset = -1;
self->files = g_list_append (self->files, file); self->files = g_list_prepend (self->files, file);
} }
} else if (g_str_has_prefix (data, "#EXT-X-ENDLIST")) { } else if (g_str_has_prefix (data, "#EXT-X-ENDLIST")) {
@ -696,6 +695,8 @@ gst_m3u8_update (GstM3U8Client * client, GstM3U8 * self, gchar * data,
g_free (current_key); g_free (current_key);
current_key = NULL; current_key = NULL;
self->files = g_list_reverse (self->files);
/* reorder playlists by bitrate */ /* reorder playlists by bitrate */
if (self->lists) { if (self->lists) {
gchar *top_variant_uri = NULL; gchar *top_variant_uri = NULL;
@ -1116,7 +1117,7 @@ gst_m3u8_client_get_current_uri (GstM3U8Client * client)
} }
gboolean gboolean
gst_m3u8_client_has_main(GstM3U8Client * client) gst_m3u8_client_has_main (GstM3U8Client * client)
{ {
gboolean ret; gboolean ret;