| OLD | NEW |
| 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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) | 216 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) |
| 217 transient_suppressor_enabled_(false), | 217 transient_suppressor_enabled_(false), |
| 218 #else | 218 #else |
| 219 transient_suppressor_enabled_(config.Get<ExperimentalNs>().enabled), | 219 transient_suppressor_enabled_(config.Get<ExperimentalNs>().enabled), |
| 220 #endif | 220 #endif |
| 221 beamformer_enabled_(config.Get<Beamforming>().enabled), | 221 beamformer_enabled_(config.Get<Beamforming>().enabled), |
| 222 beamformer_(beamformer), | 222 beamformer_(beamformer), |
| 223 array_geometry_(config.Get<Beamforming>().array_geometry), | 223 array_geometry_(config.Get<Beamforming>().array_geometry), |
| 224 target_direction_(config.Get<Beamforming>().target_direction), | 224 target_direction_(config.Get<Beamforming>().target_direction), |
| 225 intelligibility_enabled_(config.Get<Intelligibility>().enabled) { | 225 intelligibility_enabled_(config.Get<Intelligibility>().enabled) { |
| 226 echo_cancellation_ = new EchoCancellationImpl(this, crit_); | 226 render_thread_checker_.DetachFromThread(); |
| 227 capture_thread_checker_.DetachFromThread(); |
| 228 |
| 229 echo_cancellation_ = |
| 230 new EchoCancellationImpl(this, crit_, &render_thread_checker_); |
| 227 component_list_.push_back(echo_cancellation_); | 231 component_list_.push_back(echo_cancellation_); |
| 228 | 232 |
| 229 echo_control_mobile_ = new EchoControlMobileImpl(this, crit_); | 233 echo_control_mobile_ = |
| 234 new EchoControlMobileImpl(this, crit_, &render_thread_checker_); |
| 230 component_list_.push_back(echo_control_mobile_); | 235 component_list_.push_back(echo_control_mobile_); |
| 231 | 236 |
| 232 gain_control_ = new GainControlImpl(this, crit_); | 237 gain_control_ = new GainControlImpl(this, crit_, &render_thread_checker_, |
| 238 &capture_thread_checker_); |
| 233 component_list_.push_back(gain_control_); | 239 component_list_.push_back(gain_control_); |
| 234 | 240 |
| 235 high_pass_filter_ = new HighPassFilterImpl(this, crit_); | 241 high_pass_filter_ = new HighPassFilterImpl(this, crit_); |
| 236 component_list_.push_back(high_pass_filter_); | 242 component_list_.push_back(high_pass_filter_); |
| 237 | 243 |
| 238 level_estimator_ = new LevelEstimatorImpl(this, crit_); | 244 level_estimator_ = new LevelEstimatorImpl(this, crit_); |
| 239 component_list_.push_back(level_estimator_); | 245 component_list_.push_back(level_estimator_); |
| 240 | 246 |
| 241 noise_suppression_ = new NoiseSuppressionImpl(this, crit_); | 247 noise_suppression_ = new NoiseSuppressionImpl(this, crit_); |
| 242 component_list_.push_back(noise_suppression_); | 248 component_list_.push_back(noise_suppression_); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 if (fwd_proc_format_.sample_rate_hz() == kSampleRate32kHz || | 452 if (fwd_proc_format_.sample_rate_hz() == kSampleRate32kHz || |
| 447 fwd_proc_format_.sample_rate_hz() == kSampleRate48kHz) { | 453 fwd_proc_format_.sample_rate_hz() == kSampleRate48kHz) { |
| 448 split_rate_ = kSampleRate16kHz; | 454 split_rate_ = kSampleRate16kHz; |
| 449 } else { | 455 } else { |
| 450 split_rate_ = fwd_proc_format_.sample_rate_hz(); | 456 split_rate_ = fwd_proc_format_.sample_rate_hz(); |
| 451 } | 457 } |
| 452 | 458 |
| 453 return InitializeLocked(); | 459 return InitializeLocked(); |
| 454 } | 460 } |
| 455 | 461 |
| 456 | |
| 457 void AudioProcessingImpl::SetExtraOptions(const Config& config) { | 462 void AudioProcessingImpl::SetExtraOptions(const Config& config) { |
| 458 CriticalSectionScoped crit_scoped(crit_); | 463 CriticalSectionScoped crit_scoped(crit_); |
| 459 for (auto item : component_list_) { | 464 for (auto item : component_list_) { |
| 460 item->SetExtraOptions(config); | 465 item->SetExtraOptions(config); |
| 461 } | 466 } |
| 462 | 467 |
| 463 if (transient_suppressor_enabled_ != config.Get<ExperimentalNs>().enabled) { | 468 if (transient_suppressor_enabled_ != config.Get<ExperimentalNs>().enabled) { |
| 464 transient_suppressor_enabled_ = config.Get<ExperimentalNs>().enabled; | 469 transient_suppressor_enabled_ = config.Get<ExperimentalNs>().enabled; |
| 465 InitializeTransient(); | 470 InitializeTransient(); |
| 466 } | 471 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 482 int AudioProcessingImpl::num_input_channels() const { | 487 int AudioProcessingImpl::num_input_channels() const { |
| 483 return shared_state_.api_format_.input_stream().num_channels(); | 488 return shared_state_.api_format_.input_stream().num_channels(); |
| 484 } | 489 } |
| 485 | 490 |
| 486 int AudioProcessingImpl::num_output_channels() const { | 491 int AudioProcessingImpl::num_output_channels() const { |
| 487 return shared_state_.api_format_.output_stream().num_channels(); | 492 return shared_state_.api_format_.output_stream().num_channels(); |
| 488 } | 493 } |
| 489 | 494 |
| 490 void AudioProcessingImpl::set_output_will_be_muted(bool muted) { | 495 void AudioProcessingImpl::set_output_will_be_muted(bool muted) { |
| 491 CriticalSectionScoped lock(crit_); | 496 CriticalSectionScoped lock(crit_); |
| 497 RTC_DCHECK(capture_thread_checker_.CalledOnValidThread()); |
| 492 output_will_be_muted_ = muted; | 498 output_will_be_muted_ = muted; |
| 493 if (agc_manager_.get()) { | 499 if (agc_manager_.get()) { |
| 494 agc_manager_->SetCaptureMuted(output_will_be_muted_); | 500 agc_manager_->SetCaptureMuted(output_will_be_muted_); |
| 495 } | 501 } |
| 496 } | 502 } |
| 497 | 503 |
| 498 | 504 |
| 499 int AudioProcessingImpl::ProcessStream(const float* const* src, | 505 int AudioProcessingImpl::ProcessStream(const float* const* src, |
| 500 size_t samples_per_channel, | 506 size_t samples_per_channel, |
| 501 int input_sample_rate_hz, | 507 int input_sample_rate_hz, |
| 502 ChannelLayout input_layout, | 508 ChannelLayout input_layout, |
| 503 int output_sample_rate_hz, | 509 int output_sample_rate_hz, |
| 504 ChannelLayout output_layout, | 510 ChannelLayout output_layout, |
| 505 float* const* dest) { | 511 float* const* dest) { |
| 506 CriticalSectionScoped crit_scoped(crit_); | 512 CriticalSectionScoped crit_scoped(crit_); |
| 513 RTC_DCHECK(capture_thread_checker_.CalledOnValidThread()); |
| 507 StreamConfig input_stream = shared_state_.api_format_.input_stream(); | 514 StreamConfig input_stream = shared_state_.api_format_.input_stream(); |
| 508 input_stream.set_sample_rate_hz(input_sample_rate_hz); | 515 input_stream.set_sample_rate_hz(input_sample_rate_hz); |
| 509 input_stream.set_num_channels(ChannelsFromLayout(input_layout)); | 516 input_stream.set_num_channels(ChannelsFromLayout(input_layout)); |
| 510 input_stream.set_has_keyboard(LayoutHasKeyboard(input_layout)); | 517 input_stream.set_has_keyboard(LayoutHasKeyboard(input_layout)); |
| 511 | 518 |
| 512 StreamConfig output_stream = shared_state_.api_format_.output_stream(); | 519 StreamConfig output_stream = shared_state_.api_format_.output_stream(); |
| 513 output_stream.set_sample_rate_hz(output_sample_rate_hz); | 520 output_stream.set_sample_rate_hz(output_sample_rate_hz); |
| 514 output_stream.set_num_channels(ChannelsFromLayout(output_layout)); | 521 output_stream.set_num_channels(ChannelsFromLayout(output_layout)); |
| 515 output_stream.set_has_keyboard(LayoutHasKeyboard(output_layout)); | 522 output_stream.set_has_keyboard(LayoutHasKeyboard(output_layout)); |
| 516 | 523 |
| 517 if (samples_per_channel != input_stream.num_frames()) { | 524 if (samples_per_channel != input_stream.num_frames()) { |
| 518 return kBadDataLengthError; | 525 return kBadDataLengthError; |
| 519 } | 526 } |
| 520 return ProcessStream(src, input_stream, output_stream, dest); | 527 return ProcessStream(src, input_stream, output_stream, dest); |
| 521 } | 528 } |
| 522 | 529 |
| 523 int AudioProcessingImpl::ProcessStream(const float* const* src, | 530 int AudioProcessingImpl::ProcessStream(const float* const* src, |
| 524 const StreamConfig& input_config, | 531 const StreamConfig& input_config, |
| 525 const StreamConfig& output_config, | 532 const StreamConfig& output_config, |
| 526 float* const* dest) { | 533 float* const* dest) { |
| 527 CriticalSectionScoped crit_scoped(crit_); | 534 CriticalSectionScoped crit_scoped(crit_); |
| 535 RTC_DCHECK(capture_thread_checker_.CalledOnValidThread()); |
| 528 if (!src || !dest) { | 536 if (!src || !dest) { |
| 529 return kNullPointerError; | 537 return kNullPointerError; |
| 530 } | 538 } |
| 531 | 539 |
| 532 echo_cancellation_->ReadQueuedRenderData(); | 540 echo_cancellation_->ReadQueuedRenderData(); |
| 533 echo_control_mobile_->ReadQueuedRenderData(); | 541 echo_control_mobile_->ReadQueuedRenderData(); |
| 534 gain_control_->ReadQueuedRenderData(); | 542 gain_control_->ReadQueuedRenderData(); |
| 535 | 543 |
| 536 ProcessingConfig processing_config = shared_state_.api_format_; | 544 ProcessingConfig processing_config = shared_state_.api_format_; |
| 537 processing_config.input_stream() = input_config; | 545 processing_config.input_stream() = input_config; |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 RETURN_ON_ERR(level_estimator_->ProcessStream(ca)); | 721 RETURN_ON_ERR(level_estimator_->ProcessStream(ca)); |
| 714 | 722 |
| 715 was_stream_delay_set_ = false; | 723 was_stream_delay_set_ = false; |
| 716 return kNoError; | 724 return kNoError; |
| 717 } | 725 } |
| 718 | 726 |
| 719 int AudioProcessingImpl::AnalyzeReverseStream(const float* const* data, | 727 int AudioProcessingImpl::AnalyzeReverseStream(const float* const* data, |
| 720 size_t samples_per_channel, | 728 size_t samples_per_channel, |
| 721 int rev_sample_rate_hz, | 729 int rev_sample_rate_hz, |
| 722 ChannelLayout layout) { | 730 ChannelLayout layout) { |
| 731 RTC_DCHECK(render_thread_checker_.CalledOnValidThread()); |
| 723 const StreamConfig reverse_config = { | 732 const StreamConfig reverse_config = { |
| 724 rev_sample_rate_hz, ChannelsFromLayout(layout), LayoutHasKeyboard(layout), | 733 rev_sample_rate_hz, ChannelsFromLayout(layout), LayoutHasKeyboard(layout), |
| 725 }; | 734 }; |
| 726 if (samples_per_channel != reverse_config.num_frames()) { | 735 if (samples_per_channel != reverse_config.num_frames()) { |
| 727 return kBadDataLengthError; | 736 return kBadDataLengthError; |
| 728 } | 737 } |
| 729 return AnalyzeReverseStream(data, reverse_config, reverse_config); | 738 return AnalyzeReverseStream(data, reverse_config, reverse_config); |
| 730 } | 739 } |
| 731 | 740 |
| 732 int AudioProcessingImpl::ProcessReverseStream( | 741 int AudioProcessingImpl::ProcessReverseStream( |
| 733 const float* const* src, | 742 const float* const* src, |
| 734 const StreamConfig& reverse_input_config, | 743 const StreamConfig& reverse_input_config, |
| 735 const StreamConfig& reverse_output_config, | 744 const StreamConfig& reverse_output_config, |
| 736 float* const* dest) { | 745 float* const* dest) { |
| 746 RTC_DCHECK(render_thread_checker_.CalledOnValidThread()); |
| 737 RETURN_ON_ERR( | 747 RETURN_ON_ERR( |
| 738 AnalyzeReverseStream(src, reverse_input_config, reverse_output_config)); | 748 AnalyzeReverseStream(src, reverse_input_config, reverse_output_config)); |
| 739 if (is_rev_processed()) { | 749 if (is_rev_processed()) { |
| 740 render_audio_->CopyTo(shared_state_.api_format_.reverse_output_stream(), | 750 render_audio_->CopyTo(shared_state_.api_format_.reverse_output_stream(), |
| 741 dest); | 751 dest); |
| 742 } else if (rev_conversion_needed()) { | 752 } else if (rev_conversion_needed()) { |
| 743 render_converter_->Convert(src, reverse_input_config.num_samples(), dest, | 753 render_converter_->Convert(src, reverse_input_config.num_samples(), dest, |
| 744 reverse_output_config.num_samples()); | 754 reverse_output_config.num_samples()); |
| 745 } else { | 755 } else { |
| 746 CopyAudioIfNeeded(src, reverse_input_config.num_frames(), | 756 CopyAudioIfNeeded(src, reverse_input_config.num_frames(), |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 RETURN_ON_ERR(WriteMessageToDebugFile()); | 795 RETURN_ON_ERR(WriteMessageToDebugFile()); |
| 786 } | 796 } |
| 787 #endif | 797 #endif |
| 788 | 798 |
| 789 render_audio_->CopyFrom(src, | 799 render_audio_->CopyFrom(src, |
| 790 shared_state_.api_format_.reverse_input_stream()); | 800 shared_state_.api_format_.reverse_input_stream()); |
| 791 return ProcessReverseStreamLocked(); | 801 return ProcessReverseStreamLocked(); |
| 792 } | 802 } |
| 793 | 803 |
| 794 int AudioProcessingImpl::ProcessReverseStream(AudioFrame* frame) { | 804 int AudioProcessingImpl::ProcessReverseStream(AudioFrame* frame) { |
| 805 RTC_DCHECK(render_thread_checker_.CalledOnValidThread()); |
| 795 RETURN_ON_ERR(AnalyzeReverseStream(frame)); | 806 RETURN_ON_ERR(AnalyzeReverseStream(frame)); |
| 796 if (is_rev_processed()) { | 807 if (is_rev_processed()) { |
| 797 render_audio_->InterleaveTo(frame, true); | 808 render_audio_->InterleaveTo(frame, true); |
| 798 } | 809 } |
| 799 | 810 |
| 800 return kNoError; | 811 return kNoError; |
| 801 } | 812 } |
| 802 | 813 |
| 803 int AudioProcessingImpl::AnalyzeReverseStream(AudioFrame* frame) { | 814 int AudioProcessingImpl::AnalyzeReverseStream(AudioFrame* frame) { |
| 815 RTC_DCHECK(render_thread_checker_.CalledOnValidThread()); |
| 804 CriticalSectionScoped crit_scoped(crit_); | 816 CriticalSectionScoped crit_scoped(crit_); |
| 805 if (frame == NULL) { | 817 if (frame == NULL) { |
| 806 return kNullPointerError; | 818 return kNullPointerError; |
| 807 } | 819 } |
| 808 // Must be a native rate. | 820 // Must be a native rate. |
| 809 if (frame->sample_rate_hz_ != kSampleRate8kHz && | 821 if (frame->sample_rate_hz_ != kSampleRate8kHz && |
| 810 frame->sample_rate_hz_ != kSampleRate16kHz && | 822 frame->sample_rate_hz_ != kSampleRate16kHz && |
| 811 frame->sample_rate_hz_ != kSampleRate32kHz && | 823 frame->sample_rate_hz_ != kSampleRate32kHz && |
| 812 frame->sample_rate_hz_ != kSampleRate48kHz) { | 824 frame->sample_rate_hz_ != kSampleRate48kHz) { |
| 813 return kBadSampleRateError; | 825 return kBadSampleRateError; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 | 915 |
| 904 bool AudioProcessingImpl::was_stream_delay_set() const { | 916 bool AudioProcessingImpl::was_stream_delay_set() const { |
| 905 return was_stream_delay_set_; | 917 return was_stream_delay_set_; |
| 906 } | 918 } |
| 907 | 919 |
| 908 void AudioProcessingImpl::set_stream_key_pressed(bool key_pressed) { | 920 void AudioProcessingImpl::set_stream_key_pressed(bool key_pressed) { |
| 909 key_pressed_ = key_pressed; | 921 key_pressed_ = key_pressed; |
| 910 } | 922 } |
| 911 | 923 |
| 912 void AudioProcessingImpl::set_delay_offset_ms(int offset) { | 924 void AudioProcessingImpl::set_delay_offset_ms(int offset) { |
| 925 RTC_DCHECK(capture_thread_checker_.CalledOnValidThread()); |
| 913 CriticalSectionScoped crit_scoped(crit_); | 926 CriticalSectionScoped crit_scoped(crit_); |
| 914 delay_offset_ms_ = offset; | 927 delay_offset_ms_ = offset; |
| 915 } | 928 } |
| 916 | 929 |
| 917 int AudioProcessingImpl::delay_offset_ms() const { | 930 int AudioProcessingImpl::delay_offset_ms() const { |
| 931 RTC_DCHECK(capture_thread_checker_.CalledOnValidThread()); |
| 918 return delay_offset_ms_; | 932 return delay_offset_ms_; |
| 919 } | 933 } |
| 920 | 934 |
| 921 int AudioProcessingImpl::StartDebugRecording( | 935 int AudioProcessingImpl::StartDebugRecording( |
| 922 const char filename[AudioProcessing::kMaxFilenameSize]) { | 936 const char filename[AudioProcessing::kMaxFilenameSize]) { |
| 923 CriticalSectionScoped crit_scoped(crit_); | 937 CriticalSectionScoped crit_scoped(crit_); |
| 924 static_assert(kMaxFilenameSize == FileWrapper::kMaxFileNameSize, ""); | 938 static_assert(kMaxFilenameSize == FileWrapper::kMaxFileNameSize, ""); |
| 925 | 939 |
| 926 if (filename == NULL) { | 940 if (filename == NULL) { |
| 927 return kNullPointerError; | 941 return kNullPointerError; |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1287 | 1301 |
| 1288 event_msg_->set_type(audioproc::Event::CONFIG); | 1302 event_msg_->set_type(audioproc::Event::CONFIG); |
| 1289 event_msg_->mutable_config()->CopyFrom(config); | 1303 event_msg_->mutable_config()->CopyFrom(config); |
| 1290 | 1304 |
| 1291 RETURN_ON_ERR(WriteMessageToDebugFile()); | 1305 RETURN_ON_ERR(WriteMessageToDebugFile()); |
| 1292 return kNoError; | 1306 return kNoError; |
| 1293 } | 1307 } |
| 1294 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP | 1308 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 1295 | 1309 |
| 1296 } // namespace webrtc | 1310 } // namespace webrtc |
| OLD | NEW |