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