niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
tommi@webrtc.org | a990e12 | 2012-04-26 15:28:22 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | // This sub-API supports the following functionalities: |
| 12 | // |
| 13 | // - Enables full duplex VoIP sessions via RTP using G.711 (mu-Law or A-Law). |
| 14 | // - Initialization and termination. |
| 15 | // - Trace information on text files or via callbacks. |
| 16 | // - Multi-channel support (mixing, sending to multiple destinations etc.). |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 17 | // |
| 18 | // To support other codecs than G.711, the VoECodec sub-API must be utilized. |
| 19 | // |
| 20 | // Usage example, omitting error checking: |
| 21 | // |
| 22 | // using namespace webrtc; |
| 23 | // VoiceEngine* voe = VoiceEngine::Create(); |
| 24 | // VoEBase* base = VoEBase::GetInterface(voe); |
| 25 | // base->Init(); |
| 26 | // int ch = base->CreateChannel(); |
| 27 | // base->StartPlayout(ch); |
| 28 | // ... |
| 29 | // base->DeleteChannel(ch); |
| 30 | // base->Terminate(); |
| 31 | // base->Release(); |
| 32 | // VoiceEngine::Delete(voe); |
| 33 | // |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 34 | #ifndef VOICE_ENGINE_VOE_BASE_H_ |
| 35 | #define VOICE_ENGINE_VOE_BASE_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 36 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 37 | #include "api/audio_codecs/audio_decoder_factory.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 38 | #include "common_types.h" // NOLINT(build/include) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 39 | #include "modules/audio_coding/include/audio_coding_module.h" |
| 40 | #include "rtc_base/scoped_ref_ptr.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 41 | |
| 42 | namespace webrtc { |
| 43 | |
| 44 | class AudioDeviceModule; |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 45 | class AudioProcessing; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 46 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 47 | // VoiceEngine |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 48 | class WEBRTC_DLLEXPORT VoiceEngine { |
| 49 | public: |
| 50 | // Creates a VoiceEngine object, which can then be used to acquire |
| 51 | // sub-APIs. Returns NULL on failure. |
| 52 | static VoiceEngine* Create(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 53 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 54 | // Deletes a created VoiceEngine object and releases the utilized resources. |
| 55 | // Note that if there are outstanding references held via other interfaces, |
| 56 | // the voice engine instance will not actually be deleted until those |
| 57 | // references have been released. |
| 58 | static bool Delete(VoiceEngine*& voiceEngine); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 60 | protected: |
| 61 | VoiceEngine() {} |
| 62 | ~VoiceEngine() {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | // VoEBase |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 66 | class WEBRTC_DLLEXPORT VoEBase { |
| 67 | public: |
solenberg | 88499ec | 2016-09-07 07:34:41 -0700 | [diff] [blame] | 68 | struct ChannelConfig { |
| 69 | AudioCodingModule::Config acm_config; |
| 70 | bool enable_voice_pacing = false; |
| 71 | }; |
| 72 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 73 | // Factory for the VoEBase sub-API. Increases an internal reference |
| 74 | // counter if successful. Returns NULL if the API is not supported or if |
| 75 | // construction fails. |
| 76 | static VoEBase* GetInterface(VoiceEngine* voiceEngine); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 77 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 78 | // Releases the VoEBase sub-API and decreases an internal reference |
| 79 | // counter. Returns the new reference count. This value should be zero |
| 80 | // for all sub-APIs before the VoiceEngine object can be safely deleted. |
| 81 | virtual int Release() = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 82 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 83 | // Initializes all common parts of the VoiceEngine; e.g. all |
| 84 | // encoders/decoders, the sound card and core receiving components. |
| 85 | // This method also makes it possible to install some user-defined external |
| 86 | // modules: |
| 87 | // - The Audio Device Module (ADM) which implements all the audio layer |
| 88 | // functionality in a separate (reference counted) module. |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 89 | // - The AudioProcessing module is unused - only kept for API compatibility. |
ossu | 5f7cfa5 | 2016-05-30 08:11:28 -0700 | [diff] [blame] | 90 | // - An AudioDecoderFactory - used to create audio decoders. |
Karl Wiberg | f3850f6 | 2017-11-02 13:04:41 +0100 | [diff] [blame] | 91 | virtual int Init( |
Fredrik Solenberg | d319534 | 2017-11-21 20:33:05 +0100 | [diff] [blame] | 92 | AudioDeviceModule* audio_device, |
| 93 | AudioProcessing* audio_processing, |
Karl Wiberg | f3850f6 | 2017-11-02 13:04:41 +0100 | [diff] [blame] | 94 | const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory) = 0; |
solenberg | ff97631 | 2016-03-30 23:28:51 -0700 | [diff] [blame] | 95 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 96 | // Terminates all VoiceEngine functions and releases allocated resources. |
Fredrik Solenberg | 55900fd | 2017-11-23 20:22:55 +0100 | [diff] [blame] | 97 | virtual void Terminate() = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 98 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 99 | // Creates a new channel and allocates the required resources for it. |
solenberg | 88499ec | 2016-09-07 07:34:41 -0700 | [diff] [blame] | 100 | // The second version accepts a |config| struct which includes an Audio Coding |
| 101 | // Module config and an option to enable voice pacing. Note that the |
| 102 | // decoder_factory member of the ACM config will be ignored (the decoder |
| 103 | // factory set through Init() will always be used). |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 104 | // Returns channel ID or -1 in case of an error. |
| 105 | virtual int CreateChannel() = 0; |
solenberg | 88499ec | 2016-09-07 07:34:41 -0700 | [diff] [blame] | 106 | virtual int CreateChannel(const ChannelConfig& config) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 107 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 108 | // Deletes an existing channel and releases the utilized resources. |
| 109 | // Returns -1 in case of an error, 0 otherwise. |
| 110 | virtual int DeleteChannel(int channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 111 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 112 | protected: |
| 113 | VoEBase() {} |
| 114 | virtual ~VoEBase() {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 115 | }; |
| 116 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 117 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 118 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 119 | #endif // VOICE_ENGINE_VOE_BASE_H_ |