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

Function MPA_encode_init

libavcodec/mpegaudioenc.c:67–189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65#include "mpegaudiotab.h"
66
67static av_cold int MPA_encode_init(AVCodecContext *avctx)
68{
69 MpegAudioContext *s = avctx->priv_data;
70 int freq = avctx->sample_rate;
71 int bitrate = avctx->bit_rate;
72 int channels = avctx->channels;
73 int i, v, table;
74 float a;
75
76 if (channels <= 0 || channels > 2){
77 av_log(avctx, AV_LOG_ERROR, "encoding %d channel(s) is not allowed in mp2\n", channels);
78 return -1;
79 }
80 bitrate = bitrate / 1000;
81 s->nb_channels = channels;
82 s->freq = freq;
83 s->bit_rate = bitrate * 1000;
84 avctx->frame_size = MPA_FRAME_SIZE;
85
86 /* encoding freq */
87 s->lsf = 0;
88 for(i=0;i<3;i++) {
89 if (ff_mpa_freq_tab[i] == freq)
90 break;
91 if ((ff_mpa_freq_tab[i] / 2) == freq) {
92 s->lsf = 1;
93 break;
94 }
95 }
96 if (i == 3){
97 av_log(avctx, AV_LOG_ERROR, "Sampling rate %d is not allowed in mp2\n", freq);
98 return -1;
99 }
100 s->freq_index = i;
101
102 /* encoding bitrate & frequency */
103 for(i=0;i<15;i++) {
104 if (ff_mpa_bitrate_tab[s->lsf][1][i] == bitrate)
105 break;
106 }
107 if (i == 15){
108 av_log(avctx, AV_LOG_ERROR, "bitrate %d is not allowed in mp2\n", bitrate);
109 return -1;
110 }
111 s->bitrate_index = i;
112
113 /* compute total header size & pad bit */
114
115 a = (float)(bitrate * 1000 * MPA_FRAME_SIZE) / (freq * 8.0);
116 s->frame_size = ((int)a) * 8;
117
118 /* frame fractional size to compute padding */
119 s->frame_frac = 0;
120 s->frame_frac_incr = (int)((a - floor(a)) * 65536.0);
121
122 /* select the right allocation table */
123 table = ff_mpa_l2_select_table(bitrate, s->nb_channels, freq, s->lsf);
124

Callers

nothing calls this directly

Calls 3

av_logFunction · 0.85
ff_mpa_l2_select_tableFunction · 0.85
avcodec_alloc_frameFunction · 0.85

Tested by

no test coverage detected