mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-03-28 11:55:39 +00:00
hlsdemux: simplify next segment checking functions
Optimize loop by moving condition outside of it and reuse the find_next_fragment function to check if there is next instead of replicating the same loop
This commit is contained in:
parent
e21abb62e0
commit
308b2e5aaf
1 changed files with 28 additions and 30 deletions
|
@ -951,50 +951,48 @@ _find_current (GstM3U8MediaFile * file, GstM3U8Client * client)
|
|||
return file->sequence != client->sequence;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
has_next_fragment (GstM3U8Client * client, GList * l, gboolean forward)
|
||||
{
|
||||
GstM3U8MediaFile *file;
|
||||
|
||||
if (!forward)
|
||||
l = g_list_last (l);
|
||||
|
||||
while (l) {
|
||||
file = l->data;
|
||||
|
||||
if (forward && file->sequence > client->sequence)
|
||||
break;
|
||||
else if (!forward && file->sequence < client->sequence)
|
||||
break;
|
||||
|
||||
l = (forward ? l->next : l->prev);
|
||||
}
|
||||
|
||||
return l != NULL;
|
||||
}
|
||||
|
||||
static GList *
|
||||
find_next_fragment (GstM3U8Client * client, GList * l, gboolean forward)
|
||||
{
|
||||
GstM3U8MediaFile *file;
|
||||
|
||||
if (!forward)
|
||||
if (forward) {
|
||||
while (l) {
|
||||
file = l->data;
|
||||
|
||||
if (file->sequence >= client->sequence)
|
||||
break;
|
||||
|
||||
l = l->next;
|
||||
}
|
||||
} else {
|
||||
l = g_list_last (l);
|
||||
|
||||
while (l) {
|
||||
file = l->data;
|
||||
while (l) {
|
||||
file = l->data;
|
||||
|
||||
if (forward && file->sequence >= client->sequence)
|
||||
break;
|
||||
else if (!forward && file->sequence <= client->sequence)
|
||||
break;
|
||||
if (file->sequence <= client->sequence)
|
||||
break;
|
||||
|
||||
l = (forward ? l->next : l->prev);
|
||||
l = l->prev;
|
||||
}
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
has_next_fragment (GstM3U8Client * client, GList * l, gboolean forward)
|
||||
{
|
||||
l = find_next_fragment (client, l, forward);
|
||||
|
||||
if (l) {
|
||||
return (forward && l->next) || (!forward && l->prev);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_m3u8_client_get_next_fragment (GstM3U8Client * client,
|
||||
gboolean * discontinuity, gchar ** uri, GstClockTime * duration,
|
||||
|
|
Loading…
Reference in a new issue