rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | #include "AudioParamParserPriv.h" |
| 2 | |
| 3 | EXPORT ParamUnit *paramUnitCreate(AudioType *audioType, int id, Param *param) |
| 4 | { |
| 5 | size_t numOfParam, i; |
| 6 | ParamUnit *paramUnit = (ParamUnit *)malloc(sizeof(ParamUnit)); |
| 7 | paramUnit->paramId = id; |
| 8 | paramUnit->refCount = 0; |
| 9 | paramUnit->audioType = audioType; |
| 10 | paramUnit->paramHash = param; |
| 11 | |
| 12 | /* Update param's param unit info */ |
| 13 | numOfParam = paramUnitGetNumOfParam(paramUnit); |
| 14 | for (i = 0; i < numOfParam; i++) |
| 15 | { |
| 16 | Param *param = paramUnitGetParamByIndex(paramUnit, i); |
| 17 | param->paramUnit = paramUnit; |
| 18 | } |
| 19 | |
| 20 | return paramUnit; |
| 21 | } |
| 22 | |
| 23 | EXPORT ParamUnit *paramUnitClone(ParamUnit *oldParamUnit) |
| 24 | { |
| 25 | Param *item; |
| 26 | ParamUnit *paramUnit; |
| 27 | |
| 28 | if (!oldParamUnit) |
| 29 | { |
| 30 | ERR_LOG("Original ParamUnit is NULL\n"); |
| 31 | return NULL; |
| 32 | } |
| 33 | |
| 34 | paramUnit = (ParamUnit *)malloc(sizeof(ParamUnit)); |
| 35 | paramUnit->paramId = oldParamUnit->paramId; |
| 36 | paramUnit->refCount = oldParamUnit->refCount; |
| 37 | paramUnit->audioType = oldParamUnit->audioType; |
| 38 | paramUnit->paramHash = paramHashClone(oldParamUnit->paramHash); |
| 39 | |
| 40 | /* Update param's param unit info */ |
| 41 | if (paramUnit->paramHash) |
| 42 | { |
| 43 | for (item = paramUnit->paramHash; item != NULL; item = item->hh.next) |
| 44 | { |
| 45 | item->paramUnit = paramUnit; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | return paramUnit; |
| 50 | } |
| 51 | |
| 52 | EXPORT void paramUnitRelease(ParamUnit *paramUnit) |
| 53 | { |
| 54 | if (paramUnit) |
| 55 | { |
| 56 | /* Free ParamUnit's param hash */ |
| 57 | if (paramUnit->paramHash) |
| 58 | { |
| 59 | Param *tmp, *item; |
| 60 | HASH_ITER(hh, paramUnit->paramHash, item, tmp) |
| 61 | { |
| 62 | HASH_DEL(paramUnit->paramHash, item); |
| 63 | paramRelease(item); |
| 64 | } |
| 65 | free(paramUnit->paramHash); |
| 66 | } |
| 67 | free(paramUnit); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | EXPORT size_t paramUnitGetNumOfParam(ParamUnit *paramUnit) |
| 72 | { |
| 73 | if (!paramUnit) |
| 74 | { |
| 75 | ERR_LOG("paramUnit is NULL!\n"); |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | return HASH_COUNT(paramUnit->paramHash); |
| 80 | } |
| 81 | |
| 82 | EXPORT Param *paramUnitGetParamByIndex(ParamUnit *paramUnit, size_t index) |
| 83 | { |
| 84 | Param *param = NULL; |
| 85 | size_t i = 0; |
| 86 | |
| 87 | if (!paramUnit) |
| 88 | { |
| 89 | ERR_LOG("paramUnit is NULL!\n"); |
| 90 | return NULL; |
| 91 | } |
| 92 | |
| 93 | for (param = paramUnit->paramHash; param ; param = param->hh.next) |
| 94 | { |
| 95 | if (index == i++) |
| 96 | { |
| 97 | return param; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | return NULL; |
| 102 | } |
| 103 | |
| 104 | EXPORT Param *paramUnitGetParamByName(ParamUnit *paramUnit, const char *name) |
| 105 | { |
| 106 | Param *param = NULL; |
| 107 | |
| 108 | INFO_LOG("name = %s\n", name); |
| 109 | if (!paramUnit) |
| 110 | { |
| 111 | ERR_LOG("paramUnit is NULL!\n"); |
| 112 | return NULL; |
| 113 | } |
| 114 | |
| 115 | HASH_FIND_STR(paramUnit->paramHash, name, param); |
| 116 | |
| 117 | if (param && appDebugLevel <= DEBUG_LEVEL) |
| 118 | { |
| 119 | utilShowParamValue(param); |
| 120 | } |
| 121 | |
| 122 | DEBUG_LOG("name = %s, param data = 0x%p, size = %d\n", name, param ? param->data : NULL, param ? param->arraySize : NULL); |
| 123 | return param; |
| 124 | } |
| 125 | |
| 126 | |
| 127 | EXPORT APP_STATUS paramUnitGetFieldVal(ParamUnit *paramUnit, const char *paramName, const char *fieldName, unsigned int *val) |
| 128 | { |
| 129 | ParamInfo *paramInfo; |
| 130 | FieldInfo *fieldInfo; |
| 131 | Param *param; |
| 132 | |
| 133 | if (!paramUnit) |
| 134 | { |
| 135 | ERR_LOG("paramUnit is NULL!\n"); |
| 136 | return APP_ERROR; |
| 137 | } |
| 138 | |
| 139 | /* Query field Info */ |
| 140 | paramInfo = audioTypeGetParamInfoByName(paramUnit->audioType, paramName); |
| 141 | if (!paramInfo) |
| 142 | { |
| 143 | WARN_LOG("Cannot find paramInfo. (param = %s\n)", paramName); |
| 144 | return APP_ERROR; |
| 145 | } |
| 146 | |
| 147 | fieldInfo = paramInfoGetFieldInfoByName(paramInfo, fieldName); |
| 148 | if (!fieldInfo) |
| 149 | { |
| 150 | WARN_LOG("Cannot find fieldInfo. (fieldName = %s\n)", fieldName); |
| 151 | return APP_ERROR; |
| 152 | } |
| 153 | |
| 154 | /* Query param */ |
| 155 | param = paramUnitGetParamByName(paramUnit, paramName); |
| 156 | if (!param) |
| 157 | { |
| 158 | WARN_LOG("Cannot get param. (name = %s)\n", paramName); |
| 159 | return APP_ERROR; |
| 160 | } |
| 161 | |
| 162 | /* Query field val */ |
| 163 | return paramGetFieldVal(param, fieldInfo, val); |
| 164 | } |
| 165 | |
| 166 | EXPORT ParamInfo *paramUnitGetParamInfo(ParamUnit *paramUnit, const char *paramInfoName) |
| 167 | { |
| 168 | if (!paramUnit) |
| 169 | { |
| 170 | ERR_LOG("paramUnit is NULL!\n"); |
| 171 | return NULL; |
| 172 | } |
| 173 | |
| 174 | return audioTypeGetParamInfoByName(paramUnit->audioType, paramInfoName); |
| 175 | } |
| 176 | |
| 177 | EXPORT FieldInfo *paramUnitGetFieldInfo(ParamUnit *paramUnit, const char *paramName, const char *fieldName) |
| 178 | { |
| 179 | ParamInfo *paramInfo; |
| 180 | if (!paramUnit || !paramName || !fieldName) |
| 181 | { |
| 182 | WARN_LOG("Cannot get field info. (paramUnit id=%d, paramInfoName=%s, fieldInfoName=%s\n)", paramUnit ? paramUnit->paramId : -1, paramName, fieldName); |
| 183 | return NULL; |
| 184 | } |
| 185 | |
| 186 | paramInfo = audioTypeGetParamInfoByName(paramUnit->audioType, paramName); |
| 187 | if (paramInfo) |
| 188 | { |
| 189 | return paramInfoGetFieldInfoByName(paramInfo, fieldName); |
| 190 | } |
| 191 | else |
| 192 | { |
| 193 | return NULL; |
| 194 | } |
| 195 | } |