summaryrefslogtreecommitdiff
path: root/libavcodec/libopusdec.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2019-06-03 17:54:20 +0200
committerJames Almer <jamrial@gmail.com>2022-03-15 09:42:43 -0300
commite869c06ef58c8574b1ba06fdc15ea643229f8ff7 (patch)
tree755ea711385a080ecc708ddff5fb1d5ed54020ea /libavcodec/libopusdec.c
parente0bb126de8294cb0d49495caf99aaa582ef51daa (diff)
libopus: convert to new channel layout API
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavcodec/libopusdec.c')
-rw-r--r--libavcodec/libopusdec.c39
1 files changed, 22 insertions, 17 deletions
diff --git a/libavcodec/libopusdec.c b/libavcodec/libopusdec.c
index 86ef715205..e4d127ad74 100644
--- a/libavcodec/libopusdec.c
+++ b/libavcodec/libopusdec.c
@@ -50,55 +50,60 @@ struct libopus_context {
static av_cold int libopus_decode_init(AVCodecContext *avc)
{
struct libopus_context *opus = avc->priv_data;
- int ret, channel_map = 0, gain_db = 0, nb_streams, nb_coupled;
+ int ret, channel_map = 0, gain_db = 0, nb_streams, nb_coupled, channels;
uint8_t mapping_arr[8] = { 0, 1 }, *mapping;
- avc->channels = avc->extradata_size >= 10 ? avc->extradata[9] : (avc->channels == 1) ? 1 : 2;
- if (avc->channels <= 0) {
+ channels = avc->extradata_size >= 10 ? avc->extradata[9] : (avc->ch_layout.nb_channels == 1) ? 1 : 2;
+ if (channels <= 0) {
av_log(avc, AV_LOG_WARNING,
- "Invalid number of channels %d, defaulting to stereo\n", avc->channels);
- avc->channels = 2;
+ "Invalid number of channels %d, defaulting to stereo\n", channels);
+ channels = 2;
}
avc->sample_rate = 48000;
avc->sample_fmt = avc->request_sample_fmt == AV_SAMPLE_FMT_FLT ?
AV_SAMPLE_FMT_FLT : AV_SAMPLE_FMT_S16;
- avc->channel_layout = avc->channels > 8 ? 0 :
- ff_vorbis_channel_layouts[avc->channels - 1];
+ av_channel_layout_uninit(&avc->ch_layout);
+ if (channels > 8) {
+ avc->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+ avc->ch_layout.nb_channels = channels;
+ } else {
+ av_channel_layout_copy(&avc->ch_layout, &ff_vorbis_ch_layouts[channels - 1]);
+ }
if (avc->extradata_size >= OPUS_HEAD_SIZE) {
opus->pre_skip = AV_RL16(avc->extradata + 10);
gain_db = sign_extend(AV_RL16(avc->extradata + 16), 16);
channel_map = AV_RL8 (avc->extradata + 18);
}
- if (avc->extradata_size >= OPUS_HEAD_SIZE + 2 + avc->channels) {
+ if (avc->extradata_size >= OPUS_HEAD_SIZE + 2 + channels) {
nb_streams = avc->extradata[OPUS_HEAD_SIZE + 0];
nb_coupled = avc->extradata[OPUS_HEAD_SIZE + 1];
- if (nb_streams + nb_coupled != avc->channels)
+ if (nb_streams + nb_coupled != channels)
av_log(avc, AV_LOG_WARNING, "Inconsistent channel mapping.\n");
mapping = avc->extradata + OPUS_HEAD_SIZE + 2;
} else {
- if (avc->channels > 2 || channel_map) {
+ if (channels > 2 || channel_map) {
av_log(avc, AV_LOG_ERROR,
- "No channel mapping for %d channels.\n", avc->channels);
+ "No channel mapping for %d channels.\n", channels);
return AVERROR(EINVAL);
}
nb_streams = 1;
- nb_coupled = avc->channels > 1;
+ nb_coupled = channels > 1;
mapping = mapping_arr;
}
- if (avc->channels > 2 && avc->channels <= 8) {
- const uint8_t *vorbis_offset = ff_vorbis_channel_layout_offsets[avc->channels - 1];
+ if (channels > 2 && channels <= 8) {
+ const uint8_t *vorbis_offset = ff_vorbis_channel_layout_offsets[channels - 1];
int ch;
/* Remap channels from Vorbis order to ffmpeg order */
- for (ch = 0; ch < avc->channels; ch++)
+ for (ch = 0; ch < channels; ch++)
mapping_arr[ch] = mapping[vorbis_offset[ch]];
mapping = mapping_arr;
}
- opus->dec = opus_multistream_decoder_create(avc->sample_rate, avc->channels,
+ opus->dec = opus_multistream_decoder_create(avc->sample_rate, channels,
nb_streams, nb_coupled,
mapping, &ret);
if (!opus->dec) {
@@ -178,7 +183,7 @@ static int libopus_decode(AVCodecContext *avc, void *data,
#ifndef OPUS_SET_GAIN
{
- int i = avc->channels * nb_samples;
+ int i = avc->ch_layout.nb_channels * nb_samples;
if (avc->sample_fmt == AV_SAMPLE_FMT_FLT) {
float *pcm = (float *)frame->data[0];
for (; i > 0; i--, pcm++)