]> git.sesse.net Git - ffmpeg/commitdiff
avio: Add an AVIOInterruptCB parameter to ffurl_open/ffurl_alloc
authorMartin Storsjö <martin@martin.st>
Sun, 6 Nov 2011 20:50:44 +0000 (22:50 +0200)
committerAnton Khirnov <anton@khirnov.net>
Sun, 13 Nov 2011 12:12:17 +0000 (13:12 +0100)
Change all uses of these function to pass the relevant
callback on.

18 files changed:
libavformat/applehttp.c
libavformat/applehttpproto.c
libavformat/avio.c
libavformat/aviobuf.c
libavformat/concat.c
libavformat/crypto.c
libavformat/gopher.c
libavformat/http.c
libavformat/md5proto.c
libavformat/mmsh.c
libavformat/mmst.c
libavformat/rtmpproto.c
libavformat/rtpproto.c
libavformat/rtsp.c
libavformat/sapdec.c
libavformat/sapenc.c
libavformat/tls.c
libavformat/url.h

index 06884a07c6153c7a59fa205229d506c1a92baf82..ae251531e8375181c590ca7ec29b365ba2a205d0 100644 (file)
@@ -323,13 +323,15 @@ static int open_input(struct variant *var)
 {
     struct segment *seg = var->segments[var->cur_seq_no - var->start_seq_no];
     if (seg->key_type == KEY_NONE) {
-        return ffurl_open(&var->input, seg->url, AVIO_FLAG_READ);
+        return ffurl_open(&var->input, seg->url, AVIO_FLAG_READ,
+                          &var->parent->interrupt_callback);
     } else if (seg->key_type == KEY_AES_128) {
         char iv[33], key[33], url[MAX_URL_SIZE];
         int ret;
         if (strcmp(seg->key, var->key_url)) {
             URLContext *uc;
-            if (ffurl_open(&uc, seg->key, AVIO_FLAG_READ) == 0) {
+            if (ffurl_open(&uc, seg->key, AVIO_FLAG_READ,
+                           &var->parent->interrupt_callback) == 0) {
                 if (ffurl_read_complete(uc, var->key, sizeof(var->key))
                     != sizeof(var->key)) {
                     av_log(NULL, AV_LOG_ERROR, "Unable to read key file %s\n",
@@ -349,7 +351,8 @@ static int open_input(struct variant *var)
             snprintf(url, sizeof(url), "crypto+%s", seg->url);
         else
             snprintf(url, sizeof(url), "crypto:%s", seg->url);
-        if ((ret = ffurl_alloc(&var->input, url, AVIO_FLAG_READ)) < 0)
+        if ((ret = ffurl_alloc(&var->input, url, AVIO_FLAG_READ,
+                               &var->parent->interrupt_callback)) < 0)
             return ret;
         av_opt_set(var->input->priv_data, "key", key, 0);
         av_opt_set(var->input->priv_data, "iv", iv, 0);
index 1476ea28f2ca0fa6f6c85ca5ef38d285e29bb218..e8d1b495ed385198cbcdd87cb1443866d9972049 100644 (file)
@@ -274,7 +274,8 @@ retry:
     }
     url = s->segments[s->cur_seq_no - s->start_seq_no]->url,
     av_log(h, AV_LOG_DEBUG, "opening %s\n", url);
-    ret = ffurl_open(&s->seg_hd, url, AVIO_FLAG_READ);
+    ret = ffurl_open(&s->seg_hd, url, AVIO_FLAG_READ,
+                     &h->interrupt_callback);
     if (ret < 0) {
         if (ff_check_interrupt(&h->interrupt_callback))
             return AVERROR_EXIT;
index c66e2caac3a05ec2a373e2c1a29a702013d93d47..c17c1c44384a071d7d81d9572a3ee32e7a4a41a4 100644 (file)
@@ -86,7 +86,8 @@ int ffurl_register_protocol(URLProtocol *protocol, int size)
 }
 
 static int url_alloc_for_protocol (URLContext **puc, struct URLProtocol *up,
-                                   const char *filename, int flags)
+                                   const char *filename, int flags,
+                                   const AVIOInterruptCB *int_cb)
 {
     URLContext *uc;
     int err;
@@ -114,6 +115,8 @@ static int url_alloc_for_protocol (URLContext **puc, struct URLProtocol *up,
             av_opt_set_defaults(uc->priv_data);
         }
     }
+    if (int_cb)
+        uc->interrupt_callback = *int_cb;
 
     *puc = uc;
     return 0;
@@ -145,7 +148,7 @@ int url_open_protocol (URLContext **puc, struct URLProtocol *up,
 {
     int ret;
 
-    ret = url_alloc_for_protocol(puc, up, filename, flags);
+    ret = url_alloc_for_protocol(puc, up, filename, flags, NULL);
     if (ret)
         goto fail;
     ret = ffurl_connect(*puc);
@@ -158,7 +161,7 @@ int url_open_protocol (URLContext **puc, struct URLProtocol *up,
 }
 int url_alloc(URLContext **puc, const char *filename, int flags)
 {
-    return ffurl_alloc(puc, filename, flags);
+    return ffurl_alloc(puc, filename, flags, NULL);
 }
 int url_connect(URLContext* uc)
 {
@@ -166,7 +169,7 @@ int url_connect(URLContext* uc)
 }
 int url_open(URLContext **puc, const char *filename, int flags)
 {
-    return ffurl_open(puc, filename, flags);
+    return ffurl_open(puc, filename, flags, NULL);
 }
 int url_read(URLContext *h, unsigned char *buf, int size)
 {
@@ -219,7 +222,8 @@ int av_register_protocol2(URLProtocol *protocol, int size)
     "ABCDEFGHIJKLMNOPQRSTUVWXYZ"                \
     "0123456789+-."
 
-int ffurl_alloc(URLContext **puc, const char *filename, int flags)
+int ffurl_alloc(URLContext **puc, const char *filename, int flags,
+                const AVIOInterruptCB *int_cb)
 {
     URLProtocol *up;
     char proto_str[128], proto_nested[128], *ptr;
@@ -237,19 +241,20 @@ int ffurl_alloc(URLContext **puc, const char *filename, int flags)
     up = first_protocol;
     while (up != NULL) {
         if (!strcmp(proto_str, up->name))
-            return url_alloc_for_protocol (puc, up, filename, flags);
+            return url_alloc_for_protocol (puc, up, filename, flags, int_cb);
         if (up->flags & URL_PROTOCOL_FLAG_NESTED_SCHEME &&
             !strcmp(proto_nested, up->name))
-            return url_alloc_for_protocol (puc, up, filename, flags);
+            return url_alloc_for_protocol (puc, up, filename, flags, int_cb);
         up = up->next;
     }
     *puc = NULL;
     return AVERROR(ENOENT);
 }
 
-int ffurl_open(URLContext **puc, const char *filename, int flags)
+int ffurl_open(URLContext **puc, const char *filename, int flags,
+               const AVIOInterruptCB *int_cb)
 {
-    int ret = ffurl_alloc(puc, filename, flags);
+    int ret = ffurl_alloc(puc, filename, flags, int_cb);
     if (ret)
         return ret;
     ret = ffurl_connect(*puc);
@@ -348,7 +353,7 @@ int ffurl_close(URLContext *h)
 int url_exist(const char *filename)
 {
     URLContext *h;
-    if (ffurl_open(&h, filename, AVIO_FLAG_READ) < 0)
+    if (ffurl_open(&h, filename, AVIO_FLAG_READ, NULL) < 0)
         return 0;
     ffurl_close(h);
     return 1;
@@ -358,7 +363,7 @@ int url_exist(const char *filename)
 int avio_check(const char *url, int flags)
 {
     URLContext *h;
-    int ret = ffurl_alloc(&h, url, flags);
+    int ret = ffurl_alloc(&h, url, flags, NULL);
     if (ret)
         return ret;
 
index 8bd3e784466b35d25c056d726654b60977ea4010..b2bd6f8dc883aac9c0e45848174878254f5d19c9 100644 (file)
@@ -932,7 +932,7 @@ int avio_open(AVIOContext **s, const char *filename, int flags)
     URLContext *h;
     int err;
 
-    err = ffurl_open(&h, filename, flags);
+    err = ffurl_open(&h, filename, flags, NULL);
     if (err < 0)
         return err;
     err = ffio_fdopen(s, h);
index da9bee2cc48f238bb9da5300747b774404b6992a..47f97ef1e7b7b7d5f8643c2313f8c1ba0fbe8b76 100644 (file)
@@ -101,7 +101,7 @@ static av_cold int concat_open(URLContext *h, const char *uri, int flags)
         uri += len + strspn(uri+len, AV_CAT_SEPARATOR);
 
         /* creating URLContext */
-        if ((err = ffurl_open(&uc, node_uri, flags)) < 0)
+        if ((err = ffurl_open(&uc, node_uri, flags, &h->interrupt_callback)) < 0)
             break;
 
         /* creating size */
index ea417470b610e3027cad10b3a9dddf34e92840c5..5171b1256b07a5547e9ef64028306cc49fe746ca 100644 (file)
@@ -82,7 +82,8 @@ static int crypto_open(URLContext *h, const char *uri, int flags)
         ret = AVERROR(ENOSYS);
         goto err;
     }
-    if ((ret = ffurl_open(&c->hd, nested_url, AVIO_FLAG_READ)) < 0) {
+    if ((ret = ffurl_open(&c->hd, nested_url, AVIO_FLAG_READ,
+                          &h->interrupt_callback)) < 0) {
         av_log(h, AV_LOG_ERROR, "Unable to open input\n");
         goto err;
     }
index 79d1feba6bee7787a99bc0361f1298518a9b68e3..afb0aff98d2d62c8e82ba2b904728a5d65ccdc2c 100644 (file)
@@ -100,7 +100,7 @@ static int gopher_open(URLContext *h, const char *uri, int flags)
     ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);
 
     s->hd = NULL;
-    err = ffurl_open(&s->hd, buf, AVIO_FLAG_READ_WRITE);
+    err = ffurl_open(&s->hd, buf, AVIO_FLAG_READ_WRITE, &h->interrupt_callback);
     if (err < 0)
         goto fail;
 
index a8a76882dd5aa3db18acd249aa252aa522fdf8cc..dbf384efffa883531213c0573abe86387cb3adb6 100644 (file)
@@ -133,7 +133,7 @@ static int http_open_cnx(URLContext *h)
         port = 80;
 
     ff_url_join(buf, sizeof(buf), lower_proto, NULL, hostname, port, NULL);
-    err = ffurl_open(&hd, buf, AVIO_FLAG_READ_WRITE);
+    err = ffurl_open(&hd, buf, AVIO_FLAG_READ_WRITE, &h->interrupt_callback);
     if (err < 0)
         goto fail;
 
index 4630c49f5c798d18c188ae287a34b938f41ce7f4..f136e805f98e3c81ca2aefda6c1341d6de94e42c 100644 (file)
@@ -65,7 +65,7 @@ static int md5_close(URLContext *h)
     av_strstart(filename, "md5:", &filename);
 
     if (*filename) {
-        err = ffurl_open(&out, filename, AVIO_FLAG_WRITE);
+        err = ffurl_open(&out, filename, AVIO_FLAG_WRITE, &h->interrupt_callback);
         if (err)
             return err;
         err = ffurl_write(out, buf, i*2+1);
index cbce2f5284027a405463cc16d9f552c2bfee05cf..6ea1592d42cac9121343792a91357c3008572238 100644 (file)
@@ -233,7 +233,8 @@ static int mmsh_open(URLContext *h, const char *uri, int flags)
         port = 80; // default mmsh protocol port
     ff_url_join(httpname, sizeof(httpname), "http", NULL, host, port, "%s", path);
 
-    if (ffurl_alloc(&mms->mms_hd, httpname, AVIO_FLAG_READ) < 0) {
+    if (ffurl_alloc(&mms->mms_hd, httpname, AVIO_FLAG_READ,
+                    &h->interrupt_callback) < 0) {
         return AVERROR(EIO);
     }
 
@@ -261,7 +262,8 @@ static int mmsh_open(URLContext *h, const char *uri, int flags)
     // close the socket and then reopen it for sending the second play request.
     ffurl_close(mms->mms_hd);
     memset(headers, 0, sizeof(headers));
-    if (ffurl_alloc(&mms->mms_hd, httpname, AVIO_FLAG_READ) < 0) {
+    if (ffurl_alloc(&mms->mms_hd, httpname, AVIO_FLAG_READ,
+                    &h->interrupt_callback) < 0) {
         return AVERROR(EIO);
     }
     stream_selection = av_mallocz(mms->stream_num * 19 + 1);
index e1904de1e29ef6c91eca75ac412c82225594b517..e69d330e1b15a7035249840822a34496e31327dd 100644 (file)
@@ -523,7 +523,8 @@ static int mms_open(URLContext *h, const char *uri, int flags)
 
     // establish tcp connection.
     ff_url_join(tcpname, sizeof(tcpname), "tcp", NULL, mmst->host, port, NULL);
-    err = ffurl_open(&mms->mms_hd, tcpname, AVIO_FLAG_READ_WRITE);
+    err = ffurl_open(&mms->mms_hd, tcpname, AVIO_FLAG_READ_WRITE,
+                     &h->interrupt_callback);
     if (err)
         goto fail;
 
index 093d21a585f30af19caa684db99cafd1ef181dae..98e6180c92fbb5d759f2052cd2a999ef0bae1374 100644 (file)
@@ -817,7 +817,8 @@ static int rtmp_open(URLContext *s, const char *uri, int flags)
         port = RTMP_DEFAULT_PORT;
     ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);
 
-    if (ffurl_open(&rt->stream, buf, AVIO_FLAG_READ_WRITE) < 0) {
+    if (ffurl_open(&rt->stream, buf, AVIO_FLAG_READ_WRITE,
+                   &s->interrupt_callback) < 0) {
         av_log(s , AV_LOG_ERROR, "Cannot open connection %s\n", buf);
         goto fail;
     }
index 1bb0a4b8a6a09a23a7cac64bded2cd28b4c4d7ee..ca5007667a7348b2bfb746a10e0635a09ab13420 100644 (file)
@@ -188,7 +188,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags)
     build_udp_url(buf, sizeof(buf),
                   hostname, rtp_port, local_rtp_port, ttl, max_packet_size,
                   connect);
-    if (ffurl_open(&s->rtp_hd, buf, flags) < 0)
+    if (ffurl_open(&s->rtp_hd, buf, flags, &h->interrupt_callback) < 0)
         goto fail;
     if (local_rtp_port>=0 && local_rtcp_port<0)
         local_rtcp_port = ff_udp_get_local_port(s->rtp_hd) + 1;
@@ -196,7 +196,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags)
     build_udp_url(buf, sizeof(buf),
                   hostname, rtcp_port, local_rtcp_port, ttl, max_packet_size,
                   connect);
-    if (ffurl_open(&s->rtcp_hd, buf, flags) < 0)
+    if (ffurl_open(&s->rtcp_hd, buf, flags, &h->interrupt_callback) < 0)
         goto fail;
 
     /* just to ease handle access. XXX: need to suppress direct handle
index 5bdb7fa6a45e1a8cdeb57c3a1e23ea8081770d1a..d07cd406edd4ef129efa9acc7d1d5224dafe3bd6 100644 (file)
@@ -1159,7 +1159,8 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port,
                                 "?localport=%d", j);
                     /* we will use two ports per rtp stream (rtp and rtcp) */
                     j += 2;
-                    if (ffurl_open(&rtsp_st->rtp_handle, buf, AVIO_FLAG_READ_WRITE) == 0)
+                    if (ffurl_open(&rtsp_st->rtp_handle, buf, AVIO_FLAG_READ_WRITE,
+                                   &s->interrupt_callback) == 0)
                         goto rtp_opened;
                 }
             }
@@ -1306,7 +1307,8 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port,
                         namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST);
             ff_url_join(url, sizeof(url), "rtp", NULL, namebuf,
                         port, "?ttl=%d", ttl);
-            if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE) < 0) {
+            if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE,
+                           &s->interrupt_callback) < 0) {
                 err = AVERROR_INVALIDDATA;
                 goto fail;
             }
@@ -1450,7 +1452,8 @@ redirect:
                  av_get_random_seed(), av_get_random_seed());
 
         /* GET requests */
-        if (ffurl_alloc(&rt->rtsp_hd, httpname, AVIO_FLAG_READ) < 0) {
+        if (ffurl_alloc(&rt->rtsp_hd, httpname, AVIO_FLAG_READ,
+                        &s->interrupt_callback) < 0) {
             err = AVERROR(EIO);
             goto fail;
         }
@@ -1471,7 +1474,8 @@ redirect:
         }
 
         /* POST requests */
-        if (ffurl_alloc(&rt->rtsp_hd_out, httpname, AVIO_FLAG_WRITE) < 0 ) {
+        if (ffurl_alloc(&rt->rtsp_hd_out, httpname, AVIO_FLAG_WRITE,
+                        &s->interrupt_callback) < 0 ) {
             err = AVERROR(EIO);
             goto fail;
         }
@@ -1514,7 +1518,8 @@ redirect:
     } else {
         /* open the tcp connection */
         ff_url_join(tcpname, sizeof(tcpname), "tcp", NULL, host, port, NULL);
-        if (ffurl_open(&rt->rtsp_hd, tcpname, AVIO_FLAG_READ_WRITE) < 0) {
+        if (ffurl_open(&rt->rtsp_hd, tcpname, AVIO_FLAG_READ_WRITE,
+                       &s->interrupt_callback) < 0) {
             err = AVERROR(EIO);
             goto fail;
         }
@@ -1862,7 +1867,8 @@ static int sdp_read_header(AVFormatContext *s, AVFormatParameters *ap)
                     "?localport=%d&ttl=%d&connect=%d", rtsp_st->sdp_port,
                     rtsp_st->sdp_ttl,
                     rt->rtsp_flags & RTSP_FLAG_FILTER_SRC ? 1 : 0);
-        if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE) < 0) {
+        if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE,
+                       &s->interrupt_callback) < 0) {
             err = AVERROR_INVALIDDATA;
             goto fail;
         }
@@ -1926,7 +1932,8 @@ static int rtp_read_header(AVFormatContext *s,
     if (!ff_network_init())
         return AVERROR(EIO);
 
-    ret = ffurl_open(&in, s->filename, AVIO_FLAG_READ);
+    ret = ffurl_open(&in, s->filename, AVIO_FLAG_READ,
+                     &s->interrupt_callback);
     if (ret)
         goto fail;
 
index 84a9eb17b36a91b72dd047689743618e866d0317..21f893554f3d85d7d5297aa05db92785b729c6a4 100644 (file)
@@ -85,7 +85,7 @@ static int sap_read_header(AVFormatContext *s,
 
     ff_url_join(url, sizeof(url), "udp", NULL, host, port, "?localport=%d",
                 port);
-    ret = ffurl_open(&sap->ann_fd, url, AVIO_FLAG_READ);
+    ret = ffurl_open(&sap->ann_fd, url, AVIO_FLAG_READ, &s->interrupt_callback);
     if (ret)
         goto fail;
 
index 06cac938f34049d1ea14a692fe22ab8b403fbe1c..ec017909eb167c43d2debd9ed4912fab0a8453a2 100644 (file)
@@ -146,7 +146,7 @@ static int sap_write_header(AVFormatContext *s)
                     "?ttl=%d", ttl);
         if (!same_port)
             base_port += 2;
-        ret = ffurl_open(&fd, url, AVIO_FLAG_WRITE);
+        ret = ffurl_open(&fd, url, AVIO_FLAG_WRITE, &s->interrupt_callback);
         if (ret) {
             ret = AVERROR(EIO);
             goto fail;
@@ -158,7 +158,7 @@ static int sap_write_header(AVFormatContext *s)
 
     ff_url_join(url, sizeof(url), "udp", NULL, announce_addr, port,
                 "?ttl=%d&connect=1", ttl);
-    ret = ffurl_open(&sap->ann_fd, url, AVIO_FLAG_WRITE);
+    ret = ffurl_open(&sap->ann_fd, url, AVIO_FLAG_WRITE, &s->interrupt_callback);
     if (ret) {
         ret = AVERROR(EIO);
         goto fail;
index 15d51f3784c9a3790b41f0879d06af080e64271e..b2ec147adb50e98ee415697c1f9656a3ef24afc5 100644 (file)
@@ -123,7 +123,7 @@ static int tls_open(URLContext *h, const char *uri, int flags)
         freeaddrinfo(ai);
     }
 
-    ret = ffurl_open(&c->tcp, buf, AVIO_FLAG_READ_WRITE);
+    ret = ffurl_open(&c->tcp, buf, AVIO_FLAG_READ_WRITE, &h->interrupt_callback);
     if (ret)
         goto fail;
     c->fd = ffurl_get_file_handle(c->tcp);
index de100337105a7768ff261f31aff82a07fe1001c6..03ba15fdda466ef383c435bcad39ce935ce9ff64 100644 (file)
@@ -72,10 +72,13 @@ typedef struct URLProtocol {
  * function puts the pointer to the created URLContext
  * @param flags flags which control how the resource indicated by url
  * is to be opened
+ * @param int_cb interrupt callback to use for the URLContext, may be
+ * NULL
  * @return 0 in case of success, a negative value corresponding to an
  * AVERROR code in case of failure
  */
-int ffurl_alloc(URLContext **puc, const char *filename, int flags);
+int ffurl_alloc(URLContext **puc, const char *filename, int flags,
+                const AVIOInterruptCB *int_cb);
 
 /**
  * Connect an URLContext that has been allocated by ffurl_alloc
@@ -90,10 +93,13 @@ int ffurl_connect(URLContext *uc);
  * function puts the pointer to the created URLContext
  * @param flags flags which control how the resource indicated by url
  * is to be opened
+ * @param int_cb interrupt callback to use for the URLContext, may be
+ * NULL
  * @return 0 in case of success, a negative value corresponding to an
  * AVERROR code in case of failure
  */
-int ffurl_open(URLContext **puc, const char *filename, int flags);
+int ffurl_open(URLContext **puc, const char *filename, int flags,
+               const AVIOInterruptCB *int_cb);
 
 /**
  * Read up to size bytes from the resource accessed by h, and store