Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 57834076 authored by Pawin Vongmasa's avatar Pawin Vongmasa Committed by Android (Google) Code Review
Browse files

Merge "Add search paths for xml files for MediaProfiles"

parents 9ee3885b 72ad8cb0
Loading
Loading
Loading
Loading
+19 −6
Original line number Diff line number Diff line
@@ -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 @@ MediaProfiles::getInstance()
    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 @@ MediaProfiles::createDefaultInstance()
    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)
{
+31 −2
Original line number Diff line number Diff line
@@ -71,9 +71,34 @@ class MediaProfiles
{
public:

    /*
     * If property media.settings.xml is not set:
     *
     * getInstance() will search through paths listed in xmlFiles.
     * The search goes through members of xmlFiles in the order that they are
     * defined, so files at lower indices have higher priority than those at
     * higher indices.
     *
     * TODO: Add runtime validation of xml files. A search should be considered
     * successful only when validation is successful.
     */
    static constexpr char const * const xmlFiles[] = {
            "vendor/etc/media_profiles_V1_0.xml",
            "system/etc/media_profiles.xml"
            };

    /**
     * Returns the singleton instance for subsequence queries.
     * or NULL if error.
     * Returns the singleton instance for subsequence queries or NULL if error.
     *
     * If property media.settings.xml is set, getInstance() will attempt to read
     * from file path in media.settings.xml. Otherwise, getInstance() will
     * search through the list xmlFiles as described above.
     *
     * If the search is unsuccessful, the default instance will be created
     * instead.
     *
     * TODO: After validation is added, getInstance() should handle validation
     * failure properly.
     */
    static MediaProfiles* getInstance();

@@ -335,6 +360,10 @@ private:
    static void logVideoDecoderCap(const VideoDecoderCap& cap);
    static void logAudioDecoderCap(const AudioDecoderCap& cap);

    // Returns true if xmlFile exists.
    // TODO: Add runtime validation.
    static bool checkXmlFile(const char* xmlFile);

    // If the xml configuration file does exist, use the settings
    // from the xml
    static MediaProfiles* createInstanceFromXmlFile(const char *xml);