23 #include <opus_multistream.h>
42 #define OPUS_HEAD_SIZE 19
47 int ret, channel_map = 0, gain_db = 0,
nb_streams, nb_coupled;
48 uint8_t mapping_arr[8] = { 0, 1 }, *mapping;
68 if (avc->
channels > 2 || channel_map) {
70 "No channel mapping for %d channels.\n", avc->
channels);
75 mapping = mapping_arr;
83 for (ch = 0; ch < avc->
channels; ch++)
84 mapping_arr[ch] = mapping[vorbis_offset[ch]];
85 mapping = mapping_arr;
98 ret = opus_multistream_decoder_ctl(opus->
dec, OPUS_SET_GAIN(gain_db));
104 double gain_lin =
ff_exp10(gain_db / (20.0 * 256));
106 opus->
gain.
d = gain_lin;
108 opus->
gain.
i =
FFMIN(gain_lin * 65536, INT_MAX);
122 opus_multistream_decoder_destroy(opus->
dec);
126 #define MAX_FRAME_SIZE (960 * 6)
140 nb_samples = opus_multistream_decode(opus->
dec, pkt->
data, pkt->
size,
141 (opus_int16 *)frame->
data[0],
144 nb_samples = opus_multistream_decode_float(opus->
dec, pkt->
data, pkt->
size,
145 (
float *)frame->
data[0],
148 if (nb_samples < 0) {
150 opus_strerror(nb_samples));
154 #ifndef OPUS_SET_GAIN
158 float *pcm = (
float *)frame->
data[0];
159 for (; i > 0; i--, pcm++)
160 *pcm = av_clipf(*pcm * opus->
gain.
d, -1, 1);
162 int16_t *pcm = (int16_t *)frame->
data[0];
163 for (; i > 0; i--, pcm++)
164 *pcm = av_clip_int16(((int64_t)opus->
gain.
i * *pcm) >> 16);
179 opus_multistream_decoder_ctl(opus->
dec, OPUS_RESET_STATE);
static int libopus_decode(AVCodecContext *avc, void *data, int *got_frame_ptr, AVPacket *pkt)
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
#define AV_LOG_WARNING
Something somehow does not look correct.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
AVCodec ff_libopus_decoder
int ff_opus_error_to_averror(int err)
enum AVSampleFormat sample_fmt
audio sample format
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
enum AVSampleFormat request_sample_fmt
desired sample format
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
const char * name
Name of the codec implementation.
uint64_t channel_layout
Audio channel layout.
common internal API header
static av_cold int libopus_decode_init(AVCodecContext *avc)
Libavcodec external API header.
AVSampleFormat
Audio sample formats.
int sample_rate
samples per second
main external API structure.
const uint64_t ff_vorbis_channel_layouts[9]
static void libopus_flush(AVCodecContext *avc)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int skip_samples
Number of audio samples to skip at the start of the next decoded frame.
union libopus_context::@68 gain
static av_const int sign_extend(int val, unsigned bits)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
common internal api header.
int channels
number of audio channels
struct AVCodecInternal * internal
Private context used for internal data.
static av_cold int libopus_decode_close(AVCodecContext *avc)
const uint8_t ff_vorbis_channel_layout_offsets[8][8]
This structure stores compressed data.
int nb_samples
number of audio samples (per channel) described by this frame
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.