| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/process_util.h" | 9 #include "base/process_util.h" |
| 10 #include "base/shared_memory.h" | 10 #include "base/shared_memory.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 ACTION_P(QuitLoop, loop) { | 89 ACTION_P(QuitLoop, loop) { |
| 90 loop->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 90 loop->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 91 } | 91 } |
| 92 | 92 |
| 93 } // namespace. | 93 } // namespace. |
| 94 | 94 |
| 95 class AudioOutputDeviceTest | 95 class AudioOutputDeviceTest |
| 96 : public testing::Test, | 96 : public testing::Test, |
| 97 public testing::WithParamInterface<bool> { | 97 public testing::WithParamInterface<bool> { |
| 98 public: | 98 public: |
| 99 AudioOutputDeviceTest() | 99 AudioOutputDeviceTest(); |
| 100 : default_audio_parameters_(AudioParameters::AUDIO_PCM_LINEAR, | 100 ~AudioOutputDeviceTest(); |
| 101 CHANNEL_LAYOUT_STEREO, | |
| 102 48000, 16, 1024), | |
| 103 audio_device_(new AudioOutputDevice( | |
| 104 &audio_output_ipc_, io_loop_.message_loop_proxy())), | |
| 105 synchronized_io_(GetParam()), | |
| 106 input_channels_(synchronized_io_ ? 2 : 0) { | |
| 107 } | |
| 108 | 101 |
| 109 ~AudioOutputDeviceTest() {} | |
| 110 | |
| 111 void Initialize(); | |
| 112 void StartAudioDevice(); | 102 void StartAudioDevice(); |
| 113 void CreateStream(); | 103 void CreateStream(); |
| 114 void ExpectRenderCallback(); | 104 void ExpectRenderCallback(); |
| 115 void WaitUntilRenderCallback(); | 105 void WaitUntilRenderCallback(); |
| 116 void StopAudioDevice(); | 106 void StopAudioDevice(); |
| 117 | 107 |
| 118 protected: | 108 protected: |
| 119 // Used to clean up TLS pointers that the test(s) will initialize. | 109 // Used to clean up TLS pointers that the test(s) will initialize. |
| 120 // Must remain the first member of this class. | 110 // Must remain the first member of this class. |
| 121 base::ShadowingAtExitManager at_exit_manager_; | 111 base::ShadowingAtExitManager at_exit_manager_; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 150 | 140 |
| 151 int io_buffer_size = output_memory_size + input_memory_size; | 141 int io_buffer_size = output_memory_size + input_memory_size; |
| 152 | 142 |
| 153 // This is where it gets a bit hacky. The shared memory contract between | 143 // This is where it gets a bit hacky. The shared memory contract between |
| 154 // AudioOutputDevice and its browser side counter part includes a bit more | 144 // AudioOutputDevice and its browser side counter part includes a bit more |
| 155 // than just the audio data, so we must call TotalSharedMemorySizeInBytes() | 145 // than just the audio data, so we must call TotalSharedMemorySizeInBytes() |
| 156 // to get the actual size needed to fit the audio data plus the extra data. | 146 // to get the actual size needed to fit the audio data plus the extra data. |
| 157 return TotalSharedMemorySizeInBytes(io_buffer_size); | 147 return TotalSharedMemorySizeInBytes(io_buffer_size); |
| 158 } | 148 } |
| 159 | 149 |
| 160 void AudioOutputDeviceTest::Initialize() { | 150 AudioOutputDeviceTest::AudioOutputDeviceTest() |
| 151 : default_audio_parameters_(AudioParameters::AUDIO_PCM_LINEAR, |
| 152 CHANNEL_LAYOUT_STEREO, |
| 153 48000, 16, 1024), |
| 154 synchronized_io_(GetParam()), |
| 155 input_channels_(synchronized_io_ ? 2 : 0) { |
| 156 EXPECT_CALL(audio_output_ipc_, AddDelegate(_)) |
| 157 .WillOnce(Return(kStreamId)); |
| 158 |
| 159 audio_device_ = new AudioOutputDevice( |
| 160 &audio_output_ipc_, io_loop_.message_loop_proxy()); |
| 161 |
| 161 if (synchronized_io_) { | 162 if (synchronized_io_) { |
| 162 audio_device_->InitializeIO(default_audio_parameters_, | 163 audio_device_->InitializeIO(default_audio_parameters_, |
| 163 input_channels_, | 164 input_channels_, |
| 164 &callback_); | 165 &callback_); |
| 165 } else { | 166 } else { |
| 166 audio_device_->Initialize(default_audio_parameters_, | 167 audio_device_->Initialize(default_audio_parameters_, |
| 167 &callback_); | 168 &callback_); |
| 168 } | 169 } |
| 169 io_loop_.RunUntilIdle(); | 170 io_loop_.RunUntilIdle(); |
| 170 } | 171 } |
| 171 | 172 |
| 173 AudioOutputDeviceTest::~AudioOutputDeviceTest() { |
| 174 EXPECT_CALL(audio_output_ipc_, RemoveDelegate(kStreamId)); |
| 175 |
| 176 audio_device_ = NULL; |
| 177 } |
| 178 |
| 172 void AudioOutputDeviceTest::StartAudioDevice() { | 179 void AudioOutputDeviceTest::StartAudioDevice() { |
| 173 audio_device_->Start(); | 180 audio_device_->Start(); |
| 174 | 181 |
| 175 EXPECT_CALL(audio_output_ipc_, AddDelegate(audio_device_.get())) | |
| 176 .WillOnce(Return(kStreamId)); | |
| 177 EXPECT_CALL(audio_output_ipc_, CreateStream(kStreamId, _, _)); | 182 EXPECT_CALL(audio_output_ipc_, CreateStream(kStreamId, _, _)); |
| 178 | 183 |
| 179 io_loop_.RunUntilIdle(); | 184 io_loop_.RunUntilIdle(); |
| 180 } | 185 } |
| 181 | 186 |
| 182 void AudioOutputDeviceTest::CreateStream() { | 187 void AudioOutputDeviceTest::CreateStream() { |
| 183 const int kMemorySize = CalculateMemorySize(); | 188 const int kMemorySize = CalculateMemorySize(); |
| 184 | 189 |
| 185 ASSERT_TRUE(shared_memory_.CreateAndMapAnonymous(kMemorySize)); | 190 ASSERT_TRUE(shared_memory_.CreateAndMapAnonymous(kMemorySize)); |
| 186 memset(shared_memory_.memory(), 0xff, kMemorySize); | 191 memset(shared_memory_.memory(), 0xff, kMemorySize); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 // Don't hang the test if we never get the Render() callback. | 243 // Don't hang the test if we never get the Render() callback. |
| 239 io_loop_.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), | 244 io_loop_.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), |
| 240 TestTimeouts::action_timeout()); | 245 TestTimeouts::action_timeout()); |
| 241 io_loop_.Run(); | 246 io_loop_.Run(); |
| 242 } | 247 } |
| 243 | 248 |
| 244 void AudioOutputDeviceTest::StopAudioDevice() { | 249 void AudioOutputDeviceTest::StopAudioDevice() { |
| 245 audio_device_->Stop(); | 250 audio_device_->Stop(); |
| 246 | 251 |
| 247 EXPECT_CALL(audio_output_ipc_, CloseStream(kStreamId)); | 252 EXPECT_CALL(audio_output_ipc_, CloseStream(kStreamId)); |
| 248 EXPECT_CALL(audio_output_ipc_, RemoveDelegate(kStreamId)); | |
| 249 | 253 |
| 250 io_loop_.RunUntilIdle(); | 254 io_loop_.RunUntilIdle(); |
| 251 } | 255 } |
| 252 | 256 |
| 253 TEST_P(AudioOutputDeviceTest, Initialize) { | 257 TEST_P(AudioOutputDeviceTest, Initialize) { |
| 254 Initialize(); | 258 // Tests that the object can be constructed, initialized and destructed |
| 259 // without having ever been started/stopped. |
| 255 } | 260 } |
| 256 | 261 |
| 257 // Calls Start() followed by an immediate Stop() and check for the basic message | 262 // Calls Start() followed by an immediate Stop() and check for the basic message |
| 258 // filter messages being sent in that case. | 263 // filter messages being sent in that case. |
| 259 TEST_P(AudioOutputDeviceTest, StartStop) { | 264 TEST_P(AudioOutputDeviceTest, StartStop) { |
| 260 Initialize(); | |
| 261 StartAudioDevice(); | 265 StartAudioDevice(); |
| 262 StopAudioDevice(); | 266 StopAudioDevice(); |
| 263 } | 267 } |
| 264 | 268 |
| 265 // AudioOutputDevice supports multiple start/stop sequences. | 269 // AudioOutputDevice supports multiple start/stop sequences. |
| 266 TEST_P(AudioOutputDeviceTest, StartStopStartStop) { | 270 TEST_P(AudioOutputDeviceTest, StartStopStartStop) { |
| 267 Initialize(); | |
| 268 StartAudioDevice(); | 271 StartAudioDevice(); |
| 269 StopAudioDevice(); | 272 StopAudioDevice(); |
| 270 StartAudioDevice(); | 273 StartAudioDevice(); |
| 271 StopAudioDevice(); | 274 StopAudioDevice(); |
| 272 } | 275 } |
| 273 | 276 |
| 274 // Simulate receiving OnStreamCreated() prior to processing ShutDownOnIOThread() | 277 // Simulate receiving OnStreamCreated() prior to processing ShutDownOnIOThread() |
| 275 // on the IO loop. | 278 // on the IO loop. |
| 276 TEST_P(AudioOutputDeviceTest, StopBeforeRender) { | 279 TEST_P(AudioOutputDeviceTest, StopBeforeRender) { |
| 277 Initialize(); | |
| 278 StartAudioDevice(); | 280 StartAudioDevice(); |
| 279 | 281 |
| 280 // Call Stop() but don't run the IO loop yet. | 282 // Call Stop() but don't run the IO loop yet. |
| 281 audio_device_->Stop(); | 283 audio_device_->Stop(); |
| 282 | 284 |
| 283 // Expect us to shutdown IPC but not to render anything despite the stream | 285 // Expect us to shutdown IPC but not to render anything despite the stream |
| 284 // getting created. | 286 // getting created. |
| 285 EXPECT_CALL(audio_output_ipc_, CloseStream(kStreamId)); | 287 EXPECT_CALL(audio_output_ipc_, CloseStream(kStreamId)); |
| 286 EXPECT_CALL(audio_output_ipc_, RemoveDelegate(kStreamId)); | |
| 287 CreateStream(); | 288 CreateStream(); |
| 288 } | 289 } |
| 289 | 290 |
| 290 // Full test with output only. | 291 // Full test with output only. |
| 291 TEST_P(AudioOutputDeviceTest, CreateStream) { | 292 TEST_P(AudioOutputDeviceTest, CreateStream) { |
| 292 Initialize(); | |
| 293 StartAudioDevice(); | 293 StartAudioDevice(); |
| 294 ExpectRenderCallback(); | 294 ExpectRenderCallback(); |
| 295 CreateStream(); | 295 CreateStream(); |
| 296 WaitUntilRenderCallback(); | 296 WaitUntilRenderCallback(); |
| 297 StopAudioDevice(); | 297 StopAudioDevice(); |
| 298 } | 298 } |
| 299 | 299 |
| 300 INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false)); | 300 INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false)); |
| 301 INSTANTIATE_TEST_CASE_P(RenderIO, AudioOutputDeviceTest, Values(true)); | 301 INSTANTIATE_TEST_CASE_P(RenderIO, AudioOutputDeviceTest, Values(true)); |
| 302 | 302 |
| 303 } // namespace media. | 303 } // namespace media. |
| OLD | NEW |