diff options
Diffstat (limited to 'media')
-rw-r--r-- | media/audio/audio_output_controller.cc | 10 | ||||
-rw-r--r-- | media/audio/audio_output_controller_unittest.cc | 78 |
2 files changed, 69 insertions, 19 deletions
diff --git a/media/audio/audio_output_controller.cc b/media/audio/audio_output_controller.cc index 11ee96c..74e2261 100644 --- a/media/audio/audio_output_controller.cc +++ b/media/audio/audio_output_controller.cc @@ -212,9 +212,7 @@ void AudioOutputController::DoPlay() { } // We start the AudioOutputStream lazily. - if (old_state == kCreated) { - stream_->Start(this); - } + stream_->Start(this); // Tell the event handler that we are now playing. handler_->OnPlaying(this); @@ -228,12 +226,16 @@ void AudioOutputController::DoPause() { return; // Sets the |state_| to kPaused so we don't draw more audio data. - // TODO(hclam): Actually pause the audio device. { AutoLock auto_lock(lock_); state_ = kPaused; } + // Then we stop the audio device. This is not the perfect solution because + // it discards all the internal buffer in the audio device. + // TODO(hclam): Actually pause the audio device. + stream_->Stop(); + handler_->OnPaused(this); } diff --git a/media/audio/audio_output_controller_unittest.cc b/media/audio/audio_output_controller_unittest.cc index 0783b09..7839ec1 100644 --- a/media/audio/audio_output_controller_unittest.cc +++ b/media/audio/audio_output_controller_unittest.cc @@ -88,10 +88,6 @@ TEST(AudioOutputControllerTest, CreateAndClose) { // Close the controller immediately. controller->Close(); - - // TODO(hclam): Make sure releasing the reference to this - // object actually destruct it. - controller = NULL; } TEST(AudioOutputControllerTest, PlayAndClose) { @@ -133,10 +129,6 @@ TEST(AudioOutputControllerTest, PlayAndClose) { // Now stop the controller. This should shutdown the internal // thread and we hold the only reference to it. controller->Close(); - - // TODO(hclam): Make sure releasing the reference to this - // object actually destruct it. - controller = NULL; } TEST(AudioOutputControllerTest, PlayPauseClose) { @@ -189,10 +181,70 @@ TEST(AudioOutputControllerTest, PlayPauseClose) { // Now stop the controller. This should shutdown the internal // thread and we hold the only reference to it. controller->Close(); +} + +TEST(AudioOutputControllerTest, PlayPausePlay) { + if (!HasAudioOutputDevices() || IsRunningHeadless()) + return; + + 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())) + .Times(Exactly(1)) + .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal)); + + // OnPlaying() will be called only once. + EXPECT_CALL(event_handler, OnPlaying(NotNull())) + .Times(Exactly(1)) + .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)); + + // And then OnPaused() will be called. + EXPECT_CALL(event_handler, OnPaused(NotNull())) + .Times(Exactly(1)) + .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal)); + + // OnPlaying() will be called only once. + EXPECT_CALL(event_handler, OnPlaying(NotNull())) + .Times(Exactly(1)) + .RetiresOnSaturation(); + + scoped_refptr<AudioOutputController> controller = + AudioOutputController::Create(&event_handler, + AudioManager::AUDIO_PCM_LINEAR, kChannels, + kSampleRate, kBitsPerSample, + kHardwareBufferSize, kBufferCapacity); + ASSERT_TRUE(controller.get()); + + // 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(); + + // And then wait for pause to complete. + controller->Pause(); + event.Wait(); + event.Reset(); - // TODO(hclam): Make sure releasing the reference to this - // object actually destruct it. - controller = NULL; + // Then we play again. + // Play and then wait for the event to be signaled. + controller->Play(); + event.Wait(); + + // Now stop the controller. This should shutdown the internal + // thread and we hold the only reference to it. + controller->Close(); } TEST(AudioOutputControllerTest, HardwareBufferTooLarge) { @@ -228,10 +280,6 @@ TEST(AudioOutputControllerTest, CloseTwice) { // Close the controller immediately. controller->Close(); controller->Close(); - - // TODO(hclam): Make sure releasing the reference to this - // object actually destruct it. - controller = NULL; } } // namespace media |