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