summaryrefslogtreecommitdiffstats
path: root/media/audio/audio_output_controller_unittest.cc
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-29 01:21:27 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-29 01:21:27 +0000
commit5c86ecf8936269cdc5f00f57b7531cdac7b3e706 (patch)
tree79392d0c2e959af863e2b6d4626a79d039b178ab /media/audio/audio_output_controller_unittest.cc
parente10eacda58687b9363919a9203181322b649946c (diff)
downloadchromium_src-5c86ecf8936269cdc5f00f57b7531cdac7b3e706.zip
chromium_src-5c86ecf8936269cdc5f00f57b7531cdac7b3e706.tar.gz
chromium_src-5c86ecf8936269cdc5f00f57b7531cdac7b3e706.tar.bz2
Add AudioBuffersState struct. Use it for audio synchronization.
The new AudioBuffersState contains current state of the audio buffers. This object is passed all the way from the device to the audio renderer. Audio renderer uses this information to synchronize audio. BUG=52196,49110 TEST=see repro steps for 51637 and 52196. Review URL: http://codereview.chromium.org/3444017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60891 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio/audio_output_controller_unittest.cc')
-rw-r--r--media/audio/audio_output_controller_unittest.cc88
1 files changed, 51 insertions, 37 deletions
diff --git a/media/audio/audio_output_controller_unittest.cc b/media/audio/audio_output_controller_unittest.cc
index b479974d..6997016 100644
--- a/media/audio/audio_output_controller_unittest.cc
+++ b/media/audio/audio_output_controller_unittest.cc
@@ -37,9 +37,8 @@ class MockAudioOutputControllerEventHandler
MOCK_METHOD1(OnPaused, void(AudioOutputController* controller));
MOCK_METHOD2(OnError, void(AudioOutputController* controller,
int error_code));
- MOCK_METHOD3(OnMoreData,
- void(AudioOutputController* controller,
- base::Time timestamp, uint32 pending_bytes));
+ MOCK_METHOD2(OnMoreData, void(AudioOutputController* controller,
+ AudioBuffersState buffers_state));
private:
DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerEventHandler);
@@ -75,12 +74,6 @@ ACTION_P(SignalEvent, event) {
event->Signal();
}
-ACTION_P3(SignalEvent, event, count, limit) {
- if (++*count >= limit) {
- event->Signal();
- }
-}
-
// Helper functions used to close audio controller.
static void SignalClosedEvent(base::WaitableEvent* event) {
event->Signal();
@@ -98,6 +91,11 @@ TEST(AudioOutputControllerTest, CreateAndClose) {
return;
MockAudioOutputControllerEventHandler event_handler;
+
+ EXPECT_CALL(event_handler, OnCreated(NotNull()))
+ .Times(1);
+ EXPECT_CALL(event_handler, OnMoreData(NotNull(), _));
+
AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannels,
kSampleRate, kBitsPerSample);
scoped_refptr<AudioOutputController> controller =
@@ -115,7 +113,6 @@ TEST(AudioOutputControllerTest, PlayAndClose) {
MockAudioOutputControllerEventHandler event_handler;
base::WaitableEvent event(false, false);
- int count = 0;
// If OnCreated is called then signal the event.
EXPECT_CALL(event_handler, OnCreated(NotNull()))
@@ -126,9 +123,9 @@ TEST(AudioOutputControllerTest, PlayAndClose) {
.Times(Exactly(1));
// If OnMoreData is called enough then signal the event.
- EXPECT_CALL(event_handler, OnMoreData(NotNull(), _, 0))
+ EXPECT_CALL(event_handler, OnMoreData(NotNull(), _))
.Times(AtLeast(10))
- .WillRepeatedly(SignalEvent(&event, &count, 10));
+ .WillRepeatedly(SignalEvent(&event));
AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannels,
kSampleRate, kBitsPerSample);
@@ -140,9 +137,14 @@ TEST(AudioOutputControllerTest, PlayAndClose) {
// Wait for OnCreated() to be called.
event.Wait();
- // Play and then wait for the event to be signaled.
controller->Play();
- event.Wait();
+
+ // Wait until the date is requested at least 10 times.
+ for (int i = 0; i < 10; i++) {
+ event.Wait();
+ uint8 buf[1];
+ controller->EnqueueData(buf, 0);
+ }
// Now stop the controller.
CloseAudioController(controller);
@@ -154,7 +156,7 @@ TEST(AudioOutputControllerTest, PlayPauseClose) {
MockAudioOutputControllerEventHandler event_handler;
base::WaitableEvent event(false, false);
- int count = 0;
+ base::WaitableEvent pause_event(false, false);
// If OnCreated is called then signal the event.
EXPECT_CALL(event_handler, OnCreated(NotNull()))
@@ -166,14 +168,14 @@ TEST(AudioOutputControllerTest, PlayPauseClose) {
.Times(Exactly(1));
// If OnMoreData is called enough then signal the event.
- EXPECT_CALL(event_handler, OnMoreData(NotNull(), _, 0))
+ EXPECT_CALL(event_handler, OnMoreData(NotNull(), _))
.Times(AtLeast(10))
- .WillRepeatedly(SignalEvent(&event, &count, 10));
+ .WillRepeatedly(SignalEvent(&event));
// And then OnPaused() will be called.
EXPECT_CALL(event_handler, OnPaused(NotNull()))
.Times(Exactly(1))
- .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal));
+ .WillOnce(InvokeWithoutArgs(&pause_event, &base::WaitableEvent::Signal));
AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannels,
kSampleRate, kBitsPerSample);
@@ -184,16 +186,20 @@ TEST(AudioOutputControllerTest, PlayPauseClose) {
// Wait for OnCreated() to be called.
event.Wait();
- event.Reset();
- // Play and then wait for the event to be signaled.
controller->Play();
- event.Wait();
- event.Reset();
+
+ // Wait until the date is requested at least 10 times.
+ for (int i = 0; i < 10; i++) {
+ event.Wait();
+ uint8 buf[1];
+ controller->EnqueueData(buf, 0);
+ }
// And then wait for pause to complete.
+ ASSERT_FALSE(pause_event.IsSignaled());
controller->Pause();
- event.Wait();
+ pause_event.Wait();
// Now stop the controller.
CloseAudioController(controller);
@@ -205,7 +211,7 @@ TEST(AudioOutputControllerTest, PlayPausePlay) {
MockAudioOutputControllerEventHandler event_handler;
base::WaitableEvent event(false, false);
- int count = 0;
+ base::WaitableEvent pause_event(false, false);
// If OnCreated is called then signal the event.
EXPECT_CALL(event_handler, OnCreated(NotNull()))
@@ -218,14 +224,14 @@ TEST(AudioOutputControllerTest, PlayPausePlay) {
.RetiresOnSaturation();
// If OnMoreData() is called enough then signal the event.
- EXPECT_CALL(event_handler, OnMoreData(NotNull(), _, 0))
- .Times(AtLeast(10))
- .WillRepeatedly(SignalEvent(&event, &count, 10));
+ EXPECT_CALL(event_handler, OnMoreData(NotNull(), _))
+ .Times(AtLeast(1))
+ .WillRepeatedly(SignalEvent(&event));
// And then OnPaused() will be called.
EXPECT_CALL(event_handler, OnPaused(NotNull()))
.Times(Exactly(1))
- .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal));
+ .WillOnce(InvokeWithoutArgs(&pause_event, &base::WaitableEvent::Signal));
// OnPlaying() will be called only once.
EXPECT_CALL(event_handler, OnPlaying(NotNull()))
@@ -241,22 +247,30 @@ TEST(AudioOutputControllerTest, PlayPausePlay) {
// Wait for OnCreated() to be called.
event.Wait();
- event.Reset();
- // Play and then wait for the event to be signaled.
controller->Play();
- event.Wait();
- event.Reset();
+
+ // Wait until the date is requested at least 10 times.
+ for (int i = 0; i < 10; i++) {
+ event.Wait();
+ uint8 buf[1];
+ controller->EnqueueData(buf, 0);
+ }
// And then wait for pause to complete.
+ ASSERT_FALSE(pause_event.IsSignaled());
controller->Pause();
- event.Wait();
- event.Reset();
+ pause_event.Wait();
// Then we play again.
- // Play and then wait for the event to be signaled.
controller->Play();
- event.Wait();
+
+ // Wait until the date is requested at least 10 times.
+ for (int i = 0; i < 10; i++) {
+ event.Wait();
+ uint8 buf[1];
+ controller->EnqueueData(buf, 0);
+ }
// Now stop the controller.
CloseAudioController(controller);
@@ -292,7 +306,7 @@ TEST(AudioOutputControllerTest, CloseTwice) {
.WillOnce(SignalEvent(&event));
// One OnMoreData() is expected.
- EXPECT_CALL(event_handler, OnMoreData(NotNull(), _, 0))
+ EXPECT_CALL(event_handler, OnMoreData(NotNull(), _))
.Times(AtLeast(1))
.WillRepeatedly(SignalEvent(&event));