From d4e9f62ea7966a289d19076c7d53b3e1a70c3516 Mon Sep 17 00:00:00 2001 From: ossu Date: Thu, 18 Aug 2016 02:01:17 -0700 Subject: [PATCH] Updated AudioDecoderFactory to list AudioCodecSpecs instead of SdpAudioFormats. BUG=webrtc:5805 Review-Url: https://codereview.webrtc.org/2123923004 Cr-Commit-Position: refs/heads/master@{#13810} --- webrtc/media/engine/webrtcvoiceengine.cc | 18 ++++++------- .../codecs/audio_decoder_factory.h | 2 +- .../audio_coding/codecs/audio_format.h | 7 ++++- .../codecs/builtin_audio_decoder_factory.cc | 27 ++++++++++--------- .../codecs/mock/mock_audio_decoder_factory.h | 14 +++++----- 5 files changed, 36 insertions(+), 32 deletions(-) diff --git a/webrtc/media/engine/webrtcvoiceengine.cc b/webrtc/media/engine/webrtcvoiceengine.cc index bdc34bb1ed..eb8399494c 100644 --- a/webrtc/media/engine/webrtcvoiceengine.cc +++ b/webrtc/media/engine/webrtcvoiceengine.cc @@ -1093,8 +1093,8 @@ webrtc::AudioDeviceModule* WebRtcVoiceEngine::adm() { AudioCodecs WebRtcVoiceEngine::CollectRecvCodecs() const { PayloadTypeMapper mapper; AudioCodecs out; - const std::vector& formats = - decoder_factory_->GetSupportedFormats(); + const std::vector& specs = + decoder_factory_->GetSupportedDecoders(); // Only generate CN payload types for these clockrates std::map> generate_cn = {{ 8000, false }, @@ -1119,14 +1119,12 @@ AudioCodecs WebRtcVoiceEngine::CollectRecvCodecs() const { return true; }; - for (const auto& format : formats) { - if (map_format(format)) { - // TODO(ossu): We should get more than just a format from the factory, so - // we can determine if a format should be used with CN or not. For now, - // generate a CN entry for each supported clock rate also used by a format - // supported by the factory. - auto cn = generate_cn.find(format.clockrate_hz); - if (cn != generate_cn.end() /* && format.allow_comfort_noise */) { + for (const auto& spec : specs) { + if (map_format(spec.format) && spec.allow_comfort_noise) { + // Generate a CN entry if the decoder allows it and we support the + // clockrate. + auto cn = generate_cn.find(spec.format.clockrate_hz); + if (cn != generate_cn.end()) { cn->second = true; } } diff --git a/webrtc/modules/audio_coding/codecs/audio_decoder_factory.h b/webrtc/modules/audio_coding/codecs/audio_decoder_factory.h index 279667c9b7..93fca412b2 100644 --- a/webrtc/modules/audio_coding/codecs/audio_decoder_factory.h +++ b/webrtc/modules/audio_coding/codecs/audio_decoder_factory.h @@ -25,7 +25,7 @@ namespace webrtc { // NOTE: This class is still under development and may change without notice. class AudioDecoderFactory : public rtc::RefCountInterface { public: - virtual std::vector GetSupportedFormats() = 0; + virtual std::vector GetSupportedDecoders() = 0; virtual std::unique_ptr MakeAudioDecoder( const SdpAudioFormat& format) = 0; diff --git a/webrtc/modules/audio_coding/codecs/audio_format.h b/webrtc/modules/audio_coding/codecs/audio_format.h index 9b971778f8..43f82dcf04 100644 --- a/webrtc/modules/audio_coding/codecs/audio_format.h +++ b/webrtc/modules/audio_coding/codecs/audio_format.h @@ -39,12 +39,17 @@ struct SdpAudioFormat { int clockrate_hz; int num_channels; Parameters parameters; - // Parameters feedback_parameters; ?? }; void swap(SdpAudioFormat& a, SdpAudioFormat& b); std::ostream& operator<<(std::ostream& os, const SdpAudioFormat& saf); +struct AudioCodecSpec { + SdpAudioFormat format; + bool allow_comfort_noise; // This encoder can be used with an external + // comfort noise generator. +}; + } // namespace webrtc #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_AUDIO_FORMAT_H_ diff --git a/webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.cc b/webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.cc index a7f7404892..05b65c3b86 100644 --- a/webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.cc +++ b/webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.cc @@ -129,32 +129,33 @@ NamedDecoderConstructor decoder_constructors[] = { class BuiltinAudioDecoderFactory : public AudioDecoderFactory { public: - std::vector GetSupportedFormats() override { - static std::vector formats = { + std::vector GetSupportedDecoders() override { + static std::vector specs = { #ifdef WEBRTC_CODEC_OPUS - { "opus", 48000, 2, { - {"minptime", "10" }, - {"useinbandfec", "1" } - } + { { "opus", 48000, 2, { + {"minptime", "10" }, + {"useinbandfec", "1" } + } + }, false }, #endif #if (defined(WEBRTC_CODEC_ISAC) || defined(WEBRTC_CODEC_ISACFX)) - { "isac", 16000, 1 }, + { { "isac", 16000, 1 }, true }, #endif #if (defined(WEBRTC_CODEC_ISAC)) - { "isac", 32000, 1 }, + { { "isac", 32000, 1 }, true }, #endif #ifdef WEBRTC_CODEC_G722 - { "G722", 8000, 1 }, + { { "G722", 8000, 1 }, true }, #endif #ifdef WEBRTC_CODEC_ILBC - { "iLBC", 8000, 1 }, + { { "iLBC", 8000, 1 }, true }, #endif - { "PCMU", 8000, 1 }, - { "PCMA", 8000, 1 } + { { "PCMU", 8000, 1 }, true }, + { { "PCMA", 8000, 1 }, true } }; - return formats; + return specs; } std::unique_ptr MakeAudioDecoder( diff --git a/webrtc/modules/audio_coding/codecs/mock/mock_audio_decoder_factory.h b/webrtc/modules/audio_coding/codecs/mock/mock_audio_decoder_factory.h index f91a26bc10..59bbb78a4a 100644 --- a/webrtc/modules/audio_coding/codecs/mock/mock_audio_decoder_factory.h +++ b/webrtc/modules/audio_coding/codecs/mock/mock_audio_decoder_factory.h @@ -21,7 +21,7 @@ namespace webrtc { class MockAudioDecoderFactory : public AudioDecoderFactory { public: - MOCK_METHOD0(GetSupportedFormats, std::vector()); + MOCK_METHOD0(GetSupportedDecoders, std::vector()); std::unique_ptr MakeAudioDecoder( const SdpAudioFormat& format) { std::unique_ptr return_value; @@ -43,9 +43,9 @@ class MockAudioDecoderFactory : public AudioDecoderFactory { rtc::scoped_refptr factory = new rtc::RefCountedObject; - ON_CALL(*factory.get(), GetSupportedFormats()) - .WillByDefault(Return(std::vector())); - EXPECT_CALL(*factory.get(), GetSupportedFormats()).Times(AnyNumber()); + ON_CALL(*factory.get(), GetSupportedDecoders()) + .WillByDefault(Return(std::vector())); + EXPECT_CALL(*factory.get(), GetSupportedDecoders()).Times(AnyNumber()); EXPECT_CALL(*factory.get(), MakeAudioDecoderMock(_, _)).Times(0); return factory; } @@ -62,9 +62,9 @@ class MockAudioDecoderFactory : public AudioDecoderFactory { rtc::scoped_refptr factory = new rtc::RefCountedObject; - ON_CALL(*factory.get(), GetSupportedFormats()) - .WillByDefault(Return(std::vector())); - EXPECT_CALL(*factory.get(), GetSupportedFormats()).Times(AnyNumber()); + ON_CALL(*factory.get(), GetSupportedDecoders()) + .WillByDefault(Return(std::vector())); + EXPECT_CALL(*factory.get(), GetSupportedDecoders()).Times(AnyNumber()); ON_CALL(*factory.get(), MakeAudioDecoderMock(_, _)) .WillByDefault(SetArgPointee<1>(nullptr)); EXPECT_CALL(*factory.get(), MakeAudioDecoderMock(_, _)).Times(AnyNumber());