From bbb9b1da50edbbed193b342be19b62e232254f27 Mon Sep 17 00:00:00 2001 From: Praveen Chavan Date: Mon, 19 Oct 2015 14:44:52 -0700 Subject: 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 --- .../nuplayer/GenericSource.cpp | 22 +++++++++++++++++----- .../libmediaplayerservice/nuplayer/GenericSource.h | 1 + 2 files changed, 18 insertions(+), 5 deletions(-) (limited to 'media/libmediaplayerservice') 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& 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(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; + sp httpSource; + { + Mutex::Autolock _l(mSourceLock); + dataSource = mDataSource; + httpSource = mHttpSource; + } + if (dataSource != NULL) { // disconnect data source - if (mDataSource->flags() & DataSource::kIsCachingDataSource) { - static_cast(mDataSource.get())->disconnect(); + if (dataSource->flags() & DataSource::kIsCachingDataSource) { + static_cast(dataSource.get())->disconnect(); } - } else if (mHttpSource != NULL) { - static_cast(mHttpSource.get())->disconnect(); + } else if (httpSource != NULL) { + static_cast(httpSource.get())->disconnect(); } } diff --git a/media/libmediaplayerservice/nuplayer/GenericSource.h b/media/libmediaplayerservice/nuplayer/GenericSource.h index 0181947..beaee9a 100644 --- a/media/libmediaplayerservice/nuplayer/GenericSource.h +++ b/media/libmediaplayerservice/nuplayer/GenericSource.h @@ -136,6 +136,7 @@ protected: int64_t mOffset; int64_t mLength; + Mutex mSourceLock; sp mDataSource; sp mCachedSource; sp mHttpSource; -- cgit v1.1