Commit 2fd6ea3a authored by Frédéric Yhuel's avatar Frédéric Yhuel Committed by Jean-Baptiste Kempf

HLS restore pos of current segment before seeking

This prevents a "bug" when we seek backward and then play again that
segment.
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
(cherry picked from commit 982071198e54af320b684ac4bd319cc88caceb27)
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 25775825
...@@ -2196,6 +2196,20 @@ check: ...@@ -2196,6 +2196,20 @@ check:
return segment; return segment;
} }
static int segment_RestorePos( segment_t *segment )
{
if( segment->data )
{
uint64_t size = segment->size -segment->data->i_buffer;
if( size > 0 )
{
segment->data->i_buffer += size;
segment->data->p_buffer -= size;
}
}
return VLC_SUCCESS;
}
static ssize_t hls_Read(stream_t *s, uint8_t *p_read, unsigned int i_read) static ssize_t hls_Read(stream_t *s, uint8_t *p_read, unsigned int i_read)
{ {
stream_sys_t *p_sys = s->p_sys; stream_sys_t *p_sys = s->p_sys;
...@@ -2219,14 +2233,8 @@ static ssize_t hls_Read(stream_t *s, uint8_t *p_read, unsigned int i_read) ...@@ -2219,14 +2233,8 @@ static ssize_t hls_Read(stream_t *s, uint8_t *p_read, unsigned int i_read)
segment->data = NULL; segment->data = NULL;
} }
else else
{ /* reset playback pointer to start of buffer */ segment_RestorePos( segment );
uint64_t size = segment->size - segment->data->i_buffer;
if (size > 0)
{
segment->data->i_buffer += size;
segment->data->p_buffer -= size;
}
}
p_sys->playback.segment++; p_sys->playback.segment++;
vlc_mutex_unlock(&segment->lock); vlc_mutex_unlock(&segment->lock);
...@@ -2421,6 +2429,7 @@ static uint64_t GetStreamSize(stream_t *s) ...@@ -2421,6 +2429,7 @@ static uint64_t GetStreamSize(stream_t *s)
return size; return size;
} }
static int segment_Seek(stream_t *s, const uint64_t pos) static int segment_Seek(stream_t *s, const uint64_t pos)
{ {
stream_sys_t *p_sys = s->p_sys; stream_sys_t *p_sys = s->p_sys;
...@@ -2436,6 +2445,17 @@ static int segment_Seek(stream_t *s, const uint64_t pos) ...@@ -2436,6 +2445,17 @@ static int segment_Seek(stream_t *s, const uint64_t pos)
uint64_t size = hls->size; uint64_t size = hls->size;
int count = vlc_array_count(hls->segments); int count = vlc_array_count(hls->segments);
/* restore current segment to start position */
segment_t *segment = segment_GetSegment(hls, p_sys->playback.segment);
if (segment == NULL)
{
vlc_mutex_unlock(&hls->lock);
return VLC_EGENERIC;
}
vlc_mutex_lock(&segment->lock);
segment_RestorePos( segment );
vlc_mutex_unlock(&segment->lock);
for (int n = 0; n < count; n++) for (int n = 0; n < count; n++)
{ {
segment_t *segment = vlc_array_item_at_index(hls->segments, n); segment_t *segment = vlc_array_item_at_index(hls->segments, n);
...@@ -2480,17 +2500,8 @@ static int segment_Seek(stream_t *s, const uint64_t pos) ...@@ -2480,17 +2500,8 @@ static int segment_Seek(stream_t *s, const uint64_t pos)
vlc_mutex_unlock(&hls->lock); vlc_mutex_unlock(&hls->lock);
return VLC_EGENERIC; return VLC_EGENERIC;
} }
vlc_mutex_lock(&segment->lock); vlc_mutex_lock(&segment->lock);
if (segment->data) segment_RestorePos( segment );
{
uint64_t size = segment->size -segment->data->i_buffer;
if (size > 0)
{
segment->data->i_buffer += size;
segment->data->p_buffer -= size;
}
}
vlc_mutex_unlock(&segment->lock); vlc_mutex_unlock(&segment->lock);
/* start download at current playback segment */ /* start download at current playback segment */
......
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