31#define ENCODER_MAX_CHANNELS 2
55 int effective_bit_rate;
56 unsigned encoder_size;
58 if (frame_us != 2500 && frame_us != 5000 &&
59 frame_us != 7500 && frame_us != 10000 ) {
61 "Unsupported frame duration %.1f ms.\n", frame_us / 1000.f);
66 "Invalid number of channels %d. Max %d channels are accepted\n",
71 hr_mode |= srate_hz > 48000;
72 hr_mode &= srate_hz >= 48000;
74 if (frame_us == 7500 && hr_mode) {
76 "High-resolution mode is not supported with 7.5 ms frames.\n");
87 effective_bit_rate = lc3_hr_resolve_bitrate(
90 if (avctx->
bit_rate != effective_bit_rate)
92 "Bitrate changed to %d bps.\n", effective_bit_rate);
93 avctx->
bit_rate = effective_bit_rate;
95 encoder_size = lc3_hr_encoder_size(hr_mode, frame_us, srate_hz);
103 for (
int ch = 0; ch <
channels; ch++) {
104 liblc3->
encoder[ch] = lc3_hr_setup_encoder(
105 hr_mode, frame_us, srate_hz, 0,
119 liblc3->
delay_samples = lc3_hr_delay_samples(hr_mode, frame_us, srate_hz);
147 int padding =
frame->nb_samples -
frame->duration;
158 data_ptr =
pkt->data;
159 for (
int ch = 0; ch <
channels; ch++) {
162 const float *pcm =
frame ?
163 (is_planar ? (
const float*)
frame->data[ch] :
164 (
const float*)
frame->data[0] + ch) :
165 (
const float[]){ 0 };
169 lc3_encode(liblc3->
encoder[ch],
170 LC3_PCM_FORMAT_FLOAT, pcm,
stride, nbytes, data_ptr);
180#define OFFSET(x) offsetof(LibLC3EncContext, opts.x)
181#define FLAGS AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
183 {
"frame_duration",
"Duration of a frame in milliseconds",
185 { .dbl = 10.0 }, 2.5, 10.0,
FLAGS },
186 {
"high_resolution",
"Enable High-Resolution mode (48 KHz or 96 KHz)",
188 { .i64 = 0 }, 0, 1,
FLAGS },
205 .p.priv_class = &
class,
206 .p.wrapper_name =
"liblc3",
const FFCodec ff_liblc3_encoder
static av_cold void close(AVCodecParserContext *s)
Libavcodec external API header.
#define CODEC_SAMPLERATES(...)
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
#define CODEC_SAMPLEFMTS(...)
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_FLOAT
Underlying C type is float.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
#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_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
@ AV_SAMPLE_FMT_FLTP
float, planar
#define LIBAVUTIL_VERSION_INT
#define ENCODER_MAX_CHANNELS
static av_cold int liblc3_encode_close(AVCodecContext *avctx)
static int liblc3_encode(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet_ptr)
static av_cold int liblc3_encode_init(AVCodecContext *avctx)
Memory handling functions.
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
main external API structure.
AVChannelLayout ch_layout
Audio channel layout.
enum AVSampleFormat sample_fmt
audio sample format
int64_t bit_rate
the average bitrate
int sample_rate
samples per second
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
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.
lc3_encoder_t encoder[ENCODER_MAX_CHANNELS]
#define av_malloc_array(a, b)