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:
Jan Alexander Steffens (heftig) 2017-09-15 08:57:03 +02:00 committed by Sebastian Dröge
parent 234a8ecc50
commit f80ad048e6

View file

@ -306,24 +306,16 @@ gst_hls_variant_stream_compare_by_bitrate (gconstpointer a, gconstpointer b)
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
gst_m3u8_update_check_consistent_media_seqnums (GstM3U8 * self,
gboolean have_mediasequence, GList * previous_files)
check_media_seqnums (GstM3U8 * self, 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;
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
* same URI. From there on we can linearly step ahead */
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! */
GST_ERROR ("Media sequences inconsistent, ignoring");
return FALSE;
} else {
}
g_assert (f1 != 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 */
}
} else {
return TRUE;
}
/* 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;
GstM3U8MediaFile *f1 = NULL, *f2 = NULL;
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) {
gboolean match = FALSE;
@ -403,12 +408,7 @@ gst_m3u8_update_check_consistent_media_seqnums (GstM3U8 * self,
break;
}
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 {
if (l) {
/* Match, check that all following ones are matching too and continue
* 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");
}
}
} 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) {
@ -433,9 +438,6 @@ gst_m3u8_update_check_consistent_media_seqnums (GstM3U8 * self,
f1->sequence = mediasequence;
mediasequence++;
}
}
return TRUE;
}
/*
@ -688,8 +690,13 @@ gst_m3u8_update (GstM3U8 * self, gchar * data)
self->files = g_list_reverse (self->files);
if (previous_files) {
gboolean consistent = gst_m3u8_update_check_consistent_media_seqnums (self,
have_mediasequence, previous_files);
gboolean consistent = TRUE;
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_free (previous_files);