Browse code

lavf/avio: Introduce avio_find_protocol_name

Make it possible to find out what protocol will be chosen
for a given URL.

Signed-off-by: Alexander Strasser <eclipse7@gmx.net>

Alexander Strasser authored on 2014/01/05 10:11:18
Showing 3 changed files
... ...
@@ -215,18 +215,12 @@ int ffurl_connect(URLContext *uc, AVDictionary **options)
215 215
     "ABCDEFGHIJKLMNOPQRSTUVWXYZ"                \
216 216
     "0123456789+-."
217 217
 
218
-int ffurl_alloc(URLContext **puc, const char *filename, int flags,
219
-                const AVIOInterruptCB *int_cb)
218
+static struct URLProtocol *url_find_protocol(const char *filename)
220 219
 {
221 220
     URLProtocol *up = NULL;
222 221
     char proto_str[128], proto_nested[128], *ptr;
223 222
     size_t proto_len = strspn(filename, URL_SCHEME_CHARS);
224 223
 
225
-    if (!first_protocol) {
226
-        av_log(NULL, AV_LOG_WARNING, "No URL Protocols are registered. "
227
-                                     "Missing call to av_register_all()?\n");
228
-    }
229
-
230 224
     if (filename[proto_len] != ':' &&
231 225
         (filename[proto_len] != ',' || !strchr(filename + proto_len + 1, ':')) ||
232 226
         is_dos_path(filename))
... ...
@@ -243,13 +237,31 @@ int ffurl_alloc(URLContext **puc, const char *filename, int flags,
243 243
 
244 244
     while (up = ffurl_protocol_next(up)) {
245 245
         if (!strcmp(proto_str, up->name))
246
-            return url_alloc_for_protocol(puc, up, filename, flags, int_cb);
246
+            break;
247 247
         if (up->flags & URL_PROTOCOL_FLAG_NESTED_SCHEME &&
248 248
             !strcmp(proto_nested, up->name))
249
-            return url_alloc_for_protocol(puc, up, filename, flags, int_cb);
249
+            break;
250 250
     }
251
+
252
+    return up;
253
+}
254
+
255
+int ffurl_alloc(URLContext **puc, const char *filename, int flags,
256
+                const AVIOInterruptCB *int_cb)
257
+{
258
+    URLProtocol *p = NULL;
259
+
260
+    if (!first_protocol) {
261
+        av_log(NULL, AV_LOG_WARNING, "No URL Protocols are registered. "
262
+                                     "Missing call to av_register_all()?\n");
263
+    }
264
+
265
+    p = url_find_protocol(filename);
266
+    if (p)
267
+       return url_alloc_for_protocol(puc, p, filename, flags, int_cb);
268
+
251 269
     *puc = NULL;
252
-    if (!strcmp("https", proto_str))
270
+    if (av_strstart("https:", filename, NULL))
253 271
         av_log(NULL, AV_LOG_WARNING, "https protocol not found, recompile with openssl or gnutls enabled.\n");
254 272
     return AVERROR_PROTOCOL_NOT_FOUND;
255 273
 }
... ...
@@ -376,6 +388,13 @@ int ffurl_close(URLContext *h)
376 376
 }
377 377
 
378 378
 
379
+const char *avio_find_protocol_name(const char *url)
380
+{
381
+    URLProtocol *p = url_find_protocol(url);
382
+
383
+    return p ? p->name : NULL;
384
+}
385
+
379 386
 int avio_check(const char *url, int flags)
380 387
 {
381 388
     URLContext *h;
... ...
@@ -151,6 +151,15 @@ typedef struct AVIOContext {
151 151
 /* unbuffered I/O */
152 152
 
153 153
 /**
154
+ * Return the name of the protocol that will handle the passed URL.
155
+ *
156
+ * NULL is returned if no protocol could be found for the given URL.
157
+ *
158
+ * @return Name of the protocol or NULL.
159
+ */
160
+const char *avio_find_protocol_name(const char *url);
161
+
162
+/**
154 163
  * Return AVIO_FLAG_* access flags corresponding to the access permissions
155 164
  * of the resource in url, or a negative value corresponding to an
156 165
  * AVERROR code in case of failure. The returned access flags are
... ...
@@ -30,8 +30,8 @@
30 30
 #include "libavutil/version.h"
31 31
 
32 32
 #define LIBAVFORMAT_VERSION_MAJOR 55
33
-#define LIBAVFORMAT_VERSION_MINOR 32
34
-#define LIBAVFORMAT_VERSION_MICRO 101
33
+#define LIBAVFORMAT_VERSION_MINOR 33
34
+#define LIBAVFORMAT_VERSION_MICRO 100
35 35
 
36 36
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
37 37
                                                LIBAVFORMAT_VERSION_MINOR, \