aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2011-11-06 22:50:44 +0200
committerAnton Khirnov <anton@khirnov.net>2011-11-13 13:12:17 +0100
commit6f1b7b39449c4cd58e37d831d5d97bfd25eb26f0 (patch)
treeb97fb7b744d0d6d1d3611465b055dd10c17d8ebc
parent9957cdbfd5ced5baae6ec97b97b08f1ad42aa4e4 (diff)
downloadffmpeg-6f1b7b39449c4cd58e37d831d5d97bfd25eb26f0.tar.gz
avio: Add an AVIOInterruptCB parameter to ffurl_open/ffurl_alloc
Change all uses of these function to pass the relevant callback on.
-rw-r--r--libavformat/applehttp.c9
-rw-r--r--libavformat/applehttpproto.c3
-rw-r--r--libavformat/avio.c27
-rw-r--r--libavformat/aviobuf.c2
-rw-r--r--libavformat/concat.c2
-rw-r--r--libavformat/crypto.c3
-rw-r--r--libavformat/gopher.c2
-rw-r--r--libavformat/http.c2
-rw-r--r--libavformat/md5proto.c2
-rw-r--r--libavformat/mmsh.c6
-rw-r--r--libavformat/mmst.c3
-rw-r--r--libavformat/rtmpproto.c3
-rw-r--r--libavformat/rtpproto.c4
-rw-r--r--libavformat/rtsp.c21
-rw-r--r--libavformat/sapdec.c2
-rw-r--r--libavformat/sapenc.c4
-rw-r--r--libavformat/tls.c2
-rw-r--r--libavformat/url.h10
18 files changed, 67 insertions, 40 deletions
diff --git a/libavformat/applehttp.c b/libavformat/applehttp.c
index 06884a07c6..ae251531e8 100644
--- a/libavformat/applehttp.c
+++ b/libavformat/applehttp.c
@@ -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);
diff --git a/libavformat/applehttpproto.c b/libavformat/applehttpproto.c
index 1476ea28f2..e8d1b495ed 100644
--- a/libavformat/applehttpproto.c
+++ b/libavformat/applehttpproto.c
@@ -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;
diff --git a/libavformat/avio.c b/libavformat/avio.c
index c66e2caac3..c17c1c4438 100644
--- a/libavformat/avio.c
+++ b/libavformat/avio.c
@@ -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;
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 8bd3e78446..b2bd6f8dc8 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -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);
diff --git a/libavformat/concat.c b/libavformat/concat.c
index da9bee2cc4..47f97ef1e7 100644
--- a/libavformat/concat.c
+++ b/libavformat/concat.c
@@ -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 */
diff --git a/libavformat/crypto.c b/libavformat/crypto.c
index ea417470b6..5171b1256b 100644
--- a/libavformat/crypto.c
+++ b/libavformat/crypto.c
@@ -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;
}
diff --git a/libavformat/gopher.c b/libavformat/gopher.c
index 79d1feba6b..afb0aff98d 100644
--- a/libavformat/gopher.c
+++ b/libavformat/gopher.c
@@ -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;
diff --git a/libavformat/http.c b/libavformat/http.c
index a8a76882dd..dbf384efff 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -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;
diff --git a/libavformat/md5proto.c b/libavformat/md5proto.c
index 4630c49f5c..f136e805f9 100644
--- a/libavformat/md5proto.c
+++ b/libavformat/md5proto.c
@@ -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);
diff --git a/libavformat/mmsh.c b/libavformat/mmsh.c
index cbce2f5284..6ea1592d42 100644
--- a/libavformat/mmsh.c
+++ b/libavformat/mmsh.c
@@ -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);
diff --git a/libavformat/mmst.c b/libavformat/mmst.c
index e1904de1e2..e69d330e1b 100644
--- a/libavformat/mmst.c
+++ b/libavformat/mmst.c
@@ -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;
diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c
index 093d21a585..98e6180c92 100644
--- a/libavformat/rtmpproto.c
+++ b/libavformat/rtmpproto.c
@@ -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;
}
diff --git a/libavformat/rtpproto.c b/libavformat/rtpproto.c
index 1bb0a4b8a6..ca5007667a 100644
--- a/libavformat/rtpproto.c
+++ b/libavformat/rtpproto.c
@@ -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
diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 5bdb7fa6a4..d07cd406ed 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -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;
diff --git a/libavformat/sapdec.c b/libavformat/sapdec.c
index 84a9eb17b3..21f893554f 100644
--- a/libavformat/sapdec.c
+++ b/libavformat/sapdec.c
@@ -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;
diff --git a/libavformat/sapenc.c b/libavformat/sapenc.c
index 06cac938f3..ec017909eb 100644
--- a/libavformat/sapenc.c
+++ b/libavformat/sapenc.c
@@ -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;
diff --git a/libavformat/tls.c b/libavformat/tls.c
index 15d51f3784..b2ec147adb 100644
--- a/libavformat/tls.c
+++ b/libavformat/tls.c
@@ -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);
diff --git a/libavformat/url.h b/libavformat/url.h
index de10033710..03ba15fdda 100644
--- a/libavformat/url.h
+++ b/libavformat/url.h
@@ -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