Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2657)

Side by Side Diff: webrtc/voice_engine/voe_base_impl.cc

Issue 2961723004: Allow an external audio processing module to be used in WebRTC (Closed)
Patch Set: Moved creation of APMs from CreateVoiceEngines Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/voice_engine/voe_base_impl.h ('k') | webrtc/voice_engine/voe_base_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 for (voe::ChannelManager::Iterator it(&shared_->channel_manager()); 218 for (voe::ChannelManager::Iterator it(&shared_->channel_manager());
219 it.IsValid(); it.Increment()) { 219 it.IsValid(); it.Increment()) {
220 it.GetChannel()->DeRegisterVoiceEngineObserver(); 220 it.GetChannel()->DeRegisterVoiceEngineObserver();
221 } 221 }
222 222
223 return 0; 223 return 0;
224 } 224 }
225 225
226 int VoEBaseImpl::Init( 226 int VoEBaseImpl::Init(
227 AudioDeviceModule* external_adm, 227 AudioDeviceModule* external_adm,
228 AudioProcessing* audioproc, 228 AudioProcessing* external_apm,
229 const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory) { 229 const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory) {
230 // TODO(peah): Add a DCHECK for external_apm when downstream dependencies
231 // have properly been resolved.
230 rtc::CritScope cs(shared_->crit_sec()); 232 rtc::CritScope cs(shared_->crit_sec());
231 WebRtcSpl_Init(); 233 WebRtcSpl_Init();
232 if (shared_->statistics().Initialized()) { 234 if (shared_->statistics().Initialized()) {
233 return 0; 235 return 0;
234 } 236 }
235 if (shared_->process_thread()) { 237 if (shared_->process_thread()) {
236 shared_->process_thread()->Start(); 238 shared_->process_thread()->Start();
237 } 239 }
238 240
239 // Create an internal ADM if the user has not added an external 241 // Create an internal ADM if the user has not added an external
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 // determine the actual number of channels anyway. 332 // determine the actual number of channels anyway.
331 // 333 //
332 // These functions may be changed; tracked here: 334 // These functions may be changed; tracked here:
333 // http://code.google.com/p/webrtc/issues/detail?id=204 335 // http://code.google.com/p/webrtc/issues/detail?id=204
334 shared_->audio_device()->StereoRecordingIsAvailable(&available); 336 shared_->audio_device()->StereoRecordingIsAvailable(&available);
335 if (shared_->audio_device()->SetStereoRecording(available) != 0) { 337 if (shared_->audio_device()->SetStereoRecording(available) != 0) {
336 shared_->SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning, 338 shared_->SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning,
337 "Init() failed to set mono/stereo recording mode"); 339 "Init() failed to set mono/stereo recording mode");
338 } 340 }
339 341
340 if (!audioproc) { 342 // TODO(peah): Remove this when upstream dependencies have properly been
341 audioproc = AudioProcessing::Create(); 343 // resolved.
342 if (!audioproc) { 344 AudioProcessing* apm = nullptr;
345 if (!external_apm) {
346 audio_processing_ = AudioProcessing::Create();
347 if (!audio_processing_) {
348 // This can only happen if there are problems allocating the dynamic
349 // memory in the Create() call.
343 LOG(LS_ERROR) << "Failed to create AudioProcessing."; 350 LOG(LS_ERROR) << "Failed to create AudioProcessing.";
344 shared_->SetLastError(VE_NO_MEMORY); 351 shared_->SetLastError(VE_NO_MEMORY);
345 return -1; 352 return -1;
346 } 353 }
354 apm = audio_processing_.get();
355 } else {
356 apm = external_apm;
347 } 357 }
348 shared_->set_audio_processing(audioproc); 358
359 shared_->set_audio_processing(apm);
349 360
350 // Set the error state for any failures in this block. 361 // Set the error state for any failures in this block.
351 shared_->SetLastError(VE_APM_ERROR); 362 shared_->SetLastError(VE_APM_ERROR);
352 // Configure AudioProcessing components. 363 // Configure AudioProcessing components.
353 if (audioproc->high_pass_filter()->Enable(true) != 0) { 364 // TODO(peah): Move this initialization to webrtcvoiceengine.cc.
365 if (apm->high_pass_filter()->Enable(true) != 0) {
354 LOG_F(LS_ERROR) << "Failed to enable high pass filter."; 366 LOG_F(LS_ERROR) << "Failed to enable high pass filter.";
355 return -1; 367 return -1;
356 } 368 }
357 if (audioproc->echo_cancellation()->enable_drift_compensation(false) != 0) { 369 if (apm->echo_cancellation()->enable_drift_compensation(false) != 0) {
358 LOG_F(LS_ERROR) << "Failed to disable drift compensation."; 370 LOG_F(LS_ERROR) << "Failed to disable drift compensation.";
359 return -1; 371 return -1;
360 } 372 }
361 if (audioproc->noise_suppression()->set_level(kDefaultNsMode) != 0) { 373 if (apm->noise_suppression()->set_level(kDefaultNsMode) != 0) {
362 LOG_F(LS_ERROR) << "Failed to set noise suppression level: " 374 LOG_F(LS_ERROR) << "Failed to set noise suppression level: "
363 << kDefaultNsMode; 375 << kDefaultNsMode;
364 return -1; 376 return -1;
365 } 377 }
366 GainControl* agc = audioproc->gain_control(); 378 GainControl* agc = apm->gain_control();
367 if (agc->set_analog_level_limits(kMinVolumeLevel, kMaxVolumeLevel) != 0) { 379 if (agc->set_analog_level_limits(kMinVolumeLevel, kMaxVolumeLevel) != 0) {
368 LOG_F(LS_ERROR) << "Failed to set analog level limits with minimum: " 380 LOG_F(LS_ERROR) << "Failed to set analog level limits with minimum: "
369 << kMinVolumeLevel << " and maximum: " << kMaxVolumeLevel; 381 << kMinVolumeLevel << " and maximum: " << kMaxVolumeLevel;
370 return -1; 382 return -1;
371 } 383 }
372 if (agc->set_mode(kDefaultAgcMode) != 0) { 384 if (agc->set_mode(kDefaultAgcMode) != 0) {
373 LOG_F(LS_ERROR) << "Failed to set mode: " << kDefaultAgcMode; 385 LOG_F(LS_ERROR) << "Failed to set mode: " << kDefaultAgcMode;
374 return -1; 386 return -1;
375 } 387 }
376 if (agc->Enable(kDefaultAgcState) != 0) { 388 if (agc->Enable(kDefaultAgcState) != 0) {
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 "TerminateInternal() failed to de-register audio callback " 692 "TerminateInternal() failed to de-register audio callback "
681 "for the ADM"); 693 "for the ADM");
682 } 694 }
683 if (shared_->audio_device()->Terminate() != 0) { 695 if (shared_->audio_device()->Terminate() != 0) {
684 shared_->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError, 696 shared_->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError,
685 "TerminateInternal() failed to terminate the ADM"); 697 "TerminateInternal() failed to terminate the ADM");
686 } 698 }
687 shared_->set_audio_device(nullptr); 699 shared_->set_audio_device(nullptr);
688 } 700 }
689 701
690 if (shared_->audio_processing()) { 702 shared_->set_audio_processing(nullptr);
691 shared_->set_audio_processing(nullptr);
692 }
693 703
694 return shared_->statistics().SetUnInitialized(); 704 return shared_->statistics().SetUnInitialized();
695 } 705 }
696 706
697 void VoEBaseImpl::GetPlayoutData(int sample_rate, size_t number_of_channels, 707 void VoEBaseImpl::GetPlayoutData(int sample_rate, size_t number_of_channels,
698 size_t number_of_frames, bool feed_data_to_apm, 708 size_t number_of_frames, bool feed_data_to_apm,
699 void* audio_data, int64_t* elapsed_time_ms, 709 void* audio_data, int64_t* elapsed_time_ms,
700 int64_t* ntp_time_ms) { 710 int64_t* ntp_time_ms) {
701 assert(shared_->output_mixer() != nullptr); 711 assert(shared_->output_mixer() != nullptr);
702 712
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 shared_->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, 756 shared_->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
747 "AssociateSendChannel() failed to locate accociate_send_channel"); 757 "AssociateSendChannel() failed to locate accociate_send_channel");
748 return -1; 758 return -1;
749 } 759 }
750 760
751 channel_ptr->set_associate_send_channel(ch); 761 channel_ptr->set_associate_send_channel(ch);
752 return 0; 762 return 0;
753 } 763 }
754 764
755 } // namespace webrtc 765 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/voice_engine/voe_base_impl.h ('k') | webrtc/voice_engine/voe_base_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698