summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/DataSource.cpp
diff options
context:
space:
mode:
authorChong Zhang <chz@google.com>2014-08-20 13:09:58 -0700
committerChong Zhang <chz@google.com>2014-08-21 18:38:09 -0700
commitd354d8d1b09503c0166c1f3e626cda72a3eeb83c (patch)
treebcb5370e8abc4611587dbef4066c0345a647c068 /media/libstagefright/DataSource.cpp
parent111333eaab12448f45927464c8aeacbbf9a578a1 (diff)
downloadframeworks_av-d354d8d1b09503c0166c1f3e626cda72a3eeb83c.zip
frameworks_av-d354d8d1b09503c0166c1f3e626cda72a3eeb83c.tar.gz
frameworks_av-d354d8d1b09503c0166c1f3e626cda72a3eeb83c.tar.bz2
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
Diffstat (limited to 'media/libstagefright/DataSource.cpp')
-rw-r--r--media/libstagefright/DataSource.cpp77
1 files changed, 7 insertions, 70 deletions
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> DataSource::CreateFromURI(
const sp<IMediaHTTPService> &httpService,
const char *uri,
const KeyedVector<String8, String8> *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> DataSource::CreateFromURI(
}
if (!isWidevine) {
- String8 contentType = httpSource->getMIMEType();
+ if (contentType != NULL) {
+ *contentType = httpSource->getMIMEType();
+ }
- sp<NuCachedSource2> 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<AMessage> 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<int64_t*>(&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.