OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 189 matching lines...) Loading... |
200 // -1 if failed to initialize, | 200 // -1 if failed to initialize, |
201 // 0 if succeeded. | 201 // 0 if succeeded. |
202 // | 202 // |
203 virtual int32_t RegisterSendCodec(const CodecInst& send_codec) = 0; | 203 virtual int32_t RegisterSendCodec(const CodecInst& send_codec) = 0; |
204 | 204 |
205 // Registers |external_speech_encoder| as encoder. The new encoder will | 205 // Registers |external_speech_encoder| as encoder. The new encoder will |
206 // replace any previously registered speech encoder (internal or external). | 206 // replace any previously registered speech encoder (internal or external). |
207 virtual void RegisterExternalSendCodec( | 207 virtual void RegisterExternalSendCodec( |
208 AudioEncoder* external_speech_encoder) = 0; | 208 AudioEncoder* external_speech_encoder) = 0; |
209 | 209 |
| 210 // Class for doing type erasure on a functor with signature |
| 211 // AudioEncoder*(AudioEncoder*). Any functor with this signature will |
| 212 // implicitly convert to EncoderVisitor. |
| 213 class EncoderVisitor final { |
| 214 public: |
| 215 template <typename F> |
| 216 EncoderVisitor(const F& f) : f_(&f), call_(Call<F>) {} |
| 217 AudioEncoder* operator()(AudioEncoder* enc) const { return call_(f_, enc); } |
| 218 |
| 219 private: |
| 220 template <typename F> |
| 221 static AudioEncoder* Call(const void* f, AudioEncoder* enc) { |
| 222 return (*static_cast<const F*>(f))(enc); |
| 223 } |
| 224 const void* const f_; |
| 225 AudioEncoder* (*const call_)(const void* f, AudioEncoder* enc); |
| 226 }; |
| 227 |
| 228 // |ev| is called exactly once with one argument: the current encoder (or |
| 229 // nullptr if there is no current encoder). For the duration of the call, |
| 230 // |ev| has exclusive access to its argument. |ev|'s return value (which may |
| 231 // be its argument, another AudioEncoder*, or nullptr) is the new current |
| 232 // encoder. The encoder will be used as-is, without applying VAD/DTX or RED |
| 233 // or anything. |
| 234 virtual void VisitEncoder(const EncoderVisitor& ev) = 0; |
| 235 |
| 236 // Utility method for simply replacing the existing encoder with a new one. |
| 237 void SetEncoder(AudioEncoder* new_encoder) { |
| 238 VisitEncoder([&](AudioEncoder* old_encoder) { return new_encoder; }); |
| 239 } |
| 240 |
210 /////////////////////////////////////////////////////////////////////////// | 241 /////////////////////////////////////////////////////////////////////////// |
211 // int32_t SendCodec() | 242 // int32_t SendCodec() |
212 // Get parameters for the codec currently registered as send codec. | 243 // Get parameters for the codec currently registered as send codec. |
213 // | 244 // |
214 // Return value: | 245 // Return value: |
215 // The send codec, or nothing if we don't have one | 246 // The send codec, or nothing if we don't have one |
216 // | 247 // |
217 virtual rtc::Optional<CodecInst> SendCodec() const = 0; | 248 virtual rtc::Optional<CodecInst> SendCodec() const = 0; |
218 | 249 |
219 /////////////////////////////////////////////////////////////////////////// | 250 /////////////////////////////////////////////////////////////////////////// |
(...skipping 245 matching lines...) Loading... |
465 // -receive_codec : parameters of the codec to be registered, c.f. | 496 // -receive_codec : parameters of the codec to be registered, c.f. |
466 // common_types.h for the definition of | 497 // common_types.h for the definition of |
467 // CodecInst. | 498 // CodecInst. |
468 // | 499 // |
469 // Return value: | 500 // Return value: |
470 // -1 if failed to register the codec | 501 // -1 if failed to register the codec |
471 // 0 if the codec registered successfully. | 502 // 0 if the codec registered successfully. |
472 // | 503 // |
473 virtual int RegisterReceiveCodec(const CodecInst& receive_codec) = 0; | 504 virtual int RegisterReceiveCodec(const CodecInst& receive_codec) = 0; |
474 | 505 |
| 506 // Class for doing type erasure on a functor with signature AudioDecoder*(). |
| 507 // Any functor with this signature will implicitly convert to DecoderFactory. |
| 508 class DecoderFactory final { |
| 509 public: |
| 510 template <typename F> |
| 511 DecoderFactory(const F& f) : f_(&f), call_(Call<F>) {} |
| 512 AudioDecoder* operator()() const { return call_(f_); } |
| 513 |
| 514 private: |
| 515 template <typename F> |
| 516 static AudioDecoder* Call(const void* f) { |
| 517 return (*static_cast<const F*>(f))(); |
| 518 } |
| 519 const void* const f_; |
| 520 AudioDecoder* (*const call_)(const void* f); |
| 521 }; |
| 522 |
| 523 // Register a decoder; call repeatedly to register multiple decoders. |df| is |
| 524 // a decoder factory that returns an iSAC decoder; it will be called once if |
| 525 // the decoder being registered is iSAC. |
| 526 virtual int RegisterReceiveCodec(const CodecInst& receive_codec, |
| 527 const DecoderFactory& df) = 0; |
| 528 |
475 // Registers an external decoder. The name is only used to provide information | 529 // Registers an external decoder. The name is only used to provide information |
476 // back to the caller about the decoder. Hence, the name is arbitrary, and may | 530 // back to the caller about the decoder. Hence, the name is arbitrary, and may |
477 // be empty. | 531 // be empty. |
478 virtual int RegisterExternalReceiveCodec(int rtp_payload_type, | 532 virtual int RegisterExternalReceiveCodec(int rtp_payload_type, |
479 AudioDecoder* external_decoder, | 533 AudioDecoder* external_decoder, |
480 int sample_rate_hz, | 534 int sample_rate_hz, |
481 int num_channels, | 535 int num_channels, |
482 const std::string& name) = 0; | 536 const std::string& name) = 0; |
483 | 537 |
484 /////////////////////////////////////////////////////////////////////////// | 538 /////////////////////////////////////////////////////////////////////////// |
(...skipping 252 matching lines...) Loading... |
737 virtual std::vector<uint16_t> GetNackList( | 791 virtual std::vector<uint16_t> GetNackList( |
738 int64_t round_trip_time_ms) const = 0; | 792 int64_t round_trip_time_ms) const = 0; |
739 | 793 |
740 virtual void GetDecodingCallStatistics( | 794 virtual void GetDecodingCallStatistics( |
741 AudioDecodingCallStats* call_stats) const = 0; | 795 AudioDecodingCallStats* call_stats) const = 0; |
742 }; | 796 }; |
743 | 797 |
744 } // namespace webrtc | 798 } // namespace webrtc |
745 | 799 |
746 #endif // WEBRTC_MODULES_AUDIO_CODING_INCLUDE_AUDIO_CODING_MODULE_H_ | 800 #endif // WEBRTC_MODULES_AUDIO_CODING_INCLUDE_AUDIO_CODING_MODULE_H_ |
OLD | NEW |