diff options
Diffstat (limited to 'media/libstagefright/NuCachedSource2.cpp')
-rw-r--r-- | media/libstagefright/NuCachedSource2.cpp | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/media/libstagefright/NuCachedSource2.cpp b/media/libstagefright/NuCachedSource2.cpp index f82636b..f72acf7 100644 --- a/media/libstagefright/NuCachedSource2.cpp +++ b/media/libstagefright/NuCachedSource2.cpp @@ -197,7 +197,8 @@ NuCachedSource2::NuCachedSource2( mHighwaterThresholdBytes(kDefaultHighWaterThreshold), mLowwaterThresholdBytes(kDefaultLowWaterThreshold), mKeepAliveIntervalUs(kDefaultKeepAliveIntervalUs), - mDisconnectAtHighwatermark(disconnectAtHighwatermark) { + mDisconnectAtHighwatermark(disconnectAtHighwatermark), + mSuspended(false) { // We are NOT going to support disconnect-at-highwatermark indefinitely // and we are not guaranteeing support for client-specified cache // parameters. Both of these are temporary measures to solve a specific @@ -224,9 +225,6 @@ NuCachedSource2::NuCachedSource2( // So whenever we call DataSource::readAt it may end up in a call to // IMediaHTTPConnection::readAt and therefore call back into JAVA. mLooper->start(false /* runOnCallingThread */, true /* canCallJava */); - - Mutex::Autolock autoLock(mLock); - (new AMessage(kWhatFetchMore, mReflector))->post(); } NuCachedSource2::~NuCachedSource2() { @@ -237,6 +235,18 @@ NuCachedSource2::~NuCachedSource2() { mCache = NULL; } +// static +sp<NuCachedSource2> NuCachedSource2::Create( + const sp<DataSource> &source, + const char *cacheConfig, + bool disconnectAtHighwatermark) { + sp<NuCachedSource2> instance = new NuCachedSource2( + source, cacheConfig, disconnectAtHighwatermark); + Mutex::Autolock autoLock(instance->mLock); + (new AMessage(kWhatFetchMore, instance->mReflector))->post(); + return instance; +} + status_t NuCachedSource2::getEstimatedBandwidthKbps(int32_t *kbps) { if (mSource->flags() & kIsHTTPBasedSource) { HTTPBase* source = static_cast<HTTPBase *>(mSource.get()); @@ -323,7 +333,7 @@ void NuCachedSource2::fetchInternal() { } } - if (reconnect) { + if (reconnect && !mSuspended) { status_t err = mSource->reconnectAtOffset(mCacheOffset + mCache->totalSize()); @@ -433,6 +443,13 @@ void NuCachedSource2::onFetch() { delayUs = 100000ll; } + if (mSuspended) { + static_cast<HTTPBase *>(mSource.get())->disconnect(); + mFinalStatus = -EAGAIN; + return; + } + + (new AMessage(kWhatFetchMore, mReflector))->post(delayUs); } @@ -762,4 +779,25 @@ void NuCachedSource2::RemoveCacheSpecificHeaders( } } +status_t NuCachedSource2::disconnectWhileSuspend() { + if (mSource != NULL) { + static_cast<HTTPBase *>(mSource.get())->disconnect(); + mFinalStatus = -EAGAIN; + mSuspended = true; + } else { + return ERROR_UNSUPPORTED; + } + + return OK; +} + +status_t NuCachedSource2::connectWhileResume() { + mSuspended = false; + + // Begin to connect again and fetch more data + (new AMessage(kWhatFetchMore, mReflector))->post(); + + return OK; +} + } // namespace android |