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

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

Issue 11166002: Plumb render view ID from audio-related code in renderer through IPCs to AudioRendererHost in brows… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: VLOG --> DVLOG in audio*renderer_host.cc Created 8 years, 2 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
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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 } // namespace. 93 } // namespace.
94 94
95 class AudioOutputDeviceTest 95 class AudioOutputDeviceTest
96 : public testing::Test, 96 : public testing::Test,
97 public testing::WithParamInterface<bool> { 97 public testing::WithParamInterface<bool> {
98 public: 98 public:
99 AudioOutputDeviceTest() 99 AudioOutputDeviceTest()
100 : default_audio_parameters_(AudioParameters::AUDIO_PCM_LINEAR, 100 : default_audio_parameters_(AudioParameters::AUDIO_PCM_LINEAR,
101 CHANNEL_LAYOUT_STEREO, 101 CHANNEL_LAYOUT_STEREO,
102 48000, 16, 1024), 102 48000, 16, 1024),
103 audio_device_(new AudioOutputDevice(
104 &audio_output_ipc_, io_loop_.message_loop_proxy())),
105 synchronized_io_(GetParam()), 103 synchronized_io_(GetParam()),
106 input_channels_(synchronized_io_ ? 2 : 0) { 104 input_channels_(synchronized_io_ ? 2 : 0) {
107 } 105 }
108 106
109 ~AudioOutputDeviceTest() {} 107 ~AudioOutputDeviceTest() {}
110 108
111 void Initialize(); 109 void Initialize();
112 void StartAudioDevice(); 110 void StartAudioDevice();
113 void CreateStream(); 111 void CreateStream();
114 void ExpectRenderCallback(); 112 void ExpectRenderCallback();
115 void WaitUntilRenderCallback(); 113 void WaitUntilRenderCallback();
116 void StopAudioDevice(); 114 void StopAudioDevice();
117 115
118 protected: 116 protected:
119 // Used to clean up TLS pointers that the test(s) will initialize. 117 // Used to clean up TLS pointers that the test(s) will initialize.
120 // Must remain the first member of this class. 118 // Must remain the first member of this class.
121 base::ShadowingAtExitManager at_exit_manager_; 119 base::ShadowingAtExitManager at_exit_manager_;
122 MessageLoopForIO io_loop_; 120 MessageLoopForIO io_loop_;
123 const AudioParameters default_audio_parameters_; 121 const AudioParameters default_audio_parameters_;
124 StrictMock<MockRenderCallback> callback_; 122 StrictMock<MockRenderCallback> callback_;
125 StrictMock<MockAudioOutputIPC> audio_output_ipc_; 123 StrictMock<MockAudioOutputIPC>* audio_output_ipc_; // Owned by audio_device_.
126 scoped_refptr<AudioOutputDevice> audio_device_; 124 scoped_refptr<AudioOutputDevice> audio_device_;
127 125
128 private: 126 private:
129 int CalculateMemorySize(); 127 int CalculateMemorySize();
130 128
131 const bool synchronized_io_; 129 const bool synchronized_io_;
132 const int input_channels_; 130 const int input_channels_;
133 SharedMemory shared_memory_; 131 SharedMemory shared_memory_;
134 CancelableSyncSocket browser_socket_; 132 CancelableSyncSocket browser_socket_;
135 CancelableSyncSocket renderer_socket_; 133 CancelableSyncSocket renderer_socket_;
(...skipping 15 matching lines...) Expand all
151 int io_buffer_size = output_memory_size + input_memory_size; 149 int io_buffer_size = output_memory_size + input_memory_size;
152 150
153 // This is where it gets a bit hacky. The shared memory contract between 151 // This is where it gets a bit hacky. The shared memory contract between
154 // AudioOutputDevice and its browser side counter part includes a bit more 152 // AudioOutputDevice and its browser side counter part includes a bit more
155 // than just the audio data, so we must call TotalSharedMemorySizeInBytes() 153 // than just the audio data, so we must call TotalSharedMemorySizeInBytes()
156 // to get the actual size needed to fit the audio data plus the extra data. 154 // to get the actual size needed to fit the audio data plus the extra data.
157 return TotalSharedMemorySizeInBytes(io_buffer_size); 155 return TotalSharedMemorySizeInBytes(io_buffer_size);
158 } 156 }
159 157
160 void AudioOutputDeviceTest::Initialize() { 158 void AudioOutputDeviceTest::Initialize() {
159 audio_output_ipc_ = new StrictMock<MockAudioOutputIPC>;
160 audio_device_ = new AudioOutputDevice(audio_output_ipc_,
161 io_loop_.message_loop_proxy());
162
161 if (synchronized_io_) { 163 if (synchronized_io_) {
162 audio_device_->InitializeIO(default_audio_parameters_, 164 audio_device_->InitializeIO(default_audio_parameters_,
163 input_channels_, 165 input_channels_,
164 &callback_); 166 &callback_);
165 } else { 167 } else {
166 audio_device_->Initialize(default_audio_parameters_, 168 audio_device_->Initialize(default_audio_parameters_,
167 &callback_); 169 &callback_);
168 } 170 }
169 io_loop_.RunAllPending(); 171 io_loop_.RunAllPending();
170 } 172 }
171 173
172 void AudioOutputDeviceTest::StartAudioDevice() { 174 void AudioOutputDeviceTest::StartAudioDevice() {
173 audio_device_->Start(); 175 audio_device_->Start();
174 176
175 EXPECT_CALL(audio_output_ipc_, AddDelegate(audio_device_.get())) 177 EXPECT_CALL(*audio_output_ipc_, AddDelegate(audio_device_.get()))
176 .WillOnce(Return(kStreamId)); 178 .WillOnce(Return(kStreamId));
177 EXPECT_CALL(audio_output_ipc_, CreateStream(kStreamId, _, _)); 179 EXPECT_CALL(*audio_output_ipc_, CreateStream(kStreamId, _, _));
178 180
179 io_loop_.RunAllPending(); 181 io_loop_.RunAllPending();
180 } 182 }
181 183
182 void AudioOutputDeviceTest::CreateStream() { 184 void AudioOutputDeviceTest::CreateStream() {
183 const int kMemorySize = CalculateMemorySize(); 185 const int kMemorySize = CalculateMemorySize();
184 186
185 ASSERT_TRUE(shared_memory_.CreateAndMapAnonymous(kMemorySize)); 187 ASSERT_TRUE(shared_memory_.CreateAndMapAnonymous(kMemorySize));
186 memset(shared_memory_.memory(), 0xff, kMemorySize); 188 memset(shared_memory_.memory(), 0xff, kMemorySize);
187 189
(...skipping 15 matching lines...) Expand all
203 io_loop_.RunAllPending(); 205 io_loop_.RunAllPending();
204 } 206 }
205 207
206 void AudioOutputDeviceTest::ExpectRenderCallback() { 208 void AudioOutputDeviceTest::ExpectRenderCallback() {
207 // We should get a 'play' notification when we call OnStreamCreated(). 209 // We should get a 'play' notification when we call OnStreamCreated().
208 // Respond by asking for some audio data. This should ask our callback 210 // Respond by asking for some audio data. This should ask our callback
209 // to provide some audio data that AudioOutputDevice then writes into the 211 // to provide some audio data that AudioOutputDevice then writes into the
210 // shared memory section. 212 // shared memory section.
211 const int kMemorySize = CalculateMemorySize(); 213 const int kMemorySize = CalculateMemorySize();
212 214
213 EXPECT_CALL(audio_output_ipc_, PlayStream(kStreamId)) 215 EXPECT_CALL(*audio_output_ipc_, PlayStream(kStreamId))
214 .WillOnce(SendPendingBytes(&browser_socket_, kMemorySize)); 216 .WillOnce(SendPendingBytes(&browser_socket_, kMemorySize));
215 217
216 // We expect calls to our audio renderer callback, which returns the number 218 // We expect calls to our audio renderer callback, which returns the number
217 // of frames written to the memory section. 219 // of frames written to the memory section.
218 // Here's the second place where it gets hacky: There's no way for us to 220 // Here's the second place where it gets hacky: There's no way for us to
219 // know (without using a sleep loop!) when the AudioOutputDevice has finished 221 // know (without using a sleep loop!) when the AudioOutputDevice has finished
220 // writing the interleaved audio data into the shared memory section. 222 // writing the interleaved audio data into the shared memory section.
221 // So, for the sake of this test, we consider the call to Render a sign 223 // So, for the sake of this test, we consider the call to Render a sign
222 // of success and quit the loop. 224 // of success and quit the loop.
223 if (synchronized_io_) { 225 if (synchronized_io_) {
(...skipping 13 matching lines...) Expand all
237 void AudioOutputDeviceTest::WaitUntilRenderCallback() { 239 void AudioOutputDeviceTest::WaitUntilRenderCallback() {
238 // Don't hang the test if we never get the Render() callback. 240 // Don't hang the test if we never get the Render() callback.
239 io_loop_.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), 241 io_loop_.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(),
240 TestTimeouts::action_timeout()); 242 TestTimeouts::action_timeout());
241 io_loop_.Run(); 243 io_loop_.Run();
242 } 244 }
243 245
244 void AudioOutputDeviceTest::StopAudioDevice() { 246 void AudioOutputDeviceTest::StopAudioDevice() {
245 audio_device_->Stop(); 247 audio_device_->Stop();
246 248
247 EXPECT_CALL(audio_output_ipc_, CloseStream(kStreamId)); 249 EXPECT_CALL(*audio_output_ipc_, CloseStream(kStreamId));
248 EXPECT_CALL(audio_output_ipc_, RemoveDelegate(kStreamId)); 250 EXPECT_CALL(*audio_output_ipc_, RemoveDelegate(kStreamId));
249 251
250 io_loop_.RunAllPending(); 252 io_loop_.RunAllPending();
251 } 253 }
252 254
253 TEST_P(AudioOutputDeviceTest, Initialize) { 255 TEST_P(AudioOutputDeviceTest, Initialize) {
254 Initialize(); 256 Initialize();
255 } 257 }
256 258
257 // Calls Start() followed by an immediate Stop() and check for the basic message 259 // Calls Start() followed by an immediate Stop() and check for the basic message
258 // filter messages being sent in that case. 260 // filter messages being sent in that case.
(...skipping 16 matching lines...) Expand all
275 // on the IO loop. 277 // on the IO loop.
276 TEST_P(AudioOutputDeviceTest, StopBeforeRender) { 278 TEST_P(AudioOutputDeviceTest, StopBeforeRender) {
277 Initialize(); 279 Initialize();
278 StartAudioDevice(); 280 StartAudioDevice();
279 281
280 // Call Stop() but don't run the IO loop yet. 282 // Call Stop() but don't run the IO loop yet.
281 audio_device_->Stop(); 283 audio_device_->Stop();
282 284
283 // Expect us to shutdown IPC but not to render anything despite the stream 285 // Expect us to shutdown IPC but not to render anything despite the stream
284 // getting created. 286 // getting created.
285 EXPECT_CALL(audio_output_ipc_, CloseStream(kStreamId)); 287 EXPECT_CALL(*audio_output_ipc_, CloseStream(kStreamId));
286 EXPECT_CALL(audio_output_ipc_, RemoveDelegate(kStreamId)); 288 EXPECT_CALL(*audio_output_ipc_, RemoveDelegate(kStreamId));
287 CreateStream(); 289 CreateStream();
288 } 290 }
289 291
290 // Full test with output only. 292 // Full test with output only.
291 TEST_P(AudioOutputDeviceTest, CreateStream) { 293 TEST_P(AudioOutputDeviceTest, CreateStream) {
292 Initialize(); 294 Initialize();
293 StartAudioDevice(); 295 StartAudioDevice();
294 ExpectRenderCallback(); 296 ExpectRenderCallback();
295 CreateStream(); 297 CreateStream();
296 WaitUntilRenderCallback(); 298 WaitUntilRenderCallback();
297 StopAudioDevice(); 299 StopAudioDevice();
298 } 300 }
299 301
300 INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false)); 302 INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false));
301 INSTANTIATE_TEST_CASE_P(RenderIO, AudioOutputDeviceTest, Values(true)); 303 INSTANTIATE_TEST_CASE_P(RenderIO, AudioOutputDeviceTest, Values(true));
302 304
303 } // namespace media. 305 } // namespace media.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698