diff mbox series

[FFmpeg-devel] accelerate h2645 nalu start code finding

Message ID tencent_859A1C86D1006ECBD7CD10DF0075B178F406@qq.com
State New
Headers show
Series [FFmpeg-devel] accelerate h2645 nalu start code finding | expand

Checks

Context Check Description
andriy/commit_msg_x86 warning The first line of the commit message must start with a context terminated by a colon and a space, for example "lavu/opt: " or "doc: ".
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/commit_msg_ppc warning The first line of the commit message must start with a context terminated by a colon and a space, for example "lavu/opt: " or "doc: ".
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Lingjiang Fang Dec. 9, 2021, 2:54 a.m. UTC
---
 libavcodec/h2645_parse.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

refer from webrtc h264 parser
diff mbox series

Patch

diff --git a/libavcodec/h2645_parse.c b/libavcodec/h2645_parse.c
index 6fbe97ad4a..e372d2a27b 100644
--- a/libavcodec/h2645_parse.c
+++ b/libavcodec/h2645_parse.c
@@ -330,16 +330,25 @@  static int h264_parse_nal_header(H2645NAL *nal, void *logctx)
 static int find_next_start_code(const uint8_t *buf, const uint8_t *next_avc)
 {
     int i = 0;
+    const uint8_t *end = NULL;
 
     if (buf + 3 >= next_avc)
         return next_avc - buf;
 
-    while (buf + i + 3 < next_avc) {
-        if (buf[i] == 0 && buf[i + 1] == 0 && buf[i + 2] == 1)
-            break;
-        i++;
+    end = next_avc - 3;
+    while (buf + i < end) {
+        if (buf[i + 2] > 1) {
+            i += 3;
+        } else if (buf[i + 2] == 1) {
+            if (buf[i + 1] == 0 && buf[i] == 0) {
+                break;
+            }
+            i += 3;
+        } else {
+            ++i;
+        }
     }
-    return i + 3;
+    return (buf + i + 3 > next_avc)? next_avc - buf : i + 3;
 }
 
 static void alloc_rbsp_buffer(H2645RBSP *rbsp, unsigned int size, int use_ref)