| OLD | NEW |
| 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 <windows.h> | 5 #include <windows.h> |
| 6 #include <mmsystem.h> | 6 #include <mmsystem.h> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/environment.h" | 9 #include "base/environment.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 static const char kDeltaTimeMsFileName[] = "delta_times_ms.txt"; | 49 static const char kDeltaTimeMsFileName[] = "delta_times_ms.txt"; |
| 50 | 50 |
| 51 MATCHER_P(HasValidDelay, value, "") { | 51 MATCHER_P(HasValidDelay, value, "") { |
| 52 // It is difficult to come up with a perfect test condition for the delay | 52 // It is difficult to come up with a perfect test condition for the delay |
| 53 // estimation. For now, verify that the produced output delay is always | 53 // estimation. For now, verify that the produced output delay is always |
| 54 // larger than the selected buffer size. | 54 // larger than the selected buffer size. |
| 55 return arg >= value; | 55 return arg >= value; |
| 56 } | 56 } |
| 57 | 57 |
| 58 // Used to terminate a loop from a different thread than the loop belongs to. | 58 // Used to terminate a loop from a different thread than the loop belongs to. |
| 59 // |loop| should be a MessageLoopProxy. | 59 // |task_runner| should be a SingleThreadTaskRunner. |
| 60 ACTION_P(QuitLoop, loop) { | 60 ACTION_P(QuitLoop, task_runner) { |
| 61 loop->PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); | 61 task_runner->PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); |
| 62 } | 62 } |
| 63 | 63 |
| 64 // This audio source implementation should be used for manual tests only since | 64 // This audio source implementation should be used for manual tests only since |
| 65 // it takes about 20 seconds to play out a file. | 65 // it takes about 20 seconds to play out a file. |
| 66 class ReadFromFileAudioSource : public AudioOutputStream::AudioSourceCallback { | 66 class ReadFromFileAudioSource : public AudioOutputStream::AudioSourceCallback { |
| 67 public: | 67 public: |
| 68 explicit ReadFromFileAudioSource(const std::string& name) | 68 explicit ReadFromFileAudioSource(const std::string& name) |
| 69 : pos_(0), | 69 : pos_(0), |
| 70 previous_call_time_(base::TimeTicks::Now()), | 70 previous_call_time_(base::TimeTicks::Now()), |
| 71 text_file_(NULL), | 71 text_file_(NULL), |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 AudioOutputStreamWrapper aosw(audio_manager.get()); | 374 AudioOutputStreamWrapper aosw(audio_manager.get()); |
| 375 AudioOutputStream* aos = aosw.Create(); | 375 AudioOutputStream* aos = aosw.Create(); |
| 376 EXPECT_TRUE(aos->Open()); | 376 EXPECT_TRUE(aos->Open()); |
| 377 | 377 |
| 378 // Derive the expected size in bytes of each packet. | 378 // Derive the expected size in bytes of each packet. |
| 379 uint32 bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * | 379 uint32 bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * |
| 380 (aosw.bits_per_sample() / 8); | 380 (aosw.bits_per_sample() / 8); |
| 381 | 381 |
| 382 // Wait for the first callback and verify its parameters. | 382 // Wait for the first callback and verify its parameters. |
| 383 EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(bytes_per_packet))) | 383 EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(bytes_per_packet))) |
| 384 .WillOnce(DoAll( | 384 .WillOnce(DoAll(QuitLoop(loop.task_runner()), |
| 385 QuitLoop(loop.message_loop_proxy()), | 385 Return(aosw.samples_per_packet()))); |
| 386 Return(aosw.samples_per_packet()))); | |
| 387 | 386 |
| 388 aos->Start(&source); | 387 aos->Start(&source); |
| 389 loop.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitClosure(), | 388 loop.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitClosure(), |
| 390 TestTimeouts::action_timeout()); | 389 TestTimeouts::action_timeout()); |
| 391 loop.Run(); | 390 loop.Run(); |
| 392 aos->Stop(); | 391 aos->Stop(); |
| 393 aos->Close(); | 392 aos->Close(); |
| 394 } | 393 } |
| 395 | 394 |
| 396 // This test is intended for manual tests and should only be enabled | 395 // This test is intended for manual tests and should only be enabled |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 AudioOutputStreamWrapper aosw(audio_manager.get()); | 567 AudioOutputStreamWrapper aosw(audio_manager.get()); |
| 569 AudioOutputStream* aos = aosw.Create(48000, 160); | 568 AudioOutputStream* aos = aosw.Create(48000, 160); |
| 570 EXPECT_TRUE(aos->Open()); | 569 EXPECT_TRUE(aos->Open()); |
| 571 | 570 |
| 572 // Derive the expected size in bytes of each packet. | 571 // Derive the expected size in bytes of each packet. |
| 573 uint32 bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * | 572 uint32 bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * |
| 574 (aosw.bits_per_sample() / 8); | 573 (aosw.bits_per_sample() / 8); |
| 575 | 574 |
| 576 // Wait for the first callback and verify its parameters. | 575 // Wait for the first callback and verify its parameters. |
| 577 EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(bytes_per_packet))) | 576 EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(bytes_per_packet))) |
| 578 .WillOnce(DoAll( | 577 .WillOnce(DoAll(QuitLoop(loop.task_runner()), |
| 579 QuitLoop(loop.message_loop_proxy()), | 578 Return(aosw.samples_per_packet()))) |
| 580 Return(aosw.samples_per_packet()))) | |
| 581 .WillRepeatedly(Return(aosw.samples_per_packet())); | 579 .WillRepeatedly(Return(aosw.samples_per_packet())); |
| 582 | 580 |
| 583 aos->Start(&source); | 581 aos->Start(&source); |
| 584 loop.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitClosure(), | 582 loop.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitClosure(), |
| 585 TestTimeouts::action_timeout()); | 583 TestTimeouts::action_timeout()); |
| 586 loop.Run(); | 584 loop.Run(); |
| 587 aos->Stop(); | 585 aos->Stop(); |
| 588 aos->Close(); | 586 aos->Close(); |
| 589 } | 587 } |
| 590 | 588 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 603 AudioOutputStreamWrapper aosw(audio_manager.get()); | 601 AudioOutputStreamWrapper aosw(audio_manager.get()); |
| 604 AudioOutputStream* aos = aosw.Create(44100, 160); | 602 AudioOutputStream* aos = aosw.Create(44100, 160); |
| 605 EXPECT_TRUE(aos->Open()); | 603 EXPECT_TRUE(aos->Open()); |
| 606 | 604 |
| 607 // Derive the expected size in bytes of each packet. | 605 // Derive the expected size in bytes of each packet. |
| 608 uint32 bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * | 606 uint32 bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * |
| 609 (aosw.bits_per_sample() / 8); | 607 (aosw.bits_per_sample() / 8); |
| 610 | 608 |
| 611 // Wait for the first callback and verify its parameters. | 609 // Wait for the first callback and verify its parameters. |
| 612 EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(bytes_per_packet))) | 610 EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(bytes_per_packet))) |
| 613 .WillOnce(DoAll( | 611 .WillOnce(DoAll(QuitLoop(loop.task_runner()), |
| 614 QuitLoop(loop.message_loop_proxy()), | 612 Return(aosw.samples_per_packet()))) |
| 615 Return(aosw.samples_per_packet()))) | 613 .WillRepeatedly(Return(aosw.samples_per_packet())); |
| 616 .WillRepeatedly(Return(aosw.samples_per_packet())); | |
| 617 | 614 |
| 618 aos->Start(&source); | 615 aos->Start(&source); |
| 619 loop.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitClosure(), | 616 loop.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitClosure(), |
| 620 TestTimeouts::action_timeout()); | 617 TestTimeouts::action_timeout()); |
| 621 loop.Run(); | 618 loop.Run(); |
| 622 aos->Stop(); | 619 aos->Stop(); |
| 623 aos->Close(); | 620 aos->Close(); |
| 624 } | 621 } |
| 625 | 622 |
| 626 } // namespace media | 623 } // namespace media |
| OLD | NEW |