23#include <opus_multistream.h>
45#ifdef OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST
50#define OPUS_HEAD_SIZE 19
56 uint8_t mapping_arr[8] = { 0, 1 }, *mapping;
61 "Invalid number of channels %d, defaulting to stereo\n",
channels);
90 "No channel mapping for %d channels.\n",
channels);
95 mapping = mapping_arr;
104 mapping_arr[ch] = mapping[vorbis_offset[ch]];
105 mapping = mapping_arr;
118 ret = opus_multistream_decoder_ctl(opus->
dec, OPUS_SET_GAIN(gain_db));
124 double gain_lin =
ff_exp10(gain_db / (20.0 * 256));
126 opus->
gain.
d = gain_lin;
128 opus->
gain.
i =
FFMIN(gain_lin * 65536, INT_MAX);
132#ifdef OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST
133 ret = opus_multistream_decoder_ctl(opus->
dec,
134 OPUS_SET_PHASE_INVERSION_DISABLED(!opus->apply_phase_inv));
137 "Unable to set phase inversion: %s\n",
152 opus_multistream_decoder_destroy(opus->
dec);
158#define MAX_FRAME_SIZE (960 * 6)
171 nb_samples = opus_multistream_decode(opus->
dec,
pkt->data,
pkt->size,
172 (opus_int16 *)
frame->data[0],
173 frame->nb_samples, 0);
175 nb_samples = opus_multistream_decode_float(opus->
dec,
pkt->data,
pkt->size,
176 (
float *)
frame->data[0],
177 frame->nb_samples, 0);
179 if (nb_samples < 0) {
181 opus_strerror(nb_samples));
189 float *pcm = (
float *)
frame->data[0];
190 for (;
i > 0;
i--, pcm++)
193 int16_t *pcm = (int16_t *)
frame->data[0];
194 for (;
i > 0;
i--, pcm++)
200 frame->nb_samples = nb_samples;
210 opus_multistream_decoder_ctl(opus->
dec, OPUS_RESET_STATE);
217#define OFFSET(x) offsetof(struct libopus_context, x)
218#define FLAGS AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM
220#ifdef OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST
221 {
"apply_phase_inv",
"Apply intensity stereo phase inversion",
OFFSET(apply_phase_inv),
AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1,
FLAGS },
227 .class_name =
"libopusdec",
249 .p.wrapper_name =
"libopus",
const FFCodec ff_libopus_decoder
static const uint8_t channel_map[8][8]
Libavcodec external API header.
#define i(width, name, range_min, range_max)
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define CODEC_SAMPLEFMTS(...)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int(* init)(AVBSFContext *ctx)
internal math functions header
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
static unsigned int nb_streams
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
#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.
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
#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.
@ AV_SAMPLE_FMT_S16
signed 16 bits
#define LIBAVUTIL_VERSION_INT
common internal api header.
common internal API header
int ff_opus_error_to_averror(int err)
static av_cold int libopus_decode_init(AVCodecContext *avc)
static const AVClass libopusdec_class
static int libopus_decode(AVCodecContext *avc, AVFrame *frame, int *got_frame_ptr, AVPacket *pkt)
static av_cold int libopus_decode_close(AVCodecContext *avc)
static const AVOption libopusdec_options[]
static void libopus_flush(AVCodecContext *avc)
static av_const int sign_extend(int val, unsigned bits)
enum AVChannelOrder order
Channel order used in this layout.
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
enum AVSampleFormat request_sample_fmt
desired sample format
int sample_rate
samples per second
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
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.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
union libopus_context::@247020046336201346334172224354210264025236321146 gain
const AVChannelLayout ff_vorbis_ch_layouts[9]
const uint8_t ff_vorbis_channel_layout_offsets[8][8]