OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 ReadDataFromSpeechFile(capture_data.get(), length); | 73 ReadDataFromSpeechFile(capture_data.get(), length); |
74 const int16* data_ptr = reinterpret_cast<const int16*>(capture_data.get()); | 74 const int16* data_ptr = reinterpret_cast<const int16*>(capture_data.get()); |
75 scoped_ptr<media::AudioBus> data_bus = media::AudioBus::Create( | 75 scoped_ptr<media::AudioBus> data_bus = media::AudioBus::Create( |
76 params_.channels(), params_.frames_per_buffer()); | 76 params_.channels(), params_.frames_per_buffer()); |
77 for (int i = 0; i < kNumberOfPacketsForTest; ++i) { | 77 for (int i = 0; i < kNumberOfPacketsForTest; ++i) { |
78 data_bus->FromInterleaved(data_ptr, data_bus->frames(), 2); | 78 data_bus->FromInterleaved(data_ptr, data_bus->frames(), 2); |
79 audio_processor->PushCaptureData(data_bus.get()); | 79 audio_processor->PushCaptureData(data_bus.get()); |
80 | 80 |
81 // |audio_processor| does nothing when the audio processing is off in | 81 // |audio_processor| does nothing when the audio processing is off in |
82 // the processor. | 82 // the processor. |
83 audio_processor->PushRenderData( | 83 webrtc::AudioProcessing* ap = audio_processor->audio_processing_.get(); |
84 data_ptr, | 84 #if defined(OS_ANDROID) || defined(OS_IOS) |
85 params_.sample_rate(), params_.channels(), | 85 const bool is_aec_enabled = ap && ap->echo_control_mobile()->is_enabled(); |
86 params_.frames_per_buffer(), base::TimeDelta::FromMilliseconds(10)); | 86 // AEC should be turned off for mobiles. |
| 87 DCHECK(!ap || !ap->echo_cancellation()->is_enabled()); |
| 88 #else |
| 89 const bool is_aec_enabled = ap && ap->echo_cancellation()->is_enabled(); |
| 90 #endif |
| 91 if (is_aec_enabled) { |
| 92 audio_processor->OnPlayoutData(data_bus.get(), params_.sample_rate(), |
| 93 10); |
| 94 } |
87 | 95 |
88 int16* output = NULL; | 96 int16* output = NULL; |
89 int new_volume = 0; | 97 int new_volume = 0; |
90 while(audio_processor->ProcessAndConsumeData( | 98 while(audio_processor->ProcessAndConsumeData( |
91 base::TimeDelta::FromMilliseconds(10), 255, false, &new_volume, | 99 base::TimeDelta::FromMilliseconds(10), 255, false, &new_volume, |
92 &output)) { | 100 &output)) { |
93 EXPECT_TRUE(output != NULL); | 101 EXPECT_TRUE(output != NULL); |
94 EXPECT_EQ(audio_processor->OutputFormat().sample_rate(), | 102 EXPECT_EQ(audio_processor->OutputFormat().sample_rate(), |
95 expected_output_sample_rate); | 103 expected_output_sample_rate); |
96 EXPECT_EQ(audio_processor->OutputFormat().channels(), | 104 EXPECT_EQ(audio_processor->OutputFormat().channels(), |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 #endif | 146 #endif |
139 } | 147 } |
140 | 148 |
141 media::AudioParameters params_; | 149 media::AudioParameters params_; |
142 }; | 150 }; |
143 | 151 |
144 TEST_F(MediaStreamAudioProcessorTest, WithoutAudioProcessing) { | 152 TEST_F(MediaStreamAudioProcessorTest, WithoutAudioProcessing) { |
145 // Setup the audio processor without enabling the flag. | 153 // Setup the audio processor without enabling the flag. |
146 blink::WebMediaConstraints constraints; | 154 blink::WebMediaConstraints constraints; |
147 scoped_refptr<MediaStreamAudioProcessor> audio_processor( | 155 scoped_refptr<MediaStreamAudioProcessor> audio_processor( |
148 new MediaStreamAudioProcessor(params_, constraints, 0)); | 156 new MediaStreamAudioProcessor(params_, constraints, 0, NULL)); |
149 EXPECT_FALSE(audio_processor->has_audio_processing()); | 157 EXPECT_FALSE(audio_processor->has_audio_processing()); |
150 | 158 |
151 ProcessDataAndVerifyFormat(audio_processor, | 159 ProcessDataAndVerifyFormat(audio_processor, |
152 params_.sample_rate(), | 160 params_.sample_rate(), |
153 params_.channels(), | 161 params_.channels(), |
154 params_.sample_rate() / 100); | 162 params_.sample_rate() / 100); |
155 } | 163 } |
156 | 164 |
157 TEST_F(MediaStreamAudioProcessorTest, WithAudioProcessing) { | 165 TEST_F(MediaStreamAudioProcessorTest, WithAudioProcessing) { |
158 // Setup the audio processor with enabling the flag. | 166 // Setup the audio processor with enabling the flag. |
159 CommandLine::ForCurrentProcess()->AppendSwitch( | 167 CommandLine::ForCurrentProcess()->AppendSwitch( |
160 switches::kEnableAudioTrackProcessing); | 168 switches::kEnableAudioTrackProcessing); |
161 blink::WebMediaConstraints constraints; | 169 blink::WebMediaConstraints constraints; |
162 scoped_refptr<MediaStreamAudioProcessor> audio_processor( | 170 scoped_refptr<MediaStreamAudioProcessor> audio_processor( |
163 new MediaStreamAudioProcessor(params_, constraints, 0)); | 171 new MediaStreamAudioProcessor(params_, constraints, 0, NULL)); |
164 EXPECT_TRUE(audio_processor->has_audio_processing()); | 172 EXPECT_TRUE(audio_processor->has_audio_processing()); |
165 VerifyDefaultComponents(audio_processor); | 173 VerifyDefaultComponents(audio_processor); |
166 | 174 |
167 ProcessDataAndVerifyFormat(audio_processor, | 175 ProcessDataAndVerifyFormat(audio_processor, |
168 kAudioProcessingSampleRate, | 176 kAudioProcessingSampleRate, |
169 kAudioProcessingNumberOfChannel, | 177 kAudioProcessingNumberOfChannel, |
170 kAudioProcessingSampleRate / 100); | 178 kAudioProcessingSampleRate / 100); |
171 } | 179 } |
172 | 180 |
173 } // namespace content | 181 } // namespace content |
OLD | NEW |