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
3 // found in the LICENSE file.
8 #include "base/basictypes.h"
9 #include "base/environment.h"
10 #include "base/files/file_util.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop/message_loop.h"
13 #include "base/path_service.h"
14 #include "base/test/test_timeouts.h"
15 #include "base/time/time.h"
16 #include "base/win/scoped_com_initializer.h"
17 #include "media/audio/audio_io.h"
18 #include "media/audio/audio_manager.h"
19 #include "media/audio/audio_manager_base.h"
20 #include "media/audio/audio_unittest_util.h"
21 #include "media/audio/mock_audio_source_callback.h"
22 #include "media/audio/win/audio_low_latency_output_win.h"
23 #include "media/audio/win/core_audio_util_win.h"
24 #include "media/base/decoder_buffer.h"
25 #include "media/base/seekable_buffer.h"
26 #include "media/base/test_data_util.h"
27 #include "testing/gmock/include/gmock/gmock.h"
28 #include "testing/gmock_mutant.h"
29 #include "testing/gtest/include/gtest/gtest.h"
32 using ::testing::AnyNumber
;
33 using ::testing::AtLeast
;
34 using ::testing::Between
;
35 using ::testing::CreateFunctor
;
36 using ::testing::DoAll
;
38 using ::testing::InvokeWithoutArgs
;
39 using ::testing::NotNull
;
40 using ::testing::Return
;
44 static const char kSpeechFile_16b_s_48k
[] = "speech_16b_stereo_48kHz.raw";
45 static const char kSpeechFile_16b_s_44k
[] = "speech_16b_stereo_44kHz.raw";
46 static const size_t kFileDurationMs
= 20000;
47 static const size_t kNumFileSegments
= 2;
48 static const int kBitsPerSample
= 16;
49 static const size_t kMaxDeltaSamples
= 1000;
50 static const char kDeltaTimeMsFileName
[] = "delta_times_ms.txt";
52 MATCHER_P(HasValidDelay
, value
, "") {
53 // It is difficult to come up with a perfect test condition for the delay
54 // estimation. For now, verify that the produced output delay is always
55 // larger than the selected buffer size.
59 // Used to terminate a loop from a different thread than the loop belongs to.
60 // |task_runner| should be a SingleThreadTaskRunner.
61 ACTION_P(QuitLoop
, task_runner
) {
62 task_runner
->PostTask(FROM_HERE
, base::MessageLoop::QuitClosure());
65 // This audio source implementation should be used for manual tests only since
66 // it takes about 20 seconds to play out a file.
67 class ReadFromFileAudioSource
: public AudioOutputStream::AudioSourceCallback
{
69 explicit ReadFromFileAudioSource(const std::string
& name
)
71 previous_call_time_(base::TimeTicks::Now()),
73 elements_to_write_(0) {
74 // Reads a test file from media/test/data directory.
75 file_
= ReadTestDataFile(name
);
77 // Creates an array that will store delta times between callbacks.
78 // The content of this array will be written to a text file at
79 // destruction and can then be used for off-line analysis of the exact
80 // timing of callbacks. The text file will be stored in media/test/data.
81 delta_times_
.reset(new int[kMaxDeltaSamples
]);
84 ~ReadFromFileAudioSource() override
{
85 // Get complete file path to output file in directory containing
86 // media_unittests.exe.
87 base::FilePath file_name
;
88 EXPECT_TRUE(PathService::Get(base::DIR_EXE
, &file_name
));
89 file_name
= file_name
.AppendASCII(kDeltaTimeMsFileName
);
91 EXPECT_TRUE(!text_file_
);
92 text_file_
= base::OpenFile(file_name
, "wt");
93 DLOG_IF(ERROR
, !text_file_
) << "Failed to open log file.";
95 // Write the array which contains delta times to a text file.
96 size_t elements_written
= 0;
97 while (elements_written
< elements_to_write_
) {
98 fprintf(text_file_
, "%d\n", delta_times_
[elements_written
]);
102 base::CloseFile(text_file_
);
105 // AudioOutputStream::AudioSourceCallback implementation.
106 int OnMoreData(AudioBus
* audio_bus
, uint32 total_bytes_delay
) override
{
107 // Store time difference between two successive callbacks in an array.
108 // These values will be written to a file in the destructor.
109 const base::TimeTicks now_time
= base::TimeTicks::Now();
110 const int diff
= (now_time
- previous_call_time_
).InMilliseconds();
111 previous_call_time_
= now_time
;
112 if (elements_to_write_
< kMaxDeltaSamples
) {
113 delta_times_
[elements_to_write_
] = diff
;
114 ++elements_to_write_
;
118 audio_bus
->frames() * audio_bus
->channels() * kBitsPerSample
/ 8;
120 // Use samples read from a data file and fill up the audio buffer
121 // provided to us in the callback.
122 if (pos_
+ static_cast<int>(max_size
) > file_size())
123 max_size
= file_size() - pos_
;
124 int frames
= max_size
/ (audio_bus
->channels() * kBitsPerSample
/ 8);
126 audio_bus
->FromInterleaved(
127 file_
->data() + pos_
, frames
, kBitsPerSample
/ 8);
133 void OnError(AudioOutputStream
* stream
) override
{}
135 int file_size() { return file_
->data_size(); }
138 scoped_refptr
<DecoderBuffer
> file_
;
139 scoped_ptr
<int[]> delta_times_
;
141 base::TimeTicks previous_call_time_
;
143 size_t elements_to_write_
;
146 static bool ExclusiveModeIsEnabled() {
147 return (WASAPIAudioOutputStream::GetShareMode() ==
148 AUDCLNT_SHAREMODE_EXCLUSIVE
);
151 static bool HasCoreAudioAndOutputDevices(AudioManager
* audio_man
) {
152 // The low-latency (WASAPI-based) version requires Windows Vista or higher.
153 // TODO(henrika): note that we use Wave today to query the number of
154 // existing output devices.
155 return CoreAudioUtil::IsSupported() && audio_man
->HasAudioOutputDevices();
158 // Convenience method which creates a default AudioOutputStream object but
159 // also allows the user to modify the default settings.
160 class AudioOutputStreamWrapper
{
162 explicit AudioOutputStreamWrapper(AudioManager
* audio_manager
)
163 : audio_man_(audio_manager
),
164 format_(AudioParameters::AUDIO_PCM_LOW_LATENCY
),
165 bits_per_sample_(kBitsPerSample
) {
166 AudioParameters preferred_params
;
167 EXPECT_TRUE(SUCCEEDED(CoreAudioUtil::GetPreferredAudioParameters(
168 AudioManagerBase::kDefaultDeviceId
, true, &preferred_params
)));
169 channel_layout_
= preferred_params
.channel_layout();
170 sample_rate_
= preferred_params
.sample_rate();
171 samples_per_packet_
= preferred_params
.frames_per_buffer();
174 ~AudioOutputStreamWrapper() {}
176 // Creates AudioOutputStream object using default parameters.
177 AudioOutputStream
* Create() {
178 return CreateOutputStream();
181 // Creates AudioOutputStream object using non-default parameters where the
182 // frame size is modified.
183 AudioOutputStream
* Create(int samples_per_packet
) {
184 samples_per_packet_
= samples_per_packet
;
185 return CreateOutputStream();
188 // Creates AudioOutputStream object using non-default parameters where the
189 // sample rate and frame size are modified.
190 AudioOutputStream
* Create(int sample_rate
, int samples_per_packet
) {
191 sample_rate_
= sample_rate
;
192 samples_per_packet_
= samples_per_packet
;
193 return CreateOutputStream();
196 AudioParameters::Format
format() const { return format_
; }
197 int channels() const { return ChannelLayoutToChannelCount(channel_layout_
); }
198 int bits_per_sample() const { return bits_per_sample_
; }
199 int sample_rate() const { return sample_rate_
; }
200 int samples_per_packet() const { return samples_per_packet_
; }
203 AudioOutputStream
* CreateOutputStream() {
204 AudioOutputStream
* aos
= audio_man_
->MakeAudioOutputStream(
205 AudioParameters(format_
, channel_layout_
, sample_rate_
,
206 bits_per_sample_
, samples_per_packet_
),
212 AudioManager
* audio_man_
;
213 AudioParameters::Format format_
;
214 ChannelLayout channel_layout_
;
215 int bits_per_sample_
;
217 int samples_per_packet_
;
220 // Convenience method which creates a default AudioOutputStream object.
221 static AudioOutputStream
* CreateDefaultAudioOutputStream(
222 AudioManager
* audio_manager
) {
223 AudioOutputStreamWrapper
aosw(audio_manager
);
224 AudioOutputStream
* aos
= aosw
.Create();
228 // Verify that we can retrieve the current hardware/mixing sample rate
229 // for the default audio device.
230 // TODO(henrika): modify this test when we support full device enumeration.
231 TEST(WASAPIAudioOutputStreamTest
, HardwareSampleRate
) {
232 // Skip this test in exclusive mode since the resulting rate is only utilized
233 // for shared mode streams.
234 if (ExclusiveModeIsEnabled())
236 scoped_ptr
<AudioManager
> audio_manager(AudioManager::CreateForTesting());
237 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager
.get()));
239 // Default device intended for games, system notification sounds,
240 // and voice commands.
241 int fs
= static_cast<int>(
242 WASAPIAudioOutputStream::HardwareSampleRate(std::string()));
246 // Test Create(), Close() calling sequence.
247 TEST(WASAPIAudioOutputStreamTest
, CreateAndClose
) {
248 scoped_ptr
<AudioManager
> audio_manager(AudioManager::CreateForTesting());
249 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager
.get()));
250 AudioOutputStream
* aos
= CreateDefaultAudioOutputStream(audio_manager
.get());
254 // Test Open(), Close() calling sequence.
255 TEST(WASAPIAudioOutputStreamTest
, OpenAndClose
) {
256 scoped_ptr
<AudioManager
> audio_manager(AudioManager::CreateForTesting());
257 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager
.get()));
258 AudioOutputStream
* aos
= CreateDefaultAudioOutputStream(audio_manager
.get());
259 EXPECT_TRUE(aos
->Open());
263 // Test Open(), Start(), Close() calling sequence.
264 TEST(WASAPIAudioOutputStreamTest
, OpenStartAndClose
) {
265 scoped_ptr
<AudioManager
> audio_manager(AudioManager::CreateForTesting());
266 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager
.get()));
267 AudioOutputStream
* aos
= CreateDefaultAudioOutputStream(audio_manager
.get());
268 EXPECT_TRUE(aos
->Open());
269 MockAudioSourceCallback source
;
270 EXPECT_CALL(source
, OnError(aos
))
276 // Test Open(), Start(), Stop(), Close() calling sequence.
277 TEST(WASAPIAudioOutputStreamTest
, OpenStartStopAndClose
) {
278 scoped_ptr
<AudioManager
> audio_manager(AudioManager::CreateForTesting());
279 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager
.get()));
280 AudioOutputStream
* aos
= CreateDefaultAudioOutputStream(audio_manager
.get());
281 EXPECT_TRUE(aos
->Open());
282 MockAudioSourceCallback source
;
283 EXPECT_CALL(source
, OnError(aos
))
290 // Test SetVolume(), GetVolume()
291 TEST(WASAPIAudioOutputStreamTest
, Volume
) {
292 scoped_ptr
<AudioManager
> audio_manager(AudioManager::CreateForTesting());
293 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager
.get()));
294 AudioOutputStream
* aos
= CreateDefaultAudioOutputStream(audio_manager
.get());
296 // Initial volume should be full volume (1.0).
298 aos
->GetVolume(&volume
);
299 EXPECT_EQ(1.0, volume
);
301 // Verify some valid volume settings.
303 aos
->GetVolume(&volume
);
304 EXPECT_EQ(0.0, volume
);
307 aos
->GetVolume(&volume
);
308 EXPECT_EQ(0.5, volume
);
311 aos
->GetVolume(&volume
);
312 EXPECT_EQ(1.0, volume
);
314 // Ensure that invalid volume setting have no effect.
316 aos
->GetVolume(&volume
);
317 EXPECT_EQ(1.0, volume
);
319 aos
->SetVolume(-0.5);
320 aos
->GetVolume(&volume
);
321 EXPECT_EQ(1.0, volume
);
326 // Test some additional calling sequences.
327 TEST(WASAPIAudioOutputStreamTest
, MiscCallingSequences
) {
328 scoped_ptr
<AudioManager
> audio_manager(AudioManager::CreateForTesting());
329 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager
.get()));
331 AudioOutputStream
* aos
= CreateDefaultAudioOutputStream(audio_manager
.get());
332 WASAPIAudioOutputStream
* waos
= static_cast<WASAPIAudioOutputStream
*>(aos
);
334 // Open(), Open() is a valid calling sequence (second call does nothing).
335 EXPECT_TRUE(aos
->Open());
336 EXPECT_TRUE(aos
->Open());
338 MockAudioSourceCallback source
;
340 // Start(), Start() is a valid calling sequence (second call does nothing).
342 EXPECT_TRUE(waos
->started());
344 EXPECT_TRUE(waos
->started());
346 // Stop(), Stop() is a valid calling sequence (second call does nothing).
348 EXPECT_FALSE(waos
->started());
350 EXPECT_FALSE(waos
->started());
352 // Start(), Stop(), Start(), Stop().
354 EXPECT_TRUE(waos
->started());
356 EXPECT_FALSE(waos
->started());
358 EXPECT_TRUE(waos
->started());
360 EXPECT_FALSE(waos
->started());
365 // Use preferred packet size and verify that rendering starts.
366 TEST(WASAPIAudioOutputStreamTest
, ValidPacketSize
) {
367 scoped_ptr
<AudioManager
> audio_manager(AudioManager::CreateForTesting());
368 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager
.get()));
370 base::MessageLoopForUI loop
;
371 MockAudioSourceCallback source
;
373 // Create default WASAPI output stream which plays out in stereo using
374 // the shared mixing rate. The default buffer size is 10ms.
375 AudioOutputStreamWrapper
aosw(audio_manager
.get());
376 AudioOutputStream
* aos
= aosw
.Create();
377 EXPECT_TRUE(aos
->Open());
379 // Derive the expected size in bytes of each packet.
380 uint32 bytes_per_packet
= aosw
.channels() * aosw
.samples_per_packet() *
381 (aosw
.bits_per_sample() / 8);
383 // Wait for the first callback and verify its parameters.
384 EXPECT_CALL(source
, OnMoreData(NotNull(), HasValidDelay(bytes_per_packet
)))
385 .WillOnce(DoAll(QuitLoop(loop
.task_runner()),
386 Return(aosw
.samples_per_packet())));
389 loop
.PostDelayedTask(FROM_HERE
, base::MessageLoop::QuitClosure(),
390 TestTimeouts::action_timeout());
396 // This test is intended for manual tests and should only be enabled
397 // when it is required to play out data from a local PCM file.
398 // By default, GTest will print out YOU HAVE 1 DISABLED TEST.
399 // To include disabled tests in test execution, just invoke the test program
400 // with --gtest_also_run_disabled_tests or set the GTEST_ALSO_RUN_DISABLED_TESTS
401 // environment variable to a value greater than 0.
402 // The test files are approximately 20 seconds long.
403 TEST(WASAPIAudioOutputStreamTest
, DISABLED_ReadFromStereoFile
) {
404 scoped_ptr
<AudioManager
> audio_manager(AudioManager::CreateForTesting());
405 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager
.get()));
407 AudioOutputStreamWrapper
aosw(audio_manager
.get());
408 AudioOutputStream
* aos
= aosw
.Create();
409 EXPECT_TRUE(aos
->Open());
411 std::string file_name
;
412 if (aosw
.sample_rate() == 48000) {
413 file_name
= kSpeechFile_16b_s_48k
;
414 } else if (aosw
.sample_rate() == 44100) {
415 file_name
= kSpeechFile_16b_s_44k
;
416 } else if (aosw
.sample_rate() == 96000) {
417 // Use 48kHz file at 96kHz as well. Will sound like Donald Duck.
418 file_name
= kSpeechFile_16b_s_48k
;
420 FAIL() << "This test supports 44.1, 48kHz and 96kHz only.";
423 ReadFromFileAudioSource
file_source(file_name
);
425 DVLOG(0) << "File name : " << file_name
.c_str();
426 DVLOG(0) << "Sample rate : " << aosw
.sample_rate();
427 DVLOG(0) << "Bits per sample: " << aosw
.bits_per_sample();
428 DVLOG(0) << "#channels : " << aosw
.channels();
429 DVLOG(0) << "File size : " << file_source
.file_size();
430 DVLOG(0) << "#file segments : " << kNumFileSegments
;
431 DVLOG(0) << ">> Listen to the stereo file while playing...";
433 for (int i
= 0; i
< kNumFileSegments
; i
++) {
434 // Each segment will start with a short (~20ms) block of zeros, hence
435 // some short glitches might be heard in this test if kNumFileSegments
436 // is larger than one. The exact length of the silence period depends on
437 // the selected sample rate.
438 aos
->Start(&file_source
);
439 base::PlatformThread::Sleep(
440 base::TimeDelta::FromMilliseconds(kFileDurationMs
/ kNumFileSegments
));
444 DVLOG(0) << ">> Stereo file playout has stopped.";
448 // Verify that we can open the output stream in exclusive mode using a
449 // certain set of audio parameters and a sample rate of 48kHz.
450 // The expected outcomes of each setting in this test has been derived
451 // manually using log outputs (--v=1).
452 // It's disabled by default because a flag is required to enable exclusive mode.
453 TEST(WASAPIAudioOutputStreamTest
, DISABLED_ExclusiveModeBufferSizesAt48kHz
) {
454 scoped_ptr
<AudioManager
> audio_manager(AudioManager::CreateForTesting());
455 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager
.get()) &&
456 ExclusiveModeIsEnabled());
458 AudioOutputStreamWrapper
aosw(audio_manager
.get());
460 // 10ms @ 48kHz shall work.
461 // Note that, this is the same size as we can use for shared-mode streaming
462 // but here the endpoint buffer delay is only 10ms instead of 20ms.
463 AudioOutputStream
* aos
= aosw
.Create(48000, 480);
464 EXPECT_TRUE(aos
->Open());
467 // 5ms @ 48kHz does not work due to misalignment.
468 // This test will propose an aligned buffer size of 5.3333ms.
469 // Note that we must call Close() even is Open() fails since Close() also
470 // deletes the object and we want to create a new object in the next test.
471 aos
= aosw
.Create(48000, 240);
472 EXPECT_FALSE(aos
->Open());
475 // 5.3333ms @ 48kHz should work (see test above).
476 aos
= aosw
.Create(48000, 256);
477 EXPECT_TRUE(aos
->Open());
480 // 2.6667ms is smaller than the minimum supported size (=3ms).
481 aos
= aosw
.Create(48000, 128);
482 EXPECT_FALSE(aos
->Open());
485 // 3ms does not correspond to an aligned buffer size.
486 // This test will propose an aligned buffer size of 3.3333ms.
487 aos
= aosw
.Create(48000, 144);
488 EXPECT_FALSE(aos
->Open());
491 // 3.3333ms @ 48kHz <=> smallest possible buffer size we can use.
492 aos
= aosw
.Create(48000, 160);
493 EXPECT_TRUE(aos
->Open());
497 // Verify that we can open the output stream in exclusive mode using a
498 // certain set of audio parameters and a sample rate of 44.1kHz.
499 // The expected outcomes of each setting in this test has been derived
500 // manually using log outputs (--v=1).
501 // It's disabled by default because a flag is required to enable exclusive mode.
502 TEST(WASAPIAudioOutputStreamTest
, DISABLED_ExclusiveModeBufferSizesAt44kHz
) {
503 scoped_ptr
<AudioManager
> audio_manager(AudioManager::CreateForTesting());
504 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager
.get()) &&
505 ExclusiveModeIsEnabled());
507 AudioOutputStreamWrapper
aosw(audio_manager
.get());
509 // 10ms @ 44.1kHz does not work due to misalignment.
510 // This test will propose an aligned buffer size of 10.1587ms.
511 AudioOutputStream
* aos
= aosw
.Create(44100, 441);
512 EXPECT_FALSE(aos
->Open());
515 // 10.1587ms @ 44.1kHz shall work (see test above).
516 aos
= aosw
.Create(44100, 448);
517 EXPECT_TRUE(aos
->Open());
520 // 5.8050ms @ 44.1 should work.
521 aos
= aosw
.Create(44100, 256);
522 EXPECT_TRUE(aos
->Open());
525 // 4.9887ms @ 44.1kHz does not work to misalignment.
526 // This test will propose an aligned buffer size of 5.0794ms.
527 // Note that we must call Close() even is Open() fails since Close() also
528 // deletes the object and we want to create a new object in the next test.
529 aos
= aosw
.Create(44100, 220);
530 EXPECT_FALSE(aos
->Open());
533 // 5.0794ms @ 44.1kHz shall work (see test above).
534 aos
= aosw
.Create(44100, 224);
535 EXPECT_TRUE(aos
->Open());
538 // 2.9025ms is smaller than the minimum supported size (=3ms).
539 aos
= aosw
.Create(44100, 132);
540 EXPECT_FALSE(aos
->Open());
543 // 3.01587ms is larger than the minimum size but is not aligned.
544 // This test will propose an aligned buffer size of 3.6281ms.
545 aos
= aosw
.Create(44100, 133);
546 EXPECT_FALSE(aos
->Open());
549 // 3.6281ms @ 44.1kHz <=> smallest possible buffer size we can use.
550 aos
= aosw
.Create(44100, 160);
551 EXPECT_TRUE(aos
->Open());
555 // Verify that we can open and start the output stream in exclusive mode at
556 // the lowest possible delay at 48kHz.
557 // It's disabled by default because a flag is required to enable exclusive mode.
558 TEST(WASAPIAudioOutputStreamTest
, DISABLED_ExclusiveModeMinBufferSizeAt48kHz
) {
559 scoped_ptr
<AudioManager
> audio_manager(AudioManager::CreateForTesting());
560 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager
.get()) &&
561 ExclusiveModeIsEnabled());
563 base::MessageLoopForUI loop
;
564 MockAudioSourceCallback source
;
566 // Create exclusive-mode WASAPI output stream which plays out in stereo
567 // using the minimum buffer size at 48kHz sample rate.
568 AudioOutputStreamWrapper
aosw(audio_manager
.get());
569 AudioOutputStream
* aos
= aosw
.Create(48000, 160);
570 EXPECT_TRUE(aos
->Open());
572 // Derive the expected size in bytes of each packet.
573 uint32 bytes_per_packet
= aosw
.channels() * aosw
.samples_per_packet() *
574 (aosw
.bits_per_sample() / 8);
576 // Wait for the first callback and verify its parameters.
577 EXPECT_CALL(source
, OnMoreData(NotNull(), HasValidDelay(bytes_per_packet
)))
578 .WillOnce(DoAll(QuitLoop(loop
.task_runner()),
579 Return(aosw
.samples_per_packet())))
580 .WillRepeatedly(Return(aosw
.samples_per_packet()));
583 loop
.PostDelayedTask(FROM_HERE
, base::MessageLoop::QuitClosure(),
584 TestTimeouts::action_timeout());
590 // Verify that we can open and start the output stream in exclusive mode at
591 // the lowest possible delay at 44.1kHz.
592 // It's disabled by default because a flag is required to enable exclusive mode.
593 TEST(WASAPIAudioOutputStreamTest
, DISABLED_ExclusiveModeMinBufferSizeAt44kHz
) {
594 ABORT_AUDIO_TEST_IF_NOT(ExclusiveModeIsEnabled());
595 scoped_ptr
<AudioManager
> audio_manager(AudioManager::CreateForTesting());
597 base::MessageLoopForUI loop
;
598 MockAudioSourceCallback source
;
600 // Create exclusive-mode WASAPI output stream which plays out in stereo
601 // using the minimum buffer size at 44.1kHz sample rate.
602 AudioOutputStreamWrapper
aosw(audio_manager
.get());
603 AudioOutputStream
* aos
= aosw
.Create(44100, 160);
604 EXPECT_TRUE(aos
->Open());
606 // Derive the expected size in bytes of each packet.
607 uint32 bytes_per_packet
= aosw
.channels() * aosw
.samples_per_packet() *
608 (aosw
.bits_per_sample() / 8);
610 // Wait for the first callback and verify its parameters.
611 EXPECT_CALL(source
, OnMoreData(NotNull(), HasValidDelay(bytes_per_packet
)))
612 .WillOnce(DoAll(QuitLoop(loop
.task_runner()),
613 Return(aosw
.samples_per_packet())))
614 .WillRepeatedly(Return(aosw
.samples_per_packet()));
617 loop
.PostDelayedTask(FROM_HERE
, base::MessageLoop::QuitClosure(),
618 TestTimeouts::action_timeout());