| 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 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_->gain_control->ReadQueuedRenderData(); | |
| 712 | 711 |
| 713 if (!src || !dest) { | 712 if (!src || !dest) { |
| 714 return kNullPointerError; | 713 return kNullPointerError; |
| 715 } | 714 } |
| 716 | 715 |
| 717 processing_config = formats_.api_format; | 716 processing_config = formats_.api_format; |
| 718 reinitialization_required = UpdateActiveSubmoduleStates(); | 717 reinitialization_required = UpdateActiveSubmoduleStates(); |
| 719 } | 718 } |
| 720 | 719 |
| 721 processing_config.input_stream() = input_config; | 720 processing_config.input_stream() = input_config; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 msg->add_output_channel(dest[i], channel_size); | 758 msg->add_output_channel(dest[i], channel_size); |
| 760 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), | 759 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), |
| 761 &debug_dump_.num_bytes_left_for_log_, | 760 &debug_dump_.num_bytes_left_for_log_, |
| 762 &crit_debug_, &debug_dump_.capture)); | 761 &crit_debug_, &debug_dump_.capture)); |
| 763 } | 762 } |
| 764 #endif | 763 #endif |
| 765 | 764 |
| 766 return kNoError; | 765 return kNoError; |
| 767 } | 766 } |
| 768 | 767 |
| 769 void AudioProcessingImpl::QueueRenderAudio(const AudioBuffer* audio) { | 768 void AudioProcessingImpl::QueueRenderAudio(AudioBuffer* audio) { |
| 770 EchoCancellationImpl::PackRenderAudioBuffer(audio, num_output_channels(), | 769 EchoCancellationImpl::PackRenderAudioBuffer(audio, num_output_channels(), |
| 771 num_reverse_channels(), | 770 num_reverse_channels(), |
| 772 &float_render_queue_buffer_); | 771 &aec_render_queue_buffer_); |
| 773 | 772 |
| 774 RTC_DCHECK_GE(160u, audio->num_frames_per_band()); | 773 RTC_DCHECK_GE(160u, audio->num_frames_per_band()); |
| 775 | 774 |
| 776 // Insert the samples into the queue. | 775 // Insert the samples into the queue. |
| 777 if (!float_render_signal_queue_->Insert(&float_render_queue_buffer_)) { | 776 if (!aec_render_signal_queue_->Insert(&aec_render_queue_buffer_)) { |
| 778 // The data queue is full and needs to be emptied. | 777 // The data queue is full and needs to be emptied. |
| 779 EmptyQueuedRenderAudio(); | 778 EmptyQueuedRenderAudio(); |
| 780 | 779 |
| 781 // Retry the insert (should always work). | 780 // Retry the insert (should always work). |
| 782 bool result = | 781 bool result = aec_render_signal_queue_->Insert(&aec_render_queue_buffer_); |
| 783 float_render_signal_queue_->Insert(&float_render_queue_buffer_); | |
| 784 RTC_DCHECK(result); | 782 RTC_DCHECK(result); |
| 785 } | 783 } |
| 786 | 784 |
| 787 EchoControlMobileImpl::PackRenderAudioBuffer(audio, num_output_channels(), | 785 EchoControlMobileImpl::PackRenderAudioBuffer(audio, num_output_channels(), |
| 788 num_reverse_channels(), | 786 num_reverse_channels(), |
| 789 &int16_render_queue_buffer_); | 787 &aecm_render_queue_buffer_); |
| 790 | 788 |
| 791 // Insert the samples into the queue. | 789 // Insert the samples into the queue. |
| 792 if (!int16_render_signal_queue_->Insert(&int16_render_queue_buffer_)) { | 790 if (!aecm_render_signal_queue_->Insert(&aecm_render_queue_buffer_)) { |
| 793 // The data queue is full and needs to be emptied. | 791 // The data queue is full and needs to be emptied. |
| 794 EmptyQueuedRenderAudio(); | 792 EmptyQueuedRenderAudio(); |
| 795 | 793 |
| 796 // Retry the insert (should always work). | 794 // Retry the insert (should always work). |
| 797 bool result = | 795 bool result = aecm_render_signal_queue_->Insert(&aecm_render_queue_buffer_); |
| 798 int16_render_signal_queue_->Insert(&int16_render_queue_buffer_); | |
| 799 RTC_DCHECK(result); | 796 RTC_DCHECK(result); |
| 800 } | 797 } |
| 798 |
| 799 if (!constants_.use_experimental_agc) { |
| 800 GainControlImpl::PackRenderAudioBuffer(audio, &agc_render_queue_buffer_); |
| 801 // Insert the samples into the queue. |
| 802 if (!agc_render_signal_queue_->Insert(&agc_render_queue_buffer_)) { |
| 803 // The data queue is full and needs to be emptied. |
| 804 EmptyQueuedRenderAudio(); |
| 805 |
| 806 // Retry the insert (should always work). |
| 807 bool result = agc_render_signal_queue_->Insert(&agc_render_queue_buffer_); |
| 808 RTC_DCHECK(result); |
| 809 } |
| 810 } |
| 801 } | 811 } |
| 802 | 812 |
| 803 void AudioProcessingImpl::AllocateRenderQueue() { | 813 void AudioProcessingImpl::AllocateRenderQueue() { |
| 804 const size_t new_float_render_queue_element_max_size = | 814 const size_t new_aec_render_queue_element_max_size = |
| 805 std::max(static_cast<size_t>(1), | 815 std::max(static_cast<size_t>(1), |
| 806 kMaxAllowedValuesOfSamplesPerFrame * | 816 kMaxAllowedValuesOfSamplesPerFrame * |
| 807 EchoCancellationImpl::NumCancellersRequired( | 817 EchoCancellationImpl::NumCancellersRequired( |
| 808 num_output_channels(), num_reverse_channels())); | 818 num_output_channels(), num_reverse_channels())); |
| 809 | 819 |
| 810 const size_t new_int16_render_queue_element_max_size = | 820 const size_t new_aecm_render_queue_element_max_size = |
| 811 std::max(static_cast<size_t>(1), | 821 std::max(static_cast<size_t>(1), |
| 812 kMaxAllowedValuesOfSamplesPerFrame * | 822 kMaxAllowedValuesOfSamplesPerFrame * |
| 813 EchoControlMobileImpl::NumCancellersRequired( | 823 EchoControlMobileImpl::NumCancellersRequired( |
| 814 num_output_channels(), num_reverse_channels())); | 824 num_output_channels(), num_reverse_channels())); |
| 815 | 825 |
| 826 const size_t new_agc_render_queue_element_max_size = |
| 827 std::max(static_cast<size_t>(1), kMaxAllowedValuesOfSamplesPerFrame); |
| 828 |
| 816 // Reallocate the queues if the queue item sizes are too small to fit the | 829 // Reallocate the queues if the queue item sizes are too small to fit the |
| 817 // data to put in the queues. | 830 // data to put in the queues. |
| 818 if (float_render_queue_element_max_size_ < | 831 if (aec_render_queue_element_max_size_ < |
| 819 new_float_render_queue_element_max_size) { | 832 new_aec_render_queue_element_max_size) { |
| 820 float_render_queue_element_max_size_ = | 833 aec_render_queue_element_max_size_ = new_aec_render_queue_element_max_size; |
| 821 new_float_render_queue_element_max_size; | |
| 822 | 834 |
| 823 std::vector<float> template_queue_element( | 835 std::vector<float> template_queue_element( |
| 824 float_render_queue_element_max_size_); | 836 aec_render_queue_element_max_size_); |
| 825 | 837 |
| 826 float_render_signal_queue_.reset( | 838 aec_render_signal_queue_.reset( |
| 827 new SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>( | 839 new SwapQueue<std::vector<float>, RenderQueueItemVerifier<float>>( |
| 828 kMaxNumFramesToBuffer, template_queue_element, | 840 kMaxNumFramesToBuffer, template_queue_element, |
| 829 RenderQueueItemVerifier<float>( | 841 RenderQueueItemVerifier<float>( |
| 830 float_render_queue_element_max_size_))); | 842 aec_render_queue_element_max_size_))); |
| 831 | 843 |
| 832 float_render_queue_buffer_.resize(float_render_queue_element_max_size_); | 844 aec_render_queue_buffer_.resize(aec_render_queue_element_max_size_); |
| 833 float_capture_queue_buffer_.resize(float_render_queue_element_max_size_); | 845 aec_capture_queue_buffer_.resize(aec_render_queue_element_max_size_); |
| 834 } else { | 846 } else { |
| 835 float_render_signal_queue_->Clear(); | 847 aec_render_signal_queue_->Clear(); |
| 836 } | 848 } |
| 837 | 849 |
| 838 if (int16_render_queue_element_max_size_ < | 850 if (aecm_render_queue_element_max_size_ < |
| 839 new_int16_render_queue_element_max_size) { | 851 new_aecm_render_queue_element_max_size) { |
| 840 int16_render_queue_element_max_size_ = | 852 aecm_render_queue_element_max_size_ = |
| 841 new_int16_render_queue_element_max_size; | 853 new_aecm_render_queue_element_max_size; |
| 842 | 854 |
| 843 std::vector<int16_t> template_queue_element( | 855 std::vector<int16_t> template_queue_element( |
| 844 int16_render_queue_element_max_size_); | 856 aecm_render_queue_element_max_size_); |
| 845 | 857 |
| 846 int16_render_signal_queue_.reset( | 858 aecm_render_signal_queue_.reset( |
| 847 new SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>( | 859 new SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>( |
| 848 kMaxNumFramesToBuffer, template_queue_element, | 860 kMaxNumFramesToBuffer, template_queue_element, |
| 849 RenderQueueItemVerifier<int16_t>( | 861 RenderQueueItemVerifier<int16_t>( |
| 850 int16_render_queue_element_max_size_))); | 862 aecm_render_queue_element_max_size_))); |
| 851 | 863 |
| 852 int16_render_queue_buffer_.resize(int16_render_queue_element_max_size_); | 864 aecm_render_queue_buffer_.resize(aecm_render_queue_element_max_size_); |
| 853 int16_capture_queue_buffer_.resize(int16_render_queue_element_max_size_); | 865 aecm_capture_queue_buffer_.resize(aecm_render_queue_element_max_size_); |
| 854 } else { | 866 } else { |
| 855 int16_render_signal_queue_->Clear(); | 867 aecm_render_signal_queue_->Clear(); |
| 868 } |
| 869 |
| 870 if (agc_render_queue_element_max_size_ < |
| 871 new_agc_render_queue_element_max_size) { |
| 872 agc_render_queue_element_max_size_ = new_agc_render_queue_element_max_size; |
| 873 |
| 874 std::vector<int16_t> template_queue_element( |
| 875 agc_render_queue_element_max_size_); |
| 876 |
| 877 agc_render_signal_queue_.reset( |
| 878 new SwapQueue<std::vector<int16_t>, RenderQueueItemVerifier<int16_t>>( |
| 879 kMaxNumFramesToBuffer, template_queue_element, |
| 880 RenderQueueItemVerifier<int16_t>( |
| 881 agc_render_queue_element_max_size_))); |
| 882 |
| 883 agc_render_queue_buffer_.resize(agc_render_queue_element_max_size_); |
| 884 agc_capture_queue_buffer_.resize(agc_render_queue_element_max_size_); |
| 885 } else { |
| 886 agc_render_signal_queue_->Clear(); |
| 856 } | 887 } |
| 857 } | 888 } |
| 858 | 889 |
| 859 void AudioProcessingImpl::EmptyQueuedRenderAudio() { | 890 void AudioProcessingImpl::EmptyQueuedRenderAudio() { |
| 860 rtc::CritScope cs_capture(&crit_capture_); | 891 rtc::CritScope cs_capture(&crit_capture_); |
| 861 while (float_render_signal_queue_->Remove(&float_capture_queue_buffer_)) { | 892 while (aec_render_signal_queue_->Remove(&aec_capture_queue_buffer_)) { |
| 862 public_submodules_->echo_cancellation->ProcessRenderAudio( | 893 public_submodules_->echo_cancellation->ProcessRenderAudio( |
| 863 float_capture_queue_buffer_); | 894 aec_capture_queue_buffer_); |
| 864 } | 895 } |
| 865 | 896 |
| 866 while (int16_render_signal_queue_->Remove(&int16_capture_queue_buffer_)) { | 897 while (aecm_render_signal_queue_->Remove(&aecm_capture_queue_buffer_)) { |
| 867 public_submodules_->echo_control_mobile->ProcessRenderAudio( | 898 public_submodules_->echo_control_mobile->ProcessRenderAudio( |
| 868 int16_capture_queue_buffer_); | 899 aecm_capture_queue_buffer_); |
| 900 } |
| 901 |
| 902 while (agc_render_signal_queue_->Remove(&agc_capture_queue_buffer_)) { |
| 903 public_submodules_->gain_control->ProcessRenderAudio( |
| 904 agc_capture_queue_buffer_); |
| 869 } | 905 } |
| 870 } | 906 } |
| 871 | 907 |
| 872 int AudioProcessingImpl::ProcessStream(AudioFrame* frame) { | 908 int AudioProcessingImpl::ProcessStream(AudioFrame* frame) { |
| 873 TRACE_EVENT0("webrtc", "AudioProcessing::ProcessStream_AudioFrame"); | 909 TRACE_EVENT0("webrtc", "AudioProcessing::ProcessStream_AudioFrame"); |
| 874 { | 910 { |
| 875 // Acquire the capture lock in order to safely call the function | 911 // Acquire the capture lock in order to safely call the function |
| 876 // that retrieves the render side data. This function accesses apm | 912 // that retrieves the render side data. This function accesses apm |
| 877 // getters that need the capture lock held when being called. | 913 // getters that need the capture lock held when being called. |
| 878 // The lock needs to be released as | 914 // The lock needs to be released as |
| 879 // public_submodules_->echo_control_mobile->is_enabled() aquires this lock | 915 // public_submodules_->echo_control_mobile->is_enabled() aquires this lock |
| 880 // as well. | 916 // as well. |
| 881 rtc::CritScope cs_capture(&crit_capture_); | 917 rtc::CritScope cs_capture(&crit_capture_); |
| 882 EmptyQueuedRenderAudio(); | 918 EmptyQueuedRenderAudio(); |
| 883 public_submodules_->gain_control->ReadQueuedRenderData(); | |
| 884 } | 919 } |
| 885 | 920 |
| 886 if (!frame) { | 921 if (!frame) { |
| 887 return kNullPointerError; | 922 return kNullPointerError; |
| 888 } | 923 } |
| 889 // Must be a native rate. | 924 // Must be a native rate. |
| 890 if (frame->sample_rate_hz_ != kSampleRate8kHz && | 925 if (frame->sample_rate_hz_ != kSampleRate8kHz && |
| 891 frame->sample_rate_hz_ != kSampleRate16kHz && | 926 frame->sample_rate_hz_ != kSampleRate16kHz && |
| 892 frame->sample_rate_hz_ != kSampleRate32kHz && | 927 frame->sample_rate_hz_ != kSampleRate32kHz && |
| 893 frame->sample_rate_hz_ != kSampleRate48kHz) { | 928 frame->sample_rate_hz_ != kSampleRate48kHz) { |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1235 } | 1270 } |
| 1236 | 1271 |
| 1237 #if WEBRTC_INTELLIGIBILITY_ENHANCER | 1272 #if WEBRTC_INTELLIGIBILITY_ENHANCER |
| 1238 if (capture_nonlocked_.intelligibility_enabled) { | 1273 if (capture_nonlocked_.intelligibility_enabled) { |
| 1239 public_submodules_->intelligibility_enhancer->ProcessRenderAudio( | 1274 public_submodules_->intelligibility_enhancer->ProcessRenderAudio( |
| 1240 render_buffer); | 1275 render_buffer); |
| 1241 } | 1276 } |
| 1242 #endif | 1277 #endif |
| 1243 | 1278 |
| 1244 QueueRenderAudio(render_buffer); | 1279 QueueRenderAudio(render_buffer); |
| 1245 if (!constants_.use_experimental_agc) { | |
| 1246 RETURN_ON_ERR( | |
| 1247 public_submodules_->gain_control->ProcessRenderAudio(render_buffer)); | |
| 1248 } | |
| 1249 | 1280 |
| 1250 if (submodule_states_.RenderMultiBandProcessingActive() && | 1281 if (submodule_states_.RenderMultiBandProcessingActive() && |
| 1251 SampleRateSupportsMultiBand( | 1282 SampleRateSupportsMultiBand( |
| 1252 formats_.render_processing_format.sample_rate_hz())) { | 1283 formats_.render_processing_format.sample_rate_hz())) { |
| 1253 render_buffer->MergeFrequencyBands(); | 1284 render_buffer->MergeFrequencyBands(); |
| 1254 } | 1285 } |
| 1255 | 1286 |
| 1256 return kNoError; | 1287 return kNoError; |
| 1257 } | 1288 } |
| 1258 | 1289 |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1702 capture_processing_format(kSampleRate16kHz), | 1733 capture_processing_format(kSampleRate16kHz), |
| 1703 split_rate(kSampleRate16kHz) {} | 1734 split_rate(kSampleRate16kHz) {} |
| 1704 | 1735 |
| 1705 AudioProcessingImpl::ApmCaptureState::~ApmCaptureState() = default; | 1736 AudioProcessingImpl::ApmCaptureState::~ApmCaptureState() = default; |
| 1706 | 1737 |
| 1707 AudioProcessingImpl::ApmRenderState::ApmRenderState() = default; | 1738 AudioProcessingImpl::ApmRenderState::ApmRenderState() = default; |
| 1708 | 1739 |
| 1709 AudioProcessingImpl::ApmRenderState::~ApmRenderState() = default; | 1740 AudioProcessingImpl::ApmRenderState::~ApmRenderState() = default; |
| 1710 | 1741 |
| 1711 } // namespace webrtc | 1742 } // namespace webrtc |
| OLD | NEW |