| 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/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/process/process_handle.h" | 10 #include "base/process/process_handle.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 namespace media { | 30 namespace media { |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 class MockRenderCallback : public AudioRendererSink::RenderCallback { | 34 class MockRenderCallback : public AudioRendererSink::RenderCallback { |
| 35 public: | 35 public: |
| 36 MockRenderCallback() {} | 36 MockRenderCallback() {} |
| 37 virtual ~MockRenderCallback() {} | 37 virtual ~MockRenderCallback() {} |
| 38 | 38 |
| 39 MOCK_METHOD2(Render, int(AudioBus* dest, int audio_delay_milliseconds)); | 39 MOCK_METHOD2(Render, int(AudioBus* dest, int audio_delay_milliseconds)); |
| 40 MOCK_METHOD3(RenderIO, void(AudioBus* source, | |
| 41 AudioBus* dest, | |
| 42 int audio_delay_milliseconds)); | |
| 43 MOCK_METHOD0(OnRenderError, void()); | 40 MOCK_METHOD0(OnRenderError, void()); |
| 44 }; | 41 }; |
| 45 | 42 |
| 46 class MockAudioOutputIPC : public AudioOutputIPC { | 43 class MockAudioOutputIPC : public AudioOutputIPC { |
| 47 public: | 44 public: |
| 48 MockAudioOutputIPC() {} | 45 MockAudioOutputIPC() {} |
| 49 virtual ~MockAudioOutputIPC() {} | 46 virtual ~MockAudioOutputIPC() {} |
| 50 | 47 |
| 51 MOCK_METHOD3(CreateStream, void(AudioOutputIPCDelegate* delegate, | 48 MOCK_METHOD3(CreateStream, void(AudioOutputIPCDelegate* delegate, |
| 52 const AudioParameters& params, | 49 const AudioParameters& params, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 base::ShadowingAtExitManager at_exit_manager_; | 104 base::ShadowingAtExitManager at_exit_manager_; |
| 108 base::MessageLoopForIO io_loop_; | 105 base::MessageLoopForIO io_loop_; |
| 109 AudioParameters default_audio_parameters_; | 106 AudioParameters default_audio_parameters_; |
| 110 StrictMock<MockRenderCallback> callback_; | 107 StrictMock<MockRenderCallback> callback_; |
| 111 MockAudioOutputIPC* audio_output_ipc_; // owned by audio_device_ | 108 MockAudioOutputIPC* audio_output_ipc_; // owned by audio_device_ |
| 112 scoped_refptr<AudioOutputDevice> audio_device_; | 109 scoped_refptr<AudioOutputDevice> audio_device_; |
| 113 | 110 |
| 114 private: | 111 private: |
| 115 int CalculateMemorySize(); | 112 int CalculateMemorySize(); |
| 116 | 113 |
| 117 const bool synchronized_io_; | |
| 118 const int input_channels_; | |
| 119 SharedMemory shared_memory_; | 114 SharedMemory shared_memory_; |
| 120 CancelableSyncSocket browser_socket_; | 115 CancelableSyncSocket browser_socket_; |
| 121 CancelableSyncSocket renderer_socket_; | 116 CancelableSyncSocket renderer_socket_; |
| 122 | 117 |
| 123 DISALLOW_COPY_AND_ASSIGN(AudioOutputDeviceTest); | 118 DISALLOW_COPY_AND_ASSIGN(AudioOutputDeviceTest); |
| 124 }; | 119 }; |
| 125 | 120 |
| 126 int AudioOutputDeviceTest::CalculateMemorySize() { | 121 int AudioOutputDeviceTest::CalculateMemorySize() { |
| 127 // Calculate output and input memory size. | 122 // Calculate output memory size. |
| 128 int output_memory_size = | 123 return AudioBus::CalculateMemorySize(default_audio_parameters_); |
| 129 AudioBus::CalculateMemorySize(default_audio_parameters_); | |
| 130 | |
| 131 int frames = default_audio_parameters_.frames_per_buffer(); | |
| 132 int input_memory_size = | |
| 133 AudioBus::CalculateMemorySize(input_channels_, frames); | |
| 134 | |
| 135 return output_memory_size + input_memory_size; | |
| 136 } | 124 } |
| 137 | 125 |
| 138 AudioOutputDeviceTest::AudioOutputDeviceTest() | 126 AudioOutputDeviceTest::AudioOutputDeviceTest() { |
| 139 : synchronized_io_(GetParam()), | |
| 140 input_channels_(synchronized_io_ ? 2 : 0) { | |
| 141 default_audio_parameters_.Reset( | 127 default_audio_parameters_.Reset( |
| 142 AudioParameters::AUDIO_PCM_LINEAR, | 128 AudioParameters::AUDIO_PCM_LINEAR, |
| 143 CHANNEL_LAYOUT_STEREO, 2, input_channels_, | 129 CHANNEL_LAYOUT_STEREO, 2, 0, 48000, 16, 1024); |
| 144 48000, 16, 1024); | |
| 145 | 130 |
| 146 audio_output_ipc_ = new MockAudioOutputIPC(); | 131 audio_output_ipc_ = new MockAudioOutputIPC(); |
| 147 audio_device_ = new AudioOutputDevice( | 132 audio_device_ = new AudioOutputDevice( |
| 148 scoped_ptr<AudioOutputIPC>(audio_output_ipc_), | 133 scoped_ptr<AudioOutputIPC>(audio_output_ipc_), |
| 149 io_loop_.message_loop_proxy()); | 134 io_loop_.message_loop_proxy()); |
| 150 | 135 |
| 151 audio_device_->Initialize(default_audio_parameters_, | 136 audio_device_->Initialize(default_audio_parameters_, |
| 152 &callback_); | 137 &callback_); |
| 153 | 138 |
| 154 io_loop_.RunUntilIdle(); | 139 io_loop_.RunUntilIdle(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 EXPECT_CALL(*audio_output_ipc_, PlayStream()) | 185 EXPECT_CALL(*audio_output_ipc_, PlayStream()) |
| 201 .WillOnce(SendPendingBytes(&browser_socket_, kMemorySize)); | 186 .WillOnce(SendPendingBytes(&browser_socket_, kMemorySize)); |
| 202 | 187 |
| 203 // We expect calls to our audio renderer callback, which returns the number | 188 // We expect calls to our audio renderer callback, which returns the number |
| 204 // of frames written to the memory section. | 189 // of frames written to the memory section. |
| 205 // Here's the second place where it gets hacky: There's no way for us to | 190 // Here's the second place where it gets hacky: There's no way for us to |
| 206 // know (without using a sleep loop!) when the AudioOutputDevice has finished | 191 // know (without using a sleep loop!) when the AudioOutputDevice has finished |
| 207 // writing the interleaved audio data into the shared memory section. | 192 // writing the interleaved audio data into the shared memory section. |
| 208 // So, for the sake of this test, we consider the call to Render a sign | 193 // So, for the sake of this test, we consider the call to Render a sign |
| 209 // of success and quit the loop. | 194 // of success and quit the loop. |
| 210 if (synchronized_io_) { | 195 const int kNumberOfFramesToProcess = 0; |
| 211 // For synchronized I/O, we expect RenderIO(). | 196 EXPECT_CALL(callback_, Render(_, _)) |
| 212 EXPECT_CALL(callback_, RenderIO(_, _, _)) | 197 .WillOnce(DoAll( |
| 213 .WillOnce(QuitLoop(io_loop_.message_loop_proxy())); | 198 QuitLoop(io_loop_.message_loop_proxy()), |
| 214 } else { | 199 Return(kNumberOfFramesToProcess))); |
| 215 // For output only we expect Render(). | |
| 216 const int kNumberOfFramesToProcess = 0; | |
| 217 EXPECT_CALL(callback_, Render(_, _)) | |
| 218 .WillOnce(DoAll( | |
| 219 QuitLoop(io_loop_.message_loop_proxy()), | |
| 220 Return(kNumberOfFramesToProcess))); | |
| 221 } | |
| 222 } | 200 } |
| 223 | 201 |
| 224 void AudioOutputDeviceTest::WaitUntilRenderCallback() { | 202 void AudioOutputDeviceTest::WaitUntilRenderCallback() { |
| 225 // Don't hang the test if we never get the Render() callback. | 203 // Don't hang the test if we never get the Render() callback. |
| 226 io_loop_.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitClosure(), | 204 io_loop_.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitClosure(), |
| 227 TestTimeouts::action_timeout()); | 205 TestTimeouts::action_timeout()); |
| 228 io_loop_.Run(); | 206 io_loop_.Run(); |
| 229 } | 207 } |
| 230 | 208 |
| 231 void AudioOutputDeviceTest::StopAudioDevice() { | 209 void AudioOutputDeviceTest::StopAudioDevice() { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 // Full test with output only. | 251 // Full test with output only. |
| 274 TEST_P(AudioOutputDeviceTest, CreateStream) { | 252 TEST_P(AudioOutputDeviceTest, CreateStream) { |
| 275 StartAudioDevice(); | 253 StartAudioDevice(); |
| 276 ExpectRenderCallback(); | 254 ExpectRenderCallback(); |
| 277 CreateStream(); | 255 CreateStream(); |
| 278 WaitUntilRenderCallback(); | 256 WaitUntilRenderCallback(); |
| 279 StopAudioDevice(); | 257 StopAudioDevice(); |
| 280 } | 258 } |
| 281 | 259 |
| 282 INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false)); | 260 INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false)); |
| 283 INSTANTIATE_TEST_CASE_P(RenderIO, AudioOutputDeviceTest, Values(true)); | |
| 284 | 261 |
| 285 } // namespace media. | 262 } // namespace media. |
| OLD | NEW |