diff mbox series

[FFmpeg-devel,3/6] avformat: add support for demuxers/inputs from avradio

Message ID 20230722192957.703-3-michael@niedermayer.cc
State New
Headers show
Series [FFmpeg-devel,1/6] configure: libavradio support | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Michael Niedermayer July 22, 2023, 7:29 p.m. UTC
This avoids keeping diffs for libavformat in the libavradio repository

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavformat/allformats.c | 32 +++++++++++++++++++++++++-------
 libavformat/internal.h   |  1 +
 2 files changed, 26 insertions(+), 7 deletions(-)

Comments

Paul B Mahol July 22, 2023, 8:35 p.m. UTC | #1
NAK
diff mbox series

Patch

diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 6324952bd2..27a32028dd 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -570,6 +570,7 @@  extern const AVInputFormat  ff_vapoursynth_demuxer;
 
 static atomic_uintptr_t indev_list_intptr  = ATOMIC_VAR_INIT(0);
 static atomic_uintptr_t outdev_list_intptr = ATOMIC_VAR_INIT(0);
+static atomic_uintptr_t inradio_list_intptr= ATOMIC_VAR_INIT(0);
 
 const AVOutputFormat *av_muxer_iterate(void **opaque)
 {
@@ -594,20 +595,32 @@  const AVOutputFormat *av_muxer_iterate(void **opaque)
 
 const AVInputFormat *av_demuxer_iterate(void **opaque)
 {
-    static const uintptr_t size = sizeof(demuxer_list)/sizeof(demuxer_list[0]) - 1;
     uintptr_t i = (uintptr_t)*opaque;
     const AVInputFormat *f = NULL;
     uintptr_t tmp;
 
-    if (i < size) {
-        f = demuxer_list[i];
-    } else if (tmp = atomic_load_explicit(&indev_list_intptr, memory_order_relaxed)) {
-        const AVInputFormat *const *indev_list = (const AVInputFormat *const *)tmp;
-        f = indev_list[i - size];
+    if (i % 4 == 0) {
+        f = demuxer_list[i/4];
+        if (!f)
+            i = 1;
+    }
+    if (i % 4 == 1) {
+        if(tmp = atomic_load_explicit(&indev_list_intptr, memory_order_relaxed)) {
+            const AVInputFormat *const *indev_list = (const AVInputFormat *const *)tmp;
+            f = indev_list[i/4];
+        }
+        if (!f)
+            i = 2;
+    }
+    if (i % 4 == 2) {
+        if(tmp = atomic_load_explicit(&inradio_list_intptr, memory_order_relaxed)) {
+            const AVInputFormat *const *indev_list = (const AVInputFormat *const *)tmp;
+            f = indev_list[i/4];
+        }
     }
 
     if (f)
-        *opaque = (void*)(i + 1);
+        *opaque = (void*)(i + 4);
     return f;
 }
 
@@ -616,3 +629,8 @@  void avpriv_register_devices(const FFOutputFormat * const o[], const AVInputForm
     atomic_store_explicit(&outdev_list_intptr, (uintptr_t)o, memory_order_relaxed);
     atomic_store_explicit(&indev_list_intptr,  (uintptr_t)i, memory_order_relaxed);
 }
+
+void avpriv_register_radios(const FFOutputFormat * const o[], const AVInputFormat * const i[])
+{
+    atomic_store_explicit(&inradio_list_intptr,  (uintptr_t)i, memory_order_relaxed);
+}
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 9fc980601f..aa6b8b21a9 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -719,5 +719,6 @@  int ff_match_url_ext(const char *url, const char *extensions);
 
 struct FFOutputFormat;
 void avpriv_register_devices(const struct FFOutputFormat * const o[], const AVInputFormat * const i[]);
+void avpriv_register_radios(const struct FFOutputFormat * const o[], const AVInputFormat * const i[]);
 
 #endif /* AVFORMAT_INTERNAL_H */