| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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 <iostream> | 11 #include <iostream> |
| 12 | 12 |
| 13 #include "webrtc/modules/audio_processing/test/aec_dump_based_simulator.h" | 13 #include "webrtc/modules/audio_processing/test/aec_dump_based_simulator.h" |
| 14 | 14 |
| 15 #include "webrtc/modules/audio_processing/test/protobuf_utils.h" | 15 #include "webrtc/modules/audio_processing/test/protobuf_utils.h" |
| 16 #include "webrtc/rtc_base/checks.h" | 16 #include "webrtc/rtc_base/checks.h" |
| 17 #include "webrtc/rtc_base/logging.h" |
| 17 #include "webrtc/test/testsupport/trace_to_stderr.h" | 18 #include "webrtc/test/testsupport/trace_to_stderr.h" |
| 18 | 19 |
| 19 namespace webrtc { | 20 namespace webrtc { |
| 20 namespace test { | 21 namespace test { |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 // Verify output bitexactness for the fixed interface. | 24 // Verify output bitexactness for the fixed interface. |
| 24 // TODO(peah): Check whether it would make sense to add a threshold | 25 // TODO(peah): Check whether it would make sense to add a threshold |
| 25 // to use for checking the bitexactness in a soft manner. | 26 // to use for checking the bitexactness in a soft manner. |
| 26 bool VerifyFixedBitExactness(const webrtc::audioproc::Stream& msg, | 27 bool VerifyFixedBitExactness(const webrtc::audioproc::Stream& msg, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 57 } | 58 } |
| 58 } | 59 } |
| 59 } | 60 } |
| 60 } | 61 } |
| 61 return true; | 62 return true; |
| 62 } | 63 } |
| 63 | 64 |
| 64 } // namespace | 65 } // namespace |
| 65 | 66 |
| 66 AecDumpBasedSimulator::AecDumpBasedSimulator(const SimulationSettings& settings) | 67 AecDumpBasedSimulator::AecDumpBasedSimulator(const SimulationSettings& settings) |
| 67 : AudioProcessingSimulator(settings) {} | 68 : AudioProcessingSimulator(settings) { |
| 69 if (settings_.simulate_mic_gain) |
| 70 LOG(LS_VERBOSE) << "Simulating analog mic gain using AEC dump as input"; |
| 71 } |
| 68 | 72 |
| 69 AecDumpBasedSimulator::~AecDumpBasedSimulator() = default; | 73 AecDumpBasedSimulator::~AecDumpBasedSimulator() = default; |
| 70 | 74 |
| 71 void AecDumpBasedSimulator::PrepareProcessStreamCall( | 75 void AecDumpBasedSimulator::PrepareProcessStreamCall( |
| 72 const webrtc::audioproc::Stream& msg, | 76 const webrtc::audioproc::Stream& msg) { |
| 73 bool* set_stream_analog_level_called) { | |
| 74 if (msg.has_input_data()) { | 77 if (msg.has_input_data()) { |
| 75 // Fixed interface processing. | 78 // Fixed interface processing. |
| 76 // Verify interface invariance. | 79 // Verify interface invariance. |
| 77 RTC_CHECK(interface_used_ == InterfaceType::kFixedInterface || | 80 RTC_CHECK(interface_used_ == InterfaceType::kFixedInterface || |
| 78 interface_used_ == InterfaceType::kNotSpecified); | 81 interface_used_ == InterfaceType::kNotSpecified); |
| 79 interface_used_ = InterfaceType::kFixedInterface; | 82 interface_used_ = InterfaceType::kFixedInterface; |
| 80 | 83 |
| 81 // Populate input buffer. | 84 // Populate input buffer. |
| 82 RTC_CHECK_EQ(sizeof(*fwd_frame_.data()) * fwd_frame_.samples_per_channel_ * | 85 RTC_CHECK_EQ(sizeof(*fwd_frame_.data()) * fwd_frame_.samples_per_channel_ * |
| 83 fwd_frame_.num_channels_, | 86 fwd_frame_.num_channels_, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 } | 155 } |
| 153 | 156 |
| 154 if (!settings_.use_ts) { | 157 if (!settings_.use_ts) { |
| 155 if (msg.has_keypress()) { | 158 if (msg.has_keypress()) { |
| 156 ap_->set_stream_key_pressed(msg.keypress()); | 159 ap_->set_stream_key_pressed(msg.keypress()); |
| 157 } | 160 } |
| 158 } else { | 161 } else { |
| 159 ap_->set_stream_key_pressed(*settings_.use_ts); | 162 ap_->set_stream_key_pressed(*settings_.use_ts); |
| 160 } | 163 } |
| 161 | 164 |
| 162 // TODO(peah): Add support for controlling the analog level via the | 165 // Level is always logged in AEC dumps. |
| 163 // command-line. | 166 RTC_CHECK(msg.has_level()); |
| 164 if (msg.has_level()) { | 167 aec_dump_mic_level_ = rtc::Optional<int>(msg.level()); |
| 165 RTC_CHECK_EQ(AudioProcessing::kNoError, | |
| 166 ap_->gain_control()->set_stream_analog_level(msg.level())); | |
| 167 *set_stream_analog_level_called = true; | |
| 168 } else { | |
| 169 *set_stream_analog_level_called = false; | |
| 170 } | |
| 171 } | 168 } |
| 172 | 169 |
| 173 void AecDumpBasedSimulator::VerifyProcessStreamBitExactness( | 170 void AecDumpBasedSimulator::VerifyProcessStreamBitExactness( |
| 174 const webrtc::audioproc::Stream& msg) { | 171 const webrtc::audioproc::Stream& msg) { |
| 175 if (bitexact_output_) { | 172 if (bitexact_output_) { |
| 176 if (interface_used_ == InterfaceType::kFixedInterface) { | 173 if (interface_used_ == InterfaceType::kFixedInterface) { |
| 177 bitexact_output_ = VerifyFixedBitExactness(msg, fwd_frame_); | 174 bitexact_output_ = VerifyFixedBitExactness(msg, fwd_frame_); |
| 178 } else { | 175 } else { |
| 179 bitexact_output_ = VerifyFloatBitExactness(msg, out_config_, *out_buf_); | 176 bitexact_output_ = VerifyFloatBitExactness(msg, out_config_, *out_buf_); |
| 180 } | 177 } |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 } | 555 } |
| 559 | 556 |
| 560 SetupBuffersConfigsOutputs( | 557 SetupBuffersConfigsOutputs( |
| 561 msg.sample_rate(), output_sample_rate, msg.reverse_sample_rate(), | 558 msg.sample_rate(), output_sample_rate, msg.reverse_sample_rate(), |
| 562 reverse_output_sample_rate, msg.num_input_channels(), num_output_channels, | 559 reverse_output_sample_rate, msg.num_input_channels(), num_output_channels, |
| 563 msg.num_reverse_channels(), num_reverse_output_channels); | 560 msg.num_reverse_channels(), num_reverse_output_channels); |
| 564 } | 561 } |
| 565 | 562 |
| 566 void AecDumpBasedSimulator::HandleMessage( | 563 void AecDumpBasedSimulator::HandleMessage( |
| 567 const webrtc::audioproc::Stream& msg) { | 564 const webrtc::audioproc::Stream& msg) { |
| 568 bool set_stream_analog_level_called = false; | 565 PrepareProcessStreamCall(msg); |
| 569 PrepareProcessStreamCall(msg, &set_stream_analog_level_called); | |
| 570 ProcessStream(interface_used_ == InterfaceType::kFixedInterface); | 566 ProcessStream(interface_used_ == InterfaceType::kFixedInterface); |
| 571 if (set_stream_analog_level_called) { | |
| 572 // Call stream analog level to ensure that any side-effects are triggered. | |
| 573 (void)ap_->gain_control()->stream_analog_level(); | |
| 574 } | |
| 575 | |
| 576 VerifyProcessStreamBitExactness(msg); | 567 VerifyProcessStreamBitExactness(msg); |
| 577 } | 568 } |
| 578 | 569 |
| 579 void AecDumpBasedSimulator::HandleMessage( | 570 void AecDumpBasedSimulator::HandleMessage( |
| 580 const webrtc::audioproc::ReverseStream& msg) { | 571 const webrtc::audioproc::ReverseStream& msg) { |
| 581 PrepareReverseProcessStreamCall(msg); | 572 PrepareReverseProcessStreamCall(msg); |
| 582 ProcessReverseStream(interface_used_ == InterfaceType::kFixedInterface); | 573 ProcessReverseStream(interface_used_ == InterfaceType::kFixedInterface); |
| 583 } | 574 } |
| 584 | 575 |
| 585 } // namespace test | 576 } // namespace test |
| 586 } // namespace webrtc | 577 } // namespace webrtc |
| OLD | NEW |