blob: cb6fb3fbb3c36f00aba638e4192499322e3b6ad7 [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;
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000043class AudioProcessing;
niklase@google.com470e71d2011-07-07 08:21:25 +000044
45const int kVoEDefault = -1;
46
47// VoiceEngineObserver
48class WEBRTC_DLLEXPORT VoiceEngineObserver
49{
50public:
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(const int channel, const int errCode) = 0;
55
56protected:
57 virtual ~VoiceEngineObserver() {}
58};
59
60// VoiceEngine
61class WEBRTC_DLLEXPORT VoiceEngine
62{
63public:
64 // Creates a VoiceEngine object, which can then be used to acquire
65 // sub-APIs. Returns NULL on failure.
66 static VoiceEngine* Create();
67
68 // Deletes a created VoiceEngine object and releases the utilized resources.
tommi@webrtc.orga990e122012-04-26 15:28:22 +000069 // Note that if there are outstanding references held via other interfaces,
70 // the voice engine instance will not actually be deleted until those
71 // references have been released.
72 static bool Delete(VoiceEngine*& voiceEngine);
niklase@google.com470e71d2011-07-07 08:21:25 +000073
74 // Specifies the amount and type of trace information which will be
75 // created by the VoiceEngine.
76 static int SetTraceFilter(const unsigned int filter);
77
78 // Sets the name of the trace file and enables non-encrypted trace messages.
79 static int SetTraceFile(const char* fileNameUTF8,
80 const bool addFileCounter = false);
81
82 // Installs the TraceCallback implementation to ensure that the user
83 // receives callbacks for generated trace messages.
84 static int SetTraceCallback(TraceCallback* callback);
85
86 static int SetAndroidObjects(void* javaVM, void* env, void* context);
87
88protected:
89 VoiceEngine() {}
tommi@webrtc.org0989fb72013-02-15 15:07:32 +000090 ~VoiceEngine() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000091};
92
93// VoEBase
94class WEBRTC_DLLEXPORT VoEBase
95{
96public:
97 // Factory for the VoEBase sub-API. Increases an internal reference
98 // counter if successful. Returns NULL if the API is not supported or if
99 // construction fails.
100 static VoEBase* GetInterface(VoiceEngine* voiceEngine);
101
102 // Releases the VoEBase sub-API and decreases an internal reference
103 // counter. Returns the new reference count. This value should be zero
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +0000104 // for all sub-APIs before the VoiceEngine object can be safely deleted.
niklase@google.com470e71d2011-07-07 08:21:25 +0000105 virtual int Release() = 0;
106
107 // Installs the observer class to enable runtime error control and
108 // warning notifications.
109 virtual int RegisterVoiceEngineObserver(VoiceEngineObserver& observer) = 0;
110
111 // Removes and disables the observer class for runtime error control
112 // and warning notifications.
113 virtual int DeRegisterVoiceEngineObserver() = 0;
114
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +0000115 // Initializes all common parts of the VoiceEngine; e.g. all
niklase@google.com470e71d2011-07-07 08:21:25 +0000116 // encoders/decoders, the sound card and core receiving components.
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +0000117 // This method also makes it possible to install some user-defined external
118 // modules:
119 // - The Audio Device Module (ADM) which implements all the audio layer
120 // functionality in a separate (reference counted) module.
121 // - The AudioProcessing module handles capture-side processing. VoiceEngine
122 // takes ownership of this object.
123 // If NULL is passed for any of these, VoiceEngine will create its own.
124 // TODO(ajm): Remove default NULLs.
125 virtual int Init(AudioDeviceModule* external_adm = NULL,
126 AudioProcessing* audioproc = NULL) = 0;
127
128 // Returns NULL before Init() is called.
129 virtual AudioProcessing* audio_processing() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000130
131 // Terminates all VoiceEngine functions and releses allocated resources.
132 virtual int Terminate() = 0;
133
134 // Retrieves the maximum number of channels that can be created.
135 virtual int MaxNumOfChannels() = 0;
136
137 // Creates a new channel and allocates the required resources for it.
138 virtual int CreateChannel() = 0;
139
140 // Deletes an existing channel and releases the utilized resources.
141 virtual int DeleteChannel(int channel) = 0;
142
143 // Sets the local receiver port and address for a specified
144 // |channel| number.
145 virtual int SetLocalReceiver(int channel, int port,
146 int RTCPport = kVoEDefault,
147 const char ipAddr[64] = NULL,
148 const char multiCastAddr[64] = NULL) = 0;
149
150 // Gets the local receiver port and address for a specified
151 // |channel| number.
152 virtual int GetLocalReceiver(int channel, int& port, int& RTCPport,
153 char ipAddr[64]) = 0;
154
155 // Sets the destination port and address for a specified |channel| number.
156 virtual int SetSendDestination(int channel, int port,
157 const char ipAddr[64],
158 int sourcePort = kVoEDefault,
159 int RTCPport = kVoEDefault) = 0;
160
161 // Gets the destination port and address for a specified |channel| number.
162 virtual int GetSendDestination(int channel, int& port, char ipAddr[64],
163 int& sourcePort, int& RTCPport) = 0;
164
165 // Prepares and initiates the VoiceEngine for reception of
166 // incoming RTP/RTCP packets on the specified |channel|.
167 virtual int StartReceive(int channel) = 0;
168
169 // Stops receiving incoming RTP/RTCP packets on the specified |channel|.
170 virtual int StopReceive(int channel) = 0;
171
172 // Starts forwarding the packets to the mixer/soundcard for a
173 // specified |channel|.
174 virtual int StartPlayout(int channel) = 0;
175
176 // Stops forwarding the packets to the mixer/soundcard for a
177 // specified |channel|.
178 virtual int StopPlayout(int channel) = 0;
179
180 // Starts sending packets to an already specified IP address and
181 // port number for a specified |channel|.
182 virtual int StartSend(int channel) = 0;
183
184 // Stops sending packets from a specified |channel|.
185 virtual int StopSend(int channel) = 0;
186
187 // Gets the version information for VoiceEngine and its components.
188 virtual int GetVersion(char version[1024]) = 0;
189
190 // Gets the last VoiceEngine error code.
191 virtual int LastError() = 0;
192
niklase@google.com470e71d2011-07-07 08:21:25 +0000193 // Stops or resumes playout and transmission on a temporary basis.
194 virtual int SetOnHoldStatus(int channel, bool enable,
195 OnHoldModes mode = kHoldSendAndPlay) = 0;
196
197 // Gets the current playout and transmission status.
198 virtual int GetOnHoldStatus(int channel, bool& enabled,
199 OnHoldModes& mode) = 0;
200
201 // Sets the NetEQ playout mode for a specified |channel| number.
202 virtual int SetNetEQPlayoutMode(int channel, NetEqModes mode) = 0;
203
204 // Gets the NetEQ playout mode for a specified |channel| number.
205 virtual int GetNetEQPlayoutMode(int channel, NetEqModes& mode) = 0;
206
207 // Sets the NetEQ background noise mode for a specified |channel| number.
208 virtual int SetNetEQBGNMode(int channel, NetEqBgnModes mode) = 0;
209
210 // Gets the NetEQ background noise mode for a specified |channel| number.
211 virtual int GetNetEQBGNMode(int channel, NetEqBgnModes& mode) = 0;
212
213protected:
214 VoEBase() {}
215 virtual ~VoEBase() {}
216};
217
218} // namespace webrtc
219
220#endif // WEBRTC_VOICE_ENGINE_VOE_BASE_H