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

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

Issue 10823175: Switch AudioRenderSink::Callback to use AudioBus. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup MCR AudioBus usage. Created 8 years, 4 months 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 | Annotate | Revision Log
« no previous file with comments | « media/audio/audio_output_device.cc ('k') | media/audio/audio_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/process_util.h" 9 #include "base/process_util.h"
10 #include "base/shared_memory.h" 10 #include "base/shared_memory.h"
(...skipping 17 matching lines...) Expand all
28 28
29 namespace media { 29 namespace media {
30 30
31 namespace { 31 namespace {
32 32
33 class MockRenderCallback : public AudioRendererSink::RenderCallback { 33 class MockRenderCallback : public AudioRendererSink::RenderCallback {
34 public: 34 public:
35 MockRenderCallback() {} 35 MockRenderCallback() {}
36 virtual ~MockRenderCallback() {} 36 virtual ~MockRenderCallback() {}
37 37
38 MOCK_METHOD3(Render, int(const std::vector<float*>& audio_data, 38 MOCK_METHOD2(Render, int(AudioBus* audio_bus, int audio_delay_milliseconds));
39 int number_of_frames,
40 int audio_delay_milliseconds));
41 MOCK_METHOD0(OnRenderError, void()); 39 MOCK_METHOD0(OnRenderError, void());
42 }; 40 };
43 41
44 class MockAudioOutputIPC : public AudioOutputIPC { 42 class MockAudioOutputIPC : public AudioOutputIPC {
45 public: 43 public:
46 MockAudioOutputIPC() {} 44 MockAudioOutputIPC() {}
47 virtual ~MockAudioOutputIPC() {} 45 virtual ~MockAudioOutputIPC() {}
48 46
49 MOCK_METHOD1(AddDelegate, int(AudioOutputIPCDelegate* delegate)); 47 MOCK_METHOD1(AddDelegate, int(AudioOutputIPCDelegate* delegate));
50 MOCK_METHOD1(RemoveDelegate, void(int stream_id)); 48 MOCK_METHOD1(RemoveDelegate, void(int stream_id));
(...skipping 29 matching lines...) Expand all
80 ACTION_P2(SendPendingBytes, socket, pending_bytes) { 78 ACTION_P2(SendPendingBytes, socket, pending_bytes) {
81 socket->Send(&pending_bytes, sizeof(pending_bytes)); 79 socket->Send(&pending_bytes, sizeof(pending_bytes));
82 } 80 }
83 81
84 // Used to terminate a loop from a different thread than the loop belongs to. 82 // Used to terminate a loop from a different thread than the loop belongs to.
85 // |loop| should be a MessageLoopProxy. 83 // |loop| should be a MessageLoopProxy.
86 ACTION_P(QuitLoop, loop) { 84 ACTION_P(QuitLoop, loop) {
87 loop->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 85 loop->PostTask(FROM_HERE, MessageLoop::QuitClosure());
88 } 86 }
89 87
90 // Zeros out |number_of_frames| in all channel buffers pointed to by
91 // the |audio_data| vector.
92 void ZeroAudioData(int number_of_frames,
93 const std::vector<float*>& audio_data) {
94 std::vector<float*>::const_iterator it = audio_data.begin();
95 for (; it != audio_data.end(); ++it) {
96 float* channel = *it;
97 for (int j = 0; j < number_of_frames; ++j) {
98 channel[j] = 0.0f;
99 }
100 }
101 }
102
103 } // namespace. 88 } // namespace.
104 89
105 class AudioOutputDeviceTest : public testing::Test { 90 class AudioOutputDeviceTest : public testing::Test {
106 public: 91 public:
107 AudioOutputDeviceTest() 92 AudioOutputDeviceTest()
108 : default_audio_parameters_(AudioParameters::AUDIO_PCM_LINEAR, 93 : default_audio_parameters_(AudioParameters::AUDIO_PCM_LINEAR,
109 CHANNEL_LAYOUT_STEREO, 94 CHANNEL_LAYOUT_STEREO,
110 48000, 16, 1024), 95 48000, 16, 1024),
111 stream_id_(-1) { 96 stream_id_(-1) {
112 } 97 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 .WillOnce(SendPendingBytes(&browser_socket, memory_size)); 200 .WillOnce(SendPendingBytes(&browser_socket, memory_size));
216 201
217 // We expect calls to our audio renderer callback, which returns the number 202 // We expect calls to our audio renderer callback, which returns the number
218 // of frames written to the memory section. 203 // of frames written to the memory section.
219 // Here's the second place where it gets hacky: There's no way for us to 204 // Here's the second place where it gets hacky: There's no way for us to
220 // know (without using a sleep loop!) when the AudioOutputDevice has finished 205 // know (without using a sleep loop!) when the AudioOutputDevice has finished
221 // writing the interleaved audio data into the shared memory section. 206 // writing the interleaved audio data into the shared memory section.
222 // So, for the sake of this test, we consider the call to Render a sign 207 // So, for the sake of this test, we consider the call to Render a sign
223 // of success and quit the loop. 208 // of success and quit the loop.
224 209
225 // A note on the call to ZeroAudioData():
226 // Valgrind caught a bug in AudioOutputDevice::AudioThreadCallback::Process()
227 // whereby we always interleaved all the frames in the buffer regardless
228 // of how many were actually rendered. So to keep the benefits of that
229 // test, we explicitly pass 0 in here as the number of frames to
230 // ZeroAudioData(). Other tests might want to pass the requested number
231 // by using WithArgs<1, 0>(Invoke(&ZeroAudioData)) and set the return
232 // value accordingly.
233 const int kNumberOfFramesToProcess = 0; 210 const int kNumberOfFramesToProcess = 0;
234 211
235 EXPECT_CALL(callback_, Render(_, _, _)) 212 EXPECT_CALL(callback_, Render(_, _))
236 .WillOnce(DoAll( 213 .WillOnce(DoAll(
237 WithArgs<0>(Invoke(
238 testing::CreateFunctor(&ZeroAudioData,
239 kNumberOfFramesToProcess))),
240 QuitLoop(io_loop_.message_loop_proxy()), 214 QuitLoop(io_loop_.message_loop_proxy()),
241 Return(kNumberOfFramesToProcess))); 215 Return(kNumberOfFramesToProcess)));
242 216
243 audio_device->OnStreamCreated(duplicated_memory_handle, audio_device_socket, 217 audio_device->OnStreamCreated(duplicated_memory_handle, audio_device_socket,
244 memory_size); 218 memory_size);
245 219
246 io_loop_.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), 220 io_loop_.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(),
247 TestTimeouts::action_timeout()); 221 TestTimeouts::action_timeout());
248 io_loop_.Run(); 222 io_loop_.Run();
249 223
250 // Close the stream sequence. 224 // Close the stream sequence.
251 EXPECT_CALL(audio_output_ipc_, CloseStream(stream_id_)); 225 EXPECT_CALL(audio_output_ipc_, CloseStream(stream_id_));
252 226
253 audio_device->Stop(); 227 audio_device->Stop();
254 io_loop_.RunAllPending(); 228 io_loop_.RunAllPending();
255 } 229 }
256 230
257 } // namespace media. 231 } // namespace media.
OLDNEW
« no previous file with comments | « media/audio/audio_output_device.cc ('k') | media/audio/audio_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698