summaryrefslogtreecommitdiffstats
path: root/media/libmedia/mediaplayer.cpp
diff options
context:
space:
mode:
authorJason Sams <>2009-03-24 18:45:20 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-24 18:45:20 -0700
commit7dc112527d77b675d5c0451502b33fe2c552a79e (patch)
tree47fe626c09316b14f5faa3db3553d1b6330c2c67 /media/libmedia/mediaplayer.cpp
parent2c22aeb65e801f663a754d043062f85e49f77739 (diff)
downloadframeworks_av-7dc112527d77b675d5c0451502b33fe2c552a79e.zip
frameworks_av-7dc112527d77b675d5c0451502b33fe2c552a79e.tar.gz
frameworks_av-7dc112527d77b675d5c0451502b33fe2c552a79e.tar.bz2
Automated import from //branches/donutburger/...@140866,140866
Diffstat (limited to 'media/libmedia/mediaplayer.cpp')
-rw-r--r--media/libmedia/mediaplayer.cpp28
1 files changed, 23 insertions, 5 deletions
diff --git a/media/libmedia/mediaplayer.cpp b/media/libmedia/mediaplayer.cpp
index 6b40412..5841922 100644
--- a/media/libmedia/mediaplayer.cpp
+++ b/media/libmedia/mediaplayer.cpp
@@ -91,6 +91,7 @@ MediaPlayer::MediaPlayer()
mLoop = false;
mLeftVolume = mRightVolume = 1.0;
mVideoWidth = mVideoHeight = 0;
+ mLockThreadId = 0;
}
void MediaPlayer::onFirstRef()
@@ -223,16 +224,24 @@ status_t MediaPlayer::prepare()
{
LOGV("prepare");
Mutex::Autolock _l(mLock);
- if (mPrepareSync) return -EALREADY;
+ mLockThreadId = getThreadId();
+ if (mPrepareSync) {
+ mLockThreadId = 0;
+ return -EALREADY;
+ }
mPrepareSync = true;
status_t ret = prepareAsync_l();
- if (ret != NO_ERROR) return ret;
+ if (ret != NO_ERROR) {
+ mLockThreadId = 0;
+ return ret;
+ }
if (mPrepareSync) {
mSignal.wait(mLock); // wait for prepare done
mPrepareSync = false;
}
LOGV("prepare complete - status=%d", mPrepareStatus);
+ mLockThreadId = 0;
return mPrepareStatus;
}
@@ -485,14 +494,23 @@ void MediaPlayer::notify(int msg, int ext1, int ext2)
{
LOGV("message received msg=%d, ext1=%d, ext2=%d", msg, ext1, ext2);
bool send = true;
+ bool locked = false;
// TODO: In the future, we might be on the same thread if the app is
// running in the same process as the media server. In that case,
// this will deadlock.
- mLock.lock();
+ //
+ // The threadId hack below works around this for the care of prepare
+ // within the same process.
+
+ if (mLockThreadId != getThreadId()) {
+ mLock.lock();
+ locked = true;
+ }
+
if (mPlayer == 0) {
LOGV("notify(%d, %d, %d) callback on disconnected mediaplayer", msg, ext1, ext2);
- mLock.unlock(); // release the lock when done.
+ if (locked) mLock.unlock(); // release the lock when done.
return;
}
@@ -561,7 +579,7 @@ void MediaPlayer::notify(int msg, int ext1, int ext2)
}
sp<MediaPlayerListener> listener = mListener;
- mLock.unlock();
+ if (locked) mLock.unlock();
// this prevents re-entrant calls into client code
if ((listener != 0) && send) {