Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: media/audio/audio_output_device_unittest.cc

Issue 2517503003: Reland: Make more media APIs aware of |delay| and |delay_timestamp| (Closed)
Patch Set: Fixed speech synthesis on Chrome OS Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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,
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 SyncSocket::UnwrapHandle(audio_device_socket_descriptor), kMemorySize); 222 SyncSocket::UnwrapHandle(audio_device_socket_descriptor), kMemorySize);
222 base::RunLoop().RunUntilIdle(); 223 base::RunLoop().RunUntilIdle();
223 } 224 }
224 225
225 void AudioOutputDeviceTest::ExpectRenderCallback() { 226 void AudioOutputDeviceTest::ExpectRenderCallback() {
226 // We should get a 'play' notification when we call OnStreamCreated(). 227 // We should get a 'play' notification when we call OnStreamCreated().
227 // Respond by asking for some audio data. This should ask our callback 228 // Respond by asking for some audio data. This should ask our callback
228 // to provide some audio data that AudioOutputDevice then writes into the 229 // to provide some audio data that AudioOutputDevice then writes into the
229 // shared memory section. 230 // shared memory section.
230 const int kMemorySize = CalculateMemorySize(); 231 const int kMemorySize = CalculateMemorySize();
231
232 EXPECT_CALL(*audio_output_ipc_, PlayStream()) 232 EXPECT_CALL(*audio_output_ipc_, PlayStream())
233 .WillOnce(SendPendingBytes(&browser_socket_, kMemorySize)); 233 .WillOnce(SendPendingBytes(&browser_socket_, kMemorySize));
234 234
235 // 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
236 // of frames written to the memory section. 236 // of frames written to the memory section.
237 // 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
238 // know (without using a sleep loop!) when the AudioOutputDevice has finished 238 // know (without using a sleep loop!) when the AudioOutputDevice has finished
239 // writing the interleaved audio data into the shared memory section. 239 // 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 240 // So, for the sake of this test, we consider the call to Render a sign
241 // of success and quit the loop. 241 // of success and quit the loop.
242 const int kNumberOfFramesToProcess = 0; 242 const int kNumberOfFramesToProcess = 0;
243 EXPECT_CALL(callback_, Render(_, _, _)) 243 EXPECT_CALL(callback_, Render(_, _, _, _))
244 .WillOnce(DoAll(QuitLoop(io_loop_.task_runner()), 244 .WillOnce(DoAll(QuitLoop(io_loop_.task_runner()),
245 Return(kNumberOfFramesToProcess))); 245 Return(kNumberOfFramesToProcess)));
246 } 246 }
247 247
248 void AudioOutputDeviceTest::WaitUntilRenderCallback() { 248 void AudioOutputDeviceTest::WaitUntilRenderCallback() {
249 // 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.
250 io_loop_.task_runner()->PostDelayedTask( 250 io_loop_.task_runner()->PostDelayedTask(
251 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), 251 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(),
252 TestTimeouts::action_timeout()); 252 TestTimeouts::action_timeout());
253 base::RunLoop().Run(); 253 base::RunLoop().Run();
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 // 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.
364 event.RunAndWait(); 364 event.RunAndWait();
365 365
366 audio_device_->Stop(); 366 audio_device_->Stop();
367 base::RunLoop().RunUntilIdle(); 367 base::RunLoop().RunUntilIdle();
368 } 368 }
369 369
370 INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false)); 370 INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false));
371 371
372 } // namespace media. 372 } // namespace media.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698