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

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: Readded the audio_processing getter method 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
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_apmwhen upstream dependencies have
Taylor Brandstetter 2017/06/28 07:19:38 Here too, and space between "apm" and "when"
peah-webrtc 2017/06/29 11:46:31 Done.
231 // 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_) {
343 LOG(LS_ERROR) << "Failed to create AudioProcessing."; 348 LOG(LS_ERROR) << "Failed to create AudioProcessing.";
344 shared_->SetLastError(VE_NO_MEMORY); 349 shared_->SetLastError(VE_NO_MEMORY);
Taylor Brandstetter 2017/06/28 07:19:38 Can you add a comment explaining why failure to cr
peah-webrtc 2017/06/29 11:46:31 This makes sense and this is not clear at all. How
345 return -1; 350 return -1;
346 } 351 }
352 apm = audio_processing_.get();
353 } else {
354 apm = external_apm;
347 } 355 }
348 shared_->set_audio_processing(audioproc); 356
357 shared_->set_audio_processing(apm);
349 358
350 // Set the error state for any failures in this block. 359 // Set the error state for any failures in this block.
351 shared_->SetLastError(VE_APM_ERROR); 360 shared_->SetLastError(VE_APM_ERROR);
352 // Configure AudioProcessing components. 361 // Configure AudioProcessing components.
353 if (audioproc->high_pass_filter()->Enable(true) != 0) { 362 // TODO(peah): Move this initialization to webrtcvoiceengine.cc.
363 if (apm->high_pass_filter()->Enable(true) != 0) {
354 LOG_F(LS_ERROR) << "Failed to enable high pass filter."; 364 LOG_F(LS_ERROR) << "Failed to enable high pass filter.";
355 return -1; 365 return -1;
356 } 366 }
357 if (audioproc->echo_cancellation()->enable_drift_compensation(false) != 0) { 367 if (apm->echo_cancellation()->enable_drift_compensation(false) != 0) {
358 LOG_F(LS_ERROR) << "Failed to disable drift compensation."; 368 LOG_F(LS_ERROR) << "Failed to disable drift compensation.";
359 return -1; 369 return -1;
360 } 370 }
361 if (audioproc->noise_suppression()->set_level(kDefaultNsMode) != 0) { 371 if (apm->noise_suppression()->set_level(kDefaultNsMode) != 0) {
362 LOG_F(LS_ERROR) << "Failed to set noise suppression level: " 372 LOG_F(LS_ERROR) << "Failed to set noise suppression level: "
363 << kDefaultNsMode; 373 << kDefaultNsMode;
364 return -1; 374 return -1;
365 } 375 }
366 GainControl* agc = audioproc->gain_control(); 376 GainControl* agc = apm->gain_control();
367 if (agc->set_analog_level_limits(kMinVolumeLevel, kMaxVolumeLevel) != 0) { 377 if (agc->set_analog_level_limits(kMinVolumeLevel, kMaxVolumeLevel) != 0) {
368 LOG_F(LS_ERROR) << "Failed to set analog level limits with minimum: " 378 LOG_F(LS_ERROR) << "Failed to set analog level limits with minimum: "
369 << kMinVolumeLevel << " and maximum: " << kMaxVolumeLevel; 379 << kMinVolumeLevel << " and maximum: " << kMaxVolumeLevel;
370 return -1; 380 return -1;
371 } 381 }
372 if (agc->set_mode(kDefaultAgcMode) != 0) { 382 if (agc->set_mode(kDefaultAgcMode) != 0) {
373 LOG_F(LS_ERROR) << "Failed to set mode: " << kDefaultAgcMode; 383 LOG_F(LS_ERROR) << "Failed to set mode: " << kDefaultAgcMode;
374 return -1; 384 return -1;
375 } 385 }
376 if (agc->Enable(kDefaultAgcState) != 0) { 386 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 " 690 "TerminateInternal() failed to de-register audio callback "
681 "for the ADM"); 691 "for the ADM");
682 } 692 }
683 if (shared_->audio_device()->Terminate() != 0) { 693 if (shared_->audio_device()->Terminate() != 0) {
684 shared_->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError, 694 shared_->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError,
685 "TerminateInternal() failed to terminate the ADM"); 695 "TerminateInternal() failed to terminate the ADM");
686 } 696 }
687 shared_->set_audio_device(nullptr); 697 shared_->set_audio_device(nullptr);
688 } 698 }
689 699
690 if (shared_->audio_processing()) { 700 shared_->set_audio_processing(nullptr);
691 shared_->set_audio_processing(nullptr);
692 }
693 701
694 return shared_->statistics().SetUnInitialized(); 702 return shared_->statistics().SetUnInitialized();
695 } 703 }
696 704
697 void VoEBaseImpl::GetPlayoutData(int sample_rate, size_t number_of_channels, 705 void VoEBaseImpl::GetPlayoutData(int sample_rate, size_t number_of_channels,
698 size_t number_of_frames, bool feed_data_to_apm, 706 size_t number_of_frames, bool feed_data_to_apm,
699 void* audio_data, int64_t* elapsed_time_ms, 707 void* audio_data, int64_t* elapsed_time_ms,
700 int64_t* ntp_time_ms) { 708 int64_t* ntp_time_ms) {
701 assert(shared_->output_mixer() != nullptr); 709 assert(shared_->output_mixer() != nullptr);
702 710
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 shared_->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, 754 shared_->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
747 "AssociateSendChannel() failed to locate accociate_send_channel"); 755 "AssociateSendChannel() failed to locate accociate_send_channel");
748 return -1; 756 return -1;
749 } 757 }
750 758
751 channel_ptr->set_associate_send_channel(ch); 759 channel_ptr->set_associate_send_channel(ch);
752 return 0; 760 return 0;
753 } 761 }
754 762
755 } // namespace webrtc 763 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698