| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: MediaTekProprietary |
| 2 | /* MediaTek Inc. (C) 2016. All rights reserved. |
| 3 | * |
| 4 | * Copyright Statement: |
| 5 | * This software/firmware and related documentation ("MediaTek Software") are |
| 6 | * protected under relevant copyright laws. The information contained herein is |
| 7 | * confidential and proprietary to MediaTek Inc. and/or its licensors. Without |
| 8 | * the prior written permission of MediaTek inc. and/or its licensors, any |
| 9 | * reproduction, modification, use or disclosure of MediaTek Software, and |
| 10 | * information contained herein, in whole or in part, shall be strictly |
| 11 | * prohibited. |
| 12 | */ |
| 13 | |
| 14 | /* |
| 15 | * Description: |
| 16 | * Implement ParamInfo & FieldInfo related APIs |
| 17 | */ |
| 18 | |
| 19 | #include "AudioParamParserPriv.h" |
| 20 | |
| 21 | EXPORT size_t paramInfoGetNumOfFieldInfo(ParamInfo *paramInfo) { |
| 22 | if (!paramInfo) { |
| 23 | ERR_LOG("paramInfo is NULL!\n"); |
| 24 | return 0; |
| 25 | } |
| 26 | |
| 27 | return HASH_COUNT(paramInfo->fieldInfoHash); |
| 28 | } |
| 29 | |
| 30 | EXPORT FieldInfo *paramInfoGetFieldInfoByIndex(ParamInfo *paramInfo, size_t index) { |
| 31 | FieldInfo *fieldInfo = NULL; |
| 32 | size_t i = 0; |
| 33 | |
| 34 | if (!paramInfo) { |
| 35 | ERR_LOG("paramInfo is NULL!\n"); |
| 36 | return NULL; |
| 37 | } |
| 38 | |
| 39 | for (fieldInfo = paramInfo->fieldInfoHash; fieldInfo ; fieldInfo = fieldInfo->hh.next) { |
| 40 | if (index == i++) { |
| 41 | return fieldInfo; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | return NULL; |
| 46 | } |
| 47 | |
| 48 | EXPORT FieldInfo *paramInfoGetFieldInfoByName(ParamInfo *paramInfo, const char *fieldName) { |
| 49 | FieldInfo *fieldInfo; |
| 50 | |
| 51 | if (!paramInfo) { |
| 52 | ERR_LOG("paramInfo is NULL!\n"); |
| 53 | return NULL; |
| 54 | } |
| 55 | |
| 56 | /* Query Param name */ |
| 57 | HASH_FIND_STR(paramInfo->fieldInfoHash, fieldName, fieldInfo); |
| 58 | |
| 59 | return fieldInfo; |
| 60 | } |
| 61 | |
| 62 | EXPORT ParamInfo *paramInfoCreate(const char *name, DATA_TYPE dataType, AudioType *audioType) { |
| 63 | ParamInfo *paramInfo = (ParamInfo *)malloc(sizeof(ParamInfo)); |
| 64 | if (!paramInfo) { |
| 65 | ERR_LOG("malloc fail!\n"); |
| 66 | return NULL; |
| 67 | } |
| 68 | |
| 69 | paramInfo->audioType = audioType; |
| 70 | paramInfo->name = strdup(name); |
| 71 | paramInfo->dataType = dataType; |
| 72 | paramInfo->fieldInfoHash = NULL; |
| 73 | return paramInfo; |
| 74 | } |
| 75 | |
| 76 | EXPORT FieldInfo *fieldInfoCreate(const char *fieldName, unsigned int arrayIndex, int startBit, int endBit, const char *checkList, ParamInfo *paramInfo) { |
| 77 | FieldInfo *fieldInfo = (FieldInfo *)malloc(sizeof(FieldInfo)); |
| 78 | |
| 79 | if (!fieldInfo) { |
| 80 | ERR_LOG("malloc fail!\n"); |
| 81 | return NULL; |
| 82 | } |
| 83 | |
| 84 | /* Setup members */ |
| 85 | fieldInfo->name = strdup(fieldName); |
| 86 | fieldInfo->arrayIndex = arrayIndex; |
| 87 | fieldInfo->startBit = startBit; |
| 88 | fieldInfo->endBit = endBit; |
| 89 | fieldInfo->paramInfo = paramInfo; |
| 90 | |
| 91 | |
| 92 | if (checkList) { |
| 93 | fieldInfo->checkListStr = strdup(checkList); |
| 94 | } else { |
| 95 | #ifdef WIN32 |
| 96 | fieldInfo->checkListStr = utilGenCheckList(endBit - startBit + 1); |
| 97 | #else |
| 98 | /* Reduce memory usage, don't generate check list automatically */ |
| 99 | fieldInfo->checkListStr = strdup(""); |
| 100 | #endif |
| 101 | } |
| 102 | |
| 103 | return fieldInfo; |
| 104 | } |
| 105 | |
| 106 | EXPORT void paramInfoRelease(ParamInfo *paramInfo) { |
| 107 | if (paramInfo == NULL) { |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | if (paramInfo->fieldInfoHash) { |
| 112 | FieldInfo *tmp = NULL, *item = NULL; |
| 113 | HASH_ITER(hh, paramInfo->fieldInfoHash, item, tmp) { |
| 114 | if (paramInfo->fieldInfoHash) { |
| 115 | HASH_DEL(paramInfo->fieldInfoHash, item); |
| 116 | fieldInfoRelease(item); |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | free(paramInfo->name); |
| 122 | free(paramInfo); |
| 123 | } |
| 124 | |
| 125 | EXPORT void fieldInfoRelease(FieldInfo *fieldInfo) { |
| 126 | if (fieldInfo == NULL) { |
| 127 | return; |
| 128 | } |
| 129 | |
| 130 | if (fieldInfo->checkListStr) { |
| 131 | free(fieldInfo->checkListStr); |
| 132 | } |
| 133 | |
| 134 | free(fieldInfo->name); |
| 135 | free(fieldInfo); |
| 136 | } |
| 137 | |
| 138 | EXPORT APP_STATUS fieldInfoGetCheckListValue(FieldInfo *fieldInfo, const char *checkName, unsigned int *checkVal) { |
| 139 | char *checkList = NULL; |
| 140 | char *valStr = NULL; |
| 141 | char *nameStr = NULL; |
| 142 | char *restOfStr = NULL; |
| 143 | if (!fieldInfo) { |
| 144 | ERR_LOG("fieldInfo is NULL\n"); |
| 145 | return APP_ERROR; |
| 146 | } |
| 147 | |
| 148 | if (!checkName) { |
| 149 | ERR_LOG("checkName is NULL\n"); |
| 150 | return APP_ERROR; |
| 151 | } |
| 152 | |
| 153 | if (!checkVal) { |
| 154 | ERR_LOG("checkVal is NULL\n"); |
| 155 | return APP_ERROR; |
| 156 | } |
| 157 | |
| 158 | checkList = strdup(fieldInfo->checkListStr); |
| 159 | valStr = utilStrtok(checkList, ARRAY_SEPERATOR, &restOfStr); |
| 160 | if (!valStr) { |
| 161 | ERR_LOG("Cannot parse valStr\n"); |
| 162 | free(checkList); |
| 163 | return APP_ERROR; |
| 164 | } |
| 165 | |
| 166 | while ((nameStr = utilStrtok(NULL, ARRAY_SEPERATOR, &restOfStr)) != NULL) { |
| 167 | if (!strncmp(nameStr, checkName, strlen(checkName) + 1)) { |
| 168 | *checkVal = strtoul(valStr, NULL, 0); |
| 169 | free(checkList); |
| 170 | return APP_NO_ERROR; |
| 171 | } |
| 172 | |
| 173 | valStr = utilStrtok(NULL, ARRAY_SEPERATOR, &restOfStr); |
| 174 | if (!valStr) { |
| 175 | ERR_LOG("Cannot parse valStr\n"); |
| 176 | free(checkList); |
| 177 | return APP_ERROR; |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | free(checkList); |
| 182 | return APP_ERROR; |
| 183 | } |