summaryrefslogtreecommitdiffstats
path: root/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'media/libmediaplayerservice/nuplayer/NuPlayer.cpp')
-rw-r--r--media/libmediaplayerservice/nuplayer/NuPlayer.cpp52
1 files changed, 39 insertions, 13 deletions
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
index d2caf65..ceedb40 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
+++ b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
@@ -157,6 +157,7 @@ NuPlayer::NuPlayer()
mCurrentOffloadInfo(AUDIO_INFO_INITIALIZER),
mAudioDecoderGeneration(0),
mVideoDecoderGeneration(0),
+ mRendererGeneration(0),
mAudioEOS(false),
mVideoEOS(false),
mScanSourcesPending(false),
@@ -637,10 +638,10 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
flags |= Renderer::FLAG_OFFLOAD_AUDIO;
}
- mRenderer = new Renderer(
- mAudioSink,
- new AMessage(kWhatRendererNotify, id()),
- flags);
+ sp<AMessage> notify = new AMessage(kWhatRendererNotify, id());
+ ++mRendererGeneration;
+ notify->setInt32("generation", mRendererGeneration);
+ mRenderer = new Renderer(mAudioSink, notify, flags);
mRendererLooper = new ALooper;
mRendererLooper->setName("NuPlayerRenderer");
@@ -817,11 +818,13 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
ALOGV("%s shutdown completed", audio ? "audio" : "video");
if (audio) {
mAudioDecoder.clear();
+ ++mAudioDecoderGeneration;
CHECK_EQ((int)mFlushingAudio, (int)SHUTTING_DOWN_DECODER);
mFlushingAudio = SHUT_DOWN;
} else {
mVideoDecoder.clear();
+ ++mVideoDecoderGeneration;
CHECK_EQ((int)mFlushingVideo, (int)SHUTTING_DOWN_DECODER);
mFlushingVideo = SHUT_DOWN;
@@ -839,9 +842,11 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
mRenderer->queueEOS(audio, err);
if (audio && mFlushingAudio != NONE) {
mAudioDecoder.clear();
+ ++mAudioDecoderGeneration;
mFlushingAudio = SHUT_DOWN;
} else if (!audio && mFlushingVideo != NONE){
mVideoDecoder.clear();
+ ++mVideoDecoderGeneration;
mFlushingVideo = SHUT_DOWN;
}
finishFlushIfPossible();
@@ -861,6 +866,14 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
case kWhatRendererNotify:
{
+ int32_t requesterGeneration = mRendererGeneration - 1;
+ CHECK(msg->findInt32("generation", &requesterGeneration));
+ if (requesterGeneration != mRendererGeneration) {
+ ALOGV("got message from old renderer, generation(%d:%d)",
+ requesterGeneration, mRendererGeneration);
+ return;
+ }
+
int32_t what;
CHECK(msg->findInt32("what", &what));
@@ -923,6 +936,7 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
CHECK(msg->findInt64("positionUs", &positionUs));
closeAudioSink();
mAudioDecoder.clear();
+ ++mAudioDecoderGeneration;
mRenderer->flush(true /* audio */);
if (mVideoDecoder != NULL) {
mRenderer->flush(false /* audio */);
@@ -978,17 +992,31 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
case kWhatPause:
{
- CHECK(mRenderer != NULL);
- mSource->pause();
- mRenderer->pause();
+ if (mSource != NULL) {
+ mSource->pause();
+ } else {
+ ALOGW("pause called when source is gone or not set");
+ }
+ if (mRenderer != NULL) {
+ mRenderer->pause();
+ } else {
+ ALOGW("pause called when renderer is gone or not set");
+ }
break;
}
case kWhatResume:
{
- CHECK(mRenderer != NULL);
- mSource->resume();
- mRenderer->resume();
+ if (mSource != NULL) {
+ mSource->resume();
+ } else {
+ ALOGW("resume called when source is gone or not set");
+ }
+ if (mRenderer != NULL) {
+ mRenderer->resume();
+ } else {
+ ALOGW("resume called when renderer is gone or not set");
+ }
break;
}
@@ -1860,9 +1888,6 @@ void NuPlayer::performReset() {
++mScanSourcesGeneration;
mScanSourcesPending = false;
- ++mAudioDecoderGeneration;
- ++mVideoDecoderGeneration;
-
if (mRendererLooper != NULL) {
if (mRenderer != NULL) {
mRendererLooper->unregisterHandler(mRenderer->id());
@@ -1871,6 +1896,7 @@ void NuPlayer::performReset() {
mRendererLooper.clear();
}
mRenderer.clear();
+ ++mRendererGeneration;
if (mSource != NULL) {
mSource->stop();