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

Function encode_frame

libavcodec/mpegaudioenc.c:671–753  ·  view source on GitHub ↗

* Output the MPEG audio layer 2 frame. Note how the code is small * compared to other encoders :-) */

Source from the content-addressed store, hash-verified

669 * compared to other encoders :-)
670 */
671static void encode_frame(MpegAudioContext *s, uint8_t *buf, unsigned buf_size,
672 unsigned char bit_alloc[MPA_MAX_CHANNELS][SBLIMIT],
673 int padding)
674{
675 int i, j, bit_alloc_bits, ch;
676 unsigned char *sf;
677 PutBitContext p0, *p = &p0;
678
679 init_put_bits(p, buf, buf_size);
680
681 /* header */
682
683 put_bits(p, 12, 0xfff);
684 put_bits(p, 1, 1 - s->lsf); /* 1 = MPEG-1 ID, 0 = MPEG-2 lsf ID */
685 put_bits(p, 2, 4-2); /* layer 2 */
686 put_bits(p, 1, 1); /* no error protection */
687 put_bits(p, 4, s->bitrate_index);
688 put_bits(p, 2, s->freq_index);
689 put_bits(p, 1, s->do_padding); /* use padding */
690 put_bits(p, 1, 0); /* private_bit */
691 put_bits(p, 2, s->nb_channels == 2 ? MPA_STEREO : MPA_MONO);
692 put_bits(p, 2, 0); /* mode_ext */
693 put_bits(p, 1, 0); /* no copyright */
694 put_bits(p, 1, 1); /* original */
695 put_bits(p, 2, 0); /* no emphasis */
696
697 /* bit allocation */
698 j = 0;
699 for(i=0;i<s->sblimit;i++) {
700 bit_alloc_bits = s->alloc_table[j];
701 for(ch=0;ch<s->nb_channels;ch++) {
702 put_bits(p, bit_alloc_bits, bit_alloc[ch][i]);
703 }
704 j += 1 << bit_alloc_bits;
705 }
706
707 /* scale codes */
708 for(i=0;i<s->sblimit;i++) {
709 for(ch=0;ch<s->nb_channels;ch++) {
710 if (bit_alloc[ch][i])
711 put_bits(p, 2, s->scale_code[ch][i]);
712 }
713 }
714
715 /* scale factors */
716 for(i=0;i<s->sblimit;i++) {
717 for(ch=0;ch<s->nb_channels;ch++) {
718 if (bit_alloc[ch][i]) {
719 sf = &s->scale_factors[ch][i][0];
720 switch(s->scale_code[ch][i]) {
721 case 0:
722 put_bits(p, 18, sf[0] << 12 | sf[1] << 6 | sf[2]);
723 break;
724 case 3:
725 case 1:
726 put_bits(p, 12, sf[0] << 6 | sf[2]);
727 break;
728 case 2:

Callers 1

mpa_encode_frameFunction · 0.70

Calls 7

init_put_bitsFunction · 0.85
encode_subbandsFunction · 0.85
put_bits_leftFunction · 0.85
flush_put_bitsFunction · 0.85
put_bytes_leftFunction · 0.85
put_bits_ptrFunction · 0.85
put_bitsFunction · 0.70

Tested by

no test coverage detected