MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / decode_picture_header

Function decode_picture_header

libavcodec/proresdec.c:315–421  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

313}
314
315static int decode_picture_header(AVCodecContext *avctx, const uint8_t *buf, const int buf_size)
316{
317 ProresContext *ctx = avctx->priv_data;
318 int i, hdr_size, slice_count;
319 unsigned pic_data_size;
320 int log2_slice_mb_width, log2_slice_mb_height;
321 int slice_mb_count, mb_x, mb_y;
322 const uint8_t *data_ptr, *index_ptr;
323
324 hdr_size = buf[0] >> 3;
325 if (hdr_size < 8 || hdr_size > buf_size) {
326 av_log(avctx, AV_LOG_ERROR, "error, wrong picture header size\n");
327 return AVERROR_INVALIDDATA;
328 }
329
330 pic_data_size = AV_RB32(buf + 1);
331 if (pic_data_size > buf_size) {
332 av_log(avctx, AV_LOG_ERROR, "error, wrong picture data size\n");
333 return AVERROR_INVALIDDATA;
334 }
335
336 log2_slice_mb_width = buf[7] >> 4;
337 log2_slice_mb_height = buf[7] & 0xF;
338 if (log2_slice_mb_width > 3 || log2_slice_mb_height) {
339 av_log(avctx, AV_LOG_ERROR, "unsupported slice resolution: %dx%d\n",
340 1 << log2_slice_mb_width, 1 << log2_slice_mb_height);
341 return AVERROR_INVALIDDATA;
342 }
343
344 ctx->slice_mb_width = 1 << log2_slice_mb_width;
345 ctx->slice_mb_height = 1 << log2_slice_mb_height;
346
347 ctx->mb_width = (avctx->width + 15) >> 4;
348 if (ctx->frame_type)
349 ctx->mb_height = (avctx->height + 31) >> 5;
350 else
351 ctx->mb_height = (avctx->height + 15) >> 4;
352
353 // QT ignores the written value
354 // slice_count = AV_RB16(buf + 5);
355 slice_count = ctx->mb_height * ((ctx->mb_width >> log2_slice_mb_width) +
356 av_popcount(ctx->mb_width & ctx->slice_mb_width - 1));
357
358 if (ctx->slice_count != slice_count || !ctx->slices) {
359 av_freep(&ctx->slices);
360 ctx->slice_count = 0;
361 ctx->slices = av_calloc(slice_count, sizeof(*ctx->slices));
362 if (!ctx->slices)
363 return AVERROR(ENOMEM);
364 ctx->slice_count = slice_count;
365 }
366
367 if (!slice_count)
368 return AVERROR(EINVAL);
369
370 if (hdr_size + slice_count*2 > buf_size) {
371 av_log(avctx, AV_LOG_ERROR, "error, wrong slice count\n");
372 return AVERROR_INVALIDDATA;

Callers 1

decode_frameFunction · 0.85

Calls 3

av_logFunction · 0.85
av_freepFunction · 0.85
av_callocFunction · 0.85

Tested by

no test coverage detected