43#define BUFFER_SIZE (7200 + 2 * MPA_FRAME_SIZE + MPA_FRAME_SIZE / 4+1000)
48 lame_global_flags *
gfp;
66 if (!
s->buffer ||
s->buffer_size -
s->buffer_index <
BUFFER_SIZE) {
69 ff_dlog(
s->avctx,
"resizing output buffer: %d -> %d\n",
s->buffer_size,
72 s->buffer_size =
s->buffer_index = 0;
75 s->buffer_size = new_size;
103 if (!(
s->gfp = lame_init()))
121 lame_set_VBR(
s->gfp, vbr_default);
126 lame_set_VBR(
s->gfp, vbr_abr);
127 lame_set_VBR_mean_bitrate_kbps(
s->gfp, avctx->
bit_rate / 1000);
129 lame_set_brate(
s->gfp, avctx->
bit_rate / 1000);
135 lame_set_lowpassfreq(
s->gfp, avctx->
cutoff);
138 lame_set_bWriteVbrTag(
s->gfp,0);
141 lame_set_disable_reservoir(
s->gfp, !
s->reservoir);
144 lame_set_copyright(
s->gfp,
s->copyright);
147 lame_set_original(
s->gfp,
s->original);
150 if (lame_init_params(
s->gfp) < 0) {
166 sizeof(*
s->samples_flt[ch]));
167 if (!
s->samples_flt[ch]) {
191#define ENCODE_BUFFER(func, buf_type, buf_name) do { \
192 lame_result = func(s->gfp, \
193 (const buf_type *)buf_name[0], \
194 (const buf_type *)buf_name[1], frame->nb_samples, \
195 s->buffer + s->buffer_index, \
196 s->buffer_size - s->buffer_index); \
222 s->fdsp->vector_fmul_scalar(
s->samples_flt[ch],
223 (
const float *)
frame->data[ch],
232 }
else if (!
s->afq.frame_alloc) {
235 lame_result = lame_encode_flush(
s->gfp,
s->buffer +
s->buffer_index,
236 s->buffer_size -
s->buffer_index);
238 if (lame_result < 0) {
239 if (lame_result == -1) {
241 "lame: output buffer too small (buffer index: %d, free bytes: %d)\n",
242 s->buffer_index,
s->buffer_size -
s->buffer_index);
246 s->buffer_index += lame_result;
262 if (
s->buffer_index < 4)
274 len = hdr.frame_size;
280 memcpy(avpkt->
data,
s->buffer,
len);
281 s->buffer_index -=
len;
282 memmove(
s->buffer,
s->buffer +
len,
s->buffer_index);
294#define OFFSET(x) offsetof(LAMEContext, x)
295#define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
306 .class_name =
"libmp3lame encoder",
318 44100, 48000, 32000, 22050, 24000, 16000, 11025, 12000, 8000, 0
322 .p.name =
"libmp3lame",
338 .p.wrapper_name =
"libmp3lame",
const FFCodec ff_libmp3lame_encoder
av_cold void ff_af_queue_close(AudioFrameQueue *afq)
Close AudioFrameQueue.
av_cold void ff_af_queue_init(AVCodecContext *avctx, AudioFrameQueue *afq)
Initialize AudioFrameQueue.
int ff_af_queue_remove(AudioFrameQueue *afq, int nb_samples, AVPacket *pkt)
Remove frame(s) from the queue.
int ff_af_queue_add(AudioFrameQueue *afq, const AVFrame *f)
Add a frame to the queue.
Libavcodec external API header.
#define FF_COMPRESSION_DEFAULT
Public libavutil channel layout APIs header.
#define CODEC_SAMPLERATES_ARRAY(array)
#define CODEC_CH_LAYOUTS(...)
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
#define CODEC_SAMPLEFMTS(...)
common internal and external API header
int(* init)(AVBSFContext *ctx)
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_FLAG_QSCALE
Use fixed qscale.
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
#define AV_CHANNEL_LAYOUT_STEREO
#define AV_CHANNEL_LAYOUT_MONO
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
#define AVERROR_EXTERNAL
Generic error in an external library.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
@ AV_SAMPLE_FMT_FLTP
float, planar
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
#define LIBAVUTIL_VERSION_INT
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
static av_cold int mp3lame_encode_init(AVCodecContext *avctx)
#define ENCODE_BUFFER(func, buf_type, buf_name)
static const int libmp3lame_sample_rates[]
static const FFCodecDefault libmp3lame_defaults[]
static av_cold int mp3lame_encode_close(AVCodecContext *avctx)
static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
static int realloc_buffer(LAMEContext *s)
static const AVClass libmp3lame_class
Memory handling functions.
mpeg audio declarations for both encoder and decoder.
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
main external API structure.
AVChannelLayout ch_layout
Audio channel layout.
enum AVSampleFormat sample_fmt
audio sample format
int global_quality
Global quality for codecs which cannot change it per frame.
int64_t bit_rate
the average bitrate
int initial_padding
Audio only.
int sample_rate
samples per second
int flags
AV_CODEC_FLAG_*.
int cutoff
Audio cutoff bandwidth (0 means "automatic")
int frame_size
Number of samples per channel in an audio frame.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
#define av_malloc_array(a, b)
static void error(const char *err)