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

Function smka_decode_frame

libavcodec/smacker.c:565–690  ·  view source on GitHub ↗

* Decode Smacker audio data */

Source from the content-addressed store, hash-verified

563 * Decode Smacker audio data
564 */
565static int smka_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
566{
567 const uint8_t *buf = avpkt->data;
568 int buf_size = avpkt->size;
569 GetBitContext gb;
570 HuffContext h[4];
571 VLC vlc[4];
572 int16_t *samples = data;
573 int8_t *samples8 = data;
574 int val;
575 int i, res;
576 int unp_size;
577 int bits, stereo;
578 int pred[2] = {0, 0};
579
580 unp_size = AV_RL32(buf);
581
582 init_get_bits(&gb, buf + 4, (buf_size - 4) * 8);
583
584 if(!get_bits1(&gb)){
585 av_log(avctx, AV_LOG_INFO, "Sound: no data\n");
586 *data_size = 0;
587 return 1;
588 }
589 stereo = get_bits1(&gb);
590 bits = get_bits1(&gb);
591 if (unp_size & 0xC0000000 || unp_size > *data_size) {
592 av_log(avctx, AV_LOG_ERROR, "Frame is too large to fit in buffer\n");
593 return -1;
594 }
595
596 memset(vlc, 0, sizeof(VLC) * 4);
597 memset(h, 0, sizeof(HuffContext) * 4);
598 // Initialize
599 for(i = 0; i < (1 << (bits + stereo)); i++) {
600 h[i].length = 256;
601 h[i].maxlength = 0;
602 h[i].current = 0;
603 h[i].bits = av_mallocz(256 * 4);
604 h[i].lengths = av_mallocz(256 * sizeof(int));
605 h[i].values = av_mallocz(256 * sizeof(int));
606 skip_bits1(&gb);
607 smacker_decode_tree(&gb, &h[i], 0, 0);
608 skip_bits1(&gb);
609 if(h[i].current > 1) {
610 res = init_vlc(&vlc[i], SMKTREE_BITS, h[i].length,
611 h[i].lengths, sizeof(int), sizeof(int),
612 h[i].bits, sizeof(uint32_t), sizeof(uint32_t), INIT_VLC_LE);
613 if(res < 0) {
614 av_log(avctx, AV_LOG_ERROR, "Cannot build VLC table\n");
615 return -1;
616 }
617 }
618 }
619 if(bits) { //decode 16-bit data
620 for(i = stereo; i >= 0; i--)
621 pred[i] = bswap_16(get_bits(&gb, 16));
622 for(i = 0; i < stereo; i++)

Callers

nothing calls this directly

Calls 12

init_get_bitsFunction · 0.85
get_bits1Function · 0.85
av_logFunction · 0.85
av_malloczFunction · 0.85
skip_bits1Function · 0.85
smacker_decode_treeFunction · 0.85
get_bitsFunction · 0.85
get_vlc2Function · 0.85
free_vlcFunction · 0.85
av_freeFunction · 0.85
AV_RL32Function · 0.50
bswap_16Function · 0.50

Tested by

no test coverage detected