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