diff options
author | Marco Nelissen <marcone@google.com> | 2013-11-13 18:11:54 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-11-13 18:11:54 +0000 |
commit | 5595f6de606f51ec61fbf40a269b52312507aded (patch) | |
tree | e76298c16e9a54166661d417012eb996e3e7f73d | |
parent | 26c8f714361bfb6403a7c457adfb8b55c89a634a (diff) | |
parent | e3067743d6ef2c6c1aac4361b6ed65e6d7bbe3e3 (diff) | |
download | frameworks_av-5595f6de606f51ec61fbf40a269b52312507aded.zip frameworks_av-5595f6de606f51ec61fbf40a269b52312507aded.tar.gz frameworks_av-5595f6de606f51ec61fbf40a269b52312507aded.tar.bz2 |
Merge "Only initialize sniffers once, don't hold mutex while sniffing" into klp-dev
-rw-r--r-- | include/media/stagefright/DataSource.h | 4 | ||||
-rw-r--r-- | media/libstagefright/DataSource.cpp | 43 |
2 files changed, 30 insertions, 17 deletions
diff --git a/include/media/stagefright/DataSource.h b/include/media/stagefright/DataSource.h index 742bc0e..157b1aa 100644 --- a/include/media/stagefright/DataSource.h +++ b/include/media/stagefright/DataSource.h @@ -80,7 +80,6 @@ public: const sp<DataSource> &source, String8 *mimeType, float *confidence, sp<AMessage> *meta); - static void RegisterSniffer(SnifferFunc func); static void RegisterDefaultSniffers(); // for DRM @@ -101,6 +100,9 @@ protected: private: static Mutex gSnifferMutex; static List<SnifferFunc> gSniffers; + static bool gSniffersRegistered; + + static void RegisterSniffer_l(SnifferFunc func); DataSource(const DataSource &); DataSource &operator=(const DataSource &); diff --git a/media/libstagefright/DataSource.cpp b/media/libstagefright/DataSource.cpp index fc6fd9c..97987e2 100644 --- a/media/libstagefright/DataSource.cpp +++ b/media/libstagefright/DataSource.cpp @@ -107,6 +107,7 @@ status_t DataSource::getSize(off64_t *size) { Mutex DataSource::gSnifferMutex; List<DataSource::SnifferFunc> DataSource::gSniffers; +bool DataSource::gSniffersRegistered = false; bool DataSource::sniff( String8 *mimeType, float *confidence, sp<AMessage> *meta) { @@ -114,7 +115,13 @@ bool DataSource::sniff( *confidence = 0.0f; meta->clear(); - Mutex::Autolock autoLock(gSnifferMutex); + { + Mutex::Autolock autoLock(gSnifferMutex); + if (!gSniffersRegistered) { + return false; + } + } + for (List<SnifferFunc>::iterator it = gSniffers.begin(); it != gSniffers.end(); ++it) { String8 newMimeType; @@ -133,9 +140,7 @@ bool DataSource::sniff( } // static -void DataSource::RegisterSniffer(SnifferFunc func) { - Mutex::Autolock autoLock(gSnifferMutex); - +void DataSource::RegisterSniffer_l(SnifferFunc func) { for (List<SnifferFunc>::iterator it = gSniffers.begin(); it != gSniffers.end(); ++it) { if (*it == func) { @@ -148,23 +153,29 @@ void DataSource::RegisterSniffer(SnifferFunc func) { // static void DataSource::RegisterDefaultSniffers() { - RegisterSniffer(SniffMPEG4); - RegisterSniffer(SniffMatroska); - RegisterSniffer(SniffOgg); - RegisterSniffer(SniffWAV); - RegisterSniffer(SniffFLAC); - RegisterSniffer(SniffAMR); - RegisterSniffer(SniffMPEG2TS); - RegisterSniffer(SniffMP3); - RegisterSniffer(SniffAAC); - RegisterSniffer(SniffMPEG2PS); - RegisterSniffer(SniffWVM); + Mutex::Autolock autoLock(gSnifferMutex); + if (gSniffersRegistered) { + return; + } + + RegisterSniffer_l(SniffMPEG4); + RegisterSniffer_l(SniffMatroska); + RegisterSniffer_l(SniffOgg); + RegisterSniffer_l(SniffWAV); + RegisterSniffer_l(SniffFLAC); + RegisterSniffer_l(SniffAMR); + RegisterSniffer_l(SniffMPEG2TS); + RegisterSniffer_l(SniffMP3); + RegisterSniffer_l(SniffAAC); + RegisterSniffer_l(SniffMPEG2PS); + RegisterSniffer_l(SniffWVM); char value[PROPERTY_VALUE_MAX]; if (property_get("drm.service.enabled", value, NULL) && (!strcmp(value, "1") || !strcasecmp(value, "true"))) { - RegisterSniffer(SniffDRM); + RegisterSniffer_l(SniffDRM); } + gSniffersRegistered = true; } // static |