summaryrefslogtreecommitdiffstats
path: root/media/libmediaplayerservice/nuplayer/GenericSource.cpp
diff options
context:
space:
mode:
authorPraveen Chavan <pchavan@codeaurora.org>2015-10-19 14:44:52 -0700
committerGerrit - the friendly Code Review server <code-review@localhost>2015-10-26 19:21:19 -0700
commitbbb9b1da50edbbed193b342be19b62e232254f27 (patch)
treee9b4a7ebbc032f037cfe0e842ef757bc71917d88 /media/libmediaplayerservice/nuplayer/GenericSource.cpp
parent04fdb627d164cc81c8fa2830db1b20cf1261aea4 (diff)
downloadframeworks_av-bbb9b1da50edbbed193b342be19b62e232254f27.zip
frameworks_av-bbb9b1da50edbbed193b342be19b62e232254f27.tar.gz
frameworks_av-bbb9b1da50edbbed193b342be19b62e232254f27.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
Diffstat (limited to 'media/libmediaplayerservice/nuplayer/GenericSource.cpp')
-rw-r--r--media/libmediaplayerservice/nuplayer/GenericSource.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/media/libmediaplayerservice/nuplayer/GenericSource.cpp b/media/libmediaplayerservice/nuplayer/GenericSource.cpp
index 6957a90..6406971 100644
--- a/media/libmediaplayerservice/nuplayer/GenericSource.cpp
+++ b/media/libmediaplayerservice/nuplayer/GenericSource.cpp
@@ -126,6 +126,7 @@ status_t NuPlayer::GenericSource::setDataSource(
status_t NuPlayer::GenericSource::setDataSource(const sp<DataSource>& source) {
resetDataSource();
+ Mutex::Autolock _l(mSourceLock);
mDataSource = source;
return OK;
}
@@ -372,6 +373,7 @@ void NuPlayer::GenericSource::onPrepareAsync() {
}
}
+ Mutex::Autolock _l(mSourceLock);
mDataSource = DataSource::CreateFromURI(
mHTTPService, uri, &mUriHeaders, &contentType,
static_cast<HTTPBase *>(mHttpSource.get()),
@@ -379,6 +381,7 @@ void NuPlayer::GenericSource::onPrepareAsync() {
} else {
mIsWidevine = false;
+ Mutex::Autolock _l(mSourceLock);
mDataSource = new FileSource(mFd, mOffset, mLength);
mFd = -1;
}
@@ -468,6 +471,7 @@ void NuPlayer::GenericSource::finishPrepareAsync() {
void NuPlayer::GenericSource::notifyPreparedAndCleanup(status_t err) {
if (err != OK) {
+ Mutex::Autolock _l(mSourceLock);
mDataSource.clear();
mCachedSource.clear();
mHttpSource.clear();
@@ -523,13 +527,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();
}
}