blob: c8db8c63d93db6adf683d0d8ca04beea0c0fcf24 [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.).
niklase@google.com470e71d2011-07-07 08:21:25 +000017//
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
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +000037#include "webrtc/common_types.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000038
39namespace webrtc {
40
41class AudioDeviceModule;
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000042class AudioProcessing;
xians@webrtc.orgc1e28032014-02-02 15:30:20 +000043class AudioTransport;
minyue@webrtc.orge509f942013-09-12 17:03:00 +000044class Config;
niklase@google.com470e71d2011-07-07 08:21:25 +000045
46const int kVoEDefault = -1;
47
48// VoiceEngineObserver
49class WEBRTC_DLLEXPORT VoiceEngineObserver
50{
51public:
52 // This method will be called after the occurrence of any runtime error
53 // code, or warning notification, when the observer interface has been
54 // installed using VoEBase::RegisterVoiceEngineObserver().
pbos@webrtc.org92135212013-05-14 08:31:39 +000055 virtual void CallbackOnError(int channel, int errCode) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000056
57protected:
58 virtual ~VoiceEngineObserver() {}
59};
60
61// VoiceEngine
62class WEBRTC_DLLEXPORT VoiceEngine
63{
64public:
65 // Creates a VoiceEngine object, which can then be used to acquire
66 // sub-APIs. Returns NULL on failure.
67 static VoiceEngine* Create();
minyue@webrtc.orge509f942013-09-12 17:03:00 +000068 static VoiceEngine* Create(const Config& config);
niklase@google.com470e71d2011-07-07 08:21:25 +000069
70 // Deletes a created VoiceEngine object and releases the utilized resources.
tommi@webrtc.orga990e122012-04-26 15:28:22 +000071 // Note that if there are outstanding references held via other interfaces,
72 // the voice engine instance will not actually be deleted until those
73 // references have been released.
74 static bool Delete(VoiceEngine*& voiceEngine);
niklase@google.com470e71d2011-07-07 08:21:25 +000075
76 // Specifies the amount and type of trace information which will be
77 // created by the VoiceEngine.
pbos@webrtc.org92135212013-05-14 08:31:39 +000078 static int SetTraceFilter(unsigned int filter);
niklase@google.com470e71d2011-07-07 08:21:25 +000079
80 // Sets the name of the trace file and enables non-encrypted trace messages.
81 static int SetTraceFile(const char* fileNameUTF8,
pbos@webrtc.org92135212013-05-14 08:31:39 +000082 bool addFileCounter = false);
niklase@google.com470e71d2011-07-07 08:21:25 +000083
84 // Installs the TraceCallback implementation to ensure that the user
85 // receives callbacks for generated trace messages.
86 static int SetTraceCallback(TraceCallback* callback);
87
88 static int SetAndroidObjects(void* javaVM, void* env, void* context);
89
90protected:
91 VoiceEngine() {}
tommi@webrtc.org0989fb72013-02-15 15:07:32 +000092 ~VoiceEngine() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000093};
94
95// VoEBase
96class WEBRTC_DLLEXPORT VoEBase
97{
98public:
99 // Factory for the VoEBase sub-API. Increases an internal reference
100 // counter if successful. Returns NULL if the API is not supported or if
101 // construction fails.
102 static VoEBase* GetInterface(VoiceEngine* voiceEngine);
103
104 // Releases the VoEBase sub-API and decreases an internal reference
105 // counter. Returns the new reference count. This value should be zero
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +0000106 // for all sub-APIs before the VoiceEngine object can be safely deleted.
niklase@google.com470e71d2011-07-07 08:21:25 +0000107 virtual int Release() = 0;
108
109 // Installs the observer class to enable runtime error control and
110 // warning notifications.
111 virtual int RegisterVoiceEngineObserver(VoiceEngineObserver& observer) = 0;
112
113 // Removes and disables the observer class for runtime error control
114 // and warning notifications.
115 virtual int DeRegisterVoiceEngineObserver() = 0;
116
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +0000117 // Initializes all common parts of the VoiceEngine; e.g. all
niklase@google.com470e71d2011-07-07 08:21:25 +0000118 // encoders/decoders, the sound card and core receiving components.
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +0000119 // This method also makes it possible to install some user-defined external
120 // modules:
121 // - The Audio Device Module (ADM) which implements all the audio layer
122 // functionality in a separate (reference counted) module.
123 // - The AudioProcessing module handles capture-side processing. VoiceEngine
124 // takes ownership of this object.
125 // If NULL is passed for any of these, VoiceEngine will create its own.
126 // TODO(ajm): Remove default NULLs.
127 virtual int Init(AudioDeviceModule* external_adm = NULL,
128 AudioProcessing* audioproc = NULL) = 0;
129
130 // Returns NULL before Init() is called.
131 virtual AudioProcessing* audio_processing() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000132
133 // Terminates all VoiceEngine functions and releses allocated resources.
134 virtual int Terminate() = 0;
135
niklase@google.com470e71d2011-07-07 08:21:25 +0000136 // Creates a new channel and allocates the required resources for it.
turaj@webrtc.org03f33702013-11-13 00:02:48 +0000137 // One can use |config| to configure the channel. Currently that is used for
138 // choosing between ACM1 and ACM2, when creating Audio Coding Module.
niklase@google.com470e71d2011-07-07 08:21:25 +0000139 virtual int CreateChannel() = 0;
turaj@webrtc.org03f33702013-11-13 00:02:48 +0000140 virtual int CreateChannel(const Config& config) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000141
142 // Deletes an existing channel and releases the utilized resources.
143 virtual int DeleteChannel(int channel) = 0;
144
niklase@google.com470e71d2011-07-07 08:21:25 +0000145 // Prepares and initiates the VoiceEngine for reception of
146 // incoming RTP/RTCP packets on the specified |channel|.
147 virtual int StartReceive(int channel) = 0;
148
149 // Stops receiving incoming RTP/RTCP packets on the specified |channel|.
150 virtual int StopReceive(int channel) = 0;
151
152 // Starts forwarding the packets to the mixer/soundcard for a
153 // specified |channel|.
154 virtual int StartPlayout(int channel) = 0;
155
156 // Stops forwarding the packets to the mixer/soundcard for a
157 // specified |channel|.
158 virtual int StopPlayout(int channel) = 0;
159
160 // Starts sending packets to an already specified IP address and
161 // port number for a specified |channel|.
162 virtual int StartSend(int channel) = 0;
163
164 // Stops sending packets from a specified |channel|.
165 virtual int StopSend(int channel) = 0;
166
167 // Gets the version information for VoiceEngine and its components.
168 virtual int GetVersion(char version[1024]) = 0;
169
170 // Gets the last VoiceEngine error code.
171 virtual int LastError() = 0;
172
niklase@google.com470e71d2011-07-07 08:21:25 +0000173 // Stops or resumes playout and transmission on a temporary basis.
174 virtual int SetOnHoldStatus(int channel, bool enable,
175 OnHoldModes mode = kHoldSendAndPlay) = 0;
176
177 // Gets the current playout and transmission status.
178 virtual int GetOnHoldStatus(int channel, bool& enabled,
179 OnHoldModes& mode) = 0;
180
181 // Sets the NetEQ playout mode for a specified |channel| number.
182 virtual int SetNetEQPlayoutMode(int channel, NetEqModes mode) = 0;
183
184 // Gets the NetEQ playout mode for a specified |channel| number.
185 virtual int GetNetEQPlayoutMode(int channel, NetEqModes& mode) = 0;
186
xians@webrtc.org07e51962014-01-29 13:54:02 +0000187 // TODO(xians): Make the interface pure virtual after libjingle
188 // implements the interface in its FakeWebRtcVoiceEngine.
xians@webrtc.orgc1e28032014-02-02 15:30:20 +0000189 virtual AudioTransport* audio_transport() { return NULL; }
190
niklase@google.com470e71d2011-07-07 08:21:25 +0000191protected:
192 VoEBase() {}
193 virtual ~VoEBase() {}
194};
195
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000196} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000197
198#endif // WEBRTC_VOICE_ENGINE_VOE_BASE_H