Browse code

avcodec/hevc_parser: fix split function of parser

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>

Rainer Hochecker authored on 2015/09/01 23:27:02
Showing 1 changed files
... ...
@@ -410,19 +410,30 @@ static int hevc_split(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
410 410
 {
411 411
     const uint8_t *ptr = buf, *end = buf + buf_size;
412 412
     uint32_t state = -1;
413
-    int has_ps = 0, nut;
413
+    int has_vps = 0;
414
+    int has_sps = 0;
415
+    int has_pps = 0;
416
+    int nut;
414 417
 
415 418
     while (ptr < end) {
416 419
         ptr = avpriv_find_start_code(ptr, end, &state);
417 420
         if ((state >> 8) != START_CODE)
418 421
             break;
419 422
         nut = (state >> 1) & 0x3F;
420
-        if (nut >= NAL_VPS && nut <= NAL_PPS)
421
-            has_ps = 1;
422
-        else if (has_ps)
423
-            return ptr - 4 - buf;
424
-        else // no parameter set at the beginning of the stream
425
-            return 0;
423
+        if (nut == NAL_VPS)
424
+            has_vps = 1;
425
+        else if (nut == NAL_SPS)
426
+            has_sps = 1;
427
+        else if (nut == NAL_PPS)
428
+            has_pps = 1;
429
+        else if ((nut != NAL_SEI_PREFIX || has_pps) &&
430
+                  nut != NAL_AUD) {
431
+            if (has_vps && has_sps) {
432
+                while (ptr - 4 > buf && ptr[-5] == 0)
433
+                    ptr--;
434
+                return ptr - 4 - buf;
435
+            }
436
+        }
426 437
     }
427 438
     return 0;
428 439
 }