[FFmpeg-devel] [PATCH 2/4] HTTP: use URLContext.slave

Nicolas George nicolas.george
Fri Feb 18 18:59:21 CET 2011


Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
 libavformat/http.c |   50 +++++++++++++++++++++-----------------------------
 1 files changed, 21 insertions(+), 29 deletions(-)

diff --git a/libavformat/http.c b/libavformat/http.c
index b3499d1..6337b85 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -39,7 +39,6 @@
 
 typedef struct {
     const AVClass *class;
-    URLContext *hd;
     unsigned char buffer[BUFFER_SIZE], *buf_ptr, *buf_end;
     int line_count;
     int http_code;
@@ -127,7 +126,7 @@ static int http_open_cnx(URLContext *h)
     if (err < 0)
         goto fail;
 
-    s->hd = hd;
+    h->slave = hd;
     cur_auth_type = s->auth_state.auth_type;
     if (http_connect(h, path, hoststr, auth, &location_changed) < 0)
         goto fail;
@@ -151,7 +150,7 @@ static int http_open_cnx(URLContext *h)
  fail:
     if (hd)
         url_close(hd);
-    s->hd = NULL;
+    h->slave = NULL;
     return AVERROR(EIO);
 }
 
@@ -166,11 +165,12 @@ static int http_open(URLContext *h, const char *uri, int flags)
 
     return http_open_cnx(h);
 }
-static int http_getc(HTTPContext *s)
+static int http_getc(URLContext *h)
 {
+    HTTPContext *s = h->priv_data;
     int len;
     if (s->buf_ptr >= s->buf_end) {
-        len = url_read(s->hd, s->buffer, BUFFER_SIZE);
+        len = url_read(h->slave, s->buffer, BUFFER_SIZE);
         if (len < 0) {
             return AVERROR(EIO);
         } else if (len == 0) {
@@ -183,14 +183,14 @@ static int http_getc(HTTPContext *s)
     return *s->buf_ptr++;
 }
 
-static int http_get_line(HTTPContext *s, char *line, int line_size)
+static int http_get_line(URLContext *h, char *line, int line_size)
 {
     int ch;
     char *q;
 
     q = line;
     for(;;) {
-        ch = http_getc(s);
+        ch = http_getc(h);
         if (ch < 0)
             return AVERROR(EIO);
         if (ch == '\n') {
@@ -332,7 +332,7 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr,
              authstr ? authstr : "");
 
     av_freep(&authstr);
-    if (url_write(s->hd, s->buffer, strlen(s->buffer)) < 0)
+    if (url_write(h->slave, s->buffer, strlen(s->buffer)) < 0)
         return AVERROR(EIO);
 
     /* init input buffer */
@@ -353,7 +353,7 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr,
 
     /* wait for header */
     for(;;) {
-        if (http_get_line(s, line, sizeof(line)) < 0)
+        if (http_get_line(h, line, sizeof(line)) < 0)
             return AVERROR(EIO);
 
         av_dlog(NULL, "header='%s'\n", line);
@@ -381,7 +381,7 @@ static int http_read(URLContext *h, uint8_t *buf, int size)
 
             for(;;) {
                 do {
-                    if (http_get_line(s, line, sizeof(line)) < 0)
+                    if (http_get_line(h, line, sizeof(line)) < 0)
                         return AVERROR(EIO);
                 } while (!*line);    /* skip CR LF from last chunk */
 
@@ -406,7 +406,7 @@ static int http_read(URLContext *h, uint8_t *buf, int size)
     } else {
         if (!s->willclose && s->filesize >= 0 && s->off >= s->filesize)
             return AVERROR_EOF;
-        len = url_read(s->hd, buf, size);
+        len = url_read(h->slave, buf, size);
     }
     if (len > 0) {
         s->off += len;
@@ -426,7 +426,7 @@ static int http_write(URLContext *h, const uint8_t *buf, int size)
 
     if (s->chunksize == -1) {
         /* non-chunked data is sent without any special encoding */
-        return url_write(s->hd, buf, size);
+        return url_write(h->slave, buf, size);
     }
 
     /* silently ignore zero-size data since chunk encoding that would
@@ -435,9 +435,9 @@ static int http_write(URLContext *h, const uint8_t *buf, int size)
         /* upload data using chunked encoding */
         snprintf(temp, sizeof(temp), "%x\r\n", size);
 
-        if ((ret = url_write(s->hd, temp, strlen(temp))) < 0 ||
-            (ret = url_write(s->hd, buf, size)) < 0 ||
-            (ret = url_write(s->hd, crlf, sizeof(crlf) - 1)) < 0)
+        if ((ret = url_write(h->slave, temp, strlen(temp))) < 0 ||
+            (ret = url_write(h->slave, buf, size)) < 0 ||
+            (ret = url_write(h->slave, crlf, sizeof(crlf) - 1)) < 0)
             return ret;
     }
     return size;
@@ -451,19 +451,19 @@ static int http_close(URLContext *h)
 
     /* signal end of chunked encoding if used */
     if ((h->flags & URL_WRONLY) && s->chunksize != -1) {
-        ret = url_write(s->hd, footer, sizeof(footer) - 1);
+        ret = url_write(h->slave, footer, sizeof(footer) - 1);
         ret = ret > 0 ? 0 : ret;
     }
 
-    if (s->hd)
-        url_close(s->hd);
+    if (h->slave)
+        url_close(h->slave);
     return ret;
 }
 
 static int64_t http_seek(URLContext *h, int64_t off, int whence)
 {
     HTTPContext *s = h->priv_data;
-    URLContext *old_hd = s->hd;
+    URLContext *old_hd = h->slave;
     int64_t old_off = s->off;
     uint8_t old_buf[BUFFER_SIZE];
     int old_buf_size;
@@ -476,7 +476,7 @@ static int64_t http_seek(URLContext *h, int64_t off, int whence)
     /* we save the old context in case the seek fails */
     old_buf_size = s->buf_end - s->buf_ptr;
     memcpy(old_buf, s->buf_ptr, old_buf_size);
-    s->hd = NULL;
+    h->slave = NULL;
     if (whence == SEEK_CUR)
         off += s->off;
     else if (whence == SEEK_END)
@@ -488,7 +488,7 @@ static int64_t http_seek(URLContext *h, int64_t off, int whence)
         memcpy(s->buffer, old_buf, old_buf_size);
         s->buf_ptr = s->buffer;
         s->buf_end = s->buffer + old_buf_size;
-        s->hd = old_hd;
+        h->slave = old_hd;
         s->off = old_off;
         return -1;
     }
@@ -496,13 +496,6 @@ static int64_t http_seek(URLContext *h, int64_t off, int whence)
     return off;
 }
 
-static int
-http_get_file_handle(URLContext *h)
-{
-    HTTPContext *s = h->priv_data;
-    return url_get_file_handle(s->hd);
-}
-
 URLProtocol ff_http_protocol = {
     "http",
     http_open,
@@ -510,7 +503,6 @@ URLProtocol ff_http_protocol = {
     http_write,
     http_seek,
     http_close,
-    .url_get_file_handle = http_get_file_handle,
     .priv_data_size = sizeof(HTTPContext),
     .priv_data_class = &httpcontext_class,
 };
-- 
1.7.2.3




More information about the ffmpeg-devel mailing list