[FFmpeg-devel] [PATCH 04/22] avcodec/dovi_rpuenc: eliminate unnecessary loop

Niklas Haas ffmpeg at haasn.xyz
Sun Jul 28 13:25:09 EEST 2024


From: Niklas Haas <git at haasn.dev>

This struct itself contains vdr_rpu_id, so we can never match it except
in the case of i == vdr_rpu_id. So just directly use this ID.
---
 libavcodec/dovi_rpuenc.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/libavcodec/dovi_rpuenc.c b/libavcodec/dovi_rpuenc.c
index f0cfecc91b..63cbde8718 100644
--- a/libavcodec/dovi_rpuenc.c
+++ b/libavcodec/dovi_rpuenc.c
@@ -463,16 +463,7 @@ int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata,
         return AVERROR_INVALIDDATA;
     }
 
-    vdr_rpu_id = -1;
-    for (int i = 0; i <= DOVI_MAX_DM_ID; i++) {
-        if (s->vdr[i] && !memcmp(s->vdr[i], mapping, sizeof(*mapping))) {
-            vdr_rpu_id = i;
-            break;
-        } else if (vdr_rpu_id < 0 && (!s->vdr[i] || i == DOVI_MAX_DM_ID)) {
-            vdr_rpu_id = i;
-        }
-    }
-
+    vdr_rpu_id = mapping->vdr_rpu_id;
     if (!s->vdr[vdr_rpu_id]) {
         s->vdr[vdr_rpu_id] = ff_refstruct_allocz(sizeof(AVDOVIDataMapping));
         if (!s->vdr[vdr_rpu_id])
-- 
2.45.2



More information about the ffmpeg-devel mailing list