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 | |
| 37 | #include "common_types.h" |
| 38 | |
| 39 | namespace webrtc { |
| 40 | |
| 41 | class AudioDeviceModule; |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 42 | class AudioProcessing; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | |
| 44 | const int kVoEDefault = -1; |
| 45 | |
| 46 | // VoiceEngineObserver |
| 47 | class WEBRTC_DLLEXPORT VoiceEngineObserver |
| 48 | { |
| 49 | public: |
| 50 | // This method will be called after the occurrence of any runtime error |
| 51 | // code, or warning notification, when the observer interface has been |
| 52 | // installed using VoEBase::RegisterVoiceEngineObserver(). |
| 53 | virtual void CallbackOnError(const int channel, const int errCode) = 0; |
| 54 | |
| 55 | protected: |
| 56 | virtual ~VoiceEngineObserver() {} |
| 57 | }; |
| 58 | |
| 59 | // VoiceEngine |
| 60 | class WEBRTC_DLLEXPORT VoiceEngine |
| 61 | { |
| 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(); |
| 66 | |
| 67 | // Deletes a created VoiceEngine object and releases the utilized resources. |
tommi@webrtc.org | a990e12 | 2012-04-26 15:28:22 +0000 | [diff] [blame] | 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 | |
| 73 | // Specifies the amount and type of trace information which will be |
| 74 | // created by the VoiceEngine. |
| 75 | static int SetTraceFilter(const unsigned int filter); |
| 76 | |
| 77 | // Sets the name of the trace file and enables non-encrypted trace messages. |
| 78 | static int SetTraceFile(const char* fileNameUTF8, |
| 79 | const bool addFileCounter = false); |
| 80 | |
| 81 | // Installs the TraceCallback implementation to ensure that the user |
| 82 | // receives callbacks for generated trace messages. |
| 83 | static int SetTraceCallback(TraceCallback* callback); |
| 84 | |
| 85 | static int SetAndroidObjects(void* javaVM, void* env, void* context); |
| 86 | |
| 87 | protected: |
| 88 | VoiceEngine() {} |
tommi@webrtc.org | 0989fb7 | 2013-02-15 15:07:32 +0000 | [diff] [blame] | 89 | ~VoiceEngine() {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | // VoEBase |
| 93 | class WEBRTC_DLLEXPORT VoEBase |
| 94 | { |
| 95 | public: |
| 96 | // Factory for the VoEBase sub-API. Increases an internal reference |
| 97 | // counter if successful. Returns NULL if the API is not supported or if |
| 98 | // construction fails. |
| 99 | static VoEBase* GetInterface(VoiceEngine* voiceEngine); |
| 100 | |
| 101 | // Releases the VoEBase sub-API and decreases an internal reference |
| 102 | // counter. Returns the new reference count. This value should be zero |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 103 | // for all sub-APIs before the VoiceEngine object can be safely deleted. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 104 | virtual int Release() = 0; |
| 105 | |
| 106 | // Installs the observer class to enable runtime error control and |
| 107 | // warning notifications. |
| 108 | virtual int RegisterVoiceEngineObserver(VoiceEngineObserver& observer) = 0; |
| 109 | |
| 110 | // Removes and disables the observer class for runtime error control |
| 111 | // and warning notifications. |
| 112 | virtual int DeRegisterVoiceEngineObserver() = 0; |
| 113 | |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 114 | // Initializes all common parts of the VoiceEngine; e.g. all |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 115 | // encoders/decoders, the sound card and core receiving components. |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 116 | // This method also makes it possible to install some user-defined external |
| 117 | // modules: |
| 118 | // - The Audio Device Module (ADM) which implements all the audio layer |
| 119 | // functionality in a separate (reference counted) module. |
| 120 | // - The AudioProcessing module handles capture-side processing. VoiceEngine |
| 121 | // takes ownership of this object. |
| 122 | // If NULL is passed for any of these, VoiceEngine will create its own. |
| 123 | // TODO(ajm): Remove default NULLs. |
| 124 | virtual int Init(AudioDeviceModule* external_adm = NULL, |
| 125 | AudioProcessing* audioproc = NULL) = 0; |
| 126 | |
| 127 | // Returns NULL before Init() is called. |
| 128 | virtual AudioProcessing* audio_processing() = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 129 | |
| 130 | // Terminates all VoiceEngine functions and releses allocated resources. |
| 131 | virtual int Terminate() = 0; |
| 132 | |
| 133 | // Retrieves the maximum number of channels that can be created. |
| 134 | virtual int MaxNumOfChannels() = 0; |
| 135 | |
| 136 | // Creates a new channel and allocates the required resources for it. |
| 137 | virtual int CreateChannel() = 0; |
| 138 | |
| 139 | // Deletes an existing channel and releases the utilized resources. |
| 140 | virtual int DeleteChannel(int channel) = 0; |
| 141 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 142 | // Prepares and initiates the VoiceEngine for reception of |
| 143 | // incoming RTP/RTCP packets on the specified |channel|. |
| 144 | virtual int StartReceive(int channel) = 0; |
| 145 | |
| 146 | // Stops receiving incoming RTP/RTCP packets on the specified |channel|. |
| 147 | virtual int StopReceive(int channel) = 0; |
| 148 | |
| 149 | // Starts forwarding the packets to the mixer/soundcard for a |
| 150 | // specified |channel|. |
| 151 | virtual int StartPlayout(int channel) = 0; |
| 152 | |
| 153 | // Stops forwarding the packets to the mixer/soundcard for a |
| 154 | // specified |channel|. |
| 155 | virtual int StopPlayout(int channel) = 0; |
| 156 | |
| 157 | // Starts sending packets to an already specified IP address and |
| 158 | // port number for a specified |channel|. |
| 159 | virtual int StartSend(int channel) = 0; |
| 160 | |
| 161 | // Stops sending packets from a specified |channel|. |
| 162 | virtual int StopSend(int channel) = 0; |
| 163 | |
| 164 | // Gets the version information for VoiceEngine and its components. |
| 165 | virtual int GetVersion(char version[1024]) = 0; |
| 166 | |
| 167 | // Gets the last VoiceEngine error code. |
| 168 | virtual int LastError() = 0; |
| 169 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 170 | // Stops or resumes playout and transmission on a temporary basis. |
| 171 | virtual int SetOnHoldStatus(int channel, bool enable, |
| 172 | OnHoldModes mode = kHoldSendAndPlay) = 0; |
| 173 | |
| 174 | // Gets the current playout and transmission status. |
| 175 | virtual int GetOnHoldStatus(int channel, bool& enabled, |
| 176 | OnHoldModes& mode) = 0; |
| 177 | |
| 178 | // Sets the NetEQ playout mode for a specified |channel| number. |
| 179 | virtual int SetNetEQPlayoutMode(int channel, NetEqModes mode) = 0; |
| 180 | |
| 181 | // Gets the NetEQ playout mode for a specified |channel| number. |
| 182 | virtual int GetNetEQPlayoutMode(int channel, NetEqModes& mode) = 0; |
| 183 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 184 | protected: |
| 185 | VoEBase() {} |
| 186 | virtual ~VoEBase() {} |
| 187 | }; |
| 188 | |
| 189 | } // namespace webrtc |
| 190 | |
| 191 | #endif // WEBRTC_VOICE_ENGINE_VOE_BASE_H |