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

Side by Side Diff: media/audio/linux/alsa_output_unittest.cc

Issue 8818012: Remove the AudioManager singleton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Set svn eol properties for a couple of files Created 9 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 | Annotate | Revision Log
« no previous file with comments | « media/audio/linux/alsa_input.cc ('k') | media/audio/linux/audio_manager_linux.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/message_loop.h" 5 #include "base/message_loop.h"
6 #include "base/stringprintf.h" 6 #include "base/stringprintf.h"
7 #include "media/audio/linux/alsa_output.h" 7 #include "media/audio/linux/alsa_output.h"
8 #include "media/audio/linux/alsa_wrapper.h" 8 #include "media/audio/linux/alsa_wrapper.h"
9 #include "media/audio/linux/audio_manager_linux.h" 9 #include "media/audio/linux/audio_manager_linux.h"
10 #include "media/base/data_buffer.h" 10 #include "media/base/data_buffer.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 const AudioParameters& params, const std::string& device_id)); 84 const AudioParameters& params, const std::string& device_id));
85 MOCK_METHOD0(MuteAll, void()); 85 MOCK_METHOD0(MuteAll, void());
86 MOCK_METHOD0(UnMuteAll, void()); 86 MOCK_METHOD0(UnMuteAll, void());
87 87
88 MOCK_METHOD1(ReleaseOutputStream, void(AudioOutputStream* stream)); 88 MOCK_METHOD1(ReleaseOutputStream, void(AudioOutputStream* stream));
89 }; 89 };
90 90
91 class AlsaPcmOutputStreamTest : public testing::Test { 91 class AlsaPcmOutputStreamTest : public testing::Test {
92 protected: 92 protected:
93 AlsaPcmOutputStreamTest() { 93 AlsaPcmOutputStreamTest() {
94 mock_manager_ = new StrictMock<MockAudioManagerLinux>();
94 test_stream_.reset(CreateStream(kTestChannelLayout)); 95 test_stream_.reset(CreateStream(kTestChannelLayout));
95 } 96 }
96 97
97 virtual ~AlsaPcmOutputStreamTest() { 98 virtual ~AlsaPcmOutputStreamTest() {
98 test_stream_.reset(NULL); 99 test_stream_.reset(NULL);
99 } 100 }
100 101
101 AlsaPcmOutputStream* CreateStream(ChannelLayout layout) { 102 AlsaPcmOutputStream* CreateStream(ChannelLayout layout) {
102 return CreateStream(layout, kTestFramesPerPacket); 103 return CreateStream(layout, kTestFramesPerPacket);
103 } 104 }
104 105
105 AlsaPcmOutputStream* CreateStream(ChannelLayout layout, 106 AlsaPcmOutputStream* CreateStream(ChannelLayout layout,
106 int32 samples_per_packet) { 107 int32 samples_per_packet) {
107 AudioParameters params(kTestFormat, layout, kTestSampleRate, 108 AudioParameters params(kTestFormat, layout, kTestSampleRate,
108 kTestBitsPerSample, samples_per_packet); 109 kTestBitsPerSample, samples_per_packet);
109 return new AlsaPcmOutputStream(kTestDeviceName, 110 return new AlsaPcmOutputStream(kTestDeviceName,
110 params, 111 params,
111 &mock_alsa_wrapper_, 112 &mock_alsa_wrapper_,
112 &mock_manager_, 113 mock_manager_,
113 &message_loop_); 114 &message_loop_);
114 } 115 }
115 116
116 // Helper function to malloc the string returned by DeviceNameHint for NAME. 117 // Helper function to malloc the string returned by DeviceNameHint for NAME.
117 static char* EchoHint(const void* name, Unused) { 118 static char* EchoHint(const void* name, Unused) {
118 return strdup(static_cast<const char*>(name)); 119 return strdup(static_cast<const char*>(name));
119 } 120 }
120 121
121 // Helper function to malloc the string returned by DeviceNameHint for IOID. 122 // Helper function to malloc the string returned by DeviceNameHint for IOID.
122 static char* OutputHint(Unused, Unused) { 123 static char* OutputHint(Unused, Unused) {
123 return strdup("Output"); 124 return strdup("Output");
124 } 125 }
125 126
126 // Helper function to initialize |test_stream_->buffer_|. Must be called 127 // Helper function to initialize |test_stream_->buffer_|. Must be called
127 // in all tests that use buffer_ without opening the stream. 128 // in all tests that use buffer_ without opening the stream.
128 void InitBuffer() { 129 void InitBuffer() {
129 packet_ = new media::DataBuffer(kTestPacketSize); 130 packet_ = new media::DataBuffer(kTestPacketSize);
130 packet_->SetDataSize(kTestPacketSize); 131 packet_->SetDataSize(kTestPacketSize);
131 test_stream_->buffer_.reset(new media::SeekableBuffer(0, kTestPacketSize)); 132 test_stream_->buffer_.reset(new media::SeekableBuffer(0, kTestPacketSize));
132 test_stream_->buffer_->Append(packet_.get()); 133 test_stream_->buffer_->Append(packet_.get());
133 } 134 }
134 135
136 MockAudioManagerLinux& mock_manager() {
137 return *mock_manager_;
138 }
139
135 static const ChannelLayout kTestChannelLayout; 140 static const ChannelLayout kTestChannelLayout;
136 static const int kTestSampleRate; 141 static const int kTestSampleRate;
137 static const int kTestBitsPerSample; 142 static const int kTestBitsPerSample;
138 static const int kTestBytesPerFrame; 143 static const int kTestBytesPerFrame;
139 static const AudioParameters::Format kTestFormat; 144 static const AudioParameters::Format kTestFormat;
140 static const char kTestDeviceName[]; 145 static const char kTestDeviceName[];
141 static const char kDummyMessage[]; 146 static const char kDummyMessage[];
142 static const uint32 kTestFramesPerPacket; 147 static const uint32 kTestFramesPerPacket;
143 static const uint32 kTestPacketSize; 148 static const uint32 kTestPacketSize;
144 static const int kTestFailedErrno; 149 static const int kTestFailedErrno;
145 static snd_pcm_t* const kFakeHandle; 150 static snd_pcm_t* const kFakeHandle;
146 151
147 // Used to simulate DeviceNameHint. 152 // Used to simulate DeviceNameHint.
148 static char kSurround40[]; 153 static char kSurround40[];
149 static char kSurround41[]; 154 static char kSurround41[];
150 static char kSurround50[]; 155 static char kSurround50[];
151 static char kSurround51[]; 156 static char kSurround51[];
152 static char kSurround70[]; 157 static char kSurround70[];
153 static char kSurround71[]; 158 static char kSurround71[];
154 static void* kFakeHints[]; 159 static void* kFakeHints[];
155 160
156 StrictMock<MockAlsaWrapper> mock_alsa_wrapper_; 161 StrictMock<MockAlsaWrapper> mock_alsa_wrapper_;
157 StrictMock<MockAudioManagerLinux> mock_manager_; 162 scoped_refptr<StrictMock<MockAudioManagerLinux> > mock_manager_;
158 MessageLoop message_loop_; 163 MessageLoop message_loop_;
159 scoped_ptr<AlsaPcmOutputStream> test_stream_; 164 scoped_ptr<AlsaPcmOutputStream> test_stream_;
160 scoped_refptr<media::DataBuffer> packet_; 165 scoped_refptr<media::DataBuffer> packet_;
161 166
162 private: 167 private:
163 DISALLOW_COPY_AND_ASSIGN(AlsaPcmOutputStreamTest); 168 DISALLOW_COPY_AND_ASSIGN(AlsaPcmOutputStreamTest);
164 }; 169 };
165 170
166 const ChannelLayout AlsaPcmOutputStreamTest::kTestChannelLayout = 171 const ChannelLayout AlsaPcmOutputStreamTest::kTestChannelLayout =
167 CHANNEL_LAYOUT_STEREO; 172 CHANNEL_LAYOUT_STEREO;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 test_stream_.reset(CreateStream(CHANNEL_LAYOUT_SURROUND)); 209 test_stream_.reset(CreateStream(CHANNEL_LAYOUT_SURROUND));
205 EXPECT_EQ(AlsaPcmOutputStream::kCreated, test_stream_->state()); 210 EXPECT_EQ(AlsaPcmOutputStream::kCreated, test_stream_->state());
206 211
207 // Bad bits per sample. 212 // Bad bits per sample.
208 AudioParameters bad_bps_params(kTestFormat, kTestChannelLayout, 213 AudioParameters bad_bps_params(kTestFormat, kTestChannelLayout,
209 kTestSampleRate, kTestBitsPerSample - 1, 214 kTestSampleRate, kTestBitsPerSample - 1,
210 kTestFramesPerPacket); 215 kTestFramesPerPacket);
211 test_stream_.reset(new AlsaPcmOutputStream(kTestDeviceName, 216 test_stream_.reset(new AlsaPcmOutputStream(kTestDeviceName,
212 bad_bps_params, 217 bad_bps_params,
213 &mock_alsa_wrapper_, 218 &mock_alsa_wrapper_,
214 &mock_manager_, 219 mock_manager_,
215 &message_loop_)); 220 &message_loop_));
216 EXPECT_EQ(AlsaPcmOutputStream::kInError, test_stream_->state()); 221 EXPECT_EQ(AlsaPcmOutputStream::kInError, test_stream_->state());
217 222
218 // Bad format. 223 // Bad format.
219 AudioParameters bad_format_params( 224 AudioParameters bad_format_params(
220 AudioParameters::AUDIO_LAST_FORMAT, kTestChannelLayout, kTestSampleRate, 225 AudioParameters::AUDIO_LAST_FORMAT, kTestChannelLayout, kTestSampleRate,
221 kTestBitsPerSample, kTestFramesPerPacket); 226 kTestBitsPerSample, kTestFramesPerPacket);
222 test_stream_.reset(new AlsaPcmOutputStream(kTestDeviceName, 227 test_stream_.reset(new AlsaPcmOutputStream(kTestDeviceName,
223 bad_format_params, 228 bad_format_params,
224 &mock_alsa_wrapper_, 229 &mock_alsa_wrapper_,
225 &mock_manager_, 230 mock_manager_,
226 &message_loop_)); 231 &message_loop_));
227 EXPECT_EQ(AlsaPcmOutputStream::kInError, test_stream_->state()); 232 EXPECT_EQ(AlsaPcmOutputStream::kInError, test_stream_->state());
228 } 233 }
229 234
230 TEST_F(AlsaPcmOutputStreamTest, LatencyFloor) { 235 TEST_F(AlsaPcmOutputStreamTest, LatencyFloor) {
231 const double kMicrosPerFrame = 236 const double kMicrosPerFrame =
232 static_cast<double>(1000000) / kTestSampleRate; 237 static_cast<double>(1000000) / kTestSampleRate;
233 const double kPacketFramesInMinLatency = 238 const double kPacketFramesInMinLatency =
234 AlsaPcmOutputStream::kMinLatencyMicros / kMicrosPerFrame / 2.0; 239 AlsaPcmOutputStream::kMinLatencyMicros / kMicrosPerFrame / 2.0;
235 240
(...skipping 14 matching lines...) Expand all
250 255
251 test_stream_.reset(CreateStream(kTestChannelLayout, 256 test_stream_.reset(CreateStream(kTestChannelLayout,
252 kPacketFramesInMinLatency)); 257 kPacketFramesInMinLatency));
253 ASSERT_TRUE(test_stream_->Open()); 258 ASSERT_TRUE(test_stream_->Open());
254 message_loop_.RunAllPending(); 259 message_loop_.RunAllPending();
255 260
256 // Now close it and test that everything was released. 261 // Now close it and test that everything was released.
257 EXPECT_CALL(mock_alsa_wrapper_, PcmClose(kFakeHandle)).WillOnce(Return(0)); 262 EXPECT_CALL(mock_alsa_wrapper_, PcmClose(kFakeHandle)).WillOnce(Return(0));
258 EXPECT_CALL(mock_alsa_wrapper_, PcmName(kFakeHandle)) 263 EXPECT_CALL(mock_alsa_wrapper_, PcmName(kFakeHandle))
259 .WillOnce(Return(kTestDeviceName)); 264 .WillOnce(Return(kTestDeviceName));
260 EXPECT_CALL(mock_manager_, ReleaseOutputStream(test_stream_.get())); 265 EXPECT_CALL(mock_manager(), ReleaseOutputStream(test_stream_.get()));
261 test_stream_->Close(); 266 test_stream_->Close();
262 message_loop_.RunAllPending(); 267 message_loop_.RunAllPending();
263 268
264 Mock::VerifyAndClear(&mock_alsa_wrapper_); 269 Mock::VerifyAndClear(&mock_alsa_wrapper_);
265 Mock::VerifyAndClear(&mock_manager_); 270 Mock::VerifyAndClear(mock_manager_);
266 271
267 // Test that having more packets ends up with a latency based on packet size. 272 // Test that having more packets ends up with a latency based on packet size.
268 const int kOverMinLatencyPacketSize = kPacketFramesInMinLatency + 1; 273 const int kOverMinLatencyPacketSize = kPacketFramesInMinLatency + 1;
269 int64 expected_micros = 2 * AlsaPcmOutputStream::FramesToMicros( 274 int64 expected_micros = 2 * AlsaPcmOutputStream::FramesToMicros(
270 kOverMinLatencyPacketSize, kTestSampleRate); 275 kOverMinLatencyPacketSize, kTestSampleRate);
271 276
272 EXPECT_CALL(mock_alsa_wrapper_, PcmOpen(_, _, _, _)) 277 EXPECT_CALL(mock_alsa_wrapper_, PcmOpen(_, _, _, _))
273 .WillOnce(DoAll(SetArgumentPointee<0>(kFakeHandle), Return(0))); 278 .WillOnce(DoAll(SetArgumentPointee<0>(kFakeHandle), Return(0)));
274 EXPECT_CALL(mock_alsa_wrapper_, 279 EXPECT_CALL(mock_alsa_wrapper_,
275 PcmSetParams(_, _, _, _, _, _, expected_micros)) 280 PcmSetParams(_, _, _, _, _, _, expected_micros))
276 .WillOnce(Return(0)); 281 .WillOnce(Return(0));
277 EXPECT_CALL(mock_alsa_wrapper_, PcmGetParams(_, _, _)) 282 EXPECT_CALL(mock_alsa_wrapper_, PcmGetParams(_, _, _))
278 .WillOnce(DoAll(SetArgumentPointee<1>(kTestFramesPerPacket), 283 .WillOnce(DoAll(SetArgumentPointee<1>(kTestFramesPerPacket),
279 SetArgumentPointee<2>(kTestFramesPerPacket / 2), 284 SetArgumentPointee<2>(kTestFramesPerPacket / 2),
280 Return(0))); 285 Return(0)));
281 286
282 test_stream_.reset(CreateStream(kTestChannelLayout, 287 test_stream_.reset(CreateStream(kTestChannelLayout,
283 kOverMinLatencyPacketSize)); 288 kOverMinLatencyPacketSize));
284 ASSERT_TRUE(test_stream_->Open()); 289 ASSERT_TRUE(test_stream_->Open());
285 message_loop_.RunAllPending(); 290 message_loop_.RunAllPending();
286 291
287 // Now close it and test that everything was released. 292 // Now close it and test that everything was released.
288 EXPECT_CALL(mock_alsa_wrapper_, PcmClose(kFakeHandle)) 293 EXPECT_CALL(mock_alsa_wrapper_, PcmClose(kFakeHandle))
289 .WillOnce(Return(0)); 294 .WillOnce(Return(0));
290 EXPECT_CALL(mock_alsa_wrapper_, PcmName(kFakeHandle)) 295 EXPECT_CALL(mock_alsa_wrapper_, PcmName(kFakeHandle))
291 .WillOnce(Return(kTestDeviceName)); 296 .WillOnce(Return(kTestDeviceName));
292 EXPECT_CALL(mock_manager_, ReleaseOutputStream(test_stream_.get())); 297 EXPECT_CALL(mock_manager(), ReleaseOutputStream(test_stream_.get()));
293 test_stream_->Close(); 298 test_stream_->Close();
294 message_loop_.RunAllPending(); 299 message_loop_.RunAllPending();
295 300
296 Mock::VerifyAndClear(&mock_alsa_wrapper_); 301 Mock::VerifyAndClear(&mock_alsa_wrapper_);
297 Mock::VerifyAndClear(&mock_manager_); 302 Mock::VerifyAndClear(mock_manager_);
298 } 303 }
299 304
300 TEST_F(AlsaPcmOutputStreamTest, OpenClose) { 305 TEST_F(AlsaPcmOutputStreamTest, OpenClose) {
301 int64 expected_micros = 2 * 306 int64 expected_micros = 2 *
302 AlsaPcmOutputStream::FramesToMicros(kTestPacketSize / kTestBytesPerFrame, 307 AlsaPcmOutputStream::FramesToMicros(kTestPacketSize / kTestBytesPerFrame,
303 kTestSampleRate); 308 kTestSampleRate);
304 309
305 // Open() call opens the playback device, sets the parameters, posts a task 310 // Open() call opens the playback device, sets the parameters, posts a task
306 // with the resulting configuration data, and transitions the object state to 311 // with the resulting configuration data, and transitions the object state to
307 // kIsOpened. 312 // kIsOpened.
(...skipping 24 matching lines...) Expand all
332 EXPECT_EQ(kFakeHandle, test_stream_->playback_handle_); 337 EXPECT_EQ(kFakeHandle, test_stream_->playback_handle_);
333 EXPECT_EQ(kTestFramesPerPacket, test_stream_->frames_per_packet_); 338 EXPECT_EQ(kTestFramesPerPacket, test_stream_->frames_per_packet_);
334 EXPECT_TRUE(test_stream_->buffer_.get()); 339 EXPECT_TRUE(test_stream_->buffer_.get());
335 EXPECT_FALSE(test_stream_->stop_stream_); 340 EXPECT_FALSE(test_stream_->stop_stream_);
336 341
337 // Now close it and test that everything was released. 342 // Now close it and test that everything was released.
338 EXPECT_CALL(mock_alsa_wrapper_, PcmClose(kFakeHandle)) 343 EXPECT_CALL(mock_alsa_wrapper_, PcmClose(kFakeHandle))
339 .WillOnce(Return(0)); 344 .WillOnce(Return(0));
340 EXPECT_CALL(mock_alsa_wrapper_, PcmName(kFakeHandle)) 345 EXPECT_CALL(mock_alsa_wrapper_, PcmName(kFakeHandle))
341 .WillOnce(Return(kTestDeviceName)); 346 .WillOnce(Return(kTestDeviceName));
342 EXPECT_CALL(mock_manager_, ReleaseOutputStream(test_stream_.get())); 347 EXPECT_CALL(mock_manager(), ReleaseOutputStream(test_stream_.get()));
343 test_stream_->Close(); 348 test_stream_->Close();
344 message_loop_.RunAllPending(); 349 message_loop_.RunAllPending();
345 350
346 EXPECT_TRUE(test_stream_->playback_handle_ == NULL); 351 EXPECT_TRUE(test_stream_->playback_handle_ == NULL);
347 EXPECT_FALSE(test_stream_->buffer_.get()); 352 EXPECT_FALSE(test_stream_->buffer_.get());
348 EXPECT_TRUE(test_stream_->stop_stream_); 353 EXPECT_TRUE(test_stream_->stop_stream_);
349 } 354 }
350 355
351 TEST_F(AlsaPcmOutputStreamTest, PcmOpenFailed) { 356 TEST_F(AlsaPcmOutputStreamTest, PcmOpenFailed) {
352 EXPECT_CALL(mock_alsa_wrapper_, PcmOpen(_, _, _, _)) 357 EXPECT_CALL(mock_alsa_wrapper_, PcmOpen(_, _, _, _))
353 .WillOnce(Return(kTestFailedErrno)); 358 .WillOnce(Return(kTestFailedErrno));
354 EXPECT_CALL(mock_alsa_wrapper_, StrError(kTestFailedErrno)) 359 EXPECT_CALL(mock_alsa_wrapper_, StrError(kTestFailedErrno))
355 .WillOnce(Return(kDummyMessage)); 360 .WillOnce(Return(kDummyMessage));
356 361
357 // Open still succeeds since PcmOpen is delegated to another thread. 362 // Open still succeeds since PcmOpen is delegated to another thread.
358 ASSERT_TRUE(test_stream_->Open()); 363 ASSERT_TRUE(test_stream_->Open());
359 ASSERT_EQ(AlsaPcmOutputStream::kIsOpened, test_stream_->state()); 364 ASSERT_EQ(AlsaPcmOutputStream::kIsOpened, test_stream_->state());
360 ASSERT_FALSE(test_stream_->stop_stream_); 365 ASSERT_FALSE(test_stream_->stop_stream_);
361 message_loop_.RunAllPending(); 366 message_loop_.RunAllPending();
362 367
363 // Ensure internal state is set for a no-op stream if PcmOpen() failes. 368 // Ensure internal state is set for a no-op stream if PcmOpen() failes.
364 EXPECT_EQ(AlsaPcmOutputStream::kIsOpened, test_stream_->state()); 369 EXPECT_EQ(AlsaPcmOutputStream::kIsOpened, test_stream_->state());
365 EXPECT_TRUE(test_stream_->stop_stream_); 370 EXPECT_TRUE(test_stream_->stop_stream_);
366 EXPECT_TRUE(test_stream_->playback_handle_ == NULL); 371 EXPECT_TRUE(test_stream_->playback_handle_ == NULL);
367 EXPECT_FALSE(test_stream_->buffer_.get()); 372 EXPECT_FALSE(test_stream_->buffer_.get());
368 373
369 // Close the stream since we opened it to make destruction happy. 374 // Close the stream since we opened it to make destruction happy.
370 EXPECT_CALL(mock_manager_, ReleaseOutputStream(test_stream_.get())); 375 EXPECT_CALL(mock_manager(), ReleaseOutputStream(test_stream_.get()));
371 test_stream_->Close(); 376 test_stream_->Close();
372 message_loop_.RunAllPending(); 377 message_loop_.RunAllPending();
373 } 378 }
374 379
375 TEST_F(AlsaPcmOutputStreamTest, PcmSetParamsFailed) { 380 TEST_F(AlsaPcmOutputStreamTest, PcmSetParamsFailed) {
376 EXPECT_CALL(mock_alsa_wrapper_, PcmOpen(_, _, _, _)) 381 EXPECT_CALL(mock_alsa_wrapper_, PcmOpen(_, _, _, _))
377 .WillOnce(DoAll(SetArgumentPointee<0>(kFakeHandle), 382 .WillOnce(DoAll(SetArgumentPointee<0>(kFakeHandle),
378 Return(0))); 383 Return(0)));
379 EXPECT_CALL(mock_alsa_wrapper_, PcmSetParams(_, _, _, _, _, _, _)) 384 EXPECT_CALL(mock_alsa_wrapper_, PcmSetParams(_, _, _, _, _, _, _))
380 .WillOnce(Return(kTestFailedErrno)); 385 .WillOnce(Return(kTestFailedErrno));
(...skipping 11 matching lines...) Expand all
392 ASSERT_FALSE(test_stream_->stop_stream_); 397 ASSERT_FALSE(test_stream_->stop_stream_);
393 message_loop_.RunAllPending(); 398 message_loop_.RunAllPending();
394 399
395 // Ensure internal state is set for a no-op stream if PcmSetParams() failes. 400 // Ensure internal state is set for a no-op stream if PcmSetParams() failes.
396 EXPECT_EQ(AlsaPcmOutputStream::kIsOpened, test_stream_->state()); 401 EXPECT_EQ(AlsaPcmOutputStream::kIsOpened, test_stream_->state());
397 EXPECT_TRUE(test_stream_->stop_stream_); 402 EXPECT_TRUE(test_stream_->stop_stream_);
398 EXPECT_TRUE(test_stream_->playback_handle_ == NULL); 403 EXPECT_TRUE(test_stream_->playback_handle_ == NULL);
399 EXPECT_FALSE(test_stream_->buffer_.get()); 404 EXPECT_FALSE(test_stream_->buffer_.get());
400 405
401 // Close the stream since we opened it to make destruction happy. 406 // Close the stream since we opened it to make destruction happy.
402 EXPECT_CALL(mock_manager_, ReleaseOutputStream(test_stream_.get())); 407 EXPECT_CALL(mock_manager(), ReleaseOutputStream(test_stream_.get()));
403 test_stream_->Close(); 408 test_stream_->Close();
404 message_loop_.RunAllPending(); 409 message_loop_.RunAllPending();
405 } 410 }
406 411
407 TEST_F(AlsaPcmOutputStreamTest, StartStop) { 412 TEST_F(AlsaPcmOutputStreamTest, StartStop) {
408 // Open() call opens the playback device, sets the parameters, posts a task 413 // Open() call opens the playback device, sets the parameters, posts a task
409 // with the resulting configuration data, and transitions the object state to 414 // with the resulting configuration data, and transitions the object state to
410 // kIsOpened. 415 // kIsOpened.
411 EXPECT_CALL(mock_alsa_wrapper_, PcmOpen(_, _, _, _)) 416 EXPECT_CALL(mock_alsa_wrapper_, PcmOpen(_, _, _, _))
412 .WillOnce(DoAll(SetArgumentPointee<0>(kFakeHandle), 417 .WillOnce(DoAll(SetArgumentPointee<0>(kFakeHandle),
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 .Times(AtLeast(3)) 454 .Times(AtLeast(3))
450 .WillOnce(Return(kTestFramesPerPacket)) // Buffer is empty. 455 .WillOnce(Return(kTestFramesPerPacket)) // Buffer is empty.
451 .WillOnce(Return(kTestFramesPerPacket)) 456 .WillOnce(Return(kTestFramesPerPacket))
452 .WillRepeatedly(DoAll(InvokeWithoutArgs(&message_loop_, 457 .WillRepeatedly(DoAll(InvokeWithoutArgs(&message_loop_,
453 &MessageLoop::QuitNow), 458 &MessageLoop::QuitNow),
454 Return(0))); // Buffer is full. 459 Return(0))); // Buffer is full.
455 460
456 test_stream_->Start(&mock_callback); 461 test_stream_->Start(&mock_callback);
457 message_loop_.RunAllPending(); 462 message_loop_.RunAllPending();
458 463
459 EXPECT_CALL(mock_manager_, ReleaseOutputStream(test_stream_.get())); 464 EXPECT_CALL(mock_manager(), ReleaseOutputStream(test_stream_.get()));
460 EXPECT_CALL(mock_alsa_wrapper_, PcmClose(kFakeHandle)) 465 EXPECT_CALL(mock_alsa_wrapper_, PcmClose(kFakeHandle))
461 .WillOnce(Return(0)); 466 .WillOnce(Return(0));
462 EXPECT_CALL(mock_alsa_wrapper_, PcmName(kFakeHandle)) 467 EXPECT_CALL(mock_alsa_wrapper_, PcmName(kFakeHandle))
463 .WillOnce(Return(kTestDeviceName)); 468 .WillOnce(Return(kTestDeviceName));
464 test_stream_->Close(); 469 test_stream_->Close();
465 message_loop_.RunAllPending(); 470 message_loop_.RunAllPending();
466 } 471 }
467 472
468 TEST_F(AlsaPcmOutputStreamTest, WritePacket_FinishedPacket) { 473 TEST_F(AlsaPcmOutputStreamTest, WritePacket_FinishedPacket) {
469 InitBuffer(); 474 InitBuffer();
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 EXPECT_CALL(mock_alsa_wrapper_, DeviceNameGetHint(_, StrEq("IOID"))) 683 EXPECT_CALL(mock_alsa_wrapper_, DeviceNameGetHint(_, StrEq("IOID")))
679 .WillRepeatedly(Invoke(OutputHint)); 684 .WillRepeatedly(Invoke(OutputHint));
680 EXPECT_CALL(mock_alsa_wrapper_, DeviceNameGetHint(_, StrEq("NAME"))) 685 EXPECT_CALL(mock_alsa_wrapper_, DeviceNameGetHint(_, StrEq("NAME")))
681 .WillRepeatedly(Invoke(EchoHint)); 686 .WillRepeatedly(Invoke(EchoHint));
682 687
683 test_stream_.reset(CreateStream(kExpectedLayouts[i])); 688 test_stream_.reset(CreateStream(kExpectedLayouts[i]));
684 EXPECT_TRUE(test_stream_->AutoSelectDevice(i)); 689 EXPECT_TRUE(test_stream_->AutoSelectDevice(i));
685 EXPECT_EQ(kExpectedDownmix[i], test_stream_->should_downmix_); 690 EXPECT_EQ(kExpectedDownmix[i], test_stream_->should_downmix_);
686 691
687 Mock::VerifyAndClearExpectations(&mock_alsa_wrapper_); 692 Mock::VerifyAndClearExpectations(&mock_alsa_wrapper_);
688 Mock::VerifyAndClearExpectations(&mock_manager_); 693 Mock::VerifyAndClearExpectations(mock_manager_);
689 } 694 }
690 } 695 }
691 696
692 TEST_F(AlsaPcmOutputStreamTest, AutoSelectDevice_FallbackDevices) { 697 TEST_F(AlsaPcmOutputStreamTest, AutoSelectDevice_FallbackDevices) {
693 using std::string; 698 using std::string;
694 699
695 // If there are problems opening a multi-channel device, it the fallbacks 700 // If there are problems opening a multi-channel device, it the fallbacks
696 // operations should be as follows. Assume the multi-channel device name is 701 // operations should be as follows. Assume the multi-channel device name is
697 // surround50: 702 // surround50:
698 // 703 //
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 797
793 test_stream_->stop_stream_ = true; 798 test_stream_->stop_stream_ = true;
794 test_stream_->ScheduleNextWrite(true); 799 test_stream_->ScheduleNextWrite(true);
795 800
796 // TODO(ajwong): Find a way to test whether or not another task has been 801 // TODO(ajwong): Find a way to test whether or not another task has been
797 // posted so we can verify that the Alsa code will indeed break the task 802 // posted so we can verify that the Alsa code will indeed break the task
798 // posting loop. 803 // posting loop.
799 804
800 test_stream_->TransitionTo(AlsaPcmOutputStream::kIsClosed); 805 test_stream_->TransitionTo(AlsaPcmOutputStream::kIsClosed);
801 } 806 }
OLDNEW
« no previous file with comments | « media/audio/linux/alsa_input.cc ('k') | media/audio/linux/audio_manager_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698