blob: 681b5ab28420fc99b6a41b19764c2cff4cf02b46 [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//
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020034#ifndef VOICE_ENGINE_VOE_BASE_H_
35#define VOICE_ENGINE_VOE_BASE_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000036
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020037#include "api/audio_codecs/audio_decoder_factory.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020038#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020039#include "modules/audio_coding/include/audio_coding_module.h"
40#include "rtc_base/scoped_ref_ptr.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000041
42namespace webrtc {
43
44class AudioDeviceModule;
andrew@webrtc.orgf0a90c32013-03-05 01:12:49 +000045class AudioProcessing;
xians@webrtc.orgc1e28032014-02-02 15:30:20 +000046class AudioTransport;
solenberg76377c52017-02-21 00:54:31 -080047namespace voe {
48class TransmitMixer;
49} // namespace voe
niklase@google.com470e71d2011-07-07 08:21:25 +000050
51// VoiceEngineObserver
Jelena Marusic0d266052015-05-04 14:15:32 +020052class WEBRTC_DLLEXPORT VoiceEngineObserver {
53 public:
54 // This method will be called after the occurrence of any runtime error
55 // code, or warning notification, when the observer interface has been
56 // installed using VoEBase::RegisterVoiceEngineObserver().
57 virtual void CallbackOnError(int channel, int errCode) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000058
Jelena Marusic0d266052015-05-04 14:15:32 +020059 protected:
60 virtual ~VoiceEngineObserver() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000061};
62
63// VoiceEngine
Jelena Marusic0d266052015-05-04 14:15:32 +020064class WEBRTC_DLLEXPORT VoiceEngine {
65 public:
66 // Creates a VoiceEngine object, which can then be used to acquire
67 // sub-APIs. Returns NULL on failure.
68 static VoiceEngine* Create();
niklase@google.com470e71d2011-07-07 08:21:25 +000069
Jelena Marusic0d266052015-05-04 14:15:32 +020070 // Deletes a created VoiceEngine object and releases the utilized resources.
71 // 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
Jelena Marusic0d266052015-05-04 14:15:32 +020076 // Specifies the amount and type of trace information which will be
77 // created by the VoiceEngine.
78 static int SetTraceFilter(unsigned int filter);
niklase@google.com470e71d2011-07-07 08:21:25 +000079
Jelena Marusic0d266052015-05-04 14:15:32 +020080 // Sets the name of the trace file and enables non-encrypted trace messages.
81 static int SetTraceFile(const char* fileNameUTF8,
82 bool addFileCounter = false);
niklase@google.com470e71d2011-07-07 08:21:25 +000083
Jelena Marusic0d266052015-05-04 14:15:32 +020084 // Installs the TraceCallback implementation to ensure that the user
85 // receives callbacks for generated trace messages.
86 static int SetTraceCallback(TraceCallback* callback);
niklase@google.com470e71d2011-07-07 08:21:25 +000087
solenberg2515af22015-12-02 06:19:36 -080088 static std::string GetVersionString();
89
Jelena Marusic0d266052015-05-04 14:15:32 +020090 protected:
91 VoiceEngine() {}
92 ~VoiceEngine() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000093};
94
95// VoEBase
Jelena Marusic0d266052015-05-04 14:15:32 +020096class WEBRTC_DLLEXPORT VoEBase {
97 public:
solenberg88499ec2016-09-07 07:34:41 -070098 struct ChannelConfig {
99 AudioCodingModule::Config acm_config;
100 bool enable_voice_pacing = false;
101 };
102
Jelena Marusic0d266052015-05-04 14:15:32 +0200103 // Factory for the VoEBase sub-API. Increases an internal reference
104 // counter if successful. Returns NULL if the API is not supported or if
105 // construction fails.
106 static VoEBase* GetInterface(VoiceEngine* voiceEngine);
niklase@google.com470e71d2011-07-07 08:21:25 +0000107
Jelena Marusic0d266052015-05-04 14:15:32 +0200108 // Releases the VoEBase sub-API and decreases an internal reference
109 // counter. Returns the new reference count. This value should be zero
110 // for all sub-APIs before the VoiceEngine object can be safely deleted.
111 virtual int Release() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000112
Jelena Marusic0d266052015-05-04 14:15:32 +0200113 // Installs the observer class to enable runtime error control and
114 // warning notifications. Returns -1 in case of an error, 0 otherwise.
115 virtual int RegisterVoiceEngineObserver(VoiceEngineObserver& observer) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000116
Jelena Marusic0d266052015-05-04 14:15:32 +0200117 // Removes and disables the observer class for runtime error control
118 // and warning notifications. Returns 0.
119 virtual int DeRegisterVoiceEngineObserver() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000120
Jelena Marusic0d266052015-05-04 14:15:32 +0200121 // Initializes all common parts of the VoiceEngine; e.g. all
122 // encoders/decoders, the sound card and core receiving components.
123 // This method also makes it possible to install some user-defined external
124 // modules:
125 // - The Audio Device Module (ADM) which implements all the audio layer
126 // functionality in a separate (reference counted) module.
peaha9cc40b2017-06-29 08:32:09 -0700127 // - The AudioProcessing module handles capture-side processing.
ossu5f7cfa52016-05-30 08:11:28 -0700128 // - An AudioDecoderFactory - used to create audio decoders.
peaha9cc40b2017-06-29 08:32:09 -0700129 // If NULL is passed for either of ADM or AudioDecoderFactory, VoiceEngine
130 // will create its own. Returns -1 in case of an error, 0 otherwise.
Jelena Marusic0d266052015-05-04 14:15:32 +0200131 // TODO(ajm): Remove default NULLs.
132 virtual int Init(AudioDeviceModule* external_adm = NULL,
peaha9cc40b2017-06-29 08:32:09 -0700133 AudioProcessing* external_apm = nullptr,
ossu5f7cfa52016-05-30 08:11:28 -0700134 const rtc::scoped_refptr<AudioDecoderFactory>&
135 decoder_factory = nullptr) = 0;
solenbergff976312016-03-30 23:28:51 -0700136 // This method is WIP - DO NOT USE!
137 // Returns NULL before Init() is called.
138 virtual AudioDeviceModule* audio_device_module() = 0;
139
solenberg76377c52017-02-21 00:54:31 -0800140 // This method is WIP - DO NOT USE!
141 // Returns NULL before Init() is called.
142 virtual voe::TransmitMixer* transmit_mixer() = 0;
143
Jelena Marusic0d266052015-05-04 14:15:32 +0200144 // Terminates all VoiceEngine functions and releases allocated resources.
145 // Returns 0.
146 virtual int Terminate() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000147
Jelena Marusic0d266052015-05-04 14:15:32 +0200148 // Creates a new channel and allocates the required resources for it.
solenberg88499ec2016-09-07 07:34:41 -0700149 // The second version accepts a |config| struct which includes an Audio Coding
150 // Module config and an option to enable voice pacing. Note that the
151 // decoder_factory member of the ACM config will be ignored (the decoder
152 // factory set through Init() will always be used).
Jelena Marusic0d266052015-05-04 14:15:32 +0200153 // Returns channel ID or -1 in case of an error.
154 virtual int CreateChannel() = 0;
solenberg88499ec2016-09-07 07:34:41 -0700155 virtual int CreateChannel(const ChannelConfig& config) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000156
Jelena Marusic0d266052015-05-04 14:15:32 +0200157 // Deletes an existing channel and releases the utilized resources.
158 // Returns -1 in case of an error, 0 otherwise.
159 virtual int DeleteChannel(int channel) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000160
Jelena Marusic0d266052015-05-04 14:15:32 +0200161 // Prepares and initiates the VoiceEngine for reception of
162 // incoming RTP/RTCP packets on the specified |channel|.
163 virtual int StartReceive(int channel) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000164
Jelena Marusic0d266052015-05-04 14:15:32 +0200165 // Stops receiving incoming RTP/RTCP packets on the specified |channel|.
solenberge566ac72016-10-31 12:52:33 -0700166 virtual int StopReceive(int channel) { return 0; }
niklase@google.com470e71d2011-07-07 08:21:25 +0000167
Jelena Marusic0d266052015-05-04 14:15:32 +0200168 // Starts forwarding the packets to the mixer/soundcard for a
169 // specified |channel|.
170 virtual int StartPlayout(int channel) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000171
Jelena Marusic0d266052015-05-04 14:15:32 +0200172 // Stops forwarding the packets to the mixer/soundcard for a
173 // specified |channel|.
174 virtual int StopPlayout(int channel) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000175
Jelena Marusic0d266052015-05-04 14:15:32 +0200176 // Starts sending packets to an already specified IP address and
177 // port number for a specified |channel|.
178 virtual int StartSend(int channel) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000179
Jelena Marusic0d266052015-05-04 14:15:32 +0200180 // Stops sending packets from a specified |channel|.
181 virtual int StopSend(int channel) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000182
Jelena Marusic0d266052015-05-04 14:15:32 +0200183 // Gets the version information for VoiceEngine and its components.
184 virtual int GetVersion(char version[1024]) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000185
Jelena Marusic0d266052015-05-04 14:15:32 +0200186 // Gets the last VoiceEngine error code.
187 virtual int LastError() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000188
Jelena Marusic0d266052015-05-04 14:15:32 +0200189 // TODO(xians): Make the interface pure virtual after libjingle
190 // implements the interface in its FakeWebRtcVoiceEngine.
191 virtual AudioTransport* audio_transport() { return NULL; }
xians@webrtc.orgc1e28032014-02-02 15:30:20 +0000192
Minyue2013aec2015-05-13 14:14:42 +0200193 // Associate a send channel to a receive channel.
194 // Used for obtaining RTT for a receive-only channel.
195 // One should be careful not to crate a circular association, e.g.,
196 // 1 <- 2 <- 1.
Jelena Marusicf09e09c2015-05-26 10:24:55 +0200197 virtual int AssociateSendChannel(int channel, int accociate_send_channel) = 0;
henrika@webrtc.org66803482014-04-17 10:45:01 +0000198
Jelena Marusic0d266052015-05-04 14:15:32 +0200199 protected:
200 VoEBase() {}
201 virtual ~VoEBase() {}
niklase@google.com470e71d2011-07-07 08:21:25 +0000202};
203
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000204} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000205
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200206#endif // VOICE_ENGINE_VOE_BASE_H_