| 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 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 AudioParameters params_; | 397 AudioParameters params_; |
| 398 base::TimeTicks previous_time_; | 398 base::TimeTicks previous_time_; |
| 399 base::Lock lock_; | 399 base::Lock lock_; |
| 400 scoped_ptr<media::SeekableBuffer> fifo_; | 400 scoped_ptr<media::SeekableBuffer> fifo_; |
| 401 scoped_ptr<uint8[]> buffer_; | 401 scoped_ptr<uint8[]> buffer_; |
| 402 bool started_; | 402 bool started_; |
| 403 | 403 |
| 404 DISALLOW_COPY_AND_ASSIGN(FullDuplexAudioSinkSource); | 404 DISALLOW_COPY_AND_ASSIGN(FullDuplexAudioSinkSource); |
| 405 }; | 405 }; |
| 406 | 406 |
| 407 // Implements AudioOutputStream::AudioSourceCallback and provides empty audio |
| 408 // data. |
| 409 class EmptyAudioSource : public AudioOutputStream::AudioSourceCallback { |
| 410 public: |
| 411 EmptyAudioSource(base::WaitableEvent* event, int size) |
| 412 : event_(event), remaining_size_(size) {} |
| 413 ~EmptyAudioSource() override {} |
| 414 |
| 415 // AudioOutputStream::AudioSourceCallback implementation. |
| 416 int OnMoreData(AudioBus* audio_bus, uint32 total_bytes_delay) override { |
| 417 audio_bus->Zero(); |
| 418 int max_size = |
| 419 audio_bus->frames() * audio_bus->channels() * kBytesPerSample; |
| 420 bool stop_playing = false; |
| 421 if (max_size > remaining_size_) { |
| 422 stop_playing = true; |
| 423 max_size = remaining_size_; |
| 424 } |
| 425 remaining_size_ -= max_size; |
| 426 // Set event to ensure that the test can stop. |
| 427 if (stop_playing) |
| 428 event_->Signal(); |
| 429 |
| 430 return max_size / (audio_bus->channels() * kBytesPerSample); |
| 431 } |
| 432 |
| 433 void OnError(AudioOutputStream* stream) override {} |
| 434 |
| 435 private: |
| 436 base::WaitableEvent* event_; |
| 437 int remaining_size_; |
| 438 |
| 439 DISALLOW_COPY_AND_ASSIGN(EmptyAudioSource); |
| 440 }; |
| 441 |
| 407 // Test fixture class for tests which only exercise the output path. | 442 // Test fixture class for tests which only exercise the output path. |
| 408 class AudioAndroidOutputTest : public testing::Test { | 443 class AudioAndroidOutputTest : public testing::Test { |
| 409 public: | 444 public: |
| 410 AudioAndroidOutputTest() | 445 AudioAndroidOutputTest() |
| 411 : loop_(new base::MessageLoopForUI()), | 446 : loop_(new base::MessageLoopForUI()), |
| 412 audio_manager_(AudioManager::CreateForTesting()), | 447 audio_manager_(AudioManager::CreateForTesting()), |
| 413 audio_output_stream_(NULL) { | 448 audio_output_stream_(NULL) { |
| 414 } | 449 } |
| 415 | 450 |
| 416 ~AudioAndroidOutputTest() override {} | 451 ~AudioAndroidOutputTest() override {} |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 | 891 |
| 857 base::WaitableEvent event(false, false); | 892 base::WaitableEvent event(false, false); |
| 858 FileAudioSource source(&event, file_name); | 893 FileAudioSource source(&event, file_name); |
| 859 | 894 |
| 860 OpenAndStartAudioOutputStreamOnAudioThread(&source); | 895 OpenAndStartAudioOutputStreamOnAudioThread(&source); |
| 861 DVLOG(0) << ">> Verify that the file is played out correctly..."; | 896 DVLOG(0) << ">> Verify that the file is played out correctly..."; |
| 862 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); | 897 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); |
| 863 StopAndCloseAudioOutputStreamOnAudioThread(); | 898 StopAndCloseAudioOutputStreamOnAudioThread(); |
| 864 } | 899 } |
| 865 | 900 |
| 901 // Play empty data and verify that the data are consumed properly. |
| 902 TEST_F(AudioAndroidOutputTest, RunOutputStreamWithEmptySource) { |
| 903 GetDefaultOutputStreamParametersOnAudioThread(); |
| 904 const AudioParameters params = audio_output_parameters(); |
| 905 DVLOG(1) << params; |
| 906 MakeAudioOutputStreamOnAudioThread(params); |
| 907 |
| 908 base::WaitableEvent event(false, false); |
| 909 int size = 100000; |
| 910 EmptyAudioSource source(&event, size); |
| 911 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 912 |
| 913 OpenAndStartAudioOutputStreamOnAudioThread(&source); |
| 914 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout())); |
| 915 // Verify that all the data are consumed as if they are passed through audio |
| 916 // hardware. |
| 917 base::TimeDelta time_passed = base::TimeTicks::Now() - start_time; |
| 918 int estimated_consumption_time_ms = (size * 1000) / |
| 919 (params.channels() * params.sample_rate() * kBytesPerSample); |
| 920 EXPECT_LE(estimated_consumption_time_ms, time_passed.InMilliseconds()); |
| 921 StopAndCloseAudioOutputStreamOnAudioThread(); |
| 922 } |
| 923 |
| 866 // Start input streaming and run it for ten seconds while recording to a | 924 // Start input streaming and run it for ten seconds while recording to a |
| 867 // local audio file. | 925 // local audio file. |
| 868 // NOTE: this test requires user interaction and is not designed to run as an | 926 // NOTE: this test requires user interaction and is not designed to run as an |
| 869 // automatized test on bots. | 927 // automatized test on bots. |
| 870 TEST_P(AudioAndroidInputTest, DISABLED_RunSimplexInputStreamWithFileAsSink) { | 928 TEST_P(AudioAndroidInputTest, DISABLED_RunSimplexInputStreamWithFileAsSink) { |
| 871 AudioParameters params = GetInputStreamParameters(); | 929 AudioParameters params = GetInputStreamParameters(); |
| 872 DVLOG(1) << params; | 930 DVLOG(1) << params; |
| 873 MakeAudioInputStreamOnAudioThread(params); | 931 MakeAudioInputStreamOnAudioThread(params); |
| 874 | 932 |
| 875 std::string file_name = base::StringPrintf("out_simplex_%d_%d_%d.pcm", | 933 std::string file_name = base::StringPrintf("out_simplex_%d_%d_%d.pcm", |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 964 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); | 1022 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); |
| 965 printf("\n"); | 1023 printf("\n"); |
| 966 StopAndCloseAudioOutputStreamOnAudioThread(); | 1024 StopAndCloseAudioOutputStreamOnAudioThread(); |
| 967 StopAndCloseAudioInputStreamOnAudioThread(); | 1025 StopAndCloseAudioInputStreamOnAudioThread(); |
| 968 } | 1026 } |
| 969 | 1027 |
| 970 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest, | 1028 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest, |
| 971 testing::ValuesIn(RunAudioRecordInputPathTests())); | 1029 testing::ValuesIn(RunAudioRecordInputPathTests())); |
| 972 | 1030 |
| 973 } // namespace media | 1031 } // namespace media |
| OLD | NEW |