23 #include <opus_multistream.h> 53 0, 1, 1, 2, 2, 2, 2, 3
64 { 0, 4, 1, 2, 3, 5, 6 },
65 { 0, 6, 1, 2, 3, 4, 5, 7 },
76 { 0, 1, 5, 6, 2, 4, 3 },
77 { 0, 1, 6, 7, 4, 5, 2, 3 },
81 int coupled_stream_count,
88 bytestream_put_byte(&p, 1);
89 bytestream_put_byte(&p, channels);
92 bytestream_put_le16(&p, 0);
96 bytestream_put_byte(&p, channels <= 8 ? 1 : 255);
97 bytestream_put_byte(&p, stream_count);
98 bytestream_put_byte(&p, coupled_stream_count);
101 bytestream_put_byte(&p, 0);
110 ret = opus_multistream_encoder_ctl(enc, OPUS_SET_BITRATE(avctx->
bit_rate));
111 if (ret != OPUS_OK) {
113 "Failed to set bitrate: %s\n", opus_strerror(ret));
117 ret = opus_multistream_encoder_ctl(enc,
121 "Unable to set complexity: %s\n", opus_strerror(ret));
123 ret = opus_multistream_encoder_ctl(enc, OPUS_SET_VBR(!!opts->
vbr));
126 "Unable to set VBR: %s\n", opus_strerror(ret));
128 ret = opus_multistream_encoder_ctl(enc,
129 OPUS_SET_VBR_CONSTRAINT(opts->
vbr == 2));
132 "Unable to set constrained VBR: %s\n", opus_strerror(ret));
134 ret = opus_multistream_encoder_ctl(enc,
138 "Unable to set expected packet loss percentage: %s\n",
142 ret = opus_multistream_encoder_ctl(enc,
146 "Unable to set maximum bandwidth: %s\n", opus_strerror(ret));
155 const uint8_t *channel_mapping;
158 int coupled_stream_count, header_size,
frame_size;
168 "Channel layout undefined for %d channels.\n", avctx->
channels);
174 32000 * coupled_stream_count;
176 "No bit rate set. Defaulting to %d bps.\n", avctx->
bit_rate);
181 "Please choose a value between 500 and %d.\n", avctx->
bit_rate,
187 switch (frame_size) {
192 "LPC mode cannot be used with a frame duration of less " 193 "than 10ms. Enabling restricted low-delay mode.\n" 194 "Use a longer frame duration if this is not what you want.\n");
207 "Frame duration must be exactly one of: 2.5, 5, 10, 20, 40 or 60.\n",
214 "Compression level must be in the range 0 to 10. " 215 "Defaulting to 10.\n");
240 "Invalid frequency cutoff: %d. Using default maximum bandwidth.\n" 241 "Cutoff frequency must be exactly one of: 4000, 6000, 8000, 12000 or 20000.\n",
249 coupled_stream_count,
252 if (ret != OPUS_OK) {
254 "Failed to create encoder: %s\n", opus_strerror(ret));
259 if (ret != OPUS_OK) {
281 ret = opus_multistream_encoder_ctl(enc, OPUS_GET_LOOKAHEAD(&avctx->
initial_padding));
284 "Unable to get number of lookahead samples: %s\n",
297 opus_multistream_encoder_destroy(enc);
303 const AVFrame *frame,
int *got_packet_ptr)
306 const int sample_size = avctx->
channels *
319 audio = frame->
data[0];
336 ret = opus_multistream_encode_float(opus->
enc, (
float *)audio,
340 ret = opus_multistream_encode(opus->
enc, (opus_int16 *)audio,
346 "Error encoding frame: %s\n", opus_strerror(ret));
364 opus_multistream_encoder_destroy(opus->
enc);
374 #define OFFSET(x) offsetof(LibopusEncContext, opts.x) 375 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM 377 {
"application",
"Intended application type",
OFFSET(
application),
AV_OPT_TYPE_INT, { .i64 = OPUS_APPLICATION_AUDIO }, OPUS_APPLICATION_VOIP, OPUS_APPLICATION_RESTRICTED_LOWDELAY,
FLAGS,
"application" },
378 {
"voip",
"Favor improved speech intelligibility", 0,
AV_OPT_TYPE_CONST, { .i64 = OPUS_APPLICATION_VOIP }, 0, 0,
FLAGS,
"application" },
379 {
"audio",
"Favor faithfulness to the input", 0,
AV_OPT_TYPE_CONST, { .i64 = OPUS_APPLICATION_AUDIO }, 0, 0,
FLAGS,
"application" },
380 {
"lowdelay",
"Restrict to only the lowest delay modes", 0,
AV_OPT_TYPE_CONST, { .i64 = OPUS_APPLICATION_RESTRICTED_LOWDELAY }, 0, 0,
FLAGS,
"application" },
399 {
"compression_level",
"10" },
404 48000, 24000, 16000, 12000, 8000, 0,
void ff_af_queue_remove(AudioFrameQueue *afq, int nb_samples, int64_t *pts, int64_t *duration)
Remove frame(s) from the queue.
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
This structure describes decoded (raw) audio or video data.
static int libopus_configure_encoder(AVCodecContext *avctx, OpusMSEncoder *enc, LibopusEncOpts *opts)
#define AV_LOG_WARNING
Something somehow does not look correct.
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
static const uint8_t frame_size[4]
static int av_cold libopus_encode_close(AVCodecContext *avctx)
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
int ff_opus_error_to_averror(int err)
enum AVSampleFormat sample_fmt
audio sample format
av_cold void ff_af_queue_init(AVCodecContext *avctx, AudioFrameQueue *afq)
Initialize AudioFrameQueue.
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
static const AVClass libopus_class
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
static int av_cold libopus_encode_init(AVCodecContext *avctx)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int initial_padding
Audio only.
const char * name
Name of the codec implementation.
static const uint8_t libav_libopus_channel_map[8][8]
int ff_af_queue_add(AudioFrameQueue *afq, const AVFrame *f)
Add a frame to the queue.
static const uint8_t opus_coupled_streams[8]
int bit_rate
the average bitrate
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
static const int libopus_sample_rates[]
int ff_alloc_packet(AVPacket *avpkt, int size)
Check AVPacket size and/or allocate data.
#define AVERROR_PATCHWELCOME
Not yet implemented in Libav, patches welcome.
int frame_size
Number of samples per channel in an audio frame.
Libavcodec external API header.
AVSampleFormat
Audio Sample Formats.
int sample_rate
samples per second
main external API structure.
static int libopus_encode(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
const uint64_t ff_vorbis_channel_layouts[9]
AVCodec ff_libopus_encoder
Describe the class of an AVClass context structure.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
static const uint8_t opus_vorbis_channel_map[8][8]
common internal api header.
static const AVCodecDefault libopus_defaults[]
static av_cold int init(AVCodecParserContext *s)
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
int cutoff
Audio cutoff bandwidth (0 means "automatic")
int channels
number of audio channels
static const AVOption libopus_options[]
void ff_af_queue_close(AudioFrameQueue *afq)
Close AudioFrameQueue.
static enum AVSampleFormat sample_fmts[]
This structure stores compressed data.
int nb_samples
number of audio samples (per channel) described by this frame
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
static void libopus_write_header(AVCodecContext *avctx, int stream_count, int coupled_stream_count, const uint8_t *channel_mapping)