niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
| 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.). |
| 17 | // - Call setup (port and address) for receiving and sending sides. |
| 18 | // |
| 19 | // To support other codecs than G.711, the VoECodec sub-API must be utilized. |
| 20 | // |
| 21 | // Usage example, omitting error checking: |
| 22 | // |
| 23 | // using namespace webrtc; |
| 24 | // VoiceEngine* voe = VoiceEngine::Create(); |
| 25 | // VoEBase* base = VoEBase::GetInterface(voe); |
| 26 | // base->Init(); |
| 27 | // int ch = base->CreateChannel(); |
| 28 | // base->StartPlayout(ch); |
| 29 | // ... |
| 30 | // base->DeleteChannel(ch); |
| 31 | // base->Terminate(); |
| 32 | // base->Release(); |
| 33 | // VoiceEngine::Delete(voe); |
| 34 | // |
| 35 | #ifndef WEBRTC_VOICE_ENGINE_VOE_BASE_H |
| 36 | #define WEBRTC_VOICE_ENGINE_VOE_BASE_H |
| 37 | |
| 38 | #include "common_types.h" |
| 39 | |
| 40 | namespace webrtc { |
| 41 | |
| 42 | class AudioDeviceModule; |
| 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. |
| 68 | // If |ignoreRefCounters| is set to false, all reference counters must be |
| 69 | // zero to enable a valid release of the allocated resources. When set to |
| 70 | // true, a release of all resources allocated by the VoE is performed |
| 71 | // without checking the reference counter state. |
| 72 | static bool Delete(VoiceEngine*& voiceEngine, |
| 73 | bool ignoreRefCounters = false); |
| 74 | |
| 75 | // Specifies the amount and type of trace information which will be |
| 76 | // created by the VoiceEngine. |
| 77 | static int SetTraceFilter(const unsigned int filter); |
| 78 | |
| 79 | // Sets the name of the trace file and enables non-encrypted trace messages. |
| 80 | static int SetTraceFile(const char* fileNameUTF8, |
| 81 | const bool addFileCounter = false); |
| 82 | |
| 83 | // Installs the TraceCallback implementation to ensure that the user |
| 84 | // receives callbacks for generated trace messages. |
| 85 | static int SetTraceCallback(TraceCallback* callback); |
| 86 | |
| 87 | static int SetAndroidObjects(void* javaVM, void* env, void* context); |
| 88 | |
| 89 | protected: |
| 90 | VoiceEngine() {} |
| 91 | virtual ~VoiceEngine() {} |
| 92 | }; |
| 93 | |
| 94 | // VoEBase |
| 95 | class WEBRTC_DLLEXPORT VoEBase |
| 96 | { |
| 97 | public: |
| 98 | // Factory for the VoEBase sub-API. Increases an internal reference |
| 99 | // counter if successful. Returns NULL if the API is not supported or if |
| 100 | // construction fails. |
| 101 | static VoEBase* GetInterface(VoiceEngine* voiceEngine); |
| 102 | |
| 103 | // Releases the VoEBase sub-API and decreases an internal reference |
| 104 | // counter. Returns the new reference count. This value should be zero |
| 105 | // for all sub-API:s before the VoiceEngine object can be safely deleted. |
| 106 | virtual int Release() = 0; |
| 107 | |
| 108 | // Installs the observer class to enable runtime error control and |
| 109 | // warning notifications. |
| 110 | virtual int RegisterVoiceEngineObserver(VoiceEngineObserver& observer) = 0; |
| 111 | |
| 112 | // Removes and disables the observer class for runtime error control |
| 113 | // and warning notifications. |
| 114 | virtual int DeRegisterVoiceEngineObserver() = 0; |
| 115 | |
| 116 | // Installs and enables a user-defined external audio device module |
| 117 | // which implements all the audio layer functionality. |
| 118 | virtual int RegisterAudioDeviceModule(AudioDeviceModule& adm) = 0; |
| 119 | |
| 120 | // Removes and disables the external audio device module. |
| 121 | virtual int DeRegisterAudioDeviceModule() = 0; |
| 122 | |
| 123 | // Initiates all common parts of the VoiceEngine; e.g. all |
| 124 | // encoders/decoders, the sound card and core receiving components. |
| 125 | virtual int Init() = 0; |
| 126 | |
| 127 | // Terminates all VoiceEngine functions and releses allocated resources. |
| 128 | virtual int Terminate() = 0; |
| 129 | |
| 130 | // Retrieves the maximum number of channels that can be created. |
| 131 | virtual int MaxNumOfChannels() = 0; |
| 132 | |
| 133 | // Creates a new channel and allocates the required resources for it. |
| 134 | virtual int CreateChannel() = 0; |
| 135 | |
| 136 | // Deletes an existing channel and releases the utilized resources. |
| 137 | virtual int DeleteChannel(int channel) = 0; |
| 138 | |
| 139 | // Sets the local receiver port and address for a specified |
| 140 | // |channel| number. |
| 141 | virtual int SetLocalReceiver(int channel, int port, |
| 142 | int RTCPport = kVoEDefault, |
| 143 | const char ipAddr[64] = NULL, |
| 144 | const char multiCastAddr[64] = NULL) = 0; |
| 145 | |
| 146 | // Gets the local receiver port and address for a specified |
| 147 | // |channel| number. |
| 148 | virtual int GetLocalReceiver(int channel, int& port, int& RTCPport, |
| 149 | char ipAddr[64]) = 0; |
| 150 | |
| 151 | // Sets the destination port and address for a specified |channel| number. |
| 152 | virtual int SetSendDestination(int channel, int port, |
| 153 | const char ipAddr[64], |
| 154 | int sourcePort = kVoEDefault, |
| 155 | int RTCPport = kVoEDefault) = 0; |
| 156 | |
| 157 | // Gets the destination port and address for a specified |channel| number. |
| 158 | virtual int GetSendDestination(int channel, int& port, char ipAddr[64], |
| 159 | int& sourcePort, int& RTCPport) = 0; |
| 160 | |
| 161 | // Prepares and initiates the VoiceEngine for reception of |
| 162 | // incoming RTP/RTCP packets on the specified |channel|. |
| 163 | virtual int StartReceive(int channel) = 0; |
| 164 | |
| 165 | // Stops receiving incoming RTP/RTCP packets on the specified |channel|. |
| 166 | virtual int StopReceive(int channel) = 0; |
| 167 | |
| 168 | // Starts forwarding the packets to the mixer/soundcard for a |
| 169 | // specified |channel|. |
| 170 | virtual int StartPlayout(int channel) = 0; |
| 171 | |
| 172 | // Stops forwarding the packets to the mixer/soundcard for a |
| 173 | // specified |channel|. |
| 174 | virtual int StopPlayout(int channel) = 0; |
| 175 | |
| 176 | // Starts sending packets to an already specified IP address and |
| 177 | // port number for a specified |channel|. |
| 178 | virtual int StartSend(int channel) = 0; |
| 179 | |
| 180 | // Stops sending packets from a specified |channel|. |
| 181 | virtual int StopSend(int channel) = 0; |
| 182 | |
| 183 | // Gets the version information for VoiceEngine and its components. |
| 184 | virtual int GetVersion(char version[1024]) = 0; |
| 185 | |
| 186 | // Gets the last VoiceEngine error code. |
| 187 | virtual int LastError() = 0; |
| 188 | |
| 189 | |
| 190 | // Stops or resumes playout and transmission on a temporary basis. |
| 191 | virtual int SetOnHoldStatus(int channel, bool enable, |
| 192 | OnHoldModes mode = kHoldSendAndPlay) = 0; |
| 193 | |
| 194 | // Gets the current playout and transmission status. |
| 195 | virtual int GetOnHoldStatus(int channel, bool& enabled, |
| 196 | OnHoldModes& mode) = 0; |
| 197 | |
| 198 | // Sets the NetEQ playout mode for a specified |channel| number. |
| 199 | virtual int SetNetEQPlayoutMode(int channel, NetEqModes mode) = 0; |
| 200 | |
| 201 | // Gets the NetEQ playout mode for a specified |channel| number. |
| 202 | virtual int GetNetEQPlayoutMode(int channel, NetEqModes& mode) = 0; |
| 203 | |
| 204 | // Sets the NetEQ background noise mode for a specified |channel| number. |
| 205 | virtual int SetNetEQBGNMode(int channel, NetEqBgnModes mode) = 0; |
| 206 | |
| 207 | // Gets the NetEQ background noise mode for a specified |channel| number. |
| 208 | virtual int GetNetEQBGNMode(int channel, NetEqBgnModes& mode) = 0; |
| 209 | |
| 210 | protected: |
| 211 | VoEBase() {} |
| 212 | virtual ~VoEBase() {} |
| 213 | }; |
| 214 | |
| 215 | } // namespace webrtc |
| 216 | |
| 217 | #endif // WEBRTC_VOICE_ENGINE_VOE_BASE_H |