From d120192f320ef6ab0c52a0680b29bf8b73eec005 Mon Sep 17 00:00:00 2001 From: kwiberg Date: Tue, 20 Sep 2016 15:18:21 -0700 Subject: [PATCH] AcmReceiver::DecoderByPayloadType: Ask NetEq for decoder Instead of looking in AcmReceiver::decoders_, which we're trying to get rid of. (This is a re-land of https://codereview.webrtc.org/2341283002.) BUG=webrtc:5801 Review-Url: https://codereview.webrtc.org/2352623002 Cr-Commit-Position: refs/heads/master@{#14312} --- .../modules/audio_coding/acm2/acm_receiver.cc | 14 +++++--------- .../acm2/acm_receiver_unittest_oldapi.cc | 19 ++++++++++--------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/webrtc/modules/audio_coding/acm2/acm_receiver.cc b/webrtc/modules/audio_coding/acm2/acm_receiver.cc index cbf3492955..85cbd8a4ed 100644 --- a/webrtc/modules/audio_coding/acm2/acm_receiver.cc +++ b/webrtc/modules/audio_coding/acm2/acm_receiver.cc @@ -315,19 +315,15 @@ void AcmReceiver::GetNetworkStatistics(NetworkStatistics* acm_stat) { int AcmReceiver::DecoderByPayloadType(uint8_t payload_type, CodecInst* codec) const { rtc::CritScope lock(&crit_sect_); - auto it = decoders_.find(payload_type); - if (it == decoders_.end()) { + const rtc::Optional ci = neteq_->GetDecoder(payload_type); + if (ci) { + *codec = *ci; + return 0; + } else { LOG(LERROR) << "AcmReceiver::DecoderByPayloadType " << static_cast(payload_type); return -1; } - const Decoder& decoder = it->second; - *codec = *RentACodec::CodecInstById( - *RentACodec::CodecIdFromIndex(decoder.acm_codec_id)); - codec->pltype = decoder.payload_type; - codec->channels = decoder.channels; - codec->plfreq = decoder.sample_rate_hz; - return 0; } int AcmReceiver::EnableNack(size_t max_nack_list_size) { diff --git a/webrtc/modules/audio_coding/acm2/acm_receiver_unittest_oldapi.cc b/webrtc/modules/audio_coding/acm2/acm_receiver_unittest_oldapi.cc index 5622fc1073..aa4660723d 100644 --- a/webrtc/modules/audio_coding/acm2/acm_receiver_unittest_oldapi.cc +++ b/webrtc/modules/audio_coding/acm2/acm_receiver_unittest_oldapi.cc @@ -174,10 +174,11 @@ class AcmReceiverTestOldApi : public AudioPacketizationCallback, TEST_F(AcmReceiverTestOldApi, MAYBE_AddCodecGetCodec) { // Add codec. for (size_t n = 0; n < codecs_.size(); ++n) { - if (n & 0x1) // Just add codecs with odd index. - EXPECT_EQ(0, - receiver_->AddCodec(n, codecs_[n].pltype, codecs_[n].channels, - codecs_[n].plfreq, NULL, "")); + if (n & 0x1) { // Just add codecs with odd index. + EXPECT_EQ( + 0, receiver_->AddCodec(n, codecs_[n].pltype, codecs_[n].channels, + codecs_[n].plfreq, NULL, codecs_[n].plname)); + } } // Get codec and compare. for (size_t n = 0; n < codecs_.size(); ++n) { @@ -209,9 +210,9 @@ TEST_F(AcmReceiverTestOldApi, MAYBE_AddCodecChangePayloadType) { // Register the same codec with different payloads. EXPECT_EQ(0, receiver_->AddCodec(codec1.id, codec1.inst.pltype, codec1.inst.channels, codec1.inst.plfreq, - nullptr, "")); + nullptr, codec1.inst.plname)); EXPECT_EQ(0, receiver_->AddCodec(codec1.id, codec2.pltype, codec2.channels, - codec2.plfreq, NULL, "")); + codec2.plfreq, NULL, codec2.plname)); // Both payload types should exist. EXPECT_EQ(0, @@ -235,10 +236,10 @@ TEST_F(AcmReceiverTestOldApi, AddCodecChangeCodecId) { // Register the same payload type with different codec ID. EXPECT_EQ(0, receiver_->AddCodec(codec1.id, codec1.inst.pltype, codec1.inst.channels, codec1.inst.plfreq, - nullptr, "")); + nullptr, codec1.inst.plname)); EXPECT_EQ(0, receiver_->AddCodec(codec2.id, codec2.inst.pltype, codec2.inst.channels, codec2.inst.plfreq, - nullptr, "")); + nullptr, codec2.inst.plname)); // Make sure that the last codec is used. EXPECT_EQ(0, @@ -256,7 +257,7 @@ TEST_F(AcmReceiverTestOldApi, MAYBE_AddCodecRemoveCodec) { const int payload_type = codec.inst.pltype; EXPECT_EQ( 0, receiver_->AddCodec(codec.id, codec.inst.pltype, codec.inst.channels, - codec.inst.plfreq, nullptr, "")); + codec.inst.plfreq, nullptr, codec.inst.plname)); // Remove non-existing codec should not fail. ACM1 legacy. EXPECT_EQ(0, receiver_->RemoveCodec(payload_type + 1));