Imported Upstream version 6.1
[platform/upstream/ffmpeg.git] / libavformat / protocols.c
index f1b8eab..360018b 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "config.h"
+#include <string.h>
 
 #include "libavutil/avstring.h"
+#include "libavutil/log.h"
 #include "libavutil/mem.h"
 
 #include "url.h"
@@ -27,13 +28,16 @@ extern const URLProtocol ff_async_protocol;
 extern const URLProtocol ff_bluray_protocol;
 extern const URLProtocol ff_cache_protocol;
 extern const URLProtocol ff_concat_protocol;
+extern const URLProtocol ff_concatf_protocol;
 extern const URLProtocol ff_crypto_protocol;
 extern const URLProtocol ff_data_protocol;
+extern const URLProtocol ff_fd_protocol;
 extern const URLProtocol ff_ffrtmpcrypt_protocol;
 extern const URLProtocol ff_ffrtmphttp_protocol;
 extern const URLProtocol ff_file_protocol;
 extern const URLProtocol ff_ftp_protocol;
 extern const URLProtocol ff_gopher_protocol;
+extern const URLProtocol ff_gophers_protocol;
 extern const URLProtocol ff_hls_protocol;
 extern const URLProtocol ff_http_protocol;
 extern const URLProtocol ff_httpproxy_protocol;
@@ -61,6 +65,7 @@ extern const URLProtocol ff_udp_protocol;
 extern const URLProtocol ff_udplite_protocol;
 extern const URLProtocol ff_unix_protocol;
 extern const URLProtocol ff_libamqp_protocol;
+extern const URLProtocol ff_librist_protocol;
 extern const URLProtocol ff_librtmp_protocol;
 extern const URLProtocol ff_librtmpe_protocol;
 extern const URLProtocol ff_librtmps_protocol;
@@ -70,42 +75,39 @@ extern const URLProtocol ff_libsrt_protocol;
 extern const URLProtocol ff_libssh_protocol;
 extern const URLProtocol ff_libsmbclient_protocol;
 extern const URLProtocol ff_libzmq_protocol;
+extern const URLProtocol ff_ipfs_gateway_protocol;
+extern const URLProtocol ff_ipns_gateway_protocol;
 
 #include "libavformat/protocol_list.c"
 
-const AVClass *ff_urlcontext_child_class_next(const AVClass *prev)
+const AVClass *ff_urlcontext_child_class_iterate(void **iter)
 {
-    int i;
+    const AVClass *ret = NULL;
+    uintptr_t i;
 
-    /* find the protocol that corresponds to prev */
-    for (i = 0; prev && url_protocols[i]; i++) {
-        if (url_protocols[i]->priv_data_class == prev) {
-            i++;
+    for (i = (uintptr_t)*iter; url_protocols[i]; i++) {
+        ret = url_protocols[i]->priv_data_class;
+        if (ret)
             break;
-        }
     }
 
-    /* find next protocol with priv options */
-    for (; url_protocols[i]; i++)
-        if (url_protocols[i]->priv_data_class)
-            return url_protocols[i]->priv_data_class;
-    return NULL;
+    *iter = (void*)(uintptr_t)(url_protocols[i] ? i + 1 : i);
+    return ret;
 }
 
-
 const char *avio_enum_protocols(void **opaque, int output)
 {
-    const URLProtocol **p = *opaque;
+    uintptr_t i;
 
-    p = p ? p + 1 : url_protocols;
-    *opaque = p;
-    if (!*p) {
-        *opaque = NULL;
-        return NULL;
+    for (i = (uintptr_t)*opaque; url_protocols[i]; i++) {
+        const URLProtocol *p = url_protocols[i];
+        if ((output && p->url_write) || (!output && p->url_read)) {
+            *opaque = (void*)(uintptr_t)(i + 1);
+            return p->name;
+        }
     }
-    if ((output && (*p)->url_write) || (!output && (*p)->url_read))
-        return (*p)->name;
-    return avio_enum_protocols(opaque, output);
+    *opaque = NULL;
+    return NULL;
 }
 
 const AVClass *avio_protocol_get_class(const char *name)
@@ -124,7 +126,7 @@ const URLProtocol **ffurl_get_protocols(const char *whitelist,
     const URLProtocol **ret;
     int i, ret_idx = 0;
 
-    ret = av_mallocz_array(FF_ARRAY_ELEMS(url_protocols), sizeof(*ret));
+    ret = av_calloc(FF_ARRAY_ELEMS(url_protocols), sizeof(*ret));
     if (!ret)
         return NULL;