}
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() {
break;
}
+ case kWhatPause:
+ {
+ CHECK(mRenderer != NULL);
+ mRenderer->pause();
+ break;
+ }
+
+ case kWhatResume:
+ {
+ CHECK(mRenderer != NULL);
+ mRenderer->resume();
+ break;
+ }
+
default:
TRESPASS();
break;
mFlushingVideo(false),
mHasAudio(mAudioSink != NULL),
mHasVideo(true),
- mSyncQueues(mHasAudio && mHasVideo) {
+ mSyncQueues(mHasAudio && mHasVideo),
+ mPaused(false) {
}
NuPlayer::Renderer::~Renderer() {
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:
break;
}
+ case kWhatPause:
+ {
+ onPause();
+ break;
+ }
+
+ case kWhatResume:
+ {
+ onResume();
+ break;
+ }
+
default:
TRESPASS();
break;
}
void NuPlayer::Renderer::postDrainAudioQueue() {
- if (mDrainAudioQueuePending || mSyncQueues) {
+ if (mDrainAudioQueuePending || mSyncQueues || mPaused) {
return;
}
}
void NuPlayer::Renderer::postDrainVideoQueue() {
- if (mDrainVideoQueuePending || mSyncQueues) {
+ if (mDrainVideoQueuePending || mSyncQueues || mPaused) {
return;
}
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
void signalAudioSinkChanged();
+ void pause();
+ void resume();
+
enum {
kWhatEOS,
kWhatFlushComplete,
kWhatQueueEOS,
kWhatFlush,
kWhatAudioSinkChanged,
+ kWhatPause,
+ kWhatResume,
};
struct QueueEntry {
bool mHasVideo;
bool mSyncQueues;
+ bool mPaused;
+
void onDrainAudioQueue();
void postDrainAudioQueue();
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);