summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/MediaCodecList.cpp
diff options
context:
space:
mode:
authorRonghua Wu <ronghuawu@google.com>2015-06-05 09:54:53 -0700
committerRonghua Wu <ronghuawu@google.com>2015-06-07 21:41:52 -0700
commita09152c6317e0295773b91f529e63c4d7c107752 (patch)
tree560440b692a1b48e0b32476126f4770f26bb1a50 /media/libstagefright/MediaCodecList.cpp
parent81c4d806c574271e6e4e49a795bcbe809af4eff0 (diff)
downloadframeworks_av-a09152c6317e0295773b91f529e63c4d7c107752.zip
frameworks_av-a09152c6317e0295773b91f529e63c4d7c107752.tar.gz
frameworks_av-a09152c6317e0295773b91f529e63c4d7c107752.tar.bz2
libstagefright: run codec profiling in worker thread.
Bug: 21645841 Change-Id: Ia15eb3b064b671c569afb0742db7535f6b03232e
Diffstat (limited to 'media/libstagefright/MediaCodecList.cpp')
-rw-r--r--media/libstagefright/MediaCodecList.cpp102
1 files changed, 56 insertions, 46 deletions
diff --git a/media/libstagefright/MediaCodecList.cpp b/media/libstagefright/MediaCodecList.cpp
index f366b1f..d48ede9 100644
--- a/media/libstagefright/MediaCodecList.cpp
+++ b/media/libstagefright/MediaCodecList.cpp
@@ -46,8 +46,6 @@ const char *kMaxEncoderInputBuffers = "max-video-encoder-input-buffers";
static Mutex sInitMutex;
-static MediaCodecList *gCodecList = NULL;
-
static bool parseBoolean(const char *s) {
if (!strcasecmp(s, "true") || !strcasecmp(s, "yes") || !strcasecmp(s, "y")) {
return true;
@@ -57,64 +55,76 @@ static bool parseBoolean(const char *s) {
return *s != '\0' && *end == '\0' && res > 0;
}
+static bool isProfilingNeeded() {
+ bool profilingNeeded = true;
+ FILE *resultsFile = fopen(kProfilingResults, "r");
+ if (resultsFile) {
+ AString currentVersion = getProfilingVersionString();
+ size_t currentVersionSize = currentVersion.size();
+ char *versionString = new char[currentVersionSize + 1];
+ fgets(versionString, currentVersionSize + 1, resultsFile);
+ if (strcmp(versionString, currentVersion.c_str()) == 0) {
+ // profiling result up to date
+ profilingNeeded = false;
+ }
+ fclose(resultsFile);
+ delete[] versionString;
+ }
+ return profilingNeeded;
+}
+
// static
sp<IMediaCodecList> MediaCodecList::sCodecList;
// static
-sp<IMediaCodecList> MediaCodecList::getLocalInstance() {
- bool profilingNeeded = false;
+void *MediaCodecList::profilerThreadWrapper(void * /*arg*/) {
+ ALOGV("Enter profilerThreadWrapper.");
+ MediaCodecList *codecList = new MediaCodecList();
+ if (codecList->initCheck() != OK) {
+ ALOGW("Failed to create a new MediaCodecList, skipping codec profiling.");
+ delete codecList;
+ return NULL;
+ }
+
Vector<sp<MediaCodecInfo>> infos;
+ for (size_t i = 0; i < codecList->countCodecs(); ++i) {
+ infos.push_back(codecList->getCodecInfo(i));
+ }
+ ALOGV("Codec profiling started.");
+ profileCodecs(infos);
+ ALOGV("Codec profiling completed.");
+ codecList->parseTopLevelXMLFile(kProfilingResults, true /* ignore_errors */);
{
Mutex::Autolock autoLock(sInitMutex);
+ sCodecList = codecList;
+ }
+ return NULL;
+}
- if (gCodecList == NULL) {
- gCodecList = new MediaCodecList;
- if (gCodecList->initCheck() == OK) {
- sCodecList = gCodecList;
-
- FILE *resultsFile = fopen(kProfilingResults, "r");
- if (resultsFile) {
- AString currentVersion = getProfilingVersionString();
- size_t currentVersionSize = currentVersion.size();
- char *versionString = new char[currentVersionSize];
- fgets(versionString, currentVersionSize, resultsFile);
- if (strncmp(versionString, currentVersion.c_str(), currentVersionSize) != 0) {
- // profiling result out of date
- profilingNeeded = true;
- }
- fclose(resultsFile);
- delete[] versionString;
- } else {
- // profiling results doesn't existed
- profilingNeeded = true;
- }
-
- if (profilingNeeded) {
- for (size_t i = 0; i < gCodecList->countCodecs(); ++i) {
- infos.push_back(gCodecList->getCodecInfo(i));
- }
+// static
+sp<IMediaCodecList> MediaCodecList::getLocalInstance() {
+ Mutex::Autolock autoLock(sInitMutex);
+
+ if (sCodecList == NULL) {
+ MediaCodecList *codecList = new MediaCodecList;
+ if (codecList->initCheck() == OK) {
+ sCodecList = codecList;
+
+ if (isProfilingNeeded()) {
+ ALOGV("Codec profiling needed, will be run in separated thread.");
+ pthread_t profiler;
+ if (pthread_create(&profiler, NULL, profilerThreadWrapper, NULL) != 0) {
+ ALOGW("Failed to create thread for codec profiling.");
}
- } else {
- // failure to initialize may be temporary. retry on next call.
- delete gCodecList;
- gCodecList = NULL;
}
+ } else {
+ // failure to initialize may be temporary. retry on next call.
+ delete codecList;
}
}
- if (profilingNeeded) {
- profileCodecs(infos);
- }
-
- {
- Mutex::Autolock autoLock(sInitMutex);
- if (profilingNeeded) {
- gCodecList->parseTopLevelXMLFile(kProfilingResults, true /* ignore_errors */);
- }
-
- return sCodecList;
- }
+ return sCodecList;
}
static Mutex sRemoteInitMutex;