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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 : default_audio_parameters_(AudioParameters::AUDIO_PCM_LINEAR, |
101 CHANNEL_LAYOUT_STEREO, | 101 CHANNEL_LAYOUT_STEREO, |
102 48000, 16, 1024), | 102 48000, 16, 1024), |
103 audio_device_(new AudioOutputDevice( | |
104 &audio_output_ipc_, io_loop_.message_loop_proxy())), | |
105 synchronized_io_(GetParam()), | 103 synchronized_io_(GetParam()), |
106 input_channels_(synchronized_io_ ? 2 : 0) { | 104 input_channels_(synchronized_io_ ? 2 : 0) { |
107 } | 105 } |
108 | 106 |
109 ~AudioOutputDeviceTest() {} | 107 ~AudioOutputDeviceTest() {} |
110 | 108 |
| 109 void Construct(); |
| 110 void Destruct(); |
111 void Initialize(); | 111 void Initialize(); |
112 void StartAudioDevice(); | 112 void StartAudioDevice(); |
113 void CreateStream(); | 113 void CreateStream(); |
114 void ExpectRenderCallback(); | 114 void ExpectRenderCallback(); |
115 void WaitUntilRenderCallback(); | 115 void WaitUntilRenderCallback(); |
116 void StopAudioDevice(); | 116 void StopAudioDevice(); |
117 | 117 |
118 protected: | 118 protected: |
119 // Used to clean up TLS pointers that the test(s) will initialize. | 119 // Used to clean up TLS pointers that the test(s) will initialize. |
120 // Must remain the first member of this class. | 120 // Must remain the first member of this class. |
(...skipping 29 matching lines...) Expand all Loading... |
150 | 150 |
151 int io_buffer_size = output_memory_size + input_memory_size; | 151 int io_buffer_size = output_memory_size + input_memory_size; |
152 | 152 |
153 // This is where it gets a bit hacky. The shared memory contract between | 153 // 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 | 154 // AudioOutputDevice and its browser side counter part includes a bit more |
155 // than just the audio data, so we must call TotalSharedMemorySizeInBytes() | 155 // 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. | 156 // to get the actual size needed to fit the audio data plus the extra data. |
157 return TotalSharedMemorySizeInBytes(io_buffer_size); | 157 return TotalSharedMemorySizeInBytes(io_buffer_size); |
158 } | 158 } |
159 | 159 |
| 160 void AudioOutputDeviceTest::Construct() { |
| 161 audio_device_ = new AudioOutputDevice( |
| 162 &audio_output_ipc_, io_loop_.message_loop_proxy()); |
| 163 |
| 164 EXPECT_CALL(audio_output_ipc_, AddDelegate(audio_device_.get())) |
| 165 .WillOnce(Return(kStreamId)); |
| 166 |
| 167 io_loop_.RunUntilIdle(); |
| 168 } |
| 169 |
| 170 void AudioOutputDeviceTest::Destruct() { |
| 171 audio_device_ = NULL; |
| 172 |
| 173 EXPECT_CALL(audio_output_ipc_, RemoveDelegate(kStreamId)); |
| 174 |
| 175 io_loop_.RunUntilIdle(); |
| 176 } |
| 177 |
160 void AudioOutputDeviceTest::Initialize() { | 178 void AudioOutputDeviceTest::Initialize() { |
161 if (synchronized_io_) { | 179 if (synchronized_io_) { |
162 audio_device_->InitializeIO(default_audio_parameters_, | 180 audio_device_->InitializeIO(default_audio_parameters_, |
163 input_channels_, | 181 input_channels_, |
164 &callback_); | 182 &callback_); |
165 } else { | 183 } else { |
166 audio_device_->Initialize(default_audio_parameters_, | 184 audio_device_->Initialize(default_audio_parameters_, |
167 &callback_); | 185 &callback_); |
168 } | 186 } |
169 io_loop_.RunUntilIdle(); | 187 io_loop_.RunUntilIdle(); |
170 } | 188 } |
171 | 189 |
172 void AudioOutputDeviceTest::StartAudioDevice() { | 190 void AudioOutputDeviceTest::StartAudioDevice() { |
173 audio_device_->Start(); | 191 audio_device_->Start(); |
174 | 192 |
175 EXPECT_CALL(audio_output_ipc_, AddDelegate(audio_device_.get())) | |
176 .WillOnce(Return(kStreamId)); | |
177 EXPECT_CALL(audio_output_ipc_, CreateStream(kStreamId, _, _)); | 193 EXPECT_CALL(audio_output_ipc_, CreateStream(kStreamId, _, _)); |
178 | 194 |
179 io_loop_.RunUntilIdle(); | 195 io_loop_.RunUntilIdle(); |
180 } | 196 } |
181 | 197 |
182 void AudioOutputDeviceTest::CreateStream() { | 198 void AudioOutputDeviceTest::CreateStream() { |
183 const int kMemorySize = CalculateMemorySize(); | 199 const int kMemorySize = CalculateMemorySize(); |
184 | 200 |
185 ASSERT_TRUE(shared_memory_.CreateAndMapAnonymous(kMemorySize)); | 201 ASSERT_TRUE(shared_memory_.CreateAndMapAnonymous(kMemorySize)); |
186 memset(shared_memory_.memory(), 0xff, kMemorySize); | 202 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. | 254 // Don't hang the test if we never get the Render() callback. |
239 io_loop_.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), | 255 io_loop_.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), |
240 TestTimeouts::action_timeout()); | 256 TestTimeouts::action_timeout()); |
241 io_loop_.Run(); | 257 io_loop_.Run(); |
242 } | 258 } |
243 | 259 |
244 void AudioOutputDeviceTest::StopAudioDevice() { | 260 void AudioOutputDeviceTest::StopAudioDevice() { |
245 audio_device_->Stop(); | 261 audio_device_->Stop(); |
246 | 262 |
247 EXPECT_CALL(audio_output_ipc_, CloseStream(kStreamId)); | 263 EXPECT_CALL(audio_output_ipc_, CloseStream(kStreamId)); |
248 EXPECT_CALL(audio_output_ipc_, RemoveDelegate(kStreamId)); | |
249 | 264 |
250 io_loop_.RunUntilIdle(); | 265 io_loop_.RunUntilIdle(); |
251 } | 266 } |
252 | 267 |
253 TEST_P(AudioOutputDeviceTest, Initialize) { | 268 TEST_P(AudioOutputDeviceTest, Initialize) { |
| 269 Construct(); |
254 Initialize(); | 270 Initialize(); |
| 271 Destruct(); |
255 } | 272 } |
256 | 273 |
257 // Calls Start() followed by an immediate Stop() and check for the basic message | 274 // Calls Start() followed by an immediate Stop() and check for the basic message |
258 // filter messages being sent in that case. | 275 // filter messages being sent in that case. |
259 TEST_P(AudioOutputDeviceTest, StartStop) { | 276 TEST_P(AudioOutputDeviceTest, StartStop) { |
| 277 Construct(); |
260 Initialize(); | 278 Initialize(); |
261 StartAudioDevice(); | 279 StartAudioDevice(); |
262 StopAudioDevice(); | 280 StopAudioDevice(); |
| 281 Destruct(); |
263 } | 282 } |
264 | 283 |
265 // AudioOutputDevice supports multiple start/stop sequences. | 284 // AudioOutputDevice supports multiple start/stop sequences. |
266 TEST_P(AudioOutputDeviceTest, StartStopStartStop) { | 285 TEST_P(AudioOutputDeviceTest, StartStopStartStop) { |
| 286 Construct(); |
267 Initialize(); | 287 Initialize(); |
268 StartAudioDevice(); | 288 StartAudioDevice(); |
269 StopAudioDevice(); | 289 StopAudioDevice(); |
270 StartAudioDevice(); | 290 StartAudioDevice(); |
271 StopAudioDevice(); | 291 StopAudioDevice(); |
| 292 Destruct(); |
272 } | 293 } |
273 | 294 |
274 // Simulate receiving OnStreamCreated() prior to processing ShutDownOnIOThread() | 295 // Simulate receiving OnStreamCreated() prior to processing ShutDownOnIOThread() |
275 // on the IO loop. | 296 // on the IO loop. |
276 TEST_P(AudioOutputDeviceTest, StopBeforeRender) { | 297 TEST_P(AudioOutputDeviceTest, StopBeforeRender) { |
| 298 Construct(); |
277 Initialize(); | 299 Initialize(); |
278 StartAudioDevice(); | 300 StartAudioDevice(); |
279 | 301 |
280 // Call Stop() but don't run the IO loop yet. | 302 // Call Stop() but don't run the IO loop yet. |
281 audio_device_->Stop(); | 303 audio_device_->Stop(); |
282 | 304 |
283 // Expect us to shutdown IPC but not to render anything despite the stream | 305 // Expect us to shutdown IPC but not to render anything despite the stream |
284 // getting created. | 306 // getting created. |
285 EXPECT_CALL(audio_output_ipc_, CloseStream(kStreamId)); | 307 EXPECT_CALL(audio_output_ipc_, CloseStream(kStreamId)); |
286 EXPECT_CALL(audio_output_ipc_, RemoveDelegate(kStreamId)); | |
287 CreateStream(); | 308 CreateStream(); |
| 309 |
| 310 Destruct(); |
288 } | 311 } |
289 | 312 |
290 // Full test with output only. | 313 // Full test with output only. |
291 TEST_P(AudioOutputDeviceTest, CreateStream) { | 314 TEST_P(AudioOutputDeviceTest, CreateStream) { |
| 315 Construct(); |
292 Initialize(); | 316 Initialize(); |
293 StartAudioDevice(); | 317 StartAudioDevice(); |
294 ExpectRenderCallback(); | 318 ExpectRenderCallback(); |
295 CreateStream(); | 319 CreateStream(); |
296 WaitUntilRenderCallback(); | 320 WaitUntilRenderCallback(); |
297 StopAudioDevice(); | 321 StopAudioDevice(); |
| 322 Destruct(); |
298 } | 323 } |
299 | 324 |
300 INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false)); | 325 INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false)); |
301 INSTANTIATE_TEST_CASE_P(RenderIO, AudioOutputDeviceTest, Values(true)); | 326 INSTANTIATE_TEST_CASE_P(RenderIO, AudioOutputDeviceTest, Values(true)); |
302 | 327 |
303 } // namespace media. | 328 } // namespace media. |
OLD | NEW |