m3u8: Split gst_m3u8_update_check_consistent_media_seqnums
The function was basically one big if-else. Move the branch to the one caller. Currently, it's never called with previous_files == NULL. Assert that this continues. https://bugzilla.gnome.org/show_bug.cgi?id=788417
This commit is contained in:
parent
234a8ecc50
commit
f80ad048e6
@ -306,24 +306,16 @@ gst_hls_variant_stream_compare_by_bitrate (gconstpointer a, gconstpointer b)
|
|||||||
return vs_a->bandwidth - vs_b->bandwidth;
|
return vs_a->bandwidth - vs_b->bandwidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If we have MEDIA-SEQUENCE, ensure that it's consistent. If it is not,
|
||||||
|
* the client SHOULD halt playback (6.3.4), which is what we do then. */
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_m3u8_update_check_consistent_media_seqnums (GstM3U8 * self,
|
check_media_seqnums (GstM3U8 * self, GList * previous_files)
|
||||||
gboolean have_mediasequence, GList * previous_files)
|
|
||||||
{
|
{
|
||||||
if (!previous_files)
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
/* If we have MEDIA-SEQUENCE, ensure that it's consistent. If it is not,
|
|
||||||
* the client SHOULD halt playback (6.3.4), which is what we do then.
|
|
||||||
*
|
|
||||||
* If we don't have MEDIA-SEQUENCE, we check URIs in the previous and
|
|
||||||
* current playlist to calculate the/a correct MEDIA-SEQUENCE for the new
|
|
||||||
* playlist in relation to the old. That is, same URIs get the same number
|
|
||||||
* and later URIs get higher numbers */
|
|
||||||
if (have_mediasequence) {
|
|
||||||
GList *l, *m;
|
GList *l, *m;
|
||||||
GstM3U8MediaFile *f1 = NULL, *f2 = NULL;
|
GstM3U8MediaFile *f1 = NULL, *f2 = NULL;
|
||||||
|
|
||||||
|
g_return_val_if_fail (previous_files, FALSE);
|
||||||
|
|
||||||
/* Find first case of higher/equal sequence number in new playlist or
|
/* Find first case of higher/equal sequence number in new playlist or
|
||||||
* same URI. From there on we can linearly step ahead */
|
* same URI. From there on we can linearly step ahead */
|
||||||
for (l = self->files; l; l = l->next) {
|
for (l = self->files; l; l = l->next) {
|
||||||
@ -347,7 +339,8 @@ gst_m3u8_update_check_consistent_media_seqnums (GstM3U8 * self,
|
|||||||
* any in the old, and no URI was found again. This is bad! */
|
* any in the old, and no URI was found again. This is bad! */
|
||||||
GST_ERROR ("Media sequences inconsistent, ignoring");
|
GST_ERROR ("Media sequences inconsistent, ignoring");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
g_assert (f1 != NULL);
|
g_assert (f1 != NULL);
|
||||||
g_assert (f2 != NULL);
|
g_assert (f2 != NULL);
|
||||||
|
|
||||||
@ -380,12 +373,24 @@ gst_m3u8_update_check_consistent_media_seqnums (GstM3U8 * self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* All good if we're getting here */
|
/* All good if we're getting here */
|
||||||
}
|
return TRUE;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
/* If we don't have MEDIA-SEQUENCE, we check URIs in the previous and
|
||||||
|
* current playlist to calculate the/a correct MEDIA-SEQUENCE for the new
|
||||||
|
* playlist in relation to the old. That is, same URIs get the same number
|
||||||
|
* and later URIs get higher numbers */
|
||||||
|
static void
|
||||||
|
generate_media_seqnums (GstM3U8 * self, GList * previous_files)
|
||||||
|
{
|
||||||
GList *l, *m;
|
GList *l, *m;
|
||||||
GstM3U8MediaFile *f1 = NULL, *f2 = NULL;
|
GstM3U8MediaFile *f1 = NULL, *f2 = NULL;
|
||||||
gint64 mediasequence;
|
gint64 mediasequence;
|
||||||
|
|
||||||
|
g_return_if_fail (previous_files);
|
||||||
|
|
||||||
|
/* Find first case of same URI in new playlist.
|
||||||
|
* From there on we can linearly step ahead */
|
||||||
for (l = self->files; l; l = l->next) {
|
for (l = self->files; l; l = l->next) {
|
||||||
gboolean match = FALSE;
|
gboolean match = FALSE;
|
||||||
|
|
||||||
@ -403,12 +408,7 @@ gst_m3u8_update_check_consistent_media_seqnums (GstM3U8 * self,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!l) {
|
if (l) {
|
||||||
/* No match, this means f2 is the last item in the previous playlist
|
|
||||||
* and we have to start our new playlist at that sequence */
|
|
||||||
mediasequence = f2->sequence + 1;
|
|
||||||
l = self->files;
|
|
||||||
} else {
|
|
||||||
/* Match, check that all following ones are matching too and continue
|
/* Match, check that all following ones are matching too and continue
|
||||||
* sequence numbers from there on */
|
* sequence numbers from there on */
|
||||||
|
|
||||||
@ -425,6 +425,11 @@ gst_m3u8_update_check_consistent_media_seqnums (GstM3U8 * self,
|
|||||||
GST_WARNING ("Inconsistent URIs after playlist update");
|
GST_WARNING ("Inconsistent URIs after playlist update");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
/* No match, this means f2 is the last item in the previous playlist
|
||||||
|
* and we have to start our new playlist at that sequence */
|
||||||
|
mediasequence = f2->sequence + 1;
|
||||||
|
l = self->files;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; l; l = l->next) {
|
for (; l; l = l->next) {
|
||||||
@ -433,9 +438,6 @@ gst_m3u8_update_check_consistent_media_seqnums (GstM3U8 * self,
|
|||||||
f1->sequence = mediasequence;
|
f1->sequence = mediasequence;
|
||||||
mediasequence++;
|
mediasequence++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -688,8 +690,13 @@ gst_m3u8_update (GstM3U8 * self, gchar * data)
|
|||||||
self->files = g_list_reverse (self->files);
|
self->files = g_list_reverse (self->files);
|
||||||
|
|
||||||
if (previous_files) {
|
if (previous_files) {
|
||||||
gboolean consistent = gst_m3u8_update_check_consistent_media_seqnums (self,
|
gboolean consistent = TRUE;
|
||||||
have_mediasequence, previous_files);
|
|
||||||
|
if (have_mediasequence) {
|
||||||
|
consistent = check_media_seqnums (self, previous_files);
|
||||||
|
} else {
|
||||||
|
generate_media_seqnums (self, previous_files);
|
||||||
|
}
|
||||||
|
|
||||||
g_list_foreach (previous_files, (GFunc) gst_m3u8_media_file_unref, NULL);
|
g_list_foreach (previous_files, (GFunc) gst_m3u8_media_file_unref, NULL);
|
||||||
g_list_free (previous_files);
|
g_list_free (previous_files);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user