blob: b544c09f9a72bcbe6f68f79b90db6e6830fee7e3 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
kma@webrtc.orgde66b912012-02-01 18:39:44 +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#ifndef WEBRTC_VOICE_ENGINE_VOE_BASE_IMPL_H
12#define WEBRTC_VOICE_ENGINE_VOE_BASE_IMPL_H
13
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +000014#include "webrtc/voice_engine/include/voe_base.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000015
tommi31fc21f2016-01-21 10:37:37 -080016#include "webrtc/base/criticalsection.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010017#include "webrtc/modules/include/module_common_types.h"
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +000018#include "webrtc/voice_engine/shared_data.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000019
Jelena Marusic2dd6a272015-04-14 09:47:00 +020020namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000021
22class ProcessThread;
23
Jelena Marusic2dd6a272015-04-14 09:47:00 +020024class VoEBaseImpl : public VoEBase,
25 public AudioTransport,
26 public AudioDeviceObserver {
27 public:
28 int RegisterVoiceEngineObserver(VoiceEngineObserver& observer) override;
29 int DeRegisterVoiceEngineObserver() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000030
Jelena Marusic2dd6a272015-04-14 09:47:00 +020031 int Init(AudioDeviceModule* external_adm = nullptr,
ossu5f7cfa52016-05-30 08:11:28 -070032 AudioProcessing* audioproc = nullptr,
33 const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory =
34 nullptr) override;
Jelena Marusic2dd6a272015-04-14 09:47:00 +020035 AudioProcessing* audio_processing() override {
36 return shared_->audio_processing();
37 }
solenbergff976312016-03-30 23:28:51 -070038 AudioDeviceModule* audio_device_module() override {
39 return shared_->audio_device();
40 }
solenberg76377c52017-02-21 00:54:31 -080041 voe::TransmitMixer* transmit_mixer() override {
42 return shared_->transmit_mixer();
43 }
Jelena Marusic2dd6a272015-04-14 09:47:00 +020044 int Terminate() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000045
Jelena Marusic2dd6a272015-04-14 09:47:00 +020046 int CreateChannel() override;
solenberg88499ec2016-09-07 07:34:41 -070047 int CreateChannel(const ChannelConfig& config) override;
Jelena Marusic2dd6a272015-04-14 09:47:00 +020048 int DeleteChannel(int channel) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000049
Jelena Marusic2dd6a272015-04-14 09:47:00 +020050 int StartReceive(int channel) override;
51 int StartPlayout(int channel) override;
52 int StartSend(int channel) override;
Jelena Marusic2dd6a272015-04-14 09:47:00 +020053 int StopPlayout(int channel) override;
54 int StopSend(int channel) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000055
Jelena Marusic2dd6a272015-04-14 09:47:00 +020056 int GetVersion(char version[1024]) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000057
Jelena Marusic2dd6a272015-04-14 09:47:00 +020058 int LastError() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000059
Jelena Marusic2dd6a272015-04-14 09:47:00 +020060 AudioTransport* audio_transport() override { return this; }
niklase@google.com470e71d2011-07-07 08:21:25 +000061
Minyue2013aec2015-05-13 14:14:42 +020062 int AssociateSendChannel(int channel, int accociate_send_channel) override;
63
Jelena Marusic2dd6a272015-04-14 09:47:00 +020064 // AudioTransport
solenberg13725082015-11-25 08:16:52 -080065 int32_t RecordedDataIsAvailable(const void* audioSamples,
66 const size_t nSamples,
67 const size_t nBytesPerSample,
Peter Kasting69558702016-01-12 16:26:35 -080068 const size_t nChannels,
solenberg13725082015-11-25 08:16:52 -080069 const uint32_t samplesPerSec,
70 const uint32_t totalDelayMS,
71 const int32_t clockDrift,
72 const uint32_t currentMicLevel,
73 const bool keyPressed,
Jelena Marusic2dd6a272015-04-14 09:47:00 +020074 uint32_t& newMicLevel) override;
solenberg13725082015-11-25 08:16:52 -080075 int32_t NeedMorePlayData(const size_t nSamples,
76 const size_t nBytesPerSample,
Peter Kasting69558702016-01-12 16:26:35 -080077 const size_t nChannels,
solenberg13725082015-11-25 08:16:52 -080078 const uint32_t samplesPerSec,
79 void* audioSamples,
80 size_t& nSamplesOut,
Jelena Marusic2dd6a272015-04-14 09:47:00 +020081 int64_t* elapsed_time_ms,
82 int64_t* ntp_time_ms) override;
solenberg13725082015-11-25 08:16:52 -080083 void PushCaptureData(int voe_channel,
84 const void* audio_data,
85 int bits_per_sample,
86 int sample_rate,
Peter Kasting69558702016-01-12 16:26:35 -080087 size_t number_of_channels,
Peter Kastingdce40cf2015-08-24 14:52:23 -070088 size_t number_of_frames) override;
solenberg13725082015-11-25 08:16:52 -080089 void PullRenderData(int bits_per_sample,
90 int sample_rate,
Peter Kasting69558702016-01-12 16:26:35 -080091 size_t number_of_channels,
solenberg13725082015-11-25 08:16:52 -080092 size_t number_of_frames,
93 void* audio_data,
94 int64_t* elapsed_time_ms,
Jelena Marusic2dd6a272015-04-14 09:47:00 +020095 int64_t* ntp_time_ms) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000096
Jelena Marusic2dd6a272015-04-14 09:47:00 +020097 // AudioDeviceObserver
solenberg13725082015-11-25 08:16:52 -080098 void OnErrorIsReported(const ErrorCode error) override;
99 void OnWarningIsReported(const WarningCode warning) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000100
Jelena Marusic2dd6a272015-04-14 09:47:00 +0200101 protected:
102 VoEBaseImpl(voe::SharedData* shared);
103 ~VoEBaseImpl() override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000104
Jelena Marusic2dd6a272015-04-14 09:47:00 +0200105 private:
106 int32_t StartPlayout();
107 int32_t StopPlayout();
108 int32_t StartSend();
109 int32_t StopSend();
110 int32_t TerminateInternal();
niklase@google.com470e71d2011-07-07 08:21:25 +0000111
Jelena Marusic2dd6a272015-04-14 09:47:00 +0200112 // Helper function to process the recorded data with AudioProcessing Module,
113 // demultiplex the data to specific voe channels, encode and send to the
114 // network. When |number_of_VoE_channels| is 0, it will demultiplex the
115 // data to all the existing VoE channels.
116 // It returns new AGC microphone volume or 0 if no volume changes
117 // should be done.
118 int ProcessRecordedDataWithAPM(
Peter Kasting69558702016-01-12 16:26:35 -0800119 const int voe_channels[], size_t number_of_voe_channels,
120 const void* audio_data, uint32_t sample_rate, size_t number_of_channels,
Peter Kastingdce40cf2015-08-24 14:52:23 -0700121 size_t number_of_frames, uint32_t audio_delay_milliseconds,
Jelena Marusic2dd6a272015-04-14 09:47:00 +0200122 int32_t clock_drift, uint32_t volume, bool key_pressed);
niklase@google.com470e71d2011-07-07 08:21:25 +0000123
Peter Kasting69558702016-01-12 16:26:35 -0800124 void GetPlayoutData(int sample_rate, size_t number_of_channels,
Peter Kastingdce40cf2015-08-24 14:52:23 -0700125 size_t number_of_frames, bool feed_data_to_apm,
Jelena Marusic2dd6a272015-04-14 09:47:00 +0200126 void* audio_data, int64_t* elapsed_time_ms,
127 int64_t* ntp_time_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +0000128
Jelena Marusic2dd6a272015-04-14 09:47:00 +0200129 // Initialize channel by setting Engine Information then initializing
130 // channel.
131 int InitializeChannel(voe::ChannelOwner* channel_owner);
Jelena Marusic2dd6a272015-04-14 09:47:00 +0200132 VoiceEngineObserver* voiceEngineObserverPtr_;
tommi31fc21f2016-01-21 10:37:37 -0800133 rtc::CriticalSection callbackCritSect_;
ossu5f7cfa52016-05-30 08:11:28 -0700134 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000135
Jelena Marusic2dd6a272015-04-14 09:47:00 +0200136 AudioFrame audioFrame_;
137 voe::SharedData* shared_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000138};
139
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000140} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000141
142#endif // WEBRTC_VOICE_ENGINE_VOE_BASE_IMPL_H