NuPlayer: guard mSource when it's accessed on external looper.
Bug: 25121900
Change-Id: Ibc0a114acef91269c83d9494818bdb30589dcfc9
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
index 42a82ac..7b000fa 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
+++ b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
@@ -400,14 +400,20 @@
}
void NuPlayer::resetAsync() {
- if (mSource != NULL) {
+ sp<Source> source;
+ {
+ Mutex::Autolock autoLock(mSourceLock);
+ source = mSource;
+ }
+
+ if (source != NULL) {
// During a reset, the data source might be unresponsive already, we need to
// disconnect explicitly so that reads exit promptly.
// We can't queue the disconnect request to the looper, as it might be
// queued behind a stuck read and never gets processed.
// Doing a disconnect outside the looper to allows the pending reads to exit
// (either successfully or with error).
- mSource->disconnect();
+ source->disconnect();
}
(new AMessage(kWhatReset, this))->post();
@@ -484,6 +490,7 @@
sp<RefBase> obj;
CHECK(msg->findObject("source", &obj));
if (obj != NULL) {
+ Mutex::Autolock autoLock(mSourceLock);
mSource = static_cast<Source *>(obj.get());
} else {
err = UNKNOWN_ERROR;
@@ -1998,6 +2005,7 @@
if (mSource != NULL) {
mSource->stop();
+ Mutex::Autolock autoLock(mSourceLock);
mSource.clear();
}
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayer.h b/media/libmediaplayerservice/nuplayer/NuPlayer.h
index 369590b..f6eb49e 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayer.h
+++ b/media/libmediaplayerservice/nuplayer/NuPlayer.h
@@ -140,6 +140,7 @@
bool mUIDValid;
uid_t mUID;
pid_t mPID;
+ Mutex mSourceLock; // guard |mSource|.
sp<Source> mSource;
uint32_t mSourceFlags;
sp<Surface> mSurface;