Loading media/libstagefright/NuCachedSource2.cpp +52 −5 Original line number Diff line number Diff line Loading @@ -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> Loading Loading @@ -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(); Loading Loading @@ -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) { Loading @@ -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; } Loading Loading @@ -392,7 +399,7 @@ void NuCachedSource2::restartPrefetcherIfNecessary_l( if (!ignoreLowWaterThreshold && !force && mCacheOffset + mCache->totalSize() - mLastAccessPos >= kLowWaterThreshold) { >= mLowwaterThresholdBytes) { return; } Loading Loading @@ -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); Loading Loading @@ -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 media/libstagefright/include/NuCachedSource2.h +13 −4 Original line number Diff line number Diff line Loading @@ -64,12 +64,12 @@ private: enum { kPageSize = 65536, kHighWaterThreshold = 20 * 1024 * 1024, kLowWaterThreshold = 4 * 1024 * 1024, kDefaultHighWaterThreshold = 20 * 1024 * 1024, kDefaultLowWaterThreshold = 4 * 1024 * 1024, // Read data after a 15 sec timeout whether we're actively // fetching or not. kKeepAliveIntervalUs = 15000000, kDefaultKeepAliveIntervalUs = 15000000, }; enum { Loading Loading @@ -99,6 +99,12 @@ private: int32_t mNumRetriesLeft; size_t mHighwaterThresholdBytes; size_t mLowwaterThresholdBytes; // If the keep-alive interval is 0, keep-alives are disabled. int64_t mKeepAliveIntervalUs; void onMessageReceived(const sp<AMessage> &msg); void onFetch(); void onRead(const sp<AMessage> &msg); Loading @@ -112,6 +118,9 @@ private: void restartPrefetcherIfNecessary_l( bool ignoreLowWaterThreshold = false, bool force = false); void updateCacheParamsFromSystemProperty(); void updateCacheParamsFromString(const char *s); DISALLOW_EVIL_CONSTRUCTORS(NuCachedSource2); }; Loading Loading
media/libstagefright/NuCachedSource2.cpp +52 −5 Original line number Diff line number Diff line Loading @@ -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> Loading Loading @@ -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(); Loading Loading @@ -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) { Loading @@ -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; } Loading Loading @@ -392,7 +399,7 @@ void NuCachedSource2::restartPrefetcherIfNecessary_l( if (!ignoreLowWaterThreshold && !force && mCacheOffset + mCache->totalSize() - mLastAccessPos >= kLowWaterThreshold) { >= mLowwaterThresholdBytes) { return; } Loading Loading @@ -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); Loading Loading @@ -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
media/libstagefright/include/NuCachedSource2.h +13 −4 Original line number Diff line number Diff line Loading @@ -64,12 +64,12 @@ private: enum { kPageSize = 65536, kHighWaterThreshold = 20 * 1024 * 1024, kLowWaterThreshold = 4 * 1024 * 1024, kDefaultHighWaterThreshold = 20 * 1024 * 1024, kDefaultLowWaterThreshold = 4 * 1024 * 1024, // Read data after a 15 sec timeout whether we're actively // fetching or not. kKeepAliveIntervalUs = 15000000, kDefaultKeepAliveIntervalUs = 15000000, }; enum { Loading Loading @@ -99,6 +99,12 @@ private: int32_t mNumRetriesLeft; size_t mHighwaterThresholdBytes; size_t mLowwaterThresholdBytes; // If the keep-alive interval is 0, keep-alives are disabled. int64_t mKeepAliveIntervalUs; void onMessageReceived(const sp<AMessage> &msg); void onFetch(); void onRead(const sp<AMessage> &msg); Loading @@ -112,6 +118,9 @@ private: void restartPrefetcherIfNecessary_l( bool ignoreLowWaterThreshold = false, bool force = false); void updateCacheParamsFromSystemProperty(); void updateCacheParamsFromString(const char *s); DISALLOW_EVIL_CONSTRUCTORS(NuCachedSource2); }; Loading