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 | |
pbos@webrtc.org | 956aa7e | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 16 | #include "webrtc/modules/interface/module_common_types.h" |
| 17 | #include "webrtc/voice_engine/shared_data.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 18 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame^] | 19 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | |
| 21 | class ProcessThread; |
| 22 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame^] | 23 | class VoEBaseImpl : public VoEBase, |
| 24 | public AudioTransport, |
| 25 | public AudioDeviceObserver { |
| 26 | public: |
| 27 | int RegisterVoiceEngineObserver(VoiceEngineObserver& observer) override; |
| 28 | int DeRegisterVoiceEngineObserver() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 29 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame^] | 30 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 36 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame^] | 37 | int CreateChannel() override; |
| 38 | int CreateChannel(const Config& config) override; |
| 39 | int DeleteChannel(int channel) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame^] | 41 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 47 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame^] | 48 | int GetVersion(char version[1024]) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 49 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame^] | 50 | int LastError() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame^] | 52 | AudioTransport* audio_transport() override { return this; } |
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 | // AudioTransport |
| 55 | int32_t RecordedDataIsAvailable(const void* audioSamples, uint32_t nSamples, |
| 56 | uint8_t nBytesPerSample, uint8_t nChannels, |
| 57 | uint32_t samplesPerSec, uint32_t totalDelayMS, |
| 58 | int32_t clockDrift, uint32_t micLevel, |
| 59 | bool keyPressed, |
| 60 | uint32_t& newMicLevel) override; |
| 61 | int32_t NeedMorePlayData(uint32_t nSamples, uint8_t nBytesPerSample, |
| 62 | uint8_t nChannels, uint32_t samplesPerSec, |
| 63 | void* audioSamples, uint32_t& nSamplesOut, |
| 64 | int64_t* elapsed_time_ms, |
| 65 | int64_t* ntp_time_ms) override; |
| 66 | int OnDataAvailable(const int voe_channels[], int number_of_voe_channels, |
| 67 | const int16_t* audio_data, int sample_rate, |
| 68 | int number_of_channels, int number_of_frames, |
| 69 | int audio_delay_milliseconds, int volume, |
| 70 | bool key_pressed, bool need_audio_processing) override; |
| 71 | void OnData(int voe_channel, const void* audio_data, int bits_per_sample, |
| 72 | int sample_rate, int number_of_channels, |
| 73 | int number_of_frames) override; |
| 74 | void PushCaptureData(int voe_channel, const void* audio_data, |
| 75 | int bits_per_sample, int sample_rate, |
| 76 | int number_of_channels, int number_of_frames) override; |
| 77 | void PullRenderData(int bits_per_sample, int sample_rate, |
| 78 | int number_of_channels, int number_of_frames, |
| 79 | void* audio_data, int64_t* elapsed_time_ms, |
| 80 | int64_t* ntp_time_ms) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 81 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame^] | 82 | // AudioDeviceObserver |
| 83 | void OnErrorIsReported(ErrorCode error) override; |
| 84 | void OnWarningIsReported(WarningCode warning) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 85 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame^] | 86 | protected: |
| 87 | VoEBaseImpl(voe::SharedData* shared); |
| 88 | ~VoEBaseImpl() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame^] | 90 | private: |
| 91 | int32_t StartPlayout(); |
| 92 | int32_t StopPlayout(); |
| 93 | int32_t StartSend(); |
| 94 | int32_t StopSend(); |
| 95 | int32_t TerminateInternal(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 96 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame^] | 97 | // Helper function to process the recorded data with AudioProcessing Module, |
| 98 | // demultiplex the data to specific voe channels, encode and send to the |
| 99 | // network. When |number_of_VoE_channels| is 0, it will demultiplex the |
| 100 | // data to all the existing VoE channels. |
| 101 | // It returns new AGC microphone volume or 0 if no volume changes |
| 102 | // should be done. |
| 103 | int ProcessRecordedDataWithAPM( |
| 104 | const int voe_channels[], int number_of_voe_channels, |
| 105 | const void* audio_data, uint32_t sample_rate, uint8_t number_of_channels, |
| 106 | uint32_t number_of_frames, uint32_t audio_delay_milliseconds, |
| 107 | int32_t clock_drift, uint32_t volume, bool key_pressed); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 108 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame^] | 109 | void GetPlayoutData(int sample_rate, int number_of_channels, |
| 110 | int number_of_frames, bool feed_data_to_apm, |
| 111 | void* audio_data, int64_t* elapsed_time_ms, |
| 112 | int64_t* ntp_time_ms); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 113 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame^] | 114 | int32_t AddVoEVersion(char* str) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 115 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame^] | 116 | // Initialize channel by setting Engine Information then initializing |
| 117 | // channel. |
| 118 | int InitializeChannel(voe::ChannelOwner* channel_owner); |
pwestin@webrtc.org | 684f057 | 2013-03-13 23:20:57 +0000 | [diff] [blame] | 119 | #ifdef WEBRTC_EXTERNAL_TRANSPORT |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame^] | 120 | int32_t AddExternalTransportBuild(char* str) const; |
pwestin@webrtc.org | 684f057 | 2013-03-13 23:20:57 +0000 | [diff] [blame] | 121 | #endif |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame^] | 122 | VoiceEngineObserver* voiceEngineObserverPtr_; |
| 123 | CriticalSectionWrapper& callbackCritSect_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 124 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame^] | 125 | AudioFrame audioFrame_; |
| 126 | voe::SharedData* shared_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 127 | }; |
| 128 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 129 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 130 | |
| 131 | #endif // WEBRTC_VOICE_ENGINE_VOE_BASE_IMPL_H |