Add internal volume API set 70/218770/1 accepted/tizen/unified/20191204.042030 submit/tizen/20191202.063949
authorSangchul Lee <sc11.lee@samsung.com>
Tue, 12 Nov 2019 05:16:06 +0000 (14:16 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Thu, 28 Nov 2019 03:26:41 +0000 (12:26 +0900)
Initially, this patch supports the bixby volume type.

[Version] 0.12.56
[Issue Type] New feature

Change-Id: Ib6739238356dd52aa2d519154ece65a892254dfa
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
include/mm_sound.h
include/mm_sound_client.h
mm_sound.c
mm_sound_client.c
packaging/libmm-sound.spec

index 4081595be93fa92a852c455fc9bf435ffa40b7cc..39bad8295d656f733c927d750fcc4dd8431c53ae 100644 (file)
@@ -295,6 +295,10 @@ typedef enum {
        VOLUME_TYPE_MAX,                                /**< Volume type count */
 } volume_type_t;
 
+typedef enum {
+       VOLUME_TYPE_BIXBY,                              /**< Bixby volume type */
+} volume_type_internal_t;
+
 typedef enum {
        VOLUME_GAIN_DEFAULT             = 0,
        VOLUME_GAIN_DIALER              = 1<<8,
@@ -326,9 +330,9 @@ typedef enum {
 } mm_sound_source_type_e;
 
 /**
- * Active volume change callback function type.
+ * Volume change callback function prototype.
  *
- * @param      type                    [in]    The sound type of changed volume
+ * @param      type                    [in]    The type of changed volume
  * @param      volume                  [in]    The new volume value
  * @param      user_data               [in]    Argument passed when callback has called
  *
@@ -364,7 +368,6 @@ int mm_sound_remove_volume_changed_callback(unsigned int id);
  */
 int mm_sound_volume_set_value(volume_type_t type, const unsigned int value);
 
-
 /**
  * This function is to get volume level of certain volume type.
  *
@@ -399,6 +402,13 @@ int mm_sound_volume_get_value(volume_type_t type, unsigned int *value);
 int mm_sound_set_mute(volume_type_t type, bool mute);
 int mm_sound_get_mute(volume_type_t type, bool *muted);
 
+
+typedef void (*mm_sound_volume_changed_cb_internal) (volume_type_internal_t type, unsigned int volume, void *user_data);
+int mm_sound_add_volume_changed_callback_internal(mm_sound_volume_changed_cb_internal func, void* user_data, unsigned int *id);
+int mm_sound_remove_volume_changed_callback_internal(unsigned int id);
+int mm_sound_volume_set_value_internal(volume_type_internal_t type, const unsigned int value);
+int mm_sound_volume_get_value_internal(volume_type_internal_t type, unsigned int *value);
+
 /**
  * This function is to set sound filter and apply to selected stream type.
  *
index 0781b7a2599b2bbb073cf7d3f63b93fd148d524f..35d718a84b618e14ff123656acf9251cc63981dd 100644 (file)
@@ -42,9 +42,12 @@ int mm_sound_client_stop_sound(int handle);
 int mm_sound_client_set_volume_by_type(volume_type_t type, const unsigned int level);
 int mm_sound_client_get_volume_by_type(volume_type_t type, unsigned int *level);
 int mm_sound_client_add_volume_changed_callback(mm_sound_volume_changed_cb func, void* user_data, unsigned int *subs_id);
+int mm_sound_client_add_volume_changed_callback_internal(mm_sound_volume_changed_cb_internal func, void* user_data, unsigned int *subs_id);
 int mm_sound_client_remove_volume_changed_callback(unsigned int subs_id);
 int mm_sound_client_set_mute_by_type(volume_type_t type, bool mute);
 int mm_sound_client_get_mute_by_type(volume_type_t type, bool *muted);
+int mm_sound_client_set_volume_by_internal_type(volume_type_internal_t type, const unsigned int level);
+int mm_sound_client_get_volume_by_internal_type(volume_type_internal_t type, unsigned int *level);
 int mm_sound_client_set_filter_by_type(const char *stream_type, const char *filter_name, const char *filter_parameters, const char *filter_group);
 int mm_sound_client_unset_filter_by_type(const char *stream_type);
 int mm_sound_client_control_filter_by_type(const char *stream_type, const char *filter_name, const char *filter_controls);
index a7b473ddb4d77850400d0af976f80414a43712f5..e7fbf34cbb2787066c8f3d1d9831ea0c298b75e4 100644 (file)
@@ -54,6 +54,15 @@ static const char* _get_volume_str(volume_type_t type)
        return (type < VOLUME_TYPE_MAX) ? volume_type_str[type] : "Unknown";
 }
 
+static const char* _get_volume_str_internal(volume_type_internal_t type)
+{
+       static const char *volume_type_str[] = {
+               "BIXBY"
+       };
+
+       return (type < (VOLUME_TYPE_BIXBY + 1)) ? volume_type_str[type] : "Unknown";
+}
+
 EXPORT_API
 int mm_sound_add_volume_changed_callback(mm_sound_volume_changed_cb func, void* user_data, unsigned int *subs_id)
 {
@@ -114,6 +123,64 @@ int mm_sound_volume_get_value(volume_type_t type, unsigned int *value)
        return ret;
 }
 
+EXPORT_API
+int mm_sound_add_volume_changed_callback_internal(mm_sound_volume_changed_cb_internal func, void* user_data, unsigned int *subs_id)
+{
+       int ret = MM_ERROR_NONE;
+
+       if (func == NULL || subs_id == NULL) {
+               debug_error("argument is not valid");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       ret = mm_sound_client_add_volume_changed_callback_internal(func, user_data, subs_id);
+       if (ret < 0)
+               debug_error("Can not add internal volume changed callback, ret = %x", ret);
+
+       return ret;
+}
+
+EXPORT_API
+int mm_sound_remove_volume_changed_callback_internal(unsigned int subs_id)
+{
+       int ret = MM_ERROR_NONE;
+
+       ret = mm_sound_client_remove_volume_changed_callback(subs_id);
+       if (ret < 0)
+               debug_error("Can not remove internal volume changed callback, ret = %x", ret);
+
+       return ret;
+}
+
+EXPORT_API
+int mm_sound_volume_set_value_internal(volume_type_internal_t type, const unsigned int value)
+{
+       int ret = MM_ERROR_NONE;
+
+       /* request daemon to set volume */
+       ret = mm_sound_client_set_volume_by_internal_type(type, value);
+       if (ret)
+               debug_error("can not set internal volume, type(%s), value(%d), ret=0x%x", _get_volume_str_internal(type), value, ret);
+       else
+               debug_msg("set (%s) volume to (%d)",  _get_volume_str_internal(type), value);
+
+       return ret;
+}
+
+EXPORT_API
+int mm_sound_volume_get_value_internal(volume_type_internal_t type, unsigned int *value)
+{
+       int ret = MM_ERROR_NONE;
+
+       ret = mm_sound_client_get_volume_by_internal_type(type, value);
+       if (ret)
+               debug_error("can not get internal volume, type(%s), ret=0x%x", _get_volume_str_internal(type), ret);
+       else
+               debug_msg("(%s) volume : %d",  _get_volume_str_internal(type), *value);
+
+       return ret;
+}
+
 EXPORT_API
 int mm_sound_set_mute(volume_type_t type, bool mute)
 {
index ad7e57cc78e4f3f474319c163be6f218bfd244e3..ad21494c879d0142ee01c02a56d614bcfccd0e83 100644 (file)
@@ -60,6 +60,9 @@
 #define VCONF_KEY_MUTE_TYPE_VOIP                       VCONF_KEY_MUTE_PREFIX"/voip"
 #define VCONF_KEY_MUTE_TYPE_VOICE              VCONF_KEY_MUTE_PREFIX"/voice"
 
+/* For internal use */
+#define VCONF_KEY_VOLUME_TYPE_BIXBY            VCONF_KEY_VOLUME_PREFIX"/bixby"
+
 static char *g_volume_vconf[VOLUME_TYPE_MAX] = {
        VCONF_KEY_VOLUME_TYPE_SYSTEM,           /* VOLUME_TYPE_SYSTEM */
        VCONF_KEY_VOLUME_TYPE_NOTIFICATION,     /* VOLUME_TYPE_NOTIFICATION */
@@ -72,6 +75,10 @@ static char *g_volume_vconf[VOLUME_TYPE_MAX] = {
        VCONF_KEY_VOLUME_TYPE_ANDROID           /* VOLUME_TYPE_FIXED */
 };
 
+static char *g_volume_vconf_internal[] = {
+       VCONF_KEY_VOLUME_TYPE_BIXBY,            /* VOLUME_TYPE_BIXBY */
+};
+
 static char *g_mute_vconf[] = {
        VCONF_KEY_MUTE_TYPE_SYSTEM,             /* MUTE_TYPE_SYSTEM */
        VCONF_KEY_MUTE_TYPE_NOTIFICATION,       /* MUTE_TYPE_NOTIFICATION */
@@ -693,7 +700,7 @@ failed:
        return ret;
 }
 
-int __convert_volume_type_to_str(int volume_type, char **volume_type_str)
+int __convert_volume_type_to_str(volume_type_t volume_type, char **volume_type_str)
 {
        int ret = MM_ERROR_NONE;
 
@@ -729,38 +736,64 @@ int __convert_volume_type_to_str(int volume_type, char **volume_type_str)
                debug_error("unexpected volume type [%d]", volume_type);
                return MM_ERROR_SOUND_INTERNAL;
        }
-       if (!strncmp(*volume_type_str, "", VOLUME_TYPE_LEN)) {
-               debug_error("could not find the volume_type[%d] in this switch case statement", volume_type);
-               ret = MM_ERROR_SOUND_INTERNAL;
-       } else {
-               debug_log("volume_type[%s]", *volume_type_str);
+       debug_log("volume_type[%s]", *volume_type_str);
+       return ret;
+}
+
+int __convert_volume_type_internal_to_str(volume_type_internal_t volume_type, char **volume_type_str)
+{
+       int ret = MM_ERROR_NONE;
+
+       if (!volume_type_str)
+               return MM_ERROR_COMMON_INVALID_ARGUMENT;
+
+       switch (volume_type) {
+       case VOLUME_TYPE_BIXBY:
+               *volume_type_str = "bixby";
+               break;
+       default:
+               debug_error("unexpected volume type [%d]", volume_type);
+               return MM_ERROR_SOUND_INTERNAL;
        }
+       debug_log("volume_type[%s]", *volume_type_str);
        return ret;
 }
 
-static int __convert_volume_type_to_int(const char *volume_type_str, volume_type_t *volume_type)
+static int __convert_volume_type_to_int(const char *volume_type_str, int *volume_type, bool *is_for_internal)
 {
        int ret = MM_ERROR_NONE;
 
-       if (!volume_type || !volume_type_str)
+       if (!volume_type || !volume_type_str || !is_for_internal)
                return MM_ERROR_COMMON_INVALID_ARGUMENT;
 
        if (!strncmp(volume_type_str, "system", VOLUME_TYPE_LEN)) {
                *volume_type = VOLUME_TYPE_SYSTEM;
+               *is_for_internal = false;
        } else if (!strncmp(volume_type_str, "notification", VOLUME_TYPE_LEN)) {
                *volume_type = VOLUME_TYPE_NOTIFICATION;
+               *is_for_internal = false;
        } else if (!strncmp(volume_type_str, "alarm", VOLUME_TYPE_LEN)) {
                *volume_type = VOLUME_TYPE_ALARM;
+               *is_for_internal = false;
        } else if (!strncmp(volume_type_str, "ringtone", VOLUME_TYPE_LEN)) {
                *volume_type = VOLUME_TYPE_RINGTONE;
+               *is_for_internal = false;
        } else if (!strncmp(volume_type_str, "media", VOLUME_TYPE_LEN)) {
                *volume_type = VOLUME_TYPE_MEDIA;
+               *is_for_internal = false;
        } else if (!strncmp(volume_type_str, "call", VOLUME_TYPE_LEN)) {
                *volume_type = VOLUME_TYPE_CALL;
+               *is_for_internal = false;
        } else if (!strncmp(volume_type_str, "voip", VOLUME_TYPE_LEN)) {
                *volume_type = VOLUME_TYPE_VOIP;
+               *is_for_internal = false;
        } else if (!strncmp(volume_type_str, "voice", VOLUME_TYPE_LEN)) {
                *volume_type = VOLUME_TYPE_VOICE;
+               *is_for_internal = false;
+       /* else-if statements below are for internal use */
+       } else if (!strncmp(volume_type_str, "bixby", VOLUME_TYPE_LEN)) {
+               *volume_type = VOLUME_TYPE_BIXBY;
+               *is_for_internal = true;
        } else {
                debug_log("Invalid volume type : [%s]", volume_type_str);
                ret = MM_ERROR_SOUND_INTERNAL;
@@ -818,10 +851,51 @@ int mm_sound_client_get_volume_by_type(volume_type_t type, unsigned int *level)
        return ret;
 }
 
+int mm_sound_client_set_volume_by_internal_type(volume_type_internal_t type, const unsigned int level)
+{
+       int ret = MM_ERROR_NONE;
+       char *type_str = NULL;
+
+       debug_fenter();
+
+       if ((ret = __convert_volume_type_internal_to_str(type, &type_str)) != MM_ERROR_NONE) {
+               debug_error("volume type convert failed");
+               goto failed;
+       }
+
+       ret = mm_sound_proxy_set_volume_by_type(type_str, level);
+
+failed:
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_client_get_volume_by_internal_type(volume_type_internal_t type, unsigned int *level)
+{
+       int ret = MM_ERROR_NONE;
+       int vconf_value = 0;
+
+       if (level == NULL) {
+               debug_error("invalid argument, level is null");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       /* Get volume value from VCONF */
+       if (vconf_get_int(g_volume_vconf_internal[type], &vconf_value)) {
+               debug_error("vconf_get_int(%s) failed..\n", g_volume_vconf_internal[type]);
+               return MM_ERROR_SOUND_INTERNAL;
+       }
+
+       *level = vconf_value;
+
+       return ret;
+}
+
 static void _mm_sound_volume_changed_callback_wrapper_func(const char *direction, const char *volume_type_str,
                                                                                                                int volume_level, void *userdata)
 {
-       volume_type_t volume_type = 0;
+       int volume_type = 0;
+       bool is_for_internal =  false;
        struct callback_data *cb_data = (struct callback_data *) userdata;
 
        debug_log("direction : %s, volume_type : %s, volume_level : %d",
@@ -832,13 +906,20 @@ static void _mm_sound_volume_changed_callback_wrapper_func(const char *direction
                return;
        }
 
-       if (__convert_volume_type_to_int(volume_type_str, &volume_type) != MM_ERROR_NONE) {
+       if (__convert_volume_type_to_int(volume_type_str, &volume_type, &is_for_internal) != MM_ERROR_NONE) {
                debug_error("volume type convert failed");
                return;
        }
-       debug_log("Call volume changed user cb, direction : %s, vol_type : %s(%d), level : %u",
+
+       if (!is_for_internal && !cb_data->extra_data) {
+               debug_log("Invoke volume changed cb, direction : %s, vol_type : %s(%d), level : %u",
+                       direction, volume_type_str, volume_type, volume_level);
+               ((mm_sound_volume_changed_cb)(cb_data->user_cb))((volume_type_t)volume_type, volume_level, cb_data->user_data);
+       } else if (is_for_internal && (cb_data->extra_data && (bool)(cb_data->extra_data))) {
+               debug_log("Invoke internal volume changed cb, direction : %s, vol_type : %s(%d), level : %u",
                        direction, volume_type_str, volume_type, volume_level);
-       ((mm_sound_volume_changed_cb)(cb_data->user_cb))(volume_type, volume_level, cb_data->user_data);
+               ((mm_sound_volume_changed_cb_internal)(cb_data->user_cb))((volume_type_internal_t)volume_type, volume_level, cb_data->user_data);
+       }
 }
 
 int mm_sound_client_add_volume_changed_callback(mm_sound_volume_changed_cb func, void* userdata, unsigned int *subs_id)
@@ -857,6 +938,23 @@ int mm_sound_client_add_volume_changed_callback(mm_sound_volume_changed_cb func,
        return ret;
 }
 
+int mm_sound_client_add_volume_changed_callback_internal(mm_sound_volume_changed_cb_internal func, void* userdata, unsigned int *subs_id)
+{
+       int ret = MM_ERROR_NONE;
+       struct callback_data *cb_data = NULL;
+       gboolean is_for_internal = true;
+
+       debug_fenter();
+
+       GET_CB_DATA(cb_data, func, userdata, (void*)is_for_internal);
+
+       ret = mm_sound_proxy_add_volume_changed_callback(_mm_sound_volume_changed_callback_wrapper_func, cb_data, g_free, subs_id);
+
+       debug_fleave();
+
+       return ret;
+}
+
 int mm_sound_client_remove_volume_changed_callback(unsigned int subs_id)
 {
        int ret = MM_ERROR_NONE;
index 1f826fe57352400a4998da5f94caa6a37dd62c82..ec76b73b0974fda86ecdf44fcd0ebc7a66f7edaf 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-sound
 Summary:    MMSound Package contains client lib and sound_server binary
-Version:    0.12.55
+Version:    0.12.56
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0