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/android/build_info.h" | 5 #include "base/android/build_info.h" |
6 #include "base/basictypes.h" | 6 #include "base/basictypes.h" |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 EXPECT_FALSE(it->unique_id.empty()); | 114 EXPECT_FALSE(it->unique_id.empty()); |
115 DVLOG(2) << "Device ID(" << it->unique_id | 115 DVLOG(2) << "Device ID(" << it->unique_id |
116 << "), label: " << it->device_name; | 116 << "), label: " << it->device_name; |
117 EXPECT_NE(AudioManager::GetDefaultDeviceName(), it->device_name); | 117 EXPECT_NE(AudioManager::GetDefaultDeviceName(), it->device_name); |
118 EXPECT_NE(std::string(AudioManagerBase::kDefaultDeviceId), it->unique_id); | 118 EXPECT_NE(std::string(AudioManagerBase::kDefaultDeviceId), it->unique_id); |
119 ++it; | 119 ++it; |
120 } | 120 } |
121 } | 121 } |
122 | 122 |
123 // We clear the data bus to ensure that the test does not cause noise. | 123 // We clear the data bus to ensure that the test does not cause noise. |
124 int RealOnMoreData(AudioBus* dest, | 124 int RealOnMoreData(AudioBus* dest, uint32 total_bytes_delay) { |
125 uint32_t total_bytes_delay, | |
126 uint32_t frames_skipped) { | |
127 dest->Zero(); | 125 dest->Zero(); |
128 return dest->frames(); | 126 return dest->frames(); |
129 } | 127 } |
130 | 128 |
131 } // namespace | 129 } // namespace |
132 | 130 |
133 std::ostream& operator<<(std::ostream& os, const AudioParameters& params) { | 131 std::ostream& operator<<(std::ostream& os, const AudioParameters& params) { |
134 using namespace std; | 132 using namespace std; |
135 os << endl << "format: " << FormatToString(params.format()) << endl | 133 os << endl << "format: " << FormatToString(params.format()) << endl |
136 << "channel layout: " << LayoutToString(params.channel_layout()) << endl | 134 << "channel layout: " << LayoutToString(params.channel_layout()) << endl |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 base::FilePath file_path = GetTestDataFilePath(name); | 170 base::FilePath file_path = GetTestDataFilePath(name); |
173 DVLOG(0) << "Reading from file: " << file_path.value().c_str(); | 171 DVLOG(0) << "Reading from file: " << file_path.value().c_str(); |
174 } | 172 } |
175 | 173 |
176 ~FileAudioSource() override {} | 174 ~FileAudioSource() override {} |
177 | 175 |
178 // AudioOutputStream::AudioSourceCallback implementation. | 176 // AudioOutputStream::AudioSourceCallback implementation. |
179 | 177 |
180 // Use samples read from a data file and fill up the audio buffer | 178 // Use samples read from a data file and fill up the audio buffer |
181 // provided to us in the callback. | 179 // provided to us in the callback. |
182 int OnMoreData(AudioBus* audio_bus, | 180 int OnMoreData(AudioBus* audio_bus, uint32 total_bytes_delay) override { |
183 uint32_t total_bytes_delay, | |
184 uint32_t frames_skipped) override { | |
185 bool stop_playing = false; | 181 bool stop_playing = false; |
186 int max_size = | 182 int max_size = |
187 audio_bus->frames() * audio_bus->channels() * kBytesPerSample; | 183 audio_bus->frames() * audio_bus->channels() * kBytesPerSample; |
188 | 184 |
189 // Adjust data size and prepare for end signal if file has ended. | 185 // Adjust data size and prepare for end signal if file has ended. |
190 if (pos_ + max_size > file_size()) { | 186 if (pos_ + max_size > file_size()) { |
191 stop_playing = true; | 187 stop_playing = true; |
192 max_size = file_size() - pos_; | 188 max_size = file_size() - pos_; |
193 } | 189 } |
194 | 190 |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 // was exceeded. Flush the FIFO when extended just in case. | 345 // was exceeded. Flush the FIFO when extended just in case. |
350 if (!fifo_->Append((const uint8*)interleaved.get(), size)) { | 346 if (!fifo_->Append((const uint8*)interleaved.get(), size)) { |
351 fifo_->set_forward_capacity(2 * fifo_->forward_capacity()); | 347 fifo_->set_forward_capacity(2 * fifo_->forward_capacity()); |
352 fifo_->Clear(); | 348 fifo_->Clear(); |
353 } | 349 } |
354 } | 350 } |
355 | 351 |
356 void OnError(AudioInputStream* stream) override {} | 352 void OnError(AudioInputStream* stream) override {} |
357 | 353 |
358 // AudioOutputStream::AudioSourceCallback implementation | 354 // AudioOutputStream::AudioSourceCallback implementation |
359 int OnMoreData(AudioBus* dest, | 355 int OnMoreData(AudioBus* dest, uint32 total_bytes_delay) override { |
360 uint32_t total_bytes_delay, | |
361 uint32_t frames_skipped) override { | |
362 const int size_in_bytes = | 356 const int size_in_bytes = |
363 (params_.bits_per_sample() / 8) * dest->frames() * dest->channels(); | 357 (params_.bits_per_sample() / 8) * dest->frames() * dest->channels(); |
364 EXPECT_EQ(size_in_bytes, params_.GetBytesPerBuffer()); | 358 EXPECT_EQ(size_in_bytes, params_.GetBytesPerBuffer()); |
365 | 359 |
366 base::AutoLock lock(lock_); | 360 base::AutoLock lock(lock_); |
367 | 361 |
368 // We add an initial delay of ~1 second before loopback starts to ensure | 362 // We add an initial delay of ~1 second before loopback starts to ensure |
369 // a stable callback sequences and to avoid initial bursts which might add | 363 // a stable callback sequences and to avoid initial bursts which might add |
370 // to the extra FIFO delay. | 364 // to the extra FIFO delay. |
371 if (!started_) { | 365 if (!started_) { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 void StartOutputStreamCallbacks(const AudioParameters& params) { | 484 void StartOutputStreamCallbacks(const AudioParameters& params) { |
491 double expected_time_between_callbacks_ms = | 485 double expected_time_between_callbacks_ms = |
492 ExpectedTimeBetweenCallbacks(params); | 486 ExpectedTimeBetweenCallbacks(params); |
493 const int num_callbacks = | 487 const int num_callbacks = |
494 (kCallbackTestTimeMs / expected_time_between_callbacks_ms); | 488 (kCallbackTestTimeMs / expected_time_between_callbacks_ms); |
495 MakeAudioOutputStreamOnAudioThread(params); | 489 MakeAudioOutputStreamOnAudioThread(params); |
496 | 490 |
497 int count = 0; | 491 int count = 0; |
498 MockAudioSourceCallback source; | 492 MockAudioSourceCallback source; |
499 | 493 |
500 EXPECT_CALL(source, OnMoreData(NotNull(), _, 0)) | 494 EXPECT_CALL(source, OnMoreData(NotNull(), _)) |
501 .Times(AtLeast(num_callbacks)) | 495 .Times(AtLeast(num_callbacks)) |
502 .WillRepeatedly( | 496 .WillRepeatedly( |
503 DoAll(CheckCountAndPostQuitTask(&count, num_callbacks, loop()), | 497 DoAll(CheckCountAndPostQuitTask(&count, num_callbacks, loop()), |
504 Invoke(RealOnMoreData))); | 498 Invoke(RealOnMoreData))); |
505 EXPECT_CALL(source, OnError(audio_output_stream_)).Times(0); | 499 EXPECT_CALL(source, OnError(audio_output_stream_)).Times(0); |
506 | 500 |
507 OpenAndStartAudioOutputStreamOnAudioThread(&source); | 501 OpenAndStartAudioOutputStreamOnAudioThread(&source); |
508 | 502 |
509 start_time_ = base::TimeTicks::Now(); | 503 start_time_ = base::TimeTicks::Now(); |
510 loop()->Run(); | 504 loop()->Run(); |
511 end_time_ = base::TimeTicks::Now(); | 505 end_time_ = base::TimeTicks::Now(); |
512 | 506 |
513 StopAndCloseAudioOutputStreamOnAudioThread(); | 507 StopAndCloseAudioOutputStreamOnAudioThread(); |
514 | 508 |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 | 888 |
895 std::string file_name = base::StringPrintf("out_duplex_%d_%d_%d.pcm", | 889 std::string file_name = base::StringPrintf("out_duplex_%d_%d_%d.pcm", |
896 in_params.sample_rate(), | 890 in_params.sample_rate(), |
897 in_params.frames_per_buffer(), | 891 in_params.frames_per_buffer(), |
898 in_params.channels()); | 892 in_params.channels()); |
899 | 893 |
900 base::WaitableEvent event(false, false); | 894 base::WaitableEvent event(false, false); |
901 FileAudioSink sink(&event, in_params, file_name); | 895 FileAudioSink sink(&event, in_params, file_name); |
902 MockAudioSourceCallback source; | 896 MockAudioSourceCallback source; |
903 | 897 |
904 EXPECT_CALL(source, OnMoreData(NotNull(), _, 0)) | 898 EXPECT_CALL(source, OnMoreData(NotNull(), _)) |
905 .WillRepeatedly(Invoke(RealOnMoreData)); | 899 .WillRepeatedly(Invoke(RealOnMoreData)); |
906 EXPECT_CALL(source, OnError(audio_output_stream_)).Times(0); | 900 EXPECT_CALL(source, OnError(audio_output_stream_)).Times(0); |
907 | 901 |
908 OpenAndStartAudioInputStreamOnAudioThread(&sink); | 902 OpenAndStartAudioInputStreamOnAudioThread(&sink); |
909 OpenAndStartAudioOutputStreamOnAudioThread(&source); | 903 OpenAndStartAudioOutputStreamOnAudioThread(&source); |
910 DVLOG(0) << ">> Speak into the microphone to record audio"; | 904 DVLOG(0) << ">> Speak into the microphone to record audio"; |
911 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); | 905 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); |
912 StopAndCloseAudioOutputStreamOnAudioThread(); | 906 StopAndCloseAudioOutputStreamOnAudioThread(); |
913 StopAndCloseAudioInputStreamOnAudioThread(); | 907 StopAndCloseAudioInputStreamOnAudioThread(); |
914 } | 908 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
951 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); | 945 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); |
952 printf("\n"); | 946 printf("\n"); |
953 StopAndCloseAudioOutputStreamOnAudioThread(); | 947 StopAndCloseAudioOutputStreamOnAudioThread(); |
954 StopAndCloseAudioInputStreamOnAudioThread(); | 948 StopAndCloseAudioInputStreamOnAudioThread(); |
955 } | 949 } |
956 | 950 |
957 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest, | 951 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest, |
958 testing::ValuesIn(RunAudioRecordInputPathTests())); | 952 testing::ValuesIn(RunAudioRecordInputPathTests())); |
959 | 953 |
960 } // namespace media | 954 } // namespace media |
OLD | NEW |