summaryrefslogtreecommitdiff
path: root/libplatformconfig
diff options
context:
space:
mode:
authorAmit Shekhar <ashekhar@codeaurora.org>2017-04-05 15:50:21 -0700
committerGerrit - the friendly Code Review server <code-review@localhost>2017-06-29 15:48:11 -0700
commit580a327f843357bdab331efda0865f8ad026ff07 (patch)
tree1e800acbb911e1510f4d37c970256142ed53ccd9 /libplatformconfig
parentaf2fe6ad921bac55e06c1379ad1d12a9b39549aa (diff)
downloadmedia-580a327f843357bdab331efda0865f8ad026ff07.tar.gz
media: Consolidates and implements XML based config reading
Consolidates system/session properties into platform specific configs which can be parsed during media codec process start and the property values can be used during component initialization. This can also be used to switch properties between video sessions - based on PL/test- scenario requirements by making modifications to the config file and "restarting" media codec process Change-Id: Ia16accec5716b2337722c1e2e276702c75775d75 CRs-Fixed: 2066348
Diffstat (limited to 'libplatformconfig')
-rw-r--r--libplatformconfig/Android.mk44
-rw-r--r--libplatformconfig/ConfigParser.cpp135
-rw-r--r--libplatformconfig/ConfigParser.h67
-rw-r--r--libplatformconfig/PlatformConfig.cpp75
-rw-r--r--libplatformconfig/PlatformConfig.h91
5 files changed, 412 insertions, 0 deletions
diff --git a/libplatformconfig/Android.mk b/libplatformconfig/Android.mk
new file mode 100644
index 00000000..a609447a
--- /dev/null
+++ b/libplatformconfig/Android.mk
@@ -0,0 +1,44 @@
+LOCAL_PATH := $(call my-dir)
+LOCAL_DIR_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_COPY_HEADERS_TO := libplatformconfig
+
+libplatformconfig-def := \
+ -g0 -O3 -fpic \
+ -Wno-deprecated-declarations -Werror \
+ -Wno-error=unused-variable \
+ -w -Wall -Wextra\
+ -fexceptions \
+ -Wno-missing-field-initializers \
+ -D_ANDROID_
+
+COMMON_CFLAGS := -O3
+
+include $(BUILD_COPY_HEADERS)
+
+LOCAL_CFLAGS := $(COMMON_CFLAGS) $(libplatformconfig-def)
+
+LOCAL_SHARED_LIBRARIES += \
+ libexpat \
+ liblog \
+ libcutils \
+ libutils
+
+LOCAL_STATIC_LIBRARIES := libOmxVidcCommon
+
+LOCAL_C_INCLUDES += \
+ external/expat/lib \
+ $(LOCAL_PATH)/../mm-core/inc \
+ $(LOCAL_PATH)/../mm-video-v4l2/vidc/common/inc/ \
+
+LOCAL_SRC_FILES := PlatformConfig.cpp
+LOCAL_SRC_FILES += ConfigParser.cpp
+
+LOCAL_MODULE := libplatformconfig
+LOCAL_VENDOR_MODULE := true
+
+LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/obj/lib
+LOCAL_ADDITIONAL_DEPENDENCIES := $(OUT)/obj/lib
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/libplatformconfig/ConfigParser.cpp b/libplatformconfig/ConfigParser.cpp
new file mode 100644
index 00000000..f7426e52
--- /dev/null
+++ b/libplatformconfig/ConfigParser.cpp
@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) 2017, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#define LOG_TAG "ConfigParser"
+
+#include <errno.h>
+#include <cutils/log.h>
+#include <sys/mman.h>
+#include "vidc_debug.h"
+#include "PlatformConfig.h"
+#include "ConfigParser.h"
+
+namespace Platform {
+
+#define BUF_SIZE 1024
+
+void ConfigParser::processProperty(const XML_Char **attr, ConfigMap &configMap) {
+ if (strcmp(attr[0], "name") != 0) {
+ DEBUG_PRINT_HIGH("%s: Element 'name' not found!", __func__);
+ return;
+ }
+
+ std::string propName(attr[1]);
+
+ if (strcmp(attr[2], "value") != 0) {
+ DEBUG_PRINT_HIGH("%s: Element 'value' not found for %s!", __func__, propName.c_str());
+ return;
+ }
+
+ std::string propValue(attr[3]);
+
+ configMap[propName] = propValue;
+
+ return;
+}
+
+void ConfigParser::startTag(void *userdata, const XML_Char *tagName,
+ const XML_Char **attr) {
+ if (strcmp(tagName, "property") == 0) {
+ processProperty(attr, *static_cast<ConfigMap *>(userdata));
+ }
+ return;
+}
+
+void ConfigParser::endTag(void *userdata __unused, const XML_Char *tagName __unused) {
+ return;
+}
+
+int ConfigParser::initAndParse(std::string configFile, ConfigMap &configMap) {
+ int err = 1;
+ XML_Parser parser;
+ FILE *file;
+ file = fopen(configFile.c_str(), "r");
+ if (!file) {
+ DEBUG_PRINT_HIGH("%s: Error: %d (%s). Using defaults!",
+ __func__, errno, strerror(errno));
+ return err;
+ }
+
+ // Create Parser
+ parser = XML_ParserCreate(NULL);
+ if (!parser) {
+ DEBUG_PRINT_HIGH("%s: Failed to create XML parser!", __func__);
+ err = -ENODEV;
+ goto fileError;
+ }
+
+ // Set XML element handlers
+ XML_SetUserData(parser, &configMap);
+ XML_SetElementHandler(parser, startTag, endTag);
+ void *buf;
+ int bytesRead;
+
+ // Parse
+ while (1) {
+ buf = XML_GetBuffer(parser, BUF_SIZE);
+ if (buf == NULL) {
+ DEBUG_PRINT_HIGH("%s: XML_GetBuffer failed", __func__);
+ err = -ENOMEM;
+ goto parserError;
+ }
+
+ bytesRead = fread(buf, 1, BUF_SIZE, file);
+ if (bytesRead < 0) {
+ DEBUG_PRINT_HIGH("%s: fread failed, bytes read = %d", __func__, bytesRead);
+ err = bytesRead;
+ goto parserError;
+ }
+
+ if (XML_ParseBuffer(parser, bytesRead,
+ bytesRead == 0) == XML_STATUS_ERROR) {
+ DEBUG_PRINT_HIGH("%s: XML_ParseBuffer failed, for %s",
+ __func__, configFile.c_str());
+ err = -EINVAL;
+ goto parserError;
+ }
+ if (bytesRead == 0)
+ break;
+ }
+
+ // Free parser and close file in error/ at exit
+ parserError:
+ XML_ParserFree(parser);
+ fileError:
+ fclose(file);
+ return err;
+}
+
+}
diff --git a/libplatformconfig/ConfigParser.h b/libplatformconfig/ConfigParser.h
new file mode 100644
index 00000000..addf0920
--- /dev/null
+++ b/libplatformconfig/ConfigParser.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2017, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __CONFIG_PARSER_H__
+#define __CONFIG_PARSER_H__
+
+//////////////////////////////////////////////////////////////////////////////
+// Include Files
+//////////////////////////////////////////////////////////////////////////////
+#include <string>
+#include <expat.h>
+#include <cutils/log.h>
+#include <sys/types.h>
+#include <errno.h>
+#include <map>
+
+#define BUF_SIZE 1024
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+namespace Platform {
+
+class ConfigParser {
+ private:
+ static void processProperty(const XML_Char **attr, ConfigMap &confMap);
+ static void endTag(void *userdata __unused, const XML_Char *tagName __unused);
+ static void startTag(void *userdata, const XML_Char *tagName,
+ const XML_Char **attr);
+ ConfigParser() { }
+ public:
+ static std::string propFile;
+ static int initAndParse(std::string propFile, ConfigMap &confMap);
+};
+
+}
+#ifdef __cplusplus
+}
+#endif
+#endif // __CONFIG_PARSER_H__
diff --git a/libplatformconfig/PlatformConfig.cpp b/libplatformconfig/PlatformConfig.cpp
new file mode 100644
index 00000000..0636c1bc
--- /dev/null
+++ b/libplatformconfig/PlatformConfig.cpp
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2017, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#define LOG_TAG "PlatformConfig"
+
+#include <errno.h>
+#include <cutils/log.h>
+#include <sys/mman.h>
+#include "vidc_debug.h"
+#include "PlatformConfig.h"
+#include "ConfigParser.h"
+
+namespace Platform {
+
+#define PLAT_CONFIG_FILE "vendor/etc/system_properties.xml"
+
+Config* Config::mInstance;
+
+Config::Config() {
+ Platform::ConfigParser::initAndParse(PLAT_CONFIG_FILE, mConfigMap);
+}
+
+Config* Config::getInstance() {
+ DEBUG_PRINT_LOW("%s: Enter", __func__);
+ if (!mInstance) {
+ mInstance = new Config();
+ }
+ return mInstance;
+}
+
+ConfigError_t Config::getInt32(Config_t config, int32_t *value,
+ const int32_t defaultValue) {
+ Config *conf = getInstance();
+ if (conf == nullptr) {
+ *value = defaultValue;
+ return FAIL;
+ }
+ if (conf->mConfigMap.find(configStrMap[config].name) == conf->mConfigMap.end()) {
+ DEBUG_PRINT_HIGH("%s: Returning default", __func__);
+ *value = defaultValue;
+ return FAIL;
+ }
+ *value = (int32_t) atoi(conf->mConfigMap[configStrMap[config].name].c_str());
+ DEBUG_PRINT_LOW("%s Config name: %s value: %d",
+ __func__, configStrMap[config].name, *value);
+ return OK;
+}
+
+}
diff --git a/libplatformconfig/PlatformConfig.h b/libplatformconfig/PlatformConfig.h
new file mode 100644
index 00000000..72776bc9
--- /dev/null
+++ b/libplatformconfig/PlatformConfig.h
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2017, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __PLATFORM_CONFIG_H__
+#define __PLATFORM_CONFIG_H__
+
+//////////////////////////////////////////////////////////////////////////////
+// Include Files
+//////////////////////////////////////////////////////////////////////////////
+#include <string>
+#include <map>
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+namespace Platform {
+
+typedef std::map<std::string, std::string> ConfigMap;
+
+typedef enum {
+ OK = 0,
+ FAIL = 1,
+} ConfigError_t;
+
+typedef enum {
+ vidc_dec_log_in = 0,
+ vidc_dec_log_out,
+ vidc_enc_log_in,
+ vidc_enc_log_out
+} Config_t;
+
+struct configStr {
+ Config_t config;
+ const char * name;
+};
+
+static const struct configStr configStrMap[] = {
+ {vidc_dec_log_in, "vidc_dec_log_in"},
+ {vidc_dec_log_out, "vidc_dec_log_out"},
+ {vidc_enc_log_in, "vidc_enc_log_in"},
+ {vidc_enc_log_out, "vidc_enc_log_out"}
+};
+
+class Config {
+ private:
+ Config();
+ Config& operator=(Config const&) {
+ return *mInstance;
+ }
+ static Config* getInstance();
+
+ ConfigMap mConfigMap;
+ static Config* mInstance;
+
+ public:
+ static ConfigError_t getInt32(Config_t config, int32_t *value,
+ const int32_t defaultValue);
+};
+
+}
+#ifdef __cplusplus
+}
+#endif
+#endif // __PLATFORM_CONFIG_H__