From: Jaechul Lee Date: Fri, 12 Jul 2024 00:35:55 +0000 (+0900) Subject: Remove iniparse dependency for hal ABI compatibility X-Git-Tag: accepted/tizen/unified/20240727.112741~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b7e3d1fc3359234e5201f76dacab9d97605f8339;p=platform%2Fadaptation%2Fap_broadcom%2Faudio-hal-bcm2837.git Remove iniparse dependency for hal ABI compatibility * fix svace issues [Version] 0.1.22 [Issue Type] Update Change-Id: I83cfe1a17d019cc0d58e3939a05bf6a426fc3a95 Signed-off-by: Jaechul Lee --- diff --git a/configure.ac b/configure.ac index cb22621..a64267c 100644 --- a/configure.ac +++ b/configure.ac @@ -35,10 +35,6 @@ else AM_CONDITIONAL(USE_TINYALSA, false) fi -PKG_CHECK_MODULES(INIPARSER, iniparser) -AC_SUBST(INIPARSER_CFLAGS) -AC_SUBST(INIPARSER_LIBS) - PKG_CHECK_MODULES(DLOG, dlog) AC_SUBST(DLOG_CFLAGS) AC_SUBST(DLOG_LIBS) diff --git a/packaging/audio-hal-bcm2837.spec b/packaging/audio-hal-bcm2837.spec index c64da9f..415c1fa 100644 --- a/packaging/audio-hal-bcm2837.spec +++ b/packaging/audio-hal-bcm2837.spec @@ -1,12 +1,11 @@ Name: audio-hal-bcm2837 Summary: TIZEN Audio HAL for BCM2837 -Version: 0.1.21 +Version: 0.1.22 Release: 0 Group: System/Libraries License: Apache-2.0 URL: http://tizen.org Source0: audio-hal-bcm2837-%{version}.tar.gz -BuildRequires: pkgconfig(iniparser) BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(alsa) BuildRequires: pkgconfig(hal-api-common) diff --git a/tizen-audio-impl-pcm.c b/tizen-audio-impl-pcm.c index bc81858..19df164 100644 --- a/tizen-audio-impl-pcm.c +++ b/tizen-audio-impl-pcm.c @@ -483,8 +483,8 @@ audio_return_e _pcm_get_params(void *pcm_handle, uint32_t direction, void *sampl return AUDIO_ERR_PARAMETER; } - *period_size = _period_size; - *periods = _periods; + *period_size = (uint32_t)_period_size; + *periods = (uint32_t)_periods; ss.rate = _rate; ss.channels = _channels; @@ -630,7 +630,7 @@ audio_return_e _pcm_set_params(void *pcm_handle, uint32_t direction, void *sampl } AUDIO_LOG_INFO("requested period_size(%d). set period_size_near(%ld)", period_size, period_size_near); - period_size = period_size_near; + period_size = (uint32_t)period_size_near; buffer_size = period_size * periods; buffer_size_near = buffer_size; diff --git a/tizen-audio-internal.h b/tizen-audio-internal.h index d1312bb..48619c6 100644 --- a/tizen-audio-internal.h +++ b/tizen-audio-internal.h @@ -267,4 +267,11 @@ void _audio_dump_add_str(dump_data_t *dump, const char *fmt, ...); char* _audio_dump_get_str(dump_data_t *dump); void _audio_dump_free(dump_data_t *dump); +/* volume table parse API */ +typedef struct _dictionary dictionary_t; +dictionary_t *parser_load(const char *filename); +const char *parser_getstring(const dictionary_t *dict, const char *key, const char *default_value); +void parser_freedict(dictionary_t *dict); +void dump_dictionary(const dictionary_t *dict); + #endif diff --git a/tizen-audio-util.c b/tizen-audio-util.c index 0d1326b..6d83951 100644 --- a/tizen-audio-util.c +++ b/tizen-audio-util.c @@ -25,12 +25,29 @@ #include #include #include +#include #include "tizen-audio-internal.h" +#define MAX_LINE_LENGTH 256 +#define MAX_KEY_LENGTH 64 +#define MAX_VALUE_LENGTH 128 + +typedef struct { + char key[MAX_KEY_LENGTH]; + char value[MAX_VALUE_LENGTH]; +} key_value_pair_t; + +struct _dictionary { + key_value_pair_t *pairs; + int count; +}; + /* ------ dump helper -------- */ #define MAX(a, b) ((a) > (b) ? (a) : (b)) +typedef struct _dictionary dictionary_t; + #ifdef __USE_TINYALSA__ static const uint32_t g_format_convert_hal_table[] = { [AUDIO_SAMPLE_U8] = PCM_FORMAT_S8, @@ -163,3 +180,101 @@ void _audio_dump_free(dump_data_t *dump) } } /* ------ dump helper -------- */ + +/* ------ volume table parse -------- */ +char *rtrim(char *s) +{ + char* back = s + strlen(s); + while(isspace(*--back)); + *(back+1) = '\0'; + return s; +} + +dictionary_t *parser_load(const char *filename) { + FILE *file = NULL; + dictionary_t *dict = NULL; + char line[MAX_LINE_LENGTH]; + + file = fopen(filename, "r"); + if (!file) { + AUDIO_LOG_ERROR("Failed to open file: %s", filename); + return NULL; + } + + dict = (dictionary_t *)malloc(sizeof(dictionary_t)); + if (!dict) { + AUDIO_LOG_ERROR("failed to alloc memory"); + goto fail; + } + dict->pairs = NULL; + dict->count = 0; + + while (fgets(line, MAX_LINE_LENGTH, file)) { + char* saveptr; + char *key = strtok_r(line, "=", &saveptr); + char *value = strtok_r(NULL, "\n", &saveptr); + + if (key && value) { + key_value_pair_t pair; + strncpy(pair.key, key, MAX_KEY_LENGTH - 1); + rtrim(pair.key); + pair.key[MAX_KEY_LENGTH - 1] = '\0'; + strncpy(pair.value, value, MAX_VALUE_LENGTH - 1); + pair.value[MAX_VALUE_LENGTH - 1] = '\0'; + + dict->pairs = (key_value_pair_t *)realloc(dict->pairs, sizeof(key_value_pair_t) * (dict->count + 1)); + if (!dict->pairs) { + AUDIO_LOG_ERROR("failed to alloc memory"); + goto fail; + } + dict->pairs[dict->count++] = pair; + } + } + + fclose(file); + + return dict; + +fail: + if (file) + fclose(file); + if (dict) + parser_freedict(dict); + + return NULL; +} + +const char *parser_getstring(const dictionary_t *dict, const char *key, const char *default_value) { + if (!dict || !key) { + return default_value; + } + + for (int i = 0; i < dict->count; i++) { + if (strcmp(dict->pairs[i].key, key) == 0) { + return dict->pairs[i].value; + } + } + + return default_value; +} + +void parser_freedict(dictionary_t *dict) { + if (dict) { + if (dict->pairs) { + free(dict->pairs); + } + free(dict); + } +} + +void dump_dictionary(const dictionary_t *dict) { + if (!dict) { + AUDIO_LOG_ERROR("dictionary is NULL"); + return; + } + + AUDIO_LOG_INFO("dictionary contents:"); + for (int i = 0; i < dict->count; i++) + AUDIO_LOG_INFO("Key: %-16s Value: %s", dict->pairs[i].key, dict->pairs[i].value); +} + diff --git a/tizen-audio-volume.c b/tizen-audio-volume.c index 11e0813..071d606 100644 --- a/tizen-audio-volume.c +++ b/tizen-audio-volume.c @@ -24,7 +24,6 @@ #include #include #include -#include #include "tizen-audio-internal.h" #include "tizen-audio-impl.h" @@ -163,61 +162,57 @@ static void __dump_tb(audio_hal_s *ah) } -static audio_return_e __load_volume_value_table_from_ini(audio_hal_s *ah) +static audio_return_e __load_volume_value_table(audio_hal_s *ah) { - dictionary * dict = NULL; + dictionary_t * dict = NULL; uint32_t vol_type_idx, vol_level_idx, gain_type_idx; audio_volume_value_table_s *volume_value_table = ah->volume.volume_value_table; int size = 0; const char delimiter[] = ", "; - const char *table_str = "volumes"; const char *tmp_str = NULL; const char *gain_str = NULL; char *list_str = NULL, *ptr = NULL; char *key, *token; if (access(VOLUME_INI_TEMP_PATH, F_OK) == 0) - dict = iniparser_load(VOLUME_INI_TEMP_PATH); + dict = parser_load(VOLUME_INI_TEMP_PATH); if (!dict) { AUDIO_LOG_DEBUG("Use default volume&gain ini file"); - dict = iniparser_load(VOLUME_INI_DEFAULT_PATH); + dict = parser_load(VOLUME_INI_DEFAULT_PATH); if (!dict) { AUDIO_LOG_WARN("Loading volume&gain table from ini file failed"); return AUDIO_ERR_UNDEFINED; } } + dump_dictionary(dict); + /* Load volume table */ for (vol_type_idx = 0; vol_type_idx < AUDIO_VOLUME_TYPE_MAX; vol_type_idx++) { const char *vol_type_str = __get_volume_type_string_by_idx(vol_type_idx); ah->volume.volume_level_max[vol_type_idx] = 0; - size = strlen(table_str) + strlen(vol_type_str) + 2; - key = malloc(size); - if (key) { - snprintf(key, size, "%s:%s", table_str, vol_type_str); - if ((tmp_str = iniparser_getstring(dict, key, NULL))) - list_str = strdup(tmp_str); - - if (list_str) { - token = strtok_r(list_str, delimiter, &ptr); - while (token) { - /* convert dB volume to linear volume */ - double vol_value = 0.0f; - if (strncmp(token, "0", strlen(token))) - vol_value = pow(10.0, (atof(token) - 100) / 20.0); - volume_value_table->volume[vol_type_idx][ah->volume.volume_level_max[vol_type_idx]++] = vol_value; - token = strtok_r(NULL, delimiter, &ptr); - } - free(list_str); - list_str = NULL; - } else { - ah->volume.volume_level_max[vol_type_idx] = 1; - for (vol_level_idx = 0; vol_level_idx < AUDIO_VOLUME_LEVEL_MAX; vol_level_idx++) { - volume_value_table->volume[vol_type_idx][vol_level_idx] = VOLUME_VALUE_MAX; - } + + if ((tmp_str = parser_getstring(dict, vol_type_str, NULL))) + list_str = strdup(tmp_str); + + if (list_str) { + token = strtok_r(list_str, delimiter, &ptr); + while (token) { + /* convert dB volume to linear volume */ + double vol_value = 0.0f; + if (strncmp(token, "0", strlen(token))) + vol_value = pow(10.0, (atof(token) - 100) / 20.0); + volume_value_table->volume[vol_type_idx][ah->volume.volume_level_max[vol_type_idx]++] = vol_value; + token = strtok_r(NULL, delimiter, &ptr); + } + free(list_str); + list_str = NULL; + } else { + ah->volume.volume_level_max[vol_type_idx] = 1; + for (vol_level_idx = 0; vol_level_idx < AUDIO_VOLUME_LEVEL_MAX; vol_level_idx++) { + volume_value_table->volume[vol_type_idx][vol_level_idx] = VOLUME_VALUE_MAX; } - free(key); } } @@ -226,11 +221,11 @@ static audio_return_e __load_volume_value_table_from_ini(audio_hal_s *ah) for (gain_type_idx = AUDIO_GAIN_TYPE_DEFAULT + 1; gain_type_idx < AUDIO_GAIN_TYPE_MAX; gain_type_idx++) { const char *gain_type_str = __get_gain_type_string_by_idx(gain_type_idx); - size = strlen(table_str) + strlen("gain") + strlen(gain_type_str) + 3; + size = strlen("gain") + strlen(gain_type_str) + 3; key = malloc(size); if (key) { - snprintf(key, size, "%s:gain_%s", table_str, gain_type_str); - gain_str = iniparser_getstring(dict, key, NULL); + snprintf(key, size, "gain_%s", gain_type_str); + gain_str = parser_getstring(dict, key, NULL); if (gain_str) { volume_value_table->gain[gain_type_idx] = atof(gain_str); } else { @@ -242,7 +237,7 @@ static audio_return_e __load_volume_value_table_from_ini(audio_hal_s *ah) } } - iniparser_freedict(dict); + parser_freedict(dict); __dump_tb(ah); @@ -260,7 +255,7 @@ audio_return_e _audio_volume_init(audio_hal_s *ah) return AUDIO_ERR_RESOURCE; } - audio_ret = __load_volume_value_table_from_ini(ah); + audio_ret = __load_volume_value_table(ah); if (audio_ret != AUDIO_RET_OK) { AUDIO_LOG_ERROR("gain table load error"); return AUDIO_ERR_UNDEFINED;