Remove iniparse dependency for hal ABI compatibility 48/314448/8
authorJaechul Lee <jcsing.lee@samsung.com>
Fri, 12 Jul 2024 00:35:55 +0000 (09:35 +0900)
committerJaechul Lee <jcsing.lee@samsung.com>
Fri, 12 Jul 2024 04:35:16 +0000 (13:35 +0900)
 * fix svace issues

[Version] 0.1.22
[Issue Type] Update

Change-Id: I83cfe1a17d019cc0d58e3939a05bf6a426fc3a95
Signed-off-by: Jaechul Lee <jcsing.lee@samsung.com>
configure.ac
packaging/audio-hal-bcm2837.spec
tizen-audio-impl-pcm.c
tizen-audio-internal.h
tizen-audio-util.c
tizen-audio-volume.c

index cb22621a48583ec2b75c508d0c6fe4272fab227f..a64267c3e1d9d16ac66aef769fab5815ad8aabff 100644 (file)
@@ -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)
index c64da9f717c3a7676588b6da212bfbcbaf70d1e5..415c1facaa4791c984c060e061ef194536773dce 100644 (file)
@@ -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)
index bc81858ac1191db3d773419fd498699173cd1bae..19df164dc7d3cea4764ec3081a7d0068f4aa4c1e 100644 (file)
@@ -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;
 
index d1312bbb4b7cae1a139565149f7d8eef1b4c7452..48619c60830ca0537db37da68fa275b390f3c09d 100644 (file)
@@ -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
index 0d1326b7c8471150c39e5107c65771b0229304c6..6d83951eed72d02b61369f39fc402e8d0621c392 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
+#include <ctype.h>
 
 #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);
+}
+
index 11e08139c236435a4e6d011e584d89a012a45b2a..071d606404576222db9a4a080ebdb648b0d895fd 100644 (file)
@@ -24,7 +24,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <math.h>
-#include <iniparser.h>
 
 #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;