summaryrefslogtreecommitdiff
path: root/libavformat/avio.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2011-11-05 10:04:04 +0100
committerAnton Khirnov <anton@khirnov.net>2011-11-13 13:14:39 +0100
commitddffc2fdc351d60ca190b016cccff4acff27823f (patch)
treebabe7cbc4ebf1c48d680236cafdcb82999e64945 /libavformat/avio.c
parent163a31136dcb0b5966fc779917e0408cb52d7295 (diff)
avio: add support for passing options to protocols.
Not used anywhere yet, support for passing options from avio_open() will follow.
Diffstat (limited to 'libavformat/avio.c')
-rw-r--r--libavformat/avio.c55
1 files changed, 46 insertions, 9 deletions
diff --git a/libavformat/avio.c b/libavformat/avio.c
index 06972cdbdd..330d52cfec 100644
--- a/libavformat/avio.c
+++ b/libavformat/avio.c
@@ -22,6 +22,7 @@
#include <unistd.h>
#include "libavutil/avstring.h"
+#include "libavutil/dict.h"
#include "libavutil/opt.h"
#include "os_support.h"
#include "avformat.h"
@@ -45,12 +46,40 @@ static const char *urlcontext_to_name(void *ptr)
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,
};
/*@}*/
@@ -133,9 +162,13 @@ static int url_alloc_for_protocol (URLContext **puc, struct URLProtocol *up,
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;
@@ -156,7 +189,7 @@ int url_open_protocol (URLContext **puc, struct URLProtocol *up,
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:
@@ -170,11 +203,11 @@ int url_alloc(URLContext **puc, const char *filename, int flags)
}
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)
{
@@ -255,14 +288,18 @@ int ffurl_alloc(URLContext **puc, const char *filename, int flags,
}
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;
@@ -356,7 +393,7 @@ int ffurl_close(URLContext *h)
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;
@@ -373,7 +410,7 @@ int avio_check(const char *url, int flags)
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;
}