| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 const char kDefaultDeviceId[] = ""; | 46 const char kDefaultDeviceId[] = ""; |
| 47 const char kNonDefaultDeviceId[] = "valid-nondefault-device-id"; | 47 const char kNonDefaultDeviceId[] = "valid-nondefault-device-id"; |
| 48 const char kUnauthorizedDeviceId[] = "unauthorized-device-id"; | 48 const char kUnauthorizedDeviceId[] = "unauthorized-device-id"; |
| 49 const int kAuthTimeoutForTestingMs = 500; | 49 const int kAuthTimeoutForTestingMs = 500; |
| 50 | 50 |
| 51 class MockRenderCallback : public AudioRendererSink::RenderCallback { | 51 class MockRenderCallback : public AudioRendererSink::RenderCallback { |
| 52 public: | 52 public: |
| 53 MockRenderCallback() {} | 53 MockRenderCallback() {} |
| 54 virtual ~MockRenderCallback() {} | 54 virtual ~MockRenderCallback() {} |
| 55 | 55 |
| 56 MOCK_METHOD3(Render, | 56 MOCK_METHOD4(Render, |
| 57 int(AudioBus* dest, | 57 int(base::TimeDelta delay, |
| 58 uint32_t frames_delayed, | 58 base::TimeTicks timestamp, |
| 59 uint32_t frames_skipped)); | 59 int prior_frames_skipped, |
| 60 AudioBus* dest)); |
| 60 MOCK_METHOD0(OnRenderError, void()); | 61 MOCK_METHOD0(OnRenderError, void()); |
| 61 }; | 62 }; |
| 62 | 63 |
| 63 class MockAudioOutputIPC : public AudioOutputIPC { | 64 class MockAudioOutputIPC : public AudioOutputIPC { |
| 64 public: | 65 public: |
| 65 MockAudioOutputIPC() {} | 66 MockAudioOutputIPC() {} |
| 66 virtual ~MockAudioOutputIPC() {} | 67 virtual ~MockAudioOutputIPC() {} |
| 67 | 68 |
| 68 MOCK_METHOD4(RequestDeviceAuthorization, | 69 MOCK_METHOD4(RequestDeviceAuthorization, |
| 69 void(AudioOutputIPCDelegate* delegate, | 70 void(AudioOutputIPCDelegate* delegate, |
| 70 int session_id, | 71 int session_id, |
| 71 const std::string& device_id, | 72 const std::string& device_id, |
| 72 const url::Origin& security_origin)); | 73 const url::Origin& security_origin)); |
| 73 MOCK_METHOD2(CreateStream, | 74 MOCK_METHOD2(CreateStream, |
| 74 void(AudioOutputIPCDelegate* delegate, | 75 void(AudioOutputIPCDelegate* delegate, |
| 75 const AudioParameters& params)); | 76 const AudioParameters& params)); |
| 76 MOCK_METHOD0(PlayStream, void()); | 77 MOCK_METHOD0(PlayStream, void()); |
| 77 MOCK_METHOD0(PauseStream, void()); | 78 MOCK_METHOD0(PauseStream, void()); |
| 78 MOCK_METHOD0(CloseStream, void()); | 79 MOCK_METHOD0(CloseStream, void()); |
| 79 MOCK_METHOD1(SetVolume, void(double volume)); | 80 MOCK_METHOD1(SetVolume, void(double volume)); |
| 80 }; | 81 }; |
| 81 | 82 |
| 82 ACTION_P2(SendPendingBytes, socket, pending_bytes) { | 83 ACTION_P2(SendPendingData, socket, delay) { |
| 83 socket->Send(&pending_bytes, sizeof(pending_bytes)); | 84 const auto delay_timestamp = base::TimeTicks::Now(); |
| 85 media::AudioDeviceThread::Packet packet = {delay.ToInternalValue(), |
| 86 delay_timestamp.ToInternalValue()}; |
| 87 socket->Send(&packet, sizeof(packet)); |
| 84 } | 88 } |
| 85 | 89 |
| 86 // Used to terminate a loop from a different thread than the loop belongs to. | 90 // Used to terminate a loop from a different thread than the loop belongs to. |
| 87 // |task_runner| should be a SingleThreadTaskRunner. | 91 // |task_runner| should be a SingleThreadTaskRunner. |
| 88 ACTION_P(QuitLoop, task_runner) { | 92 ACTION_P(QuitLoop, task_runner) { |
| 89 task_runner->PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 93 task_runner->PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
| 90 } | 94 } |
| 91 | 95 |
| 92 } // namespace. | 96 } // namespace. |
| 93 | 97 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 duplicated_memory_handle, | 224 duplicated_memory_handle, |
| 221 SyncSocket::UnwrapHandle(audio_device_socket_descriptor), kMemorySize); | 225 SyncSocket::UnwrapHandle(audio_device_socket_descriptor), kMemorySize); |
| 222 base::RunLoop().RunUntilIdle(); | 226 base::RunLoop().RunUntilIdle(); |
| 223 } | 227 } |
| 224 | 228 |
| 225 void AudioOutputDeviceTest::ExpectRenderCallback() { | 229 void AudioOutputDeviceTest::ExpectRenderCallback() { |
| 226 // We should get a 'play' notification when we call OnStreamCreated(). | 230 // We should get a 'play' notification when we call OnStreamCreated(). |
| 227 // Respond by asking for some audio data. This should ask our callback | 231 // Respond by asking for some audio data. This should ask our callback |
| 228 // to provide some audio data that AudioOutputDevice then writes into the | 232 // to provide some audio data that AudioOutputDevice then writes into the |
| 229 // shared memory section. | 233 // shared memory section. |
| 230 const int kMemorySize = CalculateMemorySize(); | 234 const auto delay = base::TimeDelta::FromSeconds(1); |
| 231 | |
| 232 EXPECT_CALL(*audio_output_ipc_, PlayStream()) | 235 EXPECT_CALL(*audio_output_ipc_, PlayStream()) |
| 233 .WillOnce(SendPendingBytes(&browser_socket_, kMemorySize)); | 236 .WillOnce(SendPendingData(&browser_socket_, delay)); |
| 234 | 237 |
| 235 // We expect calls to our audio renderer callback, which returns the number | 238 // We expect calls to our audio renderer callback, which returns the number |
| 236 // of frames written to the memory section. | 239 // of frames written to the memory section. |
| 237 // Here's the second place where it gets hacky: There's no way for us to | 240 // Here's the second place where it gets hacky: There's no way for us to |
| 238 // know (without using a sleep loop!) when the AudioOutputDevice has finished | 241 // know (without using a sleep loop!) when the AudioOutputDevice has finished |
| 239 // writing the interleaved audio data into the shared memory section. | 242 // writing the interleaved audio data into the shared memory section. |
| 240 // So, for the sake of this test, we consider the call to Render a sign | 243 // So, for the sake of this test, we consider the call to Render a sign |
| 241 // of success and quit the loop. | 244 // of success and quit the loop. |
| 242 const int kNumberOfFramesToProcess = 0; | 245 const int kNumberOfFramesToProcess = 0; |
| 243 EXPECT_CALL(callback_, Render(_, _, _)) | 246 EXPECT_CALL(callback_, Render(_, _, _, _)) |
| 244 .WillOnce(DoAll(QuitLoop(io_loop_.task_runner()), | 247 .WillOnce(DoAll(QuitLoop(io_loop_.task_runner()), |
| 245 Return(kNumberOfFramesToProcess))); | 248 Return(kNumberOfFramesToProcess))); |
| 246 } | 249 } |
| 247 | 250 |
| 248 void AudioOutputDeviceTest::WaitUntilRenderCallback() { | 251 void AudioOutputDeviceTest::WaitUntilRenderCallback() { |
| 249 // Don't hang the test if we never get the Render() callback. | 252 // Don't hang the test if we never get the Render() callback. |
| 250 io_loop_.task_runner()->PostDelayedTask( | 253 io_loop_.task_runner()->PostDelayedTask( |
| 251 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), | 254 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
| 252 TestTimeouts::action_timeout()); | 255 TestTimeouts::action_timeout()); |
| 253 base::RunLoop().Run(); | 256 base::RunLoop().Run(); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 // Runs the loop and waits for |thread| to call event's closure. | 366 // Runs the loop and waits for |thread| to call event's closure. |
| 364 event.RunAndWait(); | 367 event.RunAndWait(); |
| 365 | 368 |
| 366 audio_device_->Stop(); | 369 audio_device_->Stop(); |
| 367 base::RunLoop().RunUntilIdle(); | 370 base::RunLoop().RunUntilIdle(); |
| 368 } | 371 } |
| 369 | 372 |
| 370 INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false)); | 373 INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false)); |
| 371 | 374 |
| 372 } // namespace media. | 375 } // namespace media. |
| OLD | NEW |