* minimizes diff due to cosmetic changes
 * reorders get_nal_start and get_nalsize to match the original if/else
   and directly break after get_nal_start at the end of buffer instead
   of calling get_nalsize.
 * rename get_nal_start -> find_start_code and
          get_nalsize   -> get_avc_nalsize

nice cleanup, ok with this squashed.
---
 libavcodec/h264.c | 39 +++++++++++++++++++++------------------
 1 file changed, 21 insertions(+), 18 deletions(-)

diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index 4c432ae..c4ce278 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -1281,8 +1281,8 @@ int ff_set_ref_count(H264Context *h)
     return 0;
 }
 
-static int get_nal_start(const uint8_t *buf, int buf_size,
-                         int buf_index, int next_avc)
+static int find_start_code(const uint8_t *buf, int buf_size,
+                           int buf_index, int next_avc)
 {
     // start code prefix search
     for (; buf_index + 3 < next_avc; buf_index++)
@@ -1298,8 +1298,8 @@ static int get_nal_start(const uint8_t *buf, int buf_size,
     return buf_index + 3;
 }
 
-static int get_nalsize(H264Context *h, const uint8_t *buf,
-                       int buf_size, int *buf_index)
+static int get_avc_nalsize(H264Context *h, const uint8_t *buf,
+                           int buf_size, int *buf_index)
 {
     int i, nalsize = 0;
 
@@ -1347,14 +1347,15 @@ static int get_last_needed_nal(H264Context *h, const 
uint8_t *buf, int buf_size)
         int dst_length, bit_length, consumed;
         const uint8_t *ptr;
 
-        if (buf_index < next_avc)
-            buf_index = get_nal_start(buf, buf_size, buf_index, next_avc);
-
         if (buf_index >= next_avc) {
-            nalsize = get_nalsize(h, buf, buf_size, &buf_index);
+            nalsize = get_avc_nalsize(h, buf, buf_size, &buf_index);
             if (nalsize < 0)
                 break;
             next_avc = buf_index + nalsize;
+        } else {
+            buf_index = find_start_code(buf, buf_size, buf_index, next_avc);
+            if (buf_index >= buf_size)
+                break;
         }
 
         ptr = ff_h264_decode_nal(h, buf + buf_index, &dst_length, &consumed,
@@ -1397,8 +1398,9 @@ static int decode_nal_units(H264Context *h, const uint8_t 
*buf, int buf_size,
     H264Context *hx; ///< thread context
     int buf_index;
     unsigned context_count;
-    int next_avc, nal_index;
+    int next_avc;
     int nals_needed = 0; ///< number of NALs that need decoding before the 
next frame thread starts
+    int nal_index;
     int ret = 0;
 
     h->max_contexts = h->slice_context_count;
@@ -1425,14 +1427,15 @@ static int decode_nal_units(H264Context *h, const 
uint8_t *buf, int buf_size,
             int nalsize = 0;
             int err;
 
-            if (buf_index < next_avc)
-                buf_index = get_nal_start(buf, buf_size, buf_index, next_avc);
-
             if (buf_index >= next_avc) {
-                nalsize = get_nalsize(h, buf, buf_size, &buf_index);
+                nalsize = get_avc_nalsize(h, buf, buf_size, &buf_index);
                 if (nalsize < 0)
                     break;
                 next_avc = buf_index + nalsize;
+            } else {
+                buf_index = find_start_code(buf, buf_size, buf_index, 
next_avc);
+                if (buf_index >= buf_size)
+                    break;
             }
 
             hx = h->thread_context[context_count];
@@ -1447,16 +1450,16 @@ static int decode_nal_units(H264Context *h, const 
uint8_t *buf, int buf_size,
             bit_length = get_bit_length(h, buf, ptr, dst_length,
                                         buf_index + consumed, next_avc);
 
-            if (h->is_avc && (nalsize != consumed) && nalsize)
-                av_log(h->avctx, AV_LOG_DEBUG,
-                       "AVC: Consumed only %d bytes instead of %d\n",
-                       consumed, nalsize);
-
             if (h->avctx->debug & FF_DEBUG_STARTCODE)
                 av_log(h->avctx, AV_LOG_DEBUG,
                        "NAL %d at %d/%d length %d\n",
                        hx->nal_unit_type, buf_index, buf_size, dst_length);
 
+            if (h->is_avc && (nalsize != consumed) && nalsize)
+                av_log(h->avctx, AV_LOG_DEBUG,
+                       "AVC: Consumed only %d bytes instead of %d\n",
+                       consumed, nalsize);
+
             buf_index += consumed;
             nal_index++;
 
-- 
1.9.1

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to