| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/android/build_info.h" | 9 #include "base/android/build_info.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 DVLOG(2) << "Device ID(" << it->unique_id | 119 DVLOG(2) << "Device ID(" << it->unique_id |
| 120 << "), label: " << it->device_name; | 120 << "), label: " << it->device_name; |
| 121 EXPECT_NE(AudioDeviceDescription::GetDefaultDeviceName(), it->device_name); | 121 EXPECT_NE(AudioDeviceDescription::GetDefaultDeviceName(), it->device_name); |
| 122 EXPECT_NE(std::string(AudioDeviceDescription::kDefaultDeviceId), | 122 EXPECT_NE(std::string(AudioDeviceDescription::kDefaultDeviceId), |
| 123 it->unique_id); | 123 it->unique_id); |
| 124 ++it; | 124 ++it; |
| 125 } | 125 } |
| 126 } | 126 } |
| 127 | 127 |
| 128 // We clear the data bus to ensure that the test does not cause noise. | 128 // We clear the data bus to ensure that the test does not cause noise. |
| 129 int RealOnMoreData(AudioBus* dest, | 129 int RealOnMoreData(base::TimeDelta /* delay */, |
| 130 uint32_t total_bytes_delay, | 130 base::TimeTicks /* delay_timestamp */, |
| 131 uint32_t frames_skipped) { | 131 int /* prior_frames_skipped */, |
| 132 AudioBus* dest) { |
| 132 dest->Zero(); | 133 dest->Zero(); |
| 133 return dest->frames(); | 134 return dest->frames(); |
| 134 } | 135 } |
| 135 | 136 |
| 136 } // namespace | 137 } // namespace |
| 137 | 138 |
| 138 std::ostream& operator<<(std::ostream& os, const AudioParameters& params) { | 139 std::ostream& operator<<(std::ostream& os, const AudioParameters& params) { |
| 139 using namespace std; | 140 using namespace std; |
| 140 os << endl << "format: " << FormatToString(params.format()) << endl | 141 os << endl << "format: " << FormatToString(params.format()) << endl |
| 141 << "channel layout: " << LayoutToString(params.channel_layout()) << endl | 142 << "channel layout: " << LayoutToString(params.channel_layout()) << endl |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 base::FilePath file_path = GetTestDataFilePath(name); | 178 base::FilePath file_path = GetTestDataFilePath(name); |
| 178 DVLOG(0) << "Reading from file: " << file_path.value().c_str(); | 179 DVLOG(0) << "Reading from file: " << file_path.value().c_str(); |
| 179 } | 180 } |
| 180 | 181 |
| 181 ~FileAudioSource() override {} | 182 ~FileAudioSource() override {} |
| 182 | 183 |
| 183 // AudioOutputStream::AudioSourceCallback implementation. | 184 // AudioOutputStream::AudioSourceCallback implementation. |
| 184 | 185 |
| 185 // Use samples read from a data file and fill up the audio buffer | 186 // Use samples read from a data file and fill up the audio buffer |
| 186 // provided to us in the callback. | 187 // provided to us in the callback. |
| 187 int OnMoreData(AudioBus* audio_bus, | 188 int OnMoreData(base::TimeDelta /* delay */, |
| 188 uint32_t total_bytes_delay, | 189 base::TimeTicks /* delay_timestamp */, |
| 189 uint32_t frames_skipped) override { | 190 int /* prior_frames_skipped */, |
| 191 AudioBus* dest) override { |
| 190 bool stop_playing = false; | 192 bool stop_playing = false; |
| 191 int max_size = | 193 int max_size = dest->frames() * dest->channels() * kBytesPerSample; |
| 192 audio_bus->frames() * audio_bus->channels() * kBytesPerSample; | |
| 193 | 194 |
| 194 // Adjust data size and prepare for end signal if file has ended. | 195 // Adjust data size and prepare for end signal if file has ended. |
| 195 if (pos_ + max_size > file_size()) { | 196 if (pos_ + max_size > file_size()) { |
| 196 stop_playing = true; | 197 stop_playing = true; |
| 197 max_size = file_size() - pos_; | 198 max_size = file_size() - pos_; |
| 198 } | 199 } |
| 199 | 200 |
| 200 // File data is stored as interleaved 16-bit values. Copy data samples from | 201 // File data is stored as interleaved 16-bit values. Copy data samples from |
| 201 // the file and deinterleave to match the audio bus format. | 202 // the file and deinterleave to match the audio bus format. |
| 202 // FromInterleaved() will zero out any unfilled frames when there is not | 203 // FromInterleaved() will zero out any unfilled frames when there is not |
| 203 // sufficient data remaining in the file to fill up the complete frame. | 204 // sufficient data remaining in the file to fill up the complete frame. |
| 204 int frames = max_size / (audio_bus->channels() * kBytesPerSample); | 205 int frames = max_size / (dest->channels() * kBytesPerSample); |
| 205 if (max_size) { | 206 if (max_size) { |
| 206 audio_bus->FromInterleaved(file_->data() + pos_, frames, kBytesPerSample); | 207 dest->FromInterleaved(file_->data() + pos_, frames, kBytesPerSample); |
| 207 pos_ += max_size; | 208 pos_ += max_size; |
| 208 } | 209 } |
| 209 | 210 |
| 210 // Set event to ensure that the test can stop when the file has ended. | 211 // Set event to ensure that the test can stop when the file has ended. |
| 211 if (stop_playing) | 212 if (stop_playing) |
| 212 event_->Signal(); | 213 event_->Signal(); |
| 213 | 214 |
| 214 return frames; | 215 return frames; |
| 215 } | 216 } |
| 216 | 217 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 // was exceeded. Flush the FIFO when extended just in case. | 355 // was exceeded. Flush the FIFO when extended just in case. |
| 355 if (!fifo_->Append((const uint8_t*)interleaved.get(), size)) { | 356 if (!fifo_->Append((const uint8_t*)interleaved.get(), size)) { |
| 356 fifo_->set_forward_capacity(2 * fifo_->forward_capacity()); | 357 fifo_->set_forward_capacity(2 * fifo_->forward_capacity()); |
| 357 fifo_->Clear(); | 358 fifo_->Clear(); |
| 358 } | 359 } |
| 359 } | 360 } |
| 360 | 361 |
| 361 void OnError(AudioInputStream* stream) override {} | 362 void OnError(AudioInputStream* stream) override {} |
| 362 | 363 |
| 363 // AudioOutputStream::AudioSourceCallback implementation | 364 // AudioOutputStream::AudioSourceCallback implementation |
| 364 int OnMoreData(AudioBus* dest, | 365 int OnMoreData(base::TimeDelta /* delay */, |
| 365 uint32_t total_bytes_delay, | 366 base::TimeTicks /* delay_timestamp */, |
| 366 uint32_t frames_skipped) override { | 367 int /* prior_frames_skipped */, |
| 368 AudioBus* dest) override { |
| 367 const int size_in_bytes = | 369 const int size_in_bytes = |
| 368 (params_.bits_per_sample() / 8) * dest->frames() * dest->channels(); | 370 (params_.bits_per_sample() / 8) * dest->frames() * dest->channels(); |
| 369 EXPECT_EQ(size_in_bytes, params_.GetBytesPerBuffer()); | 371 EXPECT_EQ(size_in_bytes, params_.GetBytesPerBuffer()); |
| 370 | 372 |
| 371 base::AutoLock lock(lock_); | 373 base::AutoLock lock(lock_); |
| 372 | 374 |
| 373 // We add an initial delay of ~1 second before loopback starts to ensure | 375 // We add an initial delay of ~1 second before loopback starts to ensure |
| 374 // a stable callback sequences and to avoid initial bursts which might add | 376 // a stable callback sequences and to avoid initial bursts which might add |
| 375 // to the extra FIFO delay. | 377 // to the extra FIFO delay. |
| 376 if (!started_) { | 378 if (!started_) { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 double expected_time_between_callbacks_ms = | 504 double expected_time_between_callbacks_ms = |
| 503 ExpectedTimeBetweenCallbacks(params); | 505 ExpectedTimeBetweenCallbacks(params); |
| 504 const int num_callbacks = | 506 const int num_callbacks = |
| 505 (kCallbackTestTimeMs / expected_time_between_callbacks_ms); | 507 (kCallbackTestTimeMs / expected_time_between_callbacks_ms); |
| 506 MakeAudioOutputStreamOnAudioThread(params); | 508 MakeAudioOutputStreamOnAudioThread(params); |
| 507 | 509 |
| 508 int count = 0; | 510 int count = 0; |
| 509 MockAudioSourceCallback source; | 511 MockAudioSourceCallback source; |
| 510 | 512 |
| 511 base::RunLoop run_loop; | 513 base::RunLoop run_loop; |
| 512 EXPECT_CALL(source, OnMoreData(NotNull(), _, 0)) | 514 EXPECT_CALL(source, OnMoreData(_, _, 0, NotNull())) |
| 513 .Times(AtLeast(num_callbacks)) | 515 .Times(AtLeast(num_callbacks)) |
| 514 .WillRepeatedly( | 516 .WillRepeatedly( |
| 515 DoAll(CheckCountAndPostQuitTask(&count, num_callbacks, | 517 DoAll(CheckCountAndPostQuitTask(&count, num_callbacks, |
| 516 base::ThreadTaskRunnerHandle::Get(), | 518 base::ThreadTaskRunnerHandle::Get(), |
| 517 run_loop.QuitWhenIdleClosure()), | 519 run_loop.QuitWhenIdleClosure()), |
| 518 Invoke(RealOnMoreData))); | 520 Invoke(RealOnMoreData))); |
| 519 EXPECT_CALL(source, OnError(audio_output_stream_)).Times(0); | 521 EXPECT_CALL(source, OnError(audio_output_stream_)).Times(0); |
| 520 | 522 |
| 521 OpenAndStartAudioOutputStreamOnAudioThread(&source); | 523 OpenAndStartAudioOutputStreamOnAudioThread(&source); |
| 522 | 524 |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 std::string file_name = base::StringPrintf("out_duplex_%d_%d_%d.pcm", | 916 std::string file_name = base::StringPrintf("out_duplex_%d_%d_%d.pcm", |
| 915 in_params.sample_rate(), | 917 in_params.sample_rate(), |
| 916 in_params.frames_per_buffer(), | 918 in_params.frames_per_buffer(), |
| 917 in_params.channels()); | 919 in_params.channels()); |
| 918 | 920 |
| 919 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 921 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 920 base::WaitableEvent::InitialState::NOT_SIGNALED); | 922 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 921 FileAudioSink sink(&event, in_params, file_name); | 923 FileAudioSink sink(&event, in_params, file_name); |
| 922 MockAudioSourceCallback source; | 924 MockAudioSourceCallback source; |
| 923 | 925 |
| 924 EXPECT_CALL(source, OnMoreData(NotNull(), _, 0)) | 926 EXPECT_CALL(source, OnMoreData(_, _, 0, NotNull())) |
| 925 .WillRepeatedly(Invoke(RealOnMoreData)); | 927 .WillRepeatedly(Invoke(RealOnMoreData)); |
| 926 EXPECT_CALL(source, OnError(audio_output_stream_)).Times(0); | 928 EXPECT_CALL(source, OnError(audio_output_stream_)).Times(0); |
| 927 | 929 |
| 928 OpenAndStartAudioInputStreamOnAudioThread(&sink); | 930 OpenAndStartAudioInputStreamOnAudioThread(&sink); |
| 929 OpenAndStartAudioOutputStreamOnAudioThread(&source); | 931 OpenAndStartAudioOutputStreamOnAudioThread(&source); |
| 930 DVLOG(0) << ">> Speak into the microphone to record audio"; | 932 DVLOG(0) << ">> Speak into the microphone to record audio"; |
| 931 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); | 933 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); |
| 932 StopAndCloseAudioOutputStreamOnAudioThread(); | 934 StopAndCloseAudioOutputStreamOnAudioThread(); |
| 933 StopAndCloseAudioInputStreamOnAudioThread(); | 935 StopAndCloseAudioInputStreamOnAudioThread(); |
| 934 } | 936 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); | 973 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); |
| 972 printf("\n"); | 974 printf("\n"); |
| 973 StopAndCloseAudioOutputStreamOnAudioThread(); | 975 StopAndCloseAudioOutputStreamOnAudioThread(); |
| 974 StopAndCloseAudioInputStreamOnAudioThread(); | 976 StopAndCloseAudioInputStreamOnAudioThread(); |
| 975 } | 977 } |
| 976 | 978 |
| 977 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest, | 979 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest, |
| 978 testing::ValuesIn(RunAudioRecordInputPathTests())); | 980 testing::ValuesIn(RunAudioRecordInputPathTests())); |
| 979 | 981 |
| 980 } // namespace media | 982 } // namespace media |
| OLD | NEW |