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 |
11 #ifndef WEBRTC_MODULES_AUDIO_CODING_INCLUDE_AUDIO_CODING_MODULE_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_CODING_INCLUDE_AUDIO_CODING_MODULE_H_ |
12 #define WEBRTC_MODULES_AUDIO_CODING_INCLUDE_AUDIO_CODING_MODULE_H_ | 12 #define WEBRTC_MODULES_AUDIO_CODING_INCLUDE_AUDIO_CODING_MODULE_H_ |
13 | 13 |
14 #include <memory> | 14 #include <memory> |
15 #include <string> | 15 #include <string> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "webrtc/base/deprecation.h" | 18 #include "webrtc/base/deprecation.h" |
| 19 #include "webrtc/base/function_view.h" |
19 #include "webrtc/base/optional.h" | 20 #include "webrtc/base/optional.h" |
20 #include "webrtc/common_types.h" | 21 #include "webrtc/common_types.h" |
21 #include "webrtc/modules/audio_coding/codecs/audio_decoder_factory.h" | 22 #include "webrtc/modules/audio_coding/codecs/audio_decoder_factory.h" |
22 #include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h" | 23 #include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h" |
23 #include "webrtc/modules/audio_coding/neteq/include/neteq.h" | 24 #include "webrtc/modules/audio_coding/neteq/include/neteq.h" |
24 #include "webrtc/modules/include/module.h" | 25 #include "webrtc/modules/include/module.h" |
25 #include "webrtc/system_wrappers/include/clock.h" | 26 #include "webrtc/system_wrappers/include/clock.h" |
26 #include "webrtc/typedefs.h" | 27 #include "webrtc/typedefs.h" |
27 | 28 |
28 namespace webrtc { | 29 namespace webrtc { |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 // -1 if failed to initialize, | 203 // -1 if failed to initialize, |
203 // 0 if succeeded. | 204 // 0 if succeeded. |
204 // | 205 // |
205 virtual int32_t RegisterSendCodec(const CodecInst& send_codec) = 0; | 206 virtual int32_t RegisterSendCodec(const CodecInst& send_codec) = 0; |
206 | 207 |
207 // Registers |external_speech_encoder| as encoder. The new encoder will | 208 // Registers |external_speech_encoder| as encoder. The new encoder will |
208 // replace any previously registered speech encoder (internal or external). | 209 // replace any previously registered speech encoder (internal or external). |
209 virtual void RegisterExternalSendCodec( | 210 virtual void RegisterExternalSendCodec( |
210 AudioEncoder* external_speech_encoder) = 0; | 211 AudioEncoder* external_speech_encoder) = 0; |
211 | 212 |
212 // Just like std::function, FunctionView will wrap any callable and hide its | |
213 // actual type, exposing only its signature. But unlike std::function, | |
214 // FunctionView doesn't own its callable---it just points to it. Thus, it's a | |
215 // good choice mainly as a function argument when the callable argument will | |
216 // not be called again once the function has returned. | |
217 template <typename T> | |
218 class FunctionView; // Undefined. | |
219 | |
220 template <typename RetT, typename... ArgT> | |
221 class FunctionView<RetT(ArgT...)> final { | |
222 public: | |
223 // This constructor is implicit, so that callers won't have to convert | |
224 // lambdas to FunctionView<Blah(Blah, Blah)> explicitly. This is safe | |
225 // because FunctionView is only a reference to the real callable. | |
226 template <typename F> | |
227 FunctionView(F&& f) | |
228 : f_(&f), call_(Call<typename std::remove_reference<F>::type>) {} | |
229 | |
230 RetT operator()(ArgT... args) const { | |
231 return call_(f_, std::forward<ArgT>(args)...); | |
232 } | |
233 | |
234 private: | |
235 template <typename F> | |
236 static RetT Call(void* f, ArgT... args) { | |
237 return (*static_cast<F*>(f))(std::forward<ArgT>(args)...); | |
238 } | |
239 void* f_; | |
240 RetT (*call_)(void* f, ArgT... args); | |
241 }; | |
242 | |
243 // |modifier| is called exactly once with one argument: a pointer to the | 213 // |modifier| is called exactly once with one argument: a pointer to the |
244 // unique_ptr that holds the current encoder (which is null if there is no | 214 // unique_ptr that holds the current encoder (which is null if there is no |
245 // current encoder). For the duration of the call, |modifier| has exclusive | 215 // current encoder). For the duration of the call, |modifier| has exclusive |
246 // access to the unique_ptr; it may call the encoder, steal the encoder and | 216 // access to the unique_ptr; it may call the encoder, steal the encoder and |
247 // replace it with another encoder or with nullptr, etc. | 217 // replace it with another encoder or with nullptr, etc. |
248 virtual void ModifyEncoder( | 218 virtual void ModifyEncoder( |
249 FunctionView<void(std::unique_ptr<AudioEncoder>*)> modifier) = 0; | 219 rtc::FunctionView<void(std::unique_ptr<AudioEncoder>*)> modifier) = 0; |
250 | 220 |
251 // |modifier| is called exactly once with one argument: a const pointer to the | 221 // |modifier| is called exactly once with one argument: a const pointer to the |
252 // current encoder (which is null if there is no current encoder). | 222 // current encoder (which is null if there is no current encoder). |
253 virtual void QueryEncoder(FunctionView<void(AudioEncoder const*)> query) = 0; | 223 virtual void QueryEncoder( |
| 224 rtc::FunctionView<void(AudioEncoder const*)> query) = 0; |
254 | 225 |
255 // Utility method for simply replacing the existing encoder with a new one. | 226 // Utility method for simply replacing the existing encoder with a new one. |
256 void SetEncoder(std::unique_ptr<AudioEncoder> new_encoder) { | 227 void SetEncoder(std::unique_ptr<AudioEncoder> new_encoder) { |
257 ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) { | 228 ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) { |
258 *encoder = std::move(new_encoder); | 229 *encoder = std::move(new_encoder); |
259 }); | 230 }); |
260 } | 231 } |
261 | 232 |
262 /////////////////////////////////////////////////////////////////////////// | 233 /////////////////////////////////////////////////////////////////////////// |
263 // int32_t SendCodec() | 234 // int32_t SendCodec() |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 // -1 if failed to register the codec | 493 // -1 if failed to register the codec |
523 // 0 if the codec registered successfully. | 494 // 0 if the codec registered successfully. |
524 // | 495 // |
525 virtual int RegisterReceiveCodec(const CodecInst& receive_codec) = 0; | 496 virtual int RegisterReceiveCodec(const CodecInst& receive_codec) = 0; |
526 | 497 |
527 // Register a decoder; call repeatedly to register multiple decoders. |df| is | 498 // Register a decoder; call repeatedly to register multiple decoders. |df| is |
528 // a decoder factory that returns an iSAC decoder; it will be called once if | 499 // a decoder factory that returns an iSAC decoder; it will be called once if |
529 // the decoder being registered is iSAC. | 500 // the decoder being registered is iSAC. |
530 virtual int RegisterReceiveCodec( | 501 virtual int RegisterReceiveCodec( |
531 const CodecInst& receive_codec, | 502 const CodecInst& receive_codec, |
532 FunctionView<std::unique_ptr<AudioDecoder>()> isac_factory) = 0; | 503 rtc::FunctionView<std::unique_ptr<AudioDecoder>()> isac_factory) = 0; |
533 | 504 |
534 // Registers an external decoder. The name is only used to provide information | 505 // Registers an external decoder. The name is only used to provide information |
535 // back to the caller about the decoder. Hence, the name is arbitrary, and may | 506 // back to the caller about the decoder. Hence, the name is arbitrary, and may |
536 // be empty. | 507 // be empty. |
537 virtual int RegisterExternalReceiveCodec(int rtp_payload_type, | 508 virtual int RegisterExternalReceiveCodec(int rtp_payload_type, |
538 AudioDecoder* external_decoder, | 509 AudioDecoder* external_decoder, |
539 int sample_rate_hz, | 510 int sample_rate_hz, |
540 int num_channels, | 511 int num_channels, |
541 const std::string& name) = 0; | 512 const std::string& name) = 0; |
542 | 513 |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 virtual std::vector<uint16_t> GetNackList( | 794 virtual std::vector<uint16_t> GetNackList( |
824 int64_t round_trip_time_ms) const = 0; | 795 int64_t round_trip_time_ms) const = 0; |
825 | 796 |
826 virtual void GetDecodingCallStatistics( | 797 virtual void GetDecodingCallStatistics( |
827 AudioDecodingCallStats* call_stats) const = 0; | 798 AudioDecodingCallStats* call_stats) const = 0; |
828 }; | 799 }; |
829 | 800 |
830 } // namespace webrtc | 801 } // namespace webrtc |
831 | 802 |
832 #endif // WEBRTC_MODULES_AUDIO_CODING_INCLUDE_AUDIO_CODING_MODULE_H_ | 803 #endif // WEBRTC_MODULES_AUDIO_CODING_INCLUDE_AUDIO_CODING_MODULE_H_ |
OLD | NEW |