]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/http.c
riff: add "GXVE" FourCC for WMV2
[ffmpeg] / libavformat / http.c
index cf4ccab7e0b935a5ba313eb317da5a49d84bb87e..948930a053d765cf462a39d265ff7df06d93f8ae 100644 (file)
@@ -58,6 +58,7 @@ typedef struct {
     char *headers;
     char *mime_type;
     char *user_agent;
+    char *content_type;
     /* Set if the server correctly handles Connection: close and will close
      * the connection after feeding us the content. */
     int willclose;
@@ -92,11 +93,12 @@ typedef struct {
 #define DEFAULT_USER_AGENT "Lavf/" AV_STRINGIFY(LIBAVFORMAT_VERSION)
 static const AVOption options[] = {
 {"chunked_post", "use chunked transfer-encoding for posts", OFFSET(chunked_post), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, E },
-{"headers", "custom HTTP headers, can override built in default headers", OFFSET(headers), AV_OPT_TYPE_STRING, { 0 }, 0, 0, D|E },
+{"headers", "set custom HTTP headers, can override built in default headers", OFFSET(headers), AV_OPT_TYPE_STRING, { 0 }, 0, 0, D|E },
+{"content_type", "set a specific content type for the POST messages", OFFSET(content_type), AV_OPT_TYPE_STRING, { 0 }, 0, 0, D|E },
 {"user_agent", "override User-Agent header", OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = DEFAULT_USER_AGENT}, 0, 0, D },
 {"user-agent", "override User-Agent header, for compatibility with ffmpeg", OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = DEFAULT_USER_AGENT}, 0, 0, D },
 {"multiple_requests", "use persistent connections", OFFSET(multiple_requests), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, D|E },
-{"post_data", "custom HTTP post data", OFFSET(post_data), AV_OPT_TYPE_BINARY, .flags = D|E },
+{"post_data", "set custom HTTP post data", OFFSET(post_data), AV_OPT_TYPE_BINARY, .flags = D|E },
 {"mime_type", "export the MIME type", OFFSET(mime_type), AV_OPT_TYPE_STRING, {0}, 0, 0, AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY  },
 {"icy", "request ICY metadata", OFFSET(icy), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, D },
 {"icy_metadata_headers", "return ICY metadata headers", OFFSET(icy_metadata_headers), AV_OPT_TYPE_STRING, {0}, 0, 0, AV_OPT_FLAG_EXPORT },
@@ -351,7 +353,7 @@ static int parse_location(HTTPContext *s, const char *p)
 }
 
 /* "bytes $from-$to/$document_size" */
-static void parse_content_range(URLContext *h, char *p)
+static void parse_content_range(URLContext *h, const char *p)
 {
     HTTPContext *s = h->priv_data;
     const char *slash;
@@ -365,7 +367,7 @@ static void parse_content_range(URLContext *h, char *p)
     h->is_streamed = 0; /* we _can_ in fact seek */
 }
 
-static int parse_content_encoding(URLContext *h, char *p)
+static int parse_content_encoding(URLContext *h, const char *p)
 {
     HTTPContext *s = h->priv_data;
 
@@ -403,6 +405,7 @@ static int parse_content_encoding(URLContext *h, char *p)
 static int parse_icy(HTTPContext *s, const char *tag, const char *p)
 {
     int len = 4 + strlen(p) + strlen(tag);
+    int is_first = !s->icy_metadata_headers;
     int ret;
 
     if (s->icy_metadata_headers)
@@ -411,6 +414,9 @@ static int parse_icy(HTTPContext *s, const char *tag, const char *p)
     if ((ret = av_reallocp(&s->icy_metadata_headers, len)) < 0)
         return ret;
 
+    if (is_first)
+        *s->icy_metadata_headers = '\0';
+
     av_strlcatf(s->icy_metadata_headers, len, "%s: %s\n", tag, p);
 
     return 0;
@@ -605,6 +611,10 @@ static int http_connect(URLContext *h, const char *path, const char *local_path,
     if (!has_header(s->headers, "\r\nContent-Length: ") && s->post_data)
         len += av_strlcatf(headers + len, sizeof(headers) - len,
                            "Content-Length: %d\r\n", s->post_datalen);
+
+    if (!has_header(s->headers, "\r\nContent-Type: ") && s->content_type)
+        len += av_strlcatf(headers + len, sizeof(headers) - len,
+                           "Content-Type: %s\r\n", s->content_type);
     if (!has_header(s->headers, "\r\nIcy-MetaData: ") && s->icy) {
         len += av_strlcatf(headers + len, sizeof(headers) - len,
                            "Icy-MetaData: %d\r\n", 1);