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

Side by Side Diff: webrtc/modules/audio_processing/audio_processing_impl.cc

Issue 2444793005: Moved the AECM render sample queue into the audio processing module (Closed)
Patch Set: Rebase Created 4 years, 1 month 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 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 float* const* dest) { 701 float* const* dest) {
702 TRACE_EVENT0("webrtc", "AudioProcessing::ProcessStream_StreamConfig"); 702 TRACE_EVENT0("webrtc", "AudioProcessing::ProcessStream_StreamConfig");
703 ProcessingConfig processing_config; 703 ProcessingConfig processing_config;
704 bool reinitialization_required = false; 704 bool reinitialization_required = false;
705 { 705 {
706 // Acquire the capture lock in order to safely call the function 706 // Acquire the capture lock in order to safely call the function
707 // that retrieves the render side data. This function accesses apm 707 // that retrieves the render side data. This function accesses apm
708 // getters that need the capture lock held when being called. 708 // getters that need the capture lock held when being called.
709 rtc::CritScope cs_capture(&crit_capture_); 709 rtc::CritScope cs_capture(&crit_capture_);
710 EmptyQueuedRenderAudio(); 710 EmptyQueuedRenderAudio();
711 public_submodules_->echo_control_mobile->ReadQueuedRenderData();
712 public_submodules_->gain_control->ReadQueuedRenderData(); 711 public_submodules_->gain_control->ReadQueuedRenderData();
713 712
714 if (!src || !dest) { 713 if (!src || !dest) {
715 return kNullPointerError; 714 return kNullPointerError;
716 } 715 }
717 716
718 processing_config = formats_.api_format; 717 processing_config = formats_.api_format;
719 reinitialization_required = UpdateActiveSubmoduleStates(); 718 reinitialization_required = UpdateActiveSubmoduleStates();
720 } 719 }
721 720
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 &crit_debug_, &debug_dump_.capture)); 762 &crit_debug_, &debug_dump_.capture));
764 } 763 }
765 #endif 764 #endif
766 765
767 return kNoError; 766 return kNoError;
768 } 767 }
769 768
770 void AudioProcessingImpl::QueueRenderAudio(const AudioBuffer* audio) { 769 void AudioProcessingImpl::QueueRenderAudio(const AudioBuffer* audio) {
771 EchoCancellationImpl::PackRenderAudioBuffer(audio, num_output_channels(), 770 EchoCancellationImpl::PackRenderAudioBuffer(audio, num_output_channels(),
772 num_reverse_channels(), 771 num_reverse_channels(),
773 &render_queue_buffer_); 772 &float_render_queue_buffer_);
774 773
775 RTC_DCHECK_GE(160u, audio->num_frames_per_band()); 774 RTC_DCHECK_GE(160u, audio->num_frames_per_band());
776 775
777 // Insert the samples into the queue. 776 // Insert the samples into the queue.
778 if (!render_signal_queue_->Insert(&render_queue_buffer_)) { 777 if (!float_render_signal_queue_->Insert(&float_render_queue_buffer_)) {
779 // The data queue is full and needs to be emptied. 778 // The data queue is full and needs to be emptied.
780 EmptyQueuedRenderAudio(); 779 EmptyQueuedRenderAudio();
781 780
782 // Retry the insert (should always work). 781 // Retry the insert (should always work).
783 bool result = render_signal_queue_->Insert(&render_queue_buffer_); 782 bool result =
783 float_render_signal_queue_->Insert(&float_render_queue_buffer_);
784 RTC_DCHECK(result);
785 }
786
787 EchoControlMobileImpl::PackRenderAudioBuffer(audio, num_output_channels(),
788 num_reverse_channels(),
789 &int16_render_queue_buffer_);
790
791 // Insert the samples into the queue.
792 if (!int16_render_signal_queue_->Insert(&int16_render_queue_buffer_)) {
793 // The data queue is full and needs to be emptied.
794 EmptyQueuedRenderAudio();
795
796 // Retry the insert (should always work).
797 bool result =
798 int16_render_signal_queue_->Insert(&int16_render_queue_buffer_);
784 RTC_DCHECK(result); 799 RTC_DCHECK(result);
785 } 800 }
786 } 801 }
787 802
788 void AudioProcessingImpl::AllocateRenderQueue() { 803 void AudioProcessingImpl::AllocateRenderQueue() {
789 const size_t new_render_queue_element_max_size = 804 const size_t new_float_render_queue_element_max_size =
790 std::max(static_cast<size_t>(1), 805 std::max(static_cast<size_t>(1),
791 kMaxAllowedValuesOfSamplesPerFrame * 806 kMaxAllowedValuesOfSamplesPerFrame *
792 EchoCancellationImpl::NumCancellersRequired( 807 EchoCancellationImpl::NumCancellersRequired(
793 num_output_channels(), num_reverse_channels())); 808 num_output_channels(), num_reverse_channels()));
794 809
795 // Reallocate the queue if the queue item size is too small to fit the 810 const size_t new_int16_render_queue_element_max_size =
796 // data to put in the queue. 811 std::max(static_cast<size_t>(1),
797 if (render_queue_element_max_size_ < new_render_queue_element_max_size) { 812 kMaxAllowedValuesOfSamplesPerFrame *
798 render_queue_element_max_size_ = new_render_queue_element_max_size; 813 EchoControlMobileImpl::NumCancellersRequired(
814 num_output_channels(), num_reverse_channels()));
799 815
800 std::vector<float> template_queue_element(render_queue_element_max_size_); 816 // Reallocate the queues if the queue item sizes are too small to fit the
817 // data to put in the queues.
818 if (float_render_queue_element_max_size_ <
819 new_float_render_queue_element_max_size) {
820 float_render_queue_element_max_size_ =
821 new_float_render_queue_element_max_size;
801 822
802 render_signal_queue_.reset( 823 std::vector<float> template_queue_element(
824 float_render_queue_element_max_size_);
825
826 float_render_signal_queue_.reset(
803 new SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>( 827 new SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>(
804 kMaxNumFramesToBuffer, template_queue_element, 828 kMaxNumFramesToBuffer, template_queue_element,
805 RenderQueueItemVerifier<float>(render_queue_element_max_size_))); 829 RenderQueueItemVerifier<float>(
830 float_render_queue_element_max_size_)));
806 831
807 render_queue_buffer_.resize(render_queue_element_max_size_); 832 float_render_queue_buffer_.resize(float_render_queue_element_max_size_);
808 capture_queue_buffer_.resize(render_queue_element_max_size_); 833 float_capture_queue_buffer_.resize(float_render_queue_element_max_size_);
809 } else { 834 } else {
810 render_signal_queue_->Clear(); 835 float_render_signal_queue_->Clear();
836 }
837
838 if (int16_render_queue_element_max_size_ <
839 new_int16_render_queue_element_max_size) {
840 int16_render_queue_element_max_size_ =
841 new_int16_render_queue_element_max_size;
842
843 std::vector<int16_t> template_queue_element(
844 int16_render_queue_element_max_size_);
845
846 int16_render_signal_queue_.reset(
847 new SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>(
848 kMaxNumFramesToBuffer, template_queue_element,
849 RenderQueueItemVerifier<int16_t>(
850 int16_render_queue_element_max_size_)));
851
852 int16_render_queue_buffer_.resize(int16_render_queue_element_max_size_);
853 int16_capture_queue_buffer_.resize(int16_render_queue_element_max_size_);
854 } else {
855 int16_render_signal_queue_->Clear();
811 } 856 }
812 } 857 }
813 858
814 void AudioProcessingImpl::EmptyQueuedRenderAudio() { 859 void AudioProcessingImpl::EmptyQueuedRenderAudio() {
815 rtc::CritScope cs_capture(&crit_capture_); 860 rtc::CritScope cs_capture(&crit_capture_);
816 while (render_signal_queue_->Remove(&capture_queue_buffer_)) { 861 while (float_render_signal_queue_->Remove(&float_capture_queue_buffer_)) {
817 public_submodules_->echo_cancellation->ProcessRenderAudio( 862 public_submodules_->echo_cancellation->ProcessRenderAudio(
818 capture_queue_buffer_); 863 float_capture_queue_buffer_);
864 }
865
866 while (int16_render_signal_queue_->Remove(&int16_capture_queue_buffer_)) {
867 public_submodules_->echo_control_mobile->ProcessRenderAudio(
868 int16_capture_queue_buffer_);
819 } 869 }
820 } 870 }
821 871
822 int AudioProcessingImpl::ProcessStream(AudioFrame* frame) { 872 int AudioProcessingImpl::ProcessStream(AudioFrame* frame) {
823 TRACE_EVENT0("webrtc", "AudioProcessing::ProcessStream_AudioFrame"); 873 TRACE_EVENT0("webrtc", "AudioProcessing::ProcessStream_AudioFrame");
824 { 874 {
825 // Acquire the capture lock in order to safely call the function 875 // Acquire the capture lock in order to safely call the function
826 // that retrieves the render side data. This function accesses apm 876 // that retrieves the render side data. This function accesses apm
827 // getters that need the capture lock held when being called. 877 // getters that need the capture lock held when being called.
828 // The lock needs to be released as 878 // The lock needs to be released as
829 // public_submodules_->echo_control_mobile->is_enabled() aquires this lock 879 // public_submodules_->echo_control_mobile->is_enabled() aquires this lock
830 // as well. 880 // as well.
831 rtc::CritScope cs_capture(&crit_capture_); 881 rtc::CritScope cs_capture(&crit_capture_);
832 EmptyQueuedRenderAudio(); 882 EmptyQueuedRenderAudio();
833 public_submodules_->echo_control_mobile->ReadQueuedRenderData();
834 public_submodules_->gain_control->ReadQueuedRenderData(); 883 public_submodules_->gain_control->ReadQueuedRenderData();
835 } 884 }
836 885
837 if (!frame) { 886 if (!frame) {
838 return kNullPointerError; 887 return kNullPointerError;
839 } 888 }
840 // Must be a native rate. 889 // Must be a native rate.
841 if (frame->sample_rate_hz_ != kSampleRate8kHz && 890 if (frame->sample_rate_hz_ != kSampleRate8kHz &&
842 frame->sample_rate_hz_ != kSampleRate16kHz && 891 frame->sample_rate_hz_ != kSampleRate16kHz &&
843 frame->sample_rate_hz_ != kSampleRate32kHz && 892 frame->sample_rate_hz_ != kSampleRate32kHz &&
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 } 1235 }
1187 1236
1188 #if WEBRTC_INTELLIGIBILITY_ENHANCER 1237 #if WEBRTC_INTELLIGIBILITY_ENHANCER
1189 if (capture_nonlocked_.intelligibility_enabled) { 1238 if (capture_nonlocked_.intelligibility_enabled) {
1190 public_submodules_->intelligibility_enhancer->ProcessRenderAudio( 1239 public_submodules_->intelligibility_enhancer->ProcessRenderAudio(
1191 render_buffer); 1240 render_buffer);
1192 } 1241 }
1193 #endif 1242 #endif
1194 1243
1195 QueueRenderAudio(render_buffer); 1244 QueueRenderAudio(render_buffer);
1196 RETURN_ON_ERR(public_submodules_->echo_control_mobile->ProcessRenderAudio(
1197 render_buffer));
1198 if (!constants_.use_experimental_agc) { 1245 if (!constants_.use_experimental_agc) {
1199 RETURN_ON_ERR( 1246 RETURN_ON_ERR(
1200 public_submodules_->gain_control->ProcessRenderAudio(render_buffer)); 1247 public_submodules_->gain_control->ProcessRenderAudio(render_buffer));
1201 } 1248 }
1202 1249
1203 if (submodule_states_.RenderMultiBandProcessingActive() && 1250 if (submodule_states_.RenderMultiBandProcessingActive() &&
1204 SampleRateSupportsMultiBand( 1251 SampleRateSupportsMultiBand(
1205 formats_.render_processing_format.sample_rate_hz())) { 1252 formats_.render_processing_format.sample_rate_hz())) {
1206 render_buffer->MergeFrequencyBands(); 1253 render_buffer->MergeFrequencyBands();
1207 } 1254 }
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
1655 capture_processing_format(kSampleRate16kHz), 1702 capture_processing_format(kSampleRate16kHz),
1656 split_rate(kSampleRate16kHz) {} 1703 split_rate(kSampleRate16kHz) {}
1657 1704
1658 AudioProcessingImpl::ApmCaptureState::~ApmCaptureState() = default; 1705 AudioProcessingImpl::ApmCaptureState::~ApmCaptureState() = default;
1659 1706
1660 AudioProcessingImpl::ApmRenderState::ApmRenderState() = default; 1707 AudioProcessingImpl::ApmRenderState::ApmRenderState() = default;
1661 1708
1662 AudioProcessingImpl::ApmRenderState::~ApmRenderState() = default; 1709 AudioProcessingImpl::ApmRenderState::~ApmRenderState() = default;
1663 1710
1664 } // namespace webrtc 1711 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/audio_processing_impl.h ('k') | webrtc/modules/audio_processing/echo_control_mobile_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698