32 #include <lame/lame.h>
34 #define BUFFER_SIZE (7200 + 2 * MPA_FRAME_SIZE + MPA_FRAME_SIZE / 4)
37 lame_global_flags *
gfp;
53 if ((s->
gfp = lame_init()) ==
NULL)
59 lame_set_quality(s->
gfp, 5);
66 lame_set_brate(s->
gfp, 0);
67 lame_set_VBR(s->
gfp, vbr_default);
70 lame_set_bWriteVbrTag(s->
gfp,0);
71 #if FF_API_LAME_GLOBAL_OPTS
75 if (lame_init_params(s->
gfp) < 0)
91 44100, 48000, 32000, 22050, 24000, 16000, 11025, 12000, 8000, 0
96 { 0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448 },
97 { 0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384 },
98 { 0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320 }
101 { 0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256 },
102 { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 },
103 { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 }
114 static int mp3len(
void *
data,
int *samplesPerFrame,
int *sampleRate)
116 uint32_t header =
AV_RB32(data);
117 int layerID = 3 - ((header >> 17) & 0x03);
118 int bitRateID = ((header >> 12) & 0x0f);
119 int sampleRateID = ((header >> 10) & 0x03);
121 int isPadded = ((header >> 9) & 0x01);
122 static int const mode_tab[4] = { 2, 3, 1, 0 };
123 int mode = mode_tab[(header >> 19) & 0x03];
124 int mpeg_id = mode > 0;
125 int temp0, temp1, bitRate;
127 if (((header >> 21) & 0x7ff) != 0x7ff || mode == 3 || layerID == 3 ||
132 if (!samplesPerFrame)
133 samplesPerFrame = &temp0;
140 bitRate =
sBitRates[mpeg_id][layerID][bitRateID] * 1000;
146 return *samplesPerFrame * bitRate / (bitsPerSlot * *sampleRate) + isPadded;
150 int buf_size,
void *
data)
160 lame_result = lame_encode_buffer_interleaved(s->
gfp, data,
165 lame_result = lame_encode_buffer(s->
gfp, data, data,
175 if (lame_result < 0) {
176 if (lame_result == -1) {
179 "lame: output buffer too small (buffer index: %d, free bytes: %d)\n",
193 if (len <= s->buffer_index) {
194 memcpy(frame, s->
buffer, len);
217 #define OFFSET(x) offsetof(Mp3AudioContext, x)
218 #define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
232 .
name =
"libmp3lame",