diff options
author | Andreas Huber <andih@google.com> | 2011-01-20 15:23:04 -0800 |
---|---|---|
committer | Andreas Huber <andih@google.com> | 2011-01-20 15:23:04 -0800 |
commit | 601fe0e5957d2ef82c51ca48f963d996ea2650bc (patch) | |
tree | 69156208d75bbae90b1a9142aab28932aedf55ed /media | |
parent | a7cb63a15319c5a4b59f67e66c93b5b9616475d4 (diff) | |
download | frameworks_base-601fe0e5957d2ef82c51ca48f963d996ea2650bc.zip frameworks_base-601fe0e5957d2ef82c51ca48f963d996ea2650bc.tar.gz frameworks_base-601fe0e5957d2ef82c51ca48f963d996ea2650bc.tar.bz2 |
Implement missing pause/resume support for NuPlayer.
Change-Id: Ia3f1ce521dd4b70e134ef03aa7c9db8e8d39a134
related-to-bug: 2368598
Diffstat (limited to 'media')
4 files changed, 85 insertions, 5 deletions
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp index 7f534c0..1fcf92b 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp +++ b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp @@ -92,11 +92,11 @@ void NuPlayer::start() { } void NuPlayer::pause() { - // XXX to be implemented + (new AMessage(kWhatPause, id()))->post(); } void NuPlayer::resume() { - // XXX to be implemented + (new AMessage(kWhatResume, id()))->post(); } void NuPlayer::resetAsync() { @@ -430,6 +430,20 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) { break; } + case kWhatPause: + { + CHECK(mRenderer != NULL); + mRenderer->pause(); + break; + } + + case kWhatResume: + { + CHECK(mRenderer != NULL); + mRenderer->resume(); + break; + } + default: TRESPASS(); break; diff --git a/media/libmediaplayerservice/nuplayer/NuPlayer.h b/media/libmediaplayerservice/nuplayer/NuPlayer.h index 339b628..bb65162 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayer.h +++ b/media/libmediaplayerservice/nuplayer/NuPlayer.h @@ -75,6 +75,8 @@ private: kWhatRendererNotify, kWhatReset, kWhatSeek, + kWhatPause, + kWhatResume, }; wp<NuPlayerDriver> mDriver; diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp index 5833697..93e5c14 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp +++ b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp @@ -42,7 +42,8 @@ NuPlayer::Renderer::Renderer( mFlushingVideo(false), mHasAudio(mAudioSink != NULL), mHasVideo(true), - mSyncQueues(mHasAudio && mHasVideo) { + mSyncQueues(mHasAudio && mHasVideo), + mPaused(false) { } NuPlayer::Renderer::~Renderer() { @@ -93,6 +94,14 @@ void NuPlayer::Renderer::signalTimeDiscontinuity() { mSyncQueues = mHasAudio && mHasVideo; } +void NuPlayer::Renderer::pause() { + (new AMessage(kWhatPause, id()))->post(); +} + +void NuPlayer::Renderer::resume() { + (new AMessage(kWhatResume, id()))->post(); +} + void NuPlayer::Renderer::onMessageReceived(const sp<AMessage> &msg) { switch (msg->what()) { case kWhatDrainAudioQueue: @@ -151,6 +160,18 @@ void NuPlayer::Renderer::onMessageReceived(const sp<AMessage> &msg) { break; } + case kWhatPause: + { + onPause(); + break; + } + + case kWhatResume: + { + onResume(); + break; + } + default: TRESPASS(); break; @@ -158,7 +179,7 @@ void NuPlayer::Renderer::onMessageReceived(const sp<AMessage> &msg) { } void NuPlayer::Renderer::postDrainAudioQueue() { - if (mDrainAudioQueuePending || mSyncQueues) { + if (mDrainAudioQueuePending || mSyncQueues || mPaused) { return; } @@ -254,7 +275,7 @@ void NuPlayer::Renderer::onDrainAudioQueue() { } void NuPlayer::Renderer::postDrainVideoQueue() { - if (mDrainVideoQueuePending || mSyncQueues) { + if (mDrainVideoQueuePending || mSyncQueues || mPaused) { return; } @@ -528,5 +549,39 @@ void NuPlayer::Renderer::notifyPosition() { notify->post(); } +void NuPlayer::Renderer::onPause() { + CHECK(!mPaused); + + mDrainAudioQueuePending = false; + ++mAudioQueueGeneration; + + mDrainVideoQueuePending = false; + ++mVideoQueueGeneration; + + if (mHasAudio) { + mAudioSink->pause(); + } + + mPaused = true; +} + +void NuPlayer::Renderer::onResume() { + CHECK(mPaused); + + if (mHasAudio) { + mAudioSink->start(); + } + + mPaused = false; + + if (!mAudioQueue.empty()) { + postDrainAudioQueue(); + } + + if (!mVideoQueue.empty()) { + postDrainVideoQueue(); + } +} + } // namespace android diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h index dbf3ecf..703e971 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h +++ b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h @@ -41,6 +41,9 @@ struct NuPlayer::Renderer : public AHandler { void signalAudioSinkChanged(); + void pause(); + void resume(); + enum { kWhatEOS, kWhatFlushComplete, @@ -60,6 +63,8 @@ private: kWhatQueueEOS, kWhatFlush, kWhatAudioSinkChanged, + kWhatPause, + kWhatResume, }; struct QueueEntry { @@ -91,6 +96,8 @@ private: bool mHasVideo; bool mSyncQueues; + bool mPaused; + void onDrainAudioQueue(); void postDrainAudioQueue(); @@ -101,6 +108,8 @@ private: void onQueueEOS(const sp<AMessage> &msg); void onFlush(const sp<AMessage> &msg); void onAudioSinkChanged(); + void onPause(); + void onResume(); void notifyEOS(bool audio); void notifyFlushComplete(bool audio); |