| 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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 EXPECT_TRUE(audio_processing->voice_detection()->is_enabled()); | 147 EXPECT_TRUE(audio_processing->voice_detection()->is_enabled()); |
| 148 EXPECT_TRUE(audio_processing->voice_detection()->likelihood() == | 148 EXPECT_TRUE(audio_processing->voice_detection()->likelihood() == |
| 149 webrtc::VoiceDetection::kVeryLowLikelihood); | 149 webrtc::VoiceDetection::kVeryLowLikelihood); |
| 150 #endif | 150 #endif |
| 151 } | 151 } |
| 152 | 152 |
| 153 media::AudioParameters params_; | 153 media::AudioParameters params_; |
| 154 }; | 154 }; |
| 155 | 155 |
| 156 TEST_F(MediaStreamAudioProcessorTest, WithoutAudioProcessing) { | 156 TEST_F(MediaStreamAudioProcessorTest, WithoutAudioProcessing) { |
| 157 // Setup the audio processor with disabled flag on. | 157 // Setup the audio processor without enabling the flag. |
| 158 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 159 switches::kDisableAudioTrackProcessing); | |
| 160 MockMediaConstraintFactory constraint_factory; | 158 MockMediaConstraintFactory constraint_factory; |
| 161 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( | 159 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( |
| 162 new WebRtcAudioDeviceImpl()); | 160 new WebRtcAudioDeviceImpl()); |
| 163 scoped_refptr<MediaStreamAudioProcessor> audio_processor( | 161 scoped_refptr<MediaStreamAudioProcessor> audio_processor( |
| 164 new talk_base::RefCountedObject<MediaStreamAudioProcessor>( | 162 new talk_base::RefCountedObject<MediaStreamAudioProcessor>( |
| 165 constraint_factory.CreateWebMediaConstraints(), 0, | 163 constraint_factory.CreateWebMediaConstraints(), 0, |
| 166 webrtc_audio_device.get())); | 164 webrtc_audio_device.get())); |
| 167 EXPECT_FALSE(audio_processor->has_audio_processing()); | 165 EXPECT_FALSE(audio_processor->has_audio_processing()); |
| 168 audio_processor->OnCaptureFormatChanged(params_); | 166 audio_processor->OnCaptureFormatChanged(params_); |
| 169 | 167 |
| 170 ProcessDataAndVerifyFormat(audio_processor, | 168 ProcessDataAndVerifyFormat(audio_processor, |
| 171 params_.sample_rate(), | 169 params_.sample_rate(), |
| 172 params_.channels(), | 170 params_.channels(), |
| 173 params_.sample_rate() / 100); | 171 params_.sample_rate() / 100); |
| 174 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives | 172 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives |
| 175 // |audio_processor|. | 173 // |audio_processor|. |
| 176 audio_processor = NULL; | 174 audio_processor = NULL; |
| 177 } | 175 } |
| 178 | 176 |
| 179 TEST_F(MediaStreamAudioProcessorTest, WithAudioProcessing) { | 177 TEST_F(MediaStreamAudioProcessorTest, WithAudioProcessing) { |
| 178 // Setup the audio processor with the flag enabled. |
| 179 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 180 switches::kEnableAudioTrackProcessing); |
| 180 MockMediaConstraintFactory constraint_factory; | 181 MockMediaConstraintFactory constraint_factory; |
| 181 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( | 182 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( |
| 182 new WebRtcAudioDeviceImpl()); | 183 new WebRtcAudioDeviceImpl()); |
| 183 scoped_refptr<MediaStreamAudioProcessor> audio_processor( | 184 scoped_refptr<MediaStreamAudioProcessor> audio_processor( |
| 184 new talk_base::RefCountedObject<MediaStreamAudioProcessor>( | 185 new talk_base::RefCountedObject<MediaStreamAudioProcessor>( |
| 185 constraint_factory.CreateWebMediaConstraints(), 0, | 186 constraint_factory.CreateWebMediaConstraints(), 0, |
| 186 webrtc_audio_device.get())); | 187 webrtc_audio_device.get())); |
| 187 EXPECT_TRUE(audio_processor->has_audio_processing()); | 188 EXPECT_TRUE(audio_processor->has_audio_processing()); |
| 188 audio_processor->OnCaptureFormatChanged(params_); | 189 audio_processor->OnCaptureFormatChanged(params_); |
| 189 VerifyDefaultComponents(audio_processor); | 190 VerifyDefaultComponents(audio_processor); |
| 190 | 191 |
| 191 ProcessDataAndVerifyFormat(audio_processor, | 192 ProcessDataAndVerifyFormat(audio_processor, |
| 192 kAudioProcessingSampleRate, | 193 kAudioProcessingSampleRate, |
| 193 kAudioProcessingNumberOfChannel, | 194 kAudioProcessingNumberOfChannel, |
| 194 kAudioProcessingSampleRate / 100); | 195 kAudioProcessingSampleRate / 100); |
| 195 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives | 196 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives |
| 196 // |audio_processor|. | 197 // |audio_processor|. |
| 197 audio_processor = NULL; | 198 audio_processor = NULL; |
| 198 } | 199 } |
| 199 | 200 |
| 200 TEST_F(MediaStreamAudioProcessorTest, VerifyTabCaptureWithoutAudioProcessing) { | 201 TEST_F(MediaStreamAudioProcessorTest, VerifyTabCaptureWithoutAudioProcessing) { |
| 202 // Setup the audio processor with enabling the flag. |
| 203 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 204 switches::kEnableAudioTrackProcessing); |
| 201 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( | 205 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( |
| 202 new WebRtcAudioDeviceImpl()); | 206 new WebRtcAudioDeviceImpl()); |
| 203 // Create MediaStreamAudioProcessor instance for kMediaStreamSourceTab source. | 207 // Create MediaStreamAudioProcessor instance for kMediaStreamSourceTab source. |
| 204 MockMediaConstraintFactory tab_constraint_factory; | 208 MockMediaConstraintFactory tab_constraint_factory; |
| 205 const std::string tab_string = kMediaStreamSourceTab; | 209 const std::string tab_string = kMediaStreamSourceTab; |
| 206 tab_constraint_factory.AddMandatory(kMediaStreamSource, | 210 tab_constraint_factory.AddMandatory(kMediaStreamSource, |
| 207 tab_string); | 211 tab_string); |
| 208 scoped_refptr<MediaStreamAudioProcessor> audio_processor( | 212 scoped_refptr<MediaStreamAudioProcessor> audio_processor( |
| 209 new talk_base::RefCountedObject<MediaStreamAudioProcessor>( | 213 new talk_base::RefCountedObject<MediaStreamAudioProcessor>( |
| 210 tab_constraint_factory.CreateWebMediaConstraints(), 0, | 214 tab_constraint_factory.CreateWebMediaConstraints(), 0, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 227 system_constraint_factory.CreateWebMediaConstraints(), 0, | 231 system_constraint_factory.CreateWebMediaConstraints(), 0, |
| 228 webrtc_audio_device.get()); | 232 webrtc_audio_device.get()); |
| 229 EXPECT_FALSE(audio_processor->has_audio_processing()); | 233 EXPECT_FALSE(audio_processor->has_audio_processing()); |
| 230 | 234 |
| 231 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives | 235 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives |
| 232 // |audio_processor|. | 236 // |audio_processor|. |
| 233 audio_processor = NULL; | 237 audio_processor = NULL; |
| 234 } | 238 } |
| 235 | 239 |
| 236 TEST_F(MediaStreamAudioProcessorTest, TurnOffDefaultConstraints) { | 240 TEST_F(MediaStreamAudioProcessorTest, TurnOffDefaultConstraints) { |
| 241 // Setup the audio processor with enabling the flag. |
| 242 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 243 switches::kEnableAudioTrackProcessing); |
| 244 |
| 237 // Turn off the default constraints and pass it to MediaStreamAudioProcessor. | 245 // Turn off the default constraints and pass it to MediaStreamAudioProcessor. |
| 238 MockMediaConstraintFactory constraint_factory; | 246 MockMediaConstraintFactory constraint_factory; |
| 239 constraint_factory.DisableDefaultAudioConstraints(); | 247 constraint_factory.DisableDefaultAudioConstraints(); |
| 240 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( | 248 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( |
| 241 new WebRtcAudioDeviceImpl()); | 249 new WebRtcAudioDeviceImpl()); |
| 242 scoped_refptr<MediaStreamAudioProcessor> audio_processor( | 250 scoped_refptr<MediaStreamAudioProcessor> audio_processor( |
| 243 new talk_base::RefCountedObject<MediaStreamAudioProcessor>( | 251 new talk_base::RefCountedObject<MediaStreamAudioProcessor>( |
| 244 constraint_factory.CreateWebMediaConstraints(), 0, | 252 constraint_factory.CreateWebMediaConstraints(), 0, |
| 245 webrtc_audio_device.get())); | 253 webrtc_audio_device.get())); |
| 246 EXPECT_FALSE(audio_processor->has_audio_processing()); | 254 EXPECT_FALSE(audio_processor->has_audio_processing()); |
| 247 audio_processor->OnCaptureFormatChanged(params_); | 255 audio_processor->OnCaptureFormatChanged(params_); |
| 248 | 256 |
| 249 ProcessDataAndVerifyFormat(audio_processor, | 257 ProcessDataAndVerifyFormat(audio_processor, |
| 250 params_.sample_rate(), | 258 params_.sample_rate(), |
| 251 params_.channels(), | 259 params_.channels(), |
| 252 params_.sample_rate() / 100); | 260 params_.sample_rate() / 100); |
| 253 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives | 261 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives |
| 254 // |audio_processor|. | 262 // |audio_processor|. |
| 255 audio_processor = NULL; | 263 audio_processor = NULL; |
| 256 } | 264 } |
| 257 | 265 |
| 258 TEST_F(MediaStreamAudioProcessorTest, VerifyConstraints) { | 266 TEST_F(MediaStreamAudioProcessorTest, VerifyConstraints) { |
| 267 // Setup the audio processor with enabling the flag. |
| 268 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 269 switches::kEnableAudioTrackProcessing); |
| 270 |
| 259 static const char* kDefaultAudioConstraints[] = { | 271 static const char* kDefaultAudioConstraints[] = { |
| 260 MediaAudioConstraints::kEchoCancellation, | 272 MediaAudioConstraints::kEchoCancellation, |
| 261 MediaAudioConstraints::kGoogAudioMirroring, | 273 MediaAudioConstraints::kGoogAudioMirroring, |
| 262 MediaAudioConstraints::kGoogAutoGainControl, | 274 MediaAudioConstraints::kGoogAutoGainControl, |
| 263 MediaAudioConstraints::kGoogEchoCancellation, | 275 MediaAudioConstraints::kGoogEchoCancellation, |
| 264 MediaAudioConstraints::kGoogExperimentalEchoCancellation, | 276 MediaAudioConstraints::kGoogExperimentalEchoCancellation, |
| 265 MediaAudioConstraints::kGoogExperimentalAutoGainControl, | 277 MediaAudioConstraints::kGoogExperimentalAutoGainControl, |
| 266 MediaAudioConstraints::kGoogExperimentalNoiseSuppression, | 278 MediaAudioConstraints::kGoogExperimentalNoiseSuppression, |
| 267 MediaAudioConstraints::kGoogHighpassFilter, | 279 MediaAudioConstraints::kGoogHighpassFilter, |
| 268 MediaAudioConstraints::kGoogNoiseSuppression, | 280 MediaAudioConstraints::kGoogNoiseSuppression, |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 kAudioProcessingNumberOfChannel, | 390 kAudioProcessingNumberOfChannel, |
| 379 kAudioProcessingSampleRate / 100); | 391 kAudioProcessingSampleRate / 100); |
| 380 } | 392 } |
| 381 | 393 |
| 382 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| | 394 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| |
| 383 // outlives |audio_processor|. | 395 // outlives |audio_processor|. |
| 384 audio_processor = NULL; | 396 audio_processor = NULL; |
| 385 } | 397 } |
| 386 | 398 |
| 387 } // namespace content | 399 } // namespace content |
| OLD | NEW |