blob: 94ac6ac461de059d0b53ffc01d9fc1e34cb32780 [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
niklase@google.com470e71d2011-07-07 08:21:25 +000051// VoiceEngine
Jelena Marusic0d266052015-05-04 14:15:32 +020052class WEBRTC_DLLEXPORT VoiceEngine {
53 public:
54 // Creates a VoiceEngine object, which can then be used to acquire
55 // sub-APIs. Returns NULL on failure.
56 static VoiceEngine* Create();
niklase@google.com470e71d2011-07-07 08:21:25 +000057
Jelena Marusic0d266052015-05-04 14:15:32 +020058 // Deletes a created VoiceEngine object and releases the utilized resources.
59 // Note that if there are outstanding references held via other interfaces,
60 // the voice engine instance will not actually be deleted until those
61 // references have been released.
62 static bool Delete(VoiceEngine*& voiceEngine);
niklase@google.com470e71d2011-07-07 08:21:25 +000063
Jelena Marusic0d266052015-05-04 14:15:32 +020064 protected:
65 VoiceEngine() {}
66 ~VoiceEngine() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000067};
68
69// VoEBase
Jelena Marusic0d266052015-05-04 14:15:32 +020070class WEBRTC_DLLEXPORT VoEBase {
71 public:
solenberg88499ec2016-09-07 07:34:41 -070072 struct ChannelConfig {
73 AudioCodingModule::Config acm_config;
74 bool enable_voice_pacing = false;
75 };
76
Jelena Marusic0d266052015-05-04 14:15:32 +020077 // Factory for the VoEBase sub-API. Increases an internal reference
78 // counter if successful. Returns NULL if the API is not supported or if
79 // construction fails.
80 static VoEBase* GetInterface(VoiceEngine* voiceEngine);
niklase@google.com470e71d2011-07-07 08:21:25 +000081
Jelena Marusic0d266052015-05-04 14:15:32 +020082 // Releases the VoEBase sub-API and decreases an internal reference
83 // counter. Returns the new reference count. This value should be zero
84 // for all sub-APIs before the VoiceEngine object can be safely deleted.
85 virtual int Release() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000086
Jelena Marusic0d266052015-05-04 14:15:32 +020087 // Initializes all common parts of the VoiceEngine; e.g. all
88 // encoders/decoders, the sound card and core receiving components.
89 // This method also makes it possible to install some user-defined external
90 // modules:
91 // - The Audio Device Module (ADM) which implements all the audio layer
92 // functionality in a separate (reference counted) module.
peaha9cc40b2017-06-29 08:32:09 -070093 // - The AudioProcessing module handles capture-side processing.
ossu5f7cfa52016-05-30 08:11:28 -070094 // - An AudioDecoderFactory - used to create audio decoders.
peaha9cc40b2017-06-29 08:32:09 -070095 // If NULL is passed for either of ADM or AudioDecoderFactory, VoiceEngine
96 // will create its own. Returns -1 in case of an error, 0 otherwise.
Jelena Marusic0d266052015-05-04 14:15:32 +020097 // TODO(ajm): Remove default NULLs.
98 virtual int Init(AudioDeviceModule* external_adm = NULL,
peaha9cc40b2017-06-29 08:32:09 -070099 AudioProcessing* external_apm = nullptr,
ossu5f7cfa52016-05-30 08:11:28 -0700100 const rtc::scoped_refptr<AudioDecoderFactory>&
101 decoder_factory = nullptr) = 0;
solenbergff976312016-03-30 23:28:51 -0700102 // This method is WIP - DO NOT USE!
103 // Returns NULL before Init() is called.
104 virtual AudioDeviceModule* audio_device_module() = 0;
105
solenberg76377c52017-02-21 00:54:31 -0800106 // This method is WIP - DO NOT USE!
107 // Returns NULL before Init() is called.
108 virtual voe::TransmitMixer* transmit_mixer() = 0;
109
Jelena Marusic0d266052015-05-04 14:15:32 +0200110 // Terminates all VoiceEngine functions and releases allocated resources.
111 // Returns 0.
112 virtual int Terminate() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000113
Jelena Marusic0d266052015-05-04 14:15:32 +0200114 // Creates a new channel and allocates the required resources for it.
solenberg88499ec2016-09-07 07:34:41 -0700115 // The second version accepts a |config| struct which includes an Audio Coding
116 // Module config and an option to enable voice pacing. Note that the
117 // decoder_factory member of the ACM config will be ignored (the decoder
118 // factory set through Init() will always be used).
Jelena Marusic0d266052015-05-04 14:15:32 +0200119 // Returns channel ID or -1 in case of an error.
120 virtual int CreateChannel() = 0;
solenberg88499ec2016-09-07 07:34:41 -0700121 virtual int CreateChannel(const ChannelConfig& config) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000122
Jelena Marusic0d266052015-05-04 14:15:32 +0200123 // Deletes an existing channel and releases the utilized resources.
124 // Returns -1 in case of an error, 0 otherwise.
125 virtual int DeleteChannel(int channel) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000126
Jelena Marusic0d266052015-05-04 14:15:32 +0200127 // Starts forwarding the packets to the mixer/soundcard for a
128 // specified |channel|.
129 virtual int StartPlayout(int channel) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000130
Jelena Marusic0d266052015-05-04 14:15:32 +0200131 // Stops forwarding the packets to the mixer/soundcard for a
132 // specified |channel|.
133 virtual int StopPlayout(int channel) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000134
Jelena Marusic0d266052015-05-04 14:15:32 +0200135 // Starts sending packets to an already specified IP address and
136 // port number for a specified |channel|.
137 virtual int StartSend(int channel) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000138
Jelena Marusic0d266052015-05-04 14:15:32 +0200139 // Stops sending packets from a specified |channel|.
140 virtual int StopSend(int channel) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000141
Jelena Marusic0d266052015-05-04 14:15:32 +0200142 // TODO(xians): Make the interface pure virtual after libjingle
143 // implements the interface in its FakeWebRtcVoiceEngine.
144 virtual AudioTransport* audio_transport() { return NULL; }
xians@webrtc.orgc1e28032014-02-02 15:30:20 +0000145
Jelena Marusic0d266052015-05-04 14:15:32 +0200146 protected:
147 VoEBase() {}
148 virtual ~VoEBase() {}
niklase@google.com470e71d2011-07-07 08:21:25 +0000149};
150
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000151} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000152
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200153#endif // VOICE_ENGINE_VOE_BASE_H_