| 357 | } |
| 358 | |
| 359 | static int cllc_decode_frame(AVCodecContext *avctx, AVFrame *pic, |
| 360 | int *got_picture_ptr, AVPacket *avpkt) |
| 361 | { |
| 362 | CLLCContext *ctx = avctx->priv_data; |
| 363 | const uint8_t *src = avpkt->data; |
| 364 | uint32_t info_tag, info_offset; |
| 365 | int data_size; |
| 366 | GetBitContext gb; |
| 367 | int coding_type, ret; |
| 368 | |
| 369 | if (avpkt->size < 4 + 4) { |
| 370 | av_log(avctx, AV_LOG_ERROR, "Frame is too small %d.\n", avpkt->size); |
| 371 | return AVERROR_INVALIDDATA; |
| 372 | } |
| 373 | |
| 374 | info_offset = 0; |
| 375 | info_tag = AV_RL32(src); |
| 376 | if (info_tag == MKTAG('I', 'N', 'F', 'O')) { |
| 377 | info_offset = AV_RL32(src + 4); |
| 378 | if (info_offset > UINT32_MAX - 8 || info_offset + 8 > avpkt->size) { |
| 379 | av_log(avctx, AV_LOG_ERROR, |
| 380 | "Invalid INFO header offset: 0x%08"PRIX32" is too large.\n", |
| 381 | info_offset); |
| 382 | return AVERROR_INVALIDDATA; |
| 383 | } |
| 384 | ff_canopus_parse_info_tag(avctx, src + 8, info_offset); |
| 385 | |
| 386 | info_offset += 8; |
| 387 | src += info_offset; |
| 388 | } |
| 389 | |
| 390 | data_size = (avpkt->size - info_offset) & ~1; |
| 391 | |
| 392 | /* Make sure our bswap16'd buffer is big enough */ |
| 393 | av_fast_padded_malloc(&ctx->swapped_buf, |
| 394 | &ctx->swapped_buf_size, data_size); |
| 395 | if (!ctx->swapped_buf) { |
| 396 | av_log(avctx, AV_LOG_ERROR, "Could not allocate swapped buffer.\n"); |
| 397 | return AVERROR(ENOMEM); |
| 398 | } |
| 399 | |
| 400 | /* bswap16 the buffer since CLLC's bitreader works in 16-bit words */ |
| 401 | ctx->bdsp.bswap16_buf((uint16_t *) ctx->swapped_buf, (uint16_t *) src, |
| 402 | data_size / 2); |
| 403 | |
| 404 | if ((ret = init_get_bits8(&gb, ctx->swapped_buf, data_size)) < 0) |
| 405 | return ret; |
| 406 | |
| 407 | /* |
| 408 | * Read in coding type. The types are as follows: |
| 409 | * |
| 410 | * 0 - YUY2 |
| 411 | * 1 - BGR24 (Triples) |
| 412 | * 2 - BGR24 (Quads) |
| 413 | * 3 - BGRA |
| 414 | */ |
| 415 | coding_type = (AV_RL32(src) >> 8) & 0xFF; |
| 416 | av_log(avctx, AV_LOG_DEBUG, "Frame coding type: %d\n", coding_type); |
nothing calls this directly
no test coverage detected