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/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 | 37 |
38 const char kDefaultDeviceId[] = ""; | 38 const char kDefaultDeviceId[] = ""; |
39 const char kNonDefaultDeviceId[] = "valid-nondefault-device-id"; | 39 const char kNonDefaultDeviceId[] = "valid-nondefault-device-id"; |
40 const char kUnauthorizedDeviceId[] = "unauthorized-device-id"; | 40 const char kUnauthorizedDeviceId[] = "unauthorized-device-id"; |
41 | 41 |
42 class MockRenderCallback : public AudioRendererSink::RenderCallback { | 42 class MockRenderCallback : public AudioRendererSink::RenderCallback { |
43 public: | 43 public: |
44 MockRenderCallback() {} | 44 MockRenderCallback() {} |
45 virtual ~MockRenderCallback() {} | 45 virtual ~MockRenderCallback() {} |
46 | 46 |
47 MOCK_METHOD3(Render, | 47 MOCK_METHOD2(Render, int(AudioBus* dest, int audio_delay_milliseconds)); |
48 int(AudioBus* dest, | |
49 uint32_t audio_delay_milliseconds, | |
50 uint32_t frames_skipped)); | |
51 MOCK_METHOD0(OnRenderError, void()); | 48 MOCK_METHOD0(OnRenderError, void()); |
52 }; | 49 }; |
53 | 50 |
54 class MockAudioOutputIPC : public AudioOutputIPC { | 51 class MockAudioOutputIPC : public AudioOutputIPC { |
55 public: | 52 public: |
56 MockAudioOutputIPC() {} | 53 MockAudioOutputIPC() {} |
57 virtual ~MockAudioOutputIPC() {} | 54 virtual ~MockAudioOutputIPC() {} |
58 | 55 |
59 MOCK_METHOD4(RequestDeviceAuthorization, | 56 MOCK_METHOD4(RequestDeviceAuthorization, |
60 void(AudioOutputIPCDelegate* delegate, | 57 void(AudioOutputIPCDelegate* delegate, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 | 110 |
114 SharedMemory shared_memory_; | 111 SharedMemory shared_memory_; |
115 CancelableSyncSocket browser_socket_; | 112 CancelableSyncSocket browser_socket_; |
116 CancelableSyncSocket renderer_socket_; | 113 CancelableSyncSocket renderer_socket_; |
117 | 114 |
118 DISALLOW_COPY_AND_ASSIGN(AudioOutputDeviceTest); | 115 DISALLOW_COPY_AND_ASSIGN(AudioOutputDeviceTest); |
119 }; | 116 }; |
120 | 117 |
121 int AudioOutputDeviceTest::CalculateMemorySize() { | 118 int AudioOutputDeviceTest::CalculateMemorySize() { |
122 // Calculate output memory size. | 119 // Calculate output memory size. |
123 return sizeof(AudioOutputBufferParameters) + | 120 return AudioBus::CalculateMemorySize(default_audio_parameters_); |
124 AudioBus::CalculateMemorySize(default_audio_parameters_); | |
125 } | 121 } |
126 | 122 |
127 AudioOutputDeviceTest::AudioOutputDeviceTest() | 123 AudioOutputDeviceTest::AudioOutputDeviceTest() |
128 : device_status_(OUTPUT_DEVICE_STATUS_ERROR_INTERNAL) { | 124 : device_status_(OUTPUT_DEVICE_STATUS_ERROR_INTERNAL) { |
129 default_audio_parameters_.Reset(AudioParameters::AUDIO_PCM_LINEAR, | 125 default_audio_parameters_.Reset(AudioParameters::AUDIO_PCM_LINEAR, |
130 CHANNEL_LAYOUT_STEREO, 48000, 16, 1024); | 126 CHANNEL_LAYOUT_STEREO, 48000, 16, 1024); |
131 SetDevice(kDefaultDeviceId); | 127 SetDevice(kDefaultDeviceId); |
132 } | 128 } |
133 | 129 |
134 AudioOutputDeviceTest::~AudioOutputDeviceTest() { | 130 AudioOutputDeviceTest::~AudioOutputDeviceTest() { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 .WillOnce(SendPendingBytes(&browser_socket_, kMemorySize)); | 207 .WillOnce(SendPendingBytes(&browser_socket_, kMemorySize)); |
212 | 208 |
213 // We expect calls to our audio renderer callback, which returns the number | 209 // We expect calls to our audio renderer callback, which returns the number |
214 // of frames written to the memory section. | 210 // of frames written to the memory section. |
215 // Here's the second place where it gets hacky: There's no way for us to | 211 // Here's the second place where it gets hacky: There's no way for us to |
216 // know (without using a sleep loop!) when the AudioOutputDevice has finished | 212 // know (without using a sleep loop!) when the AudioOutputDevice has finished |
217 // writing the interleaved audio data into the shared memory section. | 213 // writing the interleaved audio data into the shared memory section. |
218 // So, for the sake of this test, we consider the call to Render a sign | 214 // So, for the sake of this test, we consider the call to Render a sign |
219 // of success and quit the loop. | 215 // of success and quit the loop. |
220 const int kNumberOfFramesToProcess = 0; | 216 const int kNumberOfFramesToProcess = 0; |
221 EXPECT_CALL(callback_, Render(_, _, _)) | 217 EXPECT_CALL(callback_, Render(_, _)) |
222 .WillOnce(DoAll(QuitLoop(io_loop_.task_runner()), | 218 .WillOnce(DoAll( |
223 Return(kNumberOfFramesToProcess))); | 219 QuitLoop(io_loop_.task_runner()), |
| 220 Return(kNumberOfFramesToProcess))); |
224 } | 221 } |
225 | 222 |
226 void AudioOutputDeviceTest::WaitUntilRenderCallback() { | 223 void AudioOutputDeviceTest::WaitUntilRenderCallback() { |
227 // Don't hang the test if we never get the Render() callback. | 224 // Don't hang the test if we never get the Render() callback. |
228 io_loop_.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), | 225 io_loop_.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
229 TestTimeouts::action_timeout()); | 226 TestTimeouts::action_timeout()); |
230 io_loop_.Run(); | 227 io_loop_.Run(); |
231 } | 228 } |
232 | 229 |
233 void AudioOutputDeviceTest::StopAudioDevice() { | 230 void AudioOutputDeviceTest::StopAudioDevice() { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 | 306 |
310 TEST_P(AudioOutputDeviceTest, UnauthorizedDevice) { | 307 TEST_P(AudioOutputDeviceTest, UnauthorizedDevice) { |
311 SetDevice(kUnauthorizedDeviceId); | 308 SetDevice(kUnauthorizedDeviceId); |
312 StartAudioDevice(); | 309 StartAudioDevice(); |
313 StopAudioDevice(); | 310 StopAudioDevice(); |
314 } | 311 } |
315 | 312 |
316 INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false)); | 313 INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false)); |
317 | 314 |
318 } // namespace media. | 315 } // namespace media. |
OLD | NEW |