From 2758cdedfb7ac61f8b5e4861f99218b6fd43491d Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 19 Feb 2016 10:39:29 +0100 Subject: lavf: reorganize URLProtocols Instead of a linked list constructed at av_register_all(), store them in a constant array of pointers. Since no registration is necessary now, this removes some global state from lavf. This will also allow the urlprotocol layer caller to limit the available protocols in a simple and flexible way in the following commits. --- libavformat/avio.c | 54 ++++++++++++++++++++++-------------------------------- 1 file changed, 22 insertions(+), 32 deletions(-) (limited to 'libavformat/avio.c') diff --git a/libavformat/avio.c b/libavformat/avio.c index ff740a28b7..00c111a059 100644 --- a/libavformat/avio.c +++ b/libavformat/avio.c @@ -30,13 +30,6 @@ #endif #include "url.h" -static URLProtocol *first_protocol = NULL; - -URLProtocol *ffurl_protocol_next(const URLProtocol *prev) -{ - return prev ? prev->next : first_protocol; -} - /** @name Logging context. */ /*@{*/ static const char *urlcontext_to_name(void *ptr) @@ -58,17 +51,20 @@ static void *urlcontext_child_next(void *obj, void *prev) static const AVClass *urlcontext_child_class_next(const AVClass *prev) { - URLProtocol *p = NULL; + int i; /* find the protocol that corresponds to prev */ - while (prev && (p = ffurl_protocol_next(p))) - if (p->priv_data_class == prev) + for (i = 0; ff_url_protocols[i]; i++) { + if (ff_url_protocols[i]->priv_data_class == prev) { + i++; break; + } + } /* find next protocol with priv options */ - while (p = ffurl_protocol_next(p)) - if (p->priv_data_class) - return p->priv_data_class; + for (; ff_url_protocols[i]; i++) + if (ff_url_protocols[i]->priv_data_class) + return ff_url_protocols[i]->priv_data_class; return NULL; } @@ -85,27 +81,20 @@ const AVClass ffurl_context_class = { const char *avio_enum_protocols(void **opaque, int output) { - URLProtocol *p; - *opaque = ffurl_protocol_next(*opaque); - if (!(p = *opaque)) + const URLProtocol **p = *opaque; + + p = p ? p + 1 : ff_url_protocols; + *opaque = p; + if (!*p) { + *opaque = NULL; return NULL; - if ((output && p->url_write) || (!output && p->url_read)) - return p->name; + } + if ((output && (*p)->url_write) || (!output && (*p)->url_read)) + return (*p)->name; return avio_enum_protocols(opaque, output); } -int ffurl_register_protocol(URLProtocol *protocol) -{ - URLProtocol **p; - p = &first_protocol; - while (*p) - p = &(*p)->next; - *p = protocol; - protocol->next = NULL; - return 0; -} - -static int url_alloc_for_protocol(URLContext **puc, struct URLProtocol *up, +static int url_alloc_for_protocol(URLContext **puc, const URLProtocol *up, const char *filename, int flags, const AVIOInterruptCB *int_cb) { @@ -183,9 +172,9 @@ int ffurl_connect(URLContext *uc, AVDictionary **options) int ffurl_alloc(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb) { - URLProtocol *up = NULL; char proto_str[128], proto_nested[128], *ptr; size_t proto_len = strspn(filename, URL_SCHEME_CHARS); + int i; if (filename[proto_len] != ':' || is_dos_path(filename)) strcpy(proto_str, "file"); @@ -197,7 +186,8 @@ int ffurl_alloc(URLContext **puc, const char *filename, int flags, if ((ptr = strchr(proto_nested, '+'))) *ptr = '\0'; - while (up = ffurl_protocol_next(up)) { + for (i = 0; ff_url_protocols[i]; i++) { + const URLProtocol *up = ff_url_protocols[i]; if (!strcmp(proto_str, up->name)) return url_alloc_for_protocol(puc, up, filename, flags, int_cb); if (up->flags & URL_PROTOCOL_FLAG_NESTED_SCHEME && -- cgit v1.2.3