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 <solenberg@webrtc.org>
Reviewed-by: Henrik Lundin <henrik.lundin@webrtc.org>
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20937}
diff --git a/api/audio_codecs/audio_decoder_factory_template.h b/api/audio_codecs/audio_decoder_factory_template.h
index a1933aa..f40c271 100644
--- a/api/audio_codecs/audio_decoder_factory_template.h
+++ b/api/audio_codecs/audio_decoder_factory_template.h
@@ -46,6 +46,10 @@
}
static bool IsSupportedDecoder(const SdpAudioFormat& format) {
auto opt_config = T::SdpToConfig(format);
+ static_assert(std::is_same<decltype(opt_config),
+ rtc::Optional<typename T::Config>>::value,
+ "T::SdpToConfig() must return a value of type "
+ "rtc::Optional<T::Config>");
return opt_config ? true : Helper<Ts...>::IsSupportedDecoder(format);
}
static std::unique_ptr<AudioDecoder> MakeAudioDecoder(
@@ -96,7 +100,8 @@
// std::unique_ptr<AudioDecoder> 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 1d0325d..060ba8c 100644
--- a/api/audio_codecs/audio_encoder_factory_template.h
+++ b/api/audio_codecs/audio_encoder_factory_template.h
@@ -51,6 +51,10 @@
static rtc::Optional<AudioCodecInfo> QueryAudioEncoder(
const SdpAudioFormat& format) {
auto opt_config = T::SdpToConfig(format);
+ static_assert(std::is_same<decltype(opt_config),
+ rtc::Optional<typename T::Config>>::value,
+ "T::SdpToConfig() must return a value of type "
+ "rtc::Optional<T::Config>");
return opt_config ? rtc::Optional<AudioCodecInfo>(
T::QueryAudioEncoder(*opt_config))
: Helper<Ts...>::QueryAudioEncoder(format);
@@ -114,7 +118,8 @@
// 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 6c8b689..0763615 100644
--- a/api/audio_codecs/g722/audio_encoder_g722.h
+++ b/api/audio_codecs/g722/audio_encoder_g722.h
@@ -26,6 +26,7 @@
//
// NOTE: This struct is still under development and may change without notice.
struct AudioEncoderG722 {
+ using Config = AudioEncoderG722Config;
static rtc::Optional<AudioEncoderG722Config> SdpToConfig(
const SdpAudioFormat& audio_format);
static void AppendSupportedEncoders(std::vector<AudioCodecSpec>* specs);
diff --git a/api/audio_codecs/ilbc/audio_encoder_ilbc.h b/api/audio_codecs/ilbc/audio_encoder_ilbc.h
index 22c7a67..dd65375 100644
--- a/api/audio_codecs/ilbc/audio_encoder_ilbc.h
+++ b/api/audio_codecs/ilbc/audio_encoder_ilbc.h
@@ -26,6 +26,7 @@
//
// NOTE: This struct is still under development and may change without notice.
struct AudioEncoderIlbc {
+ using Config = AudioEncoderIlbcConfig;
static rtc::Optional<AudioEncoderIlbcConfig> SdpToConfig(
const SdpAudioFormat& audio_format);
static void AppendSupportedEncoders(std::vector<AudioCodecSpec>* 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 071b53a..5319903 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 @@
static AudioCodecInfo CodecInfo() { return {16000, 2, 23456}; }
};
-struct MyLittleConfig {
- SdpAudioFormat audio_format;
-};
-
template <typename Params>
struct AudioDecoderFakeApi {
- static rtc::Optional<MyLittleConfig> SdpToConfig(
- const SdpAudioFormat& audio_format) {
+ struct Config {
+ SdpAudioFormat audio_format;
+ };
+
+ static rtc::Optional<Config> 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 @@
specs->push_back({Params::AudioFormat(), Params::CodecInfo()});
}
- static AudioCodecInfo QueryAudioDecoder(const MyLittleConfig&) {
+ static AudioCodecInfo QueryAudioDecoder(const Config&) {
return Params::CodecInfo();
}
- static std::unique_ptr<AudioDecoder> MakeAudioDecoder(const MyLittleConfig&) {
+ static std::unique_ptr<AudioDecoder> MakeAudioDecoder(const Config&) {
auto dec = rtc::MakeUnique<testing::StrictMock<MockAudioDecoder>>();
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 f6e4035..4f16ff4 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 @@
static AudioCodecInfo CodecInfo() { return {16000, 2, 23456}; }
};
-struct MyLittleConfig {
- SdpAudioFormat audio_format;
-};
-
template <typename Params>
struct AudioEncoderFakeApi {
- static rtc::Optional<MyLittleConfig> SdpToConfig(
- const SdpAudioFormat& audio_format) {
+ struct Config {
+ SdpAudioFormat audio_format;
+ };
+
+ static rtc::Optional<Config> 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 @@
specs->push_back({Params::AudioFormat(), Params::CodecInfo()});
}
- static AudioCodecInfo QueryAudioEncoder(const MyLittleConfig&) {
+ static AudioCodecInfo QueryAudioEncoder(const Config&) {
return Params::CodecInfo();
}
- static std::unique_ptr<AudioEncoder> MakeAudioEncoder(const MyLittleConfig&,
+ static std::unique_ptr<AudioEncoder> MakeAudioEncoder(const Config&,
int payload_type) {
auto enc = rtc::MakeUnique<testing::StrictMock<MockAudioEncoder>>();
EXPECT_CALL(*enc, SampleRateHz())