blob: bef01c1fa7787229f52ed4b5dde8aaccc1d1348c [file] [log] [blame]
xjb04a4022021-11-25 15:01:52 +08001#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
16extern "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
32extern FILE *appLogFp;
33extern 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 */
74static 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 */
86EXPORT APP_STATUS appHandleLoadDirAudioTypeInfo(AppHandle *appHandle);
87EXPORT APP_STATUS appHandleLoadAllAudioTypeXml(AppHandle *appHandle);
88EXPORT APP_STATUS appHandleLoadAudioTypeXml(AppHandle *appHandle, AudioType *audioType);
89EXPORT int appHandleIsValidAudioType(AppHandle *appHandle, const char *audioType);
90EXPORT AudioType *appHandleAddAudioType(AppHandle *appHandle, const char *audioType);
91EXPORT AudioType *appHandleGetAudioType(AppHandle *appHandle, size_t index);
92EXPORT void appHandleReleaseAudioTypeHash(AppHandle *appHandle);
93EXPORT APP_STATUS appHandleLoadDirFeatureOptionsInfo(AppHandle *appHandle);
94EXPORT void appHandleReleaseFeatureOptionsHash(AppHandle *appHandle);
95EXPORT void appHandleDumpAudioTypeList(AppHandle *appHandle);
96EXPORT char *appHandleGetAudioTypeFilePath(AppHandle *appHandle, const char *audioType, const char *posfix);
97EXPORT char *appHandleGetPreloadAudioTypeFilePath(AppHandle *appHandle, const char *audioType, const char *posfix);
98EXPORT APP_STATUS appHandleLoadAllAudioTypeHash(AppHandle *appHandle);
99EXPORT void *appHandleThreadLoop(void *arg);
100EXPORT int appHandleWriteLock(AppHandle *appHandle, const char *callerFun);
101EXPORT int appHandleReadLock(AppHandle *appHandle, const char *callerFun);
102EXPORT int appHandleUnlock(AppHandle *appHandle);
103EXPORT int appHandleInstWriteLock(const char *callerFun);
104EXPORT int appHandleInstUnlock(void);
105EXPORT void appHandleReviseXmlDocByFeatureOptions(AppHandle *appHandle);
106EXPORT APP_STATUS appHandleGetAudioTypeSupportedVerInfo(const char* audioTypeName, int* paramUnitDescVerMaj, int* paramUnitDescVerMin, int* audioParamVerMaj, int* audioParamVerMin);
107EXPORT void appHandleShowAudioTypeSupportedVerInfo(AppHandle *appHandle);
108
109/* AudioType API */
110EXPORT AudioType *audioTypeCreate(AppHandle *appHandle, const char *audioTypeName);
111EXPORT void audioTypeRelease(AudioType *audioType);
112EXPORT void audioTypeReleaseAudioParam(AudioType *audioType);
113EXPORT void audioTypeDump(AudioType *audioType);
114EXPORT APP_STATUS audioTypeParseTabName(AudioType *audioType);
115EXPORT APP_STATUS audioTypeLoadStage1Hash(AudioType *audioType);
116EXPORT APP_STATUS audioTypeLoadStage2Hash(AudioType *audioType);
117EXPORT APP_STATUS audioTypeLoadParamTreeHash(AudioType *audioType);
118EXPORT APP_STATUS audioTypeLoadParamTreeView(AudioType *audioType);
119EXPORT APP_STATUS audioTypeLoadParamUnitHash(AudioType *audioType);
120EXPORT Param *audioTypeGetParamHash(AudioType *audioType, xmlNode *paramUnitNode);
121EXPORT APP_STATUS audioTypeParseXmlVer(AudioType *audioType);
122EXPORT APP_STATUS audioTypeLoadParamFieldInfoHash(AudioType *audioType);
123EXPORT APP_STATUS audioTypeLoadCategoryTypeHash(AudioType *audioType);
124EXPORT size_t audioTypeGetNumOfParamTree(AudioType *audioType);
125EXPORT APP_STATUS audioTypeValidCategoryGroupName(AudioType *audioType, const char *name);
126EXPORT int audioTypeIsHardCategoryGroup(AudioType *audioType, const char *categoryName);
127
128/* CategoryType API */
129EXPORT CategoryType *categoryTypeCreate(const char *name, const char *wording, AudioType *audioType, int visible);
130EXPORT void categoryTypeRelease(CategoryType *categoryType);
131EXPORT CategoryAlias *categoryTypeGetCategoryByAlias(CategoryType *categoryType, const char *alias);
132EXPORT Category *categoryTypeGetCategoryByName(CategoryType *categoryType, const char *name);
133
134/* CategoryGroup API */
135EXPORT CategoryGroup *categoryGroupCreate(const char *categoryGroupName, const char *categoryGroupWording, CategoryType *categoryType, int visible);
136EXPORT void categoryGroupRelease(CategoryGroup *categoryGroup);
137
138/* Category API */
139EXPORT Category *categoryCreate(const char *name, const char *wording, CATEGORY_PARENT_TYPE parentTypeIsCategoryType, void *parent, int visible);
140EXPORT void categoryRelease(Category *category);
141
142/* ParamTree API */
143EXPORT ParamTree *paramTreeCreate(int paramId, const char *categoryPath);
144EXPORT void paramTreeRelease(ParamTree *paramTree);
145EXPORT size_t paramTreeGetNumOfParam(ParamTree *paramTree);
146
147/* ParamUnit API */
148EXPORT ParamUnit *paramUnitCreate(AudioType *audioType, int id, Param *param);
149EXPORT ParamUnit *paramUnitClone(ParamUnit *paramUnit);
150EXPORT void paramUnitRelease(ParamUnit *paramUnit);
151
152/* ParamInfo API */
153EXPORT ParamInfo *paramInfoCreate(const char *name, DATA_TYPE dataType, AudioType *audioType);
154EXPORT void paramInfoRelease(ParamInfo *paramInfo);
155
156/* FieldInfo API */
157EXPORT FieldInfo *fieldInfoCreate(const char *fieldName, unsigned int arrayIndex, int startBit, int endBit, const char *checkList, ParamInfo *paramInfo);
158EXPORT void fieldInfoRelease(FieldInfo *paramInfo);
159
160/* Param API */
161EXPORT Param *paramCreate(const char *paramName, ParamInfo *paramInfo, const char *paramValue);
162EXPORT void paramRelease(Param *param);
163EXPORT APP_STATUS paramSetupDataInfoByStr(Param *param, const char *str);
164EXPORT APP_STATUS paramSetupDataInfoByVal(Param *param, void *data, int arraySize);
165EXPORT Param *paramHashClone(Param *paramHash);
166
167/* ParamTreeView API */
168EXPORT ParamTreeView *paramTreeViewCreate(AudioType *audioType, int verMaj, int verMin);
169EXPORT void paramTreeViewRelease(ParamTreeView *paramTreeView);
170EXPORT TreeRoot *treeRootCreate(const char *name, xmlNode *treeRootNode, ParamTreeView *paramTreeView);
171EXPORT void treeRootRelease(TreeRoot *treeRoot);
172EXPORT Feature *featureCreate(const char *name, AudioType *audioType, FieldInfo *switchFieldInfo, const char *featureOption);
173EXPORT void featureRelease(Feature *feature);
174EXPORT CategoryPath *categoryPathCreate(Feature *feature, const char *path);
175EXPORT void categoryPathRelease(CategoryPath *categoryPath);
176EXPORT APP_STATUS categoryPathValidation(CategoryPath *categoryPath);
177EXPORT FeatureField *featureFieldCreate(FieldInfo *fieldInfo);
178EXPORT void featureFieldRelease(FeatureField *featureField);
179
180/* Feature Options API */
181EXPORT FeatureOption *featureOptionCreate(const char *name, const char *value);
182EXPORT void featureOptionRelease(FeatureOption *featureOption);
183
184/* Utils API */
185EXPORT char *utilConvDataToString(DATA_TYPE dataType, void *data, int arraySize);
186EXPORT UT_string *utilNormalizeCategoryPathForAudioType(const char *categoryPath, AudioType *audioType);
187EXPORT UT_string *utilNormalizeCategoryGroupPathForAudioType(const char *categoryPath, AudioType *audioType);
188EXPORT int utilFindUnusedParamId(AudioType *audioType);
189EXPORT void utilUsleep(unsigned int usec);
190EXPORT void utilLog(char *str, ...);
191EXPORT void utilLogClose(void);
192EXPORT FieldInfo *utilXmlNodeGetFieldInfo(AppHandle *appHandle, xmlNode *node, const char *audioTypeAttrName, const char *paramAttrName, const char *fieldAttrName);
193EXPORT void appDumpXmlDoc(xmlDoc *doc);
194EXPORT void redirectIOToConsole(void);
195EXPORT void utilMkdir(const char *dir);
196EXPORT void utilShowParamValue(Param *param);
197EXPORT char *utilGenCheckList(int bits);
198EXPORT int utilCompNormalizeCategoryPath(AudioType *audioType, const char *srcCategoryPath, const char *dstCategoryPath);
199EXPORT int isCustXmlEnable(void);
200EXPORT void utilShellExecute(const char* prog, const char* params);
201#ifndef WIN32
202EXPORT void signalHandler(int sig, siginfo_t *info, void *ucontext);
203#endif
204
205/* Unit Test */
206EXPORT void testDebugLevel(void);
207EXPORT void testHashParamTree(void);
208EXPORT void testHashParamUnit(void);
209EXPORT void testHashParam(void);
210EXPORT APP_STATUS testReadWriteParam(AppHandle *appHandle);
211EXPORT APP_STATUS testMemoryLeak(AppHandle *appHandle);
212EXPORT APP_STATUS testAudioTypeLock(AppHandle *appHandle);
213EXPORT APP_STATUS testAppHandleInitUninit(void);
214EXPORT void inotifyTest(const char *path);
215EXPORT void notifyCbTest(AppHandle *appHandle);
216
217#ifndef WIN32
218#ifdef __cplusplus
219}
220#endif
221#endif