Chromium Code Reviews| 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 "webrtc/modules/audio_processing/test/wav_based_simulator.h" | 11 #include "webrtc/modules/audio_processing/test/wav_based_simulator.h" |
| 12 | 12 |
| 13 #include <string.h> | |
| 14 #include <iostream> | |
| 13 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
| 16 #include "webrtc/modules/audio_processing/test/test_utils.h" | |
| 14 #include "webrtc/test/testsupport/trace_to_stderr.h" | 17 #include "webrtc/test/testsupport/trace_to_stderr.h" |
| 15 | 18 |
| 16 namespace webrtc { | 19 namespace webrtc { |
| 17 namespace test { | 20 namespace test { |
| 18 | 21 |
| 22 std::vector<WavBasedSimulator::SimulationEventType> | |
| 23 WavBasedSimulator::GetCustomEventChain(const std::string& filename) { | |
| 24 std::vector<WavBasedSimulator::SimulationEventType> call_chain; | |
| 25 FILE* stream = OpenFile(filename.c_str(), "r"); | |
| 26 | |
| 27 if (!stream) { | |
|
hlundin-webrtc
2016/12/09 10:40:17
This is test/tools code. Crashing and burning rath
peah-webrtc
2016/12/09 10:49:59
Done.
| |
| 28 std::cout << "Could not open the custom call order file, reverting to " | |
| 29 "using the default call order"; | |
| 30 return WavBasedSimulator::GetDefaultEventChain(); | |
| 31 } | |
| 32 | |
| 33 char c; | |
| 34 size_t num_read = fread(&c, sizeof(char), 1, stream); | |
|
ivoc
2016/12/09 10:28:20
I think this is defined in <stdio.h>, shouldn't th
peah-webrtc
2016/12/09 10:49:59
Good point! I removed the inclusion of <string.h>
| |
| 35 while (num_read > 0) { | |
| 36 switch (c) { | |
| 37 case 'r': | |
| 38 call_chain.push_back(SimulationEventType::kProcessReverseStream); | |
| 39 break; | |
| 40 case 'c': | |
| 41 call_chain.push_back(SimulationEventType::kProcessStream); | |
| 42 break; | |
| 43 case '\n': | |
| 44 break; | |
| 45 default: | |
| 46 std::cout << "Incorrect custom call order file, reverting to using the " | |
|
hlundin-webrtc
2016/12/09 10:40:17
FATAL() << "What kind of input is this?!";
peah-webrtc
2016/12/09 10:49:59
Done.
| |
| 47 "default call order"; | |
| 48 fclose(stream); | |
| 49 return WavBasedSimulator::GetDefaultEventChain(); | |
| 50 } | |
| 51 | |
| 52 num_read = fread(&c, sizeof(char), 1, stream); | |
| 53 } | |
| 54 | |
| 55 fclose(stream); | |
| 56 return call_chain; | |
| 57 } | |
| 58 | |
| 19 WavBasedSimulator::WavBasedSimulator(const SimulationSettings& settings) | 59 WavBasedSimulator::WavBasedSimulator(const SimulationSettings& settings) |
| 20 : AudioProcessingSimulator(settings) {} | 60 : AudioProcessingSimulator(settings) {} |
| 21 | 61 |
| 22 WavBasedSimulator::~WavBasedSimulator() = default; | 62 WavBasedSimulator::~WavBasedSimulator() = default; |
| 23 | 63 |
| 24 std::vector<WavBasedSimulator::SimulationEventType> | 64 std::vector<WavBasedSimulator::SimulationEventType> |
| 25 WavBasedSimulator::GetDefaultEventChain() const { | 65 WavBasedSimulator::GetDefaultEventChain() { |
|
aleloi
2016/12/09 10:25:44
Why is GetDefaultEventChain not const now?
hlundin-webrtc
2016/12/09 10:40:17
It was made static in the header file.
peah-webrtc
2016/12/09 10:49:59
I made it static which caused it not possible to m
peah-webrtc
2016/12/09 10:49:59
Acknowledged.
| |
| 26 std::vector<WavBasedSimulator::SimulationEventType> call_chain(2); | 66 std::vector<WavBasedSimulator::SimulationEventType> call_chain(2); |
| 27 call_chain[0] = SimulationEventType::kProcessStream; | 67 call_chain[0] = SimulationEventType::kProcessStream; |
| 28 call_chain[1] = SimulationEventType::kProcessReverseStream; | 68 call_chain[1] = SimulationEventType::kProcessReverseStream; |
| 29 return call_chain; | 69 return call_chain; |
| 30 } | 70 } |
| 31 | 71 |
| 32 void WavBasedSimulator::PrepareProcessStreamCall() { | 72 void WavBasedSimulator::PrepareProcessStreamCall() { |
| 33 if (settings_.fixed_interface) { | 73 if (settings_.fixed_interface) { |
| 34 CopyToAudioFrame(*in_buf_, &fwd_frame_); | 74 CopyToAudioFrame(*in_buf_, &fwd_frame_); |
| 35 } | 75 } |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 52 CopyToAudioFrame(*reverse_in_buf_, &rev_frame_); | 92 CopyToAudioFrame(*reverse_in_buf_, &rev_frame_); |
| 53 } | 93 } |
| 54 } | 94 } |
| 55 | 95 |
| 56 void WavBasedSimulator::Process() { | 96 void WavBasedSimulator::Process() { |
| 57 std::unique_ptr<test::TraceToStderr> trace_to_stderr; | 97 std::unique_ptr<test::TraceToStderr> trace_to_stderr; |
| 58 if (settings_.use_verbose_logging) { | 98 if (settings_.use_verbose_logging) { |
| 59 trace_to_stderr.reset(new test::TraceToStderr(true)); | 99 trace_to_stderr.reset(new test::TraceToStderr(true)); |
| 60 } | 100 } |
| 61 | 101 |
| 62 call_chain_ = GetDefaultEventChain(); | 102 if (settings_.custom_call_order_filename) { |
| 103 call_chain_ = WavBasedSimulator::GetCustomEventChain( | |
| 104 *settings_.custom_call_order_filename); | |
| 105 } else { | |
| 106 call_chain_ = WavBasedSimulator::GetDefaultEventChain(); | |
| 107 } | |
| 63 CreateAudioProcessor(); | 108 CreateAudioProcessor(); |
| 64 | 109 |
| 65 Initialize(); | 110 Initialize(); |
| 66 | 111 |
| 67 bool samples_left_to_process = true; | 112 bool samples_left_to_process = true; |
| 68 int call_chain_index = 0; | 113 int call_chain_index = 0; |
| 69 int num_forward_chunks_processed = 0; | 114 int num_forward_chunks_processed = 0; |
| 70 const int kOneBykChunksPerSecond = | 115 const int kOneBykChunksPerSecond = |
| 71 1.f / AudioProcessingSimulator::kChunksPerSecond; | 116 1.f / AudioProcessingSimulator::kChunksPerSecond; |
| 72 while (samples_left_to_process) { | 117 while (samples_left_to_process) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 } | 199 } |
| 155 | 200 |
| 156 SetupBuffersConfigsOutputs( | 201 SetupBuffersConfigsOutputs( |
| 157 input_sample_rate_hz, output_sample_rate_hz, reverse_sample_rate_hz, | 202 input_sample_rate_hz, output_sample_rate_hz, reverse_sample_rate_hz, |
| 158 reverse_output_sample_rate_hz, input_num_channels, output_num_channels, | 203 reverse_output_sample_rate_hz, input_num_channels, output_num_channels, |
| 159 reverse_num_channels, reverse_output_num_channels); | 204 reverse_num_channels, reverse_output_num_channels); |
| 160 } | 205 } |
| 161 | 206 |
| 162 } // namespace test | 207 } // namespace test |
| 163 } // namespace webrtc | 208 } // namespace webrtc |
| OLD | NEW |