xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1 | #include "AudioParamParser.h" |
| 2 | #include <math.h> |
| 3 | |
| 4 | #ifdef WIN32 |
| 5 | #ifdef __cplusplus |
| 6 | #define EXPORT extern "C" __declspec(dllexport) |
| 7 | #else |
| 8 | #define EXPORT __declspec(dllexport) |
| 9 | #endif |
| 10 | #include <process.h> |
| 11 | #include <Windows.h> |
| 12 | #include <direct.h> |
| 13 | #else /* WIN32*/ |
| 14 | #define EXPORT |
| 15 | #ifdef __cplusplus |
| 16 | extern "C" { |
| 17 | #endif |
| 18 | #include <errno.h> |
| 19 | #include <sys/stat.h> |
| 20 | #include <sys/inotify.h> |
| 21 | #include <unistd.h> |
| 22 | #include <signal.h> |
| 23 | #include <utils/Timers.h> |
| 24 | #endif |
| 25 | |
| 26 | #ifdef __linux__ |
| 27 | #define FOLDER "/" |
| 28 | #else |
| 29 | #define FOLDER "\\" |
| 30 | #endif |
| 31 | |
| 32 | extern FILE *appLogFp; |
| 33 | extern int outputLogToStdout; |
| 34 | |
| 35 | #ifdef WIN32 |
| 36 | #define ERR_LOG(format, ...) \ |
| 37 | if(appDebugLevel <= ERR_LEVEL) \ |
| 38 | utilLog("ERROR[%d,%d](): %s(), "format"\n^^^^\n", _getpid(), GetCurrentThreadId(), __FUNCTION__, __VA_ARGS__) |
| 39 | |
| 40 | #define WARN_LOG(format, ...) \ |
| 41 | if(appDebugLevel <= WARN_LEVEL) \ |
| 42 | utilLog("WARNING[%d,%d]: %s(), "format, _getpid(), GetCurrentThreadId(), __FUNCTION__, __VA_ARGS__) |
| 43 | |
| 44 | #define INFO_LOG(format, ...) \ |
| 45 | if(appDebugLevel <= INFO_LEVEL) \ |
| 46 | utilLog("INFO[%d,%d]: %s(), "format, _getpid(), GetCurrentThreadId(), __FUNCTION__, __VA_ARGS__) |
| 47 | |
| 48 | #define DEBUG_LOG(format, ...) \ |
| 49 | if(appDebugLevel <= DEBUG_LEVEL) \ |
| 50 | utilLog("DEBUG[%d,%d]: %s(), "format, _getpid(), GetCurrentThreadId(), __FUNCTION__, __VA_ARGS__) |
| 51 | |
| 52 | #else /* WIN32 */ |
| 53 | #define LOG_TAG "AudioParamParser" |
| 54 | |
| 55 | #define ERR_LOG(format, args...) \ |
| 56 | if(appDebugLevel <= ERR_LEVEL) \ |
| 57 | printf("%s(), "format, __FUNCTION__, ##args) |
| 58 | |
| 59 | #define WARN_LOG(format, args...) \ |
| 60 | if(appDebugLevel <= WARN_LEVEL) \ |
| 61 | printf("%s(), "format, __FUNCTION__, ##args) |
| 62 | |
| 63 | #define INFO_LOG(format, args...) \ |
| 64 | if(appDebugLevel <= INFO_LEVEL) \ |
| 65 | printf("%s(), "format, __FUNCTION__, ##args) |
| 66 | |
| 67 | #define DEBUG_LOG(format, args...) \ |
| 68 | if(appDebugLevel <= DEBUG_LEVEL) \ |
| 69 | printf("%s(), "format, __FUNCTION__, ##args) |
| 70 | |
| 71 | #endif |
| 72 | |
| 73 | /* Force adding following category group info and bypass categoryGroup path checking */ |
| 74 | static const char *HARD_CATEGORY_GROUP[][3] = |
| 75 | { |
| 76 | /* {AudioTypeName, CategoryTypeName, CategoryGroupName} */ |
| 77 | {"Speech", "Band", "NB"}, |
| 78 | {"Speech", "Band", "WB"}, |
| 79 | {NULL, NULL, NULL} |
| 80 | }; |
| 81 | |
| 82 | /*********************** |
| 83 | * Private APIs |
| 84 | **********************/ |
| 85 | /* appHandle API */ |
| 86 | EXPORT APP_STATUS appHandleLoadDirAudioTypeInfo(AppHandle *appHandle); |
| 87 | EXPORT APP_STATUS appHandleLoadAllAudioTypeXml(AppHandle *appHandle); |
| 88 | EXPORT APP_STATUS appHandleLoadAudioTypeXml(AppHandle *appHandle, AudioType *audioType); |
| 89 | EXPORT int appHandleIsValidAudioType(AppHandle *appHandle, const char *audioType); |
| 90 | EXPORT AudioType *appHandleAddAudioType(AppHandle *appHandle, const char *audioType); |
| 91 | EXPORT AudioType *appHandleGetAudioType(AppHandle *appHandle, size_t index); |
| 92 | EXPORT void appHandleReleaseAudioTypeHash(AppHandle *appHandle); |
| 93 | EXPORT APP_STATUS appHandleLoadDirFeatureOptionsInfo(AppHandle *appHandle); |
| 94 | EXPORT void appHandleReleaseFeatureOptionsHash(AppHandle *appHandle); |
| 95 | EXPORT void appHandleDumpAudioTypeList(AppHandle *appHandle); |
| 96 | EXPORT char *appHandleGetAudioTypeFilePath(AppHandle *appHandle, const char *audioType, const char *posfix); |
| 97 | EXPORT char *appHandleGetPreloadAudioTypeFilePath(AppHandle *appHandle, const char *audioType, const char *posfix); |
| 98 | EXPORT APP_STATUS appHandleLoadAllAudioTypeHash(AppHandle *appHandle); |
| 99 | EXPORT void *appHandleThreadLoop(void *arg); |
| 100 | EXPORT int appHandleWriteLock(AppHandle *appHandle, const char *callerFun); |
| 101 | EXPORT int appHandleReadLock(AppHandle *appHandle, const char *callerFun); |
| 102 | EXPORT int appHandleUnlock(AppHandle *appHandle); |
| 103 | EXPORT int appHandleInstWriteLock(const char *callerFun); |
| 104 | EXPORT int appHandleInstUnlock(void); |
| 105 | EXPORT void appHandleReviseXmlDocByFeatureOptions(AppHandle *appHandle); |
| 106 | EXPORT APP_STATUS appHandleGetAudioTypeSupportedVerInfo(const char* audioTypeName, int* paramUnitDescVerMaj, int* paramUnitDescVerMin, int* audioParamVerMaj, int* audioParamVerMin); |
| 107 | EXPORT void appHandleShowAudioTypeSupportedVerInfo(AppHandle *appHandle); |
| 108 | |
| 109 | /* AudioType API */ |
| 110 | EXPORT AudioType *audioTypeCreate(AppHandle *appHandle, const char *audioTypeName); |
| 111 | EXPORT void audioTypeRelease(AudioType *audioType); |
| 112 | EXPORT void audioTypeReleaseAudioParam(AudioType *audioType); |
| 113 | EXPORT void audioTypeDump(AudioType *audioType); |
| 114 | EXPORT APP_STATUS audioTypeParseTabName(AudioType *audioType); |
| 115 | EXPORT APP_STATUS audioTypeLoadStage1Hash(AudioType *audioType); |
| 116 | EXPORT APP_STATUS audioTypeLoadStage2Hash(AudioType *audioType); |
| 117 | EXPORT APP_STATUS audioTypeLoadParamTreeHash(AudioType *audioType); |
| 118 | EXPORT APP_STATUS audioTypeLoadParamTreeView(AudioType *audioType); |
| 119 | EXPORT APP_STATUS audioTypeLoadParamUnitHash(AudioType *audioType); |
| 120 | EXPORT Param *audioTypeGetParamHash(AudioType *audioType, xmlNode *paramUnitNode); |
| 121 | EXPORT APP_STATUS audioTypeParseXmlVer(AudioType *audioType); |
| 122 | EXPORT APP_STATUS audioTypeLoadParamFieldInfoHash(AudioType *audioType); |
| 123 | EXPORT APP_STATUS audioTypeLoadCategoryTypeHash(AudioType *audioType); |
| 124 | EXPORT size_t audioTypeGetNumOfParamTree(AudioType *audioType); |
| 125 | EXPORT APP_STATUS audioTypeValidCategoryGroupName(AudioType *audioType, const char *name); |
| 126 | EXPORT int audioTypeIsHardCategoryGroup(AudioType *audioType, const char *categoryName); |
| 127 | |
| 128 | /* CategoryType API */ |
| 129 | EXPORT CategoryType *categoryTypeCreate(const char *name, const char *wording, AudioType *audioType, int visible); |
| 130 | EXPORT void categoryTypeRelease(CategoryType *categoryType); |
| 131 | EXPORT CategoryAlias *categoryTypeGetCategoryByAlias(CategoryType *categoryType, const char *alias); |
| 132 | EXPORT Category *categoryTypeGetCategoryByName(CategoryType *categoryType, const char *name); |
| 133 | |
| 134 | /* CategoryGroup API */ |
| 135 | EXPORT CategoryGroup *categoryGroupCreate(const char *categoryGroupName, const char *categoryGroupWording, CategoryType *categoryType, int visible); |
| 136 | EXPORT void categoryGroupRelease(CategoryGroup *categoryGroup); |
| 137 | |
| 138 | /* Category API */ |
| 139 | EXPORT Category *categoryCreate(const char *name, const char *wording, CATEGORY_PARENT_TYPE parentTypeIsCategoryType, void *parent, int visible); |
| 140 | EXPORT void categoryRelease(Category *category); |
| 141 | |
| 142 | /* ParamTree API */ |
| 143 | EXPORT ParamTree *paramTreeCreate(int paramId, const char *categoryPath); |
| 144 | EXPORT void paramTreeRelease(ParamTree *paramTree); |
| 145 | EXPORT size_t paramTreeGetNumOfParam(ParamTree *paramTree); |
| 146 | |
| 147 | /* ParamUnit API */ |
| 148 | EXPORT ParamUnit *paramUnitCreate(AudioType *audioType, int id, Param *param); |
| 149 | EXPORT ParamUnit *paramUnitClone(ParamUnit *paramUnit); |
| 150 | EXPORT void paramUnitRelease(ParamUnit *paramUnit); |
| 151 | |
| 152 | /* ParamInfo API */ |
| 153 | EXPORT ParamInfo *paramInfoCreate(const char *name, DATA_TYPE dataType, AudioType *audioType); |
| 154 | EXPORT void paramInfoRelease(ParamInfo *paramInfo); |
| 155 | |
| 156 | /* FieldInfo API */ |
| 157 | EXPORT FieldInfo *fieldInfoCreate(const char *fieldName, unsigned int arrayIndex, int startBit, int endBit, const char *checkList, ParamInfo *paramInfo); |
| 158 | EXPORT void fieldInfoRelease(FieldInfo *paramInfo); |
| 159 | |
| 160 | /* Param API */ |
| 161 | EXPORT Param *paramCreate(const char *paramName, ParamInfo *paramInfo, const char *paramValue); |
| 162 | EXPORT void paramRelease(Param *param); |
| 163 | EXPORT APP_STATUS paramSetupDataInfoByStr(Param *param, const char *str); |
| 164 | EXPORT APP_STATUS paramSetupDataInfoByVal(Param *param, void *data, int arraySize); |
| 165 | EXPORT Param *paramHashClone(Param *paramHash); |
| 166 | |
| 167 | /* ParamTreeView API */ |
| 168 | EXPORT ParamTreeView *paramTreeViewCreate(AudioType *audioType, int verMaj, int verMin); |
| 169 | EXPORT void paramTreeViewRelease(ParamTreeView *paramTreeView); |
| 170 | EXPORT TreeRoot *treeRootCreate(const char *name, xmlNode *treeRootNode, ParamTreeView *paramTreeView); |
| 171 | EXPORT void treeRootRelease(TreeRoot *treeRoot); |
| 172 | EXPORT Feature *featureCreate(const char *name, AudioType *audioType, FieldInfo *switchFieldInfo, const char *featureOption); |
| 173 | EXPORT void featureRelease(Feature *feature); |
| 174 | EXPORT CategoryPath *categoryPathCreate(Feature *feature, const char *path); |
| 175 | EXPORT void categoryPathRelease(CategoryPath *categoryPath); |
| 176 | EXPORT APP_STATUS categoryPathValidation(CategoryPath *categoryPath); |
| 177 | EXPORT FeatureField *featureFieldCreate(FieldInfo *fieldInfo); |
| 178 | EXPORT void featureFieldRelease(FeatureField *featureField); |
| 179 | |
| 180 | /* Feature Options API */ |
| 181 | EXPORT FeatureOption *featureOptionCreate(const char *name, const char *value); |
| 182 | EXPORT void featureOptionRelease(FeatureOption *featureOption); |
| 183 | |
| 184 | /* Utils API */ |
| 185 | EXPORT char *utilConvDataToString(DATA_TYPE dataType, void *data, int arraySize); |
| 186 | EXPORT UT_string *utilNormalizeCategoryPathForAudioType(const char *categoryPath, AudioType *audioType); |
| 187 | EXPORT UT_string *utilNormalizeCategoryGroupPathForAudioType(const char *categoryPath, AudioType *audioType); |
| 188 | EXPORT int utilFindUnusedParamId(AudioType *audioType); |
| 189 | EXPORT void utilUsleep(unsigned int usec); |
| 190 | EXPORT void utilLog(char *str, ...); |
| 191 | EXPORT void utilLogClose(void); |
| 192 | EXPORT FieldInfo *utilXmlNodeGetFieldInfo(AppHandle *appHandle, xmlNode *node, const char *audioTypeAttrName, const char *paramAttrName, const char *fieldAttrName); |
| 193 | EXPORT void appDumpXmlDoc(xmlDoc *doc); |
| 194 | EXPORT void redirectIOToConsole(void); |
| 195 | EXPORT void utilMkdir(const char *dir); |
| 196 | EXPORT void utilShowParamValue(Param *param); |
| 197 | EXPORT char *utilGenCheckList(int bits); |
| 198 | EXPORT int utilCompNormalizeCategoryPath(AudioType *audioType, const char *srcCategoryPath, const char *dstCategoryPath); |
| 199 | EXPORT int isCustXmlEnable(void); |
| 200 | EXPORT void utilShellExecute(const char* prog, const char* params); |
| 201 | #ifndef WIN32 |
| 202 | EXPORT void signalHandler(int sig, siginfo_t *info, void *ucontext); |
| 203 | #endif |
| 204 | |
| 205 | /* Unit Test */ |
| 206 | EXPORT void testDebugLevel(void); |
| 207 | EXPORT void testHashParamTree(void); |
| 208 | EXPORT void testHashParamUnit(void); |
| 209 | EXPORT void testHashParam(void); |
| 210 | EXPORT APP_STATUS testReadWriteParam(AppHandle *appHandle); |
| 211 | EXPORT APP_STATUS testMemoryLeak(AppHandle *appHandle); |
| 212 | EXPORT APP_STATUS testAudioTypeLock(AppHandle *appHandle); |
| 213 | EXPORT APP_STATUS testAppHandleInitUninit(void); |
| 214 | EXPORT void inotifyTest(const char *path); |
| 215 | EXPORT void notifyCbTest(AppHandle *appHandle); |
| 216 | |
| 217 | #ifndef WIN32 |
| 218 | #ifdef __cplusplus |
| 219 | } |
| 220 | #endif |
| 221 | #endif |