summaryrefslogtreecommitdiff
path: root/libavcodec/h264_ps.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2015-10-20 19:04:57 +0200
committerAnton Khirnov <anton@khirnov.net>2015-12-06 09:43:52 +0100
commitb09ad37c83841c399abb7f2503a2ab214d0c2d48 (patch)
tree8c174f11e24e1cf75faf5c3fa044c70e4c84266f /libavcodec/h264_ps.c
parent792b9c9dfcf44b657d7854368d975b5ca3bc22ca (diff)
h264: derive the delay from the level when it's not present
Fall back to maximum DPB size if the level is unknown. This should be more spec-compliant and does not depend on the caller setting has_b_frames before opening the decoder. The old behaviour, when the delay is supplied by the caller setting has_b_frames, can still be obtained by setting strict_std_compliance below normal.
Diffstat (limited to 'libavcodec/h264_ps.c')
-rw-r--r--libavcodec/h264_ps.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/libavcodec/h264_ps.c b/libavcodec/h264_ps.c
index fa9fa7d25b..6b29966875 100644
--- a/libavcodec/h264_ps.c
+++ b/libavcodec/h264_ps.c
@@ -105,6 +105,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;
@@ -501,6 +521,19 @@ int ff_h264_decode_seq_parameter_set(H264Context *h)
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;