[FFmpeg-devel] [PATCH 5/8] avpriv_find_start_code(): replace unnecessary for loop

Scott Theisen scott.the.elm at gmail.com
Tue Feb 1 23:20:53 EET 2022


start_code will still be invalid, i.e. all ones, but will no longer have
up to the first three bytes in p shifted in.
---
 libavcodec/utils.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 54c9dd056d..b4c5fa5009 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -944,19 +944,14 @@ const uint8_t *avpriv_find_start_code(const uint8_t *av_restrict p,
                                       const uint8_t *end,
                                       uint32_t *av_restrict start_code)
 {
-    int i;
+    *start_code = ~0;
 
     av_assert0(p <= end);
-    if (p >= end)
+    // minimum length for a start code
+    if (p + 4 > end)
         return end;
 
-    *start_code = ~0;
-    for (i = 0; i < 3; i++) {
-        uint32_t tmp = *start_code << 8;
-        *start_code = tmp + *(p++);
-        if (tmp == 0x100 || p == end)
-            return p;
-    }
+    p += 3; // offset for negative indices in while loop
 
     /* with memory address increasing left to right, we are looking for (in hexadecimal):
      * 00 00 01 XX
-- 
2.32.0



More information about the ffmpeg-devel mailing list