niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
kma@webrtc.org | de66b91 | 2012-02-01 18:39:44 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 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.org | 956aa7e | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 14 | #include "webrtc/voice_engine/include/voe_base.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 15 | |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 16 | #include "webrtc/base/criticalsection.h" |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 17 | #include "webrtc/modules/include/module_common_types.h" |
pbos@webrtc.org | 956aa7e | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 18 | #include "webrtc/voice_engine/shared_data.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 19 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 20 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | |
| 22 | class ProcessThread; |
| 23 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 24 | class VoEBaseImpl : public VoEBase, |
| 25 | public AudioTransport, |
| 26 | public AudioDeviceObserver { |
| 27 | public: |
| 28 | int RegisterVoiceEngineObserver(VoiceEngineObserver& observer) override; |
| 29 | int DeRegisterVoiceEngineObserver() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 30 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 31 | int Init(AudioDeviceModule* external_adm = nullptr, |
ossu | 5f7cfa5 | 2016-05-30 08:11:28 -0700 | [diff] [blame^] | 32 | AudioProcessing* audioproc = nullptr, |
| 33 | const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory = |
| 34 | nullptr) override; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 35 | AudioProcessing* audio_processing() override { |
| 36 | return shared_->audio_processing(); |
| 37 | } |
solenberg | ff97631 | 2016-03-30 23:28:51 -0700 | [diff] [blame] | 38 | AudioDeviceModule* audio_device_module() override { |
| 39 | return shared_->audio_device(); |
| 40 | } |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 41 | int Terminate() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 42 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 43 | int CreateChannel() override; |
| 44 | int CreateChannel(const Config& config) override; |
| 45 | int DeleteChannel(int channel) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 46 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 47 | int StartReceive(int channel) override; |
| 48 | int StartPlayout(int channel) override; |
| 49 | int StartSend(int channel) override; |
| 50 | int StopReceive(int channel) override; |
| 51 | int StopPlayout(int channel) override; |
| 52 | int StopSend(int channel) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 53 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 54 | int GetVersion(char version[1024]) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 55 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 56 | int LastError() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 57 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 58 | AudioTransport* audio_transport() override { return this; } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 60 | int AssociateSendChannel(int channel, int accociate_send_channel) override; |
| 61 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 62 | // AudioTransport |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 63 | int32_t RecordedDataIsAvailable(const void* audioSamples, |
| 64 | const size_t nSamples, |
| 65 | const size_t nBytesPerSample, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 66 | const size_t nChannels, |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 67 | const uint32_t samplesPerSec, |
| 68 | const uint32_t totalDelayMS, |
| 69 | const int32_t clockDrift, |
| 70 | const uint32_t currentMicLevel, |
| 71 | const bool keyPressed, |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 72 | uint32_t& newMicLevel) override; |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 73 | int32_t NeedMorePlayData(const size_t nSamples, |
| 74 | const size_t nBytesPerSample, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 75 | const size_t nChannels, |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 76 | const uint32_t samplesPerSec, |
| 77 | void* audioSamples, |
| 78 | size_t& nSamplesOut, |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 79 | int64_t* elapsed_time_ms, |
| 80 | int64_t* ntp_time_ms) override; |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 81 | int OnDataAvailable(const int voe_channels[], |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 82 | size_t number_of_voe_channels, |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 83 | const int16_t* audio_data, |
| 84 | int sample_rate, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 85 | size_t number_of_channels, |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 86 | size_t number_of_frames, |
| 87 | int audio_delay_milliseconds, |
| 88 | int current_volume, |
| 89 | bool key_pressed, |
| 90 | bool need_audio_processing) override; |
| 91 | void OnData(int voe_channel, |
| 92 | const void* audio_data, |
| 93 | int bits_per_sample, |
| 94 | int sample_rate, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 95 | size_t number_of_channels, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 96 | size_t number_of_frames) override; |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 97 | void PushCaptureData(int voe_channel, |
| 98 | const void* audio_data, |
| 99 | int bits_per_sample, |
| 100 | int sample_rate, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 101 | size_t number_of_channels, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 102 | size_t number_of_frames) override; |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 103 | void PullRenderData(int bits_per_sample, |
| 104 | int sample_rate, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 105 | size_t number_of_channels, |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 106 | size_t number_of_frames, |
| 107 | void* audio_data, |
| 108 | int64_t* elapsed_time_ms, |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 109 | int64_t* ntp_time_ms) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 110 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 111 | // AudioDeviceObserver |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 112 | void OnErrorIsReported(const ErrorCode error) override; |
| 113 | void OnWarningIsReported(const WarningCode warning) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 114 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 115 | protected: |
| 116 | VoEBaseImpl(voe::SharedData* shared); |
| 117 | ~VoEBaseImpl() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 118 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 119 | private: |
| 120 | int32_t StartPlayout(); |
| 121 | int32_t StopPlayout(); |
| 122 | int32_t StartSend(); |
| 123 | int32_t StopSend(); |
| 124 | int32_t TerminateInternal(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 125 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 126 | // Helper function to process the recorded data with AudioProcessing Module, |
| 127 | // demultiplex the data to specific voe channels, encode and send to the |
| 128 | // network. When |number_of_VoE_channels| is 0, it will demultiplex the |
| 129 | // data to all the existing VoE channels. |
| 130 | // It returns new AGC microphone volume or 0 if no volume changes |
| 131 | // should be done. |
| 132 | int ProcessRecordedDataWithAPM( |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 133 | const int voe_channels[], size_t number_of_voe_channels, |
| 134 | const void* audio_data, uint32_t sample_rate, size_t number_of_channels, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 135 | size_t number_of_frames, uint32_t audio_delay_milliseconds, |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 136 | int32_t clock_drift, uint32_t volume, bool key_pressed); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 137 | |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 138 | void GetPlayoutData(int sample_rate, size_t number_of_channels, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 139 | size_t number_of_frames, bool feed_data_to_apm, |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 140 | void* audio_data, int64_t* elapsed_time_ms, |
| 141 | int64_t* ntp_time_ms); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 142 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 143 | // Initialize channel by setting Engine Information then initializing |
| 144 | // channel. |
| 145 | int InitializeChannel(voe::ChannelOwner* channel_owner); |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 146 | VoiceEngineObserver* voiceEngineObserverPtr_; |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 147 | rtc::CriticalSection callbackCritSect_; |
ossu | 5f7cfa5 | 2016-05-30 08:11:28 -0700 | [diff] [blame^] | 148 | rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 149 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 150 | AudioFrame audioFrame_; |
| 151 | voe::SharedData* shared_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 152 | }; |
| 153 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 154 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 155 | |
| 156 | #endif // WEBRTC_VOICE_ENGINE_VOE_BASE_IMPL_H |