blob: 5cd0acdb729168a6d34e805ea51410ba0ad9c107 [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
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010016#include "webrtc/modules/include/module_common_types.h"
pbos@webrtc.org956aa7e2013-05-21 13:52:32 +000017#include "webrtc/voice_engine/shared_data.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000018
Jelena Marusic2dd6a272015-04-14 09:47:00 +020019namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000020
21class ProcessThread;
22
Jelena Marusic2dd6a272015-04-14 09:47:00 +020023class VoEBaseImpl : public VoEBase,
24 public AudioTransport,
25 public AudioDeviceObserver {
26 public:
27 int RegisterVoiceEngineObserver(VoiceEngineObserver& observer) override;
28 int DeRegisterVoiceEngineObserver() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000029
Jelena Marusic2dd6a272015-04-14 09:47:00 +020030 int Init(AudioDeviceModule* external_adm = nullptr,
31 AudioProcessing* audioproc = nullptr) override;
32 AudioProcessing* audio_processing() override {
33 return shared_->audio_processing();
34 }
35 int Terminate() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000036
Jelena Marusic2dd6a272015-04-14 09:47:00 +020037 int CreateChannel() override;
38 int CreateChannel(const Config& config) override;
39 int DeleteChannel(int channel) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000040
Jelena Marusic2dd6a272015-04-14 09:47:00 +020041 int StartReceive(int channel) override;
42 int StartPlayout(int channel) override;
43 int StartSend(int channel) override;
44 int StopReceive(int channel) override;
45 int StopPlayout(int channel) override;
46 int StopSend(int channel) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000047
Jelena Marusic2dd6a272015-04-14 09:47:00 +020048 int GetVersion(char version[1024]) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000049
Jelena Marusic2dd6a272015-04-14 09:47:00 +020050 int LastError() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000051
Jelena Marusic2dd6a272015-04-14 09:47:00 +020052 AudioTransport* audio_transport() override { return this; }
niklase@google.com470e71d2011-07-07 08:21:25 +000053
Minyue2013aec2015-05-13 14:14:42 +020054 int AssociateSendChannel(int channel, int accociate_send_channel) override;
55
Jelena Marusic2dd6a272015-04-14 09:47:00 +020056 // AudioTransport
Peter Kastingdce40cf2015-08-24 14:52:23 -070057 int32_t RecordedDataIsAvailable(const void* audioSamples, size_t nSamples,
58 size_t nBytesPerSample, uint8_t nChannels,
Jelena Marusic2dd6a272015-04-14 09:47:00 +020059 uint32_t samplesPerSec, uint32_t totalDelayMS,
60 int32_t clockDrift, uint32_t micLevel,
61 bool keyPressed,
62 uint32_t& newMicLevel) override;
Peter Kastingdce40cf2015-08-24 14:52:23 -070063 int32_t NeedMorePlayData(size_t nSamples, size_t nBytesPerSample,
Jelena Marusic2dd6a272015-04-14 09:47:00 +020064 uint8_t nChannels, uint32_t samplesPerSec,
Peter Kastingdce40cf2015-08-24 14:52:23 -070065 void* audioSamples, size_t& nSamplesOut,
Jelena Marusic2dd6a272015-04-14 09:47:00 +020066 int64_t* elapsed_time_ms,
67 int64_t* ntp_time_ms) override;
68 int OnDataAvailable(const int voe_channels[], int number_of_voe_channels,
69 const int16_t* audio_data, int sample_rate,
Peter Kastingdce40cf2015-08-24 14:52:23 -070070 int number_of_channels, size_t number_of_frames,
Jelena Marusic2dd6a272015-04-14 09:47:00 +020071 int audio_delay_milliseconds, int volume,
72 bool key_pressed, bool need_audio_processing) override;
73 void OnData(int voe_channel, const void* audio_data, int bits_per_sample,
74 int sample_rate, int number_of_channels,
Peter Kastingdce40cf2015-08-24 14:52:23 -070075 size_t number_of_frames) override;
Jelena Marusic2dd6a272015-04-14 09:47:00 +020076 void PushCaptureData(int voe_channel, const void* audio_data,
77 int bits_per_sample, int sample_rate,
Peter Kastingdce40cf2015-08-24 14:52:23 -070078 int number_of_channels,
79 size_t number_of_frames) override;
Jelena Marusic2dd6a272015-04-14 09:47:00 +020080 void PullRenderData(int bits_per_sample, int sample_rate,
Peter Kastingdce40cf2015-08-24 14:52:23 -070081 int number_of_channels, size_t number_of_frames,
Jelena Marusic2dd6a272015-04-14 09:47:00 +020082 void* audio_data, int64_t* elapsed_time_ms,
83 int64_t* ntp_time_ms) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000084
Jelena Marusic2dd6a272015-04-14 09:47:00 +020085 // AudioDeviceObserver
86 void OnErrorIsReported(ErrorCode error) override;
87 void OnWarningIsReported(WarningCode warning) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000088
Jelena Marusic2dd6a272015-04-14 09:47:00 +020089 protected:
90 VoEBaseImpl(voe::SharedData* shared);
91 ~VoEBaseImpl() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000092
Jelena Marusic2dd6a272015-04-14 09:47:00 +020093 private:
94 int32_t StartPlayout();
95 int32_t StopPlayout();
96 int32_t StartSend();
97 int32_t StopSend();
98 int32_t TerminateInternal();
niklase@google.com470e71d2011-07-07 08:21:25 +000099
Jelena Marusic2dd6a272015-04-14 09:47:00 +0200100 // Helper function to process the recorded data with AudioProcessing Module,
101 // demultiplex the data to specific voe channels, encode and send to the
102 // network. When |number_of_VoE_channels| is 0, it will demultiplex the
103 // data to all the existing VoE channels.
104 // It returns new AGC microphone volume or 0 if no volume changes
105 // should be done.
106 int ProcessRecordedDataWithAPM(
107 const int voe_channels[], int number_of_voe_channels,
108 const void* audio_data, uint32_t sample_rate, uint8_t number_of_channels,
Peter Kastingdce40cf2015-08-24 14:52:23 -0700109 size_t number_of_frames, uint32_t audio_delay_milliseconds,
Jelena Marusic2dd6a272015-04-14 09:47:00 +0200110 int32_t clock_drift, uint32_t volume, bool key_pressed);
niklase@google.com470e71d2011-07-07 08:21:25 +0000111
Jelena Marusic2dd6a272015-04-14 09:47:00 +0200112 void GetPlayoutData(int sample_rate, int number_of_channels,
Peter Kastingdce40cf2015-08-24 14:52:23 -0700113 size_t number_of_frames, bool feed_data_to_apm,
Jelena Marusic2dd6a272015-04-14 09:47:00 +0200114 void* audio_data, int64_t* elapsed_time_ms,
115 int64_t* ntp_time_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +0000116
Jelena Marusic2dd6a272015-04-14 09:47:00 +0200117 int32_t AddVoEVersion(char* str) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000118
Jelena Marusic2dd6a272015-04-14 09:47:00 +0200119 // Initialize channel by setting Engine Information then initializing
120 // channel.
121 int InitializeChannel(voe::ChannelOwner* channel_owner);
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000122#ifdef WEBRTC_EXTERNAL_TRANSPORT
Jelena Marusic2dd6a272015-04-14 09:47:00 +0200123 int32_t AddExternalTransportBuild(char* str) const;
pwestin@webrtc.org684f0572013-03-13 23:20:57 +0000124#endif
Jelena Marusic2dd6a272015-04-14 09:47:00 +0200125 VoiceEngineObserver* voiceEngineObserverPtr_;
126 CriticalSectionWrapper& callbackCritSect_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000127
Jelena Marusic2dd6a272015-04-14 09:47:00 +0200128 AudioFrame audioFrame_;
129 voe::SharedData* shared_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000130};
131
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000132} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000133
134#endif // WEBRTC_VOICE_ENGINE_VOE_BASE_IMPL_H