diff options
author | Andreas Huber <andih@google.com> | 2011-10-05 14:32:17 -0700 |
---|---|---|
committer | Andreas Huber <andih@google.com> | 2011-10-06 15:27:24 -0700 |
commit | a045cb0e77097120e86e367e1cab5494ce2a5d5e (patch) | |
tree | aa59a2e83f38bf06507b0c81af311f2f096287ec /media/libstagefright/NuCachedSource2.cpp | |
parent | d20bf0676d6db8f12edcd2307f82409c076c7015 (diff) | |
download | frameworks_av-a045cb0e77097120e86e367e1cab5494ce2a5d5e.zip frameworks_av-a045cb0e77097120e86e367e1cab5494ce2a5d5e.tar.gz frameworks_av-a045cb0e77097120e86e367e1cab5494ce2a5d5e.tar.bz2 |
Allow a system property "media.stagefright.cache-params" to override cache/prefetcher
default parameters. To override specify a property
adb shell setprop media.stagefright.cache-params "4096/20480/15" to
set the low water threshold to 4096 KB, the high water threshold to 20 MB
and the keepalive interval to 15 secs.
if high and/or lowwater mark are negative, the default values are used for
the respective value.
if keep-alive interval is 0, keep-alives are disabled.
Change-Id: I89a4a06836e4a2f473d7a92b567ab07818c2f87d
Diffstat (limited to 'media/libstagefright/NuCachedSource2.cpp')
-rw-r--r-- | media/libstagefright/NuCachedSource2.cpp | 57 |
1 files changed, 52 insertions, 5 deletions
diff --git a/media/libstagefright/NuCachedSource2.cpp b/media/libstagefright/NuCachedSource2.cpp index 4edb613..2cacfa7 100644 --- a/media/libstagefright/NuCachedSource2.cpp +++ b/media/libstagefright/NuCachedSource2.cpp @@ -21,6 +21,7 @@ #include "include/NuCachedSource2.h" #include "include/HTTPBase.h" +#include <cutils/properties.h> #include <media/stagefright/foundation/ADebug.h> #include <media/stagefright/foundation/AMessage.h> #include <media/stagefright/MediaErrors.h> @@ -186,7 +187,12 @@ NuCachedSource2::NuCachedSource2(const sp<DataSource> &source) mLastAccessPos(0), mFetching(true), mLastFetchTimeUs(-1), - mNumRetriesLeft(kMaxNumRetries) { + mNumRetriesLeft(kMaxNumRetries), + mHighwaterThresholdBytes(kDefaultHighWaterThreshold), + mLowwaterThresholdBytes(kDefaultLowWaterThreshold), + mKeepAliveIntervalUs(kDefaultKeepAliveIntervalUs) { + updateCacheParamsFromSystemProperty(); + mLooper->setName("NuCachedSource2"); mLooper->registerHandler(mReflector); mLooper->start(); @@ -318,7 +324,8 @@ void NuCachedSource2::onFetch() { bool keepAlive = !mFetching && mFinalStatus == OK - && ALooper::GetNowUs() >= mLastFetchTimeUs + kKeepAliveIntervalUs; + && mKeepAliveIntervalUs > 0 + && ALooper::GetNowUs() >= mLastFetchTimeUs + mKeepAliveIntervalUs; if (mFetching || keepAlive) { if (keepAlive) { @@ -329,7 +336,7 @@ void NuCachedSource2::onFetch() { mLastFetchTimeUs = ALooper::GetNowUs(); - if (mFetching && mCache->totalSize() >= kHighWaterThreshold) { + if (mFetching && mCache->totalSize() >= mHighwaterThresholdBytes) { LOGI("Cache full, done prefetching for now"); mFetching = false; } @@ -392,7 +399,7 @@ void NuCachedSource2::restartPrefetcherIfNecessary_l( if (!ignoreLowWaterThreshold && !force && mCacheOffset + mCache->totalSize() - mLastAccessPos - >= kLowWaterThreshold) { + >= mLowwaterThresholdBytes) { return; } @@ -482,7 +489,7 @@ size_t NuCachedSource2::approxDataRemaining_l(status_t *finalStatus) { } ssize_t NuCachedSource2::readInternal(off64_t offset, void *data, size_t size) { - CHECK_LE(size, (size_t)kHighWaterThreshold); + CHECK_LE(size, (size_t)mHighwaterThresholdBytes); LOGV("readInternal offset %lld size %d", offset, size); @@ -580,4 +587,44 @@ String8 NuCachedSource2::getMIMEType() const { return mSource->getMIMEType(); } +void NuCachedSource2::updateCacheParamsFromSystemProperty() { + char value[PROPERTY_VALUE_MAX]; + if (!property_get("media.stagefright.cache-params", value, NULL)) { + return; + } + + updateCacheParamsFromString(value); +} + +void NuCachedSource2::updateCacheParamsFromString(const char *s) { + ssize_t lowwaterMarkKb, highwaterMarkKb; + unsigned keepAliveSecs; + + if (sscanf(s, "%ld/%ld/%u", + &lowwaterMarkKb, &highwaterMarkKb, &keepAliveSecs) != 3 + || lowwaterMarkKb >= highwaterMarkKb) { + LOGE("Failed to parse cache parameters from '%s'.", s); + return; + } + + if (lowwaterMarkKb >= 0) { + mLowwaterThresholdBytes = lowwaterMarkKb * 1024; + } else { + mLowwaterThresholdBytes = kDefaultLowWaterThreshold; + } + + if (highwaterMarkKb >= 0) { + mHighwaterThresholdBytes = highwaterMarkKb * 1024; + } else { + mHighwaterThresholdBytes = kDefaultHighWaterThreshold; + } + + mKeepAliveIntervalUs = keepAliveSecs * 1000000ll; + + LOGV("lowwater = %d bytes, highwater = %d bytes, keepalive = %lld us", + mLowwaterThresholdBytes, + mHighwaterThresholdBytes, + mKeepAliveIntervalUs); +} + } // namespace android |