]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/mmsh.c
audiodsp/x86: clear the high bits of the order parameter on 64bit
[ffmpeg] / libavformat / mmsh.c
index ac6b60dc95ef44f868e4c930b264e15aa11b84d3..4029b86371ebb1f3f8923fee668a00748dcc2a0a 100644 (file)
 #include <string.h>
 #include "libavutil/intreadwrite.h"
 #include "libavutil/avstring.h"
-#include "libavformat/internal.h"
+#include "libavutil/opt.h"
+#include "internal.h"
 #include "mms.h"
 #include "asf.h"
 #include "http.h"
+#include "url.h"
 
 #define CHUNK_HEADER_LENGTH 4   // 2bytes chunk type and 2bytes chunk length.
 #define EXT_HEADER_LENGTH   8   // 4bytes sequence, 2bytes useless and 2bytes chunk length.
@@ -39,7 +41,7 @@
 // see Ref 2.2.1.8
 #define USERAGENT  "User-Agent: NSPlayer/4.1.0.3856\r\n"
 // see Ref 2.2.1.4.33
-// the guid value can be changed to any valid value.
+// the GUID value can be changed to any valid value.
 #define CLIENTGUID "Pragma: xClientGUID={c77e7400-738a-11d2-9add-0020af0a3278}\r\n"
 
 // see Ref 2.2.3 for packet type define:
@@ -52,7 +54,7 @@ typedef enum {
     CHUNK_TYPE_STREAM_CHANGE = 0x4324,
 } ChunkType;
 
-typedef struct {
+typedef struct MMSHContext {
     MMSContext mms;
     int request_seq;  ///< request packet sequence
     int chunk_seq;    ///< data packet sequence
@@ -63,10 +65,9 @@ static int mmsh_close(URLContext *h)
     MMSHContext *mmsh = (MMSHContext *)h->priv_data;
     MMSContext *mms   = &mmsh->mms;
     if (mms->mms_hd)
-        url_close(mms->mms_hd);
+        ffurl_close(mms->mms_hd);
     av_free(mms->streams);
     av_free(mms->asf_header);
-    av_freep(&h->priv_data);
     return 0;
 }
 
@@ -78,7 +79,7 @@ static ChunkType get_chunk_header(MMSHContext *mmsh, int *len)
     ChunkType chunk_type;
     int chunk_len, res, ext_header_len;
 
-    res = url_read_complete(mms->mms_hd, chunk_header, CHUNK_HEADER_LENGTH);
+    res = ffurl_read_complete(mms->mms_hd, chunk_header, CHUNK_HEADER_LENGTH);
     if (res != CHUNK_HEADER_LENGTH) {
         av_log(NULL, AV_LOG_ERROR, "Read data packet header failed!\n");
         return AVERROR(EIO);
@@ -100,7 +101,7 @@ static ChunkType get_chunk_header(MMSHContext *mmsh, int *len)
         return AVERROR_INVALIDDATA;
     }
 
-    res = url_read_complete(mms->mms_hd, ext_header, ext_header_len);
+    res = ffurl_read_complete(mms->mms_hd, ext_header, ext_header_len);
     if (res != ext_header_len) {
         av_log(NULL, AV_LOG_ERROR, "Read ext header failed!\n");
         return AVERROR(EIO);
@@ -121,8 +122,8 @@ static int read_data_packet(MMSHContext *mmsh, const int len)
                len, sizeof(mms->in_buffer));
         return AVERROR(EIO);
     }
-    res = url_read_complete(mms->mms_hd, mms->in_buffer, len);
-    av_dlog(NULL, "Data packet len = %d\n", len);
+    res = ffurl_read_complete(mms->mms_hd, mms->in_buffer, len);
+    av_log(NULL, AV_LOG_TRACE, "Data packet len = %d\n", len);
     if (res != len) {
         av_log(NULL, AV_LOG_ERROR, "Read data packet failed!\n");
         return AVERROR(EIO);
@@ -156,7 +157,7 @@ static int get_http_header_data(MMSHContext *mmsh)
                 if (mms->asf_header) {
                     if (len != mms->asf_header_size) {
                         mms->asf_header_size = len;
-                        av_dlog(NULL, "Header len changed from %d to %d\n",
+                        av_log(NULL, AV_LOG_TRACE, "Header len changed from %d to %d\n",
                                 mms->asf_header_size, len);
                         av_freep(&mms->asf_header);
                     }
@@ -173,7 +174,7 @@ static int get_http_header_data(MMSHContext *mmsh)
                        len, mms->asf_header_size);
                 return AVERROR(EIO);
             }
-            res = url_read_complete(mms->mms_hd, mms->asf_header, len);
+            res = ffurl_read_complete(mms->mms_hd, mms->asf_header, len);
             if (res != len) {
                 av_log(NULL, AV_LOG_ERROR,
                        "Recv asf header data len %d != expected len %d\n", res, len);
@@ -196,18 +197,17 @@ static int get_http_header_data(MMSHContext *mmsh)
                            len, sizeof(mms->in_buffer));
                     return AVERROR(EIO);
                 }
-                res = url_read_complete(mms->mms_hd, mms->in_buffer, len);
+                res = ffurl_read_complete(mms->mms_hd, mms->in_buffer, len);
                 if (res != len) {
                     av_log(NULL, AV_LOG_ERROR, "Read other chunk type data failed!\n");
                     return AVERROR(EIO);
                 } else {
-                    av_dlog(NULL, "Skip chunk type %d \n", chunk_type);
+                    av_log(NULL, AV_LOG_TRACE, "Skip chunk type %d \n", chunk_type);
                     continue;
                 }
             }
         }
     }
-    return 0;
 }
 
 static int mmsh_open(URLContext *h, const char *uri, int flags)
@@ -216,12 +216,9 @@ static int mmsh_open(URLContext *h, const char *uri, int flags)
     char httpname[256], path[256], host[128], location[1024];
     char *stream_selection = NULL;
     char headers[1024];
-    MMSHContext *mmsh;
+    MMSHContext *mmsh = h->priv_data;
     MMSContext *mms;
 
-    mmsh = h->priv_data = av_mallocz(sizeof(MMSHContext));
-    if (!h->priv_data)
-        return AVERROR(ENOMEM);
     mmsh->request_seq = h->is_streamed = 1;
     mms = &mmsh->mms;
     av_strlcpy(location, uri, sizeof(location));
@@ -230,9 +227,10 @@ static int mmsh_open(URLContext *h, const char *uri, int flags)
         host, sizeof(host), &port, path, sizeof(path), location);
     if (port<0)
         port = 80; // default mmsh protocol port
-    ff_url_join(httpname, sizeof(httpname), "http", NULL, host, port, path);
+    ff_url_join(httpname, sizeof(httpname), "http", NULL, host, port, "%s", path);
 
-    if (url_alloc(&mms->mms_hd, httpname, URL_RDONLY) < 0) {
+    if (ffurl_alloc(&mms->mms_hd, httpname, AVIO_FLAG_READ,
+                    &h->interrupt_callback, h->protocols) < 0) {
         return AVERROR(EIO);
     }
 
@@ -245,9 +243,9 @@ static int mmsh_open(URLContext *h, const char *uri, int flags)
              CLIENTGUID
              "Connection: Close\r\n\r\n",
              host, port, mmsh->request_seq++);
-    ff_http_set_headers(mms->mms_hd, headers);
+    av_opt_set(mms->mms_hd->priv_data, "headers", headers, 0);
 
-    err = url_connect(mms->mms_hd);
+    err = ffurl_connect(mms->mms_hd, NULL);
     if (err) {
         goto fail;
     }
@@ -258,10 +256,11 @@ static int mmsh_open(URLContext *h, const char *uri, int flags)
     }
 
     // close the socket and then reopen it for sending the second play request.
-    url_close(mms->mms_hd);
+    ffurl_close(mms->mms_hd);
     memset(headers, 0, sizeof(headers));
-    if (url_alloc(&mms->mms_hd, httpname, URL_RDONLY) < 0) {
-        return AVERROR(EIO);
+    if ((err = ffurl_alloc(&mms->mms_hd, httpname, AVIO_FLAG_READ,
+                           &h->interrupt_callback, h->protocols)) < 0) {
+        goto fail;
     }
     stream_selection = av_mallocz(mms->stream_num * 19 + 1);
     if (!stream_selection)
@@ -290,10 +289,10 @@ static int mmsh_open(URLContext *h, const char *uri, int flags)
         av_log(NULL, AV_LOG_ERROR, "Build play request failed!\n");
         goto fail;
     }
-    av_dlog(NULL, "out_buffer is %s", headers);
-    ff_http_set_headers(mms->mms_hd, headers);
+    av_log(NULL, AV_LOG_TRACE, "out_buffer is %s", headers);
+    av_opt_set(mms->mms_hd->priv_data, "headers", headers, 0);
 
-    err = url_connect(mms->mms_hd);
+    err = ffurl_connect(mms->mms_hd, NULL);
     if (err) {
           goto fail;
     }
@@ -304,12 +303,12 @@ static int mmsh_open(URLContext *h, const char *uri, int flags)
         goto fail;
     }
 
-    av_dlog(NULL, "Connection successfully open\n");
+    av_log(NULL, AV_LOG_TRACE, "Connection successfully open\n");
     return 0;
 fail:
     av_freep(&stream_selection);
     mmsh_close(h);
-    av_dlog(NULL, "Connection failed with error %d\n", err);
+    av_log(NULL, AV_LOG_TRACE, "Connection failed with error %d\n", err);
     return err;
 }
 
@@ -359,11 +358,11 @@ static int mmsh_read(URLContext *h, uint8_t *buf, int size)
     return res;
 }
 
-URLProtocol ff_mmsh_protocol = {
-    .name      = "mmsh",
-    .url_open  = mmsh_open,
-    .url_read  = mmsh_read,
-    .url_write = NULL,
-    .url_seek  = NULL,
-    .url_close = mmsh_close,
+const URLProtocol ff_mmsh_protocol = {
+    .name           = "mmsh",
+    .url_open       = mmsh_open,
+    .url_read       = mmsh_read,
+    .url_close      = mmsh_close,
+    .priv_data_size = sizeof(MMSHContext),
+    .flags          = URL_PROTOCOL_FLAG_NETWORK,
 };