Chromium Code Reviews| 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 | 145 |
| 146 bool is_enabled() const override { | 146 bool is_enabled() const override { |
| 147 return apm_->GetConfig().high_pass_filter.enabled; | 147 return apm_->GetConfig().high_pass_filter.enabled; |
| 148 } | 148 } |
| 149 | 149 |
| 150 private: | 150 private: |
| 151 AudioProcessingImpl* apm_; | 151 AudioProcessingImpl* apm_; |
| 152 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(HighPassFilterImpl); | 152 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(HighPassFilterImpl); |
| 153 }; | 153 }; |
| 154 | 154 |
| 155 webrtc::InternalAPMStreamsConfig ToStreamsConfig( | |
| 156 const ProcessingConfig& api_format) { | |
| 157 webrtc::InternalAPMStreamsConfig result; | |
| 158 result.input_sample_rate = api_format.input_stream().sample_rate_hz(); | |
| 159 result.input_num_channels = api_format.input_stream().num_channels(); | |
| 160 result.output_num_channels = api_format.output_stream().num_channels(); | |
| 161 result.render_input_num_channels = | |
| 162 api_format.reverse_input_stream().num_channels(); | |
| 163 result.render_input_sample_rate = | |
| 164 api_format.reverse_input_stream().sample_rate_hz(); | |
| 165 result.output_sample_rate = api_format.output_stream().sample_rate_hz(); | |
| 166 result.render_output_sample_rate = | |
| 167 api_format.reverse_output_stream().sample_rate_hz(); | |
| 168 result.render_output_num_channels = | |
| 169 api_format.reverse_output_stream().num_channels(); | |
| 170 return result; | |
| 171 } | |
| 155 } // namespace | 172 } // namespace |
| 156 | 173 |
| 157 // Throughout webrtc, it's assumed that success is represented by zero. | 174 // Throughout webrtc, it's assumed that success is represented by zero. |
| 158 static_assert(AudioProcessing::kNoError == 0, "kNoError must be zero"); | 175 static_assert(AudioProcessing::kNoError == 0, "kNoError must be zero"); |
| 159 | 176 |
| 160 AudioProcessingImpl::ApmSubmoduleStates::ApmSubmoduleStates() {} | 177 AudioProcessingImpl::ApmSubmoduleStates::ApmSubmoduleStates() {} |
| 161 | 178 |
| 162 bool AudioProcessingImpl::ApmSubmoduleStates::Update( | 179 bool AudioProcessingImpl::ApmSubmoduleStates::Update( |
| 163 bool low_cut_filter_enabled, | 180 bool low_cut_filter_enabled, |
| 164 bool echo_canceller_enabled, | 181 bool echo_canceller_enabled, |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 519 InitializeEchoCanceller3(); | 536 InitializeEchoCanceller3(); |
| 520 | 537 |
| 521 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 538 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 522 if (debug_dump_.debug_file->is_open()) { | 539 if (debug_dump_.debug_file->is_open()) { |
| 523 int err = WriteInitMessage(); | 540 int err = WriteInitMessage(); |
| 524 if (err != kNoError) { | 541 if (err != kNoError) { |
| 525 return err; | 542 return err; |
| 526 } | 543 } |
| 527 } | 544 } |
| 528 #endif | 545 #endif |
| 529 | 546 if (aec_dump_) { |
| 547 aec_dump_->WriteInitMessage(ToStreamsConfig(formats_.api_format)); | |
| 548 } | |
| 530 return kNoError; | 549 return kNoError; |
| 531 } | 550 } |
| 532 | 551 |
| 533 int AudioProcessingImpl::InitializeLocked(const ProcessingConfig& config) { | 552 int AudioProcessingImpl::InitializeLocked(const ProcessingConfig& config) { |
| 534 for (const auto& stream : config.streams) { | 553 for (const auto& stream : config.streams) { |
| 535 if (stream.num_channels() > 0 && stream.sample_rate_hz() <= 0) { | 554 if (stream.num_channels() > 0 && stream.sample_rate_hz() <= 0) { |
| 536 return kBadSampleRateError; | 555 return kBadSampleRateError; |
| 537 } | 556 } |
| 538 } | 557 } |
| 539 | 558 |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 817 debug_dump_.capture.event_msg->set_type(audioproc::Event::STREAM); | 836 debug_dump_.capture.event_msg->set_type(audioproc::Event::STREAM); |
| 818 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream(); | 837 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream(); |
| 819 const size_t channel_size = | 838 const size_t channel_size = |
| 820 sizeof(float) * formats_.api_format.input_stream().num_frames(); | 839 sizeof(float) * formats_.api_format.input_stream().num_frames(); |
| 821 for (size_t i = 0; i < formats_.api_format.input_stream().num_channels(); | 840 for (size_t i = 0; i < formats_.api_format.input_stream().num_channels(); |
| 822 ++i) | 841 ++i) |
| 823 msg->add_input_channel(src[i], channel_size); | 842 msg->add_input_channel(src[i], channel_size); |
| 824 } | 843 } |
| 825 #endif | 844 #endif |
| 826 | 845 |
| 846 if (aec_dump_) { | |
| 847 RecordUnprocessedCaptureStream(src); | |
| 848 } | |
| 849 | |
| 827 capture_.capture_audio->CopyFrom(src, formats_.api_format.input_stream()); | 850 capture_.capture_audio->CopyFrom(src, formats_.api_format.input_stream()); |
| 828 RETURN_ON_ERR(ProcessCaptureStreamLocked()); | 851 RETURN_ON_ERR(ProcessCaptureStreamLocked()); |
| 829 capture_.capture_audio->CopyTo(formats_.api_format.output_stream(), dest); | 852 capture_.capture_audio->CopyTo(formats_.api_format.output_stream(), dest); |
| 830 | 853 |
| 831 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 854 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 832 if (debug_dump_.debug_file->is_open()) { | 855 if (debug_dump_.debug_file->is_open()) { |
| 833 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream(); | 856 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream(); |
| 834 const size_t channel_size = | 857 const size_t channel_size = |
| 835 sizeof(float) * formats_.api_format.output_stream().num_frames(); | 858 sizeof(float) * formats_.api_format.output_stream().num_frames(); |
| 836 for (size_t i = 0; i < formats_.api_format.output_stream().num_channels(); | 859 for (size_t i = 0; i < formats_.api_format.output_stream().num_channels(); |
| 837 ++i) | 860 ++i) |
| 838 msg->add_output_channel(dest[i], channel_size); | 861 msg->add_output_channel(dest[i], channel_size); |
| 839 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), | 862 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), |
| 840 &debug_dump_.num_bytes_left_for_log_, | 863 &debug_dump_.num_bytes_left_for_log_, |
| 841 &crit_debug_, &debug_dump_.capture)); | 864 &crit_debug_, &debug_dump_.capture)); |
| 842 } | 865 } |
| 843 #endif | 866 #endif |
| 844 | 867 if (aec_dump_) { |
| 868 RecordProcessedCaptureStream(dest); | |
| 869 } | |
| 845 return kNoError; | 870 return kNoError; |
| 846 } | 871 } |
| 847 | 872 |
| 848 void AudioProcessingImpl::QueueRenderAudio(AudioBuffer* audio) { | 873 void AudioProcessingImpl::QueueRenderAudio(AudioBuffer* audio) { |
| 849 EchoCancellationImpl::PackRenderAudioBuffer(audio, num_output_channels(), | 874 EchoCancellationImpl::PackRenderAudioBuffer(audio, num_output_channels(), |
| 850 num_reverse_channels(), | 875 num_reverse_channels(), |
| 851 &aec_render_queue_buffer_); | 876 &aec_render_queue_buffer_); |
| 852 | 877 |
| 853 RTC_DCHECK_GE(160, audio->num_frames_per_band()); | 878 RTC_DCHECK_GE(160, audio->num_frames_per_band()); |
| 854 | 879 |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1071 rtc::CritScope cs_render(&crit_render_); | 1096 rtc::CritScope cs_render(&crit_render_); |
| 1072 RETURN_ON_ERR( | 1097 RETURN_ON_ERR( |
| 1073 MaybeInitializeCapture(processing_config, reinitialization_required)); | 1098 MaybeInitializeCapture(processing_config, reinitialization_required)); |
| 1074 } | 1099 } |
| 1075 rtc::CritScope cs_capture(&crit_capture_); | 1100 rtc::CritScope cs_capture(&crit_capture_); |
| 1076 if (frame->samples_per_channel_ != | 1101 if (frame->samples_per_channel_ != |
| 1077 formats_.api_format.input_stream().num_frames()) { | 1102 formats_.api_format.input_stream().num_frames()) { |
| 1078 return kBadDataLengthError; | 1103 return kBadDataLengthError; |
| 1079 } | 1104 } |
| 1080 | 1105 |
| 1106 if (aec_dump_) { | |
| 1107 RecordUnprocessedCaptureStream(*frame); | |
| 1108 } | |
| 1109 | |
| 1081 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 1110 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 1082 if (debug_dump_.debug_file->is_open()) { | 1111 if (debug_dump_.debug_file->is_open()) { |
| 1083 RETURN_ON_ERR(WriteConfigMessage(false)); | 1112 RETURN_ON_ERR(WriteConfigMessage(false)); |
| 1084 | 1113 |
| 1085 debug_dump_.capture.event_msg->set_type(audioproc::Event::STREAM); | 1114 debug_dump_.capture.event_msg->set_type(audioproc::Event::STREAM); |
| 1086 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream(); | 1115 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream(); |
| 1087 const size_t data_size = | 1116 const size_t data_size = |
| 1088 sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_; | 1117 sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_; |
| 1089 msg->set_input_data(frame->data_, data_size); | 1118 msg->set_input_data(frame->data_, data_size); |
| 1090 } | 1119 } |
| 1091 #endif | 1120 #endif |
| 1092 | 1121 |
| 1093 capture_.capture_audio->DeinterleaveFrom(frame); | 1122 capture_.capture_audio->DeinterleaveFrom(frame); |
| 1094 RETURN_ON_ERR(ProcessCaptureStreamLocked()); | 1123 RETURN_ON_ERR(ProcessCaptureStreamLocked()); |
| 1095 capture_.capture_audio->InterleaveTo( | 1124 capture_.capture_audio->InterleaveTo( |
| 1096 frame, submodule_states_.CaptureMultiBandProcessingActive()); | 1125 frame, submodule_states_.CaptureMultiBandProcessingActive()); |
| 1097 | 1126 |
| 1127 if (aec_dump_) { | |
| 1128 RecordProcessedCaptureStream(*frame); | |
| 1129 } | |
| 1098 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 1130 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 1099 if (debug_dump_.debug_file->is_open()) { | 1131 if (debug_dump_.debug_file->is_open()) { |
| 1100 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream(); | 1132 audioproc::Stream* msg = debug_dump_.capture.event_msg->mutable_stream(); |
| 1101 const size_t data_size = | 1133 const size_t data_size = |
| 1102 sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_; | 1134 sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_; |
| 1103 msg->set_output_data(frame->data_, data_size); | 1135 msg->set_output_data(frame->data_, data_size); |
| 1104 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), | 1136 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), |
| 1105 &debug_dump_.num_bytes_left_for_log_, | 1137 &debug_dump_.num_bytes_left_for_log_, |
| 1106 &crit_debug_, &debug_dump_.capture)); | 1138 &crit_debug_, &debug_dump_.capture)); |
| 1107 } | 1139 } |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1369 const size_t channel_size = | 1401 const size_t channel_size = |
| 1370 sizeof(float) * formats_.api_format.reverse_input_stream().num_frames(); | 1402 sizeof(float) * formats_.api_format.reverse_input_stream().num_frames(); |
| 1371 for (size_t i = 0; | 1403 for (size_t i = 0; |
| 1372 i < formats_.api_format.reverse_input_stream().num_channels(); ++i) | 1404 i < formats_.api_format.reverse_input_stream().num_channels(); ++i) |
| 1373 msg->add_channel(src[i], channel_size); | 1405 msg->add_channel(src[i], channel_size); |
| 1374 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), | 1406 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), |
| 1375 &debug_dump_.num_bytes_left_for_log_, | 1407 &debug_dump_.num_bytes_left_for_log_, |
| 1376 &crit_debug_, &debug_dump_.render)); | 1408 &crit_debug_, &debug_dump_.render)); |
| 1377 } | 1409 } |
| 1378 #endif | 1410 #endif |
| 1379 | 1411 if (aec_dump_) { |
| 1412 const size_t channel_size = | |
| 1413 formats_.api_format.reverse_input_stream().num_frames(); | |
| 1414 const size_t num_channels = | |
| 1415 formats_.api_format.reverse_input_stream().num_channels(); | |
| 1416 aec_dump_->WriteRenderStreamMessage( | |
| 1417 FloatAudioFrame(src, num_channels, channel_size)); | |
| 1418 } | |
| 1380 render_.render_audio->CopyFrom(src, | 1419 render_.render_audio->CopyFrom(src, |
| 1381 formats_.api_format.reverse_input_stream()); | 1420 formats_.api_format.reverse_input_stream()); |
| 1382 return ProcessRenderStreamLocked(); | 1421 return ProcessRenderStreamLocked(); |
| 1383 } | 1422 } |
| 1384 | 1423 |
| 1385 int AudioProcessingImpl::ProcessReverseStream(AudioFrame* frame) { | 1424 int AudioProcessingImpl::ProcessReverseStream(AudioFrame* frame) { |
| 1386 TRACE_EVENT0("webrtc", "AudioProcessing::ProcessReverseStream_AudioFrame"); | 1425 TRACE_EVENT0("webrtc", "AudioProcessing::ProcessReverseStream_AudioFrame"); |
| 1387 rtc::CritScope cs(&crit_render_); | 1426 rtc::CritScope cs(&crit_render_); |
| 1388 if (frame == nullptr) { | 1427 if (frame == nullptr) { |
| 1389 return kNullPointerError; | 1428 return kNullPointerError; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1422 audioproc::ReverseStream* msg = | 1461 audioproc::ReverseStream* msg = |
| 1423 debug_dump_.render.event_msg->mutable_reverse_stream(); | 1462 debug_dump_.render.event_msg->mutable_reverse_stream(); |
| 1424 const size_t data_size = | 1463 const size_t data_size = |
| 1425 sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_; | 1464 sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_; |
| 1426 msg->set_data(frame->data_, data_size); | 1465 msg->set_data(frame->data_, data_size); |
| 1427 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), | 1466 RETURN_ON_ERR(WriteMessageToDebugFile(debug_dump_.debug_file.get(), |
| 1428 &debug_dump_.num_bytes_left_for_log_, | 1467 &debug_dump_.num_bytes_left_for_log_, |
| 1429 &crit_debug_, &debug_dump_.render)); | 1468 &crit_debug_, &debug_dump_.render)); |
| 1430 } | 1469 } |
| 1431 #endif | 1470 #endif |
| 1471 if (aec_dump_) { | |
| 1472 aec_dump_->WriteRenderStreamMessage(*frame); | |
| 1473 } | |
| 1474 | |
| 1432 render_.render_audio->DeinterleaveFrom(frame); | 1475 render_.render_audio->DeinterleaveFrom(frame); |
| 1433 RETURN_ON_ERR(ProcessRenderStreamLocked()); | 1476 RETURN_ON_ERR(ProcessRenderStreamLocked()); |
| 1434 render_.render_audio->InterleaveTo( | 1477 render_.render_audio->InterleaveTo( |
| 1435 frame, submodule_states_.RenderMultiBandProcessingActive()); | 1478 frame, submodule_states_.RenderMultiBandProcessingActive()); |
| 1436 return kNoError; | 1479 return kNoError; |
| 1437 } | 1480 } |
| 1438 | 1481 |
| 1439 int AudioProcessingImpl::ProcessRenderStreamLocked() { | 1482 int AudioProcessingImpl::ProcessRenderStreamLocked() { |
| 1440 AudioBuffer* render_buffer = render_.render_audio.get(); // For brevity. | 1483 AudioBuffer* render_buffer = render_.render_audio.get(); // For brevity. |
| 1441 if (submodule_states_.RenderMultiBandSubModulesActive() && | 1484 if (submodule_states_.RenderMultiBandSubModulesActive() && |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1505 void AudioProcessingImpl::set_delay_offset_ms(int offset) { | 1548 void AudioProcessingImpl::set_delay_offset_ms(int offset) { |
| 1506 rtc::CritScope cs(&crit_capture_); | 1549 rtc::CritScope cs(&crit_capture_); |
| 1507 capture_.delay_offset_ms = offset; | 1550 capture_.delay_offset_ms = offset; |
| 1508 } | 1551 } |
| 1509 | 1552 |
| 1510 int AudioProcessingImpl::delay_offset_ms() const { | 1553 int AudioProcessingImpl::delay_offset_ms() const { |
| 1511 rtc::CritScope cs(&crit_capture_); | 1554 rtc::CritScope cs(&crit_capture_); |
| 1512 return capture_.delay_offset_ms; | 1555 return capture_.delay_offset_ms; |
| 1513 } | 1556 } |
| 1514 | 1557 |
| 1558 void AudioProcessingImpl::AttachAecDump(std::unique_ptr<AecDump> aec_dump) { | |
| 1559 rtc::CritScope cs_render(&crit_render_); | |
| 1560 rtc::CritScope cs_capture(&crit_capture_); | |
| 1561 RTC_DCHECK(aec_dump); | |
| 1562 aec_dump_ = std::move(aec_dump); | |
|
peah-webrtc
2017/05/16 04:55:17
What happens if someone has forgot to Detach the p
aleloi
2017/05/16 20:12:06
Thanks, great that you spotted it!
| |
| 1563 | |
| 1564 aec_dump_->WriteConfig(CollectApmConfig(), true); | |
| 1565 aec_dump_->WriteInitMessage(ToStreamsConfig(formats_.api_format)); | |
| 1566 } | |
| 1567 | |
| 1568 void AudioProcessingImpl::DetachAecDump() { | |
| 1569 // The d-tor of a task-queue based AecDump blocks until all pending | |
| 1570 // tasks are done. This construction avoids blocking while holding | |
| 1571 // the render and capture locks. | |
| 1572 std::unique_ptr<AecDump> aec_dump = nullptr; | |
| 1573 { | |
| 1574 rtc::CritScope cs_render(&crit_render_); | |
| 1575 rtc::CritScope cs_capture(&crit_capture_); | |
| 1576 aec_dump = std::move(aec_dump_); | |
| 1577 } | |
| 1578 } | |
| 1579 | |
| 1515 int AudioProcessingImpl::StartDebugRecording( | 1580 int AudioProcessingImpl::StartDebugRecording( |
| 1516 const char filename[AudioProcessing::kMaxFilenameSize], | 1581 const char filename[AudioProcessing::kMaxFilenameSize], |
| 1517 int64_t max_log_size_bytes) { | 1582 int64_t max_log_size_bytes) { |
| 1518 // Run in a single-threaded manner. | 1583 // Run in a single-threaded manner. |
| 1519 rtc::CritScope cs_render(&crit_render_); | 1584 rtc::CritScope cs_render(&crit_render_); |
| 1520 rtc::CritScope cs_capture(&crit_capture_); | 1585 rtc::CritScope cs_capture(&crit_capture_); |
| 1521 static_assert(kMaxFilenameSize == FileWrapper::kMaxFileNameSize, ""); | 1586 static_assert(kMaxFilenameSize == FileWrapper::kMaxFileNameSize, ""); |
| 1522 | 1587 |
| 1523 if (filename == nullptr) { | 1588 if (filename == nullptr) { |
| 1524 return kNullPointerError; | 1589 return kNullPointerError; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1576 int AudioProcessingImpl::StartDebugRecordingForPlatformFile( | 1641 int AudioProcessingImpl::StartDebugRecordingForPlatformFile( |
| 1577 rtc::PlatformFile handle) { | 1642 rtc::PlatformFile handle) { |
| 1578 // Run in a single-threaded manner. | 1643 // Run in a single-threaded manner. |
| 1579 rtc::CritScope cs_render(&crit_render_); | 1644 rtc::CritScope cs_render(&crit_render_); |
| 1580 rtc::CritScope cs_capture(&crit_capture_); | 1645 rtc::CritScope cs_capture(&crit_capture_); |
| 1581 FILE* stream = rtc::FdopenPlatformFileForWriting(handle); | 1646 FILE* stream = rtc::FdopenPlatformFileForWriting(handle); |
| 1582 return StartDebugRecording(stream, -1); | 1647 return StartDebugRecording(stream, -1); |
| 1583 } | 1648 } |
| 1584 | 1649 |
| 1585 int AudioProcessingImpl::StopDebugRecording() { | 1650 int AudioProcessingImpl::StopDebugRecording() { |
| 1651 DetachAecDump(); | |
| 1652 | |
| 1653 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | |
| 1586 // Run in a single-threaded manner. | 1654 // Run in a single-threaded manner. |
| 1587 rtc::CritScope cs_render(&crit_render_); | 1655 rtc::CritScope cs_render(&crit_render_); |
| 1588 rtc::CritScope cs_capture(&crit_capture_); | 1656 rtc::CritScope cs_capture(&crit_capture_); |
| 1589 | |
| 1590 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | |
| 1591 // We just return if recording hasn't started. | 1657 // We just return if recording hasn't started. |
| 1592 debug_dump_.debug_file->CloseFile(); | 1658 debug_dump_.debug_file->CloseFile(); |
| 1593 return kNoError; | 1659 return kNoError; |
| 1594 #else | 1660 #else |
| 1595 return kUnsupportedFunctionError; | 1661 return kUnsupportedFunctionError; |
| 1596 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP | 1662 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 1597 } | 1663 } |
| 1598 | 1664 |
| 1599 AudioProcessing::AudioProcessingStatistics::AudioProcessingStatistics() { | 1665 AudioProcessing::AudioProcessingStatistics::AudioProcessingStatistics() { |
| 1600 residual_echo_return_loss.Set(-100.0f, -100.0f, -100.0f, -100.0f); | 1666 residual_echo_return_loss.Set(-100.0f, -100.0f, -100.0f, -100.0f); |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1830 capture_.last_stream_delay_ms = 0; | 1896 capture_.last_stream_delay_ms = 0; |
| 1831 | 1897 |
| 1832 if (capture_.aec_system_delay_jumps > -1) { | 1898 if (capture_.aec_system_delay_jumps > -1) { |
| 1833 RTC_HISTOGRAM_ENUMERATION("WebRTC.Audio.NumOfAecSystemDelayJumps", | 1899 RTC_HISTOGRAM_ENUMERATION("WebRTC.Audio.NumOfAecSystemDelayJumps", |
| 1834 capture_.aec_system_delay_jumps, 51); | 1900 capture_.aec_system_delay_jumps, 51); |
| 1835 } | 1901 } |
| 1836 capture_.aec_system_delay_jumps = -1; | 1902 capture_.aec_system_delay_jumps = -1; |
| 1837 capture_.last_aec_system_delay_ms = 0; | 1903 capture_.last_aec_system_delay_ms = 0; |
| 1838 } | 1904 } |
| 1839 | 1905 |
| 1906 InternalAPMConfig AudioProcessingImpl::CollectApmConfig() const { | |
| 1907 std::string experiments_description = | |
| 1908 public_submodules_->echo_cancellation->GetExperimentsDescription(); | |
| 1909 // TODO(peah): Add semicolon-separated concatenations of experiment | |
| 1910 // descriptions for other submodules. | |
| 1911 if (capture_nonlocked_.level_controller_enabled) { | |
| 1912 experiments_description += "LevelController;"; | |
| 1913 } | |
| 1914 if (constants_.agc_clipped_level_min != kClippedLevelMin) { | |
| 1915 experiments_description += "AgcClippingLevelExperiment;"; | |
| 1916 } | |
| 1917 if (capture_nonlocked_.echo_canceller3_enabled) { | |
| 1918 experiments_description += "EchoCanceller3;"; | |
| 1919 } | |
| 1920 | |
| 1921 InternalAPMConfig apm_config; | |
| 1922 | |
| 1923 apm_config.aec_enabled = public_submodules_->echo_cancellation->is_enabled(); | |
| 1924 apm_config.aec_delay_agnostic_enabled = | |
| 1925 public_submodules_->echo_cancellation->is_delay_agnostic_enabled(); | |
| 1926 apm_config.aec_drift_compensation_enabled = | |
| 1927 public_submodules_->echo_cancellation->is_drift_compensation_enabled(); | |
| 1928 apm_config.aec_extended_filter_enabled = | |
| 1929 public_submodules_->echo_cancellation->is_extended_filter_enabled(); | |
| 1930 apm_config.aec_suppression_level = static_cast<int>( | |
| 1931 public_submodules_->echo_cancellation->suppression_level()); | |
| 1932 | |
| 1933 apm_config.aecm_enabled = | |
| 1934 public_submodules_->echo_control_mobile->is_enabled(); | |
| 1935 apm_config.aecm_comfort_noise_enabled = | |
| 1936 public_submodules_->echo_control_mobile->is_comfort_noise_enabled(); | |
| 1937 apm_config.aecm_routing_mode = | |
| 1938 static_cast<int>(public_submodules_->echo_control_mobile->routing_mode()); | |
| 1939 | |
| 1940 apm_config.agc_enabled = public_submodules_->gain_control->is_enabled(); | |
| 1941 apm_config.agc_mode = | |
| 1942 static_cast<int>(public_submodules_->gain_control->mode()); | |
| 1943 apm_config.agc_limiter_enabled = | |
| 1944 public_submodules_->gain_control->is_limiter_enabled(); | |
| 1945 apm_config.noise_robust_agc_enabled = constants_.use_experimental_agc; | |
| 1946 | |
| 1947 apm_config.hpf_enabled = config_.high_pass_filter.enabled; | |
| 1948 | |
| 1949 apm_config.ns_enabled = public_submodules_->noise_suppression->is_enabled(); | |
| 1950 apm_config.ns_level = | |
| 1951 static_cast<int>(public_submodules_->noise_suppression->level()); | |
| 1952 | |
| 1953 apm_config.transient_suppression_enabled = | |
| 1954 capture_.transient_suppressor_enabled; | |
| 1955 apm_config.intelligibility_enhancer_enabled = | |
| 1956 capture_nonlocked_.intelligibility_enabled; | |
| 1957 apm_config.experiments_description = experiments_description; | |
| 1958 return apm_config; | |
| 1959 } | |
| 1960 | |
| 1961 void AudioProcessingImpl::RecordUnprocessedCaptureStream( | |
| 1962 const float* const* src) { | |
| 1963 RTC_DCHECK(aec_dump_); | |
| 1964 aec_dump_->WriteConfig(CollectApmConfig(), false); | |
| 1965 | |
| 1966 const size_t channel_size = formats_.api_format.input_stream().num_frames(); | |
| 1967 const size_t num_channels = formats_.api_format.input_stream().num_channels(); | |
| 1968 aec_dump_->AddCaptureStreamInput( | |
| 1969 FloatAudioFrame(src, num_channels, channel_size)); | |
| 1970 RecordAudioProcessingState(); | |
| 1971 } | |
| 1972 | |
| 1973 void AudioProcessingImpl::RecordUnprocessedCaptureStream( | |
| 1974 const AudioFrame& capture_frame) { | |
| 1975 RTC_DCHECK(aec_dump_); | |
| 1976 | |
| 1977 aec_dump_->AddCaptureStreamInput(capture_frame); | |
| 1978 RecordAudioProcessingState(); | |
| 1979 aec_dump_->WriteConfig(CollectApmConfig(), false); | |
| 1980 } | |
| 1981 | |
| 1982 void AudioProcessingImpl::RecordProcessedCaptureStream( | |
| 1983 const float* const* processed_capture_stream) { | |
| 1984 RTC_DCHECK(aec_dump_); | |
| 1985 | |
| 1986 const size_t channel_size = formats_.api_format.output_stream().num_frames(); | |
| 1987 const size_t num_channels = | |
| 1988 formats_.api_format.output_stream().num_channels(); | |
| 1989 aec_dump_->AddCaptureStreamOutput( | |
| 1990 FloatAudioFrame(processed_capture_stream, num_channels, channel_size)); | |
| 1991 aec_dump_->WriteCaptureStreamMessage(); | |
| 1992 } | |
| 1993 | |
| 1994 void AudioProcessingImpl::RecordProcessedCaptureStream( | |
| 1995 const AudioFrame& processed_capture_frame) { | |
| 1996 RTC_DCHECK(aec_dump_); | |
| 1997 | |
| 1998 aec_dump_->AddCaptureStreamOutput(processed_capture_frame); | |
| 1999 aec_dump_->WriteCaptureStreamMessage(); | |
| 2000 } | |
| 2001 | |
| 2002 void AudioProcessingImpl::RecordAudioProcessingState() { | |
| 2003 RTC_DCHECK(aec_dump_); | |
| 2004 AudioProcessingState audio_proc_state; | |
| 2005 audio_proc_state.delay = capture_nonlocked_.stream_delay_ms; | |
| 2006 audio_proc_state.drift = | |
| 2007 public_submodules_->echo_cancellation->stream_drift_samples(); | |
| 2008 audio_proc_state.level = gain_control()->stream_analog_level(); | |
| 2009 audio_proc_state.keypress = capture_.key_pressed; | |
| 2010 aec_dump_->AddAudioProcessingState(audio_proc_state); | |
| 2011 } | |
| 2012 | |
| 1840 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 2013 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 1841 int AudioProcessingImpl::WriteMessageToDebugFile( | 2014 int AudioProcessingImpl::WriteMessageToDebugFile( |
| 1842 FileWrapper* debug_file, | 2015 FileWrapper* debug_file, |
| 1843 int64_t* filesize_limit_bytes, | 2016 int64_t* filesize_limit_bytes, |
| 1844 rtc::CriticalSection* crit_debug, | 2017 rtc::CriticalSection* crit_debug, |
| 1845 ApmDebugDumpThreadState* debug_state) { | 2018 ApmDebugDumpThreadState* debug_state) { |
| 1846 int32_t size = debug_state->event_msg->ByteSize(); | 2019 int32_t size = debug_state->event_msg->ByteSize(); |
| 1847 if (size <= 0) { | 2020 if (size <= 0) { |
| 1848 return kUnspecifiedError; | 2021 return kUnspecifiedError; |
| 1849 } | 2022 } |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2003 previous_agc_level(0), | 2176 previous_agc_level(0), |
| 2004 echo_path_gain_change(false) {} | 2177 echo_path_gain_change(false) {} |
| 2005 | 2178 |
| 2006 AudioProcessingImpl::ApmCaptureState::~ApmCaptureState() = default; | 2179 AudioProcessingImpl::ApmCaptureState::~ApmCaptureState() = default; |
| 2007 | 2180 |
| 2008 AudioProcessingImpl::ApmRenderState::ApmRenderState() = default; | 2181 AudioProcessingImpl::ApmRenderState::ApmRenderState() = default; |
| 2009 | 2182 |
| 2010 AudioProcessingImpl::ApmRenderState::~ApmRenderState() = default; | 2183 AudioProcessingImpl::ApmRenderState::~ApmRenderState() = default; |
| 2011 | 2184 |
| 2012 } // namespace webrtc | 2185 } // namespace webrtc |
| OLD | NEW |