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,
- &var->parent->interrupt_callback);
+ &var->parent->interrupt_callback, NULL);
} 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,
- &var->parent->interrupt_callback) == 0) {
+ &var->parent->interrupt_callback, NULL) == 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",
return ret;
av_opt_set(var->input->priv_data, "key", key, 0);
av_opt_set(var->input->priv_data, "iv", iv, 0);
- if ((ret = ffurl_connect(var->input)) < 0) {
+ if ((ret = ffurl_connect(var->input, NULL)) < 0) {
ffurl_close(var->input);
var->input = NULL;
return ret;
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,
- &h->interrupt_callback);
+ &h->interrupt_callback, NULL);
if (ret < 0) {
if (ff_check_interrupt(&h->interrupt_callback))
return AVERROR_EXIT;
#include <unistd.h>
#include "libavutil/avstring.h"
+#include "libavutil/dict.h"
#include "libavutil/opt.h"
#include "os_support.h"
#include "avformat.h"
if(h->prot) return h->prot->name;
else return "NULL";
}
+
+static void *urlcontext_child_next(void *obj, void *prev)
+{
+ URLContext *h = obj;
+ if (!prev && h->priv_data && h->prot->priv_data_class)
+ return h->priv_data;
+ return NULL;
+}
+
+static const AVClass *urlcontext_child_class_next(const AVClass *prev)
+{
+ URLProtocol *p = NULL;
+
+ /* find the protocol that corresponds to prev */
+ while (prev && (p = ffurl_protocol_next(p)))
+ if (p->priv_data_class == prev)
+ break;
+
+ /* find next protocol with priv options */
+ while (p = ffurl_protocol_next(p))
+ if (p->priv_data_class)
+ return p->priv_data_class;
+ return NULL;
+
+}
+
static const AVOption options[] = {{NULL}};
static const AVClass urlcontext_class = {
.class_name = "URLContext",
.item_name = urlcontext_to_name,
.option = options,
.version = LIBAVUTIL_VERSION_INT,
+ .child_next = urlcontext_child_next,
+ .child_class_next = urlcontext_child_class_next,
};
/*@}*/
return err;
}
-int ffurl_connect(URLContext* uc)
+int ffurl_connect(URLContext* uc, AVDictionary **options)
{
- int err = uc->prot->url_open(uc, uc->filename, uc->flags);
+ int err =
+#if !FF_API_OLD_AVIO
+ uc->prot->url_open2 ? uc->prot->url_open2(uc, uc->filename, uc->flags, options) :
+#endif
+ uc->prot->url_open(uc, uc->filename, uc->flags);
if (err)
return err;
uc->is_connected = 1;
ret = url_alloc_for_protocol(puc, up, filename, flags, NULL);
if (ret)
goto fail;
- ret = ffurl_connect(*puc);
+ ret = ffurl_connect(*puc, NULL);
if (!ret)
return 0;
fail:
}
int url_connect(URLContext* uc)
{
- return ffurl_connect(uc);
+ return ffurl_connect(uc, NULL);
}
int url_open(URLContext **puc, const char *filename, int flags)
{
- return ffurl_open(puc, filename, flags, NULL);
+ return ffurl_open(puc, filename, flags, NULL, NULL);
}
int url_read(URLContext *h, unsigned char *buf, int size)
{
}
int ffurl_open(URLContext **puc, const char *filename, int flags,
- const AVIOInterruptCB *int_cb)
+ const AVIOInterruptCB *int_cb, AVDictionary **options)
{
int ret = ffurl_alloc(puc, filename, flags, int_cb);
if (ret)
return ret;
- ret = ffurl_connect(*puc);
+ if (options && (*puc)->prot->priv_data_class &&
+ (ret = av_opt_set_dict((*puc)->priv_data, options)) < 0)
+ goto fail;
+ ret = ffurl_connect(*puc, options);
if (!ret)
return 0;
+fail:
ffurl_close(*puc);
*puc = NULL;
return ret;
int url_exist(const char *filename)
{
URLContext *h;
- if (ffurl_open(&h, filename, AVIO_FLAG_READ, NULL) < 0)
+ if (ffurl_open(&h, filename, AVIO_FLAG_READ, NULL, NULL) < 0)
return 0;
ffurl_close(h);
return 1;
if (h->prot->url_check) {
ret = h->prot->url_check(h, flags);
} else {
- ret = ffurl_connect(h);
+ ret = ffurl_connect(h, NULL);
if (ret >= 0)
ret = flags;
}
URLContext *h;
int err;
- err = ffurl_open(&h, filename, flags, NULL);
+ err = ffurl_open(&h, filename, flags, NULL, NULL);
if (err < 0)
return err;
err = ffio_fdopen(s, h);
uri += len + strspn(uri+len, AV_CAT_SEPARATOR);
/* creating URLContext */
- if ((err = ffurl_open(&uc, node_uri, flags, &h->interrupt_callback)) < 0)
+ if ((err = ffurl_open(&uc, node_uri, flags,
+ &h->interrupt_callback, NULL)) < 0)
break;
/* creating size */
goto err;
}
if ((ret = ffurl_open(&c->hd, nested_url, AVIO_FLAG_READ,
- &h->interrupt_callback)) < 0) {
+ &h->interrupt_callback, NULL)) < 0) {
av_log(h, AV_LOG_ERROR, "Unable to open input\n");
goto err;
}
ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);
s->hd = NULL;
- err = ffurl_open(&s->hd, buf, AVIO_FLAG_READ_WRITE, &h->interrupt_callback);
+ err = ffurl_open(&s->hd, buf, AVIO_FLAG_READ_WRITE,
+ &h->interrupt_callback, NULL);
if (err < 0)
goto fail;
port = 80;
ff_url_join(buf, sizeof(buf), lower_proto, NULL, hostname, port, NULL);
- err = ffurl_open(&hd, buf, AVIO_FLAG_READ_WRITE, &h->interrupt_callback);
+ err = ffurl_open(&hd, buf, AVIO_FLAG_READ_WRITE,
+ &h->interrupt_callback, NULL);
if (err < 0)
goto fail;
av_strstart(filename, "md5:", &filename);
if (*filename) {
- err = ffurl_open(&out, filename, AVIO_FLAG_WRITE, &h->interrupt_callback);
+ err = ffurl_open(&out, filename, AVIO_FLAG_WRITE,
+ &h->interrupt_callback, NULL);
if (err)
return err;
err = ffurl_write(out, buf, i*2+1);
host, port, mmsh->request_seq++);
av_opt_set(mms->mms_hd->priv_data, "headers", headers, 0);
- err = ffurl_connect(mms->mms_hd);
+ err = ffurl_connect(mms->mms_hd, NULL);
if (err) {
goto fail;
}
av_dlog(NULL, "out_buffer is %s", headers);
av_opt_set(mms->mms_hd->priv_data, "headers", headers, 0);
- err = ffurl_connect(mms->mms_hd);
+ err = ffurl_connect(mms->mms_hd, NULL);
if (err) {
goto fail;
}
// 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,
- &h->interrupt_callback);
+ &h->interrupt_callback, NULL);
if (err)
goto fail;
ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);
if (ffurl_open(&rt->stream, buf, AVIO_FLAG_READ_WRITE,
- &s->interrupt_callback) < 0) {
+ &s->interrupt_callback, NULL) < 0) {
av_log(s , AV_LOG_ERROR, "Cannot open connection %s\n", buf);
goto fail;
}
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, &h->interrupt_callback) < 0)
+ if (ffurl_open(&s->rtp_hd, buf, flags, &h->interrupt_callback, NULL) < 0)
goto fail;
if (local_rtp_port>=0 && local_rtcp_port<0)
local_rtcp_port = ff_udp_get_local_port(s->rtp_hd) + 1;
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, &h->interrupt_callback) < 0)
+ if (ffurl_open(&s->rtcp_hd, buf, flags, &h->interrupt_callback, NULL) < 0)
goto fail;
/* just to ease handle access. XXX: need to suppress direct handle
/* 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,
- &s->interrupt_callback) == 0)
+ &s->interrupt_callback, NULL) == 0)
goto rtp_opened;
}
}
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,
- &s->interrupt_callback) < 0) {
+ &s->interrupt_callback, NULL) < 0) {
err = AVERROR_INVALIDDATA;
goto fail;
}
av_opt_set(rt->rtsp_hd->priv_data, "headers", headers, 0);
/* complete the connection */
- if (ffurl_connect(rt->rtsp_hd)) {
+ if (ffurl_connect(rt->rtsp_hd, NULL)) {
err = AVERROR(EIO);
goto fail;
}
ff_http_init_auth_state(rt->rtsp_hd_out, rt->rtsp_hd);
/* complete the connection */
- if (ffurl_connect(rt->rtsp_hd_out)) {
+ if (ffurl_connect(rt->rtsp_hd_out, NULL)) {
err = AVERROR(EIO);
goto fail;
}
/* 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,
- &s->interrupt_callback) < 0) {
+ &s->interrupt_callback, NULL) < 0) {
err = AVERROR(EIO);
goto fail;
}
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,
- &s->interrupt_callback) < 0) {
+ &s->interrupt_callback, NULL) < 0) {
err = AVERROR_INVALIDDATA;
goto fail;
}
return AVERROR(EIO);
ret = ffurl_open(&in, s->filename, AVIO_FLAG_READ,
- &s->interrupt_callback);
+ &s->interrupt_callback, NULL);
if (ret)
goto fail;
ff_url_join(url, sizeof(url), "udp", NULL, host, port, "?localport=%d",
port);
- ret = ffurl_open(&sap->ann_fd, url, AVIO_FLAG_READ, &s->interrupt_callback);
+ ret = ffurl_open(&sap->ann_fd, url, AVIO_FLAG_READ,
+ &s->interrupt_callback, NULL);
if (ret)
goto fail;
"?ttl=%d", ttl);
if (!same_port)
base_port += 2;
- ret = ffurl_open(&fd, url, AVIO_FLAG_WRITE, &s->interrupt_callback);
+ ret = ffurl_open(&fd, url, AVIO_FLAG_WRITE, &s->interrupt_callback, NULL);
if (ret) {
ret = AVERROR(EIO);
goto fail;
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, &s->interrupt_callback);
+ ret = ffurl_open(&sap->ann_fd, url, AVIO_FLAG_WRITE,
+ &s->interrupt_callback, NULL);
if (ret) {
ret = AVERROR(EIO);
goto fail;
freeaddrinfo(ai);
}
- ret = ffurl_open(&c->tcp, buf, AVIO_FLAG_READ_WRITE, &h->interrupt_callback);
+ ret = ffurl_open(&c->tcp, buf, AVIO_FLAG_READ_WRITE,
+ &h->interrupt_callback, NULL);
if (ret)
goto fail;
c->fd = ffurl_get_file_handle(c->tcp);
#include "avio.h"
#include "libavformat/version.h"
+#include "libavutil/dict.h"
+
#if !FF_API_OLD_AVIO
#define URL_PROTOCOL_FLAG_NESTED_SCHEME 1 /*< The protocol name can be the first part of a nested protocol scheme */
typedef struct URLProtocol {
const char *name;
int (*url_open)( URLContext *h, const char *url, int flags);
+ /**
+ * This callback is to be used by protocols which open further nested
+ * protocols. options are then to be passed to ffurl_open()/ffurl_connect()
+ * for those nested protocols.
+ */
+ int (*url_open2)(URLContext *h, const char *url, int flags, AVDictionary **options);
int (*url_read)( URLContext *h, unsigned char *buf, int size);
int (*url_write)(URLContext *h, const unsigned char *buf, int size);
int64_t (*url_seek)( URLContext *h, int64_t pos, int whence);
/**
* Connect an URLContext that has been allocated by ffurl_alloc
+ *
+ * @param options A dictionary filled with options for nested protocols,
+ * i.e. it will be passed to url_open2() for protocols implementing it.
+ * This parameter will be destroyed and replaced with a dict containing options
+ * that were not found. May be NULL.
*/
-int ffurl_connect(URLContext *uc);
+int ffurl_connect(URLContext *uc, AVDictionary **options);
/**
* Create an URLContext for accessing to the resource indicated by
* is to be opened
* @param int_cb interrupt callback to use for the URLContext, may be
* NULL
+ * @param options A dictionary filled with protocol-private options. On return
+ * this parameter will be destroyed and replaced with a dict containing options
+ * that were not found. 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,
- const AVIOInterruptCB *int_cb);
+ const AVIOInterruptCB *int_cb, AVDictionary **options);
/**
* Read up to size bytes from the resource accessed by h, and store