mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-02 20:42:30 +00:00
hls/m3u8: Update current position in all cases
In order to ensure the sequence_position will always be consistently updated, store the current file duration. This way, when we advance, we can always increment the position based on what was previously outputted. https://bugzilla.gnome.org/show_bug.cgi?id=752132
This commit is contained in:
parent
e0ffcd30e8
commit
f7c4bb5ac6
2 changed files with 25 additions and 15 deletions
|
@ -766,6 +766,7 @@ gst_m3u8_client_new (const gchar * uri, const gchar * base_uri)
|
|||
client->main = gst_m3u8_new ();
|
||||
client->current = NULL;
|
||||
client->current_file = NULL;
|
||||
client->current_file_duration = GST_CLOCK_TIME_NONE;
|
||||
client->sequence = -1;
|
||||
client->sequence_position = 0;
|
||||
client->update_failed_count = 0;
|
||||
|
@ -1023,6 +1024,7 @@ gst_m3u8_client_get_next_fragment (GstM3U8Client * client,
|
|||
GST_DEBUG ("Got fragment with sequence %u (client sequence %u)",
|
||||
(guint) file->sequence, (guint) client->sequence);
|
||||
|
||||
client->current_file_duration = file->duration;
|
||||
if (timestamp)
|
||||
*timestamp = client->sequence_position;
|
||||
|
||||
|
@ -1095,14 +1097,8 @@ alternate_advance (GstM3U8Client * client, gboolean forward)
|
|||
}
|
||||
client->current_file = tmp;
|
||||
client->sequence = targetnum;
|
||||
if (forward)
|
||||
client->sequence_position += mf->duration;
|
||||
else {
|
||||
if (client->sequence_position > mf->duration)
|
||||
client->sequence_position -= mf->duration;
|
||||
else
|
||||
client->sequence_position = 0;
|
||||
}
|
||||
client->current_file_duration =
|
||||
GST_M3U8_MEDIA_FILE (client->current_file->data)->duration;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1114,6 +1110,20 @@ gst_m3u8_client_advance_fragment (GstM3U8Client * client, gboolean forward)
|
|||
g_return_if_fail (client->current != NULL);
|
||||
|
||||
GST_M3U8_CLIENT_LOCK (client);
|
||||
GST_DEBUG ("Sequence position was %" GST_TIME_FORMAT,
|
||||
GST_TIME_ARGS (client->sequence_position));
|
||||
if (GST_CLOCK_TIME_IS_VALID (client->current_file_duration)) {
|
||||
/* Advance our position based on the previous fragment we played */
|
||||
if (forward)
|
||||
client->sequence_position += client->current_file_duration;
|
||||
else if (client->current_file_duration < client->sequence_position)
|
||||
client->sequence_position -= client->current_file_duration;
|
||||
else
|
||||
client->sequence_position = 0;
|
||||
client->current_file_duration = GST_CLOCK_TIME_NONE;
|
||||
GST_DEBUG ("Sequence position now %" GST_TIME_FORMAT,
|
||||
GST_TIME_ARGS (client->sequence_position));
|
||||
}
|
||||
if (!client->current_file) {
|
||||
GList *l;
|
||||
|
||||
|
@ -1140,8 +1150,6 @@ gst_m3u8_client_advance_fragment (GstM3U8Client * client, gboolean forward)
|
|||
} else {
|
||||
client->sequence = file->sequence + 1;
|
||||
}
|
||||
|
||||
client->sequence_position += file->duration;
|
||||
} else {
|
||||
client->current_file = client->current_file->prev;
|
||||
if (client->current_file) {
|
||||
|
@ -1150,11 +1158,12 @@ gst_m3u8_client_advance_fragment (GstM3U8Client * client, gboolean forward)
|
|||
} else {
|
||||
client->sequence = file->sequence - 1;
|
||||
}
|
||||
|
||||
if (client->sequence_position > file->duration)
|
||||
client->sequence_position -= file->duration;
|
||||
else
|
||||
client->sequence_position = 0;
|
||||
}
|
||||
if (client->current_file) {
|
||||
/* Store duration of the fragment we're using to update the position
|
||||
* the next time we advance */
|
||||
client->current_file_duration =
|
||||
GST_M3U8_MEDIA_FILE (client->current_file->data)->duration;
|
||||
}
|
||||
GST_M3U8_CLIENT_UNLOCK (client);
|
||||
}
|
||||
|
|
|
@ -96,6 +96,7 @@ struct _GstM3U8Client
|
|||
GstM3U8 *current;
|
||||
guint update_failed_count;
|
||||
GList *current_file;
|
||||
GstClockTime current_file_duration; /* Duration of current fragment */
|
||||
gint64 sequence; /* the next sequence for this client */
|
||||
GstClockTime sequence_position; /* position of this sequence */
|
||||
gint64 highest_sequence_number; /* largest seen sequence number */
|
||||
|
|
Loading…
Reference in a new issue