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 | |
| 19 | namespace webrtc |
| 20 | { |
| 21 | |
| 22 | class ProcessThread; |
| 23 | |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 24 | class VoEBaseImpl: public VoEBase, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | public AudioTransport, |
| 26 | public AudioDeviceObserver |
| 27 | { |
| 28 | public: |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 29 | virtual int RegisterVoiceEngineObserver(VoiceEngineObserver& observer); |
| 30 | |
| 31 | virtual int DeRegisterVoiceEngineObserver(); |
| 32 | |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 33 | virtual int Init(AudioDeviceModule* external_adm = NULL, |
| 34 | AudioProcessing* audioproc = NULL); |
| 35 | virtual AudioProcessing* audio_processing() { |
| 36 | return _shared->audio_processing(); |
| 37 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 38 | |
| 39 | virtual int Terminate(); |
| 40 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 41 | virtual int CreateChannel(); |
turaj@webrtc.org | 03f3370 | 2013-11-13 00:02:48 +0000 | [diff] [blame] | 42 | virtual int CreateChannel(const Config& config); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | |
| 44 | virtual int DeleteChannel(int channel); |
| 45 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 46 | virtual int StartReceive(int channel); |
| 47 | |
| 48 | virtual int StartPlayout(int channel); |
| 49 | |
| 50 | virtual int StartSend(int channel); |
| 51 | |
| 52 | virtual int StopReceive(int channel); |
| 53 | |
| 54 | virtual int StopPlayout(int channel); |
| 55 | |
| 56 | virtual int StopSend(int channel); |
| 57 | |
| 58 | virtual int SetNetEQPlayoutMode(int channel, NetEqModes mode); |
| 59 | |
| 60 | virtual int GetNetEQPlayoutMode(int channel, NetEqModes& mode); |
| 61 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 62 | virtual int SetOnHoldStatus(int channel, |
| 63 | bool enable, |
| 64 | OnHoldModes mode = kHoldSendAndPlay); |
| 65 | |
| 66 | virtual int GetOnHoldStatus(int channel, bool& enabled, OnHoldModes& mode); |
| 67 | |
| 68 | virtual int GetVersion(char version[1024]); |
| 69 | |
| 70 | virtual int LastError(); |
| 71 | |
xians@webrtc.org | c1e2803 | 2014-02-02 15:30:20 +0000 | [diff] [blame] | 72 | virtual AudioTransport* audio_transport() { return this; } |
xians@webrtc.org | 07e5196 | 2014-01-29 13:54:02 +0000 | [diff] [blame] | 73 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 74 | // AudioTransport |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 75 | virtual int32_t |
henrika@webrtc.org | 907bc55 | 2012-03-09 08:59:19 +0000 | [diff] [blame] | 76 | RecordedDataIsAvailable(const void* audioSamples, |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 77 | uint32_t nSamples, |
| 78 | uint8_t nBytesPerSample, |
| 79 | uint8_t nChannels, |
| 80 | uint32_t samplesPerSec, |
| 81 | uint32_t totalDelayMS, |
| 82 | int32_t clockDrift, |
andrew@webrtc.org | 27c6980 | 2014-02-18 20:24:56 +0000 | [diff] [blame^] | 83 | uint32_t micLevel, |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 84 | bool keyPressed, |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 85 | uint32_t& newMicLevel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 86 | |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 87 | virtual int32_t NeedMorePlayData(uint32_t nSamples, |
| 88 | uint8_t nBytesPerSample, |
| 89 | uint8_t nChannels, |
| 90 | uint32_t samplesPerSec, |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 91 | void* audioSamples, |
| 92 | uint32_t& nSamplesOut); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 93 | |
xians@webrtc.org | 8fff1f0 | 2013-07-31 16:27:42 +0000 | [diff] [blame] | 94 | virtual int OnDataAvailable(const int voe_channels[], |
xians@webrtc.org | 2f84afa | 2013-07-31 16:23:37 +0000 | [diff] [blame] | 95 | int number_of_voe_channels, |
| 96 | const int16_t* audio_data, |
| 97 | int sample_rate, |
| 98 | int number_of_channels, |
| 99 | int number_of_frames, |
| 100 | int audio_delay_milliseconds, |
andrew@webrtc.org | 27c6980 | 2014-02-18 20:24:56 +0000 | [diff] [blame^] | 101 | int volume, |
xians@webrtc.org | 2f84afa | 2013-07-31 16:23:37 +0000 | [diff] [blame] | 102 | bool key_pressed, |
| 103 | bool need_audio_processing); |
| 104 | |
xians@webrtc.org | c1e2803 | 2014-02-02 15:30:20 +0000 | [diff] [blame] | 105 | virtual void OnData(int voe_channel, const void* audio_data, |
| 106 | int bits_per_sample, int sample_rate, |
| 107 | int number_of_channels, int number_of_frames); |
| 108 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 109 | // AudioDeviceObserver |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 110 | virtual void OnErrorIsReported(ErrorCode error); |
| 111 | virtual void OnWarningIsReported(WarningCode warning); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 112 | |
| 113 | protected: |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 114 | VoEBaseImpl(voe::SharedData* shared); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 115 | virtual ~VoEBaseImpl(); |
| 116 | |
| 117 | private: |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 118 | int32_t StartPlayout(); |
| 119 | int32_t StopPlayout(); |
| 120 | int32_t StartSend(); |
| 121 | int32_t StopSend(); |
| 122 | int32_t TerminateInternal(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 123 | |
xians@webrtc.org | 8fff1f0 | 2013-07-31 16:27:42 +0000 | [diff] [blame] | 124 | // Helper function to process the recorded data with AudioProcessing Module, |
| 125 | // demultiplex the data to specific voe channels, encode and send to the |
| 126 | // network. When |number_of_VoE_channels| is 0, it will demultiplex the |
| 127 | // data to all the existing VoE channels. |
| 128 | // It returns new AGC microphone volume or 0 if no volume changes |
| 129 | // should be done. |
| 130 | int ProcessRecordedDataWithAPM(const int voe_channels[], |
| 131 | int number_of_voe_channels, |
| 132 | const void* audio_data, |
| 133 | uint32_t sample_rate, |
| 134 | uint8_t number_of_channels, |
| 135 | uint32_t number_of_frames, |
| 136 | uint32_t audio_delay_milliseconds, |
| 137 | int32_t clock_drift, |
andrew@webrtc.org | 27c6980 | 2014-02-18 20:24:56 +0000 | [diff] [blame^] | 138 | uint32_t volume, |
xians@webrtc.org | 8fff1f0 | 2013-07-31 16:27:42 +0000 | [diff] [blame] | 139 | bool key_pressed); |
| 140 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 141 | int32_t AddBuildInfo(char* str) const; |
| 142 | int32_t AddVoEVersion(char* str) const; |
turaj@webrtc.org | 03f3370 | 2013-11-13 00:02:48 +0000 | [diff] [blame] | 143 | |
| 144 | // Initialize channel by setting Engine Information then initializing |
| 145 | // channel. |
| 146 | int InitializeChannel(voe::ChannelOwner* channel_owner); |
pwestin@webrtc.org | 684f057 | 2013-03-13 23:20:57 +0000 | [diff] [blame] | 147 | #ifdef WEBRTC_EXTERNAL_TRANSPORT |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 148 | int32_t AddExternalTransportBuild(char* str) const; |
pwestin@webrtc.org | 684f057 | 2013-03-13 23:20:57 +0000 | [diff] [blame] | 149 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 150 | #ifdef WEBRTC_VOE_EXTERNAL_REC_AND_PLAYOUT |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 151 | int32_t AddExternalRecAndPlayoutBuild(char* str) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 152 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 153 | VoiceEngineObserver* _voiceEngineObserverPtr; |
| 154 | CriticalSectionWrapper& _callbackCritSect; |
| 155 | |
| 156 | bool _voiceEngineObserver; |
kma@webrtc.org | de66b91 | 2012-02-01 18:39:44 +0000 | [diff] [blame] | 157 | AudioFrame _audioFrame; |
tommi@webrtc.org | 851becd | 2012-04-04 14:57:19 +0000 | [diff] [blame] | 158 | voe::SharedData* _shared; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 159 | }; |
| 160 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 161 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 162 | |
| 163 | #endif // WEBRTC_VOICE_ENGINE_VOE_BASE_IMPL_H |