@@ -786,7 +786,7 @@ int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer);
*
* @return A static string containing the name of current protocol or NULL
*/
-const char *avio_enum_protocols(void **opaque, int output);
+const char *avio_enum_protocols(void **const opaque, const int output);
/**
* Get AVClass by names of available protocols.
@@ -91,19 +91,35 @@ const AVClass *ff_urlcontext_child_class_iterate(void **iter)
return ret;
}
-const char *avio_enum_protocols(void **opaque, int output)
+#define AVIO_ENUM_PROTOCOLS(METHOD) \
+ typedef const URLProtocol *const *Iterator; \
+ for (Iterator p = *opaque ? (Iterator)(*opaque) + 1 : url_protocols; *p; ++p) { \
+ if ((*p)->METHOD) { \
+ *opaque = (void *)p; \
+ return (*p)->name; \
+ } \
+ } \
+ *opaque = NULL; \
+ return NULL;
+
+static inline
+const char *avio_enum_protocols_for_output(void **const opaque)
{
- const URLProtocol *const *p = *opaque;
+ AVIO_ENUM_PROTOCOLS(url_write);
+}
- p = p ? p + 1 : url_protocols;
- *opaque = (void *)p;
- if (!*p) {
- *opaque = NULL;
- return NULL;
- }
- if ((output && (*p)->url_write) || (!output && (*p)->url_read))
- return (*p)->name;
- return avio_enum_protocols(opaque, output);
+static inline
+const char *avio_enum_protocols_for_input(void **const opaque)
+{
+ AVIO_ENUM_PROTOCOLS(url_read);
+}
+
+const char *avio_enum_protocols(void **const opaque, const int output)
+{
+ if (output)
+ return avio_enum_protocols_for_output(opaque);
+ else
+ return avio_enum_protocols_for_input(opaque);
}
const AVClass *avio_protocol_get_class(const char *name)