}
}
-static void decode_scaling_matrices(GetBitContext *gb, SPS *sps,
- PPS *pps, int is_sps,
+/* returns non zero if the provided SPS scaling matrix has been filled */
+static int decode_scaling_matrices(GetBitContext *gb, const SPS *sps,
+ const PPS *pps, int is_sps,
uint8_t(*scaling_matrix4)[16],
uint8_t(*scaling_matrix8)[64])
{
fallback_sps ? sps->scaling_matrix8[0] : default_scaling8[0],
fallback_sps ? sps->scaling_matrix8[3] : default_scaling8[1]
};
+ int ret = 0;
if (get_bits1(gb)) {
- sps->scaling_matrix_present |= is_sps;
+ ret = is_sps;
decode_scaling_list(gb, scaling_matrix4[0], 16, default_scaling4[0], fallback[0]); // Intra, Y
decode_scaling_list(gb, scaling_matrix4[1], 16, default_scaling4[0], scaling_matrix4[0]); // Intra, Cr
decode_scaling_list(gb, scaling_matrix4[2], 16, default_scaling4[0], scaling_matrix4[1]); // Intra, Cb
}
}
}
+
+ return ret;
}
void ff_h264_ps_uninit(H264ParamSets *ps)
goto fail;
}
sps->transform_bypass = get_bits1(gb);
- decode_scaling_matrices(gb, sps, NULL, 1,
+ sps->scaling_matrix_present |= decode_scaling_matrices(gb, sps, NULL, 1,
sps->scaling_matrix4, sps->scaling_matrix8);
} else {
sps->chroma_format_idc = 1;
sps->gaps_in_frame_num_allowed_flag = get_bits1(gb);
sps->mb_width = get_ue_golomb(gb) + 1;
sps->mb_height = get_ue_golomb(gb) + 1;
- if ((unsigned)sps->mb_width >= INT_MAX / 16 ||
- (unsigned)sps->mb_height >= INT_MAX / 16 ||
- av_image_check_size(16 * sps->mb_width,
- 16 * sps->mb_height, 0, avctx)) {
- av_log(avctx, AV_LOG_ERROR, "mb_width/height overflow\n");
- goto fail;
- }
sps->frame_mbs_only_flag = get_bits1(gb);
if (!sps->frame_mbs_only_flag)
else
sps->mb_aff = 0;
+ if ((unsigned)sps->mb_width >= INT_MAX / 16 ||
+ (unsigned)sps->mb_height >= INT_MAX / (16 * (2 - sps->frame_mbs_only_flag)) ||
+ av_image_check_size(16 * sps->mb_width,
+ 16 * sps->mb_height * (2 - sps->frame_mbs_only_flag), 0, avctx)) {
+ av_log(avctx, AV_LOG_ERROR, "mb_width/height overflow\n");
+ goto fail;
+ }
+
sps->direct_8x8_inference_flag = get_bits1(gb);
#ifndef ALLOW_INTERLACE
/* if the maximum delay is not stored in the SPS, derive it based on the
* level */
- if (!sps->bitstream_restriction_flag) {
+ if (!sps->bitstream_restriction_flag &&
+ (sps->ref_frame_count || avctx->strict_std_compliance >= FF_COMPLIANCE_STRICT)) {
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) {
H264ParamSets *ps, int bit_length)
{
AVBufferRef *pps_buf;
- SPS *sps;
+ const SPS *sps;
unsigned int pps_id = get_ue_golomb(gb);
PPS *pps;
int qp_bd_offset;
pps->data_size = gb->buffer_end - gb->buffer;
if (pps->data_size > sizeof(pps->data)) {
- av_log(avctx, AV_LOG_WARNING, "Truncating likely oversized PPS\n");
+ av_log(avctx, AV_LOG_WARNING, "Truncating likely oversized PPS "
+ "(%"SIZE_SPECIFIER" > %"SIZE_SPECIFIER")\n",
+ pps->data_size, sizeof(pps->data));
pps->data_size = sizeof(pps->data);
}
memcpy(pps->data, gb->buffer, pps->data_size);
ret = AVERROR_INVALIDDATA;
goto fail;
}
- sps = (SPS*)ps->sps_list[pps->sps_id]->data;
+ sps = (const SPS*)ps->sps_list[pps->sps_id]->data;
if (sps->bit_depth_luma > 14) {
av_log(avctx, AV_LOG_ERROR,
"Invalid luma bit depth=%d\n",