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 | // |
| 34 | #ifndef WEBRTC_VOICE_ENGINE_VOE_BASE_H |
| 35 | #define WEBRTC_VOICE_ENGINE_VOE_BASE_H |
| 36 | |
ossu | 5f7cfa5 | 2016-05-30 08:11:28 -0700 | [diff] [blame] | 37 | #include "webrtc/base/scoped_ref_ptr.h" |
| 38 | #include "webrtc/modules/audio_coding/codecs/audio_decoder_factory.h" |
solenberg | 88499ec | 2016-09-07 07:34:41 -0700 | [diff] [blame^] | 39 | #include "webrtc/modules/audio_coding/include/audio_coding_module.h" |
pbos@webrtc.org | 956aa7e | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 40 | #include "webrtc/common_types.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; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 47 | |
| 48 | // VoiceEngineObserver |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 49 | class WEBRTC_DLLEXPORT VoiceEngineObserver { |
| 50 | public: |
| 51 | // This method will be called after the occurrence of any runtime error |
| 52 | // code, or warning notification, when the observer interface has been |
| 53 | // installed using VoEBase::RegisterVoiceEngineObserver(). |
| 54 | virtual void CallbackOnError(int channel, int errCode) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 55 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 56 | protected: |
| 57 | virtual ~VoiceEngineObserver() {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | // VoiceEngine |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 61 | class WEBRTC_DLLEXPORT VoiceEngine { |
| 62 | public: |
| 63 | // Creates a VoiceEngine object, which can then be used to acquire |
| 64 | // sub-APIs. Returns NULL on failure. |
| 65 | static VoiceEngine* Create(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 66 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 67 | // Deletes a created VoiceEngine object and releases the utilized resources. |
| 68 | // Note that if there are outstanding references held via other interfaces, |
| 69 | // the voice engine instance will not actually be deleted until those |
| 70 | // references have been released. |
| 71 | static bool Delete(VoiceEngine*& voiceEngine); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 72 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 73 | // Specifies the amount and type of trace information which will be |
| 74 | // created by the VoiceEngine. |
| 75 | static int SetTraceFilter(unsigned int filter); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 76 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 77 | // Sets the name of the trace file and enables non-encrypted trace messages. |
| 78 | static int SetTraceFile(const char* fileNameUTF8, |
| 79 | bool addFileCounter = false); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 81 | // Installs the TraceCallback implementation to ensure that the user |
| 82 | // receives callbacks for generated trace messages. |
| 83 | static int SetTraceCallback(TraceCallback* callback); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 84 | |
henrika@webrtc.org | 8883a0f | 2014-04-09 13:04:12 +0000 | [diff] [blame] | 85 | #if !defined(WEBRTC_CHROMIUM_BUILD) |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 86 | static int SetAndroidObjects(void* javaVM, void* context); |
henrika@webrtc.org | 8883a0f | 2014-04-09 13:04:12 +0000 | [diff] [blame] | 87 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 88 | |
solenberg | 2515af2 | 2015-12-02 06:19:36 -0800 | [diff] [blame] | 89 | static std::string GetVersionString(); |
| 90 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 91 | protected: |
| 92 | VoiceEngine() {} |
| 93 | ~VoiceEngine() {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | // VoEBase |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 97 | class WEBRTC_DLLEXPORT VoEBase { |
| 98 | public: |
solenberg | 88499ec | 2016-09-07 07:34:41 -0700 | [diff] [blame^] | 99 | struct ChannelConfig { |
| 100 | AudioCodingModule::Config acm_config; |
| 101 | bool enable_voice_pacing = false; |
| 102 | }; |
| 103 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 104 | // Factory for the VoEBase sub-API. Increases an internal reference |
| 105 | // counter if successful. Returns NULL if the API is not supported or if |
| 106 | // construction fails. |
| 107 | static VoEBase* GetInterface(VoiceEngine* voiceEngine); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 108 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 109 | // Releases the VoEBase sub-API and decreases an internal reference |
| 110 | // counter. Returns the new reference count. This value should be zero |
| 111 | // for all sub-APIs before the VoiceEngine object can be safely deleted. |
| 112 | virtual int Release() = 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 | // Installs the observer class to enable runtime error control and |
| 115 | // warning notifications. Returns -1 in case of an error, 0 otherwise. |
| 116 | virtual int RegisterVoiceEngineObserver(VoiceEngineObserver& observer) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 117 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 118 | // Removes and disables the observer class for runtime error control |
| 119 | // and warning notifications. Returns 0. |
| 120 | virtual int DeRegisterVoiceEngineObserver() = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 121 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 122 | // Initializes all common parts of the VoiceEngine; e.g. all |
| 123 | // encoders/decoders, the sound card and core receiving components. |
| 124 | // This method also makes it possible to install some user-defined external |
| 125 | // modules: |
| 126 | // - The Audio Device Module (ADM) which implements all the audio layer |
| 127 | // functionality in a separate (reference counted) module. |
| 128 | // - The AudioProcessing module handles capture-side processing. VoiceEngine |
| 129 | // takes ownership of this object. |
ossu | 5f7cfa5 | 2016-05-30 08:11:28 -0700 | [diff] [blame] | 130 | // - An AudioDecoderFactory - used to create audio decoders. |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 131 | // If NULL is passed for any of these, VoiceEngine will create its own. |
| 132 | // Returns -1 in case of an error, 0 otherwise. |
| 133 | // TODO(ajm): Remove default NULLs. |
| 134 | virtual int Init(AudioDeviceModule* external_adm = NULL, |
ossu | 5f7cfa5 | 2016-05-30 08:11:28 -0700 | [diff] [blame] | 135 | AudioProcessing* audioproc = NULL, |
| 136 | const rtc::scoped_refptr<AudioDecoderFactory>& |
| 137 | decoder_factory = nullptr) = 0; |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 138 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 139 | // Returns NULL before Init() is called. |
| 140 | virtual AudioProcessing* audio_processing() = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 141 | |
solenberg | ff97631 | 2016-03-30 23:28:51 -0700 | [diff] [blame] | 142 | // This method is WIP - DO NOT USE! |
| 143 | // Returns NULL before Init() is called. |
| 144 | virtual AudioDeviceModule* audio_device_module() = 0; |
| 145 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 146 | // Terminates all VoiceEngine functions and releases allocated resources. |
| 147 | // Returns 0. |
| 148 | virtual int Terminate() = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 149 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 150 | // Creates a new channel and allocates the required resources for it. |
solenberg | 88499ec | 2016-09-07 07:34:41 -0700 | [diff] [blame^] | 151 | // The second version accepts a |config| struct which includes an Audio Coding |
| 152 | // Module config and an option to enable voice pacing. Note that the |
| 153 | // decoder_factory member of the ACM config will be ignored (the decoder |
| 154 | // factory set through Init() will always be used). |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 155 | // Returns channel ID or -1 in case of an error. |
| 156 | virtual int CreateChannel() = 0; |
solenberg | 88499ec | 2016-09-07 07:34:41 -0700 | [diff] [blame^] | 157 | virtual int CreateChannel(const ChannelConfig& config) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 158 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 159 | // Deletes an existing channel and releases the utilized resources. |
| 160 | // Returns -1 in case of an error, 0 otherwise. |
| 161 | virtual int DeleteChannel(int channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 162 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 163 | // Prepares and initiates the VoiceEngine for reception of |
| 164 | // incoming RTP/RTCP packets on the specified |channel|. |
| 165 | virtual int StartReceive(int channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 166 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 167 | // Stops receiving incoming RTP/RTCP packets on the specified |channel|. |
| 168 | virtual int StopReceive(int channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 169 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 170 | // Starts forwarding the packets to the mixer/soundcard for a |
| 171 | // specified |channel|. |
| 172 | virtual int StartPlayout(int channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 173 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 174 | // Stops forwarding the packets to the mixer/soundcard for a |
| 175 | // specified |channel|. |
| 176 | virtual int StopPlayout(int channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 177 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 178 | // Starts sending packets to an already specified IP address and |
| 179 | // port number for a specified |channel|. |
| 180 | virtual int StartSend(int channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 181 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 182 | // Stops sending packets from a specified |channel|. |
| 183 | virtual int StopSend(int channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 184 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 185 | // Gets the version information for VoiceEngine and its components. |
| 186 | virtual int GetVersion(char version[1024]) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 187 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 188 | // Gets the last VoiceEngine error code. |
| 189 | virtual int LastError() = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 190 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 191 | // TODO(xians): Make the interface pure virtual after libjingle |
| 192 | // implements the interface in its FakeWebRtcVoiceEngine. |
| 193 | virtual AudioTransport* audio_transport() { return NULL; } |
xians@webrtc.org | c1e2803 | 2014-02-02 15:30:20 +0000 | [diff] [blame] | 194 | |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 195 | // Associate a send channel to a receive channel. |
| 196 | // Used for obtaining RTT for a receive-only channel. |
| 197 | // One should be careful not to crate a circular association, e.g., |
| 198 | // 1 <- 2 <- 1. |
Jelena Marusic | f09e09c | 2015-05-26 10:24:55 +0200 | [diff] [blame] | 199 | virtual int AssociateSendChannel(int channel, int accociate_send_channel) = 0; |
henrika@webrtc.org | 6680348 | 2014-04-17 10:45:01 +0000 | [diff] [blame] | 200 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 201 | protected: |
| 202 | VoEBase() {} |
| 203 | virtual ~VoEBase() {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 204 | }; |
| 205 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 206 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 207 | |
| 208 | #endif // WEBRTC_VOICE_ENGINE_VOE_BASE_H |