diff options
author | Seungbae Shin <seungbae.shin@samsung.com> | 2021-04-12 15:35:52 +0900 |
---|---|---|
committer | Seungbae Shin <seungbae.shin@samsung.com> | 2021-04-13 15:33:08 +0900 |
commit | d7239c0b08d91f1c48c541000300391f46f0cb6c (patch) | |
tree | 97e7fb3d6f799690ba6e72cab840fc833f126fd2 | |
parent | fd3c76fcb29164793a0257935ade8a3f567ee968 (diff) | |
download | audio-hal-sc7727-d7239c0b08d91f1c48c541000300391f46f0cb6c.tar.gz audio-hal-sc7727-d7239c0b08d91f1c48c541000300391f46f0cb6c.tar.bz2 audio-hal-sc7727-d7239c0b08d91f1c48c541000300391f46f0cb6c.zip |
SAM improvementsubmit/tizen/20210415.024428
Fixes following violations:
CC tizen-audio-impl-ucm.c _ucm_set_use_case
CC tizen-audio-impl-ucm.c _ucm_set_devices
CC tizen-audio-impl-ucm.c _ucm_set_modifiers
GV tizen-audio-volume.c g_master_volume_level
[Version] 0.1.40
[Issue Type] SAM
Change-Id: Ie8780f7b9fc752e68e89cbc60253cebbbffeeeb9
-rw-r--r-- | packaging/audio-hal-sc7727.spec | 2 | ||||
-rw-r--r-- | tizen-audio-impl-ucm.c | 510 | ||||
-rw-r--r-- | tizen-audio-volume.c | 2 |
3 files changed, 213 insertions, 301 deletions
diff --git a/packaging/audio-hal-sc7727.spec b/packaging/audio-hal-sc7727.spec index 0c5e80f..5b31666 100644 --- a/packaging/audio-hal-sc7727.spec +++ b/packaging/audio-hal-sc7727.spec @@ -1,6 +1,6 @@ Name: audio-hal-sc7727 Summary: TIZEN Audio HAL for SC7727 -Version: 0.1.39 +Version: 0.1.40 Release: 0 Group: System/Libraries License: Apache-2.0 diff --git a/tizen-audio-impl-ucm.c b/tizen-audio-impl-ucm.c index 87db8db..66e486e 100644 --- a/tizen-audio-impl-ucm.c +++ b/tizen-audio-impl-ucm.c @@ -25,6 +25,8 @@ #include <stdlib.h> #include <string.h> #include <assert.h> +#include <stdbool.h> +#include <string.h> #ifdef ALSA_UCM_DEBUG_TIME #include <sys/time.h> #include <time.h> @@ -44,10 +46,38 @@ #define DUMP_LEN 512 -static void __dump_use_case(const char* prefix, const char *verb, const char *devices[], int dev_count, const char *modifiers[], int mod_count) + +typedef enum _ucm_identifier { + UCM_IDENTIFIER_VERB, + UCM_IDENTIFIER_ENABLE_DEVICE, + UCM_IDENTIFIER_DISABLE_DEVICE, + UCM_IDENTIFIER_ENABLE_MODIFIER, + UCM_IDENTIFIER_DISABLE_MODIFIER, + UCM_IDENTIFIER_ENABLED_DEVICES, + UCM_IDENTIFIER_ENABLED_MODIFIERS +} ucm_identifier_e; + +typedef struct _ucm_case_set { + const char *identifier; + const char *description; +} ucm_case_set_s; + +static const ucm_case_set_s ucm_set[] = { + [UCM_IDENTIFIER_VERB] = { "_verb", "Verb"}, + [UCM_IDENTIFIER_ENABLE_DEVICE] = { "_enadev", "Enable device" }, + [UCM_IDENTIFIER_DISABLE_DEVICE] = { "_disdev", "Disable device" }, + [UCM_IDENTIFIER_ENABLE_MODIFIER] = { "_enamod", "Enable modifier" }, + [UCM_IDENTIFIER_DISABLE_MODIFIER] = { "_dismod", "Disable modifier" }, + [UCM_IDENTIFIER_ENABLED_DEVICES] = { "_enadevs", "Enabled devices" }, + [UCM_IDENTIFIER_ENABLED_MODIFIERS] = { "_enamods", "Enabled modifiers" }, +}; + +static void __dump_use_case(const char *prefix, const char *verb, + const char *devices[], int dev_count, + const char *modifiers[], int mod_count) { int i; - dump_data_t* dump = NULL; + dump_data_t *dump = NULL; if (!(dump = _audio_dump_new(DUMP_LEN))) { AUDIO_LOG_ERROR("Failed to create dump string..."); @@ -58,19 +88,15 @@ static void __dump_use_case(const char* prefix, const char *verb, const char *de _audio_dump_add_str(dump, "Verb [ %s ] Devices [ ", verb ? verb : AUDIO_USE_CASE_VERB_INACTIVE); /* Devices */ - if (devices) { - for (i = 0; i < dev_count; i++) { - _audio_dump_add_str(dump, (i != dev_count - 1) ? "%s, " : "%s", devices[i]); - } - } + for (i = 0; devices && i < dev_count; i++) + _audio_dump_add_str(dump, (i != dev_count - 1) ? "%s, " : "%s", devices[i]); + _audio_dump_add_str(dump, " ] Modifier [ "); /* Modifiers */ - if (modifiers) { - for (i = 0; i < mod_count; i++) { - _audio_dump_add_str(dump, (i != mod_count - 1) ? "%s, " : "%s", modifiers[i]); - } - } + for (i = 0; modifiers && i < mod_count; i++) + _audio_dump_add_str(dump, (i != mod_count - 1) ? "%s, " : "%s", modifiers[i]); + _audio_dump_add_str(dump, " ]"); AUDIO_LOG_INFO("TEST %s : %s", prefix, _audio_dump_get_str(dump)); @@ -123,13 +149,64 @@ audio_return_e _ucm_deinit(audio_hal_s *ah) return AUDIO_RET_OK; } -audio_return_e _ucm_get_device_name(audio_hal_s *ah, const char *use_case, audio_direction_e direction, const char **value) + +static int __use_case_get_count(const char **list) +{ + int i; + + for (i = 0; list && list[i]; i++) {} + + return i; +} + +static void __use_case_list_set(snd_use_case_mgr_t *uc_mgr, ucm_identifier_e identifier, + const char **list, int count) +{ + int i; + + for (i = 0; i < count; i++) { + AUDIO_LOG_INFO("%s : %s", ucm_set[identifier].description, list[i]); + if (snd_use_case_set(uc_mgr, ucm_set[identifier].identifier, list[i]) < 0) + AUDIO_LOG_ERROR("%s : %s, failed", ucm_set[identifier].description, list[i]); + } +} + +static void __ucm_get_list_to_update(const char **list, int count, + const char **old_list, int old_count, + const char **new_list, int *new_count, + bool *is_changed) +{ + int i = 0, j = 0; + int _new_count = 0; + + for (i = 0; i < count; i++) { + bool need_update = true; + + for (j = 0; j < old_count; j++) { + if (streq(list[i], old_list[j])) { + need_update = false; + break; + } + } + + if (need_update) { + if (!*is_changed) + *is_changed = true; + new_list[_new_count++] = list[i]; + } + } + + *new_count = _new_count; +} + +audio_return_e _ucm_get_device_name(audio_hal_s *ah, const char *use_case, audio_direction_e direction, + const char **value) { char identifier[70] = { 0, }; AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER); - AUDIO_RETURN_VAL_IF_FAIL(use_case, AUDIO_ERR_PARAMETER); AUDIO_RETURN_VAL_IF_FAIL(ah->ucm.uc_mgr, AUDIO_ERR_PARAMETER); + AUDIO_RETURN_VAL_IF_FAIL(use_case, AUDIO_ERR_PARAMETER); snprintf(identifier, sizeof(identifier), "%sPCM//%s", (direction == AUDIO_DIRECTION_IN) ? "Capture" : "Playback", use_case); @@ -157,7 +234,7 @@ audio_return_e _ucm_get_device_name(audio_hal_s *ah, const char *use_case, audio audio_return_e _ucm_set_use_case(audio_hal_s *ah, const char *verb, const char *devices[], const char *modifiers[]) { audio_return_e audio_ret = AUDIO_RET_OK; - int is_verb_changed = 0, is_dev_changed = 0, is_mod_changed = 0; + bool is_verb_changed = false, is_dev_changed = false, is_mod_changed = false; const char *old_verb = NULL, **old_dev_list = NULL, **old_mod_list = NULL; int old_dev_count = 0, dev_count = 0; int old_mod_count = 0, mod_count = 0; @@ -165,28 +242,40 @@ audio_return_e _ucm_set_use_case(audio_hal_s *ah, const char *verb, const char * const char **dis_mod_list = NULL, **ena_mod_list = NULL; int dis_dev_count = 0, ena_dev_count = 0; int dis_mod_count = 0, ena_mod_count = 0; - int i = 0, j = 0; AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER); AUDIO_RETURN_VAL_IF_FAIL(ah->ucm.uc_mgr, AUDIO_ERR_PARAMETER); AUDIO_RETURN_VAL_IF_FAIL(verb, AUDIO_ERR_PARAMETER); - snd_use_case_get(ah->ucm.uc_mgr, "_verb", &old_verb); - old_dev_count = snd_use_case_get_list(ah->ucm.uc_mgr, "_enadevs", &old_dev_list); - old_mod_count = snd_use_case_get_list(ah->ucm.uc_mgr, "_enamods", &old_mod_list); + snd_use_case_get(ah->ucm.uc_mgr, + ucm_set[UCM_IDENTIFIER_VERB].identifier, + &old_verb); + old_dev_count = snd_use_case_get_list(ah->ucm.uc_mgr, + ucm_set[UCM_IDENTIFIER_ENABLED_DEVICES].identifier, + &old_dev_list); + old_mod_count = snd_use_case_get_list(ah->ucm.uc_mgr, + ucm_set[UCM_IDENTIFIER_ENABLED_MODIFIERS].identifier, + &old_mod_list); __dump_use_case(UCM_PREFIX_CURRENT, old_verb, old_dev_list, old_dev_count, old_mod_list, old_mod_count); - if (devices) { - for (dev_count = 0; devices[dev_count]; dev_count++); - } - if (modifiers) { - for (mod_count = 0; modifiers[mod_count]; mod_count++); - } - + dev_count = __use_case_get_count(devices); + mod_count = __use_case_get_count(modifiers); __dump_use_case(UCM_PREFIX_REQUESTED, verb, devices, dev_count, modifiers, mod_count); - if (old_verb && streq(verb, old_verb)) { - AUDIO_LOG_DEBUG("current verb and new verb is same. No need to change verb, disable devices explicitely"); + is_verb_changed = !old_verb || !streq(verb, old_verb); + if (is_verb_changed) { + AUDIO_LOG_DEBUG("Setting new verb: %s", verb); + /* set new verb */ + if (snd_use_case_set(ah->ucm.uc_mgr, ucm_set[UCM_IDENTIFIER_VERB].identifier, verb) < 0) { + AUDIO_LOG_ERROR("Setting verb %s failed", verb); + audio_ret = AUDIO_ERR_UNDEFINED; + goto exit; + } + + __use_case_list_set(ah->ucm.uc_mgr, UCM_IDENTIFIER_ENABLE_DEVICE, devices, dev_count); + __use_case_list_set(ah->ucm.uc_mgr, UCM_IDENTIFIER_ENABLE_MODIFIER, modifiers, mod_count); + } else { + AUDIO_LOG_DEBUG("current verb and new verb is same. No need to change verb, disable devices explicitly"); if (old_dev_count > 0) { dis_dev_list = (const char **)calloc(old_dev_count, sizeof(const char *)); @@ -205,123 +294,19 @@ audio_return_e _ucm_set_use_case(audio_hal_s *ah, const char *verb, const char * assert(ena_mod_list); } - /* update disable modifiers list which are not present in new modifier list */ - for (i = 0; i < old_mod_count; i++) { - int need_disable_mod = 1; - - for (j = 0; j < mod_count; j++) { - if (streq(old_mod_list[i], modifiers[j])) { - need_disable_mod = 0; - break; - } - } - if (need_disable_mod) { - if (is_mod_changed == 0) - is_mod_changed = 1; - dis_mod_list[dis_mod_count++] = old_mod_list[i]; - } - } - - /* update disable devices list which are not present in new device list */ - for (i = 0; i < old_dev_count; i++) { - int need_disable_dev = 1; - - for (j = 0; j < dev_count; j++) { - if (streq(old_dev_list[i], devices[j])) { - need_disable_dev = 0; - break; - } - } - if (need_disable_dev) { - if (is_dev_changed == 0) - is_dev_changed = 1; - dis_dev_list[dis_dev_count++] = old_dev_list[i]; - } - } - - /* update enable devices list which are not present in old device list */ - for (i = 0; i < dev_count; i++) { - int need_enable_dev = 1; - - for (j = 0; j < old_dev_count; j++) { - if (streq(devices[i], old_dev_list[j])) { - need_enable_dev = 0; - break; - } - } - if (need_enable_dev) { - if (is_dev_changed == 0) - is_dev_changed = 1; - ena_dev_list[ena_dev_count++] = devices[i]; - } - } - - /* update enable modifiers list which are not present in old modifier list */ - for (i = 0; i < mod_count; i++) { - int need_enable_mod = 1; - - for (j = 0; j < old_mod_count; j++) { - if (streq(modifiers[i], old_mod_list[j])) { - need_enable_mod = 0; - break; - } - } - if (need_enable_mod) { - if (is_mod_changed == 0) - is_mod_changed = 1; - ena_mod_list[ena_mod_count++] = modifiers[i]; - } - } - - /* disable modifiers */ - for (i = 0; i < dis_mod_count; i++) { - AUDIO_LOG_INFO("Disable modifier : %s", dis_mod_list[i]); - if (snd_use_case_set(ah->ucm.uc_mgr, "_dismod", dis_mod_list[i]) < 0) - AUDIO_LOG_ERROR("disable %s modifier failed", dis_mod_list[i]); - } - - /* disable devices */ - for (i = 0; i < dis_dev_count; i++) { - AUDIO_LOG_INFO("Disable device : %s", dis_dev_list[i]); - if (snd_use_case_set(ah->ucm.uc_mgr, "_disdev", dis_dev_list[i]) < 0) - AUDIO_LOG_ERROR("disable %s device failed", dis_dev_list[i]); - } - - /* enable devices */ - for (i = 0; i < ena_dev_count; i++) { - AUDIO_LOG_INFO("Enable device : %s", ena_dev_list[i]); - if (snd_use_case_set(ah->ucm.uc_mgr, "_enadev", ena_dev_list[i]) < 0) - AUDIO_LOG_ERROR("enable %s device failed", ena_dev_list[i]); - } - - /* enable modifiers */ - for (i = 0; i < ena_mod_count; i++) { - AUDIO_LOG_INFO("Enable modifier : %s", ena_mod_list[i]); - if (snd_use_case_set(ah->ucm.uc_mgr, "_enamod", ena_mod_list[i]) < 0) - AUDIO_LOG_ERROR("enable %s modifier failed", ena_mod_list[i]); - } - } else { - is_verb_changed = 1; + __ucm_get_list_to_update(old_mod_list, old_mod_count, modifiers, mod_count, + dis_mod_list, &dis_mod_count, &is_mod_changed); + __ucm_get_list_to_update(old_dev_list, old_dev_count, devices, dev_count, + dis_dev_list, &dis_dev_count, &is_dev_changed); + __ucm_get_list_to_update(devices, dev_count, old_dev_list, old_dev_count, + ena_dev_list, &ena_dev_count, &is_dev_changed); + __ucm_get_list_to_update(modifiers, mod_count, old_mod_list, old_mod_count, + ena_mod_list, &ena_mod_count, &is_mod_changed); - AUDIO_LOG_DEBUG("Setting new verb: %s", verb); - /* set new verb */ - if (snd_use_case_set(ah->ucm.uc_mgr, "_verb", verb) < 0) { - AUDIO_LOG_ERROR("Setting verb %s failed", verb); - audio_ret = AUDIO_ERR_UNDEFINED; - goto exit; - } - /* enable devices */ - for (i = 0; i < dev_count; i++) { - AUDIO_LOG_DEBUG("Enable device : %s", devices[i]); - if (snd_use_case_set(ah->ucm.uc_mgr, "_enadev", devices[i]) < 0) - AUDIO_LOG_ERROR("Enable %s device failed", devices[i]); - } - /* enable modifiers */ - for (i = 0; i < mod_count; i++) { - AUDIO_LOG_DEBUG("Enable modifier : %s", modifiers[i]); - if (snd_use_case_set(ah->ucm.uc_mgr, "_enamod", modifiers[i]) < 0) - AUDIO_LOG_ERROR("Enable %s modifier failed", modifiers[i]); - } + __use_case_list_set(ah->ucm.uc_mgr, UCM_IDENTIFIER_DISABLE_MODIFIER, dis_mod_list, dis_mod_count); + __use_case_list_set(ah->ucm.uc_mgr, UCM_IDENTIFIER_DISABLE_DEVICE, dis_dev_list, dis_dev_count); + __use_case_list_set(ah->ucm.uc_mgr, UCM_IDENTIFIER_ENABLE_DEVICE, ena_dev_list, ena_dev_count); + __use_case_list_set(ah->ucm.uc_mgr, UCM_IDENTIFIER_ENABLE_MODIFIER, ena_mod_list, ena_mod_count); } exit: @@ -340,13 +325,20 @@ exit: if (ena_mod_list) free((void *)ena_mod_list); - if (is_verb_changed == 1 || is_dev_changed == 1 || is_mod_changed == 1) { + if (is_verb_changed || is_dev_changed || is_mod_changed ) { + /* dump current */ const char *new_verb = NULL, **new_dev_list = NULL, **new_mod_list = NULL; int new_dev_count = 0, new_mod_count = 0; - snd_use_case_get(ah->ucm.uc_mgr, "_verb", &new_verb); - new_dev_count = snd_use_case_get_list(ah->ucm.uc_mgr, "_enadevs", &new_dev_list); - new_mod_count = snd_use_case_get_list(ah->ucm.uc_mgr, "_enamods", &new_mod_list); + snd_use_case_get(ah->ucm.uc_mgr, + ucm_set[UCM_IDENTIFIER_VERB].identifier, + &new_verb); + new_dev_count = snd_use_case_get_list(ah->ucm.uc_mgr, + ucm_set[UCM_IDENTIFIER_ENABLED_DEVICES].identifier, + &new_dev_list); + new_mod_count = snd_use_case_get_list(ah->ucm.uc_mgr, + ucm_set[UCM_IDENTIFIER_ENABLED_MODIFIERS].identifier, + &new_mod_list); __dump_use_case(UCM_PREFIX_CHANGED, new_verb, new_dev_list, new_dev_count, new_mod_list, new_mod_count); if (new_verb) @@ -363,20 +355,23 @@ exit: audio_return_e _ucm_set_devices(audio_hal_s *ah, const char *verb, const char *devices[]) { audio_return_e audio_ret = AUDIO_RET_OK; - int is_verb_changed = 0, is_dev_changed = 0; + bool is_verb_changed = false, is_dev_changed = false; const char *old_verb = NULL, **old_dev_list = NULL; int old_dev_count = 0, dev_count = 0; const char **dis_dev_list = NULL, **ena_dev_list = NULL; int dis_dev_count = 0, ena_dev_count = 0; - int i = 0, j = 0; AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER); AUDIO_RETURN_VAL_IF_FAIL(ah->ucm.uc_mgr, AUDIO_ERR_PARAMETER); AUDIO_RETURN_VAL_IF_FAIL(verb, AUDIO_ERR_PARAMETER); AUDIO_RETURN_VAL_IF_FAIL(devices, AUDIO_ERR_PARAMETER); - snd_use_case_get(ah->ucm.uc_mgr, "_verb", &old_verb); - old_dev_count = snd_use_case_get_list(ah->ucm.uc_mgr, "_enadevs", &old_dev_list); + snd_use_case_get(ah->ucm.uc_mgr, + ucm_set[UCM_IDENTIFIER_VERB].identifier, + &old_verb); + old_dev_count = snd_use_case_get_list(ah->ucm.uc_mgr, + ucm_set[UCM_IDENTIFIER_ENABLED_DEVICES].identifier, + &old_dev_list); __dump_use_case(UCM_PREFIX_CURRENT, old_verb, old_dev_list, old_dev_count, NULL, 0); if (devices) { @@ -391,14 +386,25 @@ audio_return_e _ucm_set_devices(audio_hal_s *ah, const char *verb, const char *d } } } else { - for (dev_count = 0; devices[dev_count]; dev_count++); + dev_count = __use_case_get_count(devices); } } __dump_use_case(UCM_PREFIX_REQUESTED, verb, devices, dev_count, NULL, 0); - if (old_verb && streq(verb, old_verb)) { - AUDIO_LOG_DEBUG("current verb and new verb is same. No need to change verb, disable devices explicitely"); + is_verb_changed = !old_verb || !streq(verb, old_verb); + if (is_verb_changed) { + AUDIO_LOG_INFO("Setting new verb: %s", verb); + /* set new verb */ + if (snd_use_case_set(ah->ucm.uc_mgr, ucm_set[UCM_IDENTIFIER_VERB].identifier, verb) < 0) { + AUDIO_LOG_ERROR("Setting verb %s failed", verb); + audio_ret = AUDIO_ERR_UNDEFINED; + goto exit; + } + + __use_case_list_set(ah->ucm.uc_mgr, UCM_IDENTIFIER_ENABLE_DEVICE, devices, dev_count); + } else { + AUDIO_LOG_DEBUG("current verb and new verb is same. No need to change verb, disable devices explicitly"); if (old_dev_count > 0) { dis_dev_list = (const char **)calloc(old_dev_count, sizeof(const char *)); @@ -409,70 +415,13 @@ audio_return_e _ucm_set_devices(audio_hal_s *ah, const char *verb, const char *d assert(ena_dev_list); } - /* update disable devices list which are not present in new device list */ - for (i = 0; i < old_dev_count; i++) { - int need_disable_dev = 1; + __ucm_get_list_to_update(old_dev_list, old_dev_count, devices, dev_count, + dis_dev_list, &dis_dev_count, &is_dev_changed); + __ucm_get_list_to_update(devices, dev_count, old_dev_list, old_dev_count, + ena_dev_list, &ena_dev_count, &is_dev_changed); - for (j = 0; j < dev_count; j++) { - if (streq(old_dev_list[i], devices[j])) { - need_disable_dev = 0; - break; - } - } - if (need_disable_dev) { - if (is_dev_changed == 0) - is_dev_changed = 1; - dis_dev_list[dis_dev_count++] = old_dev_list[i]; - } - } - - /* update enable devices list which are not present in old device list */ - for (i = 0; i < dev_count; i++) { - int need_enable_dev = 1; - - for (j = 0; j < old_dev_count; j++) { - if (streq(devices[i], old_dev_list[j])) { - need_enable_dev = 0; - break; - } - } - if (need_enable_dev) { - if (is_dev_changed == 0) - is_dev_changed = 1; - ena_dev_list[ena_dev_count++] = devices[i]; - } - } - - /* disable devices */ - for (i = 0; i < dis_dev_count; i++) { - AUDIO_LOG_INFO("Disable device : %s", dis_dev_list[i]); - if (snd_use_case_set(ah->ucm.uc_mgr, "_disdev", dis_dev_list[i]) < 0) - AUDIO_LOG_ERROR("disable %s device failed", dis_dev_list[i]); - } - - /* enable devices */ - for (i = 0; i < ena_dev_count; i++) { - AUDIO_LOG_INFO("Enable device : %s", ena_dev_list[i]); - if (snd_use_case_set(ah->ucm.uc_mgr, "_enadev", ena_dev_list[i]) < 0) - AUDIO_LOG_ERROR("enable %s device failed", ena_dev_list[i]); - } - - } else { - is_verb_changed = 1; - - AUDIO_LOG_INFO("Setting new verb: %s", verb); - /* set new verb */ - if (snd_use_case_set(ah->ucm.uc_mgr, "_verb", verb) < 0) { - AUDIO_LOG_ERROR("Setting verb %s failed", verb); - audio_ret = AUDIO_ERR_UNDEFINED; - goto exit; - } - /* enable devices */ - for (i = 0; i < dev_count; i++) { - AUDIO_LOG_INFO("Enable device : %s", devices[i]); - if (snd_use_case_set(ah->ucm.uc_mgr, "_enadev", devices[i]) < 0) - AUDIO_LOG_ERROR("Enable %s device failed", devices[i]); - } + __use_case_list_set(ah->ucm.uc_mgr, UCM_IDENTIFIER_DISABLE_DEVICE, dis_dev_list, dis_dev_count); + __use_case_list_set(ah->ucm.uc_mgr, UCM_IDENTIFIER_ENABLE_DEVICE, ena_dev_list, ena_dev_count); } exit: @@ -485,12 +434,14 @@ exit: if (ena_dev_list) free((void *)ena_dev_list); - if (is_verb_changed == 1 || is_dev_changed == 1) { + if (is_verb_changed || is_dev_changed) { const char *new_verb = NULL, **new_dev_list = NULL; int new_dev_count = 0; - snd_use_case_get(ah->ucm.uc_mgr, "_verb", &new_verb); - new_dev_count = snd_use_case_get_list(ah->ucm.uc_mgr, "_enadevs", &new_dev_list); + snd_use_case_get(ah->ucm.uc_mgr, ucm_set[UCM_IDENTIFIER_VERB].identifier, &new_verb); + new_dev_count = snd_use_case_get_list(ah->ucm.uc_mgr, + ucm_set[UCM_IDENTIFIER_ENABLED_DEVICES].identifier, + &new_dev_list); __dump_use_case(UCM_PREFIX_CHANGED, new_verb, new_dev_list, new_dev_count, NULL, 0); if (new_verb) @@ -500,36 +451,45 @@ exit: } return audio_ret; - } audio_return_e _ucm_set_modifiers(audio_hal_s *ah, const char *verb, const char *modifiers[]) { audio_return_e audio_ret = AUDIO_RET_OK; - int is_verb_changed = 0, is_mod_changed = 0; + bool is_verb_changed = false, is_mod_changed = false; const char *old_verb = NULL, **old_mod_list = NULL; int old_mod_count = 0, mod_count = 0; const char **dis_mod_list = NULL, **ena_mod_list = NULL; int dis_mod_count = 0, ena_mod_count = 0; - int i = 0, j = 0; AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER); AUDIO_RETURN_VAL_IF_FAIL(ah->ucm.uc_mgr, AUDIO_ERR_PARAMETER); AUDIO_RETURN_VAL_IF_FAIL(verb, AUDIO_ERR_PARAMETER); AUDIO_RETURN_VAL_IF_FAIL(modifiers, AUDIO_ERR_PARAMETER); - snd_use_case_get(ah->ucm.uc_mgr, "_verb", &old_verb); - old_mod_count = snd_use_case_get_list(ah->ucm.uc_mgr, "_enamods", &old_mod_list); + snd_use_case_get(ah->ucm.uc_mgr, + ucm_set[UCM_IDENTIFIER_VERB].identifier, + &old_verb); + old_mod_count = snd_use_case_get_list(ah->ucm.uc_mgr, + ucm_set[UCM_IDENTIFIER_ENABLED_MODIFIERS].identifier, + &old_mod_list); __dump_use_case(UCM_PREFIX_CURRENT, old_verb, NULL, 0, old_mod_list, old_mod_count); - if (modifiers) { - for (mod_count = 0; modifiers[mod_count]; mod_count++); - } - + mod_count = __use_case_get_count(modifiers); __dump_use_case(UCM_PREFIX_REQUESTED, verb, NULL, 0, modifiers, mod_count); - if (old_verb && streq(verb, old_verb)) { - AUDIO_LOG_DEBUG("current verb and new verb is same. No need to change verb, disable devices explicitely"); + is_verb_changed = !old_verb || !streq(verb, old_verb); + if (is_verb_changed) { + AUDIO_LOG_DEBUG("Setting new verb: %s", verb); + /* set new verb */ + if (snd_use_case_set(ah->ucm.uc_mgr, ucm_set[UCM_IDENTIFIER_VERB].identifier, verb) < 0) { + AUDIO_LOG_ERROR("Setting verb %s failed", verb); + audio_ret = AUDIO_ERR_UNDEFINED; + goto exit; + } + __use_case_list_set(ah->ucm.uc_mgr, UCM_IDENTIFIER_ENABLE_MODIFIER, modifiers, mod_count); + } else { + AUDIO_LOG_DEBUG("current verb and new verb is same. No need to change verb, disable devices explicitly"); if (old_mod_count > 0) { dis_mod_list = (const char **)calloc(old_mod_count, sizeof(const char *)); @@ -540,69 +500,13 @@ audio_return_e _ucm_set_modifiers(audio_hal_s *ah, const char *verb, const char assert(ena_mod_list); } - /* update disable modifiers list which are not present in new modifier list */ - for (i = 0; i < old_mod_count; i++) { - int need_disable_mod = 1; + __ucm_get_list_to_update(old_mod_list, old_mod_count, modifiers, mod_count, + dis_mod_list, &dis_mod_count, &is_mod_changed); + __ucm_get_list_to_update(modifiers, mod_count, old_mod_list, old_mod_count, + ena_mod_list, &ena_mod_count, &is_mod_changed); - for (j = 0; j < mod_count; j++) { - if (streq(old_mod_list[i], modifiers[j])) { - need_disable_mod = 0; - break; - } - } - if (need_disable_mod) { - if (is_mod_changed == 0) - is_mod_changed = 1; - dis_mod_list[dis_mod_count++] = old_mod_list[i]; - } - } - - /* update enable modifiers list which are not present in old modifier list */ - for (i = 0; i < mod_count; i++) { - int need_enable_mod = 1; - - for (j = 0; j < old_mod_count; j++) { - if (streq(modifiers[i], old_mod_list[j])) { - need_enable_mod = 0; - break; - } - } - if (need_enable_mod) { - if (is_mod_changed == 0) - is_mod_changed = 1; - ena_mod_list[ena_mod_count++] = modifiers[i]; - } - } - - /* disable modifiers */ - for (i = 0; i < dis_mod_count; i++) { - AUDIO_LOG_INFO("Disable modifier : %s", dis_mod_list[i]); - if (snd_use_case_set(ah->ucm.uc_mgr, "_dismod", dis_mod_list[i]) < 0) - AUDIO_LOG_ERROR("disable %s modifier failed", dis_mod_list[i]); - } - - /* enable modifiers */ - for (i = 0; i < ena_mod_count; i++) { - AUDIO_LOG_INFO("Enable modifier : %s", ena_mod_list[i]); - if (snd_use_case_set(ah->ucm.uc_mgr, "_enamod", ena_mod_list[i]) < 0) - AUDIO_LOG_ERROR("enable %s modifier failed", ena_mod_list[i]); - } - } else { - is_verb_changed = 1; - - AUDIO_LOG_DEBUG("Setting new verb: %s", verb); - /* set new verb */ - if (snd_use_case_set(ah->ucm.uc_mgr, "_verb", verb) < 0) { - AUDIO_LOG_ERROR("Setting verb %s failed", verb); - audio_ret = AUDIO_ERR_UNDEFINED; - goto exit; - } - /* enable modifiers */ - for (i = 0; i < mod_count; i++) { - AUDIO_LOG_DEBUG("Enable modifier : %s", modifiers[i]); - if (snd_use_case_set(ah->ucm.uc_mgr, "_enamod", modifiers[i]) < 0) - AUDIO_LOG_ERROR("Enable %s modifier failed", modifiers[i]); - } + __use_case_list_set(ah->ucm.uc_mgr, UCM_IDENTIFIER_DISABLE_MODIFIER, dis_mod_list, dis_mod_count); + __use_case_list_set(ah->ucm.uc_mgr, UCM_IDENTIFIER_ENABLE_MODIFIER, ena_mod_list, ena_mod_count); } exit: @@ -615,12 +519,16 @@ exit: if (ena_mod_list) free((void *)ena_mod_list); - if (is_verb_changed == 1 || is_mod_changed == 1) { + if (is_verb_changed || is_mod_changed) { const char *new_verb = NULL, **new_mod_list = NULL; int new_mod_count = 0; - snd_use_case_get(ah->ucm.uc_mgr, "_verb", &new_verb); - new_mod_count = snd_use_case_get_list(ah->ucm.uc_mgr, "_enamods", &new_mod_list); + snd_use_case_get(ah->ucm.uc_mgr, + ucm_set[UCM_IDENTIFIER_VERB].identifier, + &new_verb); + new_mod_count = snd_use_case_get_list(ah->ucm.uc_mgr, + ucm_set[UCM_IDENTIFIER_ENABLED_MODIFIERS].identifier, + &new_mod_list); __dump_use_case(UCM_PREFIX_CHANGED, new_verb, NULL, 0, new_mod_list, new_mod_count); if (new_verb) @@ -640,7 +548,9 @@ audio_return_e _ucm_get_verb(audio_hal_s *ah, const char **value) AUDIO_RETURN_VAL_IF_FAIL(ah->ucm.uc_mgr, AUDIO_ERR_PARAMETER); AUDIO_RETURN_VAL_IF_FAIL(value, AUDIO_ERR_PARAMETER); - if ((ret = snd_use_case_get(ah->ucm.uc_mgr, "_verb", value)) < 0) { + if ((ret = snd_use_case_get(ah->ucm.uc_mgr, + ucm_set[UCM_IDENTIFIER_VERB].identifier, + value)) < 0) { AUDIO_LOG_ERROR("Getting current verb failed: Reason %d", ret); ret = AUDIO_ERR_UNDEFINED; } @@ -657,7 +567,9 @@ audio_return_e _ucm_reset_use_case(audio_hal_s *ah) AUDIO_LOG_INFO(">>> UCM reset Verb [ %s ]", AUDIO_USE_CASE_VERB_INACTIVE); - if ((ret = snd_use_case_set(ah->ucm.uc_mgr, "_verb", AUDIO_USE_CASE_VERB_INACTIVE)) < 0) { + if ((ret = snd_use_case_set(ah->ucm.uc_mgr, + ucm_set[UCM_IDENTIFIER_VERB].identifier, + AUDIO_USE_CASE_VERB_INACTIVE)) < 0) { AUDIO_LOG_ERROR("Reset use case failed: Reason %d", ret); ret = AUDIO_ERR_UNDEFINED; } diff --git a/tizen-audio-volume.c b/tizen-audio-volume.c index 5e363d0..0d87447 100644 --- a/tizen-audio-volume.c +++ b/tizen-audio-volume.c @@ -41,7 +41,7 @@ #define RADIO_TUNING_VOLUME_LEVELS "fmradio:volume_levels" #define RADIO_TUNING_VOLUME_TABLE "fmradio:volume_table" -uint32_t g_master_volume_level = 100; +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 */ |