niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
xians@webrtc.org | 79af734 | 2012-01-31 12:22:14 +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 | |
pbos@webrtc.org | 956aa7e | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 11 | #include "webrtc/voice_engine/voe_base_impl.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 13 | #include "webrtc/base/format_macros.h" |
turaj@webrtc.org | 03f3370 | 2013-11-13 00:02:48 +0000 | [diff] [blame] | 14 | #include "webrtc/common.h" |
pbos@webrtc.org | 956aa7e | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 15 | #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" |
| 16 | #include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h" |
| 17 | #include "webrtc/modules/audio_device/audio_device_impl.h" |
| 18 | #include "webrtc/modules/audio_processing/include/audio_processing.h" |
| 19 | #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
| 20 | #include "webrtc/system_wrappers/interface/file_wrapper.h" |
Jelena Marusic | 9e5e421 | 2015-04-13 13:41:56 +0200 | [diff] [blame] | 21 | #include "webrtc/system_wrappers/interface/logging.h" |
pbos@webrtc.org | 956aa7e | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 22 | #include "webrtc/voice_engine/channel.h" |
| 23 | #include "webrtc/voice_engine/include/voe_errors.h" |
| 24 | #include "webrtc/voice_engine/output_mixer.h" |
| 25 | #include "webrtc/voice_engine/transmit_mixer.h" |
| 26 | #include "webrtc/voice_engine/utility.h" |
| 27 | #include "webrtc/voice_engine/voice_engine_impl.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 28 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 29 | namespace webrtc { |
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 | VoEBase* VoEBase::GetInterface(VoiceEngine* voiceEngine) { |
| 32 | if (nullptr == voiceEngine) { |
| 33 | return nullptr; |
| 34 | } |
| 35 | VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine); |
| 36 | s->AddRef(); |
| 37 | return s; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 40 | VoEBaseImpl::VoEBaseImpl(voe::SharedData* shared) |
| 41 | : voiceEngineObserverPtr_(nullptr), |
| 42 | callbackCritSect_(*CriticalSectionWrapper::CreateCriticalSection()), |
| 43 | shared_(shared) {} |
| 44 | |
| 45 | VoEBaseImpl::~VoEBaseImpl() { |
| 46 | TerminateInternal(); |
| 47 | delete &callbackCritSect_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 50 | void VoEBaseImpl::OnErrorIsReported(ErrorCode error) { |
| 51 | CriticalSectionScoped cs(&callbackCritSect_); |
| 52 | int errCode = 0; |
| 53 | if (error == AudioDeviceObserver::kRecordingError) { |
| 54 | errCode = VE_RUNTIME_REC_ERROR; |
| 55 | LOG_F(LS_ERROR) << "VE_RUNTIME_REC_ERROR"; |
| 56 | } else if (error == AudioDeviceObserver::kPlayoutError) { |
| 57 | errCode = VE_RUNTIME_PLAY_ERROR; |
| 58 | LOG_F(LS_ERROR) << "VE_RUNTIME_PLAY_ERROR"; |
| 59 | } |
| 60 | if (voiceEngineObserverPtr_) { |
| 61 | // Deliver callback (-1 <=> no channel dependency) |
| 62 | voiceEngineObserverPtr_->CallbackOnError(-1, errCode); |
| 63 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 66 | void VoEBaseImpl::OnWarningIsReported(WarningCode warning) { |
| 67 | CriticalSectionScoped cs(&callbackCritSect_); |
| 68 | int warningCode = 0; |
| 69 | if (warning == AudioDeviceObserver::kRecordingWarning) { |
| 70 | warningCode = VE_RUNTIME_REC_WARNING; |
| 71 | LOG_F(LS_WARNING) << "VE_RUNTIME_REC_WARNING"; |
| 72 | } else if (warning == AudioDeviceObserver::kPlayoutWarning) { |
| 73 | warningCode = VE_RUNTIME_PLAY_WARNING; |
| 74 | LOG_F(LS_WARNING) << "VE_RUNTIME_PLAY_WARNING"; |
| 75 | } |
| 76 | if (voiceEngineObserverPtr_) { |
| 77 | // Deliver callback (-1 <=> no channel dependency) |
| 78 | voiceEngineObserverPtr_->CallbackOnError(-1, warningCode); |
| 79 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | } |
| 81 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 82 | int32_t VoEBaseImpl::RecordedDataIsAvailable( |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 83 | const void* audioSamples, size_t nSamples, size_t nBytesPerSample, |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 84 | uint8_t nChannels, uint32_t samplesPerSec, uint32_t totalDelayMS, |
| 85 | int32_t clockDrift, uint32_t micLevel, bool keyPressed, |
| 86 | uint32_t& newMicLevel) { |
| 87 | newMicLevel = static_cast<uint32_t>(ProcessRecordedDataWithAPM( |
| 88 | nullptr, 0, audioSamples, samplesPerSec, nChannels, nSamples, |
| 89 | totalDelayMS, clockDrift, micLevel, keyPressed)); |
| 90 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 93 | int32_t VoEBaseImpl::NeedMorePlayData(size_t nSamples, |
| 94 | size_t nBytesPerSample, |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 95 | uint8_t nChannels, uint32_t samplesPerSec, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 96 | void* audioSamples, size_t& nSamplesOut, |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 97 | int64_t* elapsed_time_ms, |
| 98 | int64_t* ntp_time_ms) { |
| 99 | GetPlayoutData(static_cast<int>(samplesPerSec), static_cast<int>(nChannels), |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 100 | nSamples, true, audioSamples, |
wu@webrtc.org | 94454b7 | 2014-06-05 20:34:08 +0000 | [diff] [blame] | 101 | elapsed_time_ms, ntp_time_ms); |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 102 | nSamplesOut = audioFrame_.samples_per_channel_; |
xians@webrtc.org | 5692531 | 2014-04-14 10:50:37 +0000 | [diff] [blame] | 103 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 104 | } |
| 105 | |
xians@webrtc.org | 8fff1f0 | 2013-07-31 16:27:42 +0000 | [diff] [blame] | 106 | int VoEBaseImpl::OnDataAvailable(const int voe_channels[], |
xians@webrtc.org | 2f84afa | 2013-07-31 16:23:37 +0000 | [diff] [blame] | 107 | int number_of_voe_channels, |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 108 | const int16_t* audio_data, int sample_rate, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 109 | int number_of_channels, |
| 110 | size_t number_of_frames, |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 111 | int audio_delay_milliseconds, int volume, |
| 112 | bool key_pressed, bool need_audio_processing) { |
| 113 | if (number_of_voe_channels == 0) return 0; |
xians@webrtc.org | 2f84afa | 2013-07-31 16:23:37 +0000 | [diff] [blame] | 114 | |
| 115 | if (need_audio_processing) { |
xians@webrtc.org | 8fff1f0 | 2013-07-31 16:27:42 +0000 | [diff] [blame] | 116 | return ProcessRecordedDataWithAPM( |
| 117 | voe_channels, number_of_voe_channels, audio_data, sample_rate, |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 118 | number_of_channels, number_of_frames, audio_delay_milliseconds, 0, |
| 119 | volume, key_pressed); |
xians@webrtc.org | 2f84afa | 2013-07-31 16:23:37 +0000 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | // No need to go through the APM, demultiplex the data to each VoE channel, |
| 123 | // encode and send to the network. |
| 124 | for (int i = 0; i < number_of_voe_channels; ++i) { |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 125 | // TODO(ajm): In the case where multiple channels are using the same codec |
| 126 | // rate, this path needlessly does extra conversions. We should convert once |
| 127 | // and share between channels. |
xians@webrtc.org | 5692531 | 2014-04-14 10:50:37 +0000 | [diff] [blame] | 128 | PushCaptureData(voe_channels[i], audio_data, 16, sample_rate, |
| 129 | number_of_channels, number_of_frames); |
xians@webrtc.org | 2f84afa | 2013-07-31 16:23:37 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | // Return 0 to indicate no need to change the volume. |
| 133 | return 0; |
| 134 | } |
| 135 | |
xians@webrtc.org | c1e2803 | 2014-02-02 15:30:20 +0000 | [diff] [blame] | 136 | void VoEBaseImpl::OnData(int voe_channel, const void* audio_data, |
| 137 | int bits_per_sample, int sample_rate, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 138 | int number_of_channels, size_t number_of_frames) { |
xians@webrtc.org | 5692531 | 2014-04-14 10:50:37 +0000 | [diff] [blame] | 139 | PushCaptureData(voe_channel, audio_data, bits_per_sample, sample_rate, |
| 140 | number_of_channels, number_of_frames); |
| 141 | } |
| 142 | |
| 143 | void VoEBaseImpl::PushCaptureData(int voe_channel, const void* audio_data, |
| 144 | int bits_per_sample, int sample_rate, |
| 145 | int number_of_channels, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 146 | size_t number_of_frames) { |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 147 | voe::ChannelOwner ch = shared_->channel_manager().GetChannel(voe_channel); |
xians@webrtc.org | 07e5196 | 2014-01-29 13:54:02 +0000 | [diff] [blame] | 148 | voe::Channel* channel_ptr = ch.channel(); |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 149 | if (!channel_ptr) return; |
xians@webrtc.org | 07e5196 | 2014-01-29 13:54:02 +0000 | [diff] [blame] | 150 | |
henrika@webrtc.org | 6680348 | 2014-04-17 10:45:01 +0000 | [diff] [blame] | 151 | if (channel_ptr->Sending()) { |
xians@webrtc.org | 07e5196 | 2014-01-29 13:54:02 +0000 | [diff] [blame] | 152 | channel_ptr->Demultiplex(static_cast<const int16_t*>(audio_data), |
| 153 | sample_rate, number_of_frames, number_of_channels); |
| 154 | channel_ptr->PrepareEncodeAndSend(sample_rate); |
| 155 | channel_ptr->EncodeAndSend(); |
| 156 | } |
| 157 | } |
| 158 | |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 159 | void VoEBaseImpl::PullRenderData(int bits_per_sample, |
| 160 | int sample_rate, |
| 161 | int number_of_channels, |
| 162 | size_t number_of_frames, |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 163 | void* audio_data, int64_t* elapsed_time_ms, |
wu@webrtc.org | cb711f7 | 2014-05-19 17:39:11 +0000 | [diff] [blame] | 164 | int64_t* ntp_time_ms) { |
Jelena Marusic | 6fc2d2f | 2015-04-13 14:07:04 +0200 | [diff] [blame] | 165 | assert(bits_per_sample == 16); |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 166 | assert(number_of_frames == static_cast<size_t>(sample_rate / 100)); |
xians@webrtc.org | 5692531 | 2014-04-14 10:50:37 +0000 | [diff] [blame] | 167 | |
| 168 | GetPlayoutData(sample_rate, number_of_channels, number_of_frames, false, |
wu@webrtc.org | 94454b7 | 2014-06-05 20:34:08 +0000 | [diff] [blame] | 169 | audio_data, elapsed_time_ms, ntp_time_ms); |
xians@webrtc.org | 5692531 | 2014-04-14 10:50:37 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 172 | int VoEBaseImpl::RegisterVoiceEngineObserver(VoiceEngineObserver& observer) { |
| 173 | CriticalSectionScoped cs(&callbackCritSect_); |
| 174 | if (voiceEngineObserverPtr_) { |
| 175 | shared_->SetLastError( |
| 176 | VE_INVALID_OPERATION, kTraceError, |
| 177 | "RegisterVoiceEngineObserver() observer already enabled"); |
| 178 | return -1; |
| 179 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 180 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 181 | // Register the observer in all active channels |
| 182 | for (voe::ChannelManager::Iterator it(&shared_->channel_manager()); |
| 183 | it.IsValid(); it.Increment()) { |
| 184 | it.GetChannel()->RegisterVoiceEngineObserver(observer); |
| 185 | } |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 186 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 187 | shared_->transmit_mixer()->RegisterVoiceEngineObserver(observer); |
| 188 | voiceEngineObserverPtr_ = &observer; |
| 189 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 190 | } |
| 191 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 192 | int VoEBaseImpl::DeRegisterVoiceEngineObserver() { |
| 193 | CriticalSectionScoped cs(&callbackCritSect_); |
| 194 | if (!voiceEngineObserverPtr_) { |
| 195 | shared_->SetLastError( |
| 196 | VE_INVALID_OPERATION, kTraceError, |
| 197 | "DeRegisterVoiceEngineObserver() observer already disabled"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 198 | return 0; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 199 | } |
| 200 | voiceEngineObserverPtr_ = nullptr; |
| 201 | |
| 202 | // Deregister the observer in all active channels |
| 203 | for (voe::ChannelManager::Iterator it(&shared_->channel_manager()); |
| 204 | it.IsValid(); it.Increment()) { |
| 205 | it.GetChannel()->DeRegisterVoiceEngineObserver(); |
| 206 | } |
| 207 | |
| 208 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 209 | } |
| 210 | |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 211 | int VoEBaseImpl::Init(AudioDeviceModule* external_adm, |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 212 | AudioProcessing* audioproc) { |
| 213 | CriticalSectionScoped cs(shared_->crit_sec()); |
| 214 | WebRtcSpl_Init(); |
| 215 | if (shared_->statistics().Initialized()) { |
| 216 | return 0; |
| 217 | } |
| 218 | if (shared_->process_thread()) { |
| 219 | shared_->process_thread()->Start(); |
| 220 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 221 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 222 | // Create an internal ADM if the user has not added an external |
| 223 | // ADM implementation as input to Init(). |
| 224 | if (external_adm == nullptr) { |
Tommi | 931e658 | 2015-05-20 09:44:38 +0200 | [diff] [blame] | 225 | #if !defined(WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE) |
| 226 | return -1; |
| 227 | #else |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 228 | // Create the internal ADM implementation. |
| 229 | shared_->set_audio_device(AudioDeviceModuleImpl::Create( |
| 230 | VoEId(shared_->instance_id(), -1), shared_->audio_device_layer())); |
kma@webrtc.org | 0221b78 | 2012-09-08 00:09:26 +0000 | [diff] [blame] | 231 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 232 | if (shared_->audio_device() == nullptr) { |
| 233 | shared_->SetLastError(VE_NO_MEMORY, kTraceCritical, |
| 234 | "Init() failed to create the ADM"); |
| 235 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 236 | } |
Tommi | 931e658 | 2015-05-20 09:44:38 +0200 | [diff] [blame] | 237 | #endif // WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 238 | } else { |
| 239 | // Use the already existing external ADM implementation. |
| 240 | shared_->set_audio_device(external_adm); |
| 241 | LOG_F(LS_INFO) |
| 242 | << "An external ADM implementation will be used in VoiceEngine"; |
| 243 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 244 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 245 | // Register the ADM to the process thread, which will drive the error |
| 246 | // callback mechanism |
| 247 | if (shared_->process_thread()) { |
| 248 | shared_->process_thread()->RegisterModule(shared_->audio_device()); |
| 249 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 250 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 251 | bool available = false; |
andrew@webrtc.org | f458916 | 2011-10-03 15:22:28 +0000 | [diff] [blame] | 252 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 253 | // -------------------- |
| 254 | // Reinitialize the ADM |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 255 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 256 | // Register the AudioObserver implementation |
| 257 | if (shared_->audio_device()->RegisterEventObserver(this) != 0) { |
| 258 | shared_->SetLastError( |
| 259 | VE_AUDIO_DEVICE_MODULE_ERROR, kTraceWarning, |
| 260 | "Init() failed to register event observer for the ADM"); |
| 261 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 262 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 263 | // Register the AudioTransport implementation |
| 264 | if (shared_->audio_device()->RegisterAudioCallback(this) != 0) { |
| 265 | shared_->SetLastError( |
| 266 | VE_AUDIO_DEVICE_MODULE_ERROR, kTraceWarning, |
| 267 | "Init() failed to register audio callback for the ADM"); |
| 268 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 269 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 270 | // ADM initialization |
| 271 | if (shared_->audio_device()->Init() != 0) { |
| 272 | shared_->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError, |
| 273 | "Init() failed to initialize the ADM"); |
| 274 | return -1; |
| 275 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 276 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 277 | // Initialize the default speaker |
| 278 | if (shared_->audio_device()->SetPlayoutDevice( |
| 279 | WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE) != 0) { |
| 280 | shared_->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceInfo, |
| 281 | "Init() failed to set the default output device"); |
| 282 | } |
| 283 | if (shared_->audio_device()->InitSpeaker() != 0) { |
| 284 | shared_->SetLastError(VE_CANNOT_ACCESS_SPEAKER_VOL, kTraceInfo, |
| 285 | "Init() failed to initialize the speaker"); |
| 286 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 287 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 288 | // Initialize the default microphone |
| 289 | if (shared_->audio_device()->SetRecordingDevice( |
| 290 | WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE) != 0) { |
| 291 | shared_->SetLastError(VE_SOUNDCARD_ERROR, kTraceInfo, |
| 292 | "Init() failed to set the default input device"); |
| 293 | } |
| 294 | if (shared_->audio_device()->InitMicrophone() != 0) { |
| 295 | shared_->SetLastError(VE_CANNOT_ACCESS_MIC_VOL, kTraceInfo, |
| 296 | "Init() failed to initialize the microphone"); |
| 297 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 298 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 299 | // Set number of channels |
| 300 | if (shared_->audio_device()->StereoPlayoutIsAvailable(&available) != 0) { |
| 301 | shared_->SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning, |
| 302 | "Init() failed to query stereo playout mode"); |
| 303 | } |
| 304 | if (shared_->audio_device()->SetStereoPlayout(available) != 0) { |
| 305 | shared_->SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning, |
| 306 | "Init() failed to set mono/stereo playout mode"); |
| 307 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 308 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 309 | // TODO(andrew): These functions don't tell us whether stereo recording |
| 310 | // is truly available. We simply set the AudioProcessing input to stereo |
| 311 | // here, because we have to wait until receiving the first frame to |
| 312 | // determine the actual number of channels anyway. |
| 313 | // |
| 314 | // These functions may be changed; tracked here: |
| 315 | // http://code.google.com/p/webrtc/issues/detail?id=204 |
| 316 | shared_->audio_device()->StereoRecordingIsAvailable(&available); |
| 317 | if (shared_->audio_device()->SetStereoRecording(available) != 0) { |
| 318 | shared_->SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning, |
| 319 | "Init() failed to set mono/stereo recording mode"); |
| 320 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 321 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 322 | if (!audioproc) { |
| 323 | audioproc = AudioProcessing::Create(); |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 324 | if (!audioproc) { |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 325 | LOG(LS_ERROR) << "Failed to create AudioProcessing."; |
| 326 | shared_->SetLastError(VE_NO_MEMORY); |
| 327 | return -1; |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 328 | } |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 329 | } |
| 330 | shared_->set_audio_processing(audioproc); |
niklas.enbom@webrtc.org | e33a102 | 2011-11-16 10:33:53 +0000 | [diff] [blame] | 331 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 332 | // Set the error state for any failures in this block. |
| 333 | shared_->SetLastError(VE_APM_ERROR); |
| 334 | // Configure AudioProcessing components. |
| 335 | if (audioproc->high_pass_filter()->Enable(true) != 0) { |
Jelena Marusic | f353dd5 | 2015-05-06 15:04:22 +0200 | [diff] [blame] | 336 | LOG_F(LS_ERROR) << "Failed to enable high pass filter."; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 337 | return -1; |
| 338 | } |
| 339 | if (audioproc->echo_cancellation()->enable_drift_compensation(false) != 0) { |
Jelena Marusic | f353dd5 | 2015-05-06 15:04:22 +0200 | [diff] [blame] | 340 | LOG_F(LS_ERROR) << "Failed to disable drift compensation."; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 341 | return -1; |
| 342 | } |
| 343 | if (audioproc->noise_suppression()->set_level(kDefaultNsMode) != 0) { |
Jelena Marusic | f353dd5 | 2015-05-06 15:04:22 +0200 | [diff] [blame] | 344 | LOG_F(LS_ERROR) << "Failed to set noise suppression level: " |
| 345 | << kDefaultNsMode; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 346 | return -1; |
| 347 | } |
| 348 | GainControl* agc = audioproc->gain_control(); |
| 349 | if (agc->set_analog_level_limits(kMinVolumeLevel, kMaxVolumeLevel) != 0) { |
Jelena Marusic | f353dd5 | 2015-05-06 15:04:22 +0200 | [diff] [blame] | 350 | LOG_F(LS_ERROR) << "Failed to set analog level limits with minimum: " |
| 351 | << kMinVolumeLevel << " and maximum: " << kMaxVolumeLevel; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 352 | return -1; |
| 353 | } |
| 354 | if (agc->set_mode(kDefaultAgcMode) != 0) { |
Jelena Marusic | f353dd5 | 2015-05-06 15:04:22 +0200 | [diff] [blame] | 355 | LOG_F(LS_ERROR) << "Failed to set mode: " << kDefaultAgcMode; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 356 | return -1; |
| 357 | } |
| 358 | if (agc->Enable(kDefaultAgcState) != 0) { |
Jelena Marusic | f353dd5 | 2015-05-06 15:04:22 +0200 | [diff] [blame] | 359 | LOG_F(LS_ERROR) << "Failed to set agc state: " << kDefaultAgcState; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 360 | return -1; |
| 361 | } |
| 362 | shared_->SetLastError(0); // Clear error state. |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 363 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 364 | #ifdef WEBRTC_VOICE_ENGINE_AGC |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 365 | bool agc_enabled = |
| 366 | agc->mode() == GainControl::kAdaptiveAnalog && agc->is_enabled(); |
| 367 | if (shared_->audio_device()->SetAGC(agc_enabled) != 0) { |
Jelena Marusic | f353dd5 | 2015-05-06 15:04:22 +0200 | [diff] [blame] | 368 | LOG_F(LS_ERROR) << "Failed to set agc to enabled: " << agc_enabled; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 369 | shared_->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR); |
| 370 | // TODO(ajm): No error return here due to |
| 371 | // https://code.google.com/p/webrtc/issues/detail?id=1464 |
| 372 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 373 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 374 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 375 | return shared_->statistics().SetInitialized(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 376 | } |
| 377 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 378 | int VoEBaseImpl::Terminate() { |
| 379 | CriticalSectionScoped cs(shared_->crit_sec()); |
| 380 | return TerminateInternal(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 381 | } |
| 382 | |
turaj@webrtc.org | 03f3370 | 2013-11-13 00:02:48 +0000 | [diff] [blame] | 383 | int VoEBaseImpl::CreateChannel() { |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 384 | CriticalSectionScoped cs(shared_->crit_sec()); |
| 385 | if (!shared_->statistics().Initialized()) { |
| 386 | shared_->SetLastError(VE_NOT_INITED, kTraceError); |
| 387 | return -1; |
turaj@webrtc.org | 03f3370 | 2013-11-13 00:02:48 +0000 | [diff] [blame] | 388 | } |
| 389 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 390 | voe::ChannelOwner channel_owner = shared_->channel_manager().CreateChannel(); |
turaj@webrtc.org | 03f3370 | 2013-11-13 00:02:48 +0000 | [diff] [blame] | 391 | return InitializeChannel(&channel_owner); |
| 392 | } |
| 393 | |
| 394 | int VoEBaseImpl::CreateChannel(const Config& config) { |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 395 | CriticalSectionScoped cs(shared_->crit_sec()); |
| 396 | if (!shared_->statistics().Initialized()) { |
| 397 | shared_->SetLastError(VE_NOT_INITED, kTraceError); |
| 398 | return -1; |
turaj@webrtc.org | 03f3370 | 2013-11-13 00:02:48 +0000 | [diff] [blame] | 399 | } |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 400 | voe::ChannelOwner channel_owner = |
| 401 | shared_->channel_manager().CreateChannel(config); |
turaj@webrtc.org | 03f3370 | 2013-11-13 00:02:48 +0000 | [diff] [blame] | 402 | return InitializeChannel(&channel_owner); |
| 403 | } |
| 404 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 405 | int VoEBaseImpl::InitializeChannel(voe::ChannelOwner* channel_owner) { |
| 406 | if (channel_owner->channel()->SetEngineInformation( |
| 407 | shared_->statistics(), *shared_->output_mixer(), |
| 408 | *shared_->transmit_mixer(), *shared_->process_thread(), |
| 409 | *shared_->audio_device(), voiceEngineObserverPtr_, |
| 410 | &callbackCritSect_) != 0) { |
| 411 | shared_->SetLastError( |
| 412 | VE_CHANNEL_NOT_CREATED, kTraceError, |
| 413 | "CreateChannel() failed to associate engine and channel." |
| 414 | " Destroying channel."); |
| 415 | shared_->channel_manager().DestroyChannel( |
| 416 | channel_owner->channel()->ChannelId()); |
| 417 | return -1; |
| 418 | } else if (channel_owner->channel()->Init() != 0) { |
| 419 | shared_->SetLastError( |
| 420 | VE_CHANNEL_NOT_CREATED, kTraceError, |
| 421 | "CreateChannel() failed to initialize channel. Destroying" |
| 422 | " channel."); |
| 423 | shared_->channel_manager().DestroyChannel( |
| 424 | channel_owner->channel()->ChannelId()); |
| 425 | return -1; |
| 426 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 427 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 428 | return channel_owner->channel()->ChannelId(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 429 | } |
| 430 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 431 | int VoEBaseImpl::DeleteChannel(int channel) { |
| 432 | CriticalSectionScoped cs(shared_->crit_sec()); |
| 433 | if (!shared_->statistics().Initialized()) { |
| 434 | shared_->SetLastError(VE_NOT_INITED, kTraceError); |
| 435 | return -1; |
| 436 | } |
| 437 | |
| 438 | { |
| 439 | voe::ChannelOwner ch = shared_->channel_manager().GetChannel(channel); |
| 440 | voe::Channel* channelPtr = ch.channel(); |
| 441 | if (channelPtr == nullptr) { |
| 442 | shared_->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 443 | "DeleteChannel() failed to locate channel"); |
| 444 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 445 | } |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 446 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 447 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 448 | shared_->channel_manager().DestroyChannel(channel); |
| 449 | if (StopSend() != 0) { |
| 450 | return -1; |
| 451 | } |
| 452 | if (StopPlayout() != 0) { |
| 453 | return -1; |
| 454 | } |
| 455 | return 0; |
| 456 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 457 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 458 | int VoEBaseImpl::StartReceive(int channel) { |
| 459 | CriticalSectionScoped cs(shared_->crit_sec()); |
| 460 | if (!shared_->statistics().Initialized()) { |
| 461 | shared_->SetLastError(VE_NOT_INITED, kTraceError); |
| 462 | return -1; |
| 463 | } |
| 464 | voe::ChannelOwner ch = shared_->channel_manager().GetChannel(channel); |
| 465 | voe::Channel* channelPtr = ch.channel(); |
| 466 | if (channelPtr == nullptr) { |
| 467 | shared_->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 468 | "StartReceive() failed to locate channel"); |
| 469 | return -1; |
| 470 | } |
| 471 | return channelPtr->StartReceiving(); |
| 472 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 473 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 474 | int VoEBaseImpl::StopReceive(int channel) { |
| 475 | CriticalSectionScoped cs(shared_->crit_sec()); |
| 476 | if (!shared_->statistics().Initialized()) { |
| 477 | shared_->SetLastError(VE_NOT_INITED, kTraceError); |
| 478 | return -1; |
| 479 | } |
| 480 | voe::ChannelOwner ch = shared_->channel_manager().GetChannel(channel); |
| 481 | voe::Channel* channelPtr = ch.channel(); |
| 482 | if (channelPtr == nullptr) { |
| 483 | shared_->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 484 | "SetLocalReceiver() failed to locate channel"); |
| 485 | return -1; |
| 486 | } |
| 487 | return channelPtr->StopReceiving(); |
| 488 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 489 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 490 | int VoEBaseImpl::StartPlayout(int channel) { |
| 491 | CriticalSectionScoped cs(shared_->crit_sec()); |
| 492 | if (!shared_->statistics().Initialized()) { |
| 493 | shared_->SetLastError(VE_NOT_INITED, kTraceError); |
| 494 | return -1; |
| 495 | } |
| 496 | voe::ChannelOwner ch = shared_->channel_manager().GetChannel(channel); |
| 497 | voe::Channel* channelPtr = ch.channel(); |
| 498 | if (channelPtr == nullptr) { |
| 499 | shared_->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 500 | "StartPlayout() failed to locate channel"); |
| 501 | return -1; |
| 502 | } |
| 503 | if (channelPtr->Playing()) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 504 | return 0; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 505 | } |
| 506 | if (StartPlayout() != 0) { |
| 507 | shared_->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError, |
| 508 | "StartPlayout() failed to start playout"); |
| 509 | return -1; |
| 510 | } |
| 511 | return channelPtr->StartPlayout(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 512 | } |
| 513 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 514 | int VoEBaseImpl::StopPlayout(int channel) { |
| 515 | CriticalSectionScoped cs(shared_->crit_sec()); |
| 516 | if (!shared_->statistics().Initialized()) { |
| 517 | shared_->SetLastError(VE_NOT_INITED, kTraceError); |
| 518 | return -1; |
| 519 | } |
| 520 | voe::ChannelOwner ch = shared_->channel_manager().GetChannel(channel); |
| 521 | voe::Channel* channelPtr = ch.channel(); |
| 522 | if (channelPtr == nullptr) { |
| 523 | shared_->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 524 | "StopPlayout() failed to locate channel"); |
| 525 | return -1; |
| 526 | } |
| 527 | if (channelPtr->StopPlayout() != 0) { |
| 528 | LOG_F(LS_WARNING) << "StopPlayout() failed to stop playout for channel " |
| 529 | << channel; |
| 530 | } |
| 531 | return StopPlayout(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 532 | } |
| 533 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 534 | int VoEBaseImpl::StartSend(int channel) { |
| 535 | CriticalSectionScoped cs(shared_->crit_sec()); |
| 536 | if (!shared_->statistics().Initialized()) { |
| 537 | shared_->SetLastError(VE_NOT_INITED, kTraceError); |
| 538 | return -1; |
| 539 | } |
| 540 | voe::ChannelOwner ch = shared_->channel_manager().GetChannel(channel); |
| 541 | voe::Channel* channelPtr = ch.channel(); |
| 542 | if (channelPtr == nullptr) { |
| 543 | shared_->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 544 | "StartSend() failed to locate channel"); |
| 545 | return -1; |
| 546 | } |
| 547 | if (channelPtr->Sending()) { |
| 548 | return 0; |
| 549 | } |
| 550 | if (StartSend() != 0) { |
| 551 | shared_->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError, |
| 552 | "StartSend() failed to start recording"); |
| 553 | return -1; |
| 554 | } |
| 555 | return channelPtr->StartSend(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 556 | } |
| 557 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 558 | int VoEBaseImpl::StopSend(int channel) { |
| 559 | CriticalSectionScoped cs(shared_->crit_sec()); |
| 560 | if (!shared_->statistics().Initialized()) { |
| 561 | shared_->SetLastError(VE_NOT_INITED, kTraceError); |
| 562 | return -1; |
| 563 | } |
| 564 | voe::ChannelOwner ch = shared_->channel_manager().GetChannel(channel); |
| 565 | voe::Channel* channelPtr = ch.channel(); |
| 566 | if (channelPtr == nullptr) { |
| 567 | shared_->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 568 | "StopSend() failed to locate channel"); |
| 569 | return -1; |
| 570 | } |
| 571 | if (channelPtr->StopSend() != 0) { |
| 572 | LOG_F(LS_WARNING) << "StopSend() failed to stop sending for channel " |
| 573 | << channel; |
| 574 | } |
| 575 | return StopSend(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 576 | } |
| 577 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 578 | int VoEBaseImpl::GetVersion(char version[1024]) { |
André Susano Pinto | 664cdaf | 2015-05-20 11:11:07 +0200 | [diff] [blame] | 579 | static_assert(kVoiceEngineVersionMaxMessageSize == 1024, ""); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 580 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 581 | if (version == nullptr) { |
| 582 | shared_->SetLastError(VE_INVALID_ARGUMENT, kTraceError); |
| 583 | return (-1); |
| 584 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 585 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 586 | char versionBuf[kVoiceEngineVersionMaxMessageSize]; |
| 587 | char* versionPtr = versionBuf; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 588 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 589 | int32_t len = 0; |
| 590 | int32_t accLen = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 591 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 592 | len = AddVoEVersion(versionPtr); |
| 593 | if (len == -1) { |
| 594 | return -1; |
| 595 | } |
| 596 | versionPtr += len; |
| 597 | accLen += len; |
| 598 | assert(accLen < kVoiceEngineVersionMaxMessageSize); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 599 | |
pwestin@webrtc.org | 684f057 | 2013-03-13 23:20:57 +0000 | [diff] [blame] | 600 | #ifdef WEBRTC_EXTERNAL_TRANSPORT |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 601 | len = AddExternalTransportBuild(versionPtr); |
| 602 | if (len == -1) { |
| 603 | return -1; |
| 604 | } |
| 605 | versionPtr += len; |
| 606 | accLen += len; |
| 607 | assert(accLen < kVoiceEngineVersionMaxMessageSize); |
pwestin@webrtc.org | 684f057 | 2013-03-13 23:20:57 +0000 | [diff] [blame] | 608 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 609 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 610 | memcpy(version, versionBuf, accLen); |
| 611 | version[accLen] = '\0'; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 612 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 613 | // to avoid the truncation in the trace, split the string into parts |
| 614 | char partOfVersion[256]; |
| 615 | for (int partStart = 0; partStart < accLen;) { |
| 616 | memset(partOfVersion, 0, sizeof(partOfVersion)); |
| 617 | int partEnd = partStart + 180; |
| 618 | while (version[partEnd] != '\n' && version[partEnd] != '\0') { |
| 619 | partEnd--; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 620 | } |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 621 | if (partEnd < accLen) { |
| 622 | memcpy(partOfVersion, &version[partStart], partEnd - partStart); |
| 623 | } else { |
| 624 | memcpy(partOfVersion, &version[partStart], accLen - partStart); |
| 625 | } |
| 626 | partStart = partEnd; |
| 627 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 628 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 629 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 630 | } |
| 631 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 632 | int32_t VoEBaseImpl::AddVoEVersion(char* str) const { |
| 633 | return sprintf(str, "VoiceEngine 4.1.0\n"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 634 | } |
| 635 | |
pwestin@webrtc.org | 684f057 | 2013-03-13 23:20:57 +0000 | [diff] [blame] | 636 | #ifdef WEBRTC_EXTERNAL_TRANSPORT |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 637 | int32_t VoEBaseImpl::AddExternalTransportBuild(char* str) const { |
| 638 | return sprintf(str, "External transport build\n"); |
pwestin@webrtc.org | 684f057 | 2013-03-13 23:20:57 +0000 | [diff] [blame] | 639 | } |
| 640 | #endif |
| 641 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 642 | int VoEBaseImpl::LastError() { return (shared_->statistics().LastError()); } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 643 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 644 | int32_t VoEBaseImpl::StartPlayout() { |
solenberg | e313e02 | 2015-09-08 02:16:04 -0700 | [diff] [blame^] | 645 | if (!shared_->audio_device()->Playing()) { |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 646 | if (shared_->audio_device()->InitPlayout() != 0) { |
| 647 | LOG_F(LS_ERROR) << "Failed to initialize playout"; |
| 648 | return -1; |
| 649 | } |
| 650 | if (shared_->audio_device()->StartPlayout() != 0) { |
| 651 | LOG_F(LS_ERROR) << "Failed to start playout"; |
| 652 | return -1; |
| 653 | } |
| 654 | } |
| 655 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 656 | } |
| 657 | |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 658 | int32_t VoEBaseImpl::StopPlayout() { |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 659 | // Stop audio-device playing if no channel is playing out |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 660 | if (shared_->NumOfPlayingChannels() == 0) { |
| 661 | if (shared_->audio_device()->StopPlayout() != 0) { |
| 662 | shared_->SetLastError(VE_CANNOT_STOP_PLAYOUT, kTraceError, |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 663 | "StopPlayout() failed to stop playout"); |
| 664 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 665 | } |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 666 | } |
| 667 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 668 | } |
| 669 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 670 | int32_t VoEBaseImpl::StartSend() { |
solenberg | e313e02 | 2015-09-08 02:16:04 -0700 | [diff] [blame^] | 671 | if (!shared_->audio_device()->Recording()) { |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 672 | if (shared_->audio_device()->InitRecording() != 0) { |
| 673 | LOG_F(LS_ERROR) << "Failed to initialize recording"; |
| 674 | return -1; |
| 675 | } |
| 676 | if (shared_->audio_device()->StartRecording() != 0) { |
| 677 | LOG_F(LS_ERROR) << "Failed to start recording"; |
| 678 | return -1; |
| 679 | } |
| 680 | } |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 681 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 682 | } |
| 683 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 684 | int32_t VoEBaseImpl::StopSend() { |
| 685 | if (shared_->NumOfSendingChannels() == 0 && |
| 686 | !shared_->transmit_mixer()->IsRecordingMic()) { |
| 687 | // Stop audio-device recording if no channel is recording |
| 688 | if (shared_->audio_device()->StopRecording() != 0) { |
| 689 | shared_->SetLastError(VE_CANNOT_STOP_RECORDING, kTraceError, |
| 690 | "StopSend() failed to stop recording"); |
| 691 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 692 | } |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 693 | shared_->transmit_mixer()->StopSend(); |
| 694 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 695 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 696 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 697 | } |
| 698 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 699 | int32_t VoEBaseImpl::TerminateInternal() { |
| 700 | // Delete any remaining channel objects |
| 701 | shared_->channel_manager().DestroyAllChannels(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 702 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 703 | if (shared_->process_thread()) { |
| 704 | if (shared_->audio_device()) { |
| 705 | shared_->process_thread()->DeRegisterModule(shared_->audio_device()); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 706 | } |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 707 | shared_->process_thread()->Stop(); |
| 708 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 709 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 710 | if (shared_->audio_device()) { |
| 711 | if (shared_->audio_device()->StopPlayout() != 0) { |
| 712 | shared_->SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning, |
| 713 | "TerminateInternal() failed to stop playout"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 714 | } |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 715 | if (shared_->audio_device()->StopRecording() != 0) { |
| 716 | shared_->SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning, |
| 717 | "TerminateInternal() failed to stop recording"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 718 | } |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 719 | if (shared_->audio_device()->RegisterEventObserver(nullptr) != 0) { |
| 720 | shared_->SetLastError( |
| 721 | VE_AUDIO_DEVICE_MODULE_ERROR, kTraceWarning, |
| 722 | "TerminateInternal() failed to de-register event observer " |
| 723 | "for the ADM"); |
| 724 | } |
| 725 | if (shared_->audio_device()->RegisterAudioCallback(nullptr) != 0) { |
| 726 | shared_->SetLastError( |
| 727 | VE_AUDIO_DEVICE_MODULE_ERROR, kTraceWarning, |
| 728 | "TerminateInternal() failed to de-register audio callback " |
| 729 | "for the ADM"); |
| 730 | } |
| 731 | if (shared_->audio_device()->Terminate() != 0) { |
| 732 | shared_->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError, |
| 733 | "TerminateInternal() failed to terminate the ADM"); |
| 734 | } |
| 735 | shared_->set_audio_device(nullptr); |
| 736 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 737 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 738 | if (shared_->audio_processing()) { |
| 739 | shared_->set_audio_processing(nullptr); |
| 740 | } |
| 741 | |
| 742 | return shared_->statistics().SetUnInitialized(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 743 | } |
| 744 | |
xians@webrtc.org | 8fff1f0 | 2013-07-31 16:27:42 +0000 | [diff] [blame] | 745 | int VoEBaseImpl::ProcessRecordedDataWithAPM( |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 746 | const int voe_channels[], int number_of_voe_channels, |
| 747 | const void* audio_data, uint32_t sample_rate, uint8_t number_of_channels, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 748 | size_t number_of_frames, uint32_t audio_delay_milliseconds, |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 749 | int32_t clock_drift, uint32_t volume, bool key_pressed) { |
| 750 | assert(shared_->transmit_mixer() != nullptr); |
| 751 | assert(shared_->audio_device() != nullptr); |
xians@webrtc.org | 8fff1f0 | 2013-07-31 16:27:42 +0000 | [diff] [blame] | 752 | |
xians@webrtc.org | 8fff1f0 | 2013-07-31 16:27:42 +0000 | [diff] [blame] | 753 | uint32_t max_volume = 0; |
andrew@webrtc.org | 27c6980 | 2014-02-18 20:24:56 +0000 | [diff] [blame] | 754 | uint16_t voe_mic_level = 0; |
andrew@webrtc.org | 023cc5a | 2014-01-11 01:25:53 +0000 | [diff] [blame] | 755 | // Check for zero to skip this calculation; the consumer may use this to |
| 756 | // indicate no volume is available. |
andrew@webrtc.org | 27c6980 | 2014-02-18 20:24:56 +0000 | [diff] [blame] | 757 | if (volume != 0) { |
xians@webrtc.org | 8fff1f0 | 2013-07-31 16:27:42 +0000 | [diff] [blame] | 758 | // Scale from ADM to VoE level range |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 759 | if (shared_->audio_device()->MaxMicrophoneVolume(&max_volume) == 0) { |
xians@webrtc.org | 8fff1f0 | 2013-07-31 16:27:42 +0000 | [diff] [blame] | 760 | if (max_volume) { |
andrew@webrtc.org | 27c6980 | 2014-02-18 20:24:56 +0000 | [diff] [blame] | 761 | voe_mic_level = static_cast<uint16_t>( |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 762 | (volume * kMaxVolumeLevel + static_cast<int>(max_volume / 2)) / |
| 763 | max_volume); |
xians@webrtc.org | 8fff1f0 | 2013-07-31 16:27:42 +0000 | [diff] [blame] | 764 | } |
| 765 | } |
andrew@webrtc.org | 27c6980 | 2014-02-18 20:24:56 +0000 | [diff] [blame] | 766 | // We learned that on certain systems (e.g Linux) the voe_mic_level |
xians@webrtc.org | 8fff1f0 | 2013-07-31 16:27:42 +0000 | [diff] [blame] | 767 | // can be greater than the maxVolumeLevel therefore |
andrew@webrtc.org | 27c6980 | 2014-02-18 20:24:56 +0000 | [diff] [blame] | 768 | // we are going to cap the voe_mic_level to the maxVolumeLevel |
| 769 | // and change the maxVolume to volume if it turns out that |
| 770 | // the voe_mic_level is indeed greater than the maxVolumeLevel. |
| 771 | if (voe_mic_level > kMaxVolumeLevel) { |
| 772 | voe_mic_level = kMaxVolumeLevel; |
| 773 | max_volume = volume; |
xians@webrtc.org | 8fff1f0 | 2013-07-31 16:27:42 +0000 | [diff] [blame] | 774 | } |
| 775 | } |
| 776 | |
xians@webrtc.org | 8fff1f0 | 2013-07-31 16:27:42 +0000 | [diff] [blame] | 777 | // Perform channel-independent operations |
| 778 | // (APM, mix with file, record to file, mute, etc.) |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 779 | shared_->transmit_mixer()->PrepareDemux( |
xians@webrtc.org | 8fff1f0 | 2013-07-31 16:27:42 +0000 | [diff] [blame] | 780 | audio_data, number_of_frames, number_of_channels, sample_rate, |
| 781 | static_cast<uint16_t>(audio_delay_milliseconds), clock_drift, |
andrew@webrtc.org | 27c6980 | 2014-02-18 20:24:56 +0000 | [diff] [blame] | 782 | voe_mic_level, key_pressed); |
xians@webrtc.org | 8fff1f0 | 2013-07-31 16:27:42 +0000 | [diff] [blame] | 783 | |
| 784 | // Copy the audio frame to each sending channel and perform |
| 785 | // channel-dependent operations (file mixing, mute, etc.), encode and |
| 786 | // packetize+transmit the RTP packet. When |number_of_voe_channels| == 0, |
| 787 | // do the operations on all the existing VoE channels; otherwise the |
| 788 | // operations will be done on specific channels. |
| 789 | if (number_of_voe_channels == 0) { |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 790 | shared_->transmit_mixer()->DemuxAndMix(); |
| 791 | shared_->transmit_mixer()->EncodeAndSend(); |
xians@webrtc.org | 8fff1f0 | 2013-07-31 16:27:42 +0000 | [diff] [blame] | 792 | } else { |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 793 | shared_->transmit_mixer()->DemuxAndMix(voe_channels, |
xians@webrtc.org | 8fff1f0 | 2013-07-31 16:27:42 +0000 | [diff] [blame] | 794 | number_of_voe_channels); |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 795 | shared_->transmit_mixer()->EncodeAndSend(voe_channels, |
xians@webrtc.org | 8fff1f0 | 2013-07-31 16:27:42 +0000 | [diff] [blame] | 796 | number_of_voe_channels); |
| 797 | } |
| 798 | |
xians@webrtc.org | 8fff1f0 | 2013-07-31 16:27:42 +0000 | [diff] [blame] | 799 | // Scale from VoE to ADM level range. |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 800 | uint32_t new_voe_mic_level = shared_->transmit_mixer()->CaptureLevel(); |
andrew@webrtc.org | 27c6980 | 2014-02-18 20:24:56 +0000 | [diff] [blame] | 801 | if (new_voe_mic_level != voe_mic_level) { |
xians@webrtc.org | 8fff1f0 | 2013-07-31 16:27:42 +0000 | [diff] [blame] | 802 | // Return the new volume if AGC has changed the volume. |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 803 | return static_cast<int>((new_voe_mic_level * max_volume + |
| 804 | static_cast<int>(kMaxVolumeLevel / 2)) / |
| 805 | kMaxVolumeLevel); |
xians@webrtc.org | 8fff1f0 | 2013-07-31 16:27:42 +0000 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | // Return 0 to indicate no change on the volume. |
| 809 | return 0; |
| 810 | } |
| 811 | |
xians@webrtc.org | 5692531 | 2014-04-14 10:50:37 +0000 | [diff] [blame] | 812 | void VoEBaseImpl::GetPlayoutData(int sample_rate, int number_of_channels, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 813 | size_t number_of_frames, bool feed_data_to_apm, |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 814 | void* audio_data, int64_t* elapsed_time_ms, |
wu@webrtc.org | cb711f7 | 2014-05-19 17:39:11 +0000 | [diff] [blame] | 815 | int64_t* ntp_time_ms) { |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 816 | assert(shared_->output_mixer() != nullptr); |
xians@webrtc.org | 5692531 | 2014-04-14 10:50:37 +0000 | [diff] [blame] | 817 | |
| 818 | // TODO(andrew): if the device is running in mono, we should tell the mixer |
| 819 | // here so that it will only request mono from AudioCodingModule. |
| 820 | // Perform mixing of all active participants (channel-based mixing) |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 821 | shared_->output_mixer()->MixActiveChannels(); |
xians@webrtc.org | 5692531 | 2014-04-14 10:50:37 +0000 | [diff] [blame] | 822 | |
| 823 | // Additional operations on the combined signal |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 824 | shared_->output_mixer()->DoOperationsOnCombinedSignal(feed_data_to_apm); |
xians@webrtc.org | 5692531 | 2014-04-14 10:50:37 +0000 | [diff] [blame] | 825 | |
| 826 | // Retrieve the final output mix (resampled to match the ADM) |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 827 | shared_->output_mixer()->GetMixedAudio(sample_rate, number_of_channels, |
| 828 | &audioFrame_); |
xians@webrtc.org | 5692531 | 2014-04-14 10:50:37 +0000 | [diff] [blame] | 829 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 830 | assert(number_of_frames == audioFrame_.samples_per_channel_); |
| 831 | assert(sample_rate == audioFrame_.sample_rate_hz_); |
xians@webrtc.org | 5692531 | 2014-04-14 10:50:37 +0000 | [diff] [blame] | 832 | |
| 833 | // Deliver audio (PCM) samples to the ADM |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 834 | memcpy(audio_data, audioFrame_.data_, |
xians@webrtc.org | 5692531 | 2014-04-14 10:50:37 +0000 | [diff] [blame] | 835 | sizeof(int16_t) * number_of_frames * number_of_channels); |
wu@webrtc.org | cb711f7 | 2014-05-19 17:39:11 +0000 | [diff] [blame] | 836 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 837 | *elapsed_time_ms = audioFrame_.elapsed_time_ms_; |
| 838 | *ntp_time_ms = audioFrame_.ntp_time_ms_; |
xians@webrtc.org | 5692531 | 2014-04-14 10:50:37 +0000 | [diff] [blame] | 839 | } |
| 840 | |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 841 | int VoEBaseImpl::AssociateSendChannel(int channel, |
| 842 | int accociate_send_channel) { |
| 843 | CriticalSectionScoped cs(shared_->crit_sec()); |
| 844 | |
| 845 | if (!shared_->statistics().Initialized()) { |
| 846 | shared_->SetLastError(VE_NOT_INITED, kTraceError); |
| 847 | return -1; |
| 848 | } |
| 849 | |
| 850 | voe::ChannelOwner ch = shared_->channel_manager().GetChannel(channel); |
| 851 | voe::Channel* channel_ptr = ch.channel(); |
| 852 | if (channel_ptr == NULL) { |
| 853 | shared_->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 854 | "AssociateSendChannel() failed to locate channel"); |
| 855 | return -1; |
| 856 | } |
| 857 | |
| 858 | ch = shared_->channel_manager().GetChannel(accociate_send_channel); |
| 859 | voe::Channel* accociate_send_channel_ptr = ch.channel(); |
| 860 | if (accociate_send_channel_ptr == NULL) { |
| 861 | shared_->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 862 | "AssociateSendChannel() failed to locate accociate_send_channel"); |
| 863 | return -1; |
| 864 | } |
| 865 | |
| 866 | channel_ptr->set_associate_send_channel(ch); |
| 867 | return 0; |
| 868 | } |
| 869 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 870 | } // namespace webrtc |