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