summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am7
-rw-r--r--configure.ac22
-rw-r--r--packaging/hal-backend-audio-alsa.spec9
-rw-r--r--tizen-audio-internal.h17
-rw-r--r--tizen-audio-util.c120
-rw-r--r--tizen-audio-volume.c107
6 files changed, 174 insertions, 108 deletions
diff --git a/Makefile.am b/Makefile.am
index 6457672..fc8b233 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -12,10 +12,11 @@ libhal_backend_audio_la_SOURCES = tizen-audio.c \
tizen-audio-impl-ctrl.c \
hal-backend-audio.c
libhal_backend_audio_la_LDFLAGS = $(AM_LDFLAGS) -disable-static -avoid-version
-libhal_backend_audio_la_LIBADD = $(AM_LDADD) $(ASOUNDLIB_LIBS) $(VCONF_LIBS) $(DLOG_LIBS) $(INIPARSER_LIBS)
-libhal_backend_audio_la_CFLAGS = $(AM_CFLAGS) $(ASOUNDLIB_CFLAGS) $(VCONF_CFLAGS) $(DLOG_CFLAGS) $(INIPARSER_CFLAGS) $(HALAPICOMMON) -DUSE_DLOG
+libhal_backend_audio_la_LIBADD = $(AM_LDADD) $(HALROOTSTRAP_LIBS)
+libhal_backend_audio_la_CFLAGS = $(AM_CFLAGS) $(HALROOTSTRAP_CFLAGS) -DUSE_DLOG
if USE_TINYALSA
libhal_backend_audio_la_LIBADD += $(TINYALSA_LIBS)
libhal_backend_audio_la_CFLAGS += $(TINYALSA_CFLAGS) -D__USE_TINYALSA__
-endif \ No newline at end of file
+endif
+
diff --git a/configure.ac b/configure.ac
index 06192cb..3414889 100644
--- a/configure.ac
+++ b/configure.ac
@@ -22,9 +22,9 @@ PKG_PROG_PKG_CONFIG
# Checks for libraries.
-PKG_CHECK_MODULES(ASOUNDLIB, alsa >= 1.0.24)
-AC_SUBST(ASOUNDLIB_CFLAGS)
-AC_SUBST(ASOUNDLIB_LIBS)
+PKG_CHECK_MODULES(HALROOTSTRAP, hal-rootstrap)
+AC_SUBST(HALROOTSTRAP_CFLAGS)
+AC_SUBST(HALROOTSTRAP_LIBS)
if test $USE_TINYALSA = "1"; then
PKG_CHECK_MODULES(TINYALSA, tinyalsa)
@@ -35,22 +35,6 @@ else
AM_CONDITIONAL(USE_TINYALSA, false)
fi
-PKG_CHECK_MODULES(VCONF, vconf)
-AC_SUBST(VCONF_CFLAGS)
-AC_SUBST(VCONF_LIBS)
-
-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)
-
-PKG_CHECK_MODULES(HALAPICOMMON, hal-api-common)
-AC_SUBST(HALAPICOMMON_CFLAGS)
-AC_SUBST(HALAPICOMMON_LIBS)
-
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
diff --git a/packaging/hal-backend-audio-alsa.spec b/packaging/hal-backend-audio-alsa.spec
index 0764a8a..96ad62d 100644
--- a/packaging/hal-backend-audio-alsa.spec
+++ b/packaging/hal-backend-audio-alsa.spec
@@ -1,17 +1,12 @@
Name: hal-backend-audio-alsa
Summary: TIZEN Audio HAL using ALSA
-Version: 0.0.3
+Version: 0.0.4
Release: 0
Group: System/Libraries
License: Apache-2.0
URL: http://tizen.org
Source0: %{name}-%{version}.tar.gz
-BuildRequires: pkgconfig(vconf)
-BuildRequires: pkgconfig(iniparser)
-BuildRequires: pkgconfig(dlog)
-BuildRequires: pkgconfig(alsa)
-BuildRequires: pkgconfig(hal-api-common)
-BuildRequires: pkgconfig(hal-api-audio)
+BuildRequires: pkgconfig(hal-rootstrap)
#BuildRequires: pkgconfig(tinyalsa)
Provides: libhal-backend-audio.so
diff --git a/tizen-audio-internal.h b/tizen-audio-internal.h
index af04505..e4772bc 100644
--- a/tizen-audio-internal.h
+++ b/tizen-audio-internal.h
@@ -43,11 +43,11 @@
#undef DLOG_TAG
#endif
#define DLOG_TAG "AUDIO_HAL"
-#define AUDIO_LOG_ERROR(...) SLOG(LOG_ERROR, DLOG_TAG, __VA_ARGS__)
-#define AUDIO_LOG_WARN(...) SLOG(LOG_WARN, DLOG_TAG, __VA_ARGS__)
-#define AUDIO_LOG_INFO(...) SLOG(LOG_INFO, DLOG_TAG, __VA_ARGS__)
-#define AUDIO_LOG_DEBUG(...) SLOG(LOG_DEBUG, DLOG_TAG, __VA_ARGS__)
-#define AUDIO_LOG_VERBOSE(...) SLOG(LOG_DEBUG, DLOG_TAG, __VA_ARGS__)
+#define AUDIO_LOG_ERROR(...) dlog_print(DLOG_ERROR, DLOG_TAG, __VA_ARGS__)
+#define AUDIO_LOG_WARN(...) dlog_print(DLOG_WARN, DLOG_TAG, __VA_ARGS__)
+#define AUDIO_LOG_INFO(...) dlog_print(DLOG_INFO, DLOG_TAG, __VA_ARGS__)
+#define AUDIO_LOG_DEBUG(...) dlog_print(DLOG_DEBUG, DLOG_TAG, __VA_ARGS__)
+#define AUDIO_LOG_VERBOSE(...) dlog_print(DLOG_DEBUG, DLOG_TAG, __VA_ARGS__)
#else
#define AUDIO_LOG_ERROR(...) fprintf(stderr, __VA_ARGS__)
#define AUDIO_LOG_WARN(...) fprintf(stderr, __VA_ARGS__)
@@ -252,4 +252,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 6ce8395..e8086c3 100644
--- a/tizen-audio-util.c
+++ b/tizen-audio-util.c
@@ -25,9 +25,26 @@
#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;
+};
+
+typedef struct _dictionary dictionary_t;
+
/* ------ dump helper -------- */
#define MAX(a, b) ((a) > (b) ? (a) : (b))
@@ -163,3 +180,106 @@ 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)
+ return;
+
+ 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 e9b9177..310fe6b 100644
--- a/tizen-audio-volume.c
+++ b/tizen-audio-volume.c
@@ -24,8 +24,6 @@
#include <stdlib.h>
#include <string.h>
#include <math.h>
-#include <vconf.h>
-#include <iniparser.h>
#include "tizen-audio-internal.h"
#include "tizen-audio-impl.h"
@@ -37,17 +35,6 @@
static uint32_t g_master_volume_level = 100;
-static const char *g_volume_vconf[AUDIO_VOLUME_TYPE_MAX] = {
- "file/private/sound/volume/system", /* AUDIO_VOLUME_TYPE_SYSTEM */
- "file/private/sound/volume/notification", /* AUDIO_VOLUME_TYPE_NOTIFICATION */
- "file/private/sound/volume/alarm", /* AUDIO_VOLUME_TYPE_ALARM */
- "file/private/sound/volume/ringtone", /* AUDIO_VOLUME_TYPE_RINGTONE */
- "file/private/sound/volume/media", /* AUDIO_VOLUME_TYPE_MEDIA */
- "file/private/sound/volume/call", /* AUDIO_VOLUME_TYPE_CALL */
- "file/private/sound/volume/voip", /* AUDIO_VOLUME_TYPE_VOIP */
- "file/private/sound/volume/voice", /* AUDIO_VOLUME_TYPE_VOICE */
-};
-
static const char *__get_volume_type_string_by_idx(uint32_t vol_type_idx)
{
switch (vol_type_idx) {
@@ -175,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);
}
}
@@ -238,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 {
@@ -254,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);
@@ -263,34 +246,16 @@ static audio_return_e __load_volume_value_table_from_ini(audio_hal_s *ah)
audio_return_e _audio_volume_init(audio_hal_s *ah)
{
- int i;
- int val = 0;
audio_return_e audio_ret = AUDIO_RET_OK;
- int init_value[AUDIO_VOLUME_TYPE_MAX] = { 9, 11, 7, 11, 7, 4, 4, 7 };
AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
- for (i = 0; i < AUDIO_VOLUME_TYPE_MAX; i++) {
- ah->volume.volume_level[i] = init_value[i];
- }
-
- for (i = 0; i < AUDIO_VOLUME_TYPE_MAX; i++) {
- /* Get volume value string from VCONF */
- if (vconf_get_int(g_volume_vconf[i], &val) < 0) {
- AUDIO_LOG_ERROR("vconf_get_int(%s) failed", g_volume_vconf[i]);
- continue;
- }
-
- AUDIO_LOG_INFO("read vconf. %s = %d", g_volume_vconf[i], val);
- ah->volume.volume_level[i] = val;
- }
-
if (!(ah->volume.volume_value_table = malloc(AUDIO_VOLUME_DEVICE_MAX * sizeof(audio_volume_value_table_s)))) {
AUDIO_LOG_ERROR("volume_value_table malloc failed");
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;
@@ -340,9 +305,7 @@ audio_return_e audio_get_volume_level(void *audio_handle, audio_volume_info_s *i
return AUDIO_RET_OK;
}
- *level = ah->volume.volume_level[__get_volume_idx_by_string_type(info->type)];
-
- AUDIO_LOG_INFO("get [%s] volume_level: %d, direction(%d)", info->type, *level, info->direction);
+ AUDIO_LOG_INFO("Not supported volume type[%s], skip it", info->type);
return AUDIO_RET_OK;
}
@@ -384,11 +347,7 @@ audio_return_e audio_set_volume_level(void *audio_handle, audio_volume_info_s *i
}
AUDIO_RETURN_VAL_IF_FAIL((ah->volume.volume_level_max[__get_volume_idx_by_string_type(info->type)] >= level), AUDIO_ERR_PARAMETER);
- /* Update volume level */
- ah->volume.volume_level[__get_volume_idx_by_string_type(info->type)] = level;
- AUDIO_LOG_INFO("set [%s] volume_level: %d, direction(%d)", info->type, level, info->direction);
-
- /* set mixer related to H/W volume if needed */
+ AUDIO_LOG_INFO("Not supported volume type[%s], skip it", info->type);
return audio_ret;
}