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

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

Issue 1487983002: Forward the number of skipped frames by the OS in audio playout. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Unit test fixes. Created 5 years 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 <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 27 matching lines...) Expand all
38 const std::string kDefaultDeviceId; 38 const std::string kDefaultDeviceId;
39 const std::string kNonDefaultDeviceId("valid-nondefault-device-id"); 39 const std::string kNonDefaultDeviceId("valid-nondefault-device-id");
40 const std::string kUnauthorizedDeviceId("unauthorized-device-id"); 40 const std::string kUnauthorizedDeviceId("unauthorized-device-id");
41 const url::Origin kDefaultSecurityOrigin; 41 const url::Origin kDefaultSecurityOrigin;
42 42
43 class MockRenderCallback : public AudioRendererSink::RenderCallback { 43 class MockRenderCallback : public AudioRendererSink::RenderCallback {
44 public: 44 public:
45 MockRenderCallback() {} 45 MockRenderCallback() {}
46 virtual ~MockRenderCallback() {} 46 virtual ~MockRenderCallback() {}
47 47
48 MOCK_METHOD2(Render, int(AudioBus* dest, int audio_delay_milliseconds)); 48 MOCK_METHOD3(Render,
49 int(AudioBus* dest,
50 uint32_t audio_delay_milliseconds,
51 uint32_t frames_skipped));
49 MOCK_METHOD0(OnRenderError, void()); 52 MOCK_METHOD0(OnRenderError, void());
50 }; 53 };
51 54
52 class MockAudioOutputIPC : public AudioOutputIPC { 55 class MockAudioOutputIPC : public AudioOutputIPC {
53 public: 56 public:
54 MockAudioOutputIPC() {} 57 MockAudioOutputIPC() {}
55 virtual ~MockAudioOutputIPC() {} 58 virtual ~MockAudioOutputIPC() {}
56 59
57 MOCK_METHOD4(RequestDeviceAuthorization, 60 MOCK_METHOD4(RequestDeviceAuthorization,
58 void(AudioOutputIPCDelegate* delegate, 61 void(AudioOutputIPCDelegate* delegate,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 114
112 SharedMemory shared_memory_; 115 SharedMemory shared_memory_;
113 CancelableSyncSocket browser_socket_; 116 CancelableSyncSocket browser_socket_;
114 CancelableSyncSocket renderer_socket_; 117 CancelableSyncSocket renderer_socket_;
115 118
116 DISALLOW_COPY_AND_ASSIGN(AudioOutputDeviceTest); 119 DISALLOW_COPY_AND_ASSIGN(AudioOutputDeviceTest);
117 }; 120 };
118 121
119 int AudioOutputDeviceTest::CalculateMemorySize() { 122 int AudioOutputDeviceTest::CalculateMemorySize() {
120 // Calculate output memory size. 123 // Calculate output memory size.
121 return AudioBus::CalculateMemorySize(default_audio_parameters_); 124 return sizeof(AudioOutputBufferParameters) +
125 AudioBus::CalculateMemorySize(default_audio_parameters_);
122 } 126 }
123 127
124 AudioOutputDeviceTest::AudioOutputDeviceTest() 128 AudioOutputDeviceTest::AudioOutputDeviceTest()
125 : device_status_(OUTPUT_DEVICE_STATUS_ERROR_INTERNAL) { 129 : device_status_(OUTPUT_DEVICE_STATUS_ERROR_INTERNAL) {
126 default_audio_parameters_.Reset(AudioParameters::AUDIO_PCM_LINEAR, 130 default_audio_parameters_.Reset(AudioParameters::AUDIO_PCM_LINEAR,
127 CHANNEL_LAYOUT_STEREO, 48000, 16, 1024); 131 CHANNEL_LAYOUT_STEREO, 48000, 16, 1024);
128 SetDevice(kDefaultDeviceId); 132 SetDevice(kDefaultDeviceId);
129 } 133 }
130 134
131 AudioOutputDeviceTest::~AudioOutputDeviceTest() { 135 AudioOutputDeviceTest::~AudioOutputDeviceTest() {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 .WillOnce(SendPendingBytes(&browser_socket_, kMemorySize)); 212 .WillOnce(SendPendingBytes(&browser_socket_, kMemorySize));
209 213
210 // We expect calls to our audio renderer callback, which returns the number 214 // We expect calls to our audio renderer callback, which returns the number
211 // of frames written to the memory section. 215 // of frames written to the memory section.
212 // Here's the second place where it gets hacky: There's no way for us to 216 // Here's the second place where it gets hacky: There's no way for us to
213 // know (without using a sleep loop!) when the AudioOutputDevice has finished 217 // know (without using a sleep loop!) when the AudioOutputDevice has finished
214 // writing the interleaved audio data into the shared memory section. 218 // writing the interleaved audio data into the shared memory section.
215 // So, for the sake of this test, we consider the call to Render a sign 219 // So, for the sake of this test, we consider the call to Render a sign
216 // of success and quit the loop. 220 // of success and quit the loop.
217 const int kNumberOfFramesToProcess = 0; 221 const int kNumberOfFramesToProcess = 0;
218 EXPECT_CALL(callback_, Render(_, _)) 222 EXPECT_CALL(callback_, Render(_, _, _))
219 .WillOnce(DoAll( 223 .WillOnce(DoAll(QuitLoop(io_loop_.task_runner()),
220 QuitLoop(io_loop_.task_runner()), 224 Return(kNumberOfFramesToProcess)));
221 Return(kNumberOfFramesToProcess)));
222 } 225 }
223 226
224 void AudioOutputDeviceTest::WaitUntilRenderCallback() { 227 void AudioOutputDeviceTest::WaitUntilRenderCallback() {
225 // Don't hang the test if we never get the Render() callback. 228 // Don't hang the test if we never get the Render() callback.
226 io_loop_.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), 229 io_loop_.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(),
227 TestTimeouts::action_timeout()); 230 TestTimeouts::action_timeout());
228 io_loop_.Run(); 231 io_loop_.Run();
229 } 232 }
230 233
231 void AudioOutputDeviceTest::StopAudioDevice() { 234 void AudioOutputDeviceTest::StopAudioDevice() {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 310
308 TEST_P(AudioOutputDeviceTest, UnauthorizedDevice) { 311 TEST_P(AudioOutputDeviceTest, UnauthorizedDevice) {
309 SetDevice(kUnauthorizedDeviceId); 312 SetDevice(kUnauthorizedDeviceId);
310 StartAudioDevice(); 313 StartAudioDevice();
311 StopAudioDevice(); 314 StopAudioDevice();
312 } 315 }
313 316
314 INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false)); 317 INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false));
315 318
316 } // namespace media. 319 } // namespace media.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698