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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 512) { | 62 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 512) { |
63 } | 63 } |
64 | 64 |
65 protected: | 65 protected: |
66 // Helper method to save duplicated code. | 66 // Helper method to save duplicated code. |
67 void ProcessDataAndVerifyFormat(MediaStreamAudioProcessor* audio_processor, | 67 void ProcessDataAndVerifyFormat(MediaStreamAudioProcessor* audio_processor, |
68 int expected_output_sample_rate, | 68 int expected_output_sample_rate, |
69 int expected_output_channels, | 69 int expected_output_channels, |
70 int expected_output_buffer_size) { | 70 int expected_output_buffer_size) { |
71 // Read the audio data from a file. | 71 // Read the audio data from a file. |
| 72 const media::AudioParameters& params = audio_processor->InputFormat(); |
72 const int packet_size = | 73 const int packet_size = |
73 params_.frames_per_buffer() * 2 * params_.channels(); | 74 params.frames_per_buffer() * 2 * params.channels(); |
74 const size_t length = packet_size * kNumberOfPacketsForTest; | 75 const size_t length = packet_size * kNumberOfPacketsForTest; |
75 scoped_ptr<char[]> capture_data(new char[length]); | 76 scoped_ptr<char[]> capture_data(new char[length]); |
76 ReadDataFromSpeechFile(capture_data.get(), length); | 77 ReadDataFromSpeechFile(capture_data.get(), length); |
77 const int16* data_ptr = reinterpret_cast<const int16*>(capture_data.get()); | 78 const int16* data_ptr = reinterpret_cast<const int16*>(capture_data.get()); |
78 scoped_ptr<media::AudioBus> data_bus = media::AudioBus::Create( | 79 scoped_ptr<media::AudioBus> data_bus = media::AudioBus::Create( |
79 params_.channels(), params_.frames_per_buffer()); | 80 params.channels(), params.frames_per_buffer()); |
80 for (int i = 0; i < kNumberOfPacketsForTest; ++i) { | 81 for (int i = 0; i < kNumberOfPacketsForTest; ++i) { |
81 data_bus->FromInterleaved(data_ptr, data_bus->frames(), 2); | 82 data_bus->FromInterleaved(data_ptr, data_bus->frames(), 2); |
82 audio_processor->PushCaptureData(data_bus.get()); | 83 audio_processor->PushCaptureData(data_bus.get()); |
83 | 84 |
84 // |audio_processor| does nothing when the audio processing is off in | 85 // |audio_processor| does nothing when the audio processing is off in |
85 // the processor. | 86 // the processor. |
86 webrtc::AudioProcessing* ap = audio_processor->audio_processing_.get(); | 87 webrtc::AudioProcessing* ap = audio_processor->audio_processing_.get(); |
87 #if defined(OS_ANDROID) || defined(OS_IOS) | 88 #if defined(OS_ANDROID) || defined(OS_IOS) |
88 const bool is_aec_enabled = ap && ap->echo_control_mobile()->is_enabled(); | 89 const bool is_aec_enabled = ap && ap->echo_control_mobile()->is_enabled(); |
89 // AEC should be turned off for mobiles. | 90 // AEC should be turned off for mobiles. |
90 DCHECK(!ap || !ap->echo_cancellation()->is_enabled()); | 91 DCHECK(!ap || !ap->echo_cancellation()->is_enabled()); |
91 #else | 92 #else |
92 const bool is_aec_enabled = ap && ap->echo_cancellation()->is_enabled(); | 93 const bool is_aec_enabled = ap && ap->echo_cancellation()->is_enabled(); |
93 #endif | 94 #endif |
94 if (is_aec_enabled) { | 95 if (is_aec_enabled) { |
95 audio_processor->OnPlayoutData(data_bus.get(), params_.sample_rate(), | 96 audio_processor->OnPlayoutData(data_bus.get(), params.sample_rate(), |
96 10); | 97 10); |
97 } | 98 } |
98 | 99 |
99 int16* output = NULL; | 100 int16* output = NULL; |
100 int new_volume = 0; | 101 int new_volume = 0; |
101 while(audio_processor->ProcessAndConsumeData( | 102 while(audio_processor->ProcessAndConsumeData( |
102 base::TimeDelta::FromMilliseconds(10), 255, false, &new_volume, | 103 base::TimeDelta::FromMilliseconds(10), 255, false, &new_volume, |
103 &output)) { | 104 &output)) { |
104 EXPECT_TRUE(output != NULL); | 105 EXPECT_TRUE(output != NULL); |
105 EXPECT_EQ(audio_processor->OutputFormat().sample_rate(), | 106 EXPECT_EQ(audio_processor->OutputFormat().sample_rate(), |
106 expected_output_sample_rate); | 107 expected_output_sample_rate); |
107 EXPECT_EQ(audio_processor->OutputFormat().channels(), | 108 EXPECT_EQ(audio_processor->OutputFormat().channels(), |
108 expected_output_channels); | 109 expected_output_channels); |
109 EXPECT_EQ(audio_processor->OutputFormat().frames_per_buffer(), | 110 EXPECT_EQ(audio_processor->OutputFormat().frames_per_buffer(), |
110 expected_output_buffer_size); | 111 expected_output_buffer_size); |
111 } | 112 } |
112 | 113 |
113 data_ptr += params_.frames_per_buffer() * params_.channels(); | 114 data_ptr += params.frames_per_buffer() * params.channels(); |
114 } | 115 } |
115 } | 116 } |
116 | 117 |
117 void VerifyDefaultComponents(MediaStreamAudioProcessor* audio_processor) { | 118 void VerifyDefaultComponents(MediaStreamAudioProcessor* audio_processor) { |
118 webrtc::AudioProcessing* audio_processing = | 119 webrtc::AudioProcessing* audio_processing = |
119 audio_processor->audio_processing_.get(); | 120 audio_processor->audio_processing_.get(); |
120 #if defined(OS_ANDROID) | 121 #if defined(OS_ANDROID) |
121 EXPECT_TRUE(audio_processing->echo_control_mobile()->is_enabled()); | 122 EXPECT_TRUE(audio_processing->echo_control_mobile()->is_enabled()); |
122 EXPECT_TRUE(audio_processing->echo_control_mobile()->routing_mode() == | 123 EXPECT_TRUE(audio_processing->echo_control_mobile()->routing_mode() == |
123 webrtc::EchoControlMobile::kSpeakerphone); | 124 webrtc::EchoControlMobile::kSpeakerphone); |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 | 344 |
344 TEST_F(MediaStreamAudioProcessorTest, ValidateConstraints) { | 345 TEST_F(MediaStreamAudioProcessorTest, ValidateConstraints) { |
345 MockMediaConstraintFactory constraint_factory; | 346 MockMediaConstraintFactory constraint_factory; |
346 const std::string dummy_constraint = "dummy"; | 347 const std::string dummy_constraint = "dummy"; |
347 constraint_factory.AddMandatory(dummy_constraint, true); | 348 constraint_factory.AddMandatory(dummy_constraint, true); |
348 MediaAudioConstraints audio_constraints( | 349 MediaAudioConstraints audio_constraints( |
349 constraint_factory.CreateWebMediaConstraints(), 0); | 350 constraint_factory.CreateWebMediaConstraints(), 0); |
350 EXPECT_FALSE(audio_constraints.IsValid()); | 351 EXPECT_FALSE(audio_constraints.IsValid()); |
351 } | 352 } |
352 | 353 |
| 354 TEST_F(MediaStreamAudioProcessorTest, TestAllSampleRates) { |
| 355 MockMediaConstraintFactory constraint_factory; |
| 356 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( |
| 357 new WebRtcAudioDeviceImpl()); |
| 358 scoped_refptr<MediaStreamAudioProcessor> audio_processor( |
| 359 new talk_base::RefCountedObject<MediaStreamAudioProcessor>( |
| 360 constraint_factory.CreateWebMediaConstraints(), 0, |
| 361 webrtc_audio_device.get())); |
| 362 EXPECT_TRUE(audio_processor->has_audio_processing()); |
| 363 |
| 364 static const int kSupportedSampleRates[] = |
| 365 { 8000, 16000, 22050, 32000, 44100, 48000, 88200, 96000 }; |
| 366 for (size_t i = 0; i < arraysize(kSupportedSampleRates); ++i) { |
| 367 int buffer_size = (kSupportedSampleRates[i] / 100) < 128 ? |
| 368 kSupportedSampleRates[i] / 100 : 128; |
| 369 media::AudioParameters params( |
| 370 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 371 media::CHANNEL_LAYOUT_STEREO, kSupportedSampleRates[i], 16, |
| 372 buffer_size); |
| 373 audio_processor->OnCaptureFormatChanged(params); |
| 374 VerifyDefaultComponents(audio_processor); |
| 375 |
| 376 ProcessDataAndVerifyFormat(audio_processor, |
| 377 kAudioProcessingSampleRate, |
| 378 kAudioProcessingNumberOfChannel, |
| 379 kAudioProcessingSampleRate / 100); |
| 380 } |
| 381 |
| 382 // Set |audio_processor| to NULL to make sure |webrtc_audio_device| |
| 383 // outlives |audio_processor|. |
| 384 audio_processor = NULL; |
| 385 } |
| 386 |
353 } // namespace content | 387 } // namespace content |
OLD | NEW |