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}
This commit is contained in:
Karl Wiberg 2017-11-24 14:17:27 +01:00 committed by Commit Bot
parent 94f3930106
commit 7eaf2f980f
6 changed files with 30 additions and 20 deletions

View File

@ -46,6 +46,10 @@ struct Helper<T, Ts...> {
}
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 @@ class AudioDecoderFactoryT : public AudioDecoderFactory {
// 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

View File

@ -51,6 +51,10 @@ struct Helper<T, Ts...> {
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 @@ 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,

View File

@ -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<AudioEncoderG722Config> SdpToConfig(
const SdpAudioFormat& audio_format);
static void AppendSupportedEncoders(std::vector<AudioCodecSpec>* specs);

View File

@ -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<AudioEncoderIlbcConfig> SdpToConfig(
const SdpAudioFormat& audio_format);
static void AppendSupportedEncoders(std::vector<AudioCodecSpec>* specs);

View File

@ -37,16 +37,15 @@ struct ShamParams {
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 @@ 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<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));

View File

@ -37,16 +37,15 @@ struct ShamParams {
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 @@ 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<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())