[1/5] http: Split out the non-chunked buffer reading part from http_read

Message ID 1321014025-81875-1-git-send-email-martin@martin.st
State Committed
Commit bf7723a6407b6dfced80b8e90fcbc52901389274
Headers show

Commit Message

Martin Storsjö Nov. 11, 2011, 12:20 p.m.
---
 libavformat/http.c |   44 +++++++++++++++++++++++++-------------------
 1 files changed, 25 insertions(+), 19 deletions(-)

Comments

Anton Khirnov Nov. 18, 2011, 7:55 a.m. | #1
On Fri, 11 Nov 2011 14:20:21 +0200, Martin Storsjö <martin@martin.st> wrote:
> ---
>  libavformat/http.c |   44 +++++++++++++++++++++++++-------------------
>  1 files changed, 25 insertions(+), 19 deletions(-)
> 

Sorry for the delay, the patchset looks fine to me.

Patch

diff --git a/libavformat/http.c b/libavformat/http.c
index a8a7688..66cfd69 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -412,10 +412,33 @@  static int http_connect(URLContext *h, const char *path, const char *local_path,
 }
 
 
-static int http_read(URLContext *h, uint8_t *buf, int size)
+static int http_buf_read(URLContext *h, uint8_t *buf, int size)
 {
     HTTPContext *s = h->priv_data;
     int len;
+    /* read bytes from input buffer first */
+    len = s->buf_end - s->buf_ptr;
+    if (len > 0) {
+        if (len > size)
+            len = size;
+        memcpy(buf, s->buf_ptr, len);
+        s->buf_ptr += len;
+    } else {
+        if (!s->willclose && s->filesize >= 0 && s->off >= s->filesize)
+            return AVERROR_EOF;
+        len = ffurl_read(s->hd, buf, size);
+    }
+    if (len > 0) {
+        s->off += len;
+        if (s->chunksize > 0)
+            s->chunksize -= len;
+    }
+    return len;
+}
+
+static int http_read(URLContext *h, uint8_t *buf, int size)
+{
+    HTTPContext *s = h->priv_data;
 
     if (s->chunksize >= 0) {
         if (!s->chunksize) {
@@ -438,24 +461,7 @@  static int http_read(URLContext *h, uint8_t *buf, int size)
         }
         size = FFMIN(size, s->chunksize);
     }
-    /* read bytes from input buffer first */
-    len = s->buf_end - s->buf_ptr;
-    if (len > 0) {
-        if (len > size)
-            len = size;
-        memcpy(buf, s->buf_ptr, len);
-        s->buf_ptr += len;
-    } else {
-        if (!s->willclose && s->filesize >= 0 && s->off >= s->filesize)
-            return AVERROR_EOF;
-        len = ffurl_read(s->hd, buf, size);
-    }
-    if (len > 0) {
-        s->off += len;
-        if (s->chunksize > 0)
-            s->chunksize -= len;
-    }
-    return len;
+    return http_buf_read(h, buf, size);
 }
 
 /* used only when posting data */