blob: b26f73a989213dc4aebcfd31e86e3411f8ac00ea [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
tommi@webrtc.orga990e122012-04-26 15:28:22 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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
40namespace webrtc {
41
42class AudioDeviceModule;
43
44const int kVoEDefault = -1;
45
46// VoiceEngineObserver
47class WEBRTC_DLLEXPORT VoiceEngineObserver
48{
49public:
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
55protected:
56 virtual ~VoiceEngineObserver() {}
57};
58
59// VoiceEngine
60class WEBRTC_DLLEXPORT VoiceEngine
61{
62public:
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.orga990e122012-04-26 15:28:22 +000068 // 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.com470e71d2011-07-07 08:21:25 +000072
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
87protected:
88 VoiceEngine() {}
tommi@webrtc.org0989fb72013-02-15 15:07:32 +000089 ~VoiceEngine() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000090};
91
92// VoEBase
93class WEBRTC_DLLEXPORT VoEBase
94{
95public:
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
103 // for all sub-API:s before the VoiceEngine object can be safely deleted.
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
niklase@google.com470e71d2011-07-07 08:21:25 +0000114 // Initiates all common parts of the VoiceEngine; e.g. all
115 // encoders/decoders, the sound card and core receiving components.
henrika@google.com73d65512011-09-07 15:11:18 +0000116 // This method also makes it possible to install a user-defined
117 // external Audio Device Module (ADM) which implements all the audio
118 // layer functionality in a separate (reference counted) module.
119 virtual int Init(AudioDeviceModule* external_adm = NULL) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000120
121 // Terminates all VoiceEngine functions and releses allocated resources.
122 virtual int Terminate() = 0;
123
124 // Retrieves the maximum number of channels that can be created.
125 virtual int MaxNumOfChannels() = 0;
126
127 // Creates a new channel and allocates the required resources for it.
128 virtual int CreateChannel() = 0;
129
130 // Deletes an existing channel and releases the utilized resources.
131 virtual int DeleteChannel(int channel) = 0;
132
133 // Sets the local receiver port and address for a specified
134 // |channel| number.
135 virtual int SetLocalReceiver(int channel, int port,
136 int RTCPport = kVoEDefault,
137 const char ipAddr[64] = NULL,
138 const char multiCastAddr[64] = NULL) = 0;
139
140 // Gets the local receiver port and address for a specified
141 // |channel| number.
142 virtual int GetLocalReceiver(int channel, int& port, int& RTCPport,
143 char ipAddr[64]) = 0;
144
145 // Sets the destination port and address for a specified |channel| number.
146 virtual int SetSendDestination(int channel, int port,
147 const char ipAddr[64],
148 int sourcePort = kVoEDefault,
149 int RTCPport = kVoEDefault) = 0;
150
151 // Gets the destination port and address for a specified |channel| number.
152 virtual int GetSendDestination(int channel, int& port, char ipAddr[64],
153 int& sourcePort, int& RTCPport) = 0;
154
155 // Prepares and initiates the VoiceEngine for reception of
156 // incoming RTP/RTCP packets on the specified |channel|.
157 virtual int StartReceive(int channel) = 0;
158
159 // Stops receiving incoming RTP/RTCP packets on the specified |channel|.
160 virtual int StopReceive(int channel) = 0;
161
162 // Starts forwarding the packets to the mixer/soundcard for a
163 // specified |channel|.
164 virtual int StartPlayout(int channel) = 0;
165
166 // Stops forwarding the packets to the mixer/soundcard for a
167 // specified |channel|.
168 virtual int StopPlayout(int channel) = 0;
169
170 // Starts sending packets to an already specified IP address and
171 // port number for a specified |channel|.
172 virtual int StartSend(int channel) = 0;
173
174 // Stops sending packets from a specified |channel|.
175 virtual int StopSend(int channel) = 0;
176
177 // Gets the version information for VoiceEngine and its components.
178 virtual int GetVersion(char version[1024]) = 0;
179
180 // Gets the last VoiceEngine error code.
181 virtual int LastError() = 0;
182
183
184 // Stops or resumes playout and transmission on a temporary basis.
185 virtual int SetOnHoldStatus(int channel, bool enable,
186 OnHoldModes mode = kHoldSendAndPlay) = 0;
187
188 // Gets the current playout and transmission status.
189 virtual int GetOnHoldStatus(int channel, bool& enabled,
190 OnHoldModes& mode) = 0;
191
192 // Sets the NetEQ playout mode for a specified |channel| number.
193 virtual int SetNetEQPlayoutMode(int channel, NetEqModes mode) = 0;
194
195 // Gets the NetEQ playout mode for a specified |channel| number.
196 virtual int GetNetEQPlayoutMode(int channel, NetEqModes& mode) = 0;
197
198 // Sets the NetEQ background noise mode for a specified |channel| number.
199 virtual int SetNetEQBGNMode(int channel, NetEqBgnModes mode) = 0;
200
201 // Gets the NetEQ background noise mode for a specified |channel| number.
202 virtual int GetNetEQBGNMode(int channel, NetEqBgnModes& mode) = 0;
203
204protected:
205 VoEBase() {}
206 virtual ~VoEBase() {}
207};
208
209} // namespace webrtc
210
211#endif // WEBRTC_VOICE_ENGINE_VOE_BASE_H