From 7eaf2f980fa3347dfd41555bea7c00c727c8af02 Mon Sep 17 00:00:00 2001 From: Karl Wiberg Date: Fri, 24 Nov 2017 14:17:27 +0100 Subject: [PATCH] Require audio codec API types to have a Config type member For uniformity. Uniformity is nice. Bug: none Change-Id: I3156c4db1f6f261ba035cf95b632fd413c8afc2a Reviewed-on: https://webrtc-review.googlesource.com/25482 Reviewed-by: Fredrik Solenberg Reviewed-by: Henrik Lundin Commit-Queue: Karl Wiberg Cr-Commit-Position: refs/heads/master@{#20937} --- .../audio_decoder_factory_template.h | 7 ++++++- .../audio_encoder_factory_template.h | 7 ++++++- api/audio_codecs/g722/audio_encoder_g722.h | 1 + api/audio_codecs/ilbc/audio_encoder_ilbc.h | 1 + .../audio_decoder_factory_template_unittest.cc | 17 ++++++++--------- .../audio_encoder_factory_template_unittest.cc | 17 ++++++++--------- 6 files changed, 30 insertions(+), 20 deletions(-) diff --git a/api/audio_codecs/audio_decoder_factory_template.h b/api/audio_codecs/audio_decoder_factory_template.h index a1933aa2b4..f40c271ec8 100644 --- a/api/audio_codecs/audio_decoder_factory_template.h +++ b/api/audio_codecs/audio_decoder_factory_template.h @@ -46,6 +46,10 @@ struct Helper { } static bool IsSupportedDecoder(const SdpAudioFormat& format) { auto opt_config = T::SdpToConfig(format); + static_assert(std::is_same>::value, + "T::SdpToConfig() must return a value of type " + "rtc::Optional"); return opt_config ? true : Helper::IsSupportedDecoder(format); } static std::unique_ptr MakeAudioDecoder( @@ -96,7 +100,8 @@ class AudioDecoderFactoryT : public AudioDecoderFactory { // std::unique_ptr MakeAudioDecoder(const ConfigType& config); // // ConfigType should be a type that encapsulates all the settings needed to -// create an AudioDecoder. +// create an AudioDecoder. T::Config (where T is the decoder struct) should +// either be the config type, or an alias for it. // // Whenever it tries to do something, the new factory will try each of the // decoder types in the order they were specified in the template argument diff --git a/api/audio_codecs/audio_encoder_factory_template.h b/api/audio_codecs/audio_encoder_factory_template.h index 1d0325d1a0..060ba8cb04 100644 --- a/api/audio_codecs/audio_encoder_factory_template.h +++ b/api/audio_codecs/audio_encoder_factory_template.h @@ -51,6 +51,10 @@ struct Helper { static rtc::Optional QueryAudioEncoder( const SdpAudioFormat& format) { auto opt_config = T::SdpToConfig(format); + static_assert(std::is_same>::value, + "T::SdpToConfig() must return a value of type " + "rtc::Optional"); return opt_config ? rtc::Optional( T::QueryAudioEncoder(*opt_config)) : Helper::QueryAudioEncoder(format); @@ -114,7 +118,8 @@ class AudioEncoderFactoryT : public AudioEncoderFactory { // int payload_type); // // ConfigType should be a type that encapsulates all the settings needed to -// create an AudioDecoder. +// create an AudioEncoder. T::Config (where T is the encoder struct) should +// either be the config type, or an alias for it. // // Whenever it tries to do something, the new factory will try each of the // encoders in the order they were specified in the template argument list, diff --git a/api/audio_codecs/g722/audio_encoder_g722.h b/api/audio_codecs/g722/audio_encoder_g722.h index 6c8b689894..0763615cf7 100644 --- a/api/audio_codecs/g722/audio_encoder_g722.h +++ b/api/audio_codecs/g722/audio_encoder_g722.h @@ -26,6 +26,7 @@ namespace webrtc { // // NOTE: This struct is still under development and may change without notice. struct AudioEncoderG722 { + using Config = AudioEncoderG722Config; static rtc::Optional SdpToConfig( const SdpAudioFormat& audio_format); static void AppendSupportedEncoders(std::vector* specs); diff --git a/api/audio_codecs/ilbc/audio_encoder_ilbc.h b/api/audio_codecs/ilbc/audio_encoder_ilbc.h index 22c7a67071..dd65375774 100644 --- a/api/audio_codecs/ilbc/audio_encoder_ilbc.h +++ b/api/audio_codecs/ilbc/audio_encoder_ilbc.h @@ -26,6 +26,7 @@ namespace webrtc { // // NOTE: This struct is still under development and may change without notice. struct AudioEncoderIlbc { + using Config = AudioEncoderIlbcConfig; static rtc::Optional SdpToConfig( const SdpAudioFormat& audio_format); static void AppendSupportedEncoders(std::vector* specs); diff --git a/api/audio_codecs/test/audio_decoder_factory_template_unittest.cc b/api/audio_codecs/test/audio_decoder_factory_template_unittest.cc index 071b53a77c..53199034c9 100644 --- a/api/audio_codecs/test/audio_decoder_factory_template_unittest.cc +++ b/api/audio_codecs/test/audio_decoder_factory_template_unittest.cc @@ -37,16 +37,15 @@ struct ShamParams { static AudioCodecInfo CodecInfo() { return {16000, 2, 23456}; } }; -struct MyLittleConfig { - SdpAudioFormat audio_format; -}; - template struct AudioDecoderFakeApi { - static rtc::Optional SdpToConfig( - const SdpAudioFormat& audio_format) { + struct Config { + SdpAudioFormat audio_format; + }; + + static rtc::Optional SdpToConfig(const SdpAudioFormat& audio_format) { if (Params::AudioFormat() == audio_format) { - MyLittleConfig config = {audio_format}; + Config config = {audio_format}; return config; } else { return rtc::nullopt; @@ -57,11 +56,11 @@ struct AudioDecoderFakeApi { specs->push_back({Params::AudioFormat(), Params::CodecInfo()}); } - static AudioCodecInfo QueryAudioDecoder(const MyLittleConfig&) { + static AudioCodecInfo QueryAudioDecoder(const Config&) { return Params::CodecInfo(); } - static std::unique_ptr MakeAudioDecoder(const MyLittleConfig&) { + static std::unique_ptr MakeAudioDecoder(const Config&) { auto dec = rtc::MakeUnique>(); EXPECT_CALL(*dec, SampleRateHz()) .WillOnce(testing::Return(Params::CodecInfo().sample_rate_hz)); diff --git a/api/audio_codecs/test/audio_encoder_factory_template_unittest.cc b/api/audio_codecs/test/audio_encoder_factory_template_unittest.cc index f6e4035088..4f16ff452f 100644 --- a/api/audio_codecs/test/audio_encoder_factory_template_unittest.cc +++ b/api/audio_codecs/test/audio_encoder_factory_template_unittest.cc @@ -37,16 +37,15 @@ struct ShamParams { static AudioCodecInfo CodecInfo() { return {16000, 2, 23456}; } }; -struct MyLittleConfig { - SdpAudioFormat audio_format; -}; - template struct AudioEncoderFakeApi { - static rtc::Optional SdpToConfig( - const SdpAudioFormat& audio_format) { + struct Config { + SdpAudioFormat audio_format; + }; + + static rtc::Optional SdpToConfig(const SdpAudioFormat& audio_format) { if (Params::AudioFormat() == audio_format) { - MyLittleConfig config = {audio_format}; + Config config = {audio_format}; return config; } else { return rtc::nullopt; @@ -57,11 +56,11 @@ struct AudioEncoderFakeApi { specs->push_back({Params::AudioFormat(), Params::CodecInfo()}); } - static AudioCodecInfo QueryAudioEncoder(const MyLittleConfig&) { + static AudioCodecInfo QueryAudioEncoder(const Config&) { return Params::CodecInfo(); } - static std::unique_ptr MakeAudioEncoder(const MyLittleConfig&, + static std::unique_ptr MakeAudioEncoder(const Config&, int payload_type) { auto enc = rtc::MakeUnique>(); EXPECT_CALL(*enc, SampleRateHz())