mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 06:54:49 +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;
|
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 *
|
static GList *
|
||||||
find_next_fragment (GstM3U8Client * client, GList * l, gboolean forward)
|
find_next_fragment (GstM3U8Client * client, GList * l, gboolean forward)
|
||||||
{
|
{
|
||||||
GstM3U8MediaFile *file;
|
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);
|
l = g_list_last (l);
|
||||||
|
|
||||||
while (l) {
|
while (l) {
|
||||||
file = l->data;
|
file = l->data;
|
||||||
|
|
||||||
if (forward && file->sequence >= client->sequence)
|
if (file->sequence <= client->sequence)
|
||||||
break;
|
break;
|
||||||
else if (!forward && file->sequence <= client->sequence)
|
|
||||||
break;
|
|
||||||
|
|
||||||
l = (forward ? l->next : l->prev);
|
l = l->prev;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return l;
|
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
|
gboolean
|
||||||
gst_m3u8_client_get_next_fragment (GstM3U8Client * client,
|
gst_m3u8_client_get_next_fragment (GstM3U8Client * client,
|
||||||
gboolean * discontinuity, gchar ** uri, GstClockTime * duration,
|
gboolean * discontinuity, gchar ** uri, GstClockTime * duration,
|
||||||
|
|
Loading…
Reference in a new issue