summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPraveen Chavan <pchavan@codeaurora.org>2015-10-19 14:44:52 -0700
committerSteve Kondik <steve@cyngn.com>2015-11-30 19:01:10 -0800
commit3745361e71a93f6f304c1392103f59b498cf5833 (patch)
tree611712044905dbee2051dc97cf4f7072e6452379
parentc263222162f8b1b31e8bd57de2f68894782b9fce (diff)
downloadframeworks_av-3745361e71a93f6f304c1392103f59b498cf5833.zip
frameworks_av-3745361e71a93f6f304c1392103f59b498cf5833.tar.gz
frameworks_av-3745361e71a93f6f304c1392103f59b498cf5833.tar.bz2
GenericSource: Synchronize access to dataSource
DataSource and HTTPSource can be accessed/modified by GenericSource's looper and Client's thread which can lead to race conditions when copying the sp<>. Add a Mutex lock to synchronize such accesses and avoid race conditions. CRs-Fixed: 906899 Change-Id: I2fb4b4a7079e638e151f4fe67a780007a4011652
-rw-r--r--media/libmediaplayerservice/nuplayer/GenericSource.cpp30
-rw-r--r--media/libmediaplayerservice/nuplayer/GenericSource.h1
2 files changed, 21 insertions, 10 deletions
diff --git a/media/libmediaplayerservice/nuplayer/GenericSource.cpp b/media/libmediaplayerservice/nuplayer/GenericSource.cpp
index 7c99f11..3485dd5 100644
--- a/media/libmediaplayerservice/nuplayer/GenericSource.cpp
+++ b/media/libmediaplayerservice/nuplayer/GenericSource.cpp
@@ -128,6 +128,7 @@ status_t NuPlayer::GenericSource::setDataSource(
status_t NuPlayer::GenericSource::setDataSource(const sp<DataSource>& source) {
resetDataSource();
+ Mutex::Autolock _l(mSourceLock);
mDataSource = source;
return OK;
}
@@ -387,6 +388,7 @@ void NuPlayer::GenericSource::onPrepareAsync() {
}
}
+ Mutex::Autolock _l(mSourceLock);
mDataSource = DataSource::CreateFromURI(
mHTTPService, uri, &mUriHeaders, &contentType,
static_cast<HTTPBase *>(mHttpSource.get()),
@@ -394,6 +396,7 @@ void NuPlayer::GenericSource::onPrepareAsync() {
} else {
mIsWidevine = false;
+ Mutex::Autolock _l(mSourceLock);
mDataSource = new FileSource(mFd, mOffset, mLength);
mFd = -1;
}
@@ -484,11 +487,10 @@ void NuPlayer::GenericSource::finishPrepareAsync() {
void NuPlayer::GenericSource::notifyPreparedAndCleanup(status_t err) {
if (err != OK) {
- {
- mDataSource.clear();
- mCachedSource.clear();
- mHttpSource.clear();
- }
+ Mutex::Autolock _l(mSourceLock);
+ mDataSource.clear();
+ mCachedSource.clear();
+ mHttpSource.clear();
mBitrate = -1;
cancelPollBuffering();
@@ -541,13 +543,21 @@ void NuPlayer::GenericSource::resume() {
}
void NuPlayer::GenericSource::disconnect() {
- if (mDataSource != NULL) {
+
+ sp<DataSource> dataSource;
+ sp<DataSource> httpSource;
+ {
+ Mutex::Autolock _l(mSourceLock);
+ dataSource = mDataSource;
+ httpSource = mHttpSource;
+ }
+ if (dataSource != NULL) {
// disconnect data source
- if (mDataSource->flags() & DataSource::kIsCachingDataSource) {
- static_cast<NuCachedSource2 *>(mDataSource.get())->disconnect();
+ if (dataSource->flags() & DataSource::kIsCachingDataSource) {
+ static_cast<NuCachedSource2 *>(dataSource.get())->disconnect();
}
- } else if (mHttpSource != NULL) {
- static_cast<HTTPBase *>(mHttpSource.get())->disconnect();
+ } else if (httpSource != NULL) {
+ static_cast<HTTPBase *>(httpSource.get())->disconnect();
}
}
diff --git a/media/libmediaplayerservice/nuplayer/GenericSource.h b/media/libmediaplayerservice/nuplayer/GenericSource.h
index ebc1fdc..c1d6e3e 100644
--- a/media/libmediaplayerservice/nuplayer/GenericSource.h
+++ b/media/libmediaplayerservice/nuplayer/GenericSource.h
@@ -137,6 +137,7 @@ protected:
int64_t mOffset;
int64_t mLength;
+ Mutex mSourceLock;
sp<DataSource> mDataSource;
sp<NuCachedSource2> mCachedSource;
sp<DataSource> mHttpSource;