blob: 9fc18ad6660c2a14f24b6bb9df5acf407bd0a0ba [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,
32 AudioProcessing* audioproc = nullptr) override;
33 AudioProcessing* audio_processing() override {
34 return shared_->audio_processing();
35 }
36 int Terminate() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000037
Jelena Marusic2dd6a272015-04-14 09:47:00 +020038 int CreateChannel() override;
39 int CreateChannel(const Config& config) override;
40 int DeleteChannel(int channel) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000041
Jelena Marusic2dd6a272015-04-14 09:47:00 +020042 int StartReceive(int channel) override;
43 int StartPlayout(int channel) override;
44 int StartSend(int channel) override;
45 int StopReceive(int channel) override;
46 int StopPlayout(int channel) override;
47 int StopSend(int channel) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000048
Jelena Marusic2dd6a272015-04-14 09:47:00 +020049 int GetVersion(char version[1024]) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000050
Jelena Marusic2dd6a272015-04-14 09:47:00 +020051 int LastError() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000052
Jelena Marusic2dd6a272015-04-14 09:47:00 +020053 AudioTransport* audio_transport() override { return this; }
niklase@google.com470e71d2011-07-07 08:21:25 +000054
Minyue2013aec2015-05-13 14:14:42 +020055 int AssociateSendChannel(int channel, int accociate_send_channel) override;
56
Jelena Marusic2dd6a272015-04-14 09:47:00 +020057 // AudioTransport
solenberg13725082015-11-25 08:16:52 -080058 int32_t RecordedDataIsAvailable(const void* audioSamples,
59 const size_t nSamples,
60 const size_t nBytesPerSample,
Peter Kasting69558702016-01-12 16:26:35 -080061 const size_t nChannels,
solenberg13725082015-11-25 08:16:52 -080062 const uint32_t samplesPerSec,
63 const uint32_t totalDelayMS,
64 const int32_t clockDrift,
65 const uint32_t currentMicLevel,
66 const bool keyPressed,
Jelena Marusic2dd6a272015-04-14 09:47:00 +020067 uint32_t& newMicLevel) override;
solenberg13725082015-11-25 08:16:52 -080068 int32_t NeedMorePlayData(const size_t nSamples,
69 const size_t nBytesPerSample,
Peter Kasting69558702016-01-12 16:26:35 -080070 const size_t nChannels,
solenberg13725082015-11-25 08:16:52 -080071 const uint32_t samplesPerSec,
72 void* audioSamples,
73 size_t& nSamplesOut,
Jelena Marusic2dd6a272015-04-14 09:47:00 +020074 int64_t* elapsed_time_ms,
75 int64_t* ntp_time_ms) override;
solenberg13725082015-11-25 08:16:52 -080076 int OnDataAvailable(const int voe_channels[],
Peter Kasting69558702016-01-12 16:26:35 -080077 size_t number_of_voe_channels,
solenberg13725082015-11-25 08:16:52 -080078 const int16_t* audio_data,
79 int sample_rate,
Peter Kasting69558702016-01-12 16:26:35 -080080 size_t number_of_channels,
solenberg13725082015-11-25 08:16:52 -080081 size_t number_of_frames,
82 int audio_delay_milliseconds,
83 int current_volume,
84 bool key_pressed,
85 bool need_audio_processing) override;
86 void OnData(int voe_channel,
87 const void* audio_data,
88 int bits_per_sample,
89 int sample_rate,
Peter Kasting69558702016-01-12 16:26:35 -080090 size_t number_of_channels,
Peter Kastingdce40cf2015-08-24 14:52:23 -070091 size_t number_of_frames) override;
solenberg13725082015-11-25 08:16:52 -080092 void PushCaptureData(int voe_channel,
93 const void* audio_data,
94 int bits_per_sample,
95 int sample_rate,
Peter Kasting69558702016-01-12 16:26:35 -080096 size_t number_of_channels,
Peter Kastingdce40cf2015-08-24 14:52:23 -070097 size_t number_of_frames) override;
solenberg13725082015-11-25 08:16:52 -080098 void PullRenderData(int bits_per_sample,
99 int sample_rate,
Peter Kasting69558702016-01-12 16:26:35 -0800100 size_t number_of_channels,
solenberg13725082015-11-25 08:16:52 -0800101 size_t number_of_frames,
102 void* audio_data,
103 int64_t* elapsed_time_ms,
Jelena Marusic2dd6a272015-04-14 09:47:00 +0200104 int64_t* ntp_time_ms) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000105
Jelena Marusic2dd6a272015-04-14 09:47:00 +0200106 // AudioDeviceObserver
solenberg13725082015-11-25 08:16:52 -0800107 void OnErrorIsReported(const ErrorCode error) override;
108 void OnWarningIsReported(const WarningCode warning) override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000109
Jelena Marusic2dd6a272015-04-14 09:47:00 +0200110 protected:
111 VoEBaseImpl(voe::SharedData* shared);
112 ~VoEBaseImpl() override;
niklase@google.com470e71d2011-07-07 08:21:25 +0000113
Jelena Marusic2dd6a272015-04-14 09:47:00 +0200114 private:
115 int32_t StartPlayout();
116 int32_t StopPlayout();
117 int32_t StartSend();
118 int32_t StopSend();
119 int32_t TerminateInternal();
niklase@google.com470e71d2011-07-07 08:21:25 +0000120
Jelena Marusic2dd6a272015-04-14 09:47:00 +0200121 // Helper function to process the recorded data with AudioProcessing Module,
122 // demultiplex the data to specific voe channels, encode and send to the
123 // network. When |number_of_VoE_channels| is 0, it will demultiplex the
124 // data to all the existing VoE channels.
125 // It returns new AGC microphone volume or 0 if no volume changes
126 // should be done.
127 int ProcessRecordedDataWithAPM(
Peter Kasting69558702016-01-12 16:26:35 -0800128 const int voe_channels[], size_t number_of_voe_channels,
129 const void* audio_data, uint32_t sample_rate, size_t number_of_channels,
Peter Kastingdce40cf2015-08-24 14:52:23 -0700130 size_t number_of_frames, uint32_t audio_delay_milliseconds,
Jelena Marusic2dd6a272015-04-14 09:47:00 +0200131 int32_t clock_drift, uint32_t volume, bool key_pressed);
niklase@google.com470e71d2011-07-07 08:21:25 +0000132
Peter Kasting69558702016-01-12 16:26:35 -0800133 void GetPlayoutData(int sample_rate, size_t number_of_channels,
Peter Kastingdce40cf2015-08-24 14:52:23 -0700134 size_t number_of_frames, bool feed_data_to_apm,
Jelena Marusic2dd6a272015-04-14 09:47:00 +0200135 void* audio_data, int64_t* elapsed_time_ms,
136 int64_t* ntp_time_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +0000137
Jelena Marusic2dd6a272015-04-14 09:47:00 +0200138 // Initialize channel by setting Engine Information then initializing
139 // channel.
140 int InitializeChannel(voe::ChannelOwner* channel_owner);
Jelena Marusic2dd6a272015-04-14 09:47:00 +0200141 VoiceEngineObserver* voiceEngineObserverPtr_;
tommi31fc21f2016-01-21 10:37:37 -0800142 rtc::CriticalSection callbackCritSect_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000143
Jelena Marusic2dd6a272015-04-14 09:47:00 +0200144 AudioFrame audioFrame_;
145 voe::SharedData* shared_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000146};
147
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000148} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000149
150#endif // WEBRTC_VOICE_ENGINE_VOE_BASE_IMPL_H