]> git.sesse.net Git - ffmpeg/commitdiff
h264: discard slices of redundant pictures right after parsing the slice header
authorAnton Khirnov <anton@khirnov.net>
Fri, 20 May 2016 10:30:42 +0000 (12:30 +0200)
committerAnton Khirnov <anton@khirnov.net>
Tue, 21 Jun 2016 09:20:26 +0000 (11:20 +0200)
Going through the whole decoder initialization process for a slice we
are not going to decode is unnecessary and potentially dangerous.

libavcodec/h264_slice.c
libavcodec/h264dec.c

index dbff1f3f8b611ba403b4b7188be074b515fbcec1..491039626e92bc4f201b4ed5506674e54282a0f2 100644 (file)
@@ -1565,6 +1565,10 @@ int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl,
     if (ret < 0)
         return ret;
 
+    // discard redundant pictures
+    if (sl->redundant_pic_count > 0)
+        return 0;
+
     if (!h->setup_finished) {
         if (sl->first_mb_addr == 0) { // FIXME better field boundary detection
             if (h->current_slice && h->cur_pic_ptr && FIELD_PICTURE(h)) {
index b98d1416c11f79f381a6b84a33dbed067c75b704..38ecc9477fb44b3d15c04d214c2793de7c217f4e 100644 (file)
@@ -701,6 +701,9 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size)
             if ((err = ff_h264_decode_slice_header(h, sl, nal)))
                 break;
 
+            if (sl->redundant_pic_count > 0)
+                break;
+
             if (h->sei.recovery_point.recovery_frame_cnt >= 0 && h->recovery_frame < 0) {
                 h->recovery_frame = (h->poc.frame_num + h->sei.recovery_point.recovery_frame_cnt) &
                                     ((1 << h->ps.sps->log2_max_frame_num) - 1);
@@ -724,8 +727,7 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size)
                     decode_postinit(h, i >= nals_needed);
             }
 
-            if (sl->redundant_pic_count == 0 &&
-                (avctx->skip_frame < AVDISCARD_NONREF || nal->ref_idc) &&
+            if ((avctx->skip_frame < AVDISCARD_NONREF || nal->ref_idc) &&
                 (avctx->skip_frame < AVDISCARD_BIDIR  ||
                  sl->slice_type_nos != AV_PICTURE_TYPE_B) &&
                 (avctx->skip_frame < AVDISCARD_NONKEY ||