Add search paths for xml files for MediaProfiles
This CL also adds versions to xml files. The default name for
the xml file is changed from media_profiles.xml to
media_profiles_V1_0.xml.
Test: Small CtsMediaTestCases
Test: Manual use of video recording and playback in Camera app
Bug: 36430270
Merged-In: Idd0cd07f358fb4eda8ce5b31adf62a7313eccbbf
Change-Id: Idd0cd07f358fb4eda8ce5b31adf62a7313eccbbf
diff --git a/media/libmedia/MediaProfiles.cpp b/media/libmedia/MediaProfiles.cpp
index ff0e52e..aade69a 100644
--- a/media/libmedia/MediaProfiles.cpp
+++ b/media/libmedia/MediaProfiles.cpp
@@ -27,9 +27,11 @@
#include <media/MediaProfiles.h>
#include <media/stagefright/foundation/ADebug.h>
#include <OMX_Video.h>
+#include <sys/stat.h>
namespace android {
+constexpr char const * const MediaProfiles::xmlFiles[];
Mutex MediaProfiles::sLock;
bool MediaProfiles::sIsInitialized = false;
MediaProfiles *MediaProfiles::sInstance = NULL;
@@ -593,14 +595,19 @@
if (!sIsInitialized) {
char value[PROPERTY_VALUE_MAX];
if (property_get("media.settings.xml", value, NULL) <= 0) {
- const char *defaultXmlFile = "/etc/media_profiles.xml";
- FILE *fp = fopen(defaultXmlFile, "r");
- if (fp == NULL) {
- ALOGW("could not find media config xml file");
+ const char* xmlFile = nullptr;
+ for (auto const& f : xmlFiles) {
+ if (checkXmlFile(f)) {
+ xmlFile = f;
+ break;
+ }
+ }
+ if (xmlFile == nullptr) {
+ ALOGW("Could not find a validated xml file. "
+ "Using the default instance instead.");
sInstance = createDefaultInstance();
} else {
- fclose(fp); // close the file first.
- sInstance = createInstanceFromXmlFile(defaultXmlFile);
+ sInstance = createInstanceFromXmlFile(xmlFile);
}
} else {
sInstance = createInstanceFromXmlFile(value);
@@ -838,6 +845,12 @@
return profiles;
}
+bool MediaProfiles::checkXmlFile(const char* xmlFile) {
+ struct stat fStat;
+ return stat(xmlFile, &fStat) == 0 && S_ISREG(fStat.st_mode);
+ // TODO: Add validation
+}
+
/*static*/ MediaProfiles*
MediaProfiles::createInstanceFromXmlFile(const char *xml)
{