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 |
11 #include "webrtc/modules/audio_processing/audio_processing_impl.h" | 11 #include "webrtc/modules/audio_processing/audio_processing_impl.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 #include <algorithm> | 14 #include <algorithm> |
15 | 15 |
16 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
17 #include "webrtc/base/platform_file.h" | 17 #include "webrtc/base/platform_file.h" |
| 18 #include "webrtc/base/trace_event.h" |
18 #include "webrtc/common_audio/audio_converter.h" | 19 #include "webrtc/common_audio/audio_converter.h" |
19 #include "webrtc/common_audio/channel_buffer.h" | 20 #include "webrtc/common_audio/channel_buffer.h" |
20 #include "webrtc/common_audio/include/audio_util.h" | 21 #include "webrtc/common_audio/include/audio_util.h" |
21 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" | 22 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" |
22 extern "C" { | 23 extern "C" { |
23 #include "webrtc/modules/audio_processing/aec/aec_core.h" | 24 #include "webrtc/modules/audio_processing/aec/aec_core.h" |
24 } | 25 } |
25 #include "webrtc/modules/audio_processing/agc/agc_manager_direct.h" | 26 #include "webrtc/modules/audio_processing/agc/agc_manager_direct.h" |
26 #include "webrtc/modules/audio_processing/audio_buffer.h" | 27 #include "webrtc/modules/audio_processing/audio_buffer.h" |
27 #include "webrtc/modules/audio_processing/beamformer/nonlinear_beamformer.h" | 28 #include "webrtc/modules/audio_processing/beamformer/nonlinear_beamformer.h" |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 } | 541 } |
541 | 542 |
542 | 543 |
543 int AudioProcessingImpl::ProcessStream(const float* const* src, | 544 int AudioProcessingImpl::ProcessStream(const float* const* src, |
544 size_t samples_per_channel, | 545 size_t samples_per_channel, |
545 int input_sample_rate_hz, | 546 int input_sample_rate_hz, |
546 ChannelLayout input_layout, | 547 ChannelLayout input_layout, |
547 int output_sample_rate_hz, | 548 int output_sample_rate_hz, |
548 ChannelLayout output_layout, | 549 ChannelLayout output_layout, |
549 float* const* dest) { | 550 float* const* dest) { |
| 551 TRACE_EVENT0("webrtc", "AudioProcessing::ProcessStream_ChannelLayout"); |
550 StreamConfig input_stream; | 552 StreamConfig input_stream; |
551 StreamConfig output_stream; | 553 StreamConfig output_stream; |
552 { | 554 { |
553 // Access the formats_.api_format.input_stream beneath the capture lock. | 555 // Access the formats_.api_format.input_stream beneath the capture lock. |
554 // The lock must be released as it is later required in the call | 556 // The lock must be released as it is later required in the call |
555 // to ProcessStream(,,,); | 557 // to ProcessStream(,,,); |
556 rtc::CritScope cs(&crit_capture_); | 558 rtc::CritScope cs(&crit_capture_); |
557 input_stream = formats_.api_format.input_stream(); | 559 input_stream = formats_.api_format.input_stream(); |
558 output_stream = formats_.api_format.output_stream(); | 560 output_stream = formats_.api_format.output_stream(); |
559 } | 561 } |
560 | 562 |
561 input_stream.set_sample_rate_hz(input_sample_rate_hz); | 563 input_stream.set_sample_rate_hz(input_sample_rate_hz); |
562 input_stream.set_num_channels(ChannelsFromLayout(input_layout)); | 564 input_stream.set_num_channels(ChannelsFromLayout(input_layout)); |
563 input_stream.set_has_keyboard(LayoutHasKeyboard(input_layout)); | 565 input_stream.set_has_keyboard(LayoutHasKeyboard(input_layout)); |
564 output_stream.set_sample_rate_hz(output_sample_rate_hz); | 566 output_stream.set_sample_rate_hz(output_sample_rate_hz); |
565 output_stream.set_num_channels(ChannelsFromLayout(output_layout)); | 567 output_stream.set_num_channels(ChannelsFromLayout(output_layout)); |
566 output_stream.set_has_keyboard(LayoutHasKeyboard(output_layout)); | 568 output_stream.set_has_keyboard(LayoutHasKeyboard(output_layout)); |
567 | 569 |
568 if (samples_per_channel != input_stream.num_frames()) { | 570 if (samples_per_channel != input_stream.num_frames()) { |
569 return kBadDataLengthError; | 571 return kBadDataLengthError; |
570 } | 572 } |
571 return ProcessStream(src, input_stream, output_stream, dest); | 573 return ProcessStream(src, input_stream, output_stream, dest); |
572 } | 574 } |
573 | 575 |
574 int AudioProcessingImpl::ProcessStream(const float* const* src, | 576 int AudioProcessingImpl::ProcessStream(const float* const* src, |
575 const StreamConfig& input_config, | 577 const StreamConfig& input_config, |
576 const StreamConfig& output_config, | 578 const StreamConfig& output_config, |
577 float* const* dest) { | 579 float* const* dest) { |
| 580 TRACE_EVENT0("webrtc", "AudioProcessing::ProcessStream_StreamConfig"); |
578 ProcessingConfig processing_config; | 581 ProcessingConfig processing_config; |
579 { | 582 { |
580 // Acquire the capture lock in order to safely call the function | 583 // Acquire the capture lock in order to safely call the function |
581 // that retrieves the render side data. This function accesses apm | 584 // that retrieves the render side data. This function accesses apm |
582 // getters that need the capture lock held when being called. | 585 // getters that need the capture lock held when being called. |
583 rtc::CritScope cs_capture(&crit_capture_); | 586 rtc::CritScope cs_capture(&crit_capture_); |
584 public_submodules_->echo_cancellation->ReadQueuedRenderData(); | 587 public_submodules_->echo_cancellation->ReadQueuedRenderData(); |
585 public_submodules_->echo_control_mobile->ReadQueuedRenderData(); | 588 public_submodules_->echo_control_mobile->ReadQueuedRenderData(); |
586 public_submodules_->gain_control->ReadQueuedRenderData(); | 589 public_submodules_->gain_control->ReadQueuedRenderData(); |
587 | 590 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 msg->add_output_channel(dest[i], channel_size); | 633 msg->add_output_channel(dest[i], channel_size); |
631 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), | 634 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), |
632 &crit_debug_, &debug_dump_.capture)); | 635 &crit_debug_, &debug_dump_.capture)); |
633 } | 636 } |
634 #endif | 637 #endif |
635 | 638 |
636 return kNoError; | 639 return kNoError; |
637 } | 640 } |
638 | 641 |
639 int AudioProcessingImpl::ProcessStream(AudioFrame* frame) { | 642 int AudioProcessingImpl::ProcessStream(AudioFrame* frame) { |
| 643 TRACE_EVENT0("webrtc", "AudioProcessing::ProcessStream_AudioFrame"); |
640 { | 644 { |
641 // Acquire the capture lock in order to safely call the function | 645 // Acquire the capture lock in order to safely call the function |
642 // that retrieves the render side data. This function accesses apm | 646 // that retrieves the render side data. This function accesses apm |
643 // getters that need the capture lock held when being called. | 647 // getters that need the capture lock held when being called. |
644 // The lock needs to be released as | 648 // The lock needs to be released as |
645 // public_submodules_->echo_control_mobile->is_enabled() aquires this lock | 649 // public_submodules_->echo_control_mobile->is_enabled() aquires this lock |
646 // as well. | 650 // as well. |
647 rtc::CritScope cs_capture(&crit_capture_); | 651 rtc::CritScope cs_capture(&crit_capture_); |
648 public_submodules_->echo_cancellation->ReadQueuedRenderData(); | 652 public_submodules_->echo_cancellation->ReadQueuedRenderData(); |
649 public_submodules_->echo_control_mobile->ReadQueuedRenderData(); | 653 public_submodules_->echo_control_mobile->ReadQueuedRenderData(); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 public_submodules_->level_estimator->ProcessStream(ca); | 813 public_submodules_->level_estimator->ProcessStream(ca); |
810 | 814 |
811 capture_.was_stream_delay_set = false; | 815 capture_.was_stream_delay_set = false; |
812 return kNoError; | 816 return kNoError; |
813 } | 817 } |
814 | 818 |
815 int AudioProcessingImpl::AnalyzeReverseStream(const float* const* data, | 819 int AudioProcessingImpl::AnalyzeReverseStream(const float* const* data, |
816 size_t samples_per_channel, | 820 size_t samples_per_channel, |
817 int rev_sample_rate_hz, | 821 int rev_sample_rate_hz, |
818 ChannelLayout layout) { | 822 ChannelLayout layout) { |
| 823 TRACE_EVENT0("webrtc", "AudioProcessing::AnalyzeReverseStream_ChannelLayout"); |
819 rtc::CritScope cs(&crit_render_); | 824 rtc::CritScope cs(&crit_render_); |
820 const StreamConfig reverse_config = { | 825 const StreamConfig reverse_config = { |
821 rev_sample_rate_hz, ChannelsFromLayout(layout), LayoutHasKeyboard(layout), | 826 rev_sample_rate_hz, ChannelsFromLayout(layout), LayoutHasKeyboard(layout), |
822 }; | 827 }; |
823 if (samples_per_channel != reverse_config.num_frames()) { | 828 if (samples_per_channel != reverse_config.num_frames()) { |
824 return kBadDataLengthError; | 829 return kBadDataLengthError; |
825 } | 830 } |
826 return AnalyzeReverseStreamLocked(data, reverse_config, reverse_config); | 831 return AnalyzeReverseStreamLocked(data, reverse_config, reverse_config); |
827 } | 832 } |
828 | 833 |
829 int AudioProcessingImpl::ProcessReverseStream( | 834 int AudioProcessingImpl::ProcessReverseStream( |
830 const float* const* src, | 835 const float* const* src, |
831 const StreamConfig& reverse_input_config, | 836 const StreamConfig& reverse_input_config, |
832 const StreamConfig& reverse_output_config, | 837 const StreamConfig& reverse_output_config, |
833 float* const* dest) { | 838 float* const* dest) { |
| 839 TRACE_EVENT0("webrtc", "AudioProcessing::ProcessReverseStream_StreamConfig"); |
834 rtc::CritScope cs(&crit_render_); | 840 rtc::CritScope cs(&crit_render_); |
835 RETURN_ON_ERR(AnalyzeReverseStreamLocked(src, reverse_input_config, | 841 RETURN_ON_ERR(AnalyzeReverseStreamLocked(src, reverse_input_config, |
836 reverse_output_config)); | 842 reverse_output_config)); |
837 if (is_rev_processed()) { | 843 if (is_rev_processed()) { |
838 render_.render_audio->CopyTo(formats_.api_format.reverse_output_stream(), | 844 render_.render_audio->CopyTo(formats_.api_format.reverse_output_stream(), |
839 dest); | 845 dest); |
840 } else if (render_check_rev_conversion_needed()) { | 846 } else if (render_check_rev_conversion_needed()) { |
841 render_.render_converter->Convert(src, reverse_input_config.num_samples(), | 847 render_.render_converter->Convert(src, reverse_input_config.num_samples(), |
842 dest, | 848 dest, |
843 reverse_output_config.num_samples()); | 849 reverse_output_config.num_samples()); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
883 &crit_debug_, &debug_dump_.render)); | 889 &crit_debug_, &debug_dump_.render)); |
884 } | 890 } |
885 #endif | 891 #endif |
886 | 892 |
887 render_.render_audio->CopyFrom(src, | 893 render_.render_audio->CopyFrom(src, |
888 formats_.api_format.reverse_input_stream()); | 894 formats_.api_format.reverse_input_stream()); |
889 return ProcessReverseStreamLocked(); | 895 return ProcessReverseStreamLocked(); |
890 } | 896 } |
891 | 897 |
892 int AudioProcessingImpl::ProcessReverseStream(AudioFrame* frame) { | 898 int AudioProcessingImpl::ProcessReverseStream(AudioFrame* frame) { |
| 899 TRACE_EVENT0("webrtc", "AudioProcessing::ProcessReverseStream_AudioFrame"); |
893 RETURN_ON_ERR(AnalyzeReverseStream(frame)); | 900 RETURN_ON_ERR(AnalyzeReverseStream(frame)); |
894 rtc::CritScope cs(&crit_render_); | 901 rtc::CritScope cs(&crit_render_); |
895 if (is_rev_processed()) { | 902 if (is_rev_processed()) { |
896 render_.render_audio->InterleaveTo(frame, true); | 903 render_.render_audio->InterleaveTo(frame, true); |
897 } | 904 } |
898 | 905 |
899 return kNoError; | 906 return kNoError; |
900 } | 907 } |
901 | 908 |
902 int AudioProcessingImpl::AnalyzeReverseStream(AudioFrame* frame) { | 909 int AudioProcessingImpl::AnalyzeReverseStream(AudioFrame* frame) { |
| 910 TRACE_EVENT0("webrtc", "AudioProcessing::AnalyzeReverseStream_AudioFrame"); |
903 rtc::CritScope cs(&crit_render_); | 911 rtc::CritScope cs(&crit_render_); |
904 if (frame == nullptr) { | 912 if (frame == nullptr) { |
905 return kNullPointerError; | 913 return kNullPointerError; |
906 } | 914 } |
907 // Must be a native rate. | 915 // Must be a native rate. |
908 if (frame->sample_rate_hz_ != kSampleRate8kHz && | 916 if (frame->sample_rate_hz_ != kSampleRate8kHz && |
909 frame->sample_rate_hz_ != kSampleRate16kHz && | 917 frame->sample_rate_hz_ != kSampleRate16kHz && |
910 frame->sample_rate_hz_ != kSampleRate32kHz && | 918 frame->sample_rate_hz_ != kSampleRate32kHz && |
911 frame->sample_rate_hz_ != kSampleRate48kHz) { | 919 frame->sample_rate_hz_ != kSampleRate48kHz) { |
912 return kBadSampleRateError; | 920 return kBadSampleRateError; |
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1495 debug_dump_.capture.event_msg->set_type(audioproc::Event::CONFIG); | 1503 debug_dump_.capture.event_msg->set_type(audioproc::Event::CONFIG); |
1496 debug_dump_.capture.event_msg->mutable_config()->CopyFrom(config); | 1504 debug_dump_.capture.event_msg->mutable_config()->CopyFrom(config); |
1497 | 1505 |
1498 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), | 1506 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), |
1499 &crit_debug_, &debug_dump_.capture)); | 1507 &crit_debug_, &debug_dump_.capture)); |
1500 return kNoError; | 1508 return kNoError; |
1501 } | 1509 } |
1502 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP | 1510 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
1503 | 1511 |
1504 } // namespace webrtc | 1512 } // namespace webrtc |
OLD | NEW |