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; |
xians@webrtc.org | c1e2803 | 2014-02-02 15:30:20 +0000 | [diff] [blame] | 46 | class AudioTransport; |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 47 | namespace voe { |
| 48 | class TransmitMixer; |
| 49 | } // namespace voe |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 50 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | // VoiceEngine |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 52 | class WEBRTC_DLLEXPORT VoiceEngine { |
| 53 | public: |
| 54 | // Creates a VoiceEngine object, which can then be used to acquire |
| 55 | // sub-APIs. Returns NULL on failure. |
| 56 | static VoiceEngine* Create(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 57 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 58 | // Deletes a created VoiceEngine object and releases the utilized resources. |
| 59 | // Note that if there are outstanding references held via other interfaces, |
| 60 | // the voice engine instance will not actually be deleted until those |
| 61 | // references have been released. |
| 62 | static bool Delete(VoiceEngine*& voiceEngine); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 63 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 64 | protected: |
| 65 | VoiceEngine() {} |
| 66 | ~VoiceEngine() {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | // VoEBase |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 70 | class WEBRTC_DLLEXPORT VoEBase { |
| 71 | public: |
solenberg | 88499ec | 2016-09-07 07:34:41 -0700 | [diff] [blame] | 72 | struct ChannelConfig { |
| 73 | AudioCodingModule::Config acm_config; |
| 74 | bool enable_voice_pacing = false; |
| 75 | }; |
| 76 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 77 | // Factory for the VoEBase sub-API. Increases an internal reference |
| 78 | // counter if successful. Returns NULL if the API is not supported or if |
| 79 | // construction fails. |
| 80 | static VoEBase* GetInterface(VoiceEngine* voiceEngine); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 81 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 82 | // Releases the VoEBase sub-API and decreases an internal reference |
| 83 | // counter. Returns the new reference count. This value should be zero |
| 84 | // for all sub-APIs before the VoiceEngine object can be safely deleted. |
| 85 | virtual int Release() = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 86 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 87 | // Initializes all common parts of the VoiceEngine; e.g. all |
| 88 | // encoders/decoders, the sound card and core receiving components. |
| 89 | // This method also makes it possible to install some user-defined external |
| 90 | // modules: |
| 91 | // - The Audio Device Module (ADM) which implements all the audio layer |
| 92 | // functionality in a separate (reference counted) module. |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 93 | // - The AudioProcessing module handles capture-side processing. |
ossu | 5f7cfa5 | 2016-05-30 08:11:28 -0700 | [diff] [blame] | 94 | // - An AudioDecoderFactory - used to create audio decoders. |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 95 | // If NULL is passed for either of ADM or AudioDecoderFactory, VoiceEngine |
| 96 | // will create its own. Returns -1 in case of an error, 0 otherwise. |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 97 | // TODO(ajm): Remove default NULLs. |
| 98 | virtual int Init(AudioDeviceModule* external_adm = NULL, |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 99 | AudioProcessing* external_apm = nullptr, |
ossu | 5f7cfa5 | 2016-05-30 08:11:28 -0700 | [diff] [blame] | 100 | const rtc::scoped_refptr<AudioDecoderFactory>& |
| 101 | decoder_factory = nullptr) = 0; |
solenberg | ff97631 | 2016-03-30 23:28:51 -0700 | [diff] [blame] | 102 | // This method is WIP - DO NOT USE! |
| 103 | // Returns NULL before Init() is called. |
| 104 | virtual AudioDeviceModule* audio_device_module() = 0; |
| 105 | |
solenberg | 76377c5 | 2017-02-21 00:54:31 -0800 | [diff] [blame] | 106 | // This method is WIP - DO NOT USE! |
| 107 | // Returns NULL before Init() is called. |
| 108 | virtual voe::TransmitMixer* transmit_mixer() = 0; |
| 109 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 110 | // Terminates all VoiceEngine functions and releases allocated resources. |
| 111 | // Returns 0. |
| 112 | virtual int Terminate() = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 113 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 114 | // Creates a new channel and allocates the required resources for it. |
solenberg | 88499ec | 2016-09-07 07:34:41 -0700 | [diff] [blame] | 115 | // The second version accepts a |config| struct which includes an Audio Coding |
| 116 | // Module config and an option to enable voice pacing. Note that the |
| 117 | // decoder_factory member of the ACM config will be ignored (the decoder |
| 118 | // factory set through Init() will always be used). |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 119 | // Returns channel ID or -1 in case of an error. |
| 120 | virtual int CreateChannel() = 0; |
solenberg | 88499ec | 2016-09-07 07:34:41 -0700 | [diff] [blame] | 121 | virtual int CreateChannel(const ChannelConfig& config) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 122 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 123 | // Deletes an existing channel and releases the utilized resources. |
| 124 | // Returns -1 in case of an error, 0 otherwise. |
| 125 | virtual int DeleteChannel(int channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 126 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 127 | // Starts forwarding the packets to the mixer/soundcard for a |
| 128 | // specified |channel|. |
| 129 | virtual int StartPlayout(int channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 130 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 131 | // Stops forwarding the packets to the mixer/soundcard for a |
| 132 | // specified |channel|. |
| 133 | virtual int StopPlayout(int channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 134 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 135 | // Starts sending packets to an already specified IP address and |
| 136 | // port number for a specified |channel|. |
| 137 | virtual int StartSend(int channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 138 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 139 | // Stops sending packets from a specified |channel|. |
| 140 | virtual int StopSend(int channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 141 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 142 | // TODO(xians): Make the interface pure virtual after libjingle |
| 143 | // implements the interface in its FakeWebRtcVoiceEngine. |
| 144 | virtual AudioTransport* audio_transport() { return NULL; } |
xians@webrtc.org | c1e2803 | 2014-02-02 15:30:20 +0000 | [diff] [blame] | 145 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 146 | protected: |
| 147 | VoEBase() {} |
| 148 | virtual ~VoEBase() {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 149 | }; |
| 150 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 151 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 152 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 153 | #endif // VOICE_ENGINE_VOE_BASE_H_ |