From ba5a6c3d8999df0bfbbd1bb8c20ed805fc14705b Mon Sep 17 00:00:00 2001 From: "tina.legrand@webrtc.org" Date: Sun, 23 Mar 2014 09:58:48 +0000 Subject: [PATCH] ACM2/NetEq4 did not decode Opus in stereo Two problems fixed in this CL: - setting Opus decoder to stereo had no effect, and decoding always generated mono audio - changing decoding setting from mono to stereo, or stereo to mono, for OPUS also had no effect (but required another change than the first one). BUG=3082 R=henrik.lundin@webrtc.org, turaj@webrtc.org Review URL: https://webrtc-codereview.appspot.com/10389004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@5754 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../modules/audio_coding/main/acm2/acm_receiver.cc | 12 +++++++++--- webrtc/modules/audio_coding/main/test/opus_test.cc | 5 +++++ webrtc/modules/audio_coding/neteq4/neteq_impl.cc | 7 +++---- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/webrtc/modules/audio_coding/main/acm2/acm_receiver.cc b/webrtc/modules/audio_coding/main/acm2/acm_receiver.cc index 973956fe1e..7c124c7e3b 100644 --- a/webrtc/modules/audio_coding/main/acm2/acm_receiver.cc +++ b/webrtc/modules/audio_coding/main/acm2/acm_receiver.cc @@ -473,19 +473,25 @@ int32_t AcmReceiver::AddCodec(int acm_codec_id, assert(acm_codec_id >= 0 && acm_codec_id < ACMCodecDB::kMaxNumCodecs); NetEqDecoder neteq_decoder = ACMCodecDB::neteq_decoders_[acm_codec_id]; + // Make sure the right decoder is registered for Opus. + if (neteq_decoder == kDecoderOpus && channels == 2) { + neteq_decoder = kDecoderOpus_2ch; + } + CriticalSectionScoped lock(neteq_crit_sect_); // The corresponding NetEq decoder ID. // If this coder has been registered before. if (decoders_[acm_codec_id].registered) { - if (decoders_[acm_codec_id].payload_type == payload_type) { + if (decoders_[acm_codec_id].payload_type == payload_type && + decoders_[acm_codec_id].channels == channels) { // Re-registering the same codec with the same payload-type. Do nothing // and return. return 0; } - // Changing the payload-type of this codec. First unregister. Then register - // with new payload-type. + // Changing the payload-type or number of channels for this codec. + // First unregister. Then register with new payload-type/channels. if (neteq_->RemovePayloadType(decoders_[acm_codec_id].payload_type) != NetEq::kOK) { LOG_F(LS_ERROR) << "Cannot remover payload " diff --git a/webrtc/modules/audio_coding/main/test/opus_test.cc b/webrtc/modules/audio_coding/main/test/opus_test.cc index 3c9adb7019..5eec83b7f5 100644 --- a/webrtc/modules/audio_coding/main/test/opus_test.cc +++ b/webrtc/modules/audio_coding/main/test/opus_test.cc @@ -333,6 +333,11 @@ void OpusTest::Run(TestPackStereo* channel, int channels, int bitrate, // Write stand-alone speech to file. out_file_standalone_.Write10MsData(out_audio, decoded_samples * channels); + + // Number of channels should be the same for both stand-alone and + // ACM-decoding. + EXPECT_EQ(audio_frame.num_channels_, channels); + decoded_samples = 0; } diff --git a/webrtc/modules/audio_coding/neteq4/neteq_impl.cc b/webrtc/modules/audio_coding/neteq4/neteq_impl.cc index 8b7e5173a1..29569573f7 100644 --- a/webrtc/modules/audio_coding/neteq4/neteq_impl.cc +++ b/webrtc/modules/audio_coding/neteq4/neteq_impl.cc @@ -1145,12 +1145,11 @@ int NetEqImpl::Decode(PacketList* packet_list, Operations* operation, PacketBuffer::DeleteAllPackets(packet_list); return kDecoderNotFound; } - // We should have correct sampling rate and number of channels. They - // are set when packets are inserted. + // If sampling rate or number of channels has changed, we need to make + // a reset. if (decoder_info->fs_hz != fs_hz_ || decoder->channels() != algorithm_buffer_->Channels()) { - LOG_F(LS_ERROR) << "Sampling rate or number of channels mismatch."; - assert(false); + // TODO(tlegrand): Add unittest to cover this event. SetSampleRateAndChannels(decoder_info->fs_hz, decoder->channels()); } sync_buffer_->set_end_timestamp(timestamp_);