Adapt audio codec factory templates to the new codec pair ID arguments

We use template magic to let them handle both the presence and absence
of the new argument. This will be removed in a later CL, when we can
assume that new argument is always present.

Bug: webrtc:8941
Change-Id: I2d47f7c8572a9f03e742401dcf491b948b161f63
Reviewed-on: https://webrtc-review.googlesource.com/58081
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22301}
This commit is contained in:
Karl Wiberg
2018-03-05 20:24:57 +01:00
committed by Commit Bot
parent 94ffe90a88
commit 6b54228e8b
2 changed files with 99 additions and 12 deletions

View File

@ -22,6 +22,22 @@ namespace webrtc {
namespace audio_decoder_factory_template_impl {
template <typename T, typename ConfigT>
class MakeAudioDecoderTakesTwoArgs {
private:
template <typename U>
static auto Test(int) -> decltype(
U::MakeAudioDecoder(std::declval<ConfigT>(),
std::declval<rtc::Optional<AudioCodecPairId>>()),
std::true_type());
template <typename U>
static std::false_type Test(...);
public:
static constexpr bool value = decltype(Test<T>(0))::value;
};
template <typename... Ts>
struct Helper;
@ -31,7 +47,8 @@ struct Helper<> {
static void AppendSupportedDecoders(std::vector<AudioCodecSpec>* specs) {}
static bool IsSupportedDecoder(const SdpAudioFormat& format) { return false; }
static std::unique_ptr<AudioDecoder> MakeAudioDecoder(
const SdpAudioFormat& format) {
const SdpAudioFormat& format,
rtc::Optional<AudioCodecPairId> codec_pair_id) {
return nullptr;
}
};
@ -53,10 +70,28 @@ struct Helper<T, Ts...> {
return opt_config ? true : Helper<Ts...>::IsSupportedDecoder(format);
}
static std::unique_ptr<AudioDecoder> MakeAudioDecoder(
const SdpAudioFormat& format) {
const SdpAudioFormat& format,
rtc::Optional<AudioCodecPairId> codec_pair_id) {
auto opt_config = T::SdpToConfig(format);
return opt_config ? T::MakeAudioDecoder(*opt_config)
: Helper<Ts...>::MakeAudioDecoder(format);
return opt_config ? CallMakeAudioDecoder(*opt_config, codec_pair_id)
: Helper<Ts...>::MakeAudioDecoder(format, codec_pair_id);
}
template <
typename ConfigT,
typename std::enable_if<
!MakeAudioDecoderTakesTwoArgs<T, ConfigT>::value>::type* = nullptr>
static decltype(T::MakeAudioDecoder(std::declval<ConfigT>()))
CallMakeAudioDecoder(const ConfigT& config,
rtc::Optional<AudioCodecPairId> codec_pair_id) {
return T::MakeAudioDecoder(config);
}
template <typename ConfigT>
static decltype(
T::MakeAudioDecoder(std::declval<ConfigT>(),
std::declval<rtc::Optional<AudioCodecPairId>>()))
CallMakeAudioDecoder(const ConfigT& config,
rtc::Optional<AudioCodecPairId> codec_pair_id) {
return T::MakeAudioDecoder(config, codec_pair_id);
}
};
@ -74,8 +109,9 @@ class AudioDecoderFactoryT : public AudioDecoderFactory {
}
std::unique_ptr<AudioDecoder> MakeAudioDecoder(
const SdpAudioFormat& format) override {
return Helper<Ts...>::MakeAudioDecoder(format);
const SdpAudioFormat& format,
rtc::Optional<AudioCodecPairId> codec_pair_id) override {
return Helper<Ts...>::MakeAudioDecoder(format, codec_pair_id);
}
};
@ -98,6 +134,10 @@ class AudioDecoderFactoryT : public AudioDecoderFactory {
// // Creates an AudioDecoder for the specified format. Used to implement
// // AudioDecoderFactory::MakeAudioDecoder().
// std::unique_ptr<AudioDecoder> MakeAudioDecoder(const ConfigType& config);
// OR
// std::unique_ptr<AudioDecoder> MakeAudioDecoder(
// const ConfigType& config,
// rtc::Optional<AudioCodecPairId> codec_pair_id);
//
// ConfigType should be a type that encapsulates all the settings needed to
// create an AudioDecoder. T::Config (where T is the decoder struct) should

View File

@ -22,6 +22,23 @@ namespace webrtc {
namespace audio_encoder_factory_template_impl {
template <typename T, typename ConfigT>
class MakeAudioEncoderTakesThreeArgs {
private:
template <typename U>
static auto Test(int) -> decltype(
U::MakeAudioEncoder(std::declval<ConfigT>(),
std::declval<int>(),
std::declval<rtc::Optional<AudioCodecPairId>>()),
std::true_type());
template <typename U>
static std::false_type Test(...);
public:
static constexpr bool value = decltype(Test<T>(0))::value;
};
template <typename... Ts>
struct Helper;
@ -35,7 +52,8 @@ struct Helper<> {
}
static std::unique_ptr<AudioEncoder> MakeAudioEncoder(
int payload_type,
const SdpAudioFormat& format) {
const SdpAudioFormat& format,
rtc::Optional<AudioCodecPairId> codec_pair_id) {
return nullptr;
}
};
@ -61,14 +79,37 @@ struct Helper<T, Ts...> {
}
static std::unique_ptr<AudioEncoder> MakeAudioEncoder(
int payload_type,
const SdpAudioFormat& format) {
const SdpAudioFormat& format,
rtc::Optional<AudioCodecPairId> codec_pair_id) {
auto opt_config = T::SdpToConfig(format);
if (opt_config) {
return T::MakeAudioEncoder(*opt_config, payload_type);
return CallMakeAudioEncoder(*opt_config, payload_type, codec_pair_id);
} else {
return Helper<Ts...>::MakeAudioEncoder(payload_type, format);
return Helper<Ts...>::MakeAudioEncoder(payload_type, format,
codec_pair_id);
}
}
template <
typename ConfigT,
typename std::enable_if<
!MakeAudioEncoderTakesThreeArgs<T, ConfigT>::value>::type* = nullptr>
static decltype(T::MakeAudioEncoder(std::declval<ConfigT>(),
std::declval<int>()))
CallMakeAudioEncoder(const ConfigT& config,
int payload_type,
rtc::Optional<AudioCodecPairId> codec_pair_id) {
return T::MakeAudioEncoder(config, payload_type);
}
template <typename ConfigT>
static decltype(
T::MakeAudioEncoder(std::declval<ConfigT>(),
std::declval<int>(),
std::declval<rtc::Optional<AudioCodecPairId>>()))
CallMakeAudioEncoder(const ConfigT& config,
int payload_type,
rtc::Optional<AudioCodecPairId> codec_pair_id) {
return T::MakeAudioEncoder(config, payload_type, codec_pair_id);
}
};
template <typename... Ts>
@ -87,8 +128,9 @@ class AudioEncoderFactoryT : public AudioEncoderFactory {
std::unique_ptr<AudioEncoder> MakeAudioEncoder(
int payload_type,
const SdpAudioFormat& format) override {
return Helper<Ts...>::MakeAudioEncoder(payload_type, format);
const SdpAudioFormat& format,
rtc::Optional<AudioCodecPairId> codec_pair_id) override {
return Helper<Ts...>::MakeAudioEncoder(payload_type, format, codec_pair_id);
}
};
@ -116,6 +158,11 @@ class AudioEncoderFactoryT : public AudioEncoderFactory {
// // AudioEncoderFactory::MakeAudioEncoder().
// std::unique_ptr<AudioEncoder> MakeAudioEncoder(const ConfigType& config,
// int payload_type);
// OR
// std::unique_ptr<AudioDecoder> MakeAudioEncoder(
// const ConfigType& config,
// int payload_type,
// rtc::Optional<AudioCodecPairId> codec_pair_id);
//
// ConfigType should be a type that encapsulates all the settings needed to
// create an AudioEncoder. T::Config (where T is the encoder struct) should