mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-22 00:06:36 +00:00
hlsdemux: cache total duration to avoid iterating at every query
Duration queries can be done a few times per second and would cause the segment list to be traversed for every one. Caching the duration prevents that.
This commit is contained in:
parent
4531a341a8
commit
e21abb62e0
2 changed files with 14 additions and 3 deletions
|
@ -424,6 +424,7 @@ gst_m3u8_update (GstM3U8Client * client, GstM3U8 * self, gchar * data,
|
|||
g_list_free (self->files);
|
||||
self->files = NULL;
|
||||
}
|
||||
client->duration = GST_CLOCK_TIME_NONE;
|
||||
|
||||
/* By default, allow caching */
|
||||
self->allowcache = TRUE;
|
||||
|
@ -760,6 +761,7 @@ gst_m3u8_update (GstM3U8Client * client, GstM3U8 * self, gchar * data,
|
|||
GST_TIME_FORMAT, GST_TIME_ARGS (client->first_file_start),
|
||||
GST_TIME_ARGS (client->last_file_end));
|
||||
}
|
||||
client->duration = duration;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
@ -779,6 +781,7 @@ gst_m3u8_client_new (const gchar * uri, const gchar * base_uri)
|
|||
client->sequence_position = 0;
|
||||
client->update_failed_count = 0;
|
||||
client->highest_sequence_number = -1;
|
||||
client->duration = GST_CLOCK_TIME_NONE;
|
||||
g_mutex_init (&client->lock);
|
||||
gst_m3u8_set_uri (client->main, g_strdup (uri), g_strdup (base_uri), NULL);
|
||||
|
||||
|
@ -804,6 +807,7 @@ gst_m3u8_client_set_current (GstM3U8Client * self, GstM3U8 * m3u8)
|
|||
if (m3u8 != self->current) {
|
||||
self->current = m3u8;
|
||||
self->update_failed_count = 0;
|
||||
self->duration = GST_CLOCK_TIME_NONE;
|
||||
}
|
||||
GST_M3U8_CLIENT_UNLOCK (self);
|
||||
}
|
||||
|
@ -1104,7 +1108,7 @@ _sum_duration (GstM3U8MediaFile * self, GstClockTime * duration)
|
|||
GstClockTime
|
||||
gst_m3u8_client_get_duration (GstM3U8Client * client)
|
||||
{
|
||||
GstClockTime duration = 0;
|
||||
GstClockTime duration = GST_CLOCK_TIME_NONE;
|
||||
|
||||
g_return_val_if_fail (client != NULL, GST_CLOCK_TIME_NONE);
|
||||
|
||||
|
@ -1114,9 +1118,15 @@ gst_m3u8_client_get_duration (GstM3U8Client * client)
|
|||
GST_M3U8_CLIENT_UNLOCK (client);
|
||||
return GST_CLOCK_TIME_NONE;
|
||||
}
|
||||
if (client->current->files)
|
||||
g_list_foreach (client->current->files, (GFunc) _sum_duration, &duration);
|
||||
|
||||
if (!GST_CLOCK_TIME_IS_VALID (client->duration) && client->current->files) {
|
||||
client->duration = 0;
|
||||
g_list_foreach (client->current->files, (GFunc) _sum_duration,
|
||||
&client->duration);
|
||||
}
|
||||
duration = client->duration;
|
||||
GST_M3U8_CLIENT_UNLOCK (client);
|
||||
|
||||
return duration;
|
||||
}
|
||||
|
||||
|
|
|
@ -94,6 +94,7 @@ struct _GstM3U8Client
|
|||
gint64 highest_sequence_number; /* largest seen sequence number */
|
||||
GstClockTime first_file_start; /* timecode of the start of the first fragment in the current media playlist */
|
||||
GstClockTime last_file_end; /* timecode of the end of the last fragment in the current media playlist */
|
||||
GstClockTime duration; /* cached total duration */
|
||||
GMutex lock;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue