Commit c407725c authored by Jean-Paul Saman's avatar Jean-Paul Saman

stream_filter/httplive.c: reloading playlist check before download segments

Rearrange hls_Thread logic with live playback in mind. In case all segments have been
downloaded, then make sure that reloading the playlist file happens before downloading
the next segment. This is also true when it is time to reload the playlist.
parent a84de9b1
......@@ -1206,14 +1206,15 @@ static void* hls_Thread(vlc_object_t *p_this)
vlc_mutex_unlock(&hls->lock);
/* Is there a new segment to process? */
if ((p_sys->playback.segment < (count - 6)) ||
if ((!p_sys->b_live && (p_sys->playback.segment < (count - 6))) ||
(client->segment >= count))
{
/* wait */
vlc_mutex_lock(&client->lock_wait);
while (((client->segment - p_sys->playback.segment > 6) ||
(client->segment >= count)) &&
(client->seek == -1))
(client->seek == -1) &&
(mdate() < p_sys->playlist.wakeup))
{
vlc_cond_wait(&client->wait, &client->lock_wait);
if (!vlc_object_alive(p_this)) break;
......@@ -1229,6 +1230,32 @@ static void* hls_Thread(vlc_object_t *p_this)
if (!vlc_object_alive(p_this)) break;
/* reload the m3u8 index file */
if (p_sys->b_live)
{
double wait = 1;
mtime_t now = mdate();
if (now >= p_sys->playlist.wakeup)
{
if (hls_ReloadPlaylist(client->s) != VLC_SUCCESS)
{
/* No change in playlist, then backoff */
p_sys->playlist.tries++;
if (p_sys->playlist.tries == 1) wait = 0.5;
else if (p_sys->playlist.tries == 2) wait = 1;
else if (p_sys->playlist.tries >= 3) wait = 3;
}
else p_sys->playlist.tries = 0;
/* determine next time to update playlist */
p_sys->playlist.last = now;
p_sys->playlist.wakeup = now + ((mtime_t)(hls->duration * wait)
* (mtime_t)1000000);
}
if (!vlc_object_alive(p_this)) break;
}
vlc_mutex_lock(&hls->lock);
segment_t *segment = segment_GetSegment(hls, client->segment);
assert(segment);
......@@ -1236,6 +1263,8 @@ static void* hls_Thread(vlc_object_t *p_this)
if (Download(client->s, hls, segment, &client->current) != VLC_SUCCESS)
{
if (!vlc_object_alive(p_this)) break;
if (!p_sys->b_live)
{
p_sys->b_error = true;
......@@ -1255,30 +1284,6 @@ static void* hls_Thread(vlc_object_t *p_this)
client->segment++;
vlc_cond_signal(&client->wait);
vlc_mutex_unlock(&client->lock_wait);
/* reload the m3u8 index file */
if (p_sys->b_live)
{
double wait = 1;
mtime_t now = mdate();
if (now >= p_sys->playlist.wakeup)
{
if (hls_ReloadPlaylist(client->s) != VLC_SUCCESS)
{
/* No change in playlist, then backoff */
p_sys->playlist.tries++;
if (p_sys->playlist.tries == 1) wait = 0.5;
else if (p_sys->playlist.tries == 2) wait = 1;
else if (p_sys->playlist.tries >= 3) wait = 3;
}
else p_sys->playlist.tries = 0;
/* determine next time to update playlist */
p_sys->playlist.last = now;
p_sys->playlist.wakeup = now + ((mtime_t)(hls->duration * wait)
* (mtime_t)1000000);
}
}
}
vlc_restorecancel(canc);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment