Browse code

avio: Add an AVIOInterruptCB parameter to ffurl_open/ffurl_alloc

Change all uses of these function to pass the relevant
callback on.

Martin Storsjö authored on 2011/11/07 05:50:44
Showing 18 changed files
... ...
@@ -323,13 +323,15 @@ static int open_input(struct variant *var)
323 323
 {
324 324
     struct segment *seg = var->segments[var->cur_seq_no - var->start_seq_no];
325 325
     if (seg->key_type == KEY_NONE) {
326
-        return ffurl_open(&var->input, seg->url, AVIO_FLAG_READ);
326
+        return ffurl_open(&var->input, seg->url, AVIO_FLAG_READ,
327
+                          &var->parent->interrupt_callback);
327 328
     } else if (seg->key_type == KEY_AES_128) {
328 329
         char iv[33], key[33], url[MAX_URL_SIZE];
329 330
         int ret;
330 331
         if (strcmp(seg->key, var->key_url)) {
331 332
             URLContext *uc;
332
-            if (ffurl_open(&uc, seg->key, AVIO_FLAG_READ) == 0) {
333
+            if (ffurl_open(&uc, seg->key, AVIO_FLAG_READ,
334
+                           &var->parent->interrupt_callback) == 0) {
333 335
                 if (ffurl_read_complete(uc, var->key, sizeof(var->key))
334 336
                     != sizeof(var->key)) {
335 337
                     av_log(NULL, AV_LOG_ERROR, "Unable to read key file %s\n",
... ...
@@ -349,7 +351,8 @@ static int open_input(struct variant *var)
349 349
             snprintf(url, sizeof(url), "crypto+%s", seg->url);
350 350
         else
351 351
             snprintf(url, sizeof(url), "crypto:%s", seg->url);
352
-        if ((ret = ffurl_alloc(&var->input, url, AVIO_FLAG_READ)) < 0)
352
+        if ((ret = ffurl_alloc(&var->input, url, AVIO_FLAG_READ,
353
+                               &var->parent->interrupt_callback)) < 0)
353 354
             return ret;
354 355
         av_opt_set(var->input->priv_data, "key", key, 0);
355 356
         av_opt_set(var->input->priv_data, "iv", iv, 0);
... ...
@@ -274,7 +274,8 @@ retry:
274 274
     }
275 275
     url = s->segments[s->cur_seq_no - s->start_seq_no]->url,
276 276
     av_log(h, AV_LOG_DEBUG, "opening %s\n", url);
277
-    ret = ffurl_open(&s->seg_hd, url, AVIO_FLAG_READ);
277
+    ret = ffurl_open(&s->seg_hd, url, AVIO_FLAG_READ,
278
+                     &h->interrupt_callback);
278 279
     if (ret < 0) {
279 280
         if (ff_check_interrupt(&h->interrupt_callback))
280 281
             return AVERROR_EXIT;
... ...
@@ -86,7 +86,8 @@ int ffurl_register_protocol(URLProtocol *protocol, int size)
86 86
 }
87 87
 
88 88
 static int url_alloc_for_protocol (URLContext **puc, struct URLProtocol *up,
89
-                                   const char *filename, int flags)
89
+                                   const char *filename, int flags,
90
+                                   const AVIOInterruptCB *int_cb)
90 91
 {
91 92
     URLContext *uc;
92 93
     int err;
... ...
@@ -114,6 +115,8 @@ static int url_alloc_for_protocol (URLContext **puc, struct URLProtocol *up,
114 114
             av_opt_set_defaults(uc->priv_data);
115 115
         }
116 116
     }
117
+    if (int_cb)
118
+        uc->interrupt_callback = *int_cb;
117 119
 
118 120
     *puc = uc;
119 121
     return 0;
... ...
@@ -145,7 +148,7 @@ int url_open_protocol (URLContext **puc, struct URLProtocol *up,
145 145
 {
146 146
     int ret;
147 147
 
148
-    ret = url_alloc_for_protocol(puc, up, filename, flags);
148
+    ret = url_alloc_for_protocol(puc, up, filename, flags, NULL);
149 149
     if (ret)
150 150
         goto fail;
151 151
     ret = ffurl_connect(*puc);
... ...
@@ -158,7 +161,7 @@ int url_open_protocol (URLContext **puc, struct URLProtocol *up,
158 158
 }
159 159
 int url_alloc(URLContext **puc, const char *filename, int flags)
160 160
 {
161
-    return ffurl_alloc(puc, filename, flags);
161
+    return ffurl_alloc(puc, filename, flags, NULL);
162 162
 }
163 163
 int url_connect(URLContext* uc)
164 164
 {
... ...
@@ -166,7 +169,7 @@ int url_connect(URLContext* uc)
166 166
 }
167 167
 int url_open(URLContext **puc, const char *filename, int flags)
168 168
 {
169
-    return ffurl_open(puc, filename, flags);
169
+    return ffurl_open(puc, filename, flags, NULL);
170 170
 }
171 171
 int url_read(URLContext *h, unsigned char *buf, int size)
172 172
 {
... ...
@@ -219,7 +222,8 @@ int av_register_protocol2(URLProtocol *protocol, int size)
219 219
     "ABCDEFGHIJKLMNOPQRSTUVWXYZ"                \
220 220
     "0123456789+-."
221 221
 
222
-int ffurl_alloc(URLContext **puc, const char *filename, int flags)
222
+int ffurl_alloc(URLContext **puc, const char *filename, int flags,
223
+                const AVIOInterruptCB *int_cb)
223 224
 {
224 225
     URLProtocol *up;
225 226
     char proto_str[128], proto_nested[128], *ptr;
... ...
@@ -237,19 +241,20 @@ int ffurl_alloc(URLContext **puc, const char *filename, int flags)
237 237
     up = first_protocol;
238 238
     while (up != NULL) {
239 239
         if (!strcmp(proto_str, up->name))
240
-            return url_alloc_for_protocol (puc, up, filename, flags);
240
+            return url_alloc_for_protocol (puc, up, filename, flags, int_cb);
241 241
         if (up->flags & URL_PROTOCOL_FLAG_NESTED_SCHEME &&
242 242
             !strcmp(proto_nested, up->name))
243
-            return url_alloc_for_protocol (puc, up, filename, flags);
243
+            return url_alloc_for_protocol (puc, up, filename, flags, int_cb);
244 244
         up = up->next;
245 245
     }
246 246
     *puc = NULL;
247 247
     return AVERROR(ENOENT);
248 248
 }
249 249
 
250
-int ffurl_open(URLContext **puc, const char *filename, int flags)
250
+int ffurl_open(URLContext **puc, const char *filename, int flags,
251
+               const AVIOInterruptCB *int_cb)
251 252
 {
252
-    int ret = ffurl_alloc(puc, filename, flags);
253
+    int ret = ffurl_alloc(puc, filename, flags, int_cb);
253 254
     if (ret)
254 255
         return ret;
255 256
     ret = ffurl_connect(*puc);
... ...
@@ -348,7 +353,7 @@ int ffurl_close(URLContext *h)
348 348
 int url_exist(const char *filename)
349 349
 {
350 350
     URLContext *h;
351
-    if (ffurl_open(&h, filename, AVIO_FLAG_READ) < 0)
351
+    if (ffurl_open(&h, filename, AVIO_FLAG_READ, NULL) < 0)
352 352
         return 0;
353 353
     ffurl_close(h);
354 354
     return 1;
... ...
@@ -358,7 +363,7 @@ int url_exist(const char *filename)
358 358
 int avio_check(const char *url, int flags)
359 359
 {
360 360
     URLContext *h;
361
-    int ret = ffurl_alloc(&h, url, flags);
361
+    int ret = ffurl_alloc(&h, url, flags, NULL);
362 362
     if (ret)
363 363
         return ret;
364 364
 
... ...
@@ -932,7 +932,7 @@ int avio_open(AVIOContext **s, const char *filename, int flags)
932 932
     URLContext *h;
933 933
     int err;
934 934
 
935
-    err = ffurl_open(&h, filename, flags);
935
+    err = ffurl_open(&h, filename, flags, NULL);
936 936
     if (err < 0)
937 937
         return err;
938 938
     err = ffio_fdopen(s, h);
... ...
@@ -101,7 +101,7 @@ static av_cold int concat_open(URLContext *h, const char *uri, int flags)
101 101
         uri += len + strspn(uri+len, AV_CAT_SEPARATOR);
102 102
 
103 103
         /* creating URLContext */
104
-        if ((err = ffurl_open(&uc, node_uri, flags)) < 0)
104
+        if ((err = ffurl_open(&uc, node_uri, flags, &h->interrupt_callback)) < 0)
105 105
             break;
106 106
 
107 107
         /* creating size */
... ...
@@ -82,7 +82,8 @@ static int crypto_open(URLContext *h, const char *uri, int flags)
82 82
         ret = AVERROR(ENOSYS);
83 83
         goto err;
84 84
     }
85
-    if ((ret = ffurl_open(&c->hd, nested_url, AVIO_FLAG_READ)) < 0) {
85
+    if ((ret = ffurl_open(&c->hd, nested_url, AVIO_FLAG_READ,
86
+                          &h->interrupt_callback)) < 0) {
86 87
         av_log(h, AV_LOG_ERROR, "Unable to open input\n");
87 88
         goto err;
88 89
     }
... ...
@@ -100,7 +100,7 @@ static int gopher_open(URLContext *h, const char *uri, int flags)
100 100
     ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);
101 101
 
102 102
     s->hd = NULL;
103
-    err = ffurl_open(&s->hd, buf, AVIO_FLAG_READ_WRITE);
103
+    err = ffurl_open(&s->hd, buf, AVIO_FLAG_READ_WRITE, &h->interrupt_callback);
104 104
     if (err < 0)
105 105
         goto fail;
106 106
 
... ...
@@ -133,7 +133,7 @@ static int http_open_cnx(URLContext *h)
133 133
         port = 80;
134 134
 
135 135
     ff_url_join(buf, sizeof(buf), lower_proto, NULL, hostname, port, NULL);
136
-    err = ffurl_open(&hd, buf, AVIO_FLAG_READ_WRITE);
136
+    err = ffurl_open(&hd, buf, AVIO_FLAG_READ_WRITE, &h->interrupt_callback);
137 137
     if (err < 0)
138 138
         goto fail;
139 139
 
... ...
@@ -65,7 +65,7 @@ static int md5_close(URLContext *h)
65 65
     av_strstart(filename, "md5:", &filename);
66 66
 
67 67
     if (*filename) {
68
-        err = ffurl_open(&out, filename, AVIO_FLAG_WRITE);
68
+        err = ffurl_open(&out, filename, AVIO_FLAG_WRITE, &h->interrupt_callback);
69 69
         if (err)
70 70
             return err;
71 71
         err = ffurl_write(out, buf, i*2+1);
... ...
@@ -233,7 +233,8 @@ static int mmsh_open(URLContext *h, const char *uri, int flags)
233 233
         port = 80; // default mmsh protocol port
234 234
     ff_url_join(httpname, sizeof(httpname), "http", NULL, host, port, "%s", path);
235 235
 
236
-    if (ffurl_alloc(&mms->mms_hd, httpname, AVIO_FLAG_READ) < 0) {
236
+    if (ffurl_alloc(&mms->mms_hd, httpname, AVIO_FLAG_READ,
237
+                    &h->interrupt_callback) < 0) {
237 238
         return AVERROR(EIO);
238 239
     }
239 240
 
... ...
@@ -261,7 +262,8 @@ static int mmsh_open(URLContext *h, const char *uri, int flags)
261 261
     // close the socket and then reopen it for sending the second play request.
262 262
     ffurl_close(mms->mms_hd);
263 263
     memset(headers, 0, sizeof(headers));
264
-    if (ffurl_alloc(&mms->mms_hd, httpname, AVIO_FLAG_READ) < 0) {
264
+    if (ffurl_alloc(&mms->mms_hd, httpname, AVIO_FLAG_READ,
265
+                    &h->interrupt_callback) < 0) {
265 266
         return AVERROR(EIO);
266 267
     }
267 268
     stream_selection = av_mallocz(mms->stream_num * 19 + 1);
... ...
@@ -523,7 +523,8 @@ static int mms_open(URLContext *h, const char *uri, int flags)
523 523
 
524 524
     // establish tcp connection.
525 525
     ff_url_join(tcpname, sizeof(tcpname), "tcp", NULL, mmst->host, port, NULL);
526
-    err = ffurl_open(&mms->mms_hd, tcpname, AVIO_FLAG_READ_WRITE);
526
+    err = ffurl_open(&mms->mms_hd, tcpname, AVIO_FLAG_READ_WRITE,
527
+                     &h->interrupt_callback);
527 528
     if (err)
528 529
         goto fail;
529 530
 
... ...
@@ -817,7 +817,8 @@ static int rtmp_open(URLContext *s, const char *uri, int flags)
817 817
         port = RTMP_DEFAULT_PORT;
818 818
     ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);
819 819
 
820
-    if (ffurl_open(&rt->stream, buf, AVIO_FLAG_READ_WRITE) < 0) {
820
+    if (ffurl_open(&rt->stream, buf, AVIO_FLAG_READ_WRITE,
821
+                   &s->interrupt_callback) < 0) {
821 822
         av_log(s , AV_LOG_ERROR, "Cannot open connection %s\n", buf);
822 823
         goto fail;
823 824
     }
... ...
@@ -188,7 +188,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags)
188 188
     build_udp_url(buf, sizeof(buf),
189 189
                   hostname, rtp_port, local_rtp_port, ttl, max_packet_size,
190 190
                   connect);
191
-    if (ffurl_open(&s->rtp_hd, buf, flags) < 0)
191
+    if (ffurl_open(&s->rtp_hd, buf, flags, &h->interrupt_callback) < 0)
192 192
         goto fail;
193 193
     if (local_rtp_port>=0 && local_rtcp_port<0)
194 194
         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)
196 196
     build_udp_url(buf, sizeof(buf),
197 197
                   hostname, rtcp_port, local_rtcp_port, ttl, max_packet_size,
198 198
                   connect);
199
-    if (ffurl_open(&s->rtcp_hd, buf, flags) < 0)
199
+    if (ffurl_open(&s->rtcp_hd, buf, flags, &h->interrupt_callback) < 0)
200 200
         goto fail;
201 201
 
202 202
     /* just to ease handle access. XXX: need to suppress direct handle
... ...
@@ -1159,7 +1159,8 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port,
1159 1159
                                 "?localport=%d", j);
1160 1160
                     /* we will use two ports per rtp stream (rtp and rtcp) */
1161 1161
                     j += 2;
1162
-                    if (ffurl_open(&rtsp_st->rtp_handle, buf, AVIO_FLAG_READ_WRITE) == 0)
1162
+                    if (ffurl_open(&rtsp_st->rtp_handle, buf, AVIO_FLAG_READ_WRITE,
1163
+                                   &s->interrupt_callback) == 0)
1163 1164
                         goto rtp_opened;
1164 1165
                 }
1165 1166
             }
... ...
@@ -1306,7 +1307,8 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port,
1306 1306
                         namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST);
1307 1307
             ff_url_join(url, sizeof(url), "rtp", NULL, namebuf,
1308 1308
                         port, "?ttl=%d", ttl);
1309
-            if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE) < 0) {
1309
+            if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE,
1310
+                           &s->interrupt_callback) < 0) {
1310 1311
                 err = AVERROR_INVALIDDATA;
1311 1312
                 goto fail;
1312 1313
             }
... ...
@@ -1450,7 +1452,8 @@ redirect:
1450 1450
                  av_get_random_seed(), av_get_random_seed());
1451 1451
 
1452 1452
         /* GET requests */
1453
-        if (ffurl_alloc(&rt->rtsp_hd, httpname, AVIO_FLAG_READ) < 0) {
1453
+        if (ffurl_alloc(&rt->rtsp_hd, httpname, AVIO_FLAG_READ,
1454
+                        &s->interrupt_callback) < 0) {
1454 1455
             err = AVERROR(EIO);
1455 1456
             goto fail;
1456 1457
         }
... ...
@@ -1471,7 +1474,8 @@ redirect:
1471 1471
         }
1472 1472
 
1473 1473
         /* POST requests */
1474
-        if (ffurl_alloc(&rt->rtsp_hd_out, httpname, AVIO_FLAG_WRITE) < 0 ) {
1474
+        if (ffurl_alloc(&rt->rtsp_hd_out, httpname, AVIO_FLAG_WRITE,
1475
+                        &s->interrupt_callback) < 0 ) {
1475 1476
             err = AVERROR(EIO);
1476 1477
             goto fail;
1477 1478
         }
... ...
@@ -1514,7 +1518,8 @@ redirect:
1514 1514
     } else {
1515 1515
         /* open the tcp connection */
1516 1516
         ff_url_join(tcpname, sizeof(tcpname), "tcp", NULL, host, port, NULL);
1517
-        if (ffurl_open(&rt->rtsp_hd, tcpname, AVIO_FLAG_READ_WRITE) < 0) {
1517
+        if (ffurl_open(&rt->rtsp_hd, tcpname, AVIO_FLAG_READ_WRITE,
1518
+                       &s->interrupt_callback) < 0) {
1518 1519
             err = AVERROR(EIO);
1519 1520
             goto fail;
1520 1521
         }
... ...
@@ -1862,7 +1867,8 @@ static int sdp_read_header(AVFormatContext *s, AVFormatParameters *ap)
1862 1862
                     "?localport=%d&ttl=%d&connect=%d", rtsp_st->sdp_port,
1863 1863
                     rtsp_st->sdp_ttl,
1864 1864
                     rt->rtsp_flags & RTSP_FLAG_FILTER_SRC ? 1 : 0);
1865
-        if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE) < 0) {
1865
+        if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE,
1866
+                       &s->interrupt_callback) < 0) {
1866 1867
             err = AVERROR_INVALIDDATA;
1867 1868
             goto fail;
1868 1869
         }
... ...
@@ -1926,7 +1932,8 @@ static int rtp_read_header(AVFormatContext *s,
1926 1926
     if (!ff_network_init())
1927 1927
         return AVERROR(EIO);
1928 1928
 
1929
-    ret = ffurl_open(&in, s->filename, AVIO_FLAG_READ);
1929
+    ret = ffurl_open(&in, s->filename, AVIO_FLAG_READ,
1930
+                     &s->interrupt_callback);
1930 1931
     if (ret)
1931 1932
         goto fail;
1932 1933
 
... ...
@@ -85,7 +85,7 @@ static int sap_read_header(AVFormatContext *s,
85 85
 
86 86
     ff_url_join(url, sizeof(url), "udp", NULL, host, port, "?localport=%d",
87 87
                 port);
88
-    ret = ffurl_open(&sap->ann_fd, url, AVIO_FLAG_READ);
88
+    ret = ffurl_open(&sap->ann_fd, url, AVIO_FLAG_READ, &s->interrupt_callback);
89 89
     if (ret)
90 90
         goto fail;
91 91
 
... ...
@@ -146,7 +146,7 @@ static int sap_write_header(AVFormatContext *s)
146 146
                     "?ttl=%d", ttl);
147 147
         if (!same_port)
148 148
             base_port += 2;
149
-        ret = ffurl_open(&fd, url, AVIO_FLAG_WRITE);
149
+        ret = ffurl_open(&fd, url, AVIO_FLAG_WRITE, &s->interrupt_callback);
150 150
         if (ret) {
151 151
             ret = AVERROR(EIO);
152 152
             goto fail;
... ...
@@ -158,7 +158,7 @@ static int sap_write_header(AVFormatContext *s)
158 158
 
159 159
     ff_url_join(url, sizeof(url), "udp", NULL, announce_addr, port,
160 160
                 "?ttl=%d&connect=1", ttl);
161
-    ret = ffurl_open(&sap->ann_fd, url, AVIO_FLAG_WRITE);
161
+    ret = ffurl_open(&sap->ann_fd, url, AVIO_FLAG_WRITE, &s->interrupt_callback);
162 162
     if (ret) {
163 163
         ret = AVERROR(EIO);
164 164
         goto fail;
... ...
@@ -123,7 +123,7 @@ static int tls_open(URLContext *h, const char *uri, int flags)
123 123
         freeaddrinfo(ai);
124 124
     }
125 125
 
126
-    ret = ffurl_open(&c->tcp, buf, AVIO_FLAG_READ_WRITE);
126
+    ret = ffurl_open(&c->tcp, buf, AVIO_FLAG_READ_WRITE, &h->interrupt_callback);
127 127
     if (ret)
128 128
         goto fail;
129 129
     c->fd = ffurl_get_file_handle(c->tcp);
... ...
@@ -72,10 +72,13 @@ typedef struct URLProtocol {
72 72
  * function puts the pointer to the created URLContext
73 73
  * @param flags flags which control how the resource indicated by url
74 74
  * is to be opened
75
+ * @param int_cb interrupt callback to use for the URLContext, may be
76
+ * NULL
75 77
  * @return 0 in case of success, a negative value corresponding to an
76 78
  * AVERROR code in case of failure
77 79
  */
78
-int ffurl_alloc(URLContext **puc, const char *filename, int flags);
80
+int ffurl_alloc(URLContext **puc, const char *filename, int flags,
81
+                const AVIOInterruptCB *int_cb);
79 82
 
80 83
 /**
81 84
  * Connect an URLContext that has been allocated by ffurl_alloc
... ...
@@ -90,10 +93,13 @@ int ffurl_connect(URLContext *uc);
90 90
  * function puts the pointer to the created URLContext
91 91
  * @param flags flags which control how the resource indicated by url
92 92
  * is to be opened
93
+ * @param int_cb interrupt callback to use for the URLContext, may be
94
+ * NULL
93 95
  * @return 0 in case of success, a negative value corresponding to an
94 96
  * AVERROR code in case of failure
95 97
  */
96
-int ffurl_open(URLContext **puc, const char *filename, int flags);
98
+int ffurl_open(URLContext **puc, const char *filename, int flags,
99
+               const AVIOInterruptCB *int_cb);
97 100
 
98 101
 /**
99 102
  * Read up to size bytes from the resource accessed by h, and store