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}
diff --git a/api/audio_codecs/audio_encoder_factory_template.h b/api/audio_codecs/audio_encoder_factory_template.h
index 060ba8c..6d4d9d6 100644
--- a/api/audio_codecs/audio_encoder_factory_template.h
+++ b/api/audio_codecs/audio_encoder_factory_template.h
@@ -22,6 +22,23 @@
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 @@
}
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 @@
}
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 @@
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 @@
// // 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