Commit 6f1b7b39 authored by Martin Storsjö's avatar Martin Storsjö Committed by Anton Khirnov

avio: Add an AVIOInterruptCB parameter to ffurl_open/ffurl_alloc

Change all uses of these function to pass the relevant
callback on.
parent 9957cdbf
......@@ -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);
......
......@@ -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;
......
......@@ -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;
......
......@@ -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);
......
......@@ -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 */
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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;
......
......@@ -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);
......
......@@ -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);
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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);
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment