]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/h264_ps.c
Merge commit '2080bea4a74b6b1598caa806a11ea807ba546f94'
[ffmpeg] / libavcodec / h264_ps.c
index e37a6d62fa55ea894d443e94b6fb6315099bfd8c..0bca9c1a808b2068518c2ca2cb845bdadbb09a26 100644 (file)
@@ -107,6 +107,26 @@ static const uint8_t default_scaling8[2][64] = {
       24, 25, 27, 28, 30, 32, 33, 35 }
 };
 
+/* maximum number of MBs in the DPB for a given level */
+static const int level_max_dpb_mbs[][2] = {
+    { 10, 396       },
+    { 11, 900       },
+    { 12, 2376      },
+    { 13, 2376      },
+    { 20, 2376      },
+    { 21, 4752      },
+    { 22, 8100      },
+    { 30, 8100      },
+    { 31, 18000     },
+    { 32, 20480     },
+    { 40, 32768     },
+    { 41, 32768     },
+    { 42, 34816     },
+    { 50, 110400    },
+    { 51, 184320    },
+    { 52, 184320    },
+};
+
 static inline int decode_hrd_parameters(H264Context *h, SPS *sps)
 {
     int cpb_count, i;
@@ -535,6 +555,19 @@ int ff_h264_decode_seq_parameter_set(H264Context *h, int ignore_truncation)
             goto fail;
     }
 
+    /* if the maximum delay is not stored in the SPS, derive it based on the
+     * level */
+    if (!sps->bitstream_restriction_flag) {
+        sps->num_reorder_frames = MAX_DELAYED_PIC_COUNT - 1;
+        for (i = 0; i < FF_ARRAY_ELEMS(level_max_dpb_mbs); i++) {
+            if (level_max_dpb_mbs[i][0] == sps->level_idc) {
+                sps->num_reorder_frames = FFMIN(level_max_dpb_mbs[i][1] / (sps->mb_width * sps->mb_height),
+                                                sps->num_reorder_frames);
+                break;
+            }
+        }
+    }
+
     if (!sps->sar.den)
         sps->sar.den = 1;