Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(989)

Unified Diff: webrtc/modules/audio_coding/include/audio_coding_module.h

Issue 1673213002: AudioCodingModule: Add methods for injecting external encoder stacks (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: more docs Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_coding/include/audio_coding_module.h
diff --git a/webrtc/modules/audio_coding/include/audio_coding_module.h b/webrtc/modules/audio_coding/include/audio_coding_module.h
index 9e7991f22f37930ea613c59ea702a9eb22210eba..55571f29d505197b764ee3b26f992e97edeb785e 100644
--- a/webrtc/modules/audio_coding/include/audio_coding_module.h
+++ b/webrtc/modules/audio_coding/include/audio_coding_module.h
@@ -207,6 +207,37 @@ class AudioCodingModule {
virtual void RegisterExternalSendCodec(
AudioEncoder* external_speech_encoder) = 0;
+ // Class for doing type erasure on a functor with signature
+ // AudioEncoder*(AudioEncoder*). Any functor with this signature will
+ // implicitly convert to EncoderVisitor.
+ class EncoderVisitor final {
+ public:
+ template <typename F>
+ EncoderVisitor(const F& f) : f_(&f), call_(Call<F>) {}
+ AudioEncoder* operator()(AudioEncoder* enc) const { return call_(f_, enc); }
+
+ private:
+ template <typename F>
+ static AudioEncoder* Call(const void* f, AudioEncoder* enc) {
+ return (*static_cast<const F*>(f))(enc);
+ }
+ const void* const f_;
+ AudioEncoder* (*const call_)(const void* f, AudioEncoder* enc);
+ };
+
+ // |ev| is called exactly once with one argument: the current encoder (or
+ // nullptr if there is no current encoder). For the duration of the call,
+ // |ev| has exclusive access to its argument. |ev|'s return value (which may
+ // be its argument, another AudioEncoder*, or nullptr) is the new current
+ // encoder. The encoder will be used as-is, without applying VAD/DTX or RED
+ // or anything.
+ virtual void VisitEncoder(const EncoderVisitor& ev) = 0;
+
+ // Utility method for simply replacing the existing encoder with a new one.
+ void SetEncoder(AudioEncoder* new_encoder) {
+ VisitEncoder([&](AudioEncoder* old_encoder) { return new_encoder; });
+ }
+
///////////////////////////////////////////////////////////////////////////
// int32_t SendCodec()
// Get parameters for the codec currently registered as send codec.
@@ -472,6 +503,29 @@ class AudioCodingModule {
//
virtual int RegisterReceiveCodec(const CodecInst& receive_codec) = 0;
+ // Class for doing type erasure on a functor with signature AudioDecoder*().
+ // Any functor with this signature will implicitly convert to DecoderFactory.
+ class DecoderFactory final {
+ public:
+ template <typename F>
+ DecoderFactory(const F& f) : f_(&f), call_(Call<F>) {}
+ AudioDecoder* operator()() const { return call_(f_); }
+
+ private:
+ template <typename F>
+ static AudioDecoder* Call(const void* f) {
+ return (*static_cast<const F*>(f))();
+ }
+ const void* const f_;
+ AudioDecoder* (*const call_)(const void* f);
+ };
+
+ // Register a decoder; call repeatedly to register multiple decoders. |df| is
+ // a decoder factory that returns an iSAC decoder; it will be called once if
+ // the decoder being registered is iSAC.
+ virtual int RegisterReceiveCodec(const CodecInst& receive_codec,
+ const DecoderFactory& df) = 0;
+
// Registers an external decoder. The name is only used to provide information
// back to the caller about the decoder. Hence, the name is arbitrary, and may
// be empty.

Powered by Google App Engine
This is Rietveld 408576698