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

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

Issue 2948763002: Allow an external audio processing module to be used in WebRTC (Closed)
Patch Set: tracking linux32_rel issue Created 3 years, 6 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 RTC_DCHECK(external_apm);
230 rtc::CritScope cs(shared_->crit_sec()); 231 rtc::CritScope cs(shared_->crit_sec());
231 WebRtcSpl_Init(); 232 WebRtcSpl_Init();
232 if (shared_->statistics().Initialized()) { 233 if (shared_->statistics().Initialized()) {
233 return 0; 234 return 0;
234 } 235 }
235 if (shared_->process_thread()) { 236 if (shared_->process_thread()) {
236 shared_->process_thread()->Start(); 237 shared_->process_thread()->Start();
237 } 238 }
238 239
239 // Create an internal ADM if the user has not added an external 240 // 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. 331 // determine the actual number of channels anyway.
331 // 332 //
332 // These functions may be changed; tracked here: 333 // These functions may be changed; tracked here:
333 // http://code.google.com/p/webrtc/issues/detail?id=204 334 // http://code.google.com/p/webrtc/issues/detail?id=204
334 shared_->audio_device()->StereoRecordingIsAvailable(&available); 335 shared_->audio_device()->StereoRecordingIsAvailable(&available);
335 if (shared_->audio_device()->SetStereoRecording(available) != 0) { 336 if (shared_->audio_device()->SetStereoRecording(available) != 0) {
336 shared_->SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning, 337 shared_->SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning,
337 "Init() failed to set mono/stereo recording mode"); 338 "Init() failed to set mono/stereo recording mode");
338 } 339 }
339 340
340 if (!audioproc) { 341 shared_->set_audio_processing(external_apm);
341 audioproc = AudioProcessing::Create();
342 if (!audioproc) {
343 LOG(LS_ERROR) << "Failed to create AudioProcessing.";
344 shared_->SetLastError(VE_NO_MEMORY);
345 return -1;
346 }
347 }
348 shared_->set_audio_processing(audioproc);
349 342
350 // Set the error state for any failures in this block. 343 // Set the error state for any failures in this block.
351 shared_->SetLastError(VE_APM_ERROR); 344 shared_->SetLastError(VE_APM_ERROR);
352 // Configure AudioProcessing components. 345 // Configure AudioProcessing components.
353 if (audioproc->high_pass_filter()->Enable(true) != 0) { 346 // TODO(peah): Move this initialization to webrtcvoiceengine.cc.
347 if (external_apm->high_pass_filter()->Enable(true) != 0) {
354 LOG_F(LS_ERROR) << "Failed to enable high pass filter."; 348 LOG_F(LS_ERROR) << "Failed to enable high pass filter.";
355 return -1; 349 return -1;
356 } 350 }
357 if (audioproc->echo_cancellation()->enable_drift_compensation(false) != 0) { 351 if (external_apm->echo_cancellation()->enable_drift_compensation(false) !=
352 0) {
358 LOG_F(LS_ERROR) << "Failed to disable drift compensation."; 353 LOG_F(LS_ERROR) << "Failed to disable drift compensation.";
359 return -1; 354 return -1;
360 } 355 }
361 if (audioproc->noise_suppression()->set_level(kDefaultNsMode) != 0) { 356 if (external_apm->noise_suppression()->set_level(kDefaultNsMode) != 0) {
362 LOG_F(LS_ERROR) << "Failed to set noise suppression level: " 357 LOG_F(LS_ERROR) << "Failed to set noise suppression level: "
363 << kDefaultNsMode; 358 << kDefaultNsMode;
364 return -1; 359 return -1;
365 } 360 }
366 GainControl* agc = audioproc->gain_control(); 361 GainControl* agc = external_apm->gain_control();
367 if (agc->set_analog_level_limits(kMinVolumeLevel, kMaxVolumeLevel) != 0) { 362 if (agc->set_analog_level_limits(kMinVolumeLevel, kMaxVolumeLevel) != 0) {
368 LOG_F(LS_ERROR) << "Failed to set analog level limits with minimum: " 363 LOG_F(LS_ERROR) << "Failed to set analog level limits with minimum: "
369 << kMinVolumeLevel << " and maximum: " << kMaxVolumeLevel; 364 << kMinVolumeLevel << " and maximum: " << kMaxVolumeLevel;
370 return -1; 365 return -1;
371 } 366 }
372 if (agc->set_mode(kDefaultAgcMode) != 0) { 367 if (agc->set_mode(kDefaultAgcMode) != 0) {
373 LOG_F(LS_ERROR) << "Failed to set mode: " << kDefaultAgcMode; 368 LOG_F(LS_ERROR) << "Failed to set mode: " << kDefaultAgcMode;
374 return -1; 369 return -1;
375 } 370 }
376 if (agc->Enable(kDefaultAgcState) != 0) { 371 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 " 675 "TerminateInternal() failed to de-register audio callback "
681 "for the ADM"); 676 "for the ADM");
682 } 677 }
683 if (shared_->audio_device()->Terminate() != 0) { 678 if (shared_->audio_device()->Terminate() != 0) {
684 shared_->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError, 679 shared_->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError,
685 "TerminateInternal() failed to terminate the ADM"); 680 "TerminateInternal() failed to terminate the ADM");
686 } 681 }
687 shared_->set_audio_device(nullptr); 682 shared_->set_audio_device(nullptr);
688 } 683 }
689 684
690 if (shared_->audio_processing()) { 685 shared_->set_audio_processing(nullptr);
691 shared_->set_audio_processing(nullptr);
692 }
693 686
694 return shared_->statistics().SetUnInitialized(); 687 return shared_->statistics().SetUnInitialized();
695 } 688 }
696 689
697 void VoEBaseImpl::GetPlayoutData(int sample_rate, size_t number_of_channels, 690 void VoEBaseImpl::GetPlayoutData(int sample_rate, size_t number_of_channels,
698 size_t number_of_frames, bool feed_data_to_apm, 691 size_t number_of_frames, bool feed_data_to_apm,
699 void* audio_data, int64_t* elapsed_time_ms, 692 void* audio_data, int64_t* elapsed_time_ms,
700 int64_t* ntp_time_ms) { 693 int64_t* ntp_time_ms) {
701 assert(shared_->output_mixer() != nullptr); 694 assert(shared_->output_mixer() != nullptr);
702 695
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 shared_->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, 739 shared_->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
747 "AssociateSendChannel() failed to locate accociate_send_channel"); 740 "AssociateSendChannel() failed to locate accociate_send_channel");
748 return -1; 741 return -1;
749 } 742 }
750 743
751 channel_ptr->set_associate_send_channel(ch); 744 channel_ptr->set_associate_send_channel(ch);
752 return 0; 745 return 0;
753 } 746 }
754 747
755 } // namespace webrtc 748 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698