blob: a76d2bc94322909a0394a9cdc945421c19cdbe1e [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;
niklase@google.com470e71d2011-07-07 08:21:25 +000046
niklase@google.com470e71d2011-07-07 08:21:25 +000047// VoiceEngine
Jelena Marusic0d266052015-05-04 14:15:32 +020048class WEBRTC_DLLEXPORT VoiceEngine {
49 public:
50 // Creates a VoiceEngine object, which can then be used to acquire
51 // sub-APIs. Returns NULL on failure.
52 static VoiceEngine* Create();
niklase@google.com470e71d2011-07-07 08:21:25 +000053
Jelena Marusic0d266052015-05-04 14:15:32 +020054 // Deletes a created VoiceEngine object and releases the utilized resources.
55 // Note that if there are outstanding references held via other interfaces,
56 // the voice engine instance will not actually be deleted until those
57 // references have been released.
58 static bool Delete(VoiceEngine*& voiceEngine);
niklase@google.com470e71d2011-07-07 08:21:25 +000059
Jelena Marusic0d266052015-05-04 14:15:32 +020060 protected:
61 VoiceEngine() {}
62 ~VoiceEngine() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000063};
64
65// VoEBase
Jelena Marusic0d266052015-05-04 14:15:32 +020066class WEBRTC_DLLEXPORT VoEBase {
67 public:
solenberg88499ec2016-09-07 07:34:41 -070068 struct ChannelConfig {
69 AudioCodingModule::Config acm_config;
70 bool enable_voice_pacing = false;
71 };
72
Jelena Marusic0d266052015-05-04 14:15:32 +020073 // Factory for the VoEBase sub-API. Increases an internal reference
74 // counter if successful. Returns NULL if the API is not supported or if
75 // construction fails.
76 static VoEBase* GetInterface(VoiceEngine* voiceEngine);
niklase@google.com470e71d2011-07-07 08:21:25 +000077
Jelena Marusic0d266052015-05-04 14:15:32 +020078 // Releases the VoEBase sub-API and decreases an internal reference
79 // counter. Returns the new reference count. This value should be zero
80 // for all sub-APIs before the VoiceEngine object can be safely deleted.
81 virtual int Release() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000082
Jelena Marusic0d266052015-05-04 14:15:32 +020083 // Initializes all common parts of the VoiceEngine; e.g. all
84 // encoders/decoders, the sound card and core receiving components.
85 // This method also makes it possible to install some user-defined external
86 // modules:
87 // - The Audio Device Module (ADM) which implements all the audio layer
88 // functionality in a separate (reference counted) module.
Fredrik Solenberg2a877972017-12-15 16:42:15 +010089 // - The AudioProcessing module is unused - only kept for API compatibility.
ossu5f7cfa52016-05-30 08:11:28 -070090 // - An AudioDecoderFactory - used to create audio decoders.
Karl Wibergf3850f62017-11-02 13:04:41 +010091 virtual int Init(
Fredrik Solenbergd3195342017-11-21 20:33:05 +010092 AudioDeviceModule* audio_device,
93 AudioProcessing* audio_processing,
Karl Wibergf3850f62017-11-02 13:04:41 +010094 const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory) = 0;
solenbergff976312016-03-30 23:28:51 -070095
Jelena Marusic0d266052015-05-04 14:15:32 +020096 // Terminates all VoiceEngine functions and releases allocated resources.
Fredrik Solenberg55900fd2017-11-23 20:22:55 +010097 virtual void Terminate() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000098
Jelena Marusic0d266052015-05-04 14:15:32 +020099 // Creates a new channel and allocates the required resources for it.
solenberg88499ec2016-09-07 07:34:41 -0700100 // The second version accepts a |config| struct which includes an Audio Coding
101 // Module config and an option to enable voice pacing. Note that the
102 // decoder_factory member of the ACM config will be ignored (the decoder
103 // factory set through Init() will always be used).
Jelena Marusic0d266052015-05-04 14:15:32 +0200104 // Returns channel ID or -1 in case of an error.
105 virtual int CreateChannel() = 0;
solenberg88499ec2016-09-07 07:34:41 -0700106 virtual int CreateChannel(const ChannelConfig& config) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000107
Jelena Marusic0d266052015-05-04 14:15:32 +0200108 // Deletes an existing channel and releases the utilized resources.
109 // Returns -1 in case of an error, 0 otherwise.
110 virtual int DeleteChannel(int channel) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000111
Jelena Marusic0d266052015-05-04 14:15:32 +0200112 protected:
113 VoEBase() {}
114 virtual ~VoEBase() {}
niklase@google.com470e71d2011-07-07 08:21:25 +0000115};
116
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000117} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000118
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200119#endif // VOICE_ENGINE_VOE_BASE_H_