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/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 pos_ += max_size; | 200 pos_ += max_size; |
201 } | 201 } |
202 | 202 |
203 // Set event to ensure that the test can stop when the file has ended. | 203 // Set event to ensure that the test can stop when the file has ended. |
204 if (stop_playing) | 204 if (stop_playing) |
205 event_->Signal(); | 205 event_->Signal(); |
206 | 206 |
207 return frames; | 207 return frames; |
208 } | 208 } |
209 | 209 |
210 virtual int OnMoreIOData(AudioBus* source, | |
211 AudioBus* dest, | |
212 AudioBuffersState buffers_state) OVERRIDE { | |
213 NOTREACHED(); | |
214 return 0; | |
215 } | |
216 | |
217 virtual void OnError(AudioOutputStream* stream) OVERRIDE {} | 210 virtual void OnError(AudioOutputStream* stream) OVERRIDE {} |
218 | 211 |
219 int file_size() { return file_->data_size(); } | 212 int file_size() { return file_->data_size(); } |
220 | 213 |
221 private: | 214 private: |
222 base::WaitableEvent* event_; | 215 base::WaitableEvent* event_; |
223 int pos_; | 216 int pos_; |
224 scoped_refptr<DecoderBuffer> file_; | 217 scoped_refptr<DecoderBuffer> file_; |
225 | 218 |
226 DISALLOW_COPY_AND_ASSIGN(FileAudioSource); | 219 DISALLOW_COPY_AND_ASSIGN(FileAudioSource); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 dest->Zero(); | 365 dest->Zero(); |
373 } else { | 366 } else { |
374 fifo_->Read(buffer_.get(), size_in_bytes); | 367 fifo_->Read(buffer_.get(), size_in_bytes); |
375 dest->FromInterleaved( | 368 dest->FromInterleaved( |
376 buffer_.get(), dest->frames(), params_.bits_per_sample() / 8); | 369 buffer_.get(), dest->frames(), params_.bits_per_sample() / 8); |
377 } | 370 } |
378 | 371 |
379 return dest->frames(); | 372 return dest->frames(); |
380 } | 373 } |
381 | 374 |
382 virtual int OnMoreIOData(AudioBus* source, | |
383 AudioBus* dest, | |
384 AudioBuffersState buffers_state) OVERRIDE { | |
385 NOTREACHED(); | |
386 return 0; | |
387 } | |
388 | |
389 virtual void OnError(AudioOutputStream* stream) OVERRIDE {} | 375 virtual void OnError(AudioOutputStream* stream) OVERRIDE {} |
390 | 376 |
391 private: | 377 private: |
392 // Converts from bytes to milliseconds given number of bytes and existing | 378 // Converts from bytes to milliseconds given number of bytes and existing |
393 // audio parameters. | 379 // audio parameters. |
394 double BytesToMilliseconds(int bytes) const { | 380 double BytesToMilliseconds(int bytes) const { |
395 const int frames = bytes / params_.GetBytesPerFrame(); | 381 const int frames = bytes / params_.GetBytesPerFrame(); |
396 return (base::TimeDelta::FromMicroseconds( | 382 return (base::TimeDelta::FromMicroseconds( |
397 frames * base::Time::kMicrosecondsPerSecond / | 383 frames * base::Time::kMicrosecondsPerSecond / |
398 static_cast<double>(params_.sample_rate()))).InMillisecondsF(); | 384 static_cast<double>(params_.sample_rate()))).InMillisecondsF(); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 | 483 |
498 int count = 0; | 484 int count = 0; |
499 MockAudioSourceCallback source; | 485 MockAudioSourceCallback source; |
500 | 486 |
501 EXPECT_CALL(source, OnMoreData(NotNull(), _)) | 487 EXPECT_CALL(source, OnMoreData(NotNull(), _)) |
502 .Times(AtLeast(num_callbacks)) | 488 .Times(AtLeast(num_callbacks)) |
503 .WillRepeatedly( | 489 .WillRepeatedly( |
504 DoAll(CheckCountAndPostQuitTask(&count, num_callbacks, loop()), | 490 DoAll(CheckCountAndPostQuitTask(&count, num_callbacks, loop()), |
505 Invoke(RealOnMoreData))); | 491 Invoke(RealOnMoreData))); |
506 EXPECT_CALL(source, OnError(audio_output_stream_)).Times(0); | 492 EXPECT_CALL(source, OnError(audio_output_stream_)).Times(0); |
507 EXPECT_CALL(source, OnMoreIOData(_, _, _)).Times(0); | |
508 | 493 |
509 OpenAndStartAudioOutputStreamOnAudioThread(&source); | 494 OpenAndStartAudioOutputStreamOnAudioThread(&source); |
510 | 495 |
511 start_time_ = base::TimeTicks::Now(); | 496 start_time_ = base::TimeTicks::Now(); |
512 loop()->Run(); | 497 loop()->Run(); |
513 end_time_ = base::TimeTicks::Now(); | 498 end_time_ = base::TimeTicks::Now(); |
514 | 499 |
515 StopAndCloseAudioOutputStreamOnAudioThread(); | 500 StopAndCloseAudioOutputStreamOnAudioThread(); |
516 | 501 |
517 double average_time_between_callbacks_ms = | 502 double average_time_between_callbacks_ms = |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
918 in_params.frames_per_buffer(), | 903 in_params.frames_per_buffer(), |
919 in_params.channels()); | 904 in_params.channels()); |
920 | 905 |
921 base::WaitableEvent event(false, false); | 906 base::WaitableEvent event(false, false); |
922 FileAudioSink sink(&event, in_params, file_name); | 907 FileAudioSink sink(&event, in_params, file_name); |
923 MockAudioSourceCallback source; | 908 MockAudioSourceCallback source; |
924 | 909 |
925 EXPECT_CALL(source, OnMoreData(NotNull(), _)) | 910 EXPECT_CALL(source, OnMoreData(NotNull(), _)) |
926 .WillRepeatedly(Invoke(RealOnMoreData)); | 911 .WillRepeatedly(Invoke(RealOnMoreData)); |
927 EXPECT_CALL(source, OnError(audio_output_stream_)).Times(0); | 912 EXPECT_CALL(source, OnError(audio_output_stream_)).Times(0); |
928 EXPECT_CALL(source, OnMoreIOData(_, _, _)).Times(0); | |
929 | 913 |
930 OpenAndStartAudioInputStreamOnAudioThread(&sink); | 914 OpenAndStartAudioInputStreamOnAudioThread(&sink); |
931 OpenAndStartAudioOutputStreamOnAudioThread(&source); | 915 OpenAndStartAudioOutputStreamOnAudioThread(&source); |
932 VLOG(0) << ">> Speak into the microphone to record audio"; | 916 VLOG(0) << ">> Speak into the microphone to record audio"; |
933 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); | 917 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); |
934 StopAndCloseAudioOutputStreamOnAudioThread(); | 918 StopAndCloseAudioOutputStreamOnAudioThread(); |
935 StopAndCloseAudioInputStreamOnAudioThread(); | 919 StopAndCloseAudioInputStreamOnAudioThread(); |
936 } | 920 } |
937 | 921 |
938 // Start audio in both directions while feeding captured data into a FIFO so | 922 // Start audio in both directions while feeding captured data into a FIFO so |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); | 963 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); |
980 printf("\n"); | 964 printf("\n"); |
981 StopAndCloseAudioOutputStreamOnAudioThread(); | 965 StopAndCloseAudioOutputStreamOnAudioThread(); |
982 StopAndCloseAudioInputStreamOnAudioThread(); | 966 StopAndCloseAudioInputStreamOnAudioThread(); |
983 } | 967 } |
984 | 968 |
985 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest, | 969 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest, |
986 testing::ValuesIn(RunAudioRecordInputPathTests())); | 970 testing::ValuesIn(RunAudioRecordInputPathTests())); |
987 | 971 |
988 } // namespace media | 972 } // namespace media |
OLD | NEW |