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

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

Issue 2778783002: AecDump interface (Closed)
Patch Set: Put capture logging in methods. Created 3 years, 8 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 return uppermost_native_rate; 122 return uppermost_native_rate;
123 } 123 }
124 124
125 // Maximum length that a frame of samples can have. 125 // Maximum length that a frame of samples can have.
126 static const size_t kMaxAllowedValuesOfSamplesPerFrame = 160; 126 static const size_t kMaxAllowedValuesOfSamplesPerFrame = 160;
127 // Maximum number of frames to buffer in the render queue. 127 // Maximum number of frames to buffer in the render queue.
128 // TODO(peah): Decrease this once we properly handle hugely unbalanced 128 // TODO(peah): Decrease this once we properly handle hugely unbalanced
129 // reverse and forward call numbers. 129 // reverse and forward call numbers.
130 static const size_t kMaxNumFramesToBuffer = 100; 130 static const size_t kMaxNumFramesToBuffer = 100;
131 131
132 // Maximum number of audio channels in the input and output streams.
133 constexpr size_t kMaxNumChannelsToRecord = 4;
the sun 2017/04/28 11:06:00 Why 4? We only support stereo anyway. And why arbi
peah-webrtc 2017/04/28 11:21:10 Good point :-) The reason for 4 is that that is th
aleloi 2017/05/03 13:58:18 Removed in latest patch.
134
132 class HighPassFilterImpl : public HighPassFilter { 135 class HighPassFilterImpl : public HighPassFilter {
133 public: 136 public:
134 explicit HighPassFilterImpl(AudioProcessingImpl* apm) : apm_(apm) {} 137 explicit HighPassFilterImpl(AudioProcessingImpl* apm) : apm_(apm) {}
135 ~HighPassFilterImpl() override = default; 138 ~HighPassFilterImpl() override = default;
136 139
137 // HighPassFilter implementation. 140 // HighPassFilter implementation.
138 int Enable(bool enable) override { 141 int Enable(bool enable) override {
139 apm_->MutateConfig([enable](AudioProcessing::Config* config) { 142 apm_->MutateConfig([enable](AudioProcessing::Config* config) {
140 config->high_pass_filter.enabled = enable; 143 config->high_pass_filter.enabled = enable;
141 }); 144 });
142 145
143 return AudioProcessing::kNoError; 146 return AudioProcessing::kNoError;
144 } 147 }
145 148
146 bool is_enabled() const override { 149 bool is_enabled() const override {
147 return apm_->GetConfig().high_pass_filter.enabled; 150 return apm_->GetConfig().high_pass_filter.enabled;
148 } 151 }
149 152
150 private: 153 private:
151 AudioProcessingImpl* apm_; 154 AudioProcessingImpl* apm_;
152 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(HighPassFilterImpl); 155 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(HighPassFilterImpl);
153 }; 156 };
154 157
158 webrtc::InternalAPMStreamsConfig ToStreamsConfig(
159 const ProcessingConfig& api_format) {
160 webrtc::InternalAPMStreamsConfig result;
161 result.input_sample_rate = api_format.input_stream().sample_rate_hz();
162 result.input_num_channels = api_format.input_stream().num_channels();
163 result.output_num_channels = api_format.output_stream().num_channels();
164 result.render_input_num_channels =
165 api_format.reverse_input_stream().num_channels();
166 result.render_input_sample_rate =
167 api_format.reverse_input_stream().sample_rate_hz();
168 result.output_sample_rate = api_format.output_stream().sample_rate_hz();
169 result.render_output_sample_rate =
170 api_format.reverse_output_stream().sample_rate_hz();
171 result.render_output_num_channels =
172 api_format.reverse_output_stream().num_channels();
173 return result;
174 }
175
176 rtc::ArrayView<rtc::ArrayView<const float>> CreateStreamView(
177 const float* const* stream,
178 size_t channel_size,
179 size_t num_channels) {
180 RTC_DCHECK_LE(num_channels, kMaxNumChannelsToRecord);
181
182 std::array<rtc::ArrayView<const float>, kMaxNumChannelsToRecord>
183 array_stream_view;
184 for (size_t i = 0; i < std::min(num_channels, kMaxNumChannelsToRecord); ++i) {
185 array_stream_view[i] = rtc::ArrayView<const float>(stream[i], channel_size);
186 }
187 return rtc::ArrayView<rtc::ArrayView<const float>>(&array_stream_view[0],
the sun 2017/04/28 11:06:00 ArrayView is just a pointer and length, so in this
kwiberg-webrtc 2017/04/28 12:13:06 +1. I haven't read the code closely, but I suspect
aleloi 2017/05/03 13:58:18 Now fixed.
188 num_channels);
189 }
155 } // namespace 190 } // namespace
156 191
157 // Throughout webrtc, it's assumed that success is represented by zero. 192 // Throughout webrtc, it's assumed that success is represented by zero.
158 static_assert(AudioProcessing::kNoError == 0, "kNoError must be zero"); 193 static_assert(AudioProcessing::kNoError == 0, "kNoError must be zero");
159 194
160 AudioProcessingImpl::ApmSubmoduleStates::ApmSubmoduleStates() {} 195 AudioProcessingImpl::ApmSubmoduleStates::ApmSubmoduleStates() {}
161 196
162 bool AudioProcessingImpl::ApmSubmoduleStates::Update( 197 bool AudioProcessingImpl::ApmSubmoduleStates::Update(
163 bool low_cut_filter_enabled, 198 bool low_cut_filter_enabled,
164 bool echo_canceller_enabled, 199 bool echo_canceller_enabled,
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 InitializeEchoCanceller3(); 554 InitializeEchoCanceller3();
520 555
521 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP 556 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
522 if (debug_dump_.debug_file->is_open()) { 557 if (debug_dump_.debug_file->is_open()) {
523 int err = WriteInitMessage(); 558 int err = WriteInitMessage();
524 if (err != kNoError) { 559 if (err != kNoError) {
525 return err; 560 return err;
526 } 561 }
527 } 562 }
528 #endif 563 #endif
529 564 if (aec_dump_) {
565 aec_dump_->WriteInitMessage(ToStreamsConfig(formats_.api_format));
566 }
530 return kNoError; 567 return kNoError;
531 } 568 }
532 569
533 int AudioProcessingImpl::InitializeLocked(const ProcessingConfig& config) { 570 int AudioProcessingImpl::InitializeLocked(const ProcessingConfig& config) {
534 for (const auto& stream : config.streams) { 571 for (const auto& stream : config.streams) {
535 if (stream.num_channels() > 0 && stream.sample_rate_hz() <= 0) { 572 if (stream.num_channels() > 0 && stream.sample_rate_hz() <= 0) {
536 return kBadSampleRateError; 573 return kBadSampleRateError;
537 } 574 }
538 } 575 }
539 576
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 debug_dump_.capture.event_msg->set_type(audioproc::Event::STREAM); 854 debug_dump_.capture.event_msg->set_type(audioproc::Event::STREAM);
818 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream(); 855 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream();
819 const size_t channel_size = 856 const size_t channel_size =
820 sizeof(float) * formats_.api_format.input_stream().num_frames(); 857 sizeof(float) * formats_.api_format.input_stream().num_frames();
821 for (size_t i = 0; i < formats_.api_format.input_stream().num_channels(); 858 for (size_t i = 0; i < formats_.api_format.input_stream().num_channels();
822 ++i) 859 ++i)
823 msg->add_input_channel(src[i], channel_size); 860 msg->add_input_channel(src[i], channel_size);
824 } 861 }
825 #endif 862 #endif
826 863
864 std::unique_ptr<AecDump::CaptureStreamInfo> stream_info =
865 aec_dump_ ? RecordUnprocessedCaptureStream(src) : nullptr;
peah-webrtc 2017/04/25 21:04:46 Is the else statement really needed (the nullptr
aleloi 2017/04/26 09:16:48 Done.
866
827 capture_.capture_audio->CopyFrom(src, formats_.api_format.input_stream()); 867 capture_.capture_audio->CopyFrom(src, formats_.api_format.input_stream());
828 RETURN_ON_ERR(ProcessCaptureStreamLocked()); 868 RETURN_ON_ERR(ProcessCaptureStreamLocked());
829 capture_.capture_audio->CopyTo(formats_.api_format.output_stream(), dest); 869 capture_.capture_audio->CopyTo(formats_.api_format.output_stream(), dest);
830 870
831 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP 871 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
832 if (debug_dump_.debug_file->is_open()) { 872 if (debug_dump_.debug_file->is_open()) {
833 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream(); 873 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream();
834 const size_t channel_size = 874 const size_t channel_size =
835 sizeof(float) * formats_.api_format.output_stream().num_frames(); 875 sizeof(float) * formats_.api_format.output_stream().num_frames();
836 for (size_t i = 0; i < formats_.api_format.output_stream().num_channels(); 876 for (size_t i = 0; i < formats_.api_format.output_stream().num_channels();
837 ++i) 877 ++i)
838 msg->add_output_channel(dest[i], channel_size); 878 msg->add_output_channel(dest[i], channel_size);
839 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), 879 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(),
840 &debug_dump_.num_bytes_left_for_log_, 880 &debug_dump_.num_bytes_left_for_log_,
841 &crit_debug_, &debug_dump_.capture)); 881 &crit_debug_, &debug_dump_.capture));
842 } 882 }
843 #endif 883 #endif
844 884 if (aec_dump_) {
885 RecordProcessedCaptureStream(dest, std::move(stream_info));
886 }
845 return kNoError; 887 return kNoError;
846 } 888 }
847 889
848 void AudioProcessingImpl::QueueRenderAudio(AudioBuffer* audio) { 890 void AudioProcessingImpl::QueueRenderAudio(AudioBuffer* audio) {
849 EchoCancellationImpl::PackRenderAudioBuffer(audio, num_output_channels(), 891 EchoCancellationImpl::PackRenderAudioBuffer(audio, num_output_channels(),
850 num_reverse_channels(), 892 num_reverse_channels(),
851 &aec_render_queue_buffer_); 893 &aec_render_queue_buffer_);
852 894
853 RTC_DCHECK_GE(160, audio->num_frames_per_band()); 895 RTC_DCHECK_GE(160, audio->num_frames_per_band());
854 896
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 rtc::CritScope cs_render(&crit_render_); 1113 rtc::CritScope cs_render(&crit_render_);
1072 RETURN_ON_ERR( 1114 RETURN_ON_ERR(
1073 MaybeInitializeCapture(processing_config, reinitialization_required)); 1115 MaybeInitializeCapture(processing_config, reinitialization_required));
1074 } 1116 }
1075 rtc::CritScope cs_capture(&crit_capture_); 1117 rtc::CritScope cs_capture(&crit_capture_);
1076 if (frame->samples_per_channel_ != 1118 if (frame->samples_per_channel_ !=
1077 formats_.api_format.input_stream().num_frames()) { 1119 formats_.api_format.input_stream().num_frames()) {
1078 return kBadDataLengthError; 1120 return kBadDataLengthError;
1079 } 1121 }
1080 1122
1123 std::unique_ptr<AecDump::CaptureStreamInfo> stream_info =
peah-webrtc 2017/04/25 21:04:46 Same comment as above.
aleloi 2017/04/26 09:16:48 Done.
1124 aec_dump_ ? RecordUnprocessedCaptureStream(*frame) : nullptr;
1125
1081 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP 1126 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
1082 if (debug_dump_.debug_file->is_open()) { 1127 if (debug_dump_.debug_file->is_open()) {
1083 RETURN_ON_ERR(WriteConfigMessage(false)); 1128 RETURN_ON_ERR(WriteConfigMessage(false));
1084 1129
1085 debug_dump_.capture.event_msg->set_type(audioproc::Event::STREAM); 1130 debug_dump_.capture.event_msg->set_type(audioproc::Event::STREAM);
1086 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream(); 1131 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream();
1087 const size_t data_size = 1132 const size_t data_size =
1088 sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_; 1133 sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_;
1089 msg->set_input_data(frame->data_, data_size); 1134 msg->set_input_data(frame->data_, data_size);
1090 } 1135 }
1091 #endif 1136 #endif
1092 1137
1093 capture_.capture_audio->DeinterleaveFrom(frame); 1138 capture_.capture_audio->DeinterleaveFrom(frame);
1094 RETURN_ON_ERR(ProcessCaptureStreamLocked()); 1139 RETURN_ON_ERR(ProcessCaptureStreamLocked());
1095 capture_.capture_audio->InterleaveTo( 1140 capture_.capture_audio->InterleaveTo(
1096 frame, submodule_states_.CaptureMultiBandProcessingActive()); 1141 frame, submodule_states_.CaptureMultiBandProcessingActive());
1097 1142
1143 if (aec_dump_) {
1144 RecordProcessedCaptureStream(*frame, std::move(stream_info));
1145 }
1098 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP 1146 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
1099 if (debug_dump_.debug_file->is_open()) { 1147 if (debug_dump_.debug_file->is_open()) {
1100 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream(); 1148 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream();
1101 const size_t data_size = 1149 const size_t data_size =
1102 sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_; 1150 sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_;
1103 msg->set_output_data(frame->data_, data_size); 1151 msg->set_output_data(frame->data_, data_size);
1104 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), 1152 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(),
1105 &debug_dump_.num_bytes_left_for_log_, 1153 &debug_dump_.num_bytes_left_for_log_,
1106 &crit_debug_, &debug_dump_.capture)); 1154 &crit_debug_, &debug_dump_.capture));
1107 } 1155 }
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 const size_t channel_size = 1417 const size_t channel_size =
1370 sizeof(float) * formats_.api_format.reverse_input_stream().num_frames(); 1418 sizeof(float) * formats_.api_format.reverse_input_stream().num_frames();
1371 for (size_t i = 0; 1419 for (size_t i = 0;
1372 i < formats_.api_format.reverse_input_stream().num_channels(); ++i) 1420 i < formats_.api_format.reverse_input_stream().num_channels(); ++i)
1373 msg->add_channel(src[i], channel_size); 1421 msg->add_channel(src[i], channel_size);
1374 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), 1422 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(),
1375 &debug_dump_.num_bytes_left_for_log_, 1423 &debug_dump_.num_bytes_left_for_log_,
1376 &crit_debug_, &debug_dump_.render)); 1424 &crit_debug_, &debug_dump_.render));
1377 } 1425 }
1378 #endif 1426 #endif
1379 1427 if (aec_dump_) {
1428 const size_t channel_size =
1429 sizeof(float) * formats_.api_format.reverse_input_stream().num_frames();
1430 const size_t num_channels =
1431 formats_.api_format.reverse_input_stream().num_channels();
1432 aec_dump_->WriteRenderStreamMessage(
1433 CreateStreamView(src, channel_size, num_channels));
1434 }
1380 render_.render_audio->CopyFrom(src, 1435 render_.render_audio->CopyFrom(src,
1381 formats_.api_format.reverse_input_stream()); 1436 formats_.api_format.reverse_input_stream());
1382 return ProcessRenderStreamLocked(); 1437 return ProcessRenderStreamLocked();
1383 } 1438 }
1384 1439
1385 int AudioProcessingImpl::ProcessReverseStream(AudioFrame* frame) { 1440 int AudioProcessingImpl::ProcessReverseStream(AudioFrame* frame) {
1386 TRACE_EVENT0("webrtc", "AudioProcessing::ProcessReverseStream_AudioFrame"); 1441 TRACE_EVENT0("webrtc", "AudioProcessing::ProcessReverseStream_AudioFrame");
1387 rtc::CritScope cs(&crit_render_); 1442 rtc::CritScope cs(&crit_render_);
1388 if (frame == nullptr) { 1443 if (frame == nullptr) {
1389 return kNullPointerError; 1444 return kNullPointerError;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1422 audioproc::ReverseStream* msg = 1477 audioproc::ReverseStream* msg =
1423 debug_dump_.render.event_msg->mutable_reverse_stream(); 1478 debug_dump_.render.event_msg->mutable_reverse_stream();
1424 const size_t data_size = 1479 const size_t data_size =
1425 sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_; 1480 sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_;
1426 msg->set_data(frame->data_, data_size); 1481 msg->set_data(frame->data_, data_size);
1427 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), 1482 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(),
1428 &debug_dump_.num_bytes_left_for_log_, 1483 &debug_dump_.num_bytes_left_for_log_,
1429 &crit_debug_, &debug_dump_.render)); 1484 &crit_debug_, &debug_dump_.render));
1430 } 1485 }
1431 #endif 1486 #endif
1487 if (aec_dump_) {
1488 aec_dump_->WriteRenderStreamMessage(*frame);
1489 }
1490
1432 render_.render_audio->DeinterleaveFrom(frame); 1491 render_.render_audio->DeinterleaveFrom(frame);
1433 RETURN_ON_ERR(ProcessRenderStreamLocked()); 1492 RETURN_ON_ERR(ProcessRenderStreamLocked());
1434 render_.render_audio->InterleaveTo( 1493 render_.render_audio->InterleaveTo(
1435 frame, submodule_states_.RenderMultiBandProcessingActive()); 1494 frame, submodule_states_.RenderMultiBandProcessingActive());
1436 return kNoError; 1495 return kNoError;
1437 } 1496 }
1438 1497
1439 int AudioProcessingImpl::ProcessRenderStreamLocked() { 1498 int AudioProcessingImpl::ProcessRenderStreamLocked() {
1440 AudioBuffer* render_buffer = render_.render_audio.get(); // For brevity. 1499 AudioBuffer* render_buffer = render_.render_audio.get(); // For brevity.
1441 if (submodule_states_.RenderMultiBandSubModulesActive() && 1500 if (submodule_states_.RenderMultiBandSubModulesActive() &&
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1505 void AudioProcessingImpl::set_delay_offset_ms(int offset) { 1564 void AudioProcessingImpl::set_delay_offset_ms(int offset) {
1506 rtc::CritScope cs(&crit_capture_); 1565 rtc::CritScope cs(&crit_capture_);
1507 capture_.delay_offset_ms = offset; 1566 capture_.delay_offset_ms = offset;
1508 } 1567 }
1509 1568
1510 int AudioProcessingImpl::delay_offset_ms() const { 1569 int AudioProcessingImpl::delay_offset_ms() const {
1511 rtc::CritScope cs(&crit_capture_); 1570 rtc::CritScope cs(&crit_capture_);
1512 return capture_.delay_offset_ms; 1571 return capture_.delay_offset_ms;
1513 } 1572 }
1514 1573
1574 void AudioProcessingImpl::StartDebugRecording(
1575 std::unique_ptr<AecDump> aec_dump) {
1576 rtc::CritScope cs_render(&crit_render_);
1577 rtc::CritScope cs_capture(&crit_capture_);
1578 RTC_DCHECK(aec_dump);
1579 aec_dump_ = std::move(aec_dump);
1580
1581 aec_dump_->WriteConfig(CollectApmConfig(), true);
1582 aec_dump_->WriteInitMessage(ToStreamsConfig(formats_.api_format));
1583 }
1584
1515 int AudioProcessingImpl::StartDebugRecording( 1585 int AudioProcessingImpl::StartDebugRecording(
1516 const char filename[AudioProcessing::kMaxFilenameSize], 1586 const char filename[AudioProcessing::kMaxFilenameSize],
1517 int64_t max_log_size_bytes) { 1587 int64_t max_log_size_bytes) {
1518 // Run in a single-threaded manner. 1588 // Run in a single-threaded manner.
1519 rtc::CritScope cs_render(&crit_render_); 1589 rtc::CritScope cs_render(&crit_render_);
1520 rtc::CritScope cs_capture(&crit_capture_); 1590 rtc::CritScope cs_capture(&crit_capture_);
1521 static_assert(kMaxFilenameSize == FileWrapper::kMaxFileNameSize, ""); 1591 static_assert(kMaxFilenameSize == FileWrapper::kMaxFileNameSize, "");
1522 1592
1523 if (filename == nullptr) { 1593 if (filename == nullptr) {
1524 return kNullPointerError; 1594 return kNullPointerError;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1579 rtc::CritScope cs_render(&crit_render_); 1649 rtc::CritScope cs_render(&crit_render_);
1580 rtc::CritScope cs_capture(&crit_capture_); 1650 rtc::CritScope cs_capture(&crit_capture_);
1581 FILE* stream = rtc::FdopenPlatformFileForWriting(handle); 1651 FILE* stream = rtc::FdopenPlatformFileForWriting(handle);
1582 return StartDebugRecording(stream, -1); 1652 return StartDebugRecording(stream, -1);
1583 } 1653 }
1584 1654
1585 int AudioProcessingImpl::StopDebugRecording() { 1655 int AudioProcessingImpl::StopDebugRecording() {
1586 // Run in a single-threaded manner. 1656 // Run in a single-threaded manner.
1587 rtc::CritScope cs_render(&crit_render_); 1657 rtc::CritScope cs_render(&crit_render_);
1588 rtc::CritScope cs_capture(&crit_capture_); 1658 rtc::CritScope cs_capture(&crit_capture_);
1659 aec_dump_.reset();
1589 1660
1590 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP 1661 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
1591 // We just return if recording hasn't started. 1662 // We just return if recording hasn't started.
1592 debug_dump_.debug_file->CloseFile(); 1663 debug_dump_.debug_file->CloseFile();
1593 return kNoError; 1664 return kNoError;
1594 #else 1665 #else
1595 return kUnsupportedFunctionError; 1666 return kUnsupportedFunctionError;
1596 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP 1667 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
1597 } 1668 }
1598 1669
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
1830 capture_.last_stream_delay_ms = 0; 1901 capture_.last_stream_delay_ms = 0;
1831 1902
1832 if (capture_.aec_system_delay_jumps > -1) { 1903 if (capture_.aec_system_delay_jumps > -1) {
1833 RTC_HISTOGRAM_ENUMERATION("WebRTC.Audio.NumOfAecSystemDelayJumps", 1904 RTC_HISTOGRAM_ENUMERATION("WebRTC.Audio.NumOfAecSystemDelayJumps",
1834 capture_.aec_system_delay_jumps, 51); 1905 capture_.aec_system_delay_jumps, 51);
1835 } 1906 }
1836 capture_.aec_system_delay_jumps = -1; 1907 capture_.aec_system_delay_jumps = -1;
1837 capture_.last_aec_system_delay_ms = 0; 1908 capture_.last_aec_system_delay_ms = 0;
1838 } 1909 }
1839 1910
1911 InternalAPMConfig AudioProcessingImpl::CollectApmConfig() const {
1912 std::string experiments_description =
1913 public_submodules_->echo_cancellation->GetExperimentsDescription();
1914 // TODO(peah): Add semicolon-separated concatenations of experiment
1915 // descriptions for other submodules.
1916 if (capture_nonlocked_.level_controller_enabled) {
1917 experiments_description += "LevelController;";
1918 }
1919 if (constants_.agc_clipped_level_min != kClippedLevelMin) {
1920 experiments_description += "AgcClippingLevelExperiment;";
1921 }
1922 if (capture_nonlocked_.echo_canceller3_enabled) {
1923 experiments_description += "EchoCanceller3;";
1924 }
1925
1926 InternalAPMConfig apm_config;
1927
1928 apm_config.aec_enabled = public_submodules_->echo_cancellation->is_enabled();
1929 apm_config.aec_delay_agnostic_enabled =
1930 public_submodules_->echo_cancellation->is_delay_agnostic_enabled();
1931 apm_config.aec_drift_compensation_enabled =
1932 public_submodules_->echo_cancellation->is_drift_compensation_enabled();
1933 apm_config.aec_extended_filter_enabled =
1934 public_submodules_->echo_cancellation->is_extended_filter_enabled();
1935 apm_config.aec_suppression_level = static_cast<int>(
1936 public_submodules_->echo_cancellation->suppression_level());
1937
1938 apm_config.aecm_enabled =
1939 public_submodules_->echo_control_mobile->is_enabled();
1940 apm_config.aecm_comfort_noise_enabled =
1941 public_submodules_->echo_control_mobile->is_comfort_noise_enabled();
1942 apm_config.aecm_routing_mode =
1943 static_cast<int>(public_submodules_->echo_control_mobile->routing_mode());
1944
1945 apm_config.agc_enabled = public_submodules_->gain_control->is_enabled();
1946 apm_config.agc_mode =
1947 static_cast<int>(public_submodules_->gain_control->mode());
1948 apm_config.agc_limiter_enabled =
1949 public_submodules_->gain_control->is_limiter_enabled();
1950 apm_config.noise_robust_agc_enabled = constants_.use_experimental_agc;
1951
1952 apm_config.hpf_enabled = config_.high_pass_filter.enabled;
1953
1954 apm_config.ns_enabled = public_submodules_->noise_suppression->is_enabled();
1955 apm_config.ns_level =
1956 static_cast<int>(public_submodules_->noise_suppression->level());
1957
1958 apm_config.transient_suppression_enabled =
1959 capture_.transient_suppressor_enabled;
1960 apm_config.intelligibility_enhancer_enabled =
1961 capture_nonlocked_.intelligibility_enabled;
1962 apm_config.experiments_description = experiments_description;
1963 return apm_config;
1964 }
1965
1966 std::unique_ptr<AecDump::CaptureStreamInfo>
1967 AudioProcessingImpl::RecordUnprocessedCaptureStream(
1968 const float* const* src) const {
1969 RTC_DCHECK(aec_dump_);
1970 aec_dump_->WriteConfig(CollectApmConfig(), false);
1971 auto stream_info = aec_dump_->GetCaptureStreamInfo();
1972 RTC_DCHECK(stream_info);
1973
1974 const size_t channel_size =
1975 sizeof(float) * formats_.api_format.input_stream().num_frames();
1976 const size_t num_channels = formats_.api_format.input_stream().num_channels();
1977 stream_info->AddInput(CreateStreamView(src, channel_size, num_channels));
1978 PopulateStreamInfoWithConfig(stream_info.get());
1979 return stream_info;
1980 }
1981
1982 std::unique_ptr<AecDump::CaptureStreamInfo>
1983 AudioProcessingImpl::RecordUnprocessedCaptureStream(
1984 const AudioFrame& capture_frame) const {
1985 RTC_DCHECK(aec_dump_);
1986 auto stream_info = aec_dump_->GetCaptureStreamInfo();
1987 RTC_DCHECK(stream_info);
1988
1989 stream_info->AddInput(capture_frame);
1990 PopulateStreamInfoWithConfig(stream_info.get());
1991 aec_dump_->WriteConfig(CollectApmConfig(), false);
1992 return stream_info;
1993 }
1994
1995 void AudioProcessingImpl::RecordProcessedCaptureStream(
1996 const float* const* processed_capture_stream,
1997 std::unique_ptr<AecDump::CaptureStreamInfo> stream_info) const {
1998 RTC_DCHECK(stream_info);
1999 RTC_DCHECK(aec_dump_);
2000
2001 const size_t channel_size =
2002 sizeof(float) * formats_.api_format.output_stream().num_frames();
2003 const size_t num_channels =
2004 formats_.api_format.output_stream().num_channels();
2005 stream_info->AddOutput(
2006 CreateStreamView(processed_capture_stream, channel_size, num_channels));
2007 aec_dump_->WriteCaptureStreamMessage(std::move(stream_info));
2008 }
2009
2010 void AudioProcessingImpl::RecordProcessedCaptureStream(
2011 const AudioFrame& processed_capture_frame,
2012 std::unique_ptr<AecDump::CaptureStreamInfo> stream_info) const {
2013 RTC_DCHECK(stream_info);
2014 RTC_DCHECK(aec_dump_);
2015
2016 stream_info->AddOutput(processed_capture_frame);
2017 aec_dump_->WriteCaptureStreamMessage(std::move(stream_info));
2018 }
2019
2020 void AudioProcessingImpl::PopulateStreamInfoWithConfig(
2021 AecDump::CaptureStreamInfo* stream_info) const {
2022 RTC_DCHECK(stream_info);
2023
2024 stream_info->set_delay(capture_nonlocked_.stream_delay_ms);
2025 stream_info->set_drift(
2026 public_submodules_->echo_cancellation->stream_drift_samples());
2027 stream_info->set_level(gain_control()->stream_analog_level());
2028 stream_info->set_keypress(capture_.key_pressed);
2029 }
2030
1840 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP 2031 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
1841 int AudioProcessingImpl::WriteMessageToDebugFile( 2032 int AudioProcessingImpl::WriteMessageToDebugFile(
1842 FileWrapper* debug_file, 2033 FileWrapper* debug_file,
1843 int64_t* filesize_limit_bytes, 2034 int64_t* filesize_limit_bytes,
1844 rtc::CriticalSection* crit_debug, 2035 rtc::CriticalSection* crit_debug,
1845 ApmDebugDumpThreadState* debug_state) { 2036 ApmDebugDumpThreadState* debug_state) {
1846 int32_t size = debug_state->event_msg->ByteSize(); 2037 int32_t size = debug_state->event_msg->ByteSize();
1847 if (size <= 0) { 2038 if (size <= 0) {
1848 return kUnspecifiedError; 2039 return kUnspecifiedError;
1849 } 2040 }
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
2003 previous_agc_level(0), 2194 previous_agc_level(0),
2004 echo_path_gain_change(false) {} 2195 echo_path_gain_change(false) {}
2005 2196
2006 AudioProcessingImpl::ApmCaptureState::~ApmCaptureState() = default; 2197 AudioProcessingImpl::ApmCaptureState::~ApmCaptureState() = default;
2007 2198
2008 AudioProcessingImpl::ApmRenderState::ApmRenderState() = default; 2199 AudioProcessingImpl::ApmRenderState::ApmRenderState() = default;
2009 2200
2010 AudioProcessingImpl::ApmRenderState::~ApmRenderState() = default; 2201 AudioProcessingImpl::ApmRenderState::~ApmRenderState() = default;
2011 2202
2012 } // namespace webrtc 2203 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698