summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/wifi-display/source/RepeaterSource.cpp
diff options
context:
space:
mode:
authorAndreas Huber <andih@google.com>2012-10-02 12:49:33 -0700
committerAndreas Huber <andih@google.com>2012-10-02 12:51:30 -0700
commit4a8b9a2363b7b7b4f98022e6d9aae8b8aa8e35e5 (patch)
tree30d13eb0bf3a8d013e5c867d2c1c70b9736c4194 /media/libstagefright/wifi-display/source/RepeaterSource.cpp
parent887070dbe6b6258ba04f988fd90c3ac856d2e5bf (diff)
downloadframeworks_av-4a8b9a2363b7b7b4f98022e6d9aae8b8aa8e35e5.zip
frameworks_av-4a8b9a2363b7b7b4f98022e6d9aae8b8aa8e35e5.tar.gz
frameworks_av-4a8b9a2363b7b7b4f98022e6d9aae8b8aa8e35e5.tar.bz2
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
Diffstat (limited to 'media/libstagefright/wifi-display/source/RepeaterSource.cpp')
-rw-r--r--media/libstagefright/wifi-display/source/RepeaterSource.cpp80
1 files changed, 56 insertions, 24 deletions
diff --git a/media/libstagefright/wifi-display/source/RepeaterSource.cpp b/media/libstagefright/wifi-display/source/RepeaterSource.cpp
index dc216e8..641e63f 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<MediaSource> &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<AMessage> &msg) {
}
mBuffer = buffer;
mResult = err;
+ mLastBufferUpdateUs = ALooper::GetNowUs();
mCondition.broadcast();
@@ -161,4 +184,13 @@ void RepeaterSource::onMessageReceived(const sp<AMessage> &msg) {
}
}
+void RepeaterSource::wakeUp() {
+ ALOGV("wakeUp");
+ Mutex::Autolock autoLock(mLock);
+ if (mLastBufferUpdateUs < 0ll && mBuffer != NULL) {
+ mLastBufferUpdateUs = ALooper::GetNowUs();
+ mCondition.broadcast();
+ }
+}
+
} // namespace android