summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/DataSource.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'media/libstagefright/DataSource.cpp')
-rw-r--r--media/libstagefright/DataSource.cpp76
1 files changed, 65 insertions, 11 deletions
diff --git a/media/libstagefright/DataSource.cpp b/media/libstagefright/DataSource.cpp
index 5020c6c..34f0649 100644
--- a/media/libstagefright/DataSource.cpp
+++ b/media/libstagefright/DataSource.cpp
@@ -38,7 +38,6 @@
#include <media/IMediaHTTPConnection.h>
#include <media/IMediaHTTPService.h>
#include <media/stagefright/foundation/ADebug.h>
-#include <media/stagefright/foundation/AMessage.h>
#include <media/stagefright/DataSource.h>
#include <media/stagefright/DataURISource.h>
#include <media/stagefright/FileSource.h>
@@ -47,9 +46,28 @@
#include <utils/String8.h>
#include <cutils/properties.h>
+#include <cutils/log.h>
+
+#include <dlfcn.h>
+
+#include <stagefright/AVExtensions.h>
namespace android {
+static void *loadExtractorPlugin() {
+ void *ret = NULL;
+ char lib[PROPERTY_VALUE_MAX];
+ if (property_get("media.sf.extractor-plugin", lib, NULL)) {
+ if (void *extractorLib = ::dlopen(lib, RTLD_LAZY)) {
+ ret = ::dlsym(extractorLib, "getExtractorPlugin");
+ ALOGW_IF(!ret, "Failed to find symbol, dlerror: %s", ::dlerror());
+ } else {
+ ALOGV("Failed to load %s, dlerror: %s", lib, ::dlerror());
+ }
+ }
+ return ret;
+}
+
bool DataSource::getUInt16(off64_t offset, uint16_t *x) {
*x = 0;
@@ -116,6 +134,8 @@ bool DataSource::gSniffersRegistered = false;
bool DataSource::sniff(
String8 *mimeType, float *confidence, sp<AMessage> *meta) {
+
+
*mimeType = "";
*confidence = 0.0f;
meta->clear();
@@ -127,11 +147,18 @@ bool DataSource::sniff(
}
}
+ String8 newMimeType;
+ if (mimeType != NULL) {
+ newMimeType.setTo(*mimeType);
+ }
+ float newConfidence = *confidence;
+
for (List<SnifferFunc>::iterator it = gSniffers.begin();
it != gSniffers.end(); ++it) {
- String8 newMimeType;
- float newConfidence;
- sp<AMessage> newMeta;
+ int64_t sniffStart = ALooper::GetNowUs();
+ String8 newMimeType = *mimeType;
+ float newConfidence = *confidence;
+ sp<AMessage> newMeta = *meta;
if ((*it)(this, &newMimeType, &newConfidence, &newMeta)) {
if (newConfidence > *confidence) {
*mimeType = newMimeType;
@@ -139,6 +166,9 @@ bool DataSource::sniff(
*meta = newMeta;
}
}
+ ALOGV("Sniffer (%p) completed in %.2f ms (mime=%s confidence=%.2f",
+ this, ((float)(ALooper::GetNowUs() - sniffStart) / 1000.0f),
+ mimeType == NULL ? NULL : (*mimeType).string(), *confidence);
}
return *confidence > 0.0;
@@ -156,6 +186,19 @@ void DataSource::RegisterSniffer_l(SnifferFunc func) {
gSniffers.push_back(func);
}
+void DataSource::RegisterSnifferPlugin() {
+ static void (*getExtractorPlugin)(MediaExtractor::Plugin *) =
+ (void (*)(MediaExtractor::Plugin *))loadExtractorPlugin();
+
+ MediaExtractor::Plugin *plugin = MediaExtractor::getPlugin();
+ if (!plugin->sniff && getExtractorPlugin) {
+ getExtractorPlugin(plugin);
+ }
+ if (plugin->sniff) {
+ RegisterSniffer_l(plugin->sniff);
+ }
+}
+
// static
void DataSource::RegisterDefaultSniffers() {
Mutex::Autolock autoLock(gSnifferMutex);
@@ -175,12 +218,15 @@ void DataSource::RegisterDefaultSniffers() {
RegisterSniffer_l(SniffMPEG2PS);
RegisterSniffer_l(SniffWVM);
RegisterSniffer_l(SniffMidi);
+ RegisterSniffer_l(AVUtils::get()->getExtendedSniffer());
+ RegisterSnifferPlugin();
char value[PROPERTY_VALUE_MAX];
if (property_get("drm.service.enabled", value, NULL)
&& (!strcmp(value, "1") || !strcasecmp(value, "true"))) {
RegisterSniffer_l(SniffDRM);
}
+
gSniffersRegistered = true;
}
@@ -190,7 +236,8 @@ sp<DataSource> DataSource::CreateFromURI(
const char *uri,
const KeyedVector<String8, String8> *headers,
String8 *contentType,
- HTTPBase *httpSource) {
+ HTTPBase *httpSource,
+ bool useExtendedCache) {
if (contentType != NULL) {
*contentType = "";
}
@@ -214,7 +261,7 @@ sp<DataSource> DataSource::CreateFromURI(
ALOGE("Failed to make http connection from http service!");
return NULL;
}
- httpSource = new MediaHTTP(conn);
+ httpSource = AVFactory::get()->createMediaHTTP(conn);
}
String8 tmp;
@@ -246,10 +293,17 @@ sp<DataSource> DataSource::CreateFromURI(
*contentType = httpSource->getMIMEType();
}
- source = NuCachedSource2::Create(
- httpSource,
- cacheConfig.isEmpty() ? NULL : cacheConfig.string(),
- disconnectAtHighwatermark);
+ if (useExtendedCache) {
+ source = AVFactory::get()->createCachedSource(
+ httpSource,
+ cacheConfig.isEmpty() ? NULL : cacheConfig.string(),
+ disconnectAtHighwatermark);
+ } else {
+ source = NuCachedSource2::Create(
+ httpSource,
+ cacheConfig.isEmpty() ? NULL : cacheConfig.string(),
+ disconnectAtHighwatermark);
+ }
} else {
// We do not want that prefetching, caching, datasource wrapper
// in the widevine:// case.
@@ -278,7 +332,7 @@ sp<DataSource> DataSource::CreateMediaHTTP(const sp<IMediaHTTPService> &httpServ
if (conn == NULL) {
return NULL;
} else {
- return new MediaHTTP(conn);
+ return AVFactory::get()->createMediaHTTP(conn);
}
}