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