hlsdemux: m3u8: move file lookup by sequence directly into code

Nicer to read, two lines of code less, and also the callback
function should've been a GCompareFunc that returns a gint
and not a boolean (it did work correctly, was just confusing).
This commit is contained in:
Tim-Philipp Müller 2015-09-02 16:40:17 +01:00
parent 28ac033773
commit 1c8d844ece

View file

@ -943,12 +943,6 @@ gst_m3u8_client_update_variant_playlist (GstM3U8Client * self, gchar * data,
return ret; return ret;
} }
static gboolean
_find_current (GstM3U8MediaFile * file, GstM3U8Client * client)
{
return file->sequence != client->sequence;
}
static GList * static GList *
find_next_fragment (GstM3U8Client * client, GList * l, gboolean forward) find_next_fragment (GstM3U8Client * client, GList * l, gboolean forward)
{ {
@ -1126,16 +1120,19 @@ gst_m3u8_client_advance_fragment (GstM3U8Client * client, gboolean forward)
GList *l; GList *l;
GST_DEBUG ("Looking for fragment %" G_GINT64_FORMAT, client->sequence); GST_DEBUG ("Looking for fragment %" G_GINT64_FORMAT, client->sequence);
l = g_list_find_custom (client->current->files, client, for (l = client->current->files; l != NULL; l = l->next) {
(GCompareFunc) _find_current); if (GST_M3U8_MEDIA_FILE (l->data)->sequence == client->sequence) {
if (l == NULL) { client->current_file = l;
break;
}
}
if (client->current_file == NULL) {
GST_DEBUG GST_DEBUG
("Could not find current fragment, trying next fragment directly"); ("Could not find current fragment, trying next fragment directly");
alternate_advance (client, forward); alternate_advance (client, forward);
GST_M3U8_CLIENT_UNLOCK (client); GST_M3U8_CLIENT_UNLOCK (client);
return; return;
} }
client->current_file = l;
} }
file = GST_M3U8_MEDIA_FILE (client->current_file->data); file = GST_M3U8_MEDIA_FILE (client->current_file->data);
@ -1364,19 +1361,20 @@ out:
guint64 guint64
gst_m3u8_client_get_current_fragment_duration (GstM3U8Client * client) gst_m3u8_client_get_current_fragment_duration (GstM3U8Client * client)
{ {
guint64 dur; guint64 dur = GST_CLOCK_TIME_NONE;
GList *list; GList *l;
g_return_val_if_fail (client != NULL, 0); g_return_val_if_fail (client != NULL, 0);
GST_M3U8_CLIENT_LOCK (client); GST_M3U8_CLIENT_LOCK (client);
list = g_list_find_custom (client->current->files, client, for (l = client->current->files; l != NULL; l = l->next) {
(GCompareFunc) _find_current); GstM3U8MediaFile *file = l->data;
if (list == NULL) {
dur = -1; if (file->sequence == client->sequence) {
} else { dur = file->duration;
dur = GST_M3U8_MEDIA_FILE (list->data)->duration; break;
}
} }
GST_M3U8_CLIENT_UNLOCK (client); GST_M3U8_CLIENT_UNLOCK (client);