diff mbox series

[FFmpeg-devel,2/3] libavdevice: Update to new iterating API

Message ID 2e05ebebedefffda637f1703adb3dfa8fca25ed0.1589014205.git.gang.zhao.42@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/3] avformat: Correctly check the list before accessing
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Zhao, Gang May 9, 2020, 8:50 a.m. UTC
Signed-off-by: Zhao, Gang <gang.zhao.42@gmail.com>
---
 libavdevice/avdevice.c | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git libavdevice/avdevice.c libavdevice/avdevice.c
index 3d03d89f04..8c1b296d71 100644
--- libavdevice/avdevice.c
+++ libavdevice/avdevice.c
@@ -83,16 +83,33 @@  static void *device_next(void *prev, int output,
 {
     const AVClass *pc;
     AVClassCategory category = AV_CLASS_CATEGORY_NA;
+    void *opaque = NULL;
+    void *orig_prev = prev;
+    int found_prev = 0;
+
     do {
-        if (output) {
-            if (!(prev = av_oformat_next(prev)))
-                break;
+        if (output)
+            prev = (void *)av_muxer_iterate(&opaque);
+        else
+            prev = (void *)av_demuxer_iterate(&opaque);
+
+        if (!prev)
+            break;
+
+        /* if orig_prev is NULL, start from the first muxer/demuxer */
+        orig_prev = orig_prev ? orig_prev : prev;
+
+        if (!found_prev) {
+            if (orig_prev == prev)
+                found_prev = 1;
+            continue;
+        }
+
+        if (output)
             pc = ((AVOutputFormat *)prev)->priv_class;
-        } else {
-            if (!(prev = av_iformat_next(prev)))
-                break;
+        else
             pc = ((AVInputFormat *)prev)->priv_class;
-        }
+
         if (!pc)
             continue;
         category = pc->category;