Commit a0297f63 authored by Jean-Paul Saman's avatar Jean-Paul Saman Committed by Jean-Baptiste Kempf

stream_filter/httplive.c: various cleanups

- rename copied to used in hls_Read()
- improve comment in hls_Read()
- add assert() to GetSegment()
- various cleanups
(cherry picked from commit 5b30daa8add8e4563fc26a33e73fa7353f810ac9)
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent a6d6d948
...@@ -2163,6 +2163,7 @@ static segment_t *GetSegment(stream_t *s) ...@@ -2163,6 +2163,7 @@ static segment_t *GetSegment(stream_t *s)
check: check:
/* sanity check */ /* sanity check */
assert(segment->data);
if (segment->data->i_buffer == 0) if (segment->data->i_buffer == 0)
{ {
vlc_mutex_lock(&hls->lock); vlc_mutex_lock(&hls->lock);
...@@ -2179,12 +2180,12 @@ check: ...@@ -2179,12 +2180,12 @@ check:
return segment; return segment;
} }
static int segment_RestorePos( segment_t *segment ) static int segment_RestorePos(segment_t *segment)
{ {
if( segment->data ) if (segment->data)
{ {
uint64_t size = segment->size -segment->data->i_buffer; uint64_t size = segment->size - segment->data->i_buffer;
if( size > 0 ) if (size > 0)
{ {
segment->data->i_buffer += size; segment->data->i_buffer += size;
segment->data->p_buffer -= size; segment->data->p_buffer -= size;
...@@ -2197,7 +2198,7 @@ static int segment_RestorePos( segment_t *segment ) ...@@ -2197,7 +2198,7 @@ static int segment_RestorePos( segment_t *segment )
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;
ssize_t copied = 0; ssize_t used = 0;
do do
{ {
...@@ -2217,7 +2218,7 @@ static ssize_t hls_Read(stream_t *s, uint8_t *p_read, unsigned int i_read) ...@@ -2217,7 +2218,7 @@ static ssize_t hls_Read(stream_t *s, uint8_t *p_read, unsigned int i_read)
segment->data = NULL; segment->data = NULL;
} }
else else
segment_RestorePos( segment ); segment_RestorePos(segment);
p_sys->playback.segment++; p_sys->playback.segment++;
vlc_mutex_unlock(&segment->lock); vlc_mutex_unlock(&segment->lock);
...@@ -2241,18 +2242,18 @@ static ssize_t hls_Read(stream_t *s, uint8_t *p_read, unsigned int i_read) ...@@ -2241,18 +2242,18 @@ static ssize_t hls_Read(stream_t *s, uint8_t *p_read, unsigned int i_read)
if (len > 0) if (len > 0)
{ {
if( p_read ) /* otherwise caller skips data */ if (p_read) /* if NULL, then caller skips data */
memcpy(p_read + copied, segment->data->p_buffer, len); memcpy(p_read + used, segment->data->p_buffer, len);
segment->data->i_buffer -= len; segment->data->i_buffer -= len;
segment->data->p_buffer += len; segment->data->p_buffer += len;
copied += len; used += len;
i_read -= len; i_read -= len;
} }
vlc_mutex_unlock(&segment->lock); vlc_mutex_unlock(&segment->lock);
} while (i_read > 0); } while (i_read > 0);
return copied; return used;
} }
static int Read(stream_t *s, void *buffer, unsigned int i_read) static int Read(stream_t *s, void *buffer, unsigned int i_read)
...@@ -2265,6 +2266,7 @@ static int Read(stream_t *s, void *buffer, unsigned int i_read) ...@@ -2265,6 +2266,7 @@ static int Read(stream_t *s, void *buffer, unsigned int i_read)
if (p_sys->b_error) if (p_sys->b_error)
return 0; return 0;
/* NOTE: buffer might be NULL if caller wants to skip data */
length = hls_Read(s, (uint8_t*) buffer, i_read); length = hls_Read(s, (uint8_t*) buffer, i_read);
if (length < 0) if (length < 0)
return 0; return 0;
...@@ -2428,7 +2430,7 @@ static int segment_Seek(stream_t *s, const uint64_t pos) ...@@ -2428,7 +2430,7 @@ static int segment_Seek(stream_t *s, const uint64_t pos)
return VLC_EGENERIC; return VLC_EGENERIC;
} }
vlc_mutex_lock(&segment->lock); vlc_mutex_lock(&segment->lock);
segment_RestorePos( segment ); segment_RestorePos(segment);
vlc_mutex_unlock(&segment->lock); vlc_mutex_unlock(&segment->lock);
for (int n = 0; n < count; n++) for (int n = 0; n < count; n++)
...@@ -2475,8 +2477,9 @@ static int segment_Seek(stream_t *s, const uint64_t pos) ...@@ -2475,8 +2477,9 @@ 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);
segment_RestorePos( segment ); segment_RestorePos(segment);
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