sound: Add sound pattern priority parsing 02/302902/3
authorYunhee Seo <yuni.seo@samsung.com>
Thu, 14 Dec 2023 04:53:16 +0000 (13:53 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Mon, 18 Dec 2023 08:26:54 +0000 (17:26 +0900)
To support sound pattern play with priority, this patch is added.
[SoundPatternPriority] section is supported.
It is almost similar to the usage of [Sound] section.

[SoundPatternPriority] format
FEEDBACK_PATTERN_XXX=priority value(integer 0-N)

The detailed description is added to common/data/sound.conf file.

Change-Id: I526c0054ff9fd05100aa4585ae8c3dad59335fb6
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
common/data/sound-theme1.conf
common/data/sound.conf
src/sound-parser.c
src/sound-parser.h
src/sound-theme-manager.c
src/sound-theme-manager.h
src/sound.c

index 5e7a881..6078c37 100644 (file)
@@ -26,4 +26,34 @@ FEEDBACK_PATTERN_LIST_SLIDER=/usr/share/feedback/sound/operation/operation.wav
 FEEDBACK_PATTERN_VOLUME_KEY=/usr/share/feedback/sound/operation/operation.wav
 FEEDBACK_PATTERN_CHARGERCONN_ON_CALL=/usr/share/feedback/sound/operation/operation.wav
 FEEDBACK_PATTERN_LOWBATT_ON_CALL=/usr/share/feedback/sound/operation/operation.wav
-FEEDBACK_PATTERN_SCREEN_CAPTURE=/usr/share/feedback/sound/operation/shutter.wav
\ No newline at end of file
+FEEDBACK_PATTERN_SCREEN_CAPTURE=/usr/share/feedback/sound/operation/shutter.wav
+
+[SoundPatternPriority]
+FEEDBACK_PATTERN_TAP=0
+FEEDBACK_PATTERN_SIP=1
+FEEDBACK_PATTERN_KEY0=2
+FEEDBACK_PATTERN_KEY1=3
+FEEDBACK_PATTERN_KEY2=4
+FEEDBACK_PATTERN_KEY3=5
+FEEDBACK_PATTERN_KEY4=6
+FEEDBACK_PATTERN_KEY5=7
+FEEDBACK_PATTERN_KEY6=8
+FEEDBACK_PATTERN_KEY7=9
+FEEDBACK_PATTERN_KEY8=10
+FEEDBACK_PATTERN_KEY9=11
+FEEDBACK_PATTERN_KEY_STAR=12
+FEEDBACK_PATTERN_KEY_SHARP=13
+FEEDBACK_PATTERN_KEY_BACK=14
+FEEDBACK_PATTERN_HW_TAP=15
+FEEDBACK_PATTERN_POWERON=16
+FEEDBACK_PATTERN_CHARGERCONN=17
+FEEDBACK_PATTERN_LOWBATT=18
+FEEDBACK_PATTERN_LOCK=19
+FEEDBACK_PATTERN_UNLOCK=20
+FEEDBACK_PATTERN_SILENT_OFF=21
+FEEDBACK_PATTERN_LIST_REORDER=22
+FEEDBACK_PATTERN_LIST_SLIDER=23
+FEEDBACK_PATTERN_VOLUME_KEY=24
+FEEDBACK_PATTERN_CHARGERCONN_ON_CALL=25
+FEEDBACK_PATTERN_LOWBATT_ON_CALL=26
+FEEDBACK_PATTERN_SCREEN_CAPTURE=27
\ No newline at end of file
index 2ec9dfe..8b362ad 100644 (file)
 # SoundThemeId=1
 # SoundThemePath=/usr/share/feedback/sound-theme1.conf
 # SoundThemeDefault=yes
+#
+# [SoundPatternPriority]
+# - This section allows priority to be given to the sound play.
+#   [SoundPatternPriority] should always be located with [Sound] section.
+#   The sound pattern priority value must be 0 or higher.
+#   And the smaller value, the higher the priority.
+#   That is, the 0 value has the highest priority.
+#   Do not try to put -1 value, that means no-priority and parsing will fail.
+#   If either [Sound] or [SoundPatternPriority] misses the same pattern, parsing will fail.
+#   The sound pattern pairs must be matched.
+#   You can omit this section and use [Sound] section existing method.
+#   Detailed example is exist in sound-theme1.conf file.
+#
+# Example
+# [SoundPatternPriority]
+# FEEDBACK_PATTERN_XXX=(integer)0-N
+# FEEDBACK_PATTERN_TAP=0
+# FEEDBACK_PATTERN_SIP=1
 
 [SoundTheme]
 SoundThemeId=1
index 2050968..c1dcac7 100644 (file)
@@ -29,6 +29,7 @@
 #include "sound-theme-manager.h"
 
 #define INITIAL_DEFAULT_SOUND_THEME_ID                         -1
+#define INITIAL_SOUND_PRIORITY                                 -1
 #define SOUND_CONF_FILE FEEDBACK_SYS_RO_SHARE"/feedback/sound.conf"
 
 static int default_sound_theme_id = INITIAL_DEFAULT_SOUND_THEME_ID;
@@ -207,6 +208,7 @@ static int parse_sound_property(const struct parse_result *result, void *data)
        GList *temp_glist = NULL;
        int pattern = 0;
        GHashTable *sound_config_info;
+       struct sound_pattern_data* sound_data = NULL;
 
        if (!result || !result->props)
                return 0;
@@ -223,8 +225,13 @@ static int parse_sound_property(const struct parse_result *result, void *data)
                pattern = profile->get_pattern_enum(extracted_section_prop->key);
                if (pattern < 0 || pattern >= profile->max_pattern)
                        return -EINVAL;
+               sound_data = (struct sound_pattern_data*)calloc(1, sizeof(struct sound_pattern_data));
+               if (!sound_data)
+                       return -ENOMEM;
+               sound_data->path = g_strdup(extracted_section_prop->value);
+               sound_data->priority = INITIAL_SOUND_PRIORITY;
                g_hash_table_insert(sound_config_info, GINT_TO_POINTER(pattern),
-                                       g_strdup(extracted_section_prop->value));
+                                       (gpointer)sound_data);
        }
        return 0;
 }
@@ -245,4 +252,81 @@ int sound_parser_get_config_info(const char *file_path, void *config_info)
        }
 
        return 0;
+}
+
+static int parse_sound_pattern_priority_property(const struct parse_result *result, void *data)
+{
+       struct section_property *extracted_section_prop = NULL;
+       GList *temp_glist = NULL;
+       int pattern = 0;
+       GHashTable *sound_config_info = NULL;
+       struct sound_pattern_data* sound_data = NULL;
+
+       if (!result || !result->props)
+               return 0;
+
+       if (!data)
+               return -EINVAL;
+
+       if (!MATCH("SoundPatternPriority", result->section))
+               return 0;
+
+       sound_config_info = (GHashTable*)data;
+
+       SYS_G_LIST_FOREACH(result->props, temp_glist, extracted_section_prop) {
+               pattern = profile->get_pattern_enum(extracted_section_prop->key);
+               if (pattern < 0 || pattern >= profile->max_pattern)
+                       return -EINVAL;
+               sound_data = g_hash_table_lookup(sound_config_info, GINT_TO_POINTER(pattern));
+               if (!sound_data) {
+                       _E("Failed to parse sound pattern priority, [Sound] and [SoundPatternPriority] pattern does not match");
+                       return -EPERM;
+               }
+               sound_data->priority = atoi(extracted_section_prop->value);
+       }
+       return 0;
+}
+
+static bool is_sound_section_matching_sound_priority_section(void *data)
+{
+       GList *value_list = NULL;
+       GList *temp_glist = NULL;
+       struct sound_pattern_data *sound_data = NULL;
+       int number_of_defined_priority_pattern = 0;
+
+       if (!data)
+               return -EINVAL;
+
+       value_list = g_hash_table_get_values((GHashTable*)data);
+
+       SYS_G_LIST_FOREACH(value_list, temp_glist, sound_data) {
+               if (sound_data && sound_data->priority == INITIAL_SOUND_PRIORITY)
+                       number_of_defined_priority_pattern++;
+       }
+
+       g_list_free(value_list);
+       if (number_of_defined_priority_pattern == 0 || number_of_defined_priority_pattern == g_hash_table_size((GHashTable*)data))
+               return true;
+
+       _E("Failed to parse sound pattern priority, [Sound] and [SoundPatternPriority] pattern does not match");
+       return false;
+}
+
+int sound_parser_get_priority_info(const char *file_path, void *priority_info)
+{
+       int ret = 0;
+       GHashTable *sound_info;
+
+       if (!file_path || !priority_info)
+               return -EINVAL;
+
+       sound_info = (GHashTable*)priority_info;
+       ret = libsys_config_parse_by_section(file_path, parse_sound_pattern_priority_property, sound_info);
+       if (ret < 0)
+               return -EPERM;
+
+       if (!is_sound_section_matching_sound_priority_section(sound_info))
+               return -EPERM;
+
+       return 0;
 }
\ No newline at end of file
index ed759c7..b2d5723 100644 (file)
@@ -21,5 +21,6 @@
 int sound_parser_init(void);
 void sound_parser_exit(void);
 int sound_parser_get_config_info(const char *file_path, void *config_info);
+int sound_parser_get_priority_info(const char *file_path, void *priority_info);
 
 #endif
\ No newline at end of file
index 7cea4b4..1d29bf0 100644 (file)
@@ -35,6 +35,13 @@ struct sound_theme_element {
 static unsigned int default_sound_theme_id;
 static GList *g_sound_theme_list;
 
+static void cleanup_sound_pattern_data(gpointer data)
+{
+       struct sound_pattern_data *sound_data = data;
+       g_free((char*)sound_data->path);
+       free(sound_data);
+}
+
 bool sound_thememan_is_sound_theme_id_exist(unsigned int sound_theme_id)
 {
        struct sound_theme_element *sound_theme_elem = NULL;
@@ -70,17 +77,27 @@ int sound_thememan_get_number_of_theme(unsigned int *number_of_theme)
        return 0;
 }
 
-const char* sound_thememan_get_pattern_sound_path(unsigned int sound_theme_id, feedback_pattern_e pattern)
+int sound_thememan_get_pattern_data(unsigned int sound_theme_id, feedback_pattern_e pattern,
+                                               void *sound_pattern_data)
 {
        struct sound_theme_element *sound_theme_elem = NULL;
        GList *temp_glist = NULL;
+       struct sound_pattern_data *sound_data = NULL;
+
+       if (!sound_pattern_data)
+               return -EINVAL;
 
        SYS_G_LIST_FOREACH(g_sound_theme_list, temp_glist, sound_theme_elem) {
-               if (sound_theme_elem->id == sound_theme_id)
-                       return g_hash_table_lookup(sound_theme_elem->sound_info, GINT_TO_POINTER(pattern));
+               if (sound_theme_elem->id == sound_theme_id) {
+                       sound_data = g_hash_table_lookup(sound_theme_elem->sound_info, GINT_TO_POINTER(pattern));
+                       if (sound_data) {
+                               *(struct sound_pattern_data**)sound_pattern_data = sound_data;
+                               return 0;
+                       }
+               }
        }
 
-       return NULL;
+       return 0;
 }
 
 int sound_thememan_add_sound_theme(unsigned int sound_theme_id, const char* conf_file_path)
@@ -88,7 +105,7 @@ int sound_thememan_add_sound_theme(unsigned int sound_theme_id, const char* conf
        struct sound_theme_element *sound_theme_elem = NULL;
        int ret = 0;
        GHashTable *sound_info = g_hash_table_new_full(g_direct_hash, g_direct_equal,
-                                                               NULL, g_free);
+                                                               NULL, cleanup_sound_pattern_data);
 
        if (!sound_info) {
                _E("Failed to allocate memory for sound_info.");
@@ -108,6 +125,10 @@ int sound_thememan_add_sound_theme(unsigned int sound_theme_id, const char* conf
                goto out_add_sound_theme_fail;
        }
 
+       ret = sound_parser_get_priority_info(conf_file_path, sound_info);
+       if (ret < 0)
+               goto out_add_sound_theme_fail;
+
        sound_theme_elem->id = sound_theme_id;
        sound_theme_elem->sound_info = sound_info;
        g_sound_theme_list = g_list_append(g_sound_theme_list, sound_theme_elem);
index 9e01cfc..2fb3443 100644 (file)
 
 #include "feedback-ids.h"
 
+struct sound_pattern_data {
+       const char *path;
+       int priority;
+};
+
 bool sound_thememan_is_sound_theme_id_exist(unsigned int sound_theme_id);
 void sound_thememan_set_default_sound_theme_id(unsigned int sound_theme_id);
 void sound_thememan_get_default_sound_theme_id(unsigned int *sound_theme_id);
-const char* sound_thememan_get_pattern_sound_path(unsigned int sound_theme_id, feedback_pattern_e pattern);
+int sound_thememan_get_pattern_data(unsigned int sound_theme_id, feedback_pattern_e pattern,
+                                               void *sound_pattern_data);
 int sound_thememan_get_number_of_theme(unsigned int *number_of_theme);
 int sound_thememan_add_sound_theme(unsigned int sound_theme_id, const char* conf_file_path);
 int sound_thememan_get_sound_theme_ids(unsigned int *count_of_theme, unsigned int **sound_theme_ids);
index eb2c040..9cf5402 100644 (file)
@@ -50,9 +50,11 @@ static int touch_sndstatus;
 static int keytone_sndstatus;
 static unsigned int current_theme_id = 0;
 
-static char *get_data(feedback_pattern_e pattern)
+static const char *get_data(feedback_pattern_e pattern)
 {
-       char *data;
+       const char *data;
+       struct sound_pattern_data *sound_data = NULL;
+       int ret = 0;
 
        if (pattern <= FEEDBACK_PATTERN_NONE ||
            pattern >= profile->max_pattern)
@@ -62,11 +64,16 @@ static char *get_data(feedback_pattern_e pattern)
        if (data)
                return data;
 
-       data = sound_thememan_get_pattern_sound_path(current_theme_id, pattern);
-       if (!data)
+       ret = sound_thememan_get_pattern_data(current_theme_id, pattern, &sound_data);
+       if (ret < 0)
+               return NULL;
+
+       if (!sound_data) {
                _E("Not supported pattern : %d", pattern);
+               return NULL;
+       }
 
-       return data;
+       return sound_data->path;
 }
 
 inline int is_sound_mode(void)
@@ -203,7 +210,7 @@ static int sound_play(feedback_pattern_e pattern, bool always)
        struct stat buf;
        int retry = FEEDBACK_RETRY_CNT, ret;
        sound_stream_info_h stream_info;
-       char *path;
+       const char *path;
        int level;
 
        if (vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &sndstatus) < 0) {
@@ -345,7 +352,7 @@ check_pattern:
 static int sound_is_supported(feedback_pattern_e pattern, bool *supported)
 {
        struct stat buf;
-       char *path;
+       const char *path;
        bool ret = true;
 
        if (!supported) {
@@ -384,7 +391,7 @@ static int sound_stop(void)
 //LCOV_EXCL_START Not used function
 static int sound_get_path(feedback_pattern_e pattern, char *buf, unsigned int buflen)
 {
-       char *cur_path;
+       const char *cur_path;
        int ret = 0;
 
        if (!buf || buflen == 0)