| 2354 | } |
| 2355 | |
| 2356 | static av_cold int vp3_decode_init(AVCodecContext *avctx) |
| 2357 | { |
| 2358 | static AVOnce init_static_once = AV_ONCE_INIT; |
| 2359 | Vp3DecodeContext *s = avctx->priv_data; |
| 2360 | int ret; |
| 2361 | int c_width; |
| 2362 | int c_height; |
| 2363 | int y_fragment_count, c_fragment_count; |
| 2364 | |
| 2365 | if (avctx->codec_tag == MKTAG('V', 'P', '4', '0')) { |
| 2366 | s->version = 3; |
| 2367 | #if !CONFIG_VP4_DECODER |
| 2368 | av_log(avctx, AV_LOG_ERROR, "This build does not support decoding VP4.\n"); |
| 2369 | return AVERROR_DECODER_NOT_FOUND; |
| 2370 | #endif |
| 2371 | } else if (avctx->codec_tag == MKTAG('V', 'P', '3', '0')) |
| 2372 | s->version = 0; |
| 2373 | else |
| 2374 | s->version = 1; |
| 2375 | |
| 2376 | s->avctx = avctx; |
| 2377 | s->width = FFALIGN(avctx->coded_width, 16); |
| 2378 | s->height = FFALIGN(avctx->coded_height, 16); |
| 2379 | if (s->width < 18) |
| 2380 | return AVERROR_PATCHWELCOME; |
| 2381 | if (avctx->codec_id != AV_CODEC_ID_THEORA) |
| 2382 | avctx->pix_fmt = AV_PIX_FMT_YUV420P; |
| 2383 | avctx->chroma_sample_location = AVCHROMA_LOC_CENTER; |
| 2384 | ff_hpeldsp_init(&s->hdsp, avctx->flags | AV_CODEC_FLAG_BITEXACT); |
| 2385 | ff_videodsp_init(&s->vdsp, 8); |
| 2386 | ff_vp3dsp_init(&s->vp3dsp); |
| 2387 | |
| 2388 | for (int i = 0; i < 64; i++) { |
| 2389 | #define TRANSPOSE(x) (((x) >> 3) | (((x) & 7) << 3)) |
| 2390 | s->idct_permutation[i] = TRANSPOSE(i); |
| 2391 | s->idct_scantable[i] = TRANSPOSE(ff_zigzag_direct[i]); |
| 2392 | #undef TRANSPOSE |
| 2393 | } |
| 2394 | |
| 2395 | /* initialize to an impossible value which will force a recalculation |
| 2396 | * in the first frame decode */ |
| 2397 | for (int i = 0; i < 3; i++) |
| 2398 | s->qps[i] = -1; |
| 2399 | |
| 2400 | ret = av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_x_shift, &s->chroma_y_shift); |
| 2401 | if (ret) |
| 2402 | return ret; |
| 2403 | |
| 2404 | s->y_superblock_width = (s->width + 31) / 32; |
| 2405 | s->y_superblock_height = (s->height + 31) / 32; |
| 2406 | s->y_superblock_count = s->y_superblock_width * s->y_superblock_height; |
| 2407 | |
| 2408 | /* work out the dimensions for the C planes */ |
| 2409 | c_width = s->width >> s->chroma_x_shift; |
| 2410 | c_height = s->height >> s->chroma_y_shift; |
| 2411 | s->c_superblock_width = (c_width + 31) / 32; |
| 2412 | s->c_superblock_height = (c_height + 31) / 32; |
| 2413 | s->c_superblock_count = s->c_superblock_width * s->c_superblock_height; |
no test coverage detected