23 #include <opus_multistream.h>
43 #ifdef OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST
48 #define OPUS_HEAD_SIZE 19
53 int ret, channel_map = 0, gain_db = 0,
nb_streams, nb_coupled;
54 uint8_t mapping_arr[8] = { 0, 1 }, *mapping;
59 "Invalid number of channels %d, defaulting to stereo\n", avc->
channels);
81 if (avc->
channels > 2 || channel_map) {
83 "No channel mapping for %d channels.\n", avc->
channels);
88 mapping = mapping_arr;
96 for (ch = 0; ch < avc->
channels; ch++)
97 mapping_arr[ch] = mapping[vorbis_offset[ch]];
98 mapping = mapping_arr;
111 ret = opus_multistream_decoder_ctl(opus->
dec, OPUS_SET_GAIN(gain_db));
117 double gain_lin =
ff_exp10(gain_db / (20.0 * 256));
119 opus->
gain.
d = gain_lin;
121 opus->
gain.
i =
FFMIN(gain_lin * 65536, INT_MAX);
125 #ifdef OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST
126 ret = opus_multistream_decoder_ctl(opus->
dec,
127 OPUS_SET_PHASE_INVERSION_DISABLED(!opus->apply_phase_inv));
130 "Unable to set phase inversion: %s\n",
145 opus_multistream_decoder_destroy(opus->
dec);
151 #define MAX_FRAME_SIZE (960 * 6)
173 if (nb_samples < 0) {
175 opus_strerror(nb_samples));
179 #ifndef OPUS_SET_GAIN
184 for (;
i > 0;
i--, pcm++)
187 int16_t *pcm = (int16_t *)
frame->
data[0];
188 for (;
i > 0;
i--, pcm++)
204 opus_multistream_decoder_ctl(opus->
dec, OPUS_RESET_STATE);
211 #define OFFSET(x) offsetof(struct libopus_context, x)
212 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM
214 #ifdef OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST
215 {
"apply_phase_inv",
"Apply intensity stereo phase inversion",
OFFSET(apply_phase_inv),
AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1,
FLAGS },
244 .wrapper_name =
"libopus",
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
internal math functions header
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_S16
signed 16 bits
#define LIBAVUTIL_VERSION_INT
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int ff_opus_error_to_averror(int err)
static av_cold int libopus_decode_init(AVCodecContext *avc)
static const AVClass libopusdec_class
static av_cold int libopus_decode_close(AVCodecContext *avc)
static int libopus_decode(AVCodecContext *avc, void *data, int *got_frame_ptr, AVPacket *pkt)
static const AVOption libopusdec_options[]
static void libopus_flush(AVCodecContext *avc)
AVCodec ff_libopus_decoder
static av_const int sign_extend(int val, unsigned bits)
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.
enum AVSampleFormat sample_fmt
audio sample format
enum AVSampleFormat request_sample_fmt
desired sample format
int sample_rate
samples per second
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int channels
number of audio channels
uint64_t channel_layout
Audio channel layout.
struct AVCodecInternal * internal
Private context used for internal data.
int skip_samples
Number of audio samples to skip at the start of the next decoded frame.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
int nb_samples
number of audio samples (per channel) described by this frame
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
This structure stores compressed data.
union libopus_context::@82 gain
const uint8_t ff_vorbis_channel_layout_offsets[8][8]
const uint64_t ff_vorbis_channel_layouts[9]