From d354d8d1b09503c0166c1f3e626cda72a3eeb83c Mon Sep 17 00:00:00 2001 From: Chong Zhang Date: Wed, 20 Aug 2014 13:09:58 -0700 Subject: move cache prefill to GenericSource's message handler This allows prepareAsync to be terminated by reset promptly. It also makes it easier to do buffer update as GenericSource can access the cache status now. Bug: 16892748 Bug: 17182378 Change-Id: Ia55c04a810fd805041cb2025f6739afa5120b5ed --- media/libstagefright/DataSource.cpp | 77 ++++--------------------------------- 1 file changed, 7 insertions(+), 70 deletions(-) (limited to 'media/libstagefright/DataSource.cpp') diff --git a/media/libstagefright/DataSource.cpp b/media/libstagefright/DataSource.cpp index 008da5a..9d6fd78 100644 --- a/media/libstagefright/DataSource.cpp +++ b/media/libstagefright/DataSource.cpp @@ -186,9 +186,9 @@ sp DataSource::CreateFromURI( const sp &httpService, const char *uri, const KeyedVector *headers, - AString *sniffedMIME) { - if (sniffedMIME != NULL) { - *sniffedMIME = ""; + String8 *contentType) { + if (contentType != NULL) { + *contentType = ""; } bool isWidevine = !strncasecmp("widevine://", uri, 11); @@ -226,77 +226,14 @@ sp DataSource::CreateFromURI( } if (!isWidevine) { - String8 contentType = httpSource->getMIMEType(); + if (contentType != NULL) { + *contentType = httpSource->getMIMEType(); + } - sp cachedSource = new NuCachedSource2( + source = new NuCachedSource2( httpSource, cacheConfig.isEmpty() ? NULL : cacheConfig.string(), disconnectAtHighwatermark); - - if (strncasecmp(contentType.string(), "audio/", 6)) { - // We're not doing this for streams that appear to be audio-only - // streams to ensure that even low bandwidth streams start - // playing back fairly instantly. - - // We're going to prefill the cache before trying to instantiate - // the extractor below, as the latter is an operation that otherwise - // could block on the datasource for a significant amount of time. - // During that time we'd be unable to abort the preparation phase - // without this prefill. - - // Initially make sure we have at least 192 KB for the sniff - // to complete without blocking. - static const size_t kMinBytesForSniffing = 192 * 1024; - - off64_t metaDataSize = -1ll; - for (;;) { - status_t finalStatus; - size_t cachedDataRemaining = - cachedSource->approxDataRemaining(&finalStatus); - - if (finalStatus != OK || (metaDataSize >= 0 - && (off64_t)cachedDataRemaining >= metaDataSize)) { - ALOGV("stop caching, status %d, " - "metaDataSize %lld, cachedDataRemaining %zu", - finalStatus, metaDataSize, cachedDataRemaining); - break; - } - - ALOGV("now cached %zu bytes of data", cachedDataRemaining); - - if (metaDataSize < 0 - && cachedDataRemaining >= kMinBytesForSniffing) { - String8 tmp; - float confidence; - sp meta; - if (!cachedSource->sniff(&tmp, &confidence, &meta)) { - return NULL; - } - - // We successfully identified the file's extractor to - // be, remember this mime type so we don't have to - // sniff it again when we call MediaExtractor::Create() - if (sniffedMIME != NULL) { - *sniffedMIME = tmp.string(); - } - - if (meta == NULL - || !meta->findInt64("meta-data-size", - reinterpret_cast(&metaDataSize))) { - metaDataSize = kDefaultMetaSize; - } - - if (metaDataSize < 0ll) { - ALOGE("invalid metaDataSize = %lld bytes", metaDataSize); - return NULL; - } - } - - usleep(200000); - } - } - - source = cachedSource; } else { // We do not want that prefetching, caching, datasource wrapper // in the widevine:// case. -- cgit v1.1