diff mbox

[FFmpeg-devel,4/8] avdevice/lavfi: remove access of AV_PIX_FMT_NB

Message ID 20191230135419.56529-4-quinkblack@foxmail.com
State New
Headers show

Commit Message

zhilizhao Dec. 30, 2019, 1:54 p.m. UTC
From: Zhao Zhili <zhilizhao@tencent.com>

---
 libavdevice/lavfi.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)
diff mbox

Patch

diff --git a/libavdevice/lavfi.c b/libavdevice/lavfi.c
index c949ff7e12..fc2336d8fe 100644
--- a/libavdevice/lavfi.c
+++ b/libavdevice/lavfi.c
@@ -59,24 +59,28 @@  typedef struct {
     AVPacket subcc_packet;
 } LavfiContext;
 
-static int *create_all_formats(int n)
+static int *create_all_formats()
 {
-    int i, j, *fmts, count = 0;
+    int i, *fmts, count = 0;
+    const AVPixFmtDescriptor *desc;
 
-    for (i = 0; i < n; i++) {
-        const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(i);
+    desc = NULL;
+    while ((desc = av_pix_fmt_desc_next(desc))) {
         if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL))
             count++;
     }
 
     if (!(fmts = av_malloc((count+1) * sizeof(int))))
         return NULL;
-    for (j = 0, i = 0; i < n; i++) {
-        const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(i);
-        if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL))
-            fmts[j++] = i;
+
+    desc = NULL;
+    i = 0;
+    while ((desc = av_pix_fmt_desc_next(desc))) {
+        if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL)) {
+            fmts[i++] = av_pix_fmt_desc_get_id(desc);
+        }
     }
-    fmts[j] = -1;
+    fmts[i] = AV_PIX_FMT_NONE;
     return fmts;
 }
 
@@ -121,7 +125,7 @@  av_cold static int lavfi_read_header(AVFormatContext *avctx)
     LavfiContext *lavfi = avctx->priv_data;
     AVFilterInOut *input_links = NULL, *output_links = NULL, *inout;
     const AVFilter *buffersink, *abuffersink;
-    int *pix_fmts = create_all_formats(AV_PIX_FMT_NB);
+    int *pix_fmts = create_all_formats();
     enum AVMediaType type;
     int ret = 0, i, n;