From 4a8b9a2363b7b7b4f98022e6d9aae8b8aa8e35e5 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Tue, 2 Oct 2012 12:49:33 -0700 Subject: Now back to 30fps, suspend updates if surface flinger didn't send us any new frames for one second or longer. Change-Id: I1c2ec349b0a4b7c4eb9dcdde483362ec87dd69fa related-to-bug: 7248248 --- .../wifi-display/source/RepeaterSource.cpp | 80 +++++++++++++++------- 1 file changed, 56 insertions(+), 24 deletions(-) (limited to 'media/libstagefright/wifi-display/source/RepeaterSource.cpp') diff --git a/media/libstagefright/wifi-display/source/RepeaterSource.cpp b/media/libstagefright/wifi-display/source/RepeaterSource.cpp index dc216e84..641e63fb 100644 --- a/media/libstagefright/wifi-display/source/RepeaterSource.cpp +++ b/media/libstagefright/wifi-display/source/RepeaterSource.cpp @@ -18,6 +18,7 @@ RepeaterSource::RepeaterSource(const sp &source, double rateHz) mRateHz(rateHz), mBuffer(NULL), mResult(OK), + mLastBufferUpdateUs(-1ll), mStartTimeUs(-1ll), mFrameCount(0) { } @@ -91,38 +92,59 @@ status_t RepeaterSource::read( ReadOptions::SeekMode seekMode; CHECK(options == NULL || !options->getSeekTo(&seekTimeUs, &seekMode)); - int64_t bufferTimeUs = -1ll; + for (;;) { + int64_t bufferTimeUs = -1ll; - if (mStartTimeUs < 0ll) { - Mutex::Autolock autoLock(mLock); - while (mBuffer == NULL && mResult == OK) { - mCondition.wait(mLock); - } + if (mStartTimeUs < 0ll) { + Mutex::Autolock autoLock(mLock); + while ((mLastBufferUpdateUs < 0ll || mBuffer == NULL) + && mResult == OK) { + mCondition.wait(mLock); + } - mStartTimeUs = ALooper::GetNowUs(); - bufferTimeUs = mStartTimeUs; - } else { - bufferTimeUs = mStartTimeUs + (mFrameCount * 1000000ll) / mRateHz; + ALOGV("now resuming."); + mStartTimeUs = ALooper::GetNowUs(); + bufferTimeUs = mStartTimeUs; + } else { + bufferTimeUs = mStartTimeUs + (mFrameCount * 1000000ll) / mRateHz; - int64_t nowUs = ALooper::GetNowUs(); - int64_t delayUs = bufferTimeUs - nowUs; + int64_t nowUs = ALooper::GetNowUs(); + int64_t delayUs = bufferTimeUs - nowUs; - if (delayUs > 0ll) { - usleep(delayUs); + if (delayUs > 0ll) { + usleep(delayUs); + } } - } - Mutex::Autolock autoLock(mLock); - if (mResult != OK) { - CHECK(mBuffer == NULL); - return mResult; - } + bool stale = false; - mBuffer->add_ref(); - *buffer = mBuffer; - (*buffer)->meta_data()->setInt64(kKeyTime, bufferTimeUs); + { + Mutex::Autolock autoLock(mLock); + if (mResult != OK) { + CHECK(mBuffer == NULL); + return mResult; + } - ++mFrameCount; + int64_t nowUs = ALooper::GetNowUs(); + if (nowUs - mLastBufferUpdateUs > 1000000ll) { + mLastBufferUpdateUs = -1ll; + stale = true; + } else { + mBuffer->add_ref(); + *buffer = mBuffer; + (*buffer)->meta_data()->setInt64(kKeyTime, bufferTimeUs); + ++mFrameCount; + } + } + + if (!stale) { + break; + } + + mStartTimeUs = -1ll; + mFrameCount = 0; + ALOGV("now dormant"); + } return OK; } @@ -147,6 +169,7 @@ void RepeaterSource::onMessageReceived(const sp &msg) { } mBuffer = buffer; mResult = err; + mLastBufferUpdateUs = ALooper::GetNowUs(); mCondition.broadcast(); @@ -161,4 +184,13 @@ void RepeaterSource::onMessageReceived(const sp &msg) { } } +void RepeaterSource::wakeUp() { + ALOGV("wakeUp"); + Mutex::Autolock autoLock(mLock); + if (mLastBufferUpdateUs < 0ll && mBuffer != NULL) { + mLastBufferUpdateUs = ALooper::GetNowUs(); + mCondition.broadcast(); + } +} + } // namespace android -- cgit v1.2.3