Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FFmpeg/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonald S. Bultje <rsbultje@gmail.com>2016-12-05 18:18:10 +0300
committerRonald S. Bultje <rsbultje@gmail.com>2016-12-06 00:20:06 +0300
commitce44100cb02a5576b0d389fa486a84cfc21af386 (patch)
treec0d2c386b2d2b7872175390b6846d16a7ef9be0b
parent18e3e322b36a85b6f69662e1d5fa7c245638ab86 (diff)
http: move chunk handling from http_read_stream() to http_buf_read().
(cherry picked from commit 845bb401781ef04e342bd558df16a8dbf5f800f9)
-rw-r--r--libavformat/http.c57
1 files changed, 31 insertions, 26 deletions
diff --git a/libavformat/http.c b/libavformat/http.c
index 2185dd0e57..7e109ddb5b 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -1153,6 +1153,34 @@ static int http_buf_read(URLContext *h, uint8_t *buf, int size)
{
HTTPContext *s = h->priv_data;
int len;
+
+ if (s->chunksize != UINT64_MAX) {
+ if (!s->chunksize) {
+ char line[32];
+ int err;
+
+ do {
+ if ((err = http_get_line(s, line, sizeof(line))) < 0)
+ return err;
+ } while (!*line); /* skip CR LF from last chunk */
+
+ s->chunksize = strtoull(line, NULL, 16);
+
+ av_log(h, AV_LOG_TRACE,
+ "Chunked encoding data size: %"PRIu64"'\n",
+ s->chunksize);
+
+ if (!s->chunksize)
+ return 0;
+ else if (s->chunksize == UINT64_MAX) {
+ av_log(h, AV_LOG_ERROR, "Invalid chunk size %"PRIu64"\n",
+ s->chunksize);
+ return AVERROR(EINVAL);
+ }
+ }
+ size = FFMIN(size, s->chunksize);
+ }
+
/* read bytes from input buffer first */
len = s->buf_end - s->buf_ptr;
if (len > 0) {
@@ -1175,8 +1203,10 @@ static int http_buf_read(URLContext *h, uint8_t *buf, int size)
}
if (len > 0) {
s->off += len;
- if (s->chunksize > 0)
+ if (s->chunksize > 0) {
+ av_assert0(s->chunksize >= len);
s->chunksize -= len;
+ }
}
return len;
}
@@ -1231,31 +1261,6 @@ static int http_read_stream(URLContext *h, uint8_t *buf, int size)
return err;
}
- if (s->chunksize != UINT64_MAX) {
- if (!s->chunksize) {
- char line[32];
-
- do {
- if ((err = http_get_line(s, line, sizeof(line))) < 0)
- return err;
- } while (!*line); /* skip CR LF from last chunk */
-
- s->chunksize = strtoull(line, NULL, 16);
-
- av_log(h, AV_LOG_TRACE,
- "Chunked encoding data size: %"PRIu64"'\n",
- s->chunksize);
-
- if (!s->chunksize)
- return 0;
- else if (s->chunksize == UINT64_MAX) {
- av_log(h, AV_LOG_ERROR, "Invalid chunk size %"PRIu64"\n",
- s->chunksize);
- return AVERROR(EINVAL);
- }
- }
- size = FFMIN(size, s->chunksize);
- }
#if CONFIG_ZLIB
if (s->compressed)
return http_buf_read_compressed(h, buf, size);