Finer-grained locking in AwesomePlayer, position and duration are now protected by a separate mutex that's only held for brief moments of time.
Change-Id: I989baf5a0ea8923985c560c2ec274abda0780242 related-to-bug: 2546577
This commit is contained in:
@@ -423,21 +423,23 @@ void AwesomePlayer::onBufferingUpdate() {
|
|||||||
}
|
}
|
||||||
mBufferingEventPending = false;
|
mBufferingEventPending = false;
|
||||||
|
|
||||||
if (mDurationUs >= 0) {
|
int64_t durationUs;
|
||||||
|
{
|
||||||
|
Mutex::Autolock autoLock(mMiscStateLock);
|
||||||
|
durationUs = mDurationUs;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (durationUs >= 0) {
|
||||||
int64_t cachedDurationUs = mPrefetcher->getCachedDurationUs();
|
int64_t cachedDurationUs = mPrefetcher->getCachedDurationUs();
|
||||||
|
|
||||||
LOGV("cache holds %.2f secs worth of data.", cachedDurationUs / 1E6);
|
LOGV("cache holds %.2f secs worth of data.", cachedDurationUs / 1E6);
|
||||||
|
|
||||||
int64_t positionUs = 0;
|
int64_t positionUs;
|
||||||
if (mVideoSource != NULL) {
|
getPosition(&positionUs);
|
||||||
positionUs = mVideoTimeUs;
|
|
||||||
} else if (mAudioPlayer != NULL) {
|
|
||||||
positionUs = mAudioPlayer->getMediaTimeUs();
|
|
||||||
}
|
|
||||||
|
|
||||||
cachedDurationUs += positionUs;
|
cachedDurationUs += positionUs;
|
||||||
|
|
||||||
double percentage = (double)cachedDurationUs / mDurationUs;
|
double percentage = (double)cachedDurationUs / durationUs;
|
||||||
notifyListener_l(MEDIA_BUFFERING_UPDATE, percentage * 100.0);
|
notifyListener_l(MEDIA_BUFFERING_UPDATE, percentage * 100.0);
|
||||||
|
|
||||||
postBufferingEvent_l();
|
postBufferingEvent_l();
|
||||||
@@ -653,7 +655,7 @@ status_t AwesomePlayer::setLooping(bool shouldLoop) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
status_t AwesomePlayer::getDuration(int64_t *durationUs) {
|
status_t AwesomePlayer::getDuration(int64_t *durationUs) {
|
||||||
Mutex::Autolock autoLock(mLock);
|
Mutex::Autolock autoLock(mMiscStateLock);
|
||||||
|
|
||||||
if (mDurationUs < 0) {
|
if (mDurationUs < 0) {
|
||||||
return UNKNOWN_ERROR;
|
return UNKNOWN_ERROR;
|
||||||
@@ -665,12 +667,8 @@ status_t AwesomePlayer::getDuration(int64_t *durationUs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
status_t AwesomePlayer::getPosition(int64_t *positionUs) {
|
status_t AwesomePlayer::getPosition(int64_t *positionUs) {
|
||||||
Mutex::Autolock autoLock(mLock);
|
|
||||||
return getPosition_l(positionUs);
|
|
||||||
}
|
|
||||||
|
|
||||||
status_t AwesomePlayer::getPosition_l(int64_t *positionUs) {
|
|
||||||
if (mVideoSource != NULL) {
|
if (mVideoSource != NULL) {
|
||||||
|
Mutex::Autolock autoLock(mMiscStateLock);
|
||||||
*positionUs = mVideoTimeUs;
|
*positionUs = mVideoTimeUs;
|
||||||
} else if (mAudioPlayer != NULL) {
|
} else if (mAudioPlayer != NULL) {
|
||||||
*positionUs = mAudioPlayer->getMediaTimeUs();
|
*positionUs = mAudioPlayer->getMediaTimeUs();
|
||||||
@@ -748,6 +746,7 @@ status_t AwesomePlayer::initAudioDecoder() {
|
|||||||
if (mAudioSource != NULL) {
|
if (mAudioSource != NULL) {
|
||||||
int64_t durationUs;
|
int64_t durationUs;
|
||||||
if (mAudioTrack->getFormat()->findInt64(kKeyDuration, &durationUs)) {
|
if (mAudioTrack->getFormat()->findInt64(kKeyDuration, &durationUs)) {
|
||||||
|
Mutex::Autolock autoLock(mMiscStateLock);
|
||||||
if (mDurationUs < 0 || durationUs > mDurationUs) {
|
if (mDurationUs < 0 || durationUs > mDurationUs) {
|
||||||
mDurationUs = durationUs;
|
mDurationUs = durationUs;
|
||||||
}
|
}
|
||||||
@@ -778,6 +777,7 @@ status_t AwesomePlayer::initVideoDecoder() {
|
|||||||
if (mVideoSource != NULL) {
|
if (mVideoSource != NULL) {
|
||||||
int64_t durationUs;
|
int64_t durationUs;
|
||||||
if (mVideoTrack->getFormat()->findInt64(kKeyDuration, &durationUs)) {
|
if (mVideoTrack->getFormat()->findInt64(kKeyDuration, &durationUs)) {
|
||||||
|
Mutex::Autolock autoLock(mMiscStateLock);
|
||||||
if (mDurationUs < 0 || durationUs > mDurationUs) {
|
if (mDurationUs < 0 || durationUs > mDurationUs) {
|
||||||
mDurationUs = durationUs;
|
mDurationUs = durationUs;
|
||||||
}
|
}
|
||||||
@@ -857,7 +857,10 @@ void AwesomePlayer::onVideoEvent() {
|
|||||||
int64_t timeUs;
|
int64_t timeUs;
|
||||||
CHECK(mVideoBuffer->meta_data()->findInt64(kKeyTime, &timeUs));
|
CHECK(mVideoBuffer->meta_data()->findInt64(kKeyTime, &timeUs));
|
||||||
|
|
||||||
mVideoTimeUs = timeUs;
|
{
|
||||||
|
Mutex::Autolock autoLock(mMiscStateLock);
|
||||||
|
mVideoTimeUs = timeUs;
|
||||||
|
}
|
||||||
|
|
||||||
if (mSeeking) {
|
if (mSeeking) {
|
||||||
if (mAudioPlayer != NULL) {
|
if (mAudioPlayer != NULL) {
|
||||||
@@ -1174,7 +1177,7 @@ void AwesomePlayer::onPrepareAsyncEvent() {
|
|||||||
prefetcher.clear();
|
prefetcher.clear();
|
||||||
|
|
||||||
if (result == OK) {
|
if (result == OK) {
|
||||||
LOGV("prefetcher is done preparing");
|
LOGI("prefetcher is done preparing");
|
||||||
} else {
|
} else {
|
||||||
Mutex::Autolock autoLock(mLock);
|
Mutex::Autolock autoLock(mLock);
|
||||||
|
|
||||||
@@ -1231,7 +1234,7 @@ status_t AwesomePlayer::suspend() {
|
|||||||
state->mFileSource = mFileSource;
|
state->mFileSource = mFileSource;
|
||||||
|
|
||||||
state->mFlags = mFlags & (PLAYING | LOOPING | AT_EOS);
|
state->mFlags = mFlags & (PLAYING | LOOPING | AT_EOS);
|
||||||
getPosition_l(&state->mPositionUs);
|
getPosition(&state->mPositionUs);
|
||||||
|
|
||||||
if (mLastVideoBuffer) {
|
if (mLastVideoBuffer) {
|
||||||
size_t size = mLastVideoBuffer->range_length();
|
size_t size = mLastVideoBuffer->range_length();
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
mutable Mutex mLock;
|
mutable Mutex mLock;
|
||||||
|
Mutex mMiscStateLock;
|
||||||
|
|
||||||
OMXClient mClient;
|
OMXClient mClient;
|
||||||
TimedEventQueue mQueue;
|
TimedEventQueue mQueue;
|
||||||
@@ -155,7 +156,6 @@ private:
|
|||||||
void postBufferingEvent_l();
|
void postBufferingEvent_l();
|
||||||
void postStreamDoneEvent_l(status_t status);
|
void postStreamDoneEvent_l(status_t status);
|
||||||
void postCheckAudioStatusEvent_l();
|
void postCheckAudioStatusEvent_l();
|
||||||
status_t getPosition_l(int64_t *positionUs);
|
|
||||||
status_t play_l();
|
status_t play_l();
|
||||||
|
|
||||||
MediaBuffer *mLastVideoBuffer;
|
MediaBuffer *mLastVideoBuffer;
|
||||||
|
|||||||
Reference in New Issue
Block a user