Commit 9d161343 authored by Francois Cartegnie's avatar Francois Cartegnie Committed by Jean-Baptiste Kempf

stream_filter: httplive: use stream size for m3u8

(cherry picked from commit f162660200e8f706a101963745010dccc0e77540)
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent ae609f2b
......@@ -1909,47 +1909,48 @@ end:
/* Read M3U8 file */
static ssize_t read_M3U8_from_stream(stream_t *s, uint8_t **buffer)
{
int64_t total_bytes = 0;
int64_t total_allocated = 0;
uint8_t *p = NULL;
int64_t size = stream_Size(s);
size = VLC_CLIP(size, 0, INT64_MAX - 1);
int64_t i_alloc_size = 0;
ssize_t i_total_read = 0;
unsigned i_chunk_size = HLS_READ_SIZE;
while (1)
for( ;; )
{
char buf[4096];
int64_t bytes;
int i_toread = (size) ? size - i_total_read : i_chunk_size;
if(i_toread + i_total_read > INT64_MAX - 1)
break;
if(i_alloc_size < i_toread)
{
i_alloc_size += i_toread;
p = realloc_or_free(p, 1 + i_alloc_size);
if (p == NULL)
return VLC_ENOMEM;
if (i_chunk_size < (1 << 26))
i_chunk_size <<= 1;
}
bytes = stream_Read(s, buf, sizeof(buf));
if (bytes == 0)
int i_read = stream_Read(s, & p[i_total_read], i_toread);
if (i_read == 0)
{
break; /* EOF ? */
else if (bytes < 0)
}
else if (i_read < 0)
{
free (p);
return bytes;
return i_read;
}
if ( (total_bytes + bytes + 1) > total_allocated )
else
{
if (total_allocated)
total_allocated *= 2;
else
total_allocated = __MIN((uint64_t)bytes+1, sizeof(buf));
p = realloc_or_free(p, total_allocated);
if (p == NULL)
return VLC_ENOMEM;
i_total_read += i_read;
}
memcpy(p+total_bytes, buf, bytes);
total_bytes += bytes;
}
if (total_allocated == 0)
return VLC_EGENERIC;
p[total_bytes] = '\0';
p[i_total_read] = '\0';
*buffer = p;
return total_bytes;
return i_total_read;
}
static ssize_t read_M3U8_from_url(stream_t *s, const char* psz_url, uint8_t **buffer)
......
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