diff options
author | Andreas Huber <andih@google.com> | 2012-04-16 11:11:02 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-04-16 11:11:02 -0700 |
commit | a98db787397633155fd71b06ecaa765a7ad20cf2 (patch) | |
tree | 312df209f64c9ed371bb7855ca6243352207fd62 | |
parent | b388e531613730572067e193b6b66afb5d042233 (diff) | |
parent | 918c7652b9a38c02e26c0c46541cea82070c0e43 (diff) | |
download | frameworks_av-a98db787397633155fd71b06ecaa765a7ad20cf2.zip frameworks_av-a98db787397633155fd71b06ecaa765a7ad20cf2.tar.gz frameworks_av-a98db787397633155fd71b06ecaa765a7ad20cf2.tar.bz2 |
Merge "Change NuMediaExtractor's API to support different kinds of data sources."
-rw-r--r-- | include/media/stagefright/NuMediaExtractor.h | 8 | ||||
-rw-r--r-- | media/libstagefright/DataSource.cpp | 14 | ||||
-rw-r--r-- | media/libstagefright/NuMediaExtractor.cpp | 36 |
3 files changed, 54 insertions, 4 deletions
diff --git a/include/media/stagefright/NuMediaExtractor.h b/include/media/stagefright/NuMediaExtractor.h index 07c7be5..a09f971 100644 --- a/include/media/stagefright/NuMediaExtractor.h +++ b/include/media/stagefright/NuMediaExtractor.h @@ -19,7 +19,9 @@ #include <media/stagefright/foundation/ABase.h> #include <utils/Errors.h> +#include <utils/KeyedVector.h> #include <utils/RefBase.h> +#include <utils/String8.h> #include <utils/Vector.h> namespace android { @@ -38,7 +40,11 @@ struct NuMediaExtractor : public RefBase { NuMediaExtractor(); - status_t setDataSource(const char *path); + status_t setDataSource( + const char *path, + const KeyedVector<String8, String8> *headers = NULL); + + status_t setDataSource(int fd, off64_t offset, off64_t size); size_t countTracks() const; status_t getTrackFormat(size_t index, sp<AMessage> *format) const; diff --git a/media/libstagefright/DataSource.cpp b/media/libstagefright/DataSource.cpp index d0a7880..aba95bc 100644 --- a/media/libstagefright/DataSource.cpp +++ b/media/libstagefright/DataSource.cpp @@ -142,7 +142,19 @@ sp<DataSource> DataSource::CreateFromURI( if (httpSource->connect(uri, headers) != OK) { return NULL; } - source = new NuCachedSource2(httpSource); + + String8 cacheConfig; + bool disconnectAtHighwatermark; + if (headers != NULL) { + KeyedVector<String8, String8> copy = *headers; + NuCachedSource2::RemoveCacheSpecificHeaders( + ©, &cacheConfig, &disconnectAtHighwatermark); + } + + source = new NuCachedSource2( + httpSource, + cacheConfig.isEmpty() ? NULL : cacheConfig.string()); + # if CHROMIUM_AVAILABLE } else if (!strncasecmp("data:", uri, 5)) { source = new DataUriSource(uri); diff --git a/media/libstagefright/NuMediaExtractor.cpp b/media/libstagefright/NuMediaExtractor.cpp index 224ec33..8758c93 100644 --- a/media/libstagefright/NuMediaExtractor.cpp +++ b/media/libstagefright/NuMediaExtractor.cpp @@ -26,6 +26,7 @@ #include <media/stagefright/foundation/ADebug.h> #include <media/stagefright/foundation/AMessage.h> #include <media/stagefright/DataSource.h> +#include <media/stagefright/FileSource.h> #include <media/stagefright/MediaBuffer.h> #include <media/stagefright/MediaDefs.h> #include <media/stagefright/MediaErrors.h> @@ -51,8 +52,13 @@ NuMediaExtractor::~NuMediaExtractor() { mSelectedTracks.clear(); } -status_t NuMediaExtractor::setDataSource(const char *path) { - sp<DataSource> dataSource = DataSource::CreateFromURI(path); +status_t NuMediaExtractor::setDataSource( + const char *path, const KeyedVector<String8, String8> *headers) { + if (mImpl != NULL) { + return -EINVAL; + } + + sp<DataSource> dataSource = DataSource::CreateFromURI(path, headers); if (dataSource == NULL) { return -ENOENT; @@ -67,6 +73,27 @@ status_t NuMediaExtractor::setDataSource(const char *path) { return OK; } +status_t NuMediaExtractor::setDataSource(int fd, off64_t offset, off64_t size) { + if (mImpl != NULL) { + return -EINVAL; + } + + sp<FileSource> fileSource = new FileSource(dup(fd), offset, size); + + status_t err = fileSource->initCheck(); + if (err != OK) { + return err; + } + + mImpl = MediaExtractor::Create(fileSource); + + if (mImpl == NULL) { + return ERROR_UNSUPPORTED; + } + + return OK; +} + size_t NuMediaExtractor::countTracks() const { return mImpl == NULL ? 0 : mImpl->countTracks(); } @@ -91,6 +118,11 @@ status_t NuMediaExtractor::getTrackFormat( sp<AMessage> msg = new AMessage; msg->setString("mime", mime); + int64_t durationUs; + if (meta->findInt64(kKeyDuration, &durationUs)) { + msg->setInt64("durationUs", durationUs); + } + if (!strncasecmp("video/", mime, 6)) { int32_t width, height; CHECK(meta->findInt32(kKeyWidth, &width)); |