Remove sound_server in build packages
[platform/core/multimedia/libmm-sound.git] / mm_sound_client.c
index b3fe160..9bcc86e 100644 (file)
  *
  */
 
-#include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
-#include <poll.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 #include <unistd.h>
 #include <errno.h>
-#include <signal.h>
-
 #include <pthread.h>
-#include <semaphore.h>
-
+#include <glib.h>
 #include <mm_error.h>
 #include <mm_debug.h>
+#include <vconf.h>
 
 #include "include/mm_sound.h"
 #include "include/mm_sound_client.h"
 #include "include/mm_sound_common.h"
 #include "include/mm_sound_device.h"
 #include "include/mm_sound_stream.h"
-
-#include <mm_session.h>
-#include <mm_session_private.h>
-
-#include <glib.h>
-#if defined(__GSOURCE_CALLBACK__)
-#include <sys/poll.h>
-#endif
+#include "include/mm_sound_focus_private.h"
 
 #define CLIENT_HANDLE_MAX 256
+#define VOLUME_TYPE_LEN 64
 
-#define FOCUS_HANDLE_MAX 512
-#define FOCUS_HANDLE_INIT_VAL -1
-#define CONFIG_ENABLE_RETCB
+#define VCONF_KEY_VOLUME_PREFIX                                "file/private/sound/volume"
+#define VCONF_KEY_VOLUME_TYPE_SYSTEM           VCONF_KEY_VOLUME_PREFIX"/system"
+#define VCONF_KEY_VOLUME_TYPE_NOTIFICATION     VCONF_KEY_VOLUME_PREFIX"/notification"
+#define VCONF_KEY_VOLUME_TYPE_ALARM                    VCONF_KEY_VOLUME_PREFIX"/alarm"
+#define VCONF_KEY_VOLUME_TYPE_RINGTONE         VCONF_KEY_VOLUME_PREFIX"/ringtone"
+#define VCONF_KEY_VOLUME_TYPE_MEDIA                    VCONF_KEY_VOLUME_PREFIX"/media"
+#define VCONF_KEY_VOLUME_TYPE_CALL                     VCONF_KEY_VOLUME_PREFIX"/call"
+#define VCONF_KEY_VOLUME_TYPE_VOIP                     VCONF_KEY_VOLUME_PREFIX"/voip"
+#define VCONF_KEY_VOLUME_TYPE_VOICE            VCONF_KEY_VOLUME_PREFIX"/voice"
+#define VCONF_KEY_VOLUME_TYPE_ANDROID          VCONF_KEY_VOLUME_PREFIX"/fixed"
+
+#define VCONF_KEY_MUTE_PREFIX                          "file/private/sound/mute"
+#define VCONF_KEY_MUTE_TYPE_SYSTEM             VCONF_KEY_MUTE_PREFIX"/system"
+#define VCONF_KEY_MUTE_TYPE_NOTIFICATION       VCONF_KEY_MUTE_PREFIX"/notification"
+#define VCONF_KEY_MUTE_TYPE_ALARM                      VCONF_KEY_MUTE_PREFIX"/alarm"
+#define VCONF_KEY_MUTE_TYPE_RINGTONE           VCONF_KEY_MUTE_PREFIX"/ringtone"
+#define VCONF_KEY_MUTE_TYPE_MEDIA                      VCONF_KEY_MUTE_PREFIX"/media"
+#define VCONF_KEY_MUTE_TYPE_CALL                       VCONF_KEY_MUTE_PREFIX"/call"
+#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 */
+       VCONF_KEY_VOLUME_TYPE_ALARM,            /* VOLUME_TYPE_ALARM */
+       VCONF_KEY_VOLUME_TYPE_RINGTONE,         /* VOLUME_TYPE_RINGTONE */
+       VCONF_KEY_VOLUME_TYPE_MEDIA,            /* VOLUME_TYPE_MEDIA */
+       VCONF_KEY_VOLUME_TYPE_CALL,                     /* VOLUME_TYPE_CALL */
+       VCONF_KEY_VOLUME_TYPE_VOIP,                     /* VOLUME_TYPE_VOIP */
+       VCONF_KEY_VOLUME_TYPE_VOICE,            /* VOLUME_TYPE_VOICE */
+       VCONF_KEY_VOLUME_TYPE_ANDROID           /* VOLUME_TYPE_FIXED */
+};
 
-#define VOLUME_TYPE_LEN 64
+static char *g_volume_vconf_internal[] = {
+       VCONF_KEY_VOLUME_TYPE_BIXBY,            /* VOLUME_TYPE_BIXBY */
+};
 
-struct sigaction system_int_old_action;
-struct sigaction system_abrt_old_action;
-struct sigaction system_segv_old_action;
-struct sigaction system_term_old_action;
-struct sigaction system_sys_old_action;
-struct sigaction system_xcpu_old_action;
+static char *g_mute_vconf[] = {
+       VCONF_KEY_MUTE_TYPE_SYSTEM,             /* MUTE_TYPE_SYSTEM */
+       VCONF_KEY_MUTE_TYPE_NOTIFICATION,       /* MUTE_TYPE_NOTIFICATION */
+       VCONF_KEY_MUTE_TYPE_ALARM,              /* MUTE_TYPE_ALARM */
+       VCONF_KEY_MUTE_TYPE_RINGTONE,           /* MUTE_TYPE_RINGTONE */
+       VCONF_KEY_MUTE_TYPE_MEDIA,              /* MUTE_TYPE_MEDIA */
+       VCONF_KEY_MUTE_TYPE_CALL,                       /* MUTE_TYPE_CALL */
+       VCONF_KEY_MUTE_TYPE_VOIP,                       /* MUTE_TYPE_VOIP */
+       VCONF_KEY_MUTE_TYPE_VOICE,              /* MUTE_TYPE_VOICE */
+};
 
 struct callback_data {
        void *user_cb;
@@ -74,43 +99,19 @@ struct callback_data {
 
 #define GET_CB_DATA(_cb_data, _func, _userdata, _extradata) \
        do { \
-               _cb_data = (struct callback_data*) g_malloc0(sizeof(struct callback_data)); \
+               _cb_data = (struct callback_data*) g_try_malloc0(sizeof(struct callback_data)); \
+               if (!_cb_data) { \
+                       debug_error("failed to allocate callback_data"); \
+                       return MM_ERROR_OUT_OF_MEMORY; \
+               } \
                _cb_data->user_cb = _func; \
                _cb_data->user_data = _userdata; \
                _cb_data->extra_data = _extradata; \
        } while (0)
 
-
-typedef struct {
-       int focus_tid;
-       int handle;
-       int focus_fd;
-       GSourceFuncs* g_src_funcs;
-       GPollFD* g_poll_fd;
-       GSource* focus_src;
-       bool is_used;
-       bool auto_reacquire;
-       GMutex focus_lock;
-       mm_sound_focus_changed_cb focus_callback;
-       mm_sound_focus_changed_watch_cb watch_callback;
-       void* user_data;
-
-       bool is_for_session;    /* will be removed when the session concept is completely left out*/
-} focus_sound_info_t;
-
-typedef struct {
-       int pid;
-       int handle;
-       int type;
-       int state;
-       char stream_type[MAX_STREAM_TYPE_LEN];
-       char name[MM_SOUND_NAME_NUM];
-} focus_cb_data_lib;
-
-typedef struct {
-       mm_sound_focus_session_interrupt_cb user_cb;
-       void* user_data;
-} focus_session_interrupt_info_t;
+static pthread_mutex_t g_index_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t g_event_mutex = PTHREAD_MUTEX_INITIALIZER;
+static guint g_idle_event_src;
 
 typedef struct {
        /* handle to watch end of playing */
@@ -119,94 +120,19 @@ typedef struct {
        unsigned subs_id;
 } play_sound_end_callback_data_t;
 
-typedef gboolean (*focus_gLoopPollHandler_t)(gpointer d);
-
-GThread *g_focus_thread;
-GMainLoop *g_focus_loop;
-focus_sound_info_t g_focus_sound_handle[FOCUS_HANDLE_MAX];
-focus_session_interrupt_info_t g_focus_session_interrupt_info = {NULL, NULL};
-
-/* global variables for device list */
-static pthread_mutex_t g_id_mutex = PTHREAD_MUTEX_INITIALIZER;
-
-guint g_focus_signal_handle = 0;
-gboolean g_need_emergent_exit = FALSE;
-
-void _system_signal_handler(int signo)
-{
-       int ret = MM_ERROR_NONE;
-       sigset_t old_mask, all_mask;
-
-       debug_error("Got signal : signo(%d)", signo);
-
-       /* signal block */
-
-       sigfillset(&all_mask);
-       sigprocmask(SIG_BLOCK, &all_mask, &old_mask);
-
-       if (g_need_emergent_exit) {
-               ret = mm_sound_proxy_emergent_exit(getpid());
-               if (ret == MM_ERROR_NONE)
-                       debug_msg("[Client] Success to emergnet_exit\n");
-               else
-                       debug_error("[Client] Error occurred : 0x%x \n",ret);
-       }
-
-       sigprocmask(SIG_SETMASK, &old_mask, NULL);
-       /* signal unblock */
-
-       switch (signo) {
-       case SIGINT:
-               sigaction(SIGINT, &system_int_old_action, NULL);
-               raise( signo);
-               break;
-       case SIGABRT:
-               sigaction(SIGABRT, &system_abrt_old_action, NULL);
-               raise( signo);
-               break;
-       case SIGSEGV:
-               sigaction(SIGSEGV, &system_segv_old_action, NULL);
-               raise( signo);
-               break;
-       case SIGTERM:
-               sigaction(SIGTERM, &system_term_old_action, NULL);
-               raise( signo);
-               break;
-       case SIGSYS:
-               sigaction(SIGSYS, &system_sys_old_action, NULL);
-               raise( signo);
-               break;
-       case SIGXCPU:
-               sigaction(SIGXCPU, &system_xcpu_old_action, NULL);
-               raise( signo);
-               break;
-       default:
-               break;
-       }
-
-       debug_error("signal handling end");
-}
+typedef struct _focus_idle_event {
+       focus_idle_event_type_e type;
+       int data;
+} focus_idle_event_t;
 
 int mm_sound_client_initialize(void)
 {
        int ret = MM_ERROR_NONE;
+
        debug_fenter();
 
        mm_sound_proxy_initialize();
-
-
-       struct sigaction system_action;
-       system_action.sa_handler = _system_signal_handler;
-       system_action.sa_flags = SA_NOCLDSTOP;
-
-       sigemptyset(&system_action.sa_mask);
-
-       sigaction(SIGINT, &system_action, &system_int_old_action);
-       sigaction(SIGABRT, &system_action, &system_abrt_old_action);
-       sigaction(SIGSEGV, &system_action, &system_segv_old_action);
-       sigaction(SIGTERM, &system_action, &system_term_old_action);
-       sigaction(SIGSYS, &system_action, &system_sys_old_action);
-       sigaction(SIGXCPU, &system_action, &system_xcpu_old_action);
+       g_idle_event_src = 0;
 
        debug_fleave();
        return ret;
@@ -218,36 +144,14 @@ int mm_sound_client_finalize(void)
 
        debug_fenter();
 
-       if (g_need_emergent_exit) {
-               ret = mm_sound_proxy_emergent_exit(getpid());
-               if (ret == MM_ERROR_NONE)
-                       debug_msg("[Client] Success to emergnet_exit\n");
-               else
-                       debug_error("[Client] Error occurred : 0x%x \n",ret);
-       }
-
-       sigaction(SIGINT, &system_int_old_action, NULL);
-       sigaction(SIGABRT, &system_abrt_old_action, NULL);
-       sigaction(SIGSEGV, &system_segv_old_action, NULL);
-       sigaction(SIGTERM, &system_term_old_action, NULL);
-       sigaction(SIGSYS, &system_sys_old_action, NULL);
-       sigaction(SIGXCPU, &system_xcpu_old_action, NULL);
-
        ret = mm_sound_proxy_finalize();
 
-
-#ifdef USE_FOCUS
-
-       if (g_focus_thread) {
-               g_main_loop_quit(g_focus_loop);
-               g_thread_join(g_focus_thread);
-               debug_log("after thread join");
-               g_main_loop_unref(g_focus_loop);
-               g_focus_thread = NULL;
+       if (g_idle_event_src > 0) {
+               MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_event_mutex, MM_ERROR_SOUND_INTERNAL);
+               g_source_remove(g_idle_event_src);
+               MMSOUND_LEAVE_CRITICAL_SECTION(&g_event_mutex);
        }
 
-#endif
-
        debug_fleave();
        return ret;
 }
@@ -256,467 +160,410 @@ void mm_sound_convert_volume_type_to_stream_type(int volume_type, char *stream_t
 {
        switch (volume_type) {
        case VOLUME_TYPE_SYSTEM:
-               MMSOUND_STRNCPY(stream_type, "system", MM_SOUND_STREAM_TYPE_LEN);
+               MMSOUND_STRNCPY(stream_type, "system", MAX_STREAM_TYPE_LEN);
                break;
        case VOLUME_TYPE_NOTIFICATION:
-               MMSOUND_STRNCPY(stream_type, "notification", MM_SOUND_STREAM_TYPE_LEN);
+               MMSOUND_STRNCPY(stream_type, "notification", MAX_STREAM_TYPE_LEN);
                break;
        case VOLUME_TYPE_ALARM:
-               MMSOUND_STRNCPY(stream_type, "alarm", MM_SOUND_STREAM_TYPE_LEN);
+               MMSOUND_STRNCPY(stream_type, "alarm", MAX_STREAM_TYPE_LEN);
                break;
        case VOLUME_TYPE_RINGTONE:
-               MMSOUND_STRNCPY(stream_type, "ringtone-voip", MM_SOUND_STREAM_TYPE_LEN);
+               MMSOUND_STRNCPY(stream_type, "ringtone-voip", MAX_STREAM_TYPE_LEN);
                break;
        case VOLUME_TYPE_MEDIA:
-               MMSOUND_STRNCPY(stream_type, "media", MM_SOUND_STREAM_TYPE_LEN);
+               MMSOUND_STRNCPY(stream_type, "media", MAX_STREAM_TYPE_LEN);
                break;
        case VOLUME_TYPE_CALL:
-               MMSOUND_STRNCPY(stream_type, "call-voice", MM_SOUND_STREAM_TYPE_LEN);
+               MMSOUND_STRNCPY(stream_type, "call-voice", MAX_STREAM_TYPE_LEN);
                break;
        case VOLUME_TYPE_VOIP:
-               MMSOUND_STRNCPY(stream_type, "voip", MM_SOUND_STREAM_TYPE_LEN);
+               MMSOUND_STRNCPY(stream_type, "voip", MAX_STREAM_TYPE_LEN);
                break;
        case VOLUME_TYPE_VOICE:
-               MMSOUND_STRNCPY(stream_type, "voice-recognition", MM_SOUND_STREAM_TYPE_LEN);
+               MMSOUND_STRNCPY(stream_type, "voice-information", MAX_STREAM_TYPE_LEN);
                break;
        default:
-               MMSOUND_STRNCPY(stream_type, "media", MM_SOUND_STREAM_TYPE_LEN);
+               MMSOUND_STRNCPY(stream_type, "media", MAX_STREAM_TYPE_LEN);
                break;
        }
 
-       debug_error("volume type (%d) converted to stream type (%s)", volume_type, stream_type);
+       debug_msg("volume type (%d) converted to stream type (%s)", volume_type, stream_type);
 
 }
 
 /*****************************************************************************************
                            DBUS SUPPORTED FUNCTIONS
 ******************************************************************************************/
-
-void _mm_sound_client_focus_signal_callback(mm_sound_signal_name_t signal, int value, void *user_data)
+static int _mm_sound_client_device_list_dump(GList *device_list)
 {
        int ret = MM_ERROR_NONE;
+       GList *list = NULL;
+       mm_sound_device_t *device_node = NULL;
+       int count = 0;
+       if (!device_list) {
+               debug_error("Device list NULL, cannot dump list");
+               return MM_ERROR_SOUND_INTERNAL;
+       }
 
-       debug_fenter();
-       debug_error("focus signal received, value = %d", value);
-
-       if (value == 1) {
-               ret = mm_sound_proxy_clear_focus(getpid());
-               if (ret)
-                       debug_error("clear focus failed ret = 0x%x", ret);
-               mm_sound_unsubscribe_signal(g_focus_signal_handle);
-               g_focus_signal_handle = 0;
+       debug_log("======================== device list : start ==========================");
+       for (list = device_list; list != NULL; list = list->next) {
+               device_node = (mm_sound_device_t *)list->data;
+               if (device_node) {
+                       debug_log(" list idx[%d]: type[%17s], id[%02d], io_direction[%d], state[%d], name[%s]",
+                                               count++, device_node->type, device_node->id, device_node->io_direction,
+                                               device_node->state, device_node->name);
+               }
        }
+       debug_log("======================== device list : end ============================");
+
+       return ret;
 }
 
-int mm_sound_client_play_tone(int number, int volume_config, double volume, int time, int *handle, bool enable_session)
+int mm_sound_client_get_current_connected_device_list(int device_flags, mm_sound_device_list_t *device_list)
 {
        int ret = MM_ERROR_NONE;
-//      int instance = -1;     /* instance is unique to communicate with server : client message queue filter type */
-       int volume_type = MM_SOUND_VOLUME_CONFIG_TYPE(volume_config);
-       char stream_type[MM_SOUND_STREAM_TYPE_LEN] = {0, };
-
-        debug_fenter();
-
-       /* read session information */
-       int session_type = MM_SESSION_TYPE_MEDIA;
-       int session_options = 0;
-       int is_focus_registered = 0;
+       debug_fenter();
 
-       ret = mm_sound_get_signal_value(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, &is_focus_registered);
-       if (ret) {
-               debug_error("mm_sound_get_signal_value failed [0x%x]", ret);
-               return MM_ERROR_POLICY_INTERNAL;
+       if (!device_list) {
+               debug_error("Device list NULL");
+               ret = MM_ERROR_COMMON_INVALID_ARGUMENT;
+               goto failed;
        }
 
-       if (is_focus_registered)
-               enable_session = false;
-
-       if (enable_session) {
-               if (MM_ERROR_NONE != _mm_session_util_read_information(-1, &session_type, &session_options)) {
-                       debug_warning("[Client] Read Session Information failed. use default \"media\" type\n");
-                       session_type = MM_SESSION_TYPE_MEDIA;
-
-                       if(MM_ERROR_NONE != mm_session_init(session_type)) {
-                               debug_critical("[Client] MMSessionInit() failed\n");
-                               return MM_ERROR_POLICY_INTERNAL;
-                       }
-               }
+       if ((ret = mm_sound_proxy_get_current_connected_device_list(device_flags, &device_list->list)) != MM_ERROR_NONE) {
+               debug_error("failed to get current connected device list with dbus, ret[0x%x]", ret);
+               goto failed;
        }
-
-        // instance = getpid();
-        //debug_log("[Client] pid for client ::: [%d]\n", instance);
-
-        /* Send msg */
-        debug_msg("[Client] Input number : %d\n", number);
-        /* Send req memory */
-
-       mm_sound_convert_volume_type_to_stream_type(volume_type, stream_type);
-       ret = mm_sound_proxy_play_tone(number, time, volume, volume_config,
-                                       session_type, session_options, getpid(), enable_session, handle, stream_type, -1);
-
-       if (enable_session && !g_focus_signal_handle) {
-               ret = mm_sound_subscribe_signal(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, &g_focus_signal_handle, _mm_sound_client_focus_signal_callback, NULL);
-               if (ret) {
-                       debug_error("mm_sound_subscribe_signal failed [0x%x]", ret);
-                       return MM_ERROR_POLICY_INTERNAL;
-               }
+       if (!device_list->list) {
+               debug_error("Got device list null");
+               ret = MM_ERROR_SOUND_NO_DATA;
+               goto failed;
        }
+       _mm_sound_client_device_list_dump(device_list->list);
 
+failed:
        debug_fleave();
        return ret;
 }
 
-int mm_sound_client_play_tone_with_stream_info(int tone, char *stream_type, int stream_id, double volume, int duration, int *handle)
+int mm_sound_client_get_device_by_id(int device_id, mm_sound_device_t **device)
 {
        int ret = MM_ERROR_NONE;
 
        debug_fenter();
 
-       ret = mm_sound_proxy_play_tone_with_stream_info(getpid(), tone, stream_type, stream_id, volume, duration, handle);
+       if ((ret = mm_sound_proxy_get_device_by_id(device_id, device)) != MM_ERROR_NONE)
+               debug_error("failed to get device by id");
 
        debug_fleave();
+
        return ret;
 }
 
-static void _mm_sound_stop_callback_wrapper_func(int ended_handle, void *userdata)
+static bool device_is_match_direction(int direction, int mask)
 {
-       struct callback_data *cb_data = (struct callback_data*) userdata;
-       play_sound_end_callback_data_t *end_cb_data = (play_sound_end_callback_data_t*) cb_data->extra_data;
+       if (mask == DEVICE_IO_DIRECTION_FLAGS || mask == 0)
+               return true;
 
-       debug_log("[Wrapper CB][Play Stop] ended_handle : %d", ended_handle);
+       if ((mask & MM_SOUND_DEVICE_IO_DIRECTION_IN_FLAG) && (direction & MM_SOUND_DEVICE_IO_DIRECTION_IN))
+               return true;
+       if ((mask & MM_SOUND_DEVICE_IO_DIRECTION_OUT_FLAG) && (direction & MM_SOUND_DEVICE_IO_DIRECTION_OUT))
+               return true;
+       if ((mask & MM_SOUND_DEVICE_IO_DIRECTION_BOTH_FLAG) && (direction == MM_SOUND_DEVICE_IO_DIRECTION_BOTH))
+               return true;
 
-       if (cb_data == NULL) {
-               debug_warning("stop callback data null");
-               return;
-       }
-       if (ended_handle == end_cb_data->watching_handle) {
-               debug_log("Interested playing handle end : %d", ended_handle);
-               ((mm_sound_stop_callback_func)(cb_data->user_cb))(cb_data->user_data, ended_handle);
-               if (mm_sound_proxy_remove_play_sound_end_callback(end_cb_data->subs_id) != MM_ERROR_NONE)
-                       debug_error("mm_sound_client_dbus_remove_play_file_end_callback failed");
-       } else {
-               debug_log("Not interested playing handle : %d", ended_handle);
-       }
+       return false;
 }
 
-static void play_end_callback_data_free_func(void *data)
+static bool device_is_match_state(int state, int mask)
 {
-       struct callback_data *cb_data = (struct callback_data*) data;
+       if (mask == DEVICE_STATE_FLAGS || mask == 0)
+               return true;
 
-       if (cb_data) {
-               if (cb_data->extra_data)
-                       g_free(cb_data->extra_data);
-               g_free(cb_data);
-       }
+       if ((mask & MM_SOUND_DEVICE_STATE_DEACTIVATED_FLAG) && (state == MM_SOUND_DEVICE_STATE_DEACTIVATED))
+               return true;
+       if ((mask & MM_SOUND_DEVICE_STATE_ACTIVATED_FLAG) && (state == MM_SOUND_DEVICE_STATE_ACTIVATED))
+               return true;
+
+       return false;
 }
 
-int mm_sound_client_play_sound(MMSoundPlayParam *param, int tone, int *handle)
+static bool device_is_match_type(const char *type, int mask)
 {
-       int ret = MM_ERROR_NONE;
-       int session_type = MM_SESSION_TYPE_MEDIA;
-       int session_options = 0;
-       int is_focus_registered = 0;
-//     int instance = -1;      /* instance is unique to communicate with server : client message queue filter type */
-       int volume_type = MM_SOUND_VOLUME_CONFIG_TYPE(param->volume_config);
-       char stream_type[MM_SOUND_STREAM_TYPE_LEN] = {0, };
-       struct callback_data *cb_data = NULL;
-       play_sound_end_callback_data_t *end_cb_data;
+       bool is_builtin;
+       const char *builtin_prefix = "builtin";
 
-       debug_fenter();
+       if (mask == DEVICE_TYPE_FLAGS || mask == 0)
+               return true;
 
-       /* read session information */
+       is_builtin = !strncmp(type, builtin_prefix, strlen(builtin_prefix));
 
-       ret = mm_sound_get_signal_value(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, &is_focus_registered);
-       if (ret) {
-               debug_error("mm_sound_get_signal_value failed [0x%x]", ret);
-               return MM_ERROR_POLICY_INTERNAL;
-       }
+       if ((mask & MM_SOUND_DEVICE_TYPE_INTERNAL_FLAG) && (is_builtin))
+               return true;
+       if ((mask & MM_SOUND_DEVICE_TYPE_EXTERNAL_FLAG) && (!is_builtin))
+               return true;
 
-       if (is_focus_registered)
-               param->skip_session = true;
+       return false;
+}
 
-       if (param->skip_session == false) {
-               if(MM_ERROR_NONE != _mm_session_util_read_information(-1, &session_type, &session_options)) {
-                       debug_warning("[Client] Read MMSession Type failed. use default \"media\" type\n");
-                       session_type = MM_SESSION_TYPE_MEDIA;
+static bool device_is_match_with_mask(const char *type, int direction, int state, int mask)
+{
+       if (mask == DEVICE_ALL_FLAG)
+               return true;
 
-                       if(MM_ERROR_NONE != mm_session_init(session_type)) {
-                               debug_critical("[Client] MMSessionInit() failed\n");
-                               return MM_ERROR_POLICY_INTERNAL;
-                       }
-               }
-       }
+       return (device_is_match_direction(direction, mask & DEVICE_IO_DIRECTION_FLAGS) &&
+                       device_is_match_state(state, mask & DEVICE_STATE_FLAGS) &&
+                       device_is_match_type(type, mask & DEVICE_TYPE_FLAGS));
+}
 
-       /* Send msg */
-       if ((param->mem_ptr && param->mem_size)) {
-               // Play memory, deprecated
-               return MM_ERROR_INVALID_ARGUMENT;
+static int _fill_sound_device(mm_sound_device_t *device_h, int device_id, const char *device_type,
+               int direction, int state, const char *name, int vendor_id, int product_id,
+               int *stream_id, int stream_num, bool is_running)
+{
+       int i;
+
+       if (stream_num > 0 && stream_id == NULL) {
+               debug_error("stream_num is %d, but stream_id is NULL", stream_num);
+               return -1;
        }
 
-       mm_sound_convert_volume_type_to_stream_type(volume_type, stream_type);
-       ret = mm_sound_proxy_play_sound(param->filename, tone, param->loop, param->volume, param->volume_config,
-                                        param->priority, session_type, session_options, getpid(), param->handle_route,
-                                        !param->skip_session, handle, stream_type, -1);
-       if (ret != MM_ERROR_NONE) {
-               debug_error("Play Sound Failed");
-               goto failed;
+       if (stream_num > MAX_STREAM_ON_DEVICE) {
+               debug_error("too many streams on this device");
+               return -1;
        }
-       if (param->callback) {
-               end_cb_data = (play_sound_end_callback_data_t *) g_malloc0(sizeof(play_sound_end_callback_data_t));
-               end_cb_data->watching_handle = *handle;
-               GET_CB_DATA(cb_data, param->callback, param->data, end_cb_data);
-
-               ret = mm_sound_proxy_add_play_sound_end_callback(_mm_sound_stop_callback_wrapper_func, cb_data, play_end_callback_data_free_func, &end_cb_data->subs_id);
-               if (ret != MM_ERROR_NONE) {
-                       debug_error("Add callback for play sound(%d) Failed", *handle);
+
+       device_h->id = device_id;
+       device_h->io_direction = direction;
+       device_h->state = state;
+       MMSOUND_STRNCPY(device_h->name, name, MAX_DEVICE_NAME_NUM);
+       MMSOUND_STRNCPY(device_h->type, device_type, MAX_DEVICE_TYPE_STR_LEN);
+       device_h->vendor_id = vendor_id;
+       device_h->product_id = product_id;
+       device_h->is_running = is_running;
+
+       if (stream_num > 0) {
+               device_h->stream_num = stream_num;
+               debug_log("%d streams on this device", stream_num);
+               for (i = 0; i < stream_num; i++) {
+                       debug_log("  stream_id : %d", stream_id[i]);
+                       device_h->stream_id[i] = stream_id[i];
                }
+       } else {
+               device_h->stream_num = 0;
+               debug_log("There is no stream on this device");
        }
-       if (!param->skip_session && !g_focus_signal_handle) {
-               ret = mm_sound_subscribe_signal(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, &g_focus_signal_handle, _mm_sound_client_focus_signal_callback, NULL);
-               if (ret) {
-                       debug_error("mm_sound_subscribe_signal failed [0x%x]", ret);
-                       return MM_ERROR_POLICY_INTERNAL;
-               }
+
+       return 0;
+}
+
+static void _mm_sound_device_connected_callback_wrapper_func(int device_id, const char *device_type, int io_direction,
+                                                                                                                       int state, const char *name, int vendor_id, int product_id, bool is_running,
+                                                                                                                       int *stream_id, int stream_num, bool is_connected, void *userdata)
+{
+       mm_sound_device_t device_h;
+       struct callback_data *cb_data = (struct callback_data*) userdata;
+       int device_flags;
+
+       debug_log("[Device %s] id(%d) type(%s) direction(%d) state(%d) name(%s) is_running(%d) vendor-id(%04x) product-id(%04x)",
+                               is_connected ? "Connected" : "Disconnected", device_id, device_type, io_direction, state, name,
+                               is_running, vendor_id, product_id);
+
+       if (cb_data == NULL) {
+               debug_warning("device connected changed callback data null");
+               return;
        }
 
-failed:
+       device_flags = (int) cb_data->extra_data;
+       if (!device_is_match_with_mask(device_type, io_direction, state, device_flags))
+               return;
 
-       debug_fleave();
-       return ret;
+       if (_fill_sound_device(&device_h, device_id, device_type, io_direction, state, name,
+                                                       vendor_id, product_id, stream_id, stream_num, is_running) < 0) {
+               debug_error("Failed to fill sound device");
+               return;
+       }
+
+       ((mm_sound_device_connected_cb)(cb_data->user_cb))(&device_h, is_connected, cb_data->user_data);
 }
 
-int mm_sound_client_play_sound_with_stream_info(MMSoundPlayParam *param, int *handle, char* stream_type, int stream_id)
+int mm_sound_client_add_device_connected_callback(int device_flags, mm_sound_device_connected_cb func,
+                                                                                               void* userdata, unsigned int *subs_id)
 {
        int ret = MM_ERROR_NONE;
        struct callback_data *cb_data = NULL;
-       play_sound_end_callback_data_t *end_cb_data;
 
-       ret = mm_sound_proxy_play_sound_with_stream_info(param->filename, param->loop, param->volume,
-                                        param->priority, getpid(), param->handle_route, handle, stream_type, stream_id);
-       if (ret != MM_ERROR_NONE) {
-               debug_error("Play Sound Failed");
-               goto failed;
-       }
-       if (param->callback) {
-               end_cb_data = (play_sound_end_callback_data_t *) g_malloc0(sizeof(play_sound_end_callback_data_t));
-               end_cb_data->watching_handle = *handle;
-               GET_CB_DATA(cb_data, param->callback, param->data, end_cb_data);
-
-               ret = mm_sound_proxy_add_play_sound_end_callback(_mm_sound_stop_callback_wrapper_func, cb_data, play_end_callback_data_free_func, &end_cb_data->subs_id);
-               if (ret != MM_ERROR_NONE) {
-                       debug_error("Add callback for play sound(%d) Failed", *handle);
-               }
-       }
+       debug_fenter();
 
-failed:
+       GET_CB_DATA(cb_data, func, userdata, (void*) device_flags);
+
+       ret = mm_sound_proxy_add_device_connected_callback(_mm_sound_device_connected_callback_wrapper_func,
+                                                                                                       cb_data, g_free, subs_id);
 
        debug_fleave();
        return ret;
-
 }
 
-int mm_sound_client_stop_sound(int handle)
+int mm_sound_client_remove_device_connected_callback(unsigned int subs_id)
 {
        int ret = MM_ERROR_NONE;
        debug_fenter();
 
-       if (handle < 0 || handle > CLIENT_HANDLE_MAX) {
-               ret = MM_ERROR_INVALID_ARGUMENT;
-               return ret;
-       }
-
-       ret = mm_sound_proxy_stop_sound(handle);
+       ret = mm_sound_proxy_remove_device_connected_callback(subs_id);
 
        debug_fleave();
        return ret;
 }
 
-static int _mm_sound_client_device_list_dump (GList *device_list)
+static void _mm_sound_device_info_changed_callback_wrapper_func(int device_id, const char *device_type, int io_direction,
+                                                                                                                               int state, const char *name, int vendor_id, int product_id, bool is_running,
+                                                                                                                               int *stream_id, int stream_num, int changed_device_info_type, void *userdata)
 {
-       int ret = MM_ERROR_NONE;
-       GList *list = NULL;
-       mm_sound_device_t *device_node = NULL;
-       int count = 0;
-       if (!device_list) {
-               debug_error("Device list NULL, cannot dump list");
-               return MM_ERROR_SOUND_INTERNAL;
+       mm_sound_device_t device_h;
+       struct callback_data *cb_data = (struct callback_data*) userdata;
+       int device_flags;
+
+       debug_log("[Device Info Changed] id(%d) type(%s) direction(%d) state(%d) name(%s) is_running(%d) "
+                       "vendor-id(%04x) product-id(%04x) changed_info_type(%d)",
+                       device_id, device_type, io_direction, state, name, is_running, vendor_id, product_id, changed_device_info_type);
+
+       if (cb_data == NULL) {
+               debug_warning("device info changed callback data null");
+               return;
        }
 
-       debug_log("======================== device list : start ==========================\n");
-       for (list = device_list; list != NULL; list = list->next) {
-               device_node = (mm_sound_device_t *)list->data;
-               if (device_node) {
-                       debug_log(" list idx[%d]: type[%17s], id[%02d], io_direction[%d], state[%d], name[%s]\n",
-                                               count++, device_node->type, device_node->id, device_node->io_direction, device_node->state, device_node->name);
-               }
+       device_flags = (int) cb_data->extra_data;
+       if (!device_is_match_with_mask(device_type, io_direction, state, device_flags))
+               return;
+
+       if (_fill_sound_device(&device_h, device_id, device_type, io_direction, state, name,
+                               vendor_id, product_id, stream_id, stream_num, is_running) < 0) {
+               debug_error("Failed to fill sound device");
+               return;
        }
-       debug_log("======================== device list : end ============================\n");
 
-       return ret;
+       ((mm_sound_device_info_changed_cb)(cb_data->user_cb))(&device_h, changed_device_info_type, cb_data->user_data);
 }
 
-int mm_sound_client_get_current_connected_device_list(int device_flags, mm_sound_device_list_t *device_list)
+int mm_sound_client_add_device_info_changed_callback(int device_flags, mm_sound_device_info_changed_cb func,
+                                                                                                       void *userdata, unsigned int *subs_id)
 {
        int ret = MM_ERROR_NONE;
+       struct callback_data *cb_data = (struct callback_data*) userdata;
+
        debug_fenter();
 
-       if (!device_list) {
-               debug_error("Device list NULL");
-               ret = MM_ERROR_COMMON_INVALID_ARGUMENT;
-               goto failed;
-       }
+       GET_CB_DATA(cb_data, func, userdata, (void *) device_flags);
 
-       if ((ret = mm_sound_proxy_get_current_connected_device_list(device_flags, &device_list->list)) != MM_ERROR_NONE) {
-               debug_error("[Client] failed to get current connected device list with dbus, ret[0x%x]", ret);
-               goto failed;
-       }
-       if (!device_list->list) {
-               debug_error("Got device list null");
-               ret = MM_ERROR_SOUND_NO_DATA;
-               goto failed;
-       }
-       _mm_sound_client_device_list_dump(device_list->list);
+       ret = mm_sound_proxy_add_device_info_changed_callback(_mm_sound_device_info_changed_callback_wrapper_func,
+                                                                                                               cb_data, g_free, subs_id);
 
-failed:
        debug_fleave();
        return ret;
 }
 
-static bool is_device_match_flags(const char *device_type, int io_direction, int state, int device_flags)
+int mm_sound_client_remove_device_info_changed_callback(unsigned int subs_id)
 {
-       int io_direction_flag = device_flags & DEVICE_IO_DIRECTION_FLAGS;
-       int state_flag = device_flags & DEVICE_STATE_FLAGS;
-       int type_flag = device_flags & DEVICE_TYPE_FLAGS;
-       char builtin_prefix[] = "builtin";
-
-       if (device_flags == DEVICE_ALL_FLAG)
-               return TRUE;
-
-       switch (io_direction_flag) {
-       case DEVICE_IO_DIRECTION_IN_FLAG:
-               if (io_direction != DEVICE_IO_DIRECTION_IN)
-                       return FALSE;
-               break;
-       case DEVICE_IO_DIRECTION_OUT_FLAG:
-               if (io_direction != DEVICE_IO_DIRECTION_OUT)
-                       return FALSE;
-               break;
-       case DEVICE_IO_DIRECTION_BOTH_FLAG:
-               if (io_direction != DEVICE_IO_DIRECTION_BOTH)
-                       return FALSE;
-               break;
-       default:
-               break;
-       }
+       int ret = MM_ERROR_NONE;
+       debug_fenter();
 
-       switch (state_flag) {
-       case DEVICE_STATE_DEACTIVATED_FLAG:
-               if (state != DEVICE_STATE_DEACTIVATED)
-                       return FALSE;
-               break;
-       case DEVICE_STATE_ACTIVATED_FLAG:
-               if (state != DEVICE_STATE_ACTIVATED)
-                       return FALSE;
-               break;
-       default:
-               break;
-       }
+       ret =  mm_sound_proxy_remove_device_info_changed_callback(subs_id);
 
-       switch (type_flag) {
-       case DEVICE_TYPE_INTERNAL_FLAG:
-               if (strncmp(device_type, builtin_prefix, strlen(builtin_prefix)) != 0)
-                       return FALSE;
-               break;
-       case DEVICE_TYPE_EXTERNAL_FLAG:
-               if (strncmp(device_type, builtin_prefix, strlen(builtin_prefix)) == 0)
-                       return FALSE;
-               break;
-       default:
-               break;
-       }
+       debug_fleave();
+       return ret;
 
-       return TRUE;
 }
 
-static void _mm_sound_device_connected_callback_wrapper_func(int device_id, const char *device_type, int io_direction, int state, const char *name, gboolean is_connected, void *userdata)
+static void _mm_sound_device_state_changed_callback_wrapper_func(int device_id, const char *device_type, int io_direction,
+                                                                                                                               int state, const char *name, int vendor_id, int product_id,
+                                                                                                                               bool is_running, int *stream_id, int stream_num, void *userdata)
 {
        mm_sound_device_t device_h;
        struct callback_data *cb_data = (struct callback_data*) userdata;
-       int device_flags = (int) cb_data->extra_data;
+       int device_flags;
 
-       debug_log("[Wrapper CB][Device Connnected] device_id : %d, device_type : %s, direction : %d, state : %d, name : %s, is_connected : %d",
-                         device_id, device_type, io_direction, state, name, is_connected);
+       debug_log("[Device State Changed] id(%d) type(%s) direction(%d) state(%d) name(%s) is_running(%d) vendor-id(%04x) product-id(%04x)",
+                               device_id, device_type, io_direction, state, name, is_running, vendor_id, product_id);
 
        if (cb_data == NULL) {
-               debug_warning("device connected changed callback data null");
+               debug_warning("device state changed callback data null");
                return;
        }
-       if (!is_device_match_flags(device_type, io_direction, state, device_flags))
+
+       device_flags = (int) cb_data->extra_data;
+
+       if (!device_is_match_with_mask(device_type, io_direction, state, device_flags))
                return;
 
-       device_h.id = device_id;
-       device_h.io_direction = io_direction;
-       device_h.state = state;
-       MMSOUND_STRNCPY(device_h.name, name, MAX_DEVICE_NAME_NUM);
-       MMSOUND_STRNCPY(device_h.type, device_type, MAX_DEVICE_TYPE_STR_LEN);
+       if (_fill_sound_device(&device_h, device_id, device_type, io_direction, state, name,
+                               vendor_id, product_id, stream_id, stream_num, is_running) < 0) {
+               debug_error("Failed to fill sound device");
+               return;
+       }
 
-       ((mm_sound_device_connected_cb)(cb_data->user_cb))(&device_h, is_connected, cb_data->user_data);
+       ((mm_sound_device_state_changed_cb)(cb_data->user_cb))(&device_h, state, cb_data->user_data);
 }
 
-int mm_sound_client_add_device_connected_callback(int device_flags, mm_sound_device_connected_cb func, void* userdata, unsigned int *subs_id)
+int mm_sound_client_add_device_state_changed_callback(int device_flags, mm_sound_device_state_changed_cb func,
+                                                                                                       void *userdata, unsigned int *id)
 {
        int ret = MM_ERROR_NONE;
-       struct callback_data *cb_data = NULL;
+       struct callback_data *cb_data = (struct callback_data*) userdata;
 
        debug_fenter();
 
-       GET_CB_DATA(cb_data, func, userdata, (void*) device_flags);
+       GET_CB_DATA(cb_data, func, userdata, (void *) device_flags);
 
-       ret = mm_sound_proxy_add_device_connected_callback(device_flags, _mm_sound_device_connected_callback_wrapper_func, cb_data, g_free, subs_id);
-       if (ret == MM_ERROR_NONE)
-               g_need_emergent_exit = TRUE;
+       ret = mm_sound_proxy_add_device_state_changed_callback(_mm_sound_device_state_changed_callback_wrapper_func,
+                                                                                                               cb_data, g_free, id);
 
        debug_fleave();
        return ret;
 }
 
-int mm_sound_client_remove_device_connected_callback(unsigned int subs_id)
+int mm_sound_client_remove_device_state_changed_callback(unsigned int id)
 {
        int ret = MM_ERROR_NONE;
        debug_fenter();
 
-       ret = mm_sound_proxy_remove_device_connected_callback(subs_id);
+       ret =  mm_sound_proxy_remove_device_state_changed_callback(id);
 
        debug_fleave();
        return ret;
 }
 
-static void _mm_sound_device_info_changed_callback_wrapper_func(int device_id, const char *device_type, int io_direction, int state, const char *name, int changed_device_info_type, void *userdata)
+static void _mm_sound_device_running_changed_callback_wrapper_func(int device_id, const char *device_type, int io_direction,
+                                                                                                                               int state, const char *name, int vendor_id, int product_id,
+                                                                                                                               bool is_running, int *stream_id, int stream_num, void *userdata)
 {
        mm_sound_device_t device_h;
        struct callback_data *cb_data = (struct callback_data*) userdata;
-       int device_flags = (int) cb_data->extra_data;
+       int device_flags;
 
-       debug_log("[Wrapper CB][Device Info Changed] device_id : %d, device_type : %s, direction : %d, state : %d, name : %s, changed_info_type : %d",
-                         device_id, device_type, io_direction, state, name, changed_device_info_type);
+       debug_log("[Device Running Changed] id(%d) type(%s) direction(%d) state(%d) name(%s) is_running(%d) vendor-id(%04x), product-id(%04x)",
+                       device_id, device_type, io_direction, state, name, is_running, vendor_id, product_id);
 
        if (cb_data == NULL) {
-               debug_warning("device info changed callback data null");
+               debug_warning("device running changed callback data null");
                return;
        }
-       if (!is_device_match_flags(device_type, io_direction, state, device_flags))
+
+       device_flags = (int) cb_data->extra_data;
+
+       if (!device_is_match_with_mask(device_type, io_direction, state, device_flags))
                return;
 
-       device_h.id = device_id;
-       device_h.io_direction = io_direction;
-       device_h.state = state;
-       MMSOUND_STRNCPY(device_h.name, name, MAX_DEVICE_NAME_NUM);
-       MMSOUND_STRNCPY(device_h.type, device_type, MAX_DEVICE_TYPE_STR_LEN);
+       if (_fill_sound_device(&device_h, device_id, device_type, io_direction, state, name,
+                                                       vendor_id, product_id, stream_id, stream_num, is_running) < 0) {
+               debug_error("Failed to fill sound device");
+               return;
+       }
 
-       ((mm_sound_device_info_changed_cb)(cb_data->user_cb))(&device_h, changed_device_info_type, cb_data->user_data);
+       ((mm_sound_device_running_changed_cb)(cb_data->user_cb))(&device_h, is_running, cb_data->user_data);
 }
 
-int mm_sound_client_add_device_info_changed_callback(int device_flags, mm_sound_device_info_changed_cb func, void *userdata, unsigned int *subs_id)
+int mm_sound_client_add_device_running_changed_callback(int device_flags, mm_sound_device_running_changed_cb func,
+                                                                                                               void *userdata, unsigned int *id)
 {
        int ret = MM_ERROR_NONE;
        struct callback_data *cb_data = (struct callback_data*) userdata;
@@ -725,31 +572,51 @@ int mm_sound_client_add_device_info_changed_callback(int device_flags, mm_sound_
 
        GET_CB_DATA(cb_data, func, userdata, (void *) device_flags);
 
-       ret = mm_sound_proxy_add_device_info_changed_callback(device_flags, _mm_sound_device_info_changed_callback_wrapper_func, cb_data, g_free, subs_id);
+       ret = mm_sound_proxy_add_device_running_changed_callback(_mm_sound_device_running_changed_callback_wrapper_func,
+                                                                                                                       cb_data, g_free, id);
 
        debug_fleave();
        return ret;
 }
 
-int mm_sound_client_remove_device_info_changed_callback(unsigned int subs_id)
+int mm_sound_client_remove_device_running_changed_callback(unsigned int id)
 {
        int ret = MM_ERROR_NONE;
        debug_fenter();
 
-       ret =  mm_sound_proxy_remove_device_info_changed_callback(subs_id);
+       ret =  mm_sound_proxy_remove_device_running_changed_callback(id);
 
        debug_fleave();
        return ret;
+}
+
+int mm_sound_client_is_stream_on_device(int stream_id, int device_id, bool *is_on)
+{
+       int ret = MM_ERROR_NONE;
+       debug_fenter();
+
+       if (!is_on) {
+               debug_error("Invalid Parameter");
+               ret = MM_ERROR_COMMON_INVALID_ARGUMENT;
+               goto failed;
+       }
 
+       if ((ret = mm_sound_proxy_is_stream_on_device(stream_id, device_id, is_on)) != MM_ERROR_NONE) {
+               debug_error("failed to query is stream on device, ret[0x%x]", ret);
+               goto failed;
+       }
+
+failed:
+       debug_fleave();
+       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;
 
-       if (!volume_type_str) {
+       if (!volume_type_str)
                return MM_ERROR_COMMON_INVALID_ARGUMENT;
-       }
 
        switch (volume_type) {
        case VOLUME_TYPE_SYSTEM:
@@ -776,40 +643,68 @@ int __convert_volume_type_to_str(int volume_type, char **volume_type_str)
        case VOLUME_TYPE_VOICE:
                *volume_type_str = "voice";
                break;
+       default:
+               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;
 }
 
-static int __convert_volume_type_to_int(const char *volume_type_str, volume_type_t *volume_type)
+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 || !volume_type_str) {
+       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, int *volume_type, bool *is_for_internal)
+{
+       int ret = MM_ERROR_NONE;
+
+       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,725 +713,364 @@ static int __convert_volume_type_to_int(const char *volume_type_str, volume_type
        return ret;
 }
 
-int mm_sound_client_set_volume_by_type(const int volume_type, const unsigned int volume_level)
+int mm_sound_client_set_volume_by_type(volume_type_t type, const unsigned int level)
 {
        int ret = MM_ERROR_NONE;
        char *type_str = NULL;
        debug_fenter();
 
-       if ((ret = __convert_volume_type_to_str(volume_type, &type_str)) != MM_ERROR_NONE) {
-               debug_error("volume type convert failed");
-               goto failed;
-       }
-
-       ret = mm_sound_proxy_set_volume_by_type(type_str, volume_level);
-
-failed:
-       debug_fleave();
-       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;
-       struct callback_data *cb_data = (struct callback_data *) userdata;
-
-       debug_log("[Wrapper CB][Volume Changed] direction : %s, volume_type : %s, volume_level : %d", direction, volume_type_str, volume_level);
-
-       if (cb_data == NULL) {
-               debug_warning("volume changed callback data null");
-               return;
+       if (type >= VOLUME_TYPE_MAX) {
+               debug_error("invalid volume type %d", type);
+               return MM_ERROR_INVALID_ARGUMENT;
        }
 
-       if (__convert_volume_type_to_int(volume_type_str, &volume_type) != MM_ERROR_NONE) {
+       if ((ret = __convert_volume_type_to_str(type, &type_str)) != MM_ERROR_NONE) {
                debug_error("volume type convert failed");
-               return;
+               goto failed;
        }
-       debug_log("Call volume changed user 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);
-}
-
-int mm_sound_client_add_volume_changed_callback(mm_sound_volume_changed_cb func, void* userdata, unsigned int *subs_id)
-{
-       int ret = MM_ERROR_NONE;
-       struct callback_data *cb_data = NULL;
-
-       debug_fenter();
-
-       GET_CB_DATA(cb_data, func, userdata, NULL);
-
-       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;
-       debug_fenter();
-
-       ret = mm_sound_proxy_remove_volume_changed_callback(subs_id);
+       ret = mm_sound_proxy_set_volume_by_type(type_str, level);
 
+failed:
        debug_fleave();
        return ret;
 }
 
-#ifdef USE_FOCUS
-int mm_sound_client_set_session_interrupt_callback(mm_sound_focus_session_interrupt_cb callback, void* user_data)
+int mm_sound_client_get_volume_by_type(volume_type_t type, unsigned int *level)
 {
        int ret = MM_ERROR_NONE;
+       int vconf_value = 0;
 
-       debug_fenter();
-
-       if (!callback)
+       if (level == NULL) {
+               debug_error("invalid argument, level is null");
                return MM_ERROR_INVALID_ARGUMENT;
-
-       g_focus_session_interrupt_info.user_cb = callback;
-       g_focus_session_interrupt_info.user_data = user_data;
-
-       debug_fleave();
-       return ret;
-}
-
-int mm_sound_client_unset_session_interrupt_callback(void)
-{
-       int ret = MM_ERROR_NONE;
-
-       debug_fenter();
-
-       if (!g_focus_session_interrupt_info.user_cb) {
-               debug_error("no callback to unset");
-               return MM_ERROR_SOUND_INTERNAL;
-       }
-
-       g_focus_session_interrupt_info.user_cb = NULL;
-       g_focus_session_interrupt_info.user_data = NULL;
-
-       debug_fleave();
-       return ret;
-}
-
-static gpointer _focus_thread_func(gpointer data)
-{
-       debug_log(">>> thread func..ID of this thread(%u)\n", (unsigned int)pthread_self());
-       g_main_loop_run(g_focus_loop);
-       debug_log("<<< quit thread func..\n");
-       return NULL;
-}
-
-static gboolean _focus_fd_check(GSource * source)
-{
-       GSList *fd_list;
-       GPollFD *temp;
-
-       if (!source) {
-               debug_error("GSource is null");
-               return FALSE;
-       }
-       fd_list = source->poll_fds;
-       if (!fd_list) {
-               debug_error("fd_list is null");
-               return FALSE;
        }
-       do {
-               temp = (GPollFD*)fd_list->data;
-               if (!temp) {
-                       debug_error("fd_list->data is null");
-                       return FALSE;
-               }
-               if (temp->revents & (POLLIN | POLLPRI)) {
-                       return TRUE;
-               }
-               fd_list = fd_list->next;
-       } while (fd_list);
-
-       return FALSE; /* there is no change in any fd state */
-}
 
-static gboolean _focus_fd_prepare(GSource *source, gint *timeout)
-{
-       return FALSE;
-}
-
-static gboolean _focus_fd_dispatch(GSource *source,    GSourceFunc callback, gpointer user_data)
-{
-       callback(user_data);
-       return TRUE;
-}
-
-
-static int _focus_find_index_by_handle(int handle)
-{
-       int i = 0;
-       for(i = 0; i< FOCUS_HANDLE_MAX; i++) {
-               if (handle == g_focus_sound_handle[i].handle) {
-                       //debug_msg("found index(%d) for handle(%d)", i, handle);
-                       if (handle == FOCUS_HANDLE_INIT_VAL) {
-                               return -1;
-                       }
-                       return i;
-               }
-       }
-       return -1;
-}
-
-static gboolean _focus_callback_handler(gpointer d)
-{
-       GPollFD *data = (GPollFD*)d;
-       int count;
-       int tid = 0;
-       int focus_index = 0;
-       focus_cb_data_lib cb_data;
-       debug_log(">>> focus_callback_handler()..ID of this thread(%u)\n", (unsigned int)pthread_self());
-
-       memset(&cb_data, 0, sizeof(focus_cb_data_lib));
-
-       if (!data) {
-               debug_error("GPollFd is null");
-               return FALSE;
+       if (type >= VOLUME_TYPE_MAX) {
+               debug_error("invalid volume type %d", type);
+               return MM_ERROR_INVALID_ARGUMENT;
        }
-       if (data->revents & (POLLIN | POLLPRI)) {
-               int changed_state = -1;
-
-               count = read(data->fd, &cb_data, sizeof(cb_data));
-               if (count < 0){
-                       char str_error[256];
-                       strerror_r(errno, str_error, sizeof(str_error));
-                       debug_error("GpollFD read fail, errno=%d(%s)",errno, str_error);
-                       return FALSE;
-               }
-               changed_state = cb_data.state;
-               focus_index = _focus_find_index_by_handle(cb_data.handle);
-               if (focus_index == -1) {
-                       debug_error("Could not find index");
-                       return FALSE;
-               }
 
-               g_mutex_lock(&g_focus_sound_handle[focus_index].focus_lock);
-
-               tid = g_focus_sound_handle[focus_index].focus_tid;
-
-               if (changed_state != -1) {
-                       debug_error("Got and start CB : TID(%d), handle(%d), type(%d), state(%d,(DEACTIVATED(0)/ACTIVATED(1)), trigger(%s)", tid, cb_data.handle, cb_data.type, cb_data.state, cb_data.stream_type);
-                       if (g_focus_sound_handle[focus_index].focus_callback== NULL) {
-                                       debug_error("callback is null..");
-                                       g_mutex_unlock(&g_focus_sound_handle[focus_index].focus_lock);
-                                       return FALSE;
-                       }
-                       debug_error("[CALLBACK(%p) START]",g_focus_sound_handle[focus_index].focus_callback);
-                       (g_focus_sound_handle[focus_index].focus_callback)(cb_data.handle, cb_data.type, cb_data.state, cb_data.stream_type, cb_data.name, g_focus_sound_handle[focus_index].user_data);
-                       debug_error("[CALLBACK END]");
-                       if (g_focus_session_interrupt_info.user_cb) {
-                               debug_error("sending session interrupt callback(%p)", g_focus_session_interrupt_info.user_cb);
-                               (g_focus_session_interrupt_info.user_cb)(cb_data.state, cb_data.stream_type, false, g_focus_session_interrupt_info.user_data);
-                       }
-               }
-#ifdef CONFIG_ENABLE_RETCB
-
-                               int rett = 0;
-                               int tmpfd = -1;
-                               unsigned int buf = 0;
-                               char *filename2 = g_strdup_printf("/tmp/FOCUS.%d.%dr", g_focus_sound_handle[focus_index].focus_tid, cb_data.handle);
-                               tmpfd = open(filename2, O_WRONLY | O_NONBLOCK);
-                               if (tmpfd < 0) {
-                                       char str_error[256];
-                                       strerror_r(errno, str_error, sizeof(str_error));
-                                       debug_error("[RETCB][Failed(May Server Close First)]tid(%d) fd(%d) %s errno=%d(%s)\n", tid, tmpfd, filename2, errno, str_error);
-                                       g_free(filename2);
-                                       g_mutex_unlock(&g_focus_sound_handle[focus_index].focus_lock);
-                                       return FALSE;
-                               }
-                               buf = (unsigned int)((0x0000ffff & cb_data.handle) |(g_focus_sound_handle[focus_index].auto_reacquire << 16));
-                               rett = write(tmpfd, &buf, sizeof(buf));
-                               close(tmpfd);
-                               g_free(filename2);
-                               debug_msg("[RETCB] tid(%d) finishing CB (write=%d)\n", tid, rett);
-#endif
+       /* Get volume value from VCONF */
+       if (vconf_get_int(g_volume_vconf[type], &vconf_value)) {
+               debug_error("vconf_get_int(%s) failed..\n", g_volume_vconf[type]);
+               return MM_ERROR_SOUND_INTERNAL;
        }
 
-       g_mutex_unlock(&g_focus_sound_handle[focus_index].focus_lock);
+       *level = vconf_value;
 
-       return TRUE;
+       return ret;
 }
 
-static gboolean _focus_watch_callback_handler( gpointer d)
+int mm_sound_client_set_volume_by_internal_type(volume_type_internal_t type, const unsigned int level)
 {
-       GPollFD *data = (GPollFD*)d;
-       int count;
-       int tid = 0;
-       int focus_index = 0;
-       focus_cb_data_lib cb_data;
+       int ret = MM_ERROR_NONE;
+       char *type_str = NULL;
 
        debug_fenter();
 
-       memset(&cb_data, 0, sizeof(focus_cb_data_lib));
-
-       if (!data) {
-               debug_error("GPollFd is null");
-               return FALSE;
-       }
-       if (data->revents & (POLLIN | POLLPRI)) {
-               count = read(data->fd, &cb_data, sizeof(cb_data));
-               if (count < 0){
-                       char str_error[256];
-                       strerror_r(errno, str_error, sizeof(str_error));
-                       debug_error("GpollFD read fail, errno=%d(%s)",errno, str_error);
-                       return FALSE;
-               }
-
-               focus_index = _focus_find_index_by_handle(cb_data.handle);
-               if (focus_index == -1) {
-                       debug_error("Could not find index");
-                       return FALSE;
-               }
-
-               debug_error("lock focus_lock = %p", &g_focus_sound_handle[focus_index].focus_lock);
-               g_mutex_lock(&g_focus_sound_handle[focus_index].focus_lock);
-
-               tid = g_focus_sound_handle[focus_index].focus_tid;
-
-               debug_error("Got and start CB : TID(%d), handle(%d), type(%d), state(%d,(DEACTIVATED(0)/ACTIVATED(1)), trigger(%s)", tid, cb_data.handle,  cb_data.type, cb_data.state, cb_data.stream_type);
-
-               if (g_focus_sound_handle[focus_index].watch_callback == NULL) {
-                       debug_msg("callback is null..");
-               } else {
-                       debug_msg("[CALLBACK(%p) START]",g_focus_sound_handle[focus_index].watch_callback);
-                       (g_focus_sound_handle[focus_index].watch_callback)(cb_data.handle, cb_data.type, cb_data.state, cb_data.stream_type, cb_data.name, g_focus_sound_handle[focus_index].user_data);
-                       debug_msg("[CALLBACK END]");
-                       if (g_focus_session_interrupt_info.user_cb) {
-                               debug_error("sending session interrupt callback(%p)", g_focus_session_interrupt_info.user_cb);
-                               (g_focus_session_interrupt_info.user_cb)(cb_data.state, cb_data.stream_type, true, g_focus_session_interrupt_info.user_data);
-                       }
-               }
-
-#ifdef CONFIG_ENABLE_RETCB
-
-                       int rett = 0;
-                       int tmpfd = -1;
-                       int buf = -1;
-                       char *filename2 = g_strdup_printf("/tmp/FOCUS.%d.wchr", g_focus_sound_handle[focus_index].focus_tid);
-                       tmpfd = open(filename2, O_WRONLY | O_NONBLOCK);
-                       if (tmpfd < 0) {
-                               char str_error[256];
-                               strerror_r(errno, str_error, sizeof(str_error));
-                               debug_error("[RETCB][Failed(May Server Close First)]tid(%d) fd(%d) %s errno=%d(%s)\n", tid, tmpfd, filename2, errno, str_error);
-                               g_free(filename2);
-                               g_mutex_unlock(&g_focus_sound_handle[focus_index].focus_lock);
-                               return FALSE;
-                       }
-                       buf = cb_data.handle;
-                       rett = write(tmpfd, &buf, sizeof(buf));
-                       close(tmpfd);
-                       g_free(filename2);
-                       debug_msg("[RETCB] tid(%d) finishing CB (write=%d)\n", tid, rett);
-
-#endif
-
+       if ((ret = __convert_volume_type_internal_to_str(type, &type_str)) != MM_ERROR_NONE) {
+               debug_error("volume type convert failed");
+               goto failed;
        }
 
-       debug_error("unlock focus_lock = %p", &g_focus_sound_handle[focus_index].focus_lock);
-       g_mutex_unlock(&g_focus_sound_handle[focus_index].focus_lock);
+       ret = mm_sound_proxy_set_volume_by_type(type_str, level);
 
+failed:
        debug_fleave();
-
-
-       return TRUE;
+       return ret;
 }
 
-static void _focus_open_callback(int index, bool is_for_watching)
+int mm_sound_client_get_volume_by_internal_type(volume_type_internal_t type, unsigned int *level)
 {
-       mode_t pre_mask;
-       char *filename;
-
-       debug_fenter();
-
-       if (is_for_watching) {
-               filename = g_strdup_printf("/tmp/FOCUS.%d.wch", g_focus_sound_handle[index].focus_tid);
-       } else {
-               filename = g_strdup_printf("/tmp/FOCUS.%d.%d", g_focus_sound_handle[index].focus_tid, g_focus_sound_handle[index].handle);
-       }
-       pre_mask = umask(0);
-       if (mknod(filename, S_IFIFO|0666, 0)) {
-               debug_error("mknod() failure, errno(%d)", errno);
-       }
-       umask(pre_mask);
-       g_focus_sound_handle[index].focus_fd = open( filename, O_RDWR|O_NONBLOCK);
-       if (g_focus_sound_handle[index].focus_fd == -1) {
-               debug_error("Open fail : index(%d), file open error(%d)", index, errno);
-       } else {
-               debug_log("Open sucess : index(%d), filename(%s), fd(%d)", index, filename, g_focus_sound_handle[index].focus_fd);
-       }
-       g_free(filename);
-       filename = NULL;
-
-#ifdef CONFIG_ENABLE_RETCB
-       char *filename2;
+       int ret = MM_ERROR_NONE;
+       int vconf_value = 0;
 
-       if (is_for_watching) {
-               filename2 = g_strdup_printf("/tmp/FOCUS.%d.wchr", g_focus_sound_handle[index].focus_tid);
-       } else {
-               filename2 = g_strdup_printf("/tmp/FOCUS.%d.%dr", g_focus_sound_handle[index].focus_tid, g_focus_sound_handle[index].handle);
+       if (level == NULL) {
+               debug_error("invalid argument, level is null");
+               return MM_ERROR_INVALID_ARGUMENT;
        }
-       pre_mask = umask(0);
-       if (mknod(filename2, S_IFIFO | 0666, 0)) {
-               debug_error("mknod() failure, errno(%d)", errno);
+
+       /* 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;
        }
-       umask(pre_mask);
-       g_free(filename2);
-       filename2 = NULL;
-#endif
-       debug_fleave();
 
+       *level = vconf_value;
+
+       return ret;
 }
 
-void _focus_close_callback(int index, bool is_for_watching)
+static void _mm_sound_volume_changed_callback_wrapper_func(const char *direction, const char *volume_type_str,
+                                                                                                               int volume_level, void *userdata)
 {
-       debug_fenter();
-
-       if (g_focus_sound_handle[index].focus_fd < 0) {
-               debug_error("Close fail : fd error.");
-       } else {
-               char *filename;
-               if (is_for_watching) {
-                       filename = g_strdup_printf("/tmp/FOCUS.%d.wch", g_focus_sound_handle[index].focus_tid);
-               } else {
-                       filename = g_strdup_printf("/tmp/FOCUS.%d.%d", g_focus_sound_handle[index].focus_tid, g_focus_sound_handle[index].handle);
-               }
-               close(g_focus_sound_handle[index].focus_fd);
-               if (remove(filename)) {
-                       debug_error("remove() failure, filename(%s), errno(%d)", filename, errno);
-               }
-               debug_log("Close Sucess : index(%d), filename(%s)", index, filename);
-               g_free(filename);
-               filename = NULL;
-       }
+       int volume_type = 0;
+       bool is_for_internal =  false;
+       struct callback_data *cb_data = (struct callback_data *) userdata;
 
-#ifdef CONFIG_ENABLE_RETCB
-       char *filename2;
+       debug_log("direction : %s, volume_type : %s, volume_level : %d",
+                       direction, volume_type_str, volume_level);
 
-       if (is_for_watching) {
-               filename2 = g_strdup_printf("/tmp/FOCUS.%d.wchr", g_focus_sound_handle[index].focus_tid);
-       } else {
-               filename2 = g_strdup_printf("/tmp/FOCUS.%d.%dr", g_focus_sound_handle[index].focus_tid, g_focus_sound_handle[index].handle);
+       if (cb_data == NULL) {
+               debug_warning("volume changed callback data null");
+               return;
        }
 
-       /* Defensive code - wait until callback timeout although callback is removed */
-       int buf = MM_ERROR_NONE; //no need to specify cb result to server, just notice if the client got the callback properly or not
-       int tmpfd = -1;
-       char str_error[256];
-
-       tmpfd = open(filename2, O_WRONLY | O_NONBLOCK);
-       if (tmpfd < 0) {
-               strerror_r(errno, str_error, sizeof(str_error));
-               debug_warning("could not open file(%s) (may server close it first), tid(%d) fd(%d) %s errno=%d(%s)",
-                       filename2, g_focus_sound_handle[index].focus_tid, tmpfd, filename2, errno, str_error);
-       } else {
-               ssize_t written;
-               debug_msg("write MM_ERROR_NONE(tid:%d) for waiting server", g_focus_sound_handle[index].focus_tid);
-               written = write(tmpfd, &buf, sizeof(buf));
-               if (written == -1) {
-                   strerror_r(errno, str_error, sizeof(str_error));
-                   debug_warning("write failed, %s", str_error);
-               }
-               close(tmpfd);
+       if (__convert_volume_type_to_int(volume_type_str, &volume_type, &is_for_internal) != MM_ERROR_NONE) {
+               debug_error("volume type convert failed");
+               return;
        }
 
-       if (remove(filename2)) {
-               debug_error("remove() failure, filename(%s), errno(%d)", filename2, errno);
+       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_internal)(cb_data->user_cb))((volume_type_internal_t)volume_type, volume_level, cb_data->user_data);
        }
-       g_free(filename2);
-       filename2 = NULL;
-#endif
-
 }
 
-static bool _focus_add_sound_callback(int index, int fd, gushort events, focus_gLoopPollHandler_t p_gloop_poll_handler )
+int mm_sound_client_add_volume_changed_callback(mm_sound_volume_changed_cb func, void* userdata, unsigned int *subs_id)
 {
-       GSource* g_src = NULL;
-       GSourceFuncs *g_src_funcs = NULL;               /* handler function */
-       guint gsource_handle;
-       GPollFD *g_poll_fd = NULL;                      /* file descriptor */
+       int ret = MM_ERROR_NONE;
+       struct callback_data *cb_data = NULL;
 
        debug_fenter();
 
-       g_mutex_init(&g_focus_sound_handle[index].focus_lock);
+       GET_CB_DATA(cb_data, func, userdata, NULL);
 
-       /* 1. make GSource Object */
-       g_src_funcs = (GSourceFuncs *)g_malloc(sizeof(GSourceFuncs));
-       if (!g_src_funcs) {
-               debug_error("g_malloc failed on g_src_funcs");
-               return false;
-       }
+       ret = mm_sound_proxy_add_volume_changed_callback(_mm_sound_volume_changed_callback_wrapper_func, cb_data, g_free, subs_id);
 
-       g_src_funcs->prepare = _focus_fd_prepare;
-       g_src_funcs->check = _focus_fd_check;
-       g_src_funcs->dispatch = _focus_fd_dispatch;
-       g_src_funcs->finalize = NULL;
-       g_src = g_source_new(g_src_funcs, sizeof(GSource));
-       if (!g_src) {
-               debug_error("g_malloc failed on m_readfd");
-               return false;
-       }
-       g_focus_sound_handle[index].focus_src = g_src;
-       g_focus_sound_handle[index].g_src_funcs = g_src_funcs;
-
-       /* 2. add file description which used in g_loop() */
-       g_poll_fd = (GPollFD *)g_malloc(sizeof(GPollFD));
-       if (!g_poll_fd) {
-               debug_error("g_malloc failed on g_poll_fd");
-               return false;
-       }
-       g_poll_fd->fd = fd;
-       g_poll_fd->events = events;
-       g_focus_sound_handle[index].g_poll_fd = g_poll_fd;
-
-       /* 3. combine g_source object and file descriptor */
-       g_source_add_poll(g_src, g_poll_fd);
-       gsource_handle = g_source_attach(g_src, g_main_loop_get_context(g_focus_loop));
-       if (!gsource_handle) {
-               debug_error(" Failed to attach the source to context");
-               return false;
-       }
-       //g_source_unref(g_src);
+       debug_fleave();
+
+       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();
 
-       /* 4. set callback */
-       g_source_set_callback(g_src, p_gloop_poll_handler,(gpointer)g_poll_fd, NULL);
+       GET_CB_DATA(cb_data, func, userdata, (void*)is_for_internal);
 
-       debug_log(" g_malloc:g_src_funcs(%#X),g_poll_fd(%#X)  g_source_add_poll:g_src_id(%d)  g_source_set_callback:errno(%d)",
-                               g_src_funcs, g_poll_fd, gsource_handle, errno);
+       ret = mm_sound_proxy_add_volume_changed_callback(_mm_sound_volume_changed_callback_wrapper_func, cb_data, g_free, subs_id);
 
        debug_fleave();
-       return true;
-
 
+       return ret;
 }
 
-static bool _focus_remove_sound_callback(int index, gushort events)
+int mm_sound_client_remove_volume_changed_callback(unsigned int subs_id)
 {
-       bool ret = true;
-
+       int ret = MM_ERROR_NONE;
        debug_fenter();
 
-       g_mutex_clear(&g_focus_sound_handle[index].focus_lock);
+       ret = mm_sound_proxy_remove_volume_changed_callback(subs_id);
 
-       GSourceFuncs *g_src_funcs = g_focus_sound_handle[index].g_src_funcs;
-       GPollFD *g_poll_fd = g_focus_sound_handle[index].g_poll_fd;     /* store file descriptor */
-       if (!g_poll_fd) {
-               debug_error("g_poll_fd is null..");
-               ret = false;
-               goto init_handle;
-       }
-       g_poll_fd->fd = g_focus_sound_handle[index].focus_fd;
-       g_poll_fd->events = events;
+       debug_fleave();
+       return ret;
+}
 
-       if (!g_focus_sound_handle[index].focus_src) {
-               debug_error("FOCUS_sound_handle[%d].focus_src is null..", index);
-               goto init_handle;
-       }
-       debug_log(" g_source_remove_poll : fd(%d), event(%x), errno(%d)", g_poll_fd->fd, g_poll_fd->events, errno);
-       g_source_remove_poll(g_focus_sound_handle[index].focus_src, g_poll_fd);
+int mm_sound_client_set_mute_by_type(volume_type_t type, bool mute)
+{
+       int ret = MM_ERROR_NONE;
+       char *type_str = NULL;
 
-init_handle:
+       debug_fenter();
 
-       if (g_focus_sound_handle[index].focus_src) {
-               g_source_destroy(g_focus_sound_handle[index].focus_src);
-               if (!g_source_is_destroyed (g_focus_sound_handle[index].focus_src)) {
-                       debug_warning(" failed to g_source_destroy(), focus_src(0x%p)", g_focus_sound_handle[index].focus_src);
-               }
+       if (type > VOLUME_TYPE_VOICE) {
+               debug_error("invalid volume type %d", type);
+               return MM_ERROR_INVALID_ARGUMENT;
        }
-       debug_log(" g_free : g_src_funcs(%#X), g_poll_fd(%#X)", g_src_funcs, g_poll_fd);
 
-       if (g_src_funcs) {
-               g_free(g_src_funcs);
-               g_src_funcs = NULL;
-       }
-       if (g_poll_fd) {
-               g_free(g_poll_fd);
-               g_poll_fd = NULL;
+       if ((ret = __convert_volume_type_to_str(type, &type_str)) != MM_ERROR_NONE) {
+               debug_error("volume type convert failed");
+               goto failed;
        }
 
-       g_focus_sound_handle[index].g_src_funcs = NULL;
-       g_focus_sound_handle[index].g_poll_fd = NULL;
-       g_focus_sound_handle[index].focus_src = NULL;
-       g_focus_sound_handle[index].focus_callback = NULL;
-       g_focus_sound_handle[index].watch_callback = NULL;
+       ret = mm_sound_proxy_set_mute_by_type(type_str, mute);
 
+failed:
        debug_fleave();
        return ret;
 }
 
-
-static void _focus_add_callback(int index, bool is_for_watching)
+int mm_sound_client_get_mute_by_type(volume_type_t type, bool *muted)
 {
+       int ret = MM_ERROR_NONE;
+       int vconf_value = 0;
+
        debug_fenter();
-       if (!is_for_watching) {
-               if (!_focus_add_sound_callback(index, g_focus_sound_handle[index].focus_fd, (gushort)POLLIN | POLLPRI, _focus_callback_handler)) {
-                       debug_error("failed to _focus_add_sound_callback()");
-                       //return false;
-               }
-       } else { // need to check if it's necessary
-               if (!_focus_add_sound_callback(index, g_focus_sound_handle[index].focus_fd, (gushort)POLLIN | POLLPRI, _focus_watch_callback_handler)) {
-                       debug_error("failed to _focus_add_sound_callback()");
-                       //return false;
-               }
+
+       if (type > VOLUME_TYPE_VOICE) {
+               debug_error("invalid volume type %d", type);
+               return MM_ERROR_INVALID_ARGUMENT;
        }
-       debug_fleave();
-}
 
-static void _focus_remove_callback(int index)
-{
-       debug_fenter();
-       if (!_focus_remove_sound_callback(index, (gushort)POLLIN | POLLPRI)) {
-               debug_error("failed to __focus_remove_sound_callback()");
-               //return false;
+       /* Get mute state from VCONF */
+       if (vconf_get_bool(g_mute_vconf[type], &vconf_value)) {
+               debug_error("vconf_get_int(%s) failed..\n", g_mute_vconf[type]);
+               return MM_ERROR_SOUND_INTERNAL;
        }
+
+       *muted = (bool)vconf_value;
+
        debug_fleave();
+       return ret;
 }
 
-static void _focus_init_callback(int index, bool is_for_watching)
+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 ret = MM_ERROR_NONE;
        debug_fenter();
-       _focus_open_callback(index, is_for_watching);
-       _focus_add_callback(index, is_for_watching);
+
+       ret = mm_sound_proxy_set_filter_by_type(stream_type, filter_name, filter_parameters, filter_group);
+
        debug_fleave();
+       return ret;
 }
 
-static void _focus_destroy_callback(int index, bool is_for_watching)
+int mm_sound_client_unset_filter_by_type(const char *stream_type)
 {
+       int ret = MM_ERROR_NONE;
        debug_fenter();
-       _focus_remove_callback(index);
-       _focus_close_callback(index, is_for_watching);
+
+       ret = mm_sound_proxy_unset_filter_by_type(stream_type);
+
        debug_fleave();
+       return ret;
 }
 
-int mm_sound_client_get_unique_id(int *id)
+int mm_sound_client_control_filter_by_type(const char *stream_type, const char *filter_name, const char *filter_controls)
 {
        int ret = MM_ERROR_NONE;
-
-       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_id_mutex, MM_ERROR_SOUND_INTERNAL);
        debug_fenter();
 
-       if (!id)
-               ret = MM_ERROR_INVALID_ARGUMENT;
-       else
-               ret = mm_sound_proxy_get_unique_id(id);
+       ret = mm_sound_proxy_control_filter_by_type(stream_type, filter_name, filter_controls);
 
        debug_fleave();
-       MMSOUND_LEAVE_CRITICAL_SECTION(&g_id_mutex);
-
        return ret;
 }
 
-int mm_sound_client_is_focus_cb_thread(GThread *mine, bool *result)
+int mm_sound_client_is_focus_cb_thread(GThread *mine, bool *result, bool *is_for_watching)
 {
        int ret = MM_ERROR_NONE;
+       int i = 0;
 
        if (!mine || !result)
                ret = MM_ERROR_INVALID_ARGUMENT;
        else {
-               if (mine == g_focus_thread)
-                       *result = true;
-               else
-                       *result = false;
+               *result = false;
+               for (i = 0; i < FOCUS_HANDLE_MAX; i++) {
+                       if (!g_focus_sound_handle[i].is_used)
+                               continue;
+                       if (g_focus_sound_handle[i].focus_cb_thread == mine) {
+                               *result = true;
+                               if (is_for_watching)
+                                       *is_for_watching = false;
+                               break;
+                       }
+                       if (g_focus_sound_handle[i].focus_watch_cb_thread == mine) {
+                               *result = true;
+                               if (is_for_watching)
+                                       *is_for_watching = true;
+                               break;
+                       }
+               }
        }
 
        return ret;
 }
 
-int mm_sound_client_register_focus(int id, int pid, const char *stream_type, mm_sound_focus_changed_cb callback, bool is_for_session, void* user_data)
+int mm_sound_client_register_focus(int pid, const char *stream_type,
+                                                               mm_sound_focus_changed_cb callback, void* user_data, int *id)
 {
        int ret = MM_ERROR_NONE;
-       int instance;
-       int index = 0;
-       debug_fenter();
+       int index = -1;
 
-       instance = pid;
+       debug_fenter();
+       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_index_mutex, MM_ERROR_SOUND_INTERNAL);
 
-       for (index = 0; index < FOCUS_HANDLE_MAX - 1; index++) {
-               if (g_focus_sound_handle[index].is_used == false) {
-                       g_focus_sound_handle[index].is_used = true;
-                       break;
-               }
+       if (focus_find_empty_index(&index)) {
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto cleanup;
        }
 
-       g_focus_sound_handle[index].focus_tid = instance;
-       g_focus_sound_handle[index].handle = id;
+       g_focus_sound_handle[index].focus_pid = pid;
        g_focus_sound_handle[index].focus_callback = callback;
        g_focus_sound_handle[index].user_data = user_data;
-       g_focus_sound_handle[index].is_for_session = is_for_session;
        g_focus_sound_handle[index].auto_reacquire = true;
 
-       ret = mm_sound_proxy_register_focus(id, pid, stream_type, callback, is_for_session, user_data);
-
+       ret = mm_sound_proxy_register_focus(index, stream_type, id);
        if (ret == MM_ERROR_NONE) {
-               debug_msg("[Client] Success to register focus\n");
-               g_need_emergent_exit = TRUE;
-               if (!g_focus_thread) {
-                       GMainContext* focus_context = g_main_context_new ();
-                       g_focus_loop = g_main_loop_new (focus_context, FALSE);
-                       g_main_context_unref(focus_context);
-                       g_focus_thread = g_thread_new("focus-callback-thread", _focus_thread_func, NULL);
-                       if (g_focus_thread == NULL) {
-                               debug_error ("could not create thread..");
-                               g_main_loop_unref(g_focus_loop);
-                               g_focus_sound_handle[index].is_used = false;
-                               ret = MM_ERROR_SOUND_INTERNAL;
-                               goto cleanup;
-                       }
+               debug_msg("Success to register focus, client_fd[%d], id[%d]", g_focus_sound_handle[index].client_fd, *id);
+               if (focus_init_context(index, false)) {
+                       ret = MM_ERROR_SOUND_INTERNAL;
+                       goto cleanup;
                }
        } else {
-               debug_error("[Client] Error occurred : 0x%x \n",ret);
-               g_focus_sound_handle[index].is_used = false;
+               debug_error("Error occurred : 0x%x", ret);
                goto cleanup;
        }
 
-       _focus_init_callback(index, false);
+       focus_init_callback(index, false);
 
 cleanup:
+       if (ret != MM_ERROR_NONE && index >= 0)
+               g_focus_sound_handle[index].is_used = false;
 
+       MMSOUND_LEAVE_CRITICAL_SECTION(&g_index_mutex);
        debug_fleave();
+
        return ret;
 }
 
 int mm_sound_client_unregister_focus(int id)
 {
        int ret = MM_ERROR_NONE;
-       int instance;
        int index = -1;
+
        debug_fenter();
+       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_index_mutex, MM_ERROR_SOUND_INTERNAL);
 
-       index = _focus_find_index_by_handle(id);
+       index = focus_find_index_by_handle(id);
        if (index == -1) {
                debug_error("Could not find index");
-               return MM_ERROR_INVALID_ARGUMENT;
+               ret = MM_ERROR_INVALID_ARGUMENT;
+               goto cleanup;
        }
-       instance = g_focus_sound_handle[index].focus_tid;
 
        if (!g_mutex_trylock(&g_focus_sound_handle[index].focus_lock)) {
                debug_warning("maybe focus_callback is being called, try one more time..");
-               usleep(2500000); // 2.5 sec
-               if (g_mutex_trylock(&g_focus_sound_handle[index].focus_lock)) {
+               usleep(2500000); /* 2.5 sec */
+               if (g_mutex_trylock(&g_focus_sound_handle[index].focus_lock))
                        debug_msg("finally got focus_lock");
-               }
        }
 
-       ret = mm_sound_proxy_unregister_focus(instance, id, g_focus_sound_handle[index].is_for_session);
-
+       ret = mm_sound_proxy_unregister_focus(index);
        if (ret == MM_ERROR_NONE)
-               debug_msg("[Client] Success to unregister focus\n");
+               debug_msg("Success to unregister focus");
        else
-               debug_error("[Client] Error occurred : 0x%x \n",ret);
+               debug_error("Error occurred : 0x%x", ret);
 
        g_mutex_unlock(&g_focus_sound_handle[index].focus_lock);
 
-       _focus_destroy_callback(index, false);
+       focus_deinit_callback(index, false);
        g_focus_sound_handle[index].focus_fd = 0;
-       g_focus_sound_handle[index].focus_tid = 0;
+       g_focus_sound_handle[index].focus_pid = 0;
+       g_focus_sound_handle[index].client_fd = 0;
        g_focus_sound_handle[index].handle = 0;
        g_focus_sound_handle[index].is_used = false;
+       focus_deinit_context(index, false);
 
+cleanup:
+       MMSOUND_LEAVE_CRITICAL_SECTION(&g_index_mutex);
        debug_fleave();
        return ret;
 }
@@ -1544,39 +1078,41 @@ int mm_sound_client_unregister_focus(int id)
 int mm_sound_client_set_focus_reacquisition(int id, bool reacquisition)
 {
        int ret = MM_ERROR_NONE;
-       int instance;
        int index = -1;
        bool result;
 
        debug_fenter();
 
-       index = _focus_find_index_by_handle(id);
+       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_index_mutex, MM_ERROR_SOUND_INTERNAL);
+
+       index = focus_find_index_by_handle(id);
        if (index == -1) {
                debug_error("Could not find index");
-               return MM_ERROR_INVALID_ARGUMENT;
+               ret = MM_ERROR_INVALID_ARGUMENT;
+               goto cleanup;
        }
-       instance = g_focus_sound_handle[index].focus_tid;
 
-       ret = mm_sound_client_is_focus_cb_thread(g_thread_self(), &result);
+       ret = mm_sound_client_is_focus_cb_thread(g_thread_self(), &result, NULL);
        if (ret) {
-               debug_error("[Client] mm_sound_client_is_focus_cb_thread failed");
+               debug_error("mm_sound_client_is_focus_cb_thread failed");
                goto cleanup;
        } else if (!result) {
-               ret = mm_sound_proxy_set_foucs_reacquisition(instance, id, reacquisition);
+               ret = mm_sound_proxy_set_focus_reacquisition(index, reacquisition);
                if (ret == MM_ERROR_NONE) {
-                       debug_msg("[Client] Success to set focus reacquisition\n");
+                       debug_msg("Success to set focus reacquisition to [%d]", reacquisition);
                } else {
-                       debug_error("[Client] Error occurred : 0x%x \n",ret);
+                       debug_error("Error occurred : 0x%x", ret);
                        goto cleanup;
                }
        } else {
-               debug_warning("[Client] Inside the focus cb thread, bypassing dbus method call");
+               debug_warning("Inside the focus cb thread, set focus reacquisition to [%d]", reacquisition);
        }
 
        g_focus_sound_handle[index].auto_reacquire = reacquisition;
+       debug_msg("set focus reacquisition(%d) for id(%d)", reacquisition, id);
 
 cleanup:
-
+       MMSOUND_LEAVE_CRITICAL_SECTION(&g_index_mutex);
        debug_fleave();
        return ret;
 }
@@ -1593,147 +1129,212 @@ int mm_sound_client_get_focus_reacquisition(int id, bool *reacquisition)
                return MM_ERROR_INVALID_ARGUMENT;
        }
 
-       index = _focus_find_index_by_handle(id);
+       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_index_mutex, MM_ERROR_SOUND_INTERNAL);
+
+       index = focus_find_index_by_handle(id);
        if (index == -1) {
                debug_error("Could not find index");
-               return MM_ERROR_INVALID_ARGUMENT;
+               ret = MM_ERROR_INVALID_ARGUMENT;
+               goto cleanup;
        }
 
        *reacquisition = g_focus_sound_handle[index].auto_reacquire;
+       debug_msg("get focus reacquisition(%d) for id(%d)", *reacquisition, id);
 
+cleanup:
+       MMSOUND_LEAVE_CRITICAL_SECTION(&g_index_mutex);
        debug_fleave();
        return ret;
 }
 
-int mm_sound_client_get_acquired_focus_stream_type(int focus_type, char **stream_type, char **additional_info)
+int mm_sound_client_get_acquired_focus_stream_type(int focus_type, char **stream_type, int *option, char **ext_info)
 {
        int ret = MM_ERROR_NONE;
 
        debug_fenter();
 
-       ret = mm_sound_proxy_get_acquired_focus_stream_type(focus_type, stream_type, additional_info);
+       ret = mm_sound_proxy_get_acquired_focus_stream_type(focus_type, stream_type, option, ext_info);
        if (ret == MM_ERROR_NONE)
-               debug_msg("[Client] Success to get stream type of acquired focus, stream_type(%s), additional_info(%s)\n", *stream_type, *additional_info);
+               debug_msg("Success to get stream type of acquired focus, stream_type(%s), ext_info(%s)",
+                               *stream_type, *ext_info);
        else
-               debug_error("[Client] Error occurred : 0x%x \n",ret);
+               debug_error("Error occurred : 0x%x", ret);
 
        debug_fleave();
+
        return ret;
 }
 
-int mm_sound_client_acquire_focus(int id, mm_sound_focus_type_e type, const char *option)
+int mm_sound_client_acquire_focus(int id, mm_sound_focus_type_e type, int option, const char *ext_info)
 {
        int ret = MM_ERROR_NONE;
-       int instance;
        int index = -1;
 
        debug_fenter();
+       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_index_mutex, MM_ERROR_SOUND_INTERNAL);
 
-       index = _focus_find_index_by_handle(id);
+       index = focus_find_index_by_handle(id);
        if (index == -1) {
                debug_error("Could not find index");
-               return MM_ERROR_INVALID_ARGUMENT;
+               ret = MM_ERROR_INVALID_ARGUMENT;
+               goto cleanup;
        }
-       instance = g_focus_sound_handle[index].focus_tid;
-
-       ret = mm_sound_proxy_acquire_focus(instance, id, type, option, g_focus_sound_handle[index].is_for_session);
 
+       ret = mm_sound_proxy_acquire_focus(index, type, option, ext_info);
        if (ret == MM_ERROR_NONE)
-               debug_msg("[Client] Success to acquire focus\n");
+               debug_msg("Success to acquire focus");
        else
-               debug_error("[Client] Error occurred : 0x%x \n",ret);
+               debug_error("Error occurred : 0x%x", ret);
 
+cleanup:
+       MMSOUND_LEAVE_CRITICAL_SECTION(&g_index_mutex);
        debug_fleave();
        return ret;
 }
 
-int mm_sound_client_release_focus(int id, mm_sound_focus_type_e type, const char *option)
+int mm_sound_client_release_focus(int id, mm_sound_focus_type_e type, int option, const char *ext_info)
 {
        int ret = MM_ERROR_NONE;
-       int instance;
        int index = -1;
+
        debug_fenter();
+       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_index_mutex, MM_ERROR_SOUND_INTERNAL);
 
-       index = _focus_find_index_by_handle(id);
+       index = focus_find_index_by_handle(id);
        if (index == -1) {
                debug_error("Could not find index");
-               return MM_ERROR_INVALID_ARGUMENT;
+               ret = MM_ERROR_INVALID_ARGUMENT;
+               goto cleanup;
        }
-       instance = g_focus_sound_handle[index].focus_tid;
-
-       ret = mm_sound_proxy_release_focus(instance, id, type, option, g_focus_sound_handle[index].is_for_session);
 
+       ret = mm_sound_proxy_release_focus(index, type, option, ext_info);
        if (ret == MM_ERROR_NONE)
-               debug_msg("[Client] Success to release focus\n");
+               debug_msg("Success to release focus");
        else
-               debug_error("[Client] Error occurred : 0x%x \n",ret);
+               debug_error("Error occurred : 0x%x", ret);
+
+cleanup:
+       MMSOUND_LEAVE_CRITICAL_SECTION(&g_index_mutex);
+       debug_fleave();
+       return ret;
+}
 
+int mm_sound_client_update_stream_focus_status(int id, unsigned int status)
+{
+       int ret = MM_ERROR_NONE;
+       debug_fenter();
+
+       if ((ret = mm_sound_proxy_update_stream_focus_status(id, status)) != MM_ERROR_NONE)
+               debug_error("failed to update stream focus status, ret[0x%x]", ret);
 
        debug_fleave();
        return ret;
 }
 
-int mm_sound_client_set_focus_watch_callback(int pid, mm_sound_focus_type_e focus_type, mm_sound_focus_changed_watch_cb callback, bool is_for_session, void* user_data, int *id)
+int mm_sound_client_deliver_focus(int src_id, int dst_id, mm_sound_focus_type_e focus_type)
 {
        int ret = MM_ERROR_NONE;
-       int instance;
-       int index = 0;
+       int src_index;
+       int dst_index;
+
        debug_fenter();
 
-       if (!id)
-               return MM_ERROR_INVALID_ARGUMENT;
+       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_index_mutex, MM_ERROR_SOUND_INTERNAL);
+
+       src_index = focus_find_index_by_handle(src_id);
+       if (src_index == -1) {
+               debug_error("Could not find src index");
+               ret = MM_ERROR_INVALID_ARGUMENT;
+               goto cleanup;
+       }
+       dst_index = focus_find_index_by_handle(dst_id);
+       if (dst_index == -1) {
+               debug_error("Could not find dst index");
+               ret = MM_ERROR_INVALID_ARGUMENT;
+               goto cleanup;
+       }
+       if (g_focus_sound_handle[src_index].focus_pid != g_focus_sound_handle[dst_index].focus_pid) {
+               debug_error("pid[%d/%d] are not same for dst/src",
+                                       g_focus_sound_handle[src_index].focus_pid,
+                                       g_focus_sound_handle[dst_index].focus_pid);
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto cleanup;
+       }
+
+       if ((ret = mm_sound_proxy_deliver_focus(src_index, dst_index, focus_type)) != MM_ERROR_NONE)
+               debug_error("failed to deliver focus, ret[0x%x]", ret);
+
+cleanup:
+       MMSOUND_LEAVE_CRITICAL_SECTION(&g_index_mutex);
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_client_set_focus_watch_callback(int pid, mm_sound_focus_type_e focus_type,
+                                                                                       mm_sound_focus_changed_watch_cb callback, void* user_data, int *id)
+{
+       int ret = MM_ERROR_NONE;
+       int index = -1;
 
-       //pthread_mutex_lock(&g_thread_mutex2);
+       debug_fenter();
 
-       instance = pid;
+       if (!id)
+               return MM_ERROR_INVALID_ARGUMENT;
 
-       ret = mm_sound_proxy_get_unique_id(id);
-       if (ret)
-               return ret;
+       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_index_mutex, MM_ERROR_SOUND_INTERNAL);
 
-       for (index = 0; index < FOCUS_HANDLE_MAX - 1; index++) {
-               if (g_focus_sound_handle[index].is_used == false) {
-                       g_focus_sound_handle[index].is_used = true;
-                       break;
-               }
+       if (focus_find_empty_index(&index)) {
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto cleanup;
        }
 
-       g_focus_sound_handle[index].focus_tid = instance;
-       g_focus_sound_handle[index].handle = *id;
+       g_focus_sound_handle[index].focus_pid = pid;
        g_focus_sound_handle[index].watch_callback = callback;
        g_focus_sound_handle[index].user_data = user_data;
-       g_focus_sound_handle[index].is_for_session = is_for_session;
-
-       ret = mm_sound_proxy_set_focus_watch_callback(pid, g_focus_sound_handle[index].handle, focus_type, callback, is_for_session, user_data);
+       g_focus_sound_handle[index].unset_watch_callback_requested = false;
 
+       ret = mm_sound_proxy_add_focus_watch_callback(index, focus_type);
        if (ret == MM_ERROR_NONE) {
-               debug_msg("[Client] Success to watch focus");
-               g_need_emergent_exit = TRUE;
-               if (!g_focus_thread) {
-                       GMainContext* focus_context = g_main_context_new ();
-                       g_focus_loop = g_main_loop_new (focus_context, FALSE);
-                       g_main_context_unref(focus_context);
-                       g_focus_thread = g_thread_new("focus-callback-thread", _focus_thread_func, NULL);
-                       if (g_focus_thread == NULL) {
-                               debug_error ("could not create thread..");
-                               g_main_loop_unref(g_focus_loop);
-                               ret = MM_ERROR_SOUND_INTERNAL;
-                               goto cleanup;
-                       }
+               *id = g_focus_sound_handle[index].handle;
+               debug_msg("Success to add watch focus cb, id(%d)", *id);
+               if (focus_init_context(index, true)) {
+                       ret = MM_ERROR_SOUND_INTERNAL;
+                       goto cleanup;
                }
        } else {
-               debug_error("[Client] Error occurred : 0x%x",ret);
+               debug_error("Error occurred : 0x%x", ret);
                goto cleanup;
        }
 
-       _focus_init_callback(index, true);
+       focus_init_callback(index, true);
 
 cleanup:
-
-       if (ret) {
+       if (ret != MM_ERROR_NONE && index >= 0)
                g_focus_sound_handle[index].is_used = false;
+
+       MMSOUND_LEAVE_CRITICAL_SECTION(&g_index_mutex);
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_client_request_unset_focus_watch_callback(int id)
+{
+       int ret = MM_ERROR_NONE;
+       int index = -1;
+
+       debug_fenter();
+       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_index_mutex, MM_ERROR_SOUND_INTERNAL);
+
+       index = focus_watch_find_index_by_handle(id);
+       if (index == -1) {
+               debug_error("Could not find index");
+               ret = MM_ERROR_INVALID_ARGUMENT;
+               goto cleanup;
        }
+       g_focus_sound_handle[index].unset_watch_callback_requested = true;
 
+cleanup:
+       MMSOUND_LEAVE_CRITICAL_SECTION(&g_index_mutex);
        debug_fleave();
        return ret;
 }
@@ -1742,37 +1343,127 @@ int mm_sound_client_unset_focus_watch_callback(int id)
 {
        int ret = MM_ERROR_NONE;
        int index = -1;
+
        debug_fenter();
+       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_index_mutex, MM_ERROR_SOUND_INTERNAL);
 
-       index = _focus_find_index_by_handle(id);
+       index = focus_watch_find_index_by_handle(id);
        if (index == -1) {
                debug_error("Could not find index");
-               return MM_ERROR_INVALID_ARGUMENT;
+               ret = MM_ERROR_INVALID_ARGUMENT;
+               goto cleanup;
        }
 
        g_mutex_lock(&g_focus_sound_handle[index].focus_lock);
 
-       ret = mm_sound_proxy_unset_focus_watch_callback(g_focus_sound_handle[index].focus_tid, g_focus_sound_handle[index].handle, g_focus_sound_handle[index].is_for_session);
+       g_focus_sound_handle[index].is_used = false;
 
+       ret = mm_sound_proxy_remove_focus_watch_callback(index);
        if (ret == MM_ERROR_NONE)
-               debug_msg("[Client] Success to unwatch focus\n");
+               debug_msg("Success to remove watch focus cb, id(%d)", g_focus_sound_handle[index].handle);
        else
-               debug_error("[Client] Error occurred : 0x%x \n",ret);
+               debug_error("Error occurred : 0x%x", ret);
 
 
        g_mutex_unlock(&g_focus_sound_handle[index].focus_lock);
 
-       _focus_destroy_callback(index, true);
+       focus_deinit_callback(index, true);
        g_focus_sound_handle[index].focus_fd = 0;
-       g_focus_sound_handle[index].focus_tid = 0;
+       g_focus_sound_handle[index].focus_pid = 0;
+       g_focus_sound_handle[index].client_fd = 0;
        g_focus_sound_handle[index].handle = 0;
-       g_focus_sound_handle[index].is_used = false;
+       focus_deinit_context(index, true);
+
+cleanup:
+       MMSOUND_LEAVE_CRITICAL_SECTION(&g_index_mutex);
+       debug_fleave();
+       return ret;
+}
+
+static gboolean _idle_event_callback(void *data)
+{
+       focus_idle_event_t *idle_event_data = (focus_idle_event_t*)data;
+       int ret = MM_ERROR_NONE;
+
+       if (data == NULL) {
+               debug_error("data is null");
+               return FALSE;
+       }
+
+       debug_msg("idle_event_data(%p): type(%d), data(%d)",
+               idle_event_data, idle_event_data->type, idle_event_data->data);
+
+       switch (idle_event_data->type) {
+       case IDLE_EVENT_TYPE_UNSET_FOCUS_WATCH_CB:
+               if ((ret = mm_sound_client_unset_focus_watch_callback(idle_event_data->data)))
+                       debug_error("Could not unset focus watch callback, id(%d), ret = %x", idle_event_data->data, ret);
+               break;
+       case IDLE_EVENT_TYPE_UNREGISTER_FOCUS:
+               if ((ret = mm_sound_client_unregister_focus(idle_event_data->data)))
+                       debug_error("Could not unregister focus, id(%d), ret = %x", idle_event_data->data, ret);
+               break;
+       default:
+               debug_warning("invalid type(%d)", idle_event_data->type);
+               break;
+       }
+
+       g_free(idle_event_data);
+
+       g_idle_event_src = 0;
+
+       MMSOUND_LEAVE_CRITICAL_SECTION(&g_event_mutex);
+
+       return FALSE;
+}
+
+int mm_sound_client_execute_focus_func_in_main_context(focus_idle_event_type_e type, int data)
+{
+       focus_idle_event_t *idle_event_data = NULL;
+
+       if (IDLE_EVENT_TYPE_MAX < type)
+               return MM_ERROR_INVALID_ARGUMENT;
+
+       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_event_mutex, MM_ERROR_SOUND_INTERNAL);
+
+       idle_event_data = g_new0(focus_idle_event_t, 1);
+       idle_event_data->type = type;
+       idle_event_data->data = data;
+
+       g_idle_event_src = g_idle_add_full(G_PRIORITY_HIGH,
+                               (GSourceFunc)_idle_event_callback,
+                               (gpointer)idle_event_data,
+                               NULL);
+
+       return MM_ERROR_NONE;
+}
+
+int mm_sound_client_add_ducking_state_changed_callback(mm_sound_ducking_state_changed_cb func, void* userdata, unsigned int *subs_id)
+{
+       int ret = MM_ERROR_NONE;
+       struct callback_data *cb_data = NULL;
+
+       debug_fenter();
+
+       GET_CB_DATA(cb_data, func, userdata, NULL);
+
+       ret = mm_sound_proxy_add_ducking_state_changed_callback((mm_sound_ducking_state_changed_wrapper_cb)func,
+               cb_data, g_free, subs_id);
 
        debug_fleave();
+
        return ret;
 }
-#endif
 
+int mm_sound_client_remove_ducking_state_changed_callback(unsigned int subs_id)
+{
+       int ret = MM_ERROR_NONE;
+       debug_fenter();
+
+       ret = mm_sound_proxy_remove_ducking_state_changed_callback(subs_id);
+
+       debug_fleave();
+       return ret;
+}
 
 int mm_sound_client_add_test_callback(mm_sound_test_cb func, void* user_data, unsigned int *subs_id)
 {
@@ -1797,7 +1488,6 @@ int mm_sound_client_remove_test_callback(unsigned int subs_id)
        return ret;
 }
 
-
 int mm_sound_client_test(int a, int b, int* getv)
 {
        int ret = MM_ERROR_NONE;