hc
2023-11-20 2e7bd41e4e8ab3d1efdabd9e263a2f7fe79bff8c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
From 7b677a25ac08940b78bf7d24908ae76757c60475 Mon Sep 17 00:00:00 2001
From: Hertz Wang <wangh@rock-chips.com>
Date: Mon, 29 Oct 2018 11:28:40 +0800
Subject: [PATCH 01/11] find_codec prefer hardware capability
 
Change-Id: Ib885af15b8942ea13cc1e944ab84ecb6b939ac70
Signed-off-by: Hertz Wang <wangh@rock-chips.com>
---
 libavcodec/allcodecs.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
 
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 1b8144a..a8fa898 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -853,7 +853,7 @@ static enum AVCodecID remap_deprecated_codec_id(enum AVCodecID id)
 
 static AVCodec *find_codec(enum AVCodecID id, int (*x)(const AVCodec *))
 {
-    const AVCodec *p, *experimental = NULL;
+    const AVCodec *p, *experimental = NULL, *first = NULL;
     void *i = 0;
 
     id = remap_deprecated_codec_id(id);
@@ -864,12 +864,17 @@ static AVCodec *find_codec(enum AVCodecID id, int (*x)(const AVCodec *))
         if (p->id == id) {
             if (p->capabilities & AV_CODEC_CAP_EXPERIMENTAL && !experimental) {
                 experimental = p;
-            } else
-                return (AVCodec*)p;
+            } else {
+                if (!first)
+                    first = p;
+                // prefer hardware
+                if (p->capabilities & AV_CODEC_CAP_HARDWARE)
+                    return (AVCodec*)p;
+            }
         }
     }
 
-    return (AVCodec*)experimental;
+    return first ? (AVCodec*)first : (AVCodec*)experimental;
 }
 
 AVCodec *avcodec_find_encoder(enum AVCodecID id)
-- 
2.7.4