mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2026-04-18 08:30:24 +00:00
avformat/http: parse range size from Content-Range header
In the event that the range returned is smaller than the true filesize, we should only expect to receive that many bytes - not the entire rest of the file. This commit is theoretically non-functional on its own, since any conforming HTTP server will always return us the full file range, but I wanted to split it off from the subsequent changes in order to make review easier.
This commit is contained in:
parent
19cae9151c
commit
ca2c5ff412
1 changed files with 7 additions and 4 deletions
|
|
@ -78,7 +78,7 @@ typedef struct HTTPContext {
|
|||
/* Used if "Transfer-Encoding: chunked" otherwise -1. */
|
||||
uint64_t chunksize;
|
||||
int chunkend;
|
||||
uint64_t off, end_off, filesize;
|
||||
uint64_t off, end_off, filesize, range_end;
|
||||
char *uri;
|
||||
char *location;
|
||||
HTTPAuthState auth_state;
|
||||
|
|
@ -892,11 +892,13 @@ static int parse_location(HTTPContext *s, const char *p)
|
|||
static void parse_content_range(URLContext *h, const char *p)
|
||||
{
|
||||
HTTPContext *s = h->priv_data;
|
||||
const char *slash;
|
||||
const char *slash, *end;
|
||||
|
||||
if (!strncmp(p, "bytes ", 6)) {
|
||||
p += 6;
|
||||
s->off = strtoull(p, NULL, 10);
|
||||
if ((end = strchr(p, '-')) && strlen(end) > 0)
|
||||
s->range_end = strtoull(end + 1, NULL, 10) + 1;
|
||||
if ((slash = strchr(p, '/')) && strlen(slash) > 0)
|
||||
s->filesize_from_content_range = strtoull(slash + 1, NULL, 10);
|
||||
}
|
||||
|
|
@ -1702,8 +1704,9 @@ static int http_buf_read(URLContext *h, uint8_t *buf, int size)
|
|||
memcpy(buf, s->buf_ptr, len);
|
||||
s->buf_ptr += len;
|
||||
} else {
|
||||
uint64_t target_end = s->end_off ? s->end_off : s->filesize;
|
||||
if ((!s->willclose || s->chunksize == UINT64_MAX) && s->off >= target_end)
|
||||
uint64_t file_end = s->end_off ? s->end_off : s->filesize;
|
||||
uint64_t target_end = s->range_end ? s->range_end : file_end;
|
||||
if ((!s->willclose || s->chunksize == UINT64_MAX) && s->off >= file_end)
|
||||
return AVERROR_EOF;
|
||||
len = ffurl_read(s->hd, buf, size);
|
||||
if ((!len || len == AVERROR_EOF) &&
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue