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

Function decode_frame

libavcodec/alsdec.c:1380–1444  ·  view source on GitHub ↗

Decodes an ALS frame. */

Source from the content-addressed store, hash-verified

1378/** Decodes an ALS frame.
1379 */
1380static int decode_frame(AVCodecContext *avctx,
1381 void *data, int *data_size,
1382 AVPacket *avpkt)
1383{
1384 ALSDecContext *ctx = avctx->priv_data;
1385 ALSSpecificConfig *sconf = &ctx->sconf;
1386 const uint8_t *buffer = avpkt->data;
1387 int buffer_size = avpkt->size;
1388 int invalid_frame, size;
1389 unsigned int c, sample, ra_frame, bytes_read, shift;
1390
1391 init_get_bits(&ctx->gb, buffer, buffer_size * 8);
1392
1393 // In the case that the distance between random access frames is set to zero
1394 // (sconf->ra_distance == 0) no frame is treated as a random access frame.
1395 // For the first frame, if prediction is used, all samples used from the
1396 // previous frame are assumed to be zero.
1397 ra_frame = sconf->ra_distance && !(ctx->frame_id % sconf->ra_distance);
1398
1399 // the last frame to decode might have a different length
1400 if (sconf->samples != 0xFFFFFFFF)
1401 ctx->cur_frame_length = FFMIN(sconf->samples - ctx->frame_id * (uint64_t) sconf->frame_length,
1402 sconf->frame_length);
1403 else
1404 ctx->cur_frame_length = sconf->frame_length;
1405
1406 // decode the frame data
1407 if ((invalid_frame = read_frame_data(ctx, ra_frame) < 0))
1408 av_log(ctx->avctx, AV_LOG_WARNING,
1409 "Reading frame data failed. Skipping RA unit.\n");
1410
1411 ctx->frame_id++;
1412
1413 // check for size of decoded data
1414 size = ctx->cur_frame_length * avctx->channels *
1415 (av_get_bits_per_sample_format(avctx->sample_fmt) >> 3);
1416
1417 if (size > *data_size) {
1418 av_log(avctx, AV_LOG_ERROR, "Decoded data exceeds buffer size.\n");
1419 return -1;
1420 }
1421
1422 *data_size = size;
1423
1424 // transform decoded frame into output format
1425 #define INTERLEAVE_OUTPUT(bps) \
1426 { \
1427 int##bps##_t *dest = (int##bps##_t*) data; \
1428 shift = bps - ctx->avctx->bits_per_raw_sample; \
1429 for (sample = 0; sample < ctx->cur_frame_length; sample++) \
1430 for (c = 0; c < avctx->channels; c++) \
1431 *dest++ = ctx->raw_samples[c][sample] << shift; \
1432 }
1433
1434 if (ctx->avctx->bits_per_raw_sample <= 16) {
1435 INTERLEAVE_OUTPUT(16)
1436 } else {
1437 INTERLEAVE_OUTPUT(32)

Callers

nothing calls this directly

Calls 5

init_get_bitsFunction · 0.85
read_frame_dataFunction · 0.85
av_logFunction · 0.85
get_bits_countFunction · 0.85

Tested by

no test coverage detected