Merge "Make the prefetcher read packets from the network after a keep-alive timeout expires regardless of whether its currently actively fetching data or not." into gingerbread
This commit is contained in:
committed by
Android (Google) Code Review
commit
ef1c48d6a9
@@ -178,7 +178,8 @@ NuCachedSource2::NuCachedSource2(const sp<DataSource> &source)
|
|||||||
mCacheOffset(0),
|
mCacheOffset(0),
|
||||||
mFinalStatus(OK),
|
mFinalStatus(OK),
|
||||||
mLastAccessPos(0),
|
mLastAccessPos(0),
|
||||||
mFetching(true) {
|
mFetching(true),
|
||||||
|
mLastFetchTimeUs(-1) {
|
||||||
mLooper->registerHandler(mReflector);
|
mLooper->registerHandler(mReflector);
|
||||||
mLooper->start();
|
mLooper->start();
|
||||||
|
|
||||||
@@ -259,10 +260,21 @@ void NuCachedSource2::onFetch() {
|
|||||||
mFetching = false;
|
mFetching = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mFetching) {
|
bool keepAlive =
|
||||||
|
!mFetching
|
||||||
|
&& mFinalStatus == OK
|
||||||
|
&& ALooper::GetNowUs() >= mLastFetchTimeUs + kKeepAliveIntervalUs;
|
||||||
|
|
||||||
|
if (mFetching || keepAlive) {
|
||||||
|
if (keepAlive) {
|
||||||
|
LOG(INFO) << "Keep alive";
|
||||||
|
}
|
||||||
|
|
||||||
fetchInternal();
|
fetchInternal();
|
||||||
|
|
||||||
if (mCache->totalSize() >= kHighWaterThreshold) {
|
mLastFetchTimeUs = ALooper::GetNowUs();
|
||||||
|
|
||||||
|
if (mFetching && mCache->totalSize() >= kHighWaterThreshold) {
|
||||||
LOG(INFO) << "Cache full, done prefetching for now";
|
LOG(INFO) << "Cache full, done prefetching for now";
|
||||||
mFetching = false;
|
mFetching = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,9 +49,13 @@ private:
|
|||||||
friend struct AHandlerReflector<NuCachedSource2>;
|
friend struct AHandlerReflector<NuCachedSource2>;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
kPageSize = 16384,
|
kPageSize = 16384,
|
||||||
kHighWaterThreshold = 3 * 1024 * 1024,
|
kHighWaterThreshold = 3 * 1024 * 1024,
|
||||||
kLowWaterThreshold = 512 * 1024,
|
kLowWaterThreshold = 512 * 1024,
|
||||||
|
|
||||||
|
// Read data after a 15 sec timeout whether we're actively
|
||||||
|
// fetching or not.
|
||||||
|
kKeepAliveIntervalUs = 15000000,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@@ -73,6 +77,7 @@ private:
|
|||||||
off_t mLastAccessPos;
|
off_t mLastAccessPos;
|
||||||
sp<AMessage> mAsyncResult;
|
sp<AMessage> mAsyncResult;
|
||||||
bool mFetching;
|
bool mFetching;
|
||||||
|
int64_t mLastFetchTimeUs;
|
||||||
|
|
||||||
void onMessageReceived(const sp<AMessage> &msg);
|
void onMessageReceived(const sp<AMessage> &msg);
|
||||||
void onFetch();
|
void onFetch();
|
||||||
|
|||||||
Reference in New Issue
Block a user