| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "media/audio/audio_output.h" | 6 #include "media/audio/audio_output.h" |
| 7 #include "media/audio/simple_sources.h" | 7 #include "media/audio/simple_sources.h" |
| 8 #include "testing/gmock/include/gmock/gmock.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 10 |
| 11 using ::testing::_; |
| 12 using ::testing::AnyNumber; |
| 13 using ::testing::DoAll; |
| 14 using ::testing::InSequence; |
| 15 using ::testing::Invoke; |
| 16 using ::testing::NiceMock; |
| 17 using ::testing::NotNull; |
| 18 using ::testing::Return; |
| 19 |
| 20 class MockAudioSource : public AudioOutputStream::AudioSourceCallback { |
| 21 public: |
| 22 MOCK_METHOD4(OnMoreData, size_t(AudioOutputStream* stream, void* dest, |
| 23 size_t max_size, int pending_bytes)); |
| 24 MOCK_METHOD1(OnClose, void(AudioOutputStream* stream)); |
| 25 MOCK_METHOD2(OnError, void(AudioOutputStream* stream, int code)); |
| 26 }; |
| 10 | 27 |
| 11 // Validate that the SineWaveAudioSource writes the expected values for | 28 // Validate that the SineWaveAudioSource writes the expected values for |
| 12 // the FORMAT_16BIT_MONO. | 29 // the FORMAT_16BIT_MONO. |
| 13 TEST(MacAudioTest, SineWaveAudio16MonoTest) { | 30 TEST(MacAudioTest, SineWaveAudio16MonoTest) { |
| 14 const size_t samples = 1024; | 31 const size_t samples = 1024; |
| 15 const int freq = 200; | 32 const int freq = 200; |
| 16 | 33 |
| 17 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, | 34 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, |
| 18 freq, AudioManager::kTelephoneSampleRate); | 35 freq, AudioManager::kTelephoneSampleRate); |
| 19 | 36 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, | 114 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, |
| 98 200.0, AudioManager::kAudioCDSampleRate/2); | 115 200.0, AudioManager::kAudioCDSampleRate/2); |
| 99 size_t bytes_100_ms = (AudioManager::kAudioCDSampleRate / 20) * 2; | 116 size_t bytes_100_ms = (AudioManager::kAudioCDSampleRate / 20) * 2; |
| 100 | 117 |
| 101 EXPECT_TRUE(oas->Open(bytes_100_ms)); | 118 EXPECT_TRUE(oas->Open(bytes_100_ms)); |
| 102 oas->Start(&source); | 119 oas->Start(&source); |
| 103 usleep(1500000); | 120 usleep(1500000); |
| 104 oas->Stop(); | 121 oas->Stop(); |
| 105 oas->Close(); | 122 oas->Close(); |
| 106 } | 123 } |
| 124 |
| 125 // Custom action to clear a memory buffer. |
| 126 static void ClearBuffer(AudioOutputStream* strea, void* dest, |
| 127 size_t max_size, size_t pending_bytes) { |
| 128 memset(dest, 0, max_size); |
| 129 } |
| 130 |
| 131 TEST(MacAudioTest, PCMWaveStreamPendingBytes) { |
| 132 AudioManager* audio_man = AudioManager::GetAudioManager(); |
| 133 ASSERT_TRUE(NULL != audio_man); |
| 134 if (!audio_man->HasAudioDevices()) |
| 135 return; |
| 136 AudioOutputStream* oas = |
| 137 audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LINEAR, 1, |
| 138 AudioManager::kAudioCDSampleRate, 16); |
| 139 ASSERT_TRUE(NULL != oas); |
| 140 |
| 141 NiceMock<MockAudioSource> source; |
| 142 size_t bytes_100_ms = (AudioManager::kAudioCDSampleRate / 10) * 2; |
| 143 EXPECT_TRUE(oas->Open(bytes_100_ms)); |
| 144 |
| 145 // We expect the amount of pending bytes will reaching |bytes_100_ms| |
| 146 // because the audio output stream has a double buffer scheme. |
| 147 // And then we will try to provide zero data so the amount of pending bytes |
| 148 // will go down and eventually read zero. |
| 149 InSequence s; |
| 150 EXPECT_CALL(source, OnMoreData(oas, NotNull(), bytes_100_ms, 0)) |
| 151 .WillOnce(DoAll(Invoke(&ClearBuffer), Return(bytes_100_ms))); |
| 152 EXPECT_CALL(source, OnMoreData(oas, NotNull(), bytes_100_ms, bytes_100_ms)) |
| 153 .WillOnce(DoAll(Invoke(&ClearBuffer), Return(bytes_100_ms))); |
| 154 EXPECT_CALL(source, OnMoreData(oas, NotNull(), bytes_100_ms, bytes_100_ms)) |
| 155 .WillOnce(Return(0)); |
| 156 EXPECT_CALL(source, OnMoreData(oas, NotNull(), bytes_100_ms, _)) |
| 157 .Times(AnyNumber()) |
| 158 .WillRepeatedly(Return(0)); |
| 159 |
| 160 oas->Start(&source); |
| 161 usleep(500000); |
| 162 oas->Stop(); |
| 163 oas->Close(); |
| 164 } |
| OLD | NEW |