blob: b2daca19cdb53bf2331364ce6b35e4688e694aa1 [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 protected:
77 VoiceEngine() {}
78 ~VoiceEngine() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000079};
80
81// VoEBase
Jelena Marusic0d266052015-05-04 14:15:32 +020082class WEBRTC_DLLEXPORT VoEBase {
83 public:
solenberg88499ec2016-09-07 07:34:41 -070084 struct ChannelConfig {
85 AudioCodingModule::Config acm_config;
86 bool enable_voice_pacing = false;
87 };
88
Jelena Marusic0d266052015-05-04 14:15:32 +020089 // Factory for the VoEBase sub-API. Increases an internal reference
90 // counter if successful. Returns NULL if the API is not supported or if
91 // construction fails.
92 static VoEBase* GetInterface(VoiceEngine* voiceEngine);
niklase@google.com470e71d2011-07-07 08:21:25 +000093
Jelena Marusic0d266052015-05-04 14:15:32 +020094 // Releases the VoEBase sub-API and decreases an internal reference
95 // counter. Returns the new reference count. This value should be zero
96 // for all sub-APIs before the VoiceEngine object can be safely deleted.
97 virtual int Release() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000098
Jelena Marusic0d266052015-05-04 14:15:32 +020099 // Installs the observer class to enable runtime error control and
100 // warning notifications. Returns -1 in case of an error, 0 otherwise.
101 virtual int RegisterVoiceEngineObserver(VoiceEngineObserver& observer) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000102
Jelena Marusic0d266052015-05-04 14:15:32 +0200103 // Removes and disables the observer class for runtime error control
104 // and warning notifications. Returns 0.
105 virtual int DeRegisterVoiceEngineObserver() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000106
Jelena Marusic0d266052015-05-04 14:15:32 +0200107 // Initializes all common parts of the VoiceEngine; e.g. all
108 // encoders/decoders, the sound card and core receiving components.
109 // This method also makes it possible to install some user-defined external
110 // modules:
111 // - The Audio Device Module (ADM) which implements all the audio layer
112 // functionality in a separate (reference counted) module.
peaha9cc40b2017-06-29 08:32:09 -0700113 // - The AudioProcessing module handles capture-side processing.
ossu5f7cfa52016-05-30 08:11:28 -0700114 // - An AudioDecoderFactory - used to create audio decoders.
peaha9cc40b2017-06-29 08:32:09 -0700115 // If NULL is passed for either of ADM or AudioDecoderFactory, VoiceEngine
116 // will create its own. Returns -1 in case of an error, 0 otherwise.
Jelena Marusic0d266052015-05-04 14:15:32 +0200117 // TODO(ajm): Remove default NULLs.
118 virtual int Init(AudioDeviceModule* external_adm = NULL,
peaha9cc40b2017-06-29 08:32:09 -0700119 AudioProcessing* external_apm = nullptr,
ossu5f7cfa52016-05-30 08:11:28 -0700120 const rtc::scoped_refptr<AudioDecoderFactory>&
121 decoder_factory = nullptr) = 0;
solenbergff976312016-03-30 23:28:51 -0700122 // This method is WIP - DO NOT USE!
123 // Returns NULL before Init() is called.
124 virtual AudioDeviceModule* audio_device_module() = 0;
125
solenberg76377c52017-02-21 00:54:31 -0800126 // This method is WIP - DO NOT USE!
127 // Returns NULL before Init() is called.
128 virtual voe::TransmitMixer* transmit_mixer() = 0;
129
Jelena Marusic0d266052015-05-04 14:15:32 +0200130 // Terminates all VoiceEngine functions and releases allocated resources.
131 // Returns 0.
132 virtual int Terminate() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000133
Jelena Marusic0d266052015-05-04 14:15:32 +0200134 // Creates a new channel and allocates the required resources for it.
solenberg88499ec2016-09-07 07:34:41 -0700135 // The second version accepts a |config| struct which includes an Audio Coding
136 // Module config and an option to enable voice pacing. Note that the
137 // decoder_factory member of the ACM config will be ignored (the decoder
138 // factory set through Init() will always be used).
Jelena Marusic0d266052015-05-04 14:15:32 +0200139 // Returns channel ID or -1 in case of an error.
140 virtual int CreateChannel() = 0;
solenberg88499ec2016-09-07 07:34:41 -0700141 virtual int CreateChannel(const ChannelConfig& config) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000142
Jelena Marusic0d266052015-05-04 14:15:32 +0200143 // Deletes an existing channel and releases the utilized resources.
144 // Returns -1 in case of an error, 0 otherwise.
145 virtual int DeleteChannel(int channel) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000146
Jelena Marusic0d266052015-05-04 14:15:32 +0200147 // Starts forwarding the packets to the mixer/soundcard for a
148 // specified |channel|.
149 virtual int StartPlayout(int channel) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000150
Jelena Marusic0d266052015-05-04 14:15:32 +0200151 // Stops forwarding the packets to the mixer/soundcard for a
152 // specified |channel|.
153 virtual int StopPlayout(int channel) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000154
Jelena Marusic0d266052015-05-04 14:15:32 +0200155 // Starts sending packets to an already specified IP address and
156 // port number for a specified |channel|.
157 virtual int StartSend(int channel) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000158
Jelena Marusic0d266052015-05-04 14:15:32 +0200159 // Stops sending packets from a specified |channel|.
160 virtual int StopSend(int channel) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000161
Jelena Marusic0d266052015-05-04 14:15:32 +0200162 // TODO(xians): Make the interface pure virtual after libjingle
163 // implements the interface in its FakeWebRtcVoiceEngine.
164 virtual AudioTransport* audio_transport() { return NULL; }
xians@webrtc.orgc1e28032014-02-02 15:30:20 +0000165
Jelena Marusic0d266052015-05-04 14:15:32 +0200166 protected:
167 VoEBase() {}
168 virtual ~VoEBase() {}
niklase@google.com470e71d2011-07-07 08:21:25 +0000169};
170
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000171} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000172
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200173#endif // VOICE_ENGINE_VOE_BASE_H_