Let's start tizen audio 3.0 54/41654/5
authorSeonmi Jin <seonmi.jin@samsung.com>
Tue, 27 Jan 2015 06:08:07 +0000 (15:08 +0900)
committerinhyeok <i_bc.kim@samsung.com>
Tue, 7 Jul 2015 04:11:40 +0000 (13:11 +0900)
- Big Changes
Change IPC from msgq to dbus between client and sound-server
Adopt focus and Stream-based routing
Move device managing code to pulseaudio

- Others
Support container
Fix bugs
Some refactoring
Remove accessibility related code
Remove vconf code for product
change sound-server to system permission

- Commits
Bug Fix : Remove not matching endif
Remove audio-balance/muteall/mono-audio related code
Remove accessibility related code
Change smack execution label("none") for dump script
remove muteall check when volume set
Add MMSoundMgrPulseSetDefaultSink() to load proper sink for a2dp
Remove code accessing to call related vonfkey
Remove unused vconf code
Remove vconf-key related to product feature
Remove voicerecoder vconf-keys usage
Remove recoder vconf-keys usage on TV profile
Seperate code and build require for bluetooth operation
Fix clear_dead_cb_list invalid operation
Remove voice control vconf-key usage
Update device direction in bt sco callback
Remove device-volume
Fix bug, invalid parameter to pa_usec_to_bytes, play sound endcallback
[Keytone Plugin] Remove unused code
Add and modify tone/wav player related APIs for stream_info
Revise primary volume feature
Send error just with string on dbus (not use quark)
Fix bug, print device id,state correctly
Modify signal send/subscribe API(change dest/sender bus name to NULL)
Set volume to pulseaudio through dbus
Fix index bug regarding focus watch cb
Fix invalid header include
add libmmsoundcommon dependency in plugin tone makefile
Add libpulse, libmmfsound depndency in plugin Makefiles
Start id of focus watch callback from 1, modify FOCUS_HANDLE_MAX
Add signal API set(subscribe/unsubscribe/send)
modify focus apis param for container support
SIGSEGV fixed when call sound_manager_destroy_stream_information()
enable new focus watch callback
disable new focus watch callback
Revise focus watch callback, add focus API to get uniq id
Revert device-type to enum
Disable mgr_device,pulse,session, and ask device to pulseaudio
Count device id from 1
[Wav] Fix route selection timing
add handle check for mm_sound_client_stop_sound
1.Change mm_sound_boot_play_sound() to use pipe IPC rather than vconf-to-pa-operation(remove vconfkey for url of power_on sound) 2.Apply stream role, volume_gain to keysound/bootsound/run_keytone
Remove mm_sound_pa_get_volume_max (rather use dbus interface in pulseaudio)
Fix strcat memory bug
Remove updating volume when an active device is changed (no need to do it in SPIN)
[security] remove kill() for removing cap_kill / cap_ptrace
change sound-server to system permission
Remove defines for stream types(no used now)
Support container for focus
Remove deprecated functions
Replace muteall vconf to dbus
Replace mono-audio vconf to dbus
Remove unsupported-format error type in dbus error entry
Get stream list including priority from pulseaudio stream-manager via DBUS
Fix bug regarding focus state that is sending to user callback
Replace audio balance vconf to dbus
Refactoring
modify focus victim node update logic & some typos
applying pipe to focus callback
Revise code (mgr_focus)
Use security-server to get container name (disabled yet)
Support container
Change emergent-exit method to signal
Replace bool with gboolean when using gdbus
Use glib type in play sound method handler
Fix bug when get connected device list
remove the null check of callback function
Replace IPC(msgq) with Dbus for communication between server and client.
1.change the prototype of focus callback 2.reset information about nodes which took the focus when unregistering the focus node
Remove BT module dependency
include mm_sound_focus.h to devel package
fix script for change toolchain
Add API for watching focus status
Fix build script for change toolchain
Support Audio Focus Feature
testsuite: add test menu for mono audio

Change-Id: I29a4dceacc9575bff2dffb65ccc3a4ee9f920fa0
Signed-off-by: Seonmi Jin <seonmi.jin@samsung.com>
68 files changed:
Makefile.am
common/mm_sound_utils.c
configure.ac
include/mm_ipc.h
include/mm_sound.h
include/mm_sound_client.h
include/mm_sound_client_dbus.h [new file with mode: 0644]
include/mm_sound_client_msgq.h [new file with mode: 0644]
include/mm_sound_common.h
include/mm_sound_device.h
include/mm_sound_focus.h [new file with mode: 0644]
include/mm_sound_msg.h
include/mm_sound_pa_client.h
include/mm_sound_private.h
include/mm_sound_stream.h [new file with mode: 0644]
include/mm_sound_utils.h
libmm-sound.manifest
mm_sound.c
mm_sound_bootsound.c
mm_sound_client.c
mm_sound_client_dbus.c [new file with mode: 0644]
mm_sound_client_msgq.c [new file with mode: 0644]
mm_sound_device.c
mm_sound_focus.c [new file with mode: 0644]
mm_sound_keysound.c
mm_sound_pa_client.c
mm_sound_pcm.c
mm_sound_pcm_async.c
packaging/libmm-sound.spec
packaging/sound-server.service
server/Makefile.am
server/include/mm_sound_mgr_asm.h
server/include/mm_sound_mgr_codec.h
server/include/mm_sound_mgr_device.h
server/include/mm_sound_mgr_device_dock.h
server/include/mm_sound_mgr_device_hdmi.h
server/include/mm_sound_mgr_device_headset.h
server/include/mm_sound_mgr_device_wfd.h
server/include/mm_sound_mgr_focus.h [new file with mode: 0644]
server/include/mm_sound_mgr_ipc.h
server/include/mm_sound_mgr_ipc_dbus.h [new file with mode: 0644]
server/include/mm_sound_mgr_ipc_msgq.h [new file with mode: 0644]
server/include/mm_sound_mgr_pulse.h
server/include/mm_sound_mgr_session.h
server/include/mm_sound_plugin_codec.h
server/mm_sound_mgr_asm.c
server/mm_sound_mgr_codec.c
server/mm_sound_mgr_device.c
server/mm_sound_mgr_device_dock.c
server/mm_sound_mgr_device_hdmi.c
server/mm_sound_mgr_device_headset.c
server/mm_sound_mgr_device_wfd.c
server/mm_sound_mgr_focus.c [new file with mode: 0644]
server/mm_sound_mgr_ipc.c
server/mm_sound_mgr_ipc_dbus.c [new file with mode: 0644]
server/mm_sound_mgr_pulse.c
server/mm_sound_mgr_session.c
server/mm_sound_plugin.c
server/mm_sound_server.c
server/plugin/keytone/Makefile.am
server/plugin/keytone/mm_sound_plugin_run_key_tone.c
server/plugin/ogg/Makefile.am
server/plugin/ogg/mm_sound_plugin_codec_ogg.c
server/plugin/tone/Makefile.am
server/plugin/tone/mm_sound_plugin_codec_tone.c
server/plugin/wav/Makefile.am
server/plugin/wav/mm_sound_plugin_codec_wave.c
testsuite/mm_sound_testsuite_simple.c [changed mode: 0644->0755]

index 20bf7bd..6f946c9 100644 (file)
@@ -10,14 +10,19 @@ includelibmmfsounddir = $(includedir)/mmf
 includelibmmfsound_HEADERS = include/mm_sound.h \
                                                        include/mm_sound_private.h \
                                                        include/mm_sound_pa_client.h \
-                                                       include/mm_sound_pcm_async.h
+                                                       include/mm_sound_pcm_async.h \
+                                                       include/mm_sound_focus.h
 
 libmmfsound_la_SOURCES = mm_sound.c \
                        mm_sound_client.c \
+                       mm_sound_client_dbus.c \
                        mm_sound_device.c \
                        mm_sound_pcm.c \
                        mm_sound_pa_client.c \
                        mm_sound_pcm_async.c
+if USE_FOCUS
+libmmfsound_la_SOURCES += mm_sound_focus.c
+endif
 
 libmmfsound_la_DEPENDENCIES = common/libmmfsoundcommon.la
 
@@ -26,6 +31,7 @@ libmmfsound_la_CFLAGS = -I$(srcdir)/include \
                        $(VCONF_CFLAGS) \
                        -I$(srcdir)/servertype/include \
                        $(GLIB2_CFLAGS) \
+                       $(GIO_CFLAGS) \
                        $(MMSESSION_CFLAGS) \
                        $(AUDIOSESSIONMGR_CFLAGS) \
                        -D_USE_INTERNAL_SOUND_PATH_ \
@@ -41,6 +47,7 @@ libmmfsound_la_LIBADD = $(MMCOMMON_LIBS) \
                        $(MMSESSION_LIBS) \
                        $(AUDIOSESSIONMGR_LIBS) \
                        $(GLIB2_LIBS) \
+                       $(GIO_LIBS) \
                        $(srcdir)/common/libmmfsoundcommon.la \
                        $(PASIMPLE_LIBS) \
                        $(PA_LIBS) \
index 2193ea5..c87ec74 100644 (file)
@@ -26,6 +26,7 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <errno.h>
+#include <glib.h>
 
 #include <vconf.h>
 #include <vconf-keys.h>
@@ -79,7 +80,7 @@ static char *g_volume_str[VOLUME_TYPE_MAX] = {
 };
 
 EXPORT_API
-int _mm_sound_get_valid_route_list(mm_sound_route **route_list)
+int mm_sound_util_get_valid_route_list(mm_sound_route **route_list)
 {
        *route_list = g_valid_route;
 
@@ -87,13 +88,13 @@ int _mm_sound_get_valid_route_list(mm_sound_route **route_list)
 }
 
 EXPORT_API
-bool _mm_sound_is_route_valid(mm_sound_route route)
+bool mm_sound_util_is_route_valid(mm_sound_route route)
 {
        mm_sound_route *route_list = 0;
        int route_index = 0;
        int route_list_count = 0;
 
-       route_list_count = _mm_sound_get_valid_route_list(&route_list);
+       route_list_count = mm_sound_util_get_valid_route_list(&route_list);
        for (route_index = 0; route_index < route_list_count; route_index++) {
                if (route_list[route_index] == route)
                        return 1;
@@ -103,7 +104,7 @@ bool _mm_sound_is_route_valid(mm_sound_route route)
 }
 
 EXPORT_API
-void _mm_sound_get_devices_from_route(mm_sound_route route, mm_sound_device_in *device_in, mm_sound_device_out *device_out)
+void mm_sound_util_get_devices_from_route(mm_sound_route route, mm_sound_device_in *device_in, mm_sound_device_out *device_out)
 {
        if (device_in && device_out) {
                *device_in = route & 0x00FF;
@@ -112,28 +113,7 @@ void _mm_sound_get_devices_from_route(mm_sound_route route, mm_sound_device_in *
 }
 
 EXPORT_API
-bool _mm_sound_check_hibernation (const char *path)
-{
-       int fd = -1;
-       if (path == NULL) {
-               debug_error ("Path is null\n");
-               return false;
-       }
-
-       fd = open (path, O_RDONLY | O_CREAT, 0644);
-       if (fd != -1) {
-               debug_log ("Open [%s] success!!\n", path);
-       } else {
-               debug_error ("Can't create [%s] with errno [%d]\n", path, errno);
-               return false;
-       }
-
-       close (fd);
-       return true;
-}
-
-EXPORT_API
-int _mm_sound_volume_add_callback(volume_type_t type, void *func, void* user_data)
+int mm_sound_util_volume_add_callback(volume_type_t type, void *func, void* user_data)
 {
        if (vconf_notify_key_changed(g_volume_vconf[type], func, user_data)) {
                debug_error ("vconf_notify_key_changed failed..\n");
@@ -144,7 +124,7 @@ int _mm_sound_volume_add_callback(volume_type_t type, void *func, void* user_dat
 }
 
 EXPORT_API
-int _mm_sound_volume_remove_callback(volume_type_t type, void *func)
+int mm_sound_util_volume_remove_callback(volume_type_t type, void *func)
 {
        if (vconf_ignore_key_changed(g_volume_vconf[type], func)) {
                debug_error ("vconf_ignore_key_changed failed..\n");
@@ -155,29 +135,7 @@ int _mm_sound_volume_remove_callback(volume_type_t type, void *func)
 }
 
 EXPORT_API
-int _mm_sound_muteall_add_callback(void *func)
-{
-       if (vconf_notify_key_changed(VCONF_KEY_MUTE_ALL, func, NULL)) {
-               debug_error ("vconf_notify_key_changed failed..\n");
-               return MM_ERROR_SOUND_INTERNAL;
-       }
-
-       return MM_ERROR_NONE;
-}
-
-EXPORT_API
-int _mm_sound_muteall_remove_callback(void *func)
-{
-       if (vconf_ignore_key_changed(VCONF_KEY_MUTE_ALL, func)) {
-               debug_error ("vconf_ignore_key_changed failed..\n");
-               return MM_ERROR_SOUND_INTERNAL;
-       }
-
-       return MM_ERROR_NONE;
-}
-
-EXPORT_API
-int _mm_sound_volume_get_value_by_type(volume_type_t type, unsigned int *value)
+int mm_sound_util_volume_get_value_by_type(volume_type_t type, unsigned int *value)
 {
        int ret = MM_ERROR_NONE;
        int vconf_value = 0;
@@ -196,7 +154,7 @@ int _mm_sound_volume_get_value_by_type(volume_type_t type, unsigned int *value)
 }
 
 EXPORT_API
-int _mm_sound_volume_set_value_by_type(volume_type_t type, unsigned int value)
+int mm_sound_util_volume_set_value_by_type(volume_type_t type, unsigned int value)
 {
        int ret = MM_ERROR_NONE;
        int vconf_value = 0;
@@ -216,94 +174,7 @@ int _mm_sound_volume_set_value_by_type(volume_type_t type, unsigned int value)
 }
 
 EXPORT_API
-int _mm_sound_volume_set_balance(float balance)
-{
-       /* Set balance value to VCONF */
-       if (vconf_set_dbl(VCONF_KEY_VOLUME_BALANCE, balance)) {
-               debug_error ("vconf_set_dbl(%s) failed..\n", VCONF_KEY_VOLUME_BALANCE);
-               return MM_ERROR_SOUND_INTERNAL;
-       }
-
-       return MM_ERROR_NONE;
-}
-
-EXPORT_API
-int _mm_sound_volume_get_balance(float *balance)
-{
-       double balance_value = 0;
-
-       /* Get balance value from VCONF */
-       if (vconf_get_dbl(VCONF_KEY_VOLUME_BALANCE, &balance_value)) {
-               debug_error ("vconf_get_int(%s) failed..\n", VCONF_KEY_VOLUME_BALANCE);
-               return MM_ERROR_SOUND_INTERNAL;
-       }
-
-       *balance = balance_value;
-       debug_log("balance get value [%s]=[%f]", VCONF_KEY_VOLUME_BALANCE, *balance);
-
-       return MM_ERROR_NONE;
-}
-
-EXPORT_API
-int _mm_sound_set_muteall(int muteall)
-{
-       /* Set muteall value to VCONF */
-       if (vconf_set_int(VCONF_KEY_MUTE_ALL, muteall)) {
-               debug_error ("vconf_set_int(%s) failed..\n", VCONF_KEY_MUTE_ALL);
-               return MM_ERROR_SOUND_INTERNAL;
-       }
-
-       return MM_ERROR_NONE;
-}
-
-EXPORT_API
-int _mm_sound_get_muteall(int *muteall)
-{
-       int muteall_value = 0;
-
-       /* Get muteall value from VCONF */
-       if (vconf_get_int(VCONF_KEY_MUTE_ALL, &muteall_value)) {
-               debug_error ("vconf_get_int(%s) failed..\n", VCONF_KEY_MUTE_ALL);
-               return MM_ERROR_SOUND_INTERNAL;
-       }
-
-       *muteall = muteall_value;
-       debug_log("muteall get value [%s]=[%d]", VCONF_KEY_MUTE_ALL, *muteall);
-
-       return MM_ERROR_NONE;
-}
-
-EXPORT_API
-int __mm_sound_set_stereo_to_mono(int ismono)
-{
-       /* Set ismono value to VCONF */
-       if (vconf_set_int(VCONF_KEY_MONO_AUDIO, ismono)) {
-               debug_error ("vconf_set_int(%s) failed..\n", VCONF_KEY_MONO_AUDIO);
-               return MM_ERROR_SOUND_INTERNAL;
-       }
-
-       return MM_ERROR_NONE;
-}
-
-EXPORT_API
-int __mm_sound_get_stereo_to_mono(int *ismono)
-{
-       int ismono_value = 0;
-
-       /* Get ismono value from VCONF */
-       if (vconf_get_int(VCONF_KEY_MONO_AUDIO, &ismono_value)) {
-               debug_error ("vconf_get_int(%s) failed..\n", VCONF_KEY_MONO_AUDIO);
-               return MM_ERROR_SOUND_INTERNAL;
-       }
-
-       *ismono = ismono_value;
-       debug_log("ismono get value [%s]=[%d]", VCONF_KEY_MONO_AUDIO, *ismono);
-
-       return MM_ERROR_NONE;
-}
-
-EXPORT_API
-int _mm_sound_get_earjack_type (int *type)
+int mm_sound_util_get_earjack_type (int *type)
 {
        int earjack_status = 0;
 
@@ -322,7 +193,7 @@ int _mm_sound_get_earjack_type (int *type)
 }
 
 EXPORT_API
-int _mm_sound_get_dock_type (int *type)
+int mm_sound_util_get_dock_type (int *type)
 {
        int dock_status = 0;
 
@@ -341,7 +212,7 @@ int _mm_sound_get_dock_type (int *type)
 }
 
 EXPORT_API
-bool _mm_sound_is_recording (void)
+bool mm_sound_util_is_recording (void)
 {
        int capture_status = 0;
        bool result = false;
@@ -351,7 +222,7 @@ bool _mm_sound_is_recording (void)
 }
 
 EXPORT_API
-bool _mm_sound_is_mute_policy (void)
+bool mm_sound_util_is_mute_policy (void)
 {
        int setting_sound_status = true;
 
@@ -361,3 +232,32 @@ bool _mm_sound_is_mute_policy (void)
 
        return !setting_sound_status;
 }
+
+EXPORT_API
+bool mm_sound_util_is_process_alive(pid_t pid)
+{
+       gchar *tmp = NULL;
+       int ret = -1;
+
+       if (pid > 999999 || pid < 2)
+               return false;
+
+       if ((tmp = g_strdup_printf("/proc/%d", pid))) {
+               ret = access(tmp, F_OK);
+               g_free(tmp);
+       }
+
+       if (ret == -1) {
+               if (errno == ENOENT) {
+                       debug_warning ("/proc/%d not exist", pid);
+                       return false;
+               } else {
+                       debug_error ("/proc/%d access errno[%d]", pid, errno);
+
+                       /* FIXME: error occured but file exists */
+                       return true;
+               }
+       }
+
+       return true;
+}
index f497df0..06b99ee 100644 (file)
@@ -58,35 +58,6 @@ PKG_CHECK_MODULES(VCONF, vconf)
 AC_SUBST(VCONF_CFLAGS)
 AC_SUBST(VCONF_LIBS)
 
-AC_ARG_ENABLE(bluetooth, AC_HELP_STRING([--enable-bluetooth], [enable bluetooth client]),
-[
- case "${enableval}" in
-        yes) SUPPORT_BT_SCO=yes ;;
-        no)  SUPPORT_BT_SCO=no ;;
-        *)   AC_MSG_ERROR(bad value ${enableval} for --enable-bluetooth) ;;
- esac
- ],[SUPPORT_BT_SCO=no])
-if test "x$SUPPORT_BT_SCO" = "xyes"; then
-PKG_CHECK_MODULES(BLUETOOTH, capi-network-bluetooth)
-AC_SUBST(BLUETOOTH_CFLAGS)
-AC_SUBST(BLUETOOTH_LIBS)
-fi
-AM_CONDITIONAL([SUPPORT_BT_SCO], [test "x$SUPPORT_BT_SCO" = "xyes"])
-
-AC_ARG_ENABLE(hfp, AC_HELP_STRING([--enable-hfp], [enable hfp api]),
-[
- case "${enableval}" in
-        yes) USE_HFP=yes ;;
-        no)  USE_HFP=no ;;
-        *)   AC_MSG_ERROR(bad value ${enableval} for --enable-hfp) ;;
- esac
- ],[USE_HFP=no])
-if test "x$USE_HFP" = "xyes"; then
-PKG_CHECK_MODULES(BLUETOOTH_API, bluetooth-api)
-AC_SUBST(BLUETOOTH_API_CFLAGS)
-AC_SUBST(BLUETOOTH_API_LIBS)
-fi
-
 AC_ARG_ENABLE(pulse, AC_HELP_STRING([--enable-pulse], [enable pulseaudio client]),
 [
  case "${enableval}" in
@@ -120,6 +91,35 @@ AC_SUBST(TREMOLO_LIBS)
 fi
 AM_CONDITIONAL([OGG_SUPPORT], [test "x$OGG_SUPPORT" = "xyes"])
 
+dnl use security ---------------------------------------------------------------
+AC_ARG_ENABLE(security, AC_HELP_STRING([--enable-security], [using security]),
+[
+    case "${enableval}" in
+    yes) USE_SECURITY=yes ;;
+    no)  USE_SECURITY=no ;;
+    *)   AC_MSG_ERROR(bad value ${enableval} for --enable-security) ;;
+    esac
+],[USE_SECURITY=no])
+
+if test "x$USE_SECURITY" = "xyes"; then
+    PKG_CHECK_MODULES(SECURITY, security-server)
+    AC_SUBST(SECURITY_CFLAGS)
+    AC_SUBST(SECURITY_LIBS)
+fi
+AM_CONDITIONAL(USE_SECURITY, test "x$USE_SECURITY" = "xyes")
+dnl end ------------------------------------------------------------------------
+
+
+AC_ARG_ENABLE(focus, AC_HELP_STRING([--enable-focus], [enable focus feature]),
+[
+ case "${enableval}" in
+        yes) USE_FOCUS=yes ;;
+        no)  USE_FOCUS=no ;;
+        *)   AC_MSG_ERROR(bad value ${enableval} for --enable-focus) ;;
+ esac
+ ],[USE_FOCUS=no])
+AM_CONDITIONAL([USE_FOCUS], [test "x$USE_FOCUS" = "xyes"])
+
 # Checks for header files.
 AC_HEADER_STDC
 AC_CHECK_HEADERS([fcntl.h memory.h stdlib.h string.h sys/time.h unistd.h errno.h sys/types.h sys/stat.h])
index 2aaf5e8..243b60f 100644 (file)
@@ -27,6 +27,9 @@
 
 #include "mm_sound.h"
 #include "mm_sound_device.h"
+#ifdef USE_FOCUS
+#include "mm_sound_stream.h"
+#endif
 
 
 #define FILE_PATH 512
@@ -68,6 +71,13 @@ typedef struct
        int is_available;
        int route_list[MM_SOUND_ROUTE_NUM];
 
+#ifdef USE_FOCUS
+       /* Focus */
+       int handle_id;
+       int focus_type;
+       int changed_state;
+       char stream_type[MAX_STREAM_TYPE_LEN];
+#endif
        /* Volume */
        int type;
        int val;
@@ -94,6 +104,7 @@ typedef struct
 {
        long msg_type;
        mmsound_ipc_t sound_msg;
+       bool wait_for_reply;
 } mm_ipc_msg_t;
 
 typedef void (*mm_ipc_callback_t)(int code, int size);
index fdd7969..dcae36d 100644 (file)
        </table></div>
 
  */
+#define MM_SOUND_STREAM_TYPE_LEN 64
 
 /*
  * MMSound Volume APIs
@@ -293,7 +294,7 @@ typedef enum {
        VOLUME_TYPE_VOICE,                              /**< VOICE volume type */
        VOLUME_TYPE_FIXED,                              /**< Volume type for fixed acoustic level */
        VOLUME_TYPE_MAX,                                /**< Volume type count */
-       VOLUME_TYPE_EXT_ANDROID = VOLUME_TYPE_FIXED,            /**< External system volume for Android */
+       VOLUME_TYPE_UNKNOWN = -1,       /**< volume type is not determined */
 } volume_type_t;
 
 typedef enum {
@@ -352,17 +353,6 @@ typedef void (*mm_sound_volume_changed_cb) (volume_type_t type, unsigned int vol
 
 
 /**
- * Muteall state change callback function type.
- *
- * @param      user_data               [in]    Argument passed when callback has called
- *
- * @return     No return value
- * @remark     None.
- * @see                mm_sound_muteall_add_callback mm_sound_muteall_remove_callback
- */
-typedef void (*muteall_callback_fn)(void* user_data);
-
-/**
  * This function is to retrieve number of volume level.
  *
  * @param      type                    [in]    volume type to query
@@ -506,86 +496,6 @@ int mm_sound_volume_remove_callback(volume_type_t type);
 int mm_sound_remove_volume_changed_callback(void);
 
 /**
- * This function is to add muteall changed callback.
- *
- * @param      func                    [in]    callback function pointer
- * @param      user_data               [in]    user data passing to callback function
- *
- * @return     This function returns MM_ERROR_NONE on success, or negative value
- *                     with error code.
- * @see                muteall_callback_fn
- * @code
-void _muteall_callback(void *data)
-{
-       int  muteall;
-
-       mm_sound_get_muteall(&muteall);
-       g_print("Muteall Callback Runs :::: muteall value = %d\n", muteall);
-}
-
-int muteall_callback()
-{
-       int ret = 0;
-
-       ret = mm_sound_muteall_add_callback( _muteall_callback);
-
-       if ( MM_ERROR_NONE != ret)
-       {
-               printf("Can not add callback\n");
-       }
-       else
-       {
-               printf("Add callback success\n");
-       }
-
-       return 0;
-}
-
- * @endcode
- */
-int mm_sound_muteall_add_callback(muteall_callback_fn func);
-
-
-/**
- * This function is to remove muteall changed callback.
- *
- * @param      func                    [in]    callback function pointer
- *
- * @return     This function returns MM_ERROR_NONE on success, or negative value
- *                     with error code.
- * @remark     None.
- * @post       Callback function will not be called anymore.
- * @see                muteall_callback_fn
- * @code
-void _muteall_callback(void *data)
-{
-       printf("Callback function\n");
-}
-
-int muteall_callback()
-{
-       int ret = 0;
-
-       mm_sound_muteall_add_callback( _muteall_callback);
-
-       ret = mm_sound_muteall_remove_callback(_muteall_callback);
-       if ( MM_ERROR_NONE == ret)
-       {
-               printf("Remove callback success\n");
-       }
-       else
-       {
-               printf("Remove callback failed\n");
-       }
-
-       return ret;
-}
-
- * @endcode
- */
-int mm_sound_muteall_remove_callback(muteall_callback_fn func);
-
-/**
  * This function is to set volume level of certain volume type.
  *
  * @param      type                    [in]    volume type to set value.
@@ -620,26 +530,7 @@ else
 }
  * @endcode
  */
-int mm_sound_volume_set_value(volume_type_t type, const unsigned int value);
-
-
-
-
-
-
-/**
- * This function is to set all volume type to mute or unmute.
- *
- * @param      muteall                 [in]    the switch to control  mute or unmute.
- *
- * @return     This function returns MM_ERROR_NONE on success, or negative value
- *                     with error code.
- * @remark     None.
- * @pre                None.
- * @post       None.
- */
-int mm_sound_mute_all(int muteall);
-
+int mm_sound_volume_set_value(volume_type_t type, const unsigned int volume_level);
 
 
 /**
@@ -705,7 +596,7 @@ static int _pause(void* data)
 {
        int ret = 0;
 
-       ret = mm_sound_volume_primary_type_clear();
+       ret = mm_sound_volume_primary_type_set(VOLUME_TYPE_UNKNOWN);
        if(ret < 0)
        {
                printf("Can not clear primary volume type\n");
@@ -729,123 +620,12 @@ int main()
  * @endcode
  */
 int mm_sound_volume_primary_type_set(volume_type_t type);
-
-
-
-/**
- * This function is to clear primary volume type.
- *
- *
- * @return     This function returns MM_ERROR_NONE on success, or negative value
- *                     with error code.
- * @remark     mm_sound_volume_primary_type_set() and mm_sound_volume_primary_type_clear() should be used as pair
- * @see                mm_sound_volume_primary_type_set
- * @pre                primary volume should be set at same process.
- * @post       primary volume will be cleared.
- * @par Example
- * @code
-static int _resume(void *data)
-{
-       int ret = 0;
-
-       ret = mm_sound_volume_primary_type_set(VOLUME_TYPE_MEDIA);
-       if(ret < 0)
-       {
-               printf("Can not set primary volume type\n");
-       }
-       ...
-}
-
-static int _pause(void* data)
-{
-       int ret = 0;
-
-       ret = mm_sound_volume_primary_type_clear();
-       if(ret < 0)
-       {
-               printf("Can not clear primary volume type\n");
-       }
-       ...
-}
-
-int main()
-{
-       ...
-       struct appcore_ops ops = {
-               .create = _create,
-               .terminate = _terminate,
-               .pause = _pause,
-               .resume = _resume,
-               .reset = _reset,
-       };
-       ...
-       return appcore_efl_main(PACKAGE, ..., &ops);
-}
- * @endcode
- */
+int mm_sound_volume_primary_type_get(volume_type_t *type);
 int mm_sound_volume_primary_type_clear(void);
 
-
-
-/**
- * This function is to get current playing volume type
- *
- * @param      type                    [out]   current playing volume type
- *
- * @return     This function returns MM_ERROR_NONE on success,
- *          or MM_ERROR_SOUND_VOLUME_NO_INSTANCE when there is no existing playing instance,
- *          or MM_ERROR_SOUND_VOLUME_CAPTURE_ONLY when only capture audio instances are exist.
- *          or negative value with error code for other errors.
- * @remark     None.
- * @pre                None.
- * @post       None.
- * @see                mm_sound_volume_get_value, mm_sound_volume_set_value
- * @par Example
- * @code
-int ret=0;
-volume_type_t type = 0;
-
-ret = mm_sound_volume_get_current_playing_type(&type);
-switch(ret)
-{
-case MM_ERROR_NONE:
-       printf("Current playing is %d\n", type);
-       break;
-case MM_ERROR_SOUND_VOLUME_NO_INSTANCE:
-       printf("No sound instance\n");
-       break;
-case MM_ERROR_SOUND_VOLUME_CAPTURE_ONLY:
-       printf("Only sound capture instances are exist\n");
-       break;
-default:
-       printf("Error\n");
-       break;
-}
-
- * @endcode
- */
-int mm_sound_volume_get_current_playing_type(volume_type_t *type);
-
-int mm_sound_volume_set_balance (float balance);
-
-int mm_sound_volume_get_balance (float *balance);
-
-int mm_sound_set_muteall (int muteall);
-
-int mm_sound_get_muteall (int *muteall);
-
-int mm_sound_set_stereo_to_mono (int ismono);
-
-int mm_sound_get_stereo_to_mono (int *ismono);
-
 int mm_sound_set_call_mute(volume_type_t type, int mute);
-
 int mm_sound_get_call_mute(volume_type_t type, int *mute);
 
-int mm_sound_set_factory_loopback_test(int loopback);
-
-int mm_sound_get_factory_loopback_test(int *loopback);
-
 typedef enum {
        MM_SOUND_FACTORY_MIC_TEST_STATUS_OFF = 0,
        MM_SOUND_FACTORY_MIC_TEST_STATUS_MAIN_MIC,
@@ -1961,165 +1741,11 @@ else
  */
 int mm_sound_play_tone (MMSoundTone_t num, int volume_config, const double volume, const int duration, int *handle);
 
+int mm_sound_play_tone_with_stream_info(MMSoundTone_t tone, char *stream_type, int stream_id, const double volume, const int duration, int *handle);
+
 /*
  * Enumerations of System audio route policy
  */
-typedef enum {
-       SYSTEM_AUDIO_ROUTE_POLICY_DEFAULT,                      /**< Play via a2dp headset if connected. or play via headset if connected. or play via speaker.
-                                                                                                       And capture via 4pole headset-mic if connected. or capture via mic */
-       SYSTEM_AUDIO_ROUTE_POLICY_IGNORE_A2DP,          /**< Play via headset if connected. or play via speaker
-                                                                                                        And capture via 4pole headset-mic if connected. or capture via mic */
-       SYSTEM_AUDIO_ROUTE_POLICY_HANDSET_ONLY,         /**< Play via speaker. and capture via mic  */
-       SYSTEM_AUDIO_ROUTE_POLICY_MAX
-}system_audio_route_t;
-
-typedef enum {
-       SYSTEM_AUDIO_ROUTE_PLAYBACK_DEVICE_NONE,                        /**< Abnormal case */
-       SYSTEM_AUDIO_ROUTE_PLAYBACK_DEVICE_HANDSET,             /**< Speaker or Headset or Earpiece */
-       SYSTEM_AUDIO_ROUTE_PLAYBACK_DEVICE_BLUETOOTH,   /**< Bluetooth */
-       SYSTEM_AUDIO_ROUTE_PLAYBACK_DEVICE_EARPHONE,    /**< Earphone */
-       SYSTEM_AUDIO_ROUTE_PLAYBACK_DEVICE_MAX,
-}system_audio_route_device_t;
-
-typedef enum {
-       SYSTEM_AUDIO_CAPTURE_NONE,      /**< Capture device is not in use */
-       SYSTEM_AUDIO_CAPTURE_ACTIVE,    /**< Capture device is in use */
-       SYSTEM_AUDIO_CAPTURE_MAX,
-}system_audio_capture_status_t;
-
-
-/**
- * This function set system route policy.
- *
- * @param      route           [in] audio route type
- *
- * @return     This function returns MM_ERROR_NONE on success, or negative value
- *                     with error code.
- * @remark     If bluetooth has disconnected during SYSTEM_AUDIO_ROUTE_POLICY_IGNORE_A2DP policy,
- *                     The audio route policy will be changed to SYSTEM_AUDIO_ROUTE_POLICY_DEFAULT.
- * @see                mm_sound_route_get_system_policy system_audio_route_t mm_sound_route_is_a2dp_on
- * @pre                None.
- * @post       Audio routing policy will be changed with given type. And route change callback function will be called if registered.
- * @par Example
- * @code
-int g_stop = 0;
-void _stop_callback()
-{
-       g_stop = 1;
-}
-
-int play_file_via_speaker()
-{
-       int ret = 0;
-       system_audio_route_t route, original_route;
-
-       //get backup current policy
-       ret = mm_sound_route_get_system_policy(&original_route);
-       if(ret < 0)
-       {
-               printf("Can not get system audio route policy\n");
-       }
-       else
-       {
-               //set route policy to ignore a2dp
-               route = SYSTEM_AUDIO_ROUTE_POLICY_IGNORE_A2DP;
-               ret = mm_sound_route_set_system_policy(route);
-               if(ret < 0)
-               {
-                       printf("Ca not set route policy\n");
-               }
-               else
-               {
-                       int handle;
-                       //play wav file
-                       ret = mm_sound_play_sound("/opt/media/Sound/alert.wav", VOLUME_TYPE_SYSTEM, NULL, NULL, &handle);
-                       if(ret < 0)
-                       {
-                               printf("Can not play wav file\n");
-                       }
-                       else
-                       {
-                               while(g_stop == 0)
-                               {
-                                       sleep(1);
-                               }
-                               //restore original policy
-                               mm_sound_route_set_system_policy(original_route);
-                       }
-               }
-       }
-       return 0;
-}
- * @endcode
- */
-int mm_sound_route_set_system_policy (system_audio_route_t route);
-
-/**
- * This function get sysytem route policy.
- *
- * @param      route           [out] audio route type
- *
- * @return     This function returns MM_ERROR_NONE on success, or negative value
- *                     with error code.
- * @remark     None.
- * @see                mm_sound_route_set_system_policy system_audio_route_t mm_sound_route_is_a2dp_on
- * @pre                None.
- * @post       None.
- * @par Example
- * @code
-int g_stop = 0;
-void _stop_callback()
-{
-       g_stop = 1;
-}
-
-int play_file_via_speaker()
-{
-       int ret = 0;
-       system_audio_route_t route, original_route;
-
-       //get backup current policy
-       ret = mm_sound_route_get_system_policy(&original_route);
-       if(ret < 0)
-       {
-               printf("Can not get system audio route policy\n");
-       }
-       else
-       {
-               //set route policy to ignore a2dp
-               route = SYSTEM_AUDIO_ROUTE_POLICY_IGNORE_A2DP;
-               ret = mm_sound_route_set_system_policy(route);
-               if(ret < 0)
-               {
-                       printf("Can not set route policy\n");
-               }
-               else
-               {
-                       int handle;
-                       //play wav file
-                       ret = mm_sound_play_sound("/opt/media/Sound/alert.wav", VOLUME_TYPE_SYSTEM, NULL, NULL, &handle);
-                       if(ret < 0)
-                       {
-                               printf("Can not play wav file\n");
-                       }
-                       else
-                       {
-                               while(g_stop == 0)
-                               {
-                                       sleep(1);
-                               }
-                               //restore original policy
-                               mm_sound_route_set_system_policy(original_route);
-                       }
-               }
-       }
-       return 0;
-}
- * @endcode
- */
-int mm_sound_route_get_system_policy (system_audio_route_t *route);
-
-
 
 /**
  * This function get a2dp activation information.
@@ -2155,155 +1781,6 @@ if (ret == MM_ERROR_NONE) {
 int mm_sound_route_get_a2dp_status (bool* connected, char** bt_name);
 
 
-/**
- * This function get current playing device.
- *
- * @param      dev             [out] current playing device information
- *
- * @return     This function returns MM_ERROR_NONE on success, or negative value
- *                     with error code.
- * @remark     if there is no running instance in system,
- *                     output parameter dev can be SYSTEM_AUDIO_ROUTE_PLAYING_DEVICE_NONE.
- *
- * @see                system_audio_route_device_t
- * @pre                None.
- * @post       None.
- * @par Example
- * @code
-int ret = 0;
-system_audio_route_device_t dev;
-
-ret = mm_sound_route_get_playing_device (&dev);
-if(ret == MM_ERROR_NONE)
-{
-       switch(dev)
-       {
-       case SYSTEM_AUDIO_ROUTE_PLAYBACK_DEVICE_HANDSET:
-               printf("Handset is playing\n");
-               break;
-       case SYSTEM_AUDIO_ROUTE_PLAYBACK_DEVICE_BLUETOOTH:
-               printf("Bluetooth is playing\n");
-               break;
-       case SYSTEM_AUDIO_ROUTE_PLAYBACK_DEVICE_NONE:
-       default:
-               printf("Unexptected\n");
-               break;
-       }
-}
-else
-{
-       printf ("Can not get current running device\n");
-}
-
- * @endcode
- */
-int mm_sound_route_get_playing_device(system_audio_route_device_t *dev);
-
-/**
- * Audio route policy change callback function type.
- *
- * @param      user_data               [in]    Argument passed when callback has called
- * @param      policy                  [in]    changed policy type
- *
- * @return     No return value
- * @remark
- * @see                mm_sound_volume_add_callback mm_sound_volume_remove_callback
- */
-typedef void (*audio_route_policy_changed_callback_fn)(void* user_data, system_audio_route_t policy);
-
-/**
- * This function set system audio policy changed callback function.
- *
- * @param      func            [in] callback function pointer
- * @param      user_data       [in] user data will be called with func
- *
- * @return     This function returns MM_ERROR_NONE on success, or negative value
- *                     with error code.
- * @remark     None.
- * @see                mm_sound_route_remove_change_callback mm_sound_route_set_system_policy mm_sound_route_get_system_policy system_audio_route_t
- * @pre                None.
- * @post       None.
- * @par Example
- * @code
-void audio_route_policy_changed_callback(void* data, system_audio_route_t policy)
-{
-       int value = (int) data;
-       system_audio_route_t lv_policy;
-       char *str_route[SYSTEM_AUDIO_ROUTE_POLICY_MAX] = {
-                       "DEFAULT","IGN_A2DP","HANDSET"
-               };
-       printf("Audio Route Policy has changed to [%s]\n", str_route[policy]);
-       printf("user data : %d\n", value);
-       if(0 > mm_sound_route_get_system_policy(&lv_policy)) {
-               printf("Can not get policy...in callback function\n");
-       }
-       else {
-               printf("readed policy [%s]\n", str_route[lv_policy]);
-       }
-}
-int make_callback()
-{
-       int ret = 0;
-       ret = mm_sound_route_add_change_callback(audio_route_policy_changed_callback, (void*)111);
-       if(ret < 0)
-       {
-               printf("Can not add callback\n");
-       }
-       return 0;
-}
- * @endcode
- */
-int mm_sound_route_add_change_callback(audio_route_policy_changed_callback_fn func, void* user_data);
-
-/**
- * This function remove system audio policy changed callback function.
- *
- * @return     This function returns MM_ERROR_NONE on success, or negative value
- *                     with error code.
- * @remark     None.
- * @see                mm_sound_route_add_change_callback mm_sound_route_set_system_policy mm_sound_route_get_system_policy system_audio_route_t
- * @pre                Sound route change callback should be registered.
- * @post       Sound route change callback deregistered and does not be called anymore.
- * @par Example
- * @code
-void audio_route_policy_changed_callback(void* data, system_audio_route_t policy)
-{
-       int value = (int) data;
-       system_audio_route_t lv_policy;
-       char *str_route[SYSTEM_AUDIO_ROUTE_POLICY_MAX] = {
-                       "DEFAULT","IGN_A2DP","HANDSET"
-               };
-       printf("Audio Route Policy has changed to [%s]\n", str_route[policy]);
-       printf("user data : %d\n", value);
-       if(0 > mm_sound_route_get_system_policy(&lv_policy)) {
-               printf("Can not get policy...in callback function\n");
-       }
-       else {
-               printf("readed policy [%s]\n", str_route[lv_policy]);
-       }
-}
-int make_callback()
-{
-       int ret = 0;
-       ret = mm_sound_route_add_change_callback(audio_route_policy_changed_callback, (void*)111);
-       if(ret < 0)
-       {
-               printf("Can not add callback\n");
-       }
-       else
-       {
-               ret = mm_sound_route_remove_change_callback();
-               if(ret < 0)
-               {
-                       printf("Can not remove callback\n");
-               }
-       }
-       return 0;
-}
- * @endcode
- */
-int mm_sound_route_remove_change_callback(void);
-
 /*
  * Enumerations of device & route
  */
@@ -2387,9 +1864,9 @@ typedef enum {
 } mm_sound_device_flags_e;
 
 typedef enum {
-       MM_SOUND_DEVICE_IO_DIRECTION_IN,
-       MM_SOUND_DEVICE_IO_DIRECTION_OUT,
-       MM_SOUND_DEVICE_IO_DIRECTION_BOTH,
+       MM_SOUND_DEVICE_IO_DIRECTION_IN           = 0x1,
+       MM_SOUND_DEVICE_IO_DIRECTION_OUT          = 0x2,
+       MM_SOUND_DEVICE_IO_DIRECTION_BOTH         = MM_SOUND_DEVICE_IO_DIRECTION_IN | MM_SOUND_DEVICE_IO_DIRECTION_OUT,
 } mm_sound_device_io_direction_e;
 
 typedef enum {
@@ -2679,6 +2156,26 @@ int mm_sound_set_sound_path_for_active_device(mm_sound_device_out device_out, mm
 
 int mm_sound_get_audio_path(mm_sound_device_in *device_in, mm_sound_device_out *device_out);
 
+
+
+typedef void (*mm_sound_test_cb) (int a, void *user_data);
+int mm_sound_test(int a, int b, int* get);
+int mm_sound_add_test_callback(mm_sound_test_cb func, void *user_data);
+int mm_sound_remove_test_callback(void);
+
+void mm_sound_convert_volume_type_to_stream_type(int volume_type, char *stream_type);
+
+typedef enum {
+       MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS,
+       MM_SOUND_SIGNAL_MAX,
+} mm_sound_signal_name_t;
+
+typedef void (* mm_sound_signal_callback) (mm_sound_signal_name_t signal, int value, void *user_data);
+int mm_sound_subscribe_signal(mm_sound_signal_name_t signal, unsigned int *subscribe_id, mm_sound_signal_callback callback, void *user_data);
+void mm_sound_unsubscribe_signal(unsigned int subscribe_id);
+int mm_sound_send_signal(mm_sound_signal_name_t signal, int value);
+int mm_sound_get_signal_value(mm_sound_signal_name_t signal, int *value);
+
 /**
        @}
  */
index a6a112b..584610f 100644 (file)
 
 #include "mm_sound_private.h"
 #include "mm_sound_device.h"
+#ifdef USE_FOCUS
+#include "mm_sound_focus.h"
+#endif
 
 //#define MEMTYPE_TRANS_PER_MAX (1024 * 1024) /* 1MB */
 
-int MMSoundClientInit(void);
-int MMSoundClientCallbackFini(void);
-int MMSoundClientPlayTone(int number, int volume_config, double volume, int time, int *handle, bool enable_session);
-int MMSoundClientPlaySound(MMSoundPlayParam *param, int tone, int keytone, int *handle);
-int MMSoundClientStopSound(int handle);
-int _mm_sound_client_is_route_available(mm_sound_route route, bool *is_available);
-int _mm_sound_client_foreach_available_route_cb(mm_sound_available_route_cb, void *user_data);
-int _mm_sound_client_set_active_route(mm_sound_route route, bool need_broadcast);
-int _mm_sound_client_get_active_device(mm_sound_device_in *device_in, mm_sound_device_out *device_out);
-int _mm_sound_client_add_active_device_changed_callback(const char *name, mm_sound_active_device_changed_cb func, void* user_data);
-int _mm_sound_client_remove_active_device_changed_callback(const char *name);
-int _mm_sound_client_add_available_route_changed_callback(mm_sound_available_route_changed_cb func, void* user_data);
-int _mm_sound_client_remove_available_route_changed_callback(void);
-int _mm_sound_client_add_volume_changed_callback(mm_sound_volume_changed_cb func, void* user_data);
-int _mm_sound_client_remove_volume_changed_callback(void);
-int _mm_sound_client_set_sound_path_for_active_device(mm_sound_device_out device_out, mm_sound_device_in device_in);
-int _mm_sound_client_get_current_connected_device_list(int device_flgas, mm_sound_device_list_t **device_list);
-int _mm_sound_client_add_device_connected_callback(int device_flags, mm_sound_device_connected_cb func, void* user_data);
-int _mm_sound_client_remove_device_connected_callback(void);
-int _mm_sound_client_add_device_info_changed_callback(int device_flags, mm_sound_device_info_changed_cb func, void* user_data);
-int _mm_sound_client_remove_device_info_changed_callback(void);
-
-#ifdef PULSE_CLIENT
-int MMSoundClientIsBtA2dpOn (bool *connected, char** bt_name);
+int mm_sound_client_initialize(void);
+int mm_sound_client_finalize(void);
+int mm_sound_client_play_tone(int number, int volume_config, double volume, int time, int *handle, bool enable_session);
+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_play_sound(MMSoundPlayParam *param, int tone, int keytone, int *handle);
+int mm_sound_client_play_sound_with_stream_info(MMSoundPlayParam *param, int *handle, char* stream_type, int stream_id);
+int mm_sound_client_stop_sound(int handle);
+int mm_sound_client_is_route_available(mm_sound_route route, bool *is_available);
+int mm_sound_client_foreach_available_route_cb(mm_sound_available_route_cb, void *user_data);
+int mm_sound_client_set_active_route(mm_sound_route route, bool need_broadcast);
+int mm_sound_client_get_active_device(mm_sound_device_in *device_in, mm_sound_device_out *device_out);
+int mm_sound_client_add_active_device_changed_callback(const char *name, mm_sound_active_device_changed_cb func, void* user_data);
+int mm_sound_client_remove_active_device_changed_callback(const char *name);
+int mm_sound_client_add_available_route_changed_callback(mm_sound_available_route_changed_cb func, void* user_data);
+int mm_sound_client_remove_available_route_changed_callback(void);
+int mm_sound_client_set_volume_by_type(const int volume_type, const unsigned int volume_level);
+int mm_sound_client_add_volume_changed_callback(mm_sound_volume_changed_cb func, void* user_data);
+int mm_sound_client_remove_volume_changed_callback(void);
+int mm_sound_client_set_sound_path_for_active_device(mm_sound_device_out device_out, mm_sound_device_in device_in);
+int mm_sound_client_get_current_connected_device_list(int device_flgas, mm_sound_device_list_t **device_list);
+int mm_sound_client_add_device_connected_callback(int device_flags, mm_sound_device_connected_cb func, void* user_data);
+int mm_sound_client_remove_device_connected_callback(void);
+int mm_sound_client_add_device_info_changed_callback(int device_flags, mm_sound_device_info_changed_cb func, void* user_data);
+int mm_sound_client_remove_device_info_changed_callback(void);
+#ifdef USE_FOCUS
+int mm_sound_client_get_uniq_id(int *id);
+int mm_sound_client_register_focus(int id, const char *stream_type, mm_sound_focus_changed_cb callback, void* user_data);
+int mm_sound_client_unregister_focus(int id);
+int mm_sound_client_acquire_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, const char *option);
+int mm_sound_client_set_focus_watch_callback(mm_sound_focus_type_e type, mm_sound_focus_changed_watch_cb callback, void* user_data, int *id);
+int mm_sound_client_unset_focus_watch_callback(int id);
 #endif
-int _mm_sound_client_set_active_route_auto(void);
-int _mm_sound_client_get_audio_path(mm_sound_device_in *device_in, mm_sound_device_out *device_out);
+
+int mm_sound_client_is_bt_a2dp_on (bool *connected, char** bt_name);
+int mm_sound_client_set_active_route_auto(void);
+int mm_sound_client_get_audio_path(mm_sound_device_in *device_in, mm_sound_device_out *device_out);
+
+int mm_sound_client_add_test_callback(mm_sound_test_cb func, void* user_data);
+int mm_sound_client_remove_test_callback(void);
+int mm_sound_client_test(int a, int b, int* get);
 
 #endif /* __MM_SOUND_CLIENT_H__ */
diff --git a/include/mm_sound_client_dbus.h b/include/mm_sound_client_dbus.h
new file mode 100644 (file)
index 0000000..933fae5
--- /dev/null
@@ -0,0 +1,58 @@
+
+
+#ifndef __MM_SOUND_CLIENT_DBUS_H__
+#define __MM_SOUND_CLIENT_DBUS_H__
+
+#include "mm_sound_private.h"
+#include "mm_sound_device.h"
+#ifdef USE_FOCUS
+#include "mm_sound_focus.h"
+#endif
+
+int mm_sound_client_dbus_play_tone(int tone, int repeat, int volume, int volume_config,
+                          int session_type, int session_options, int client_pid,
+                          bool enable_session, int *codechandle, char *stream_type, int stream_index);
+int mm_sound_client_dbus_play_tone_with_stream_info(int client_pid, int tone, char *stream_type, int stream_id, int volume, int repeat, int *codechandle);
+int mm_sound_client_dbus_play_sound(char* filename, int tone, int repeat, int volume, int volume_config,
+                          int priority, int session_type, int session_options, int client_pid, int keytone,  int handle_route,
+                          bool enable_session, int *codechandle, char *stream_type, int stream_index);
+int mm_sound_client_dbus_stop_sound(int handle);
+int mm_sound_client_dbus_is_route_available(mm_sound_route route, bool *is_available);
+int mm_sound_client_dbus_foreach_available_route_cb(mm_sound_available_route_cb, void *user_data);
+int mm_sound_client_dbus_set_active_route(mm_sound_route route, bool need_broadcast);
+int mm_sound_client_dbus_get_active_device(mm_sound_device_in *device_in, mm_sound_device_out *device_out);
+int mm_sound_client_dbus_add_active_device_changed_callback(const char *name, mm_sound_active_device_changed_cb func, void* user_data);
+int mm_sound_client_dbus_remove_active_device_changed_callback(const char *name);
+int mm_sound_client_dbus_add_available_route_changed_callback(mm_sound_available_route_changed_cb func, void* user_data);
+int mm_sound_client_dbus_remove_available_route_changed_callback(void);
+int mm_sound_client_dbus_set_sound_path_for_active_device(mm_sound_device_out device_out, mm_sound_device_in device_in);
+int mm_sound_client_dbus_set_active_route_auto(void);
+int mm_sound_client_dbus_add_play_sound_end_callback(int handle, mm_sound_stop_callback_func stop_cb, void* userdata);
+int mm_sound_client_dbus_get_current_connected_device_list(int device_flags, GList** device_list);
+int mm_sound_client_dbus_add_device_connected_callback(int device_flags, mm_sound_device_connected_cb func, void* user_data);
+int mm_sound_client_dbus_remove_device_connected_callback(void);
+int mm_sound_client_dbus_add_device_info_changed_callback(int device_flags, mm_sound_device_info_changed_cb func, void* user_data);
+int mm_sound_client_dbus_remove_device_info_changed_callback(void);
+int mm_sound_client_dbus_is_bt_a2dp_on (bool *connected, char** bt_name);
+int mm_sound_client_dbus_set_volume_by_type(const int volume_type, const unsigned int volume_level);
+int mm_sound_client_dbus_add_volume_changed_callback(mm_sound_volume_changed_cb func, void* user_data);
+int mm_sound_client_dbus_remove_volume_changed_callback(void);
+int mm_sound_client_dbus_get_audio_path(mm_sound_device_in *device_in, mm_sound_device_out *device_out);
+
+#ifdef USE_FOCUS
+int mm_sound_client_dbus_register_focus(int id, const char *stream_type, mm_sound_focus_changed_cb callback, void* user_data);
+int mm_sound_client_dbus_unregister_focus(int id);
+int mm_sound_client_dbus_acquire_focus(int id, mm_sound_focus_type_e type, const char *option);
+int mm_sound_client_dbus_release_focus(int id, mm_sound_focus_type_e type, const char *option);
+int mm_sound_client_dbus_set_focus_watch_callback(mm_sound_focus_type_e type, mm_sound_focus_changed_watch_cb callback, void* user_data, int *id);
+int mm_sound_client_dbus_unset_focus_watch_callback(int id);
+#endif
+
+int mm_sound_client_dbus_add_test_callback(mm_sound_test_cb func, void* user_data);
+int mm_sound_client_dbus_remove_test_callback(void);
+int mm_sound_client_dbus_test(int a, int b, int* get);
+
+int mm_sound_client_dbus_initialize(void);
+int mm_sound_client_dbus_finalize(void);
+
+#endif /* __MM_SOUND_CLIENT_DBUS_H__ */
diff --git a/include/mm_sound_client_msgq.h b/include/mm_sound_client_msgq.h
new file mode 100644 (file)
index 0000000..ca76851
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * libmm-sound
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Seungbae Shin <seungbae.shin@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __MM_SOUND_CLIENT_MSGQ_H__
+#define __MM_SOUND_CLIENT_MSGQ_H__
+
+#include "mm_sound_private.h"
+#include "mm_sound_device.h"
+#ifdef USE_FOCUS
+#include "mm_sound_focus.h"
+#endif
+
+//#define MEMTYPE_TRANS_PER_MAX (1024 * 1024) /* 1MB */
+
+int MMSoundClientMsgqInit(void);
+int MMSoundClientMsgqCallbackFini(void);
+int MMSoundClientMsgqPlayTone(int number, int volume_config, double volume, int time, int *handle, bool enable_session);
+int MMSoundClientMsgqPlaySound(MMSoundPlayParam *param, int tone, int keytone, int *handle);
+int MMSoundClientMsgqStopSound(int handle);
+int _mm_sound_client_msgq_is_route_available(mm_sound_route route, bool *is_available);
+int _mm_sound_client_msgq_foreach_available_route_cb(mm_sound_available_route_cb , void *user_data);
+int _mm_sound_client_msgq_set_active_route(mm_sound_route route, bool need_broadcast);
+int _mm_sound_client_msgq_get_active_device(mm_sound_device_in *device_in, mm_sound_device_out *device_out);
+int _mm_sound_client_msgq_add_active_device_changed_callback(const char *name, mm_sound_active_device_changed_cb func, void* user_data);
+int _mm_sound_client_msgq_remove_active_device_changed_callback(const char *name);
+int _mm_sound_client_msgq_add_available_route_changed_callback(mm_sound_available_route_changed_cb func, void* user_data);
+int _mm_sound_client_msgq_remove_available_route_changed_callback(void);
+int _mm_sound_client_msgq_add_volume_changed_callback(mm_sound_volume_changed_cb func, void* user_data);
+int _mm_sound_client_msgq_remove_volume_changed_callback(void);
+int _mm_sound_client_msgq_set_sound_path_for_active_device(mm_sound_device_out device_out, mm_sound_device_in device_in);
+int _mm_sound_client_msgq_get_current_connected_device_list(int device_flgas, mm_sound_device_list_t **device_list);
+int _mm_sound_client_msgq_add_device_connected_callback(int device_flags, mm_sound_device_connected_cb func, void* user_data);
+int _mm_sound_client_msgq_remove_device_connected_callback(void);
+int _mm_sound_client_msgq_add_device_info_changed_callback(int device_flags, mm_sound_device_info_changed_cb func, void* user_data);
+int _mm_sound_client_msgq_remove_device_info_changed_callback(void);
+#ifdef USE_FOCUS
+int _mm_sound_client_msgq_register_focus(int id, const char *stream_type, mm_sound_focus_changed_cb callback, void* user_data);
+int _mm_sound_client_msgq_unregister_focus(int id);
+int _mm_sound_client_msgq_acquire_focus(int id, mm_sound_focus_type_e type, const char *option);
+int _mm_sound_client_msgq_release_focus(int id, mm_sound_focus_type_e type, const char *option);
+int _mm_sound_client_msgq_set_focus_watch_callback(mm_sound_focus_type_e type, mm_sound_focus_changed_watch_cb callback, void* user_data);
+int _mm_sound_client_msgq_unset_focus_watch_callback(void);
+#endif
+
+#ifdef PULSE_CLIENT
+int MMSoundClientMsgqIsBtA2dpOn (bool *connected, char** bt_name);
+#endif
+int _mm_sound_client_msgq_set_active_route_auto(void);
+int _mm_sound_client_msgq_get_audio_path(mm_sound_device_in *device_in, mm_sound_device_out *device_out);
+
+#endif /* __MM_SOUND_CLIENT_MSGQ_H__ */
index 9b18afb..616f90c 100644 (file)
@@ -22,6 +22,8 @@
 #ifndef __MM_SOUND_COMMON_H__
 #define __MM_SOUND_COMMON_H__
 
+#include <errno.h>
+
 ///////////////////////////////////
 ////     MMSOUND VOLUME APIs
 ///////////////////////////////////
 #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_VOLUME_BALANCE                       VCONF_KEY_VOLUME_PREFIX"/balance"
-#define VCONF_KEY_MUTE_ALL                             VCONF_KEY_VOLUME_PREFIX"/muteall"
-#define VCONF_KEY_MONO_AUDIO                           VCONFKEY_SETAPPL_ACCESSIBILITY_MONO_AUDIO
-
-#define VCONFKEY_SOUND_PRIMARY_VOLUME_TYPE             "memory/private/sound/PrimaryVolumetype"
-#define VCONFKEY_SOUND_PRIMARY_VOLUME_TYPE_FORCE       "memory/private/sound/PrimaryVolumetypeForce"
-
-
+#define VCONFKEY_SOUND_PRIMARY_VOLUME_TYPE     "memory/private/sound/PrimaryVolumeType"
 #ifndef _TIZEN_PUBLIC_
-#define VCONF_KEY_NOISE_REDUCTION                      VCONFKEY_CALL_NOISE_REDUCTION_STATE_BOOL
-#define VCONF_KEY_EXTRA_VOLUME                         VCONFKEY_CALL_EXTRA_VOLUME_STATE_BOOL
-#define VCONF_KEY_WBAMR                                                VCONFKEY_CALL_WBAMR_STATE_BOOL
-#define VCONF_KEY_VR_ENABLED                           VCONFKEY_VOICE_CONTROL_ENABLED
-#define VCONF_KEY_VR_RINGTONE_ENABLED          VCONFKEY_VOICE_CONTROL_INCOMING_CALL_ENABLED
 #ifdef TIZEN_MICRO
 #define VCONF_KEY_VR_LEFTHAND_ENABLED          VCONFKEY_SETAPPL_PERFERED_ARM_LEFT_BOOL
 #endif
index 6950cd7..ccb568a 100644 (file)
@@ -37,8 +37,9 @@
 #endif
 
 #define MAX_DEVICE_NAME_NUM 256
+#define MAX_DEVICE_TYPE_STR_LEN 30
 typedef struct {
-       int type;
+       char type[MAX_DEVICE_TYPE_STR_LEN];
        int io_direction;
        int id;
        char name[MAX_DEVICE_NAME_NUM];
@@ -50,9 +51,9 @@ typedef struct {
 } mm_sound_device_list_t;
 
 typedef enum {
-       DEVICE_IO_DIRECTION_IN,
-       DEVICE_IO_DIRECTION_OUT,
-       DEVICE_IO_DIRECTION_BOTH,
+       DEVICE_IO_DIRECTION_IN = 0x1,
+       DEVICE_IO_DIRECTION_OUT = 0x2,
+       DEVICE_IO_DIRECTION_BOTH = DEVICE_IO_DIRECTION_IN | DEVICE_IO_DIRECTION_OUT,
 } device_io_direction_e;
 
 typedef enum {
diff --git a/include/mm_sound_focus.h b/include/mm_sound_focus.h
new file mode 100644 (file)
index 0000000..3c0552c
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * libmm-sound
+ *
+ * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Sangchul Lee <sc11.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/**
+ * @file               mm_sound_focus.h
+ * @brief              Application interface library for sound module.
+ * @date
+ *
+ * Application interface library for sound module.
+ */
+
+#ifndef        __MM_SOUND_FOCUS_H__
+#define        __MM_SOUND_FOCUS_H__
+
+#ifdef __cplusplus
+       extern "C" {
+#endif
+
+typedef enum {
+       FOCUS_IS_RELEASED,
+       FOCUS_IS_ACQUIRED,
+} mm_sound_focus_state_e;
+
+typedef enum {
+       FOCUS_FOR_PLAYBACK = 1,
+       FOCUS_FOR_CAPTURE,
+       FOCUS_FOR_BOTH,
+} mm_sound_focus_type_e;
+
+int mm_sound_focus_get_id(int *id);
+
+typedef void (*mm_sound_focus_changed_cb) (int id, mm_sound_focus_type_e focus_type, mm_sound_focus_state_e state, const char *reason_for_change, const char *additional_info, void *user_data);
+int mm_sound_register_focus(int id, const char *stream_type, mm_sound_focus_changed_cb callback, void *user_data);
+int mm_sound_unregister_focus(int id);
+int mm_sound_acquire_focus(int id, mm_sound_focus_type_e focus_type, const char *additional_info);
+int mm_sound_release_focus(int id, mm_sound_focus_type_e focus_type, const char *additional_info);
+
+typedef void (*mm_sound_focus_changed_watch_cb) (int id, mm_sound_focus_type_e focus_type, mm_sound_focus_state_e state, const char *reason_for_change, const char *additional_info, void *user_data);
+int mm_sound_set_focus_watch_callback(mm_sound_focus_type_e focus_type, mm_sound_focus_changed_watch_cb callback, void *user_data, int *id);
+int mm_sound_unset_focus_watch_callback(int id);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __MM_SOUND_FOCUS_H__ */
+
index 4b1789b..27dcd37 100644 (file)
@@ -30,6 +30,8 @@
 #define RCV_MSG        0x21    /* rcv key */
 #define SND_MSG 0x24   /* snd key */
 #define CB_MSG   0x64          /* cb key */
+#define RCV_CB_MSG   0x41      /* cb rcv key */
+#define SND_CB_MSG   0x44      /* cb snd key */
 
 #define MEMTYPE_SUPPORT_MAX (1024 * 1024) /* 1MB */
 
@@ -95,6 +97,100 @@ enum {
        MM_SOUND_MSG_INF_DEVICE_INFO_CHANGED_CB,
        MM_SOUND_MSG_REQ_GET_CONNECTED_DEVICE_LIST,
        MM_SOUND_MSG_RES_GET_CONNECTED_DEVICE_LIST,
+#ifdef USE_FOCUS
+       MM_SOUND_MSG_REQ_REGISTER_FOCUS,
+       MM_SOUND_MSG_RES_REGISTER_FOCUS,
+       MM_SOUND_MSG_REQ_UNREGISTER_FOCUS,
+       MM_SOUND_MSG_RES_UNREGISTER_FOCUS,
+       MM_SOUND_MSG_REQ_ACQUIRE_FOCUS,
+       MM_SOUND_MSG_RES_ACQUIRE_FOCUS,
+       MM_SOUND_MSG_REQ_RELEASE_FOCUS,
+       MM_SOUND_MSG_RES_RELEASE_FOCUS,
+       MM_SOUND_MSG_INF_FOCUS_CHANGED_CB,
+       MM_SOUND_MSG_REQ_SET_FOCUS_WATCH_CB,
+       MM_SOUND_MSG_RES_SET_FOCUS_WATCH_CB,
+       MM_SOUND_MSG_REQ_UNSET_FOCUS_WATCH_CB,
+       MM_SOUND_MSG_RES_UNSET_FOCUS_WATCH_CB,
+       MM_SOUND_MSG_INF_FOCUS_WATCH_CB,
+#endif
+};
+
+
+/* TODO : make this general , can be used in other IPC not only dbus */
+enum {
+        METHOD_CALL_TEST,
+        METHOD_CALL_PLAY_FILE_START,
+        METHOD_CALL_PLAY_FILE_START_WITH_STREAM_INFO,
+        METHOD_CALL_PLAY_FILE_STOP,
+        METHOD_CALL_PLAY_DTMF,
+        METHOD_CALL_PLAY_DTMF_WITH_STREAM_INFO,
+        METHOD_CALL_GET_BT_A2DP_STATUS,
+        METHOD_CALL_SET_PATH_FOR_ACTIVE_DEVICE,
+        METHOD_CALL_GET_CONNECTED_DEVICE_LIST,
+        METHOD_CALL_GET_AUDIO_PATH,
+        METHOD_CALL_SET_VOLUME_LEVEL,
+
+        METHOD_CALL_REGISTER_FOCUS,
+        METHOD_CALL_UNREGISTER_FOCUS,
+        METHOD_CALL_ACQUIRE_FOCUS,
+        METHOD_CALL_RELEASE_FOCUS,
+        METHOD_CALL_WATCH_FOCUS,
+        METHOD_CALL_UNWATCH_FOCUS,
+
+        METHOD_CALL_ASM_REGISTER_SOUND,
+        METHOD_CALL_ASM_UNREGISTER_SOUND,
+        METHOD_CALL_ASM_REGISTER_WATCHER,
+        METHOD_CALL_ASM_UNREGISTER_WATCHER,
+        METHOD_CALL_ASM_GET_MYSTATE,
+        METHOD_CALL_ASM_GET_STATE,
+        METHOD_CALL_ASM_SET_STATE,
+        METHOD_CALL_ASM_SET_SUBSESSION,
+        METHOD_CALL_ASM_GET_SUBSESSION,
+        METHOD_CALL_ASM_SET_SUBEVENT,
+        METHOD_CALL_ASM_GET_SUBEVENT,
+        METHOD_CALL_ASM_SET_SESSION_OPTION,
+        METHOD_CALL_ASM_GET_SESSION_OPTION,
+        METHOD_CALL_ASM_RESET_RESUME_TAG,
+        METHOD_CALL_ASM_DUMP,
+        METHOD_CALL_ASM_EMERGENT_EXIT,
+
+        METHOD_CALL_MAX,
+};
+
+
+typedef enum sound_server_signal {
+        SIGNAL_TEST,
+        SIGNAL_PLAY_FILE_END,
+        SIGNAL_VOLUME_CHANGED,
+        SIGNAL_DEVICE_CONNECTED,
+        SIGNAL_DEVICE_INFO_CHANGED,
+        SIGNAL_FOCUS_CHANGED,
+        SIGNAL_FOCUS_WATCH,
+        SIGNAL_MAX
+} sound_server_signal_t;
+
+typedef enum pulseaudio_property {
+        PULSEAUDIO_PROP_AUDIO_BALANCE,
+        PULSEAUDIO_PROP_MONO_AUDIO,
+        PULSEAUDIO_PROP_MUTE_ALL,
+        PULSEAUDIO_PROP_MAX
+} pulseaudio_property_t;
+
+struct mm_sound_dbus_method_info{
+        const char* name;
+        /*
+        const char* argument;
+        const char* reply;
+        */
+};
+
+struct mm_sound_dbus_signal_info{
+        const char* name;
+        const char* argument;
+};
+
+struct pulseaudio_dbus_property_info {
+        const char* name;
 };
 
 #define DSIZE sizeof(mm_ipc_msg_t)-sizeof(long)        /* data size for rcv & snd */
index 13c7d64..c0e2b31 100644 (file)
@@ -72,17 +72,15 @@ typedef struct mm_sound_handle_route_info{
        bool do_not_restore;
 }mm_sound_handle_route_info;
 
-int mm_sound_pa_open(MMSoundHandleMode mode, mm_sound_handle_route_info *route_info, MMSoundHandlePriority priority, int volume_config, pa_sample_spec* ss, pa_channel_map* channel_map, int* size);
+int mm_sound_pa_open(MMSoundHandleMode mode, mm_sound_handle_route_info *route_info, MMSoundHandlePriority priority, int volume_config, pa_sample_spec* ss, pa_channel_map* channel_map, int* size, char *stream_type, int stream_index);
 int mm_sound_pa_read(const int handle, void* buf, const int size);
 int mm_sound_pa_write(const int handle, void* buf, const int size);
 int mm_sound_pa_close(const int handle);
 int mm_sound_pa_cork(const int handle, const int cork);
 int mm_sound_pa_drain(const int handle);
 int mm_sound_pa_flush(const int handle);
-int mm_sound_pa_set_volume_by_type(const int type, const int value);
 int mm_sound_pa_get_latency(const int handle, int* latency);
 int mm_sound_pa_set_call_mute(const int type, const int mute, int direction);
-int mm_sound_pa_get_volume_max(const int type, int* step);
 int mm_sound_pa_get_volume_level(const int handle, const int type, int* level);
 int mm_sound_pa_set_volume_level(const int handle, const int type, int level);
 int mm_sound_pa_set_mute(const int handle, const int type, int direction, int mute);
index c8c1a12..4cdf68b 100644 (file)
@@ -141,6 +141,7 @@ typedef struct {
  */
 int mm_sound_play_sound_ex(MMSoundPlayParam *param, int *handle);
 
+int mm_sound_play_sound_with_stream_info(const char *filename, char *stream_type, int stream_id, mm_sound_stop_callback_func _completed_cb, void *data, int *handle);
 
 /**
  * This function is to play key sound.
diff --git a/include/mm_sound_stream.h b/include/mm_sound_stream.h
new file mode 100644 (file)
index 0000000..79e54aa
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * libmm-sound
+ *
+ * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Sangchul Lee <sc11.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/**
+ * @file               mm_sound_stream.h
+ * @brief              Application interface library for sound module.
+ * @date
+ *
+ * Application interface library for sound module.
+ */
+
+#ifndef        __MM_SOUND_STREAM_H__
+#define        __MM_SOUND_STREAM_H__
+
+#ifdef __cplusplus
+       extern "C" {
+#endif
+
+#include <glib.h>
+#define MAX_STREAM_TYPE_LEN 64
+#define NUM_OF_STREAM_IO_TYPE         2    /* playback / capture */
+#define AVAIL_STREAMS_MAX 32
+typedef struct _stream_list {
+       gchar *stream_types[AVAIL_STREAMS_MAX];
+       int priorities[AVAIL_STREAMS_MAX];
+} stream_list_t;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __MM_SOUND_STREAM_H__ */
+
index 9ee2593..782046e 100644 (file)
@@ -33,6 +33,7 @@
 
 #include <mm_types.h>
 #include <mm_error.h>
+#include <unistd.h>
 
 #include "../include/mm_sound.h"
 
        extern "C" {
 #endif
 
-int _mm_sound_get_valid_route_list(mm_sound_route **route_list);
-bool _mm_sound_is_route_valid(mm_sound_route route);
-void _mm_sound_get_devices_from_route(mm_sound_route route, mm_sound_device_in *device_in, mm_sound_device_out *device_out);
-bool _mm_sound_check_hibernation (const char *path);
-int _mm_sound_volume_add_callback(volume_type_t type, void *func, void* user_data);
-int _mm_sound_volume_remove_callback(volume_type_t type, void *func);
-int _mm_sound_volume_get_value_by_type(volume_type_t type, unsigned int *value);
-int _mm_sound_volume_set_value_by_type(volume_type_t type, unsigned int value);
-int _mm_sound_muteall_add_callback(void *func);
-int _mm_sound_muteall_remove_callback(void *func);
-int _mm_sound_volume_set_balance(float balance);
-int _mm_sound_volume_get_balance(float *balance);
-int _mm_sound_set_muteall(int muteall);
-int _mm_sound_get_muteall(int *muteall);
-int _mm_sound_set_stereo_to_mono(int ismono);
-int _mm_sound_get_stereo_to_mono(int *ismono);
-int _mm_sound_get_earjack_type (int *type);
-int _mm_sound_get_dock_type (int *type);
-mm_sound_device_in _mm_sound_get_device_in_from_path (int path);
-mm_sound_device_out _mm_sound_get_device_out_from_path (int path);
+int mm_sound_util_get_valid_route_list(mm_sound_route **route_list);
+bool mm_sound_util_is_route_valid(mm_sound_route route);
+void mm_sound_util_get_devices_from_route(mm_sound_route route, mm_sound_device_in *device_in, mm_sound_device_out *device_out);
+int mm_sound_util_volume_add_callback(volume_type_t type, void *func, void* user_data);
+int mm_sound_util_volume_remove_callback(volume_type_t type, void *func);
+int mm_sound_util_volume_get_value_by_type(volume_type_t type, unsigned int *value);
+int mm_sound_util_volume_set_value_by_type(volume_type_t type, unsigned int value);
+int mm_sound_util_get_earjack_type(int* type);
+int mm_sound_util_get_dock_type (int *type);
 
-bool _mm_sound_is_recording (void);
-bool _mm_sound_is_mute_policy (void);
+bool mm_sound_util_is_recording (void);
+bool mm_sound_util_is_mute_policy (void);
+
+bool mm_sound_util_is_process_alive(pid_t pid);
 
 #ifdef __cplusplus
 }
index 97e8c31..0345f39 100644 (file)
@@ -1,4 +1,20 @@
 <manifest>
+       <define>
+               <request>
+                       <smack request="system::vconf" type="arwxt"/>
+                       <smack request="system::vconf_system" type="arwxt"/>
+                       <smack request="system::vconf_inhouse" type="arwxt"/>
+                       <smack request="system::vconf_network" type="arwxt"/>
+                       <smack request="system::vconf_multimedia" type="arwxt"/>
+                       <smack request="system::share" type="rwx"/>
+                       <smack request="system::homedir" type="arwxt"/>
+                       <smack request="device::sys_logging" type="w"/>
+                       <smack request="device::app_logging" type="w"/>
+                       <smack request="sys-assert::core" type="arwxt"/>
+                       <smack request="pulseaudio" type="rwx"/>
+                       <smack request="org.tizen.setting" type="rw"/>
+               </request>
+       </define>
        <request>
                <domain name="_"/>
        </request>
index 9dfb50c..fdf3ba1 100644 (file)
@@ -57,20 +57,45 @@ typedef struct {
        volume_callback_fn      func;
        void*                           data;
        volume_type_t           type;
-}volume_cb_param;
+} volume_cb_param;
 
 volume_cb_param g_volume_param[VOLUME_TYPE_MAX];
 
-static pthread_mutex_t _volume_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t g_volume_mutex = PTHREAD_MUTEX_INITIALIZER;
 
-static char *volume_type_str[VOLUME_TYPE_MAX] = { "SYSTEM", "NOTIFICATION", "ALARM", "RINGTONE", "MEDIA", "CALL", "VOIP", "VOICE", "FIXED"};
+#include <gio/gio.h>
 
-static char* __get_volume_str (volume_type_t type)
+static GList *g_subscribe_cb_list = NULL;
+static pthread_mutex_t g_subscribe_cb_list_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+#define MM_SOUND_DBUS_BUS_NAME_PREPIX  "org.tizen.MMSound"
+#define MM_SOUND_DBUS_OBJECT_PATH  "/org/tizen/MMSound"
+#define MM_SOUND_DBUS_INTERFACE    "org.tizen.mmsound"
+
+GDBusConnection *g_dbus_conn_mmsound;
+
+int g_dbus_signal_values[MM_SOUND_SIGNAL_MAX] = {0,};
+
+const char* dbus_signal_name_str[] = {
+       "ReleaseInternalFocus",
+};
+
+typedef struct _subscribe_cb {
+       mm_sound_signal_name_t signal_type;
+       mm_sound_signal_callback callback;
+       void *user_data;
+       unsigned int id;
+} subscribe_cb_t;
+
+static char* _get_volume_str (volume_type_t type)
 {
+       static const char *volume_type_str[VOLUME_TYPE_MAX] =
+               { "SYSTEM", "NOTIFICATION", "ALARM", "RINGTONE", "MEDIA", "CALL", "VOIP", "VOICE", "FIXED"};
+
        return (type >= VOLUME_TYPE_SYSTEM && type < VOLUME_TYPE_MAX)? volume_type_str[type] : "Unknown";
 }
 
-static int __validate_volume(volume_type_t type, int value)
+static int _validate_volume(volume_type_t type, int value)
 {
        if (value < 0)
                return -1;
@@ -93,11 +118,6 @@ static int __validate_volume(volume_type_t type, int value)
                        return -1;
                }
                break;
-       case VOLUME_TYPE_EXT_ANDROID:
-               if (value >= VOLUME_MAX_SINGLE) {
-                       return -1;
-               }
-               break;
        default:
                return -1;
                break;
@@ -105,26 +125,26 @@ static int __validate_volume(volume_type_t type, int value)
        return 0;
 }
 
-static void volume_changed_cb(keynode_t* node, void* data)
+static void _volume_changed_cb(keynode_t* node, void* data)
 {
        volume_cb_param* param = (volume_cb_param*) data;
 
        debug_msg("%s changed callback called\n",vconf_keynode_get_name(node));
 
-       MMSOUND_ENTER_CRITICAL_SECTION( &_volume_mutex )
+       MMSOUND_ENTER_CRITICAL_SECTION( &g_volume_mutex )
 
        if(param && (param->func != NULL)) {
                debug_log("function 0x%x\n", param->func);
                ((volume_callback_fn)param->func)(param->data);
        }
 
-       MMSOUND_LEAVE_CRITICAL_SECTION( &_volume_mutex )
+       MMSOUND_LEAVE_CRITICAL_SECTION( &g_volume_mutex )
 }
 
 EXPORT_API
 int mm_sound_volume_add_callback(volume_type_t type, volume_callback_fn func, void* user_data)
 {
-       debug_msg("type = (%d)%15s, func = %p, user_data = %p", type, __get_volume_str(type), func, user_data);
+       debug_msg("type = (%d)%15s, func = %p, user_data = %p", type, _get_volume_str(type), func, user_data);
 
        /* Check input param */
        if (type < 0 || type >= VOLUME_TYPE_MAX) {
@@ -136,36 +156,36 @@ int mm_sound_volume_add_callback(volume_type_t type, volume_callback_fn func, vo
                return MM_ERROR_INVALID_ARGUMENT;
        }
 
-       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN( &_volume_mutex, MM_ERROR_SOUND_INTERNAL );
+       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN( &g_volume_mutex, MM_ERROR_SOUND_INTERNAL );
 
        g_volume_param[type].func = func;
        g_volume_param[type].data = user_data;
        g_volume_param[type].type = type;
 
-       MMSOUND_LEAVE_CRITICAL_SECTION( &_volume_mutex );
+       MMSOUND_LEAVE_CRITICAL_SECTION( &g_volume_mutex );
 
-       return _mm_sound_volume_add_callback(type, volume_changed_cb, (void*)&g_volume_param[type]);
+       return mm_sound_util_volume_add_callback(type, _volume_changed_cb, (void*)&g_volume_param[type]);
 }
 
 EXPORT_API
 int mm_sound_volume_remove_callback(volume_type_t type)
 {
-       debug_msg("type = (%d)%s", type, __get_volume_str(type));
+       debug_msg("type = (%d)%s", type, _get_volume_str(type));
 
        if(type < 0 || type >=VOLUME_TYPE_MAX) {
                debug_error("invalid argument\n");
                return MM_ERROR_INVALID_ARGUMENT;
        }
 
-       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN( &_volume_mutex, MM_ERROR_SOUND_INTERNAL );
+       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN( &g_volume_mutex, MM_ERROR_SOUND_INTERNAL );
 
        g_volume_param[type].func = NULL;
        g_volume_param[type].data = NULL;
        g_volume_param[type].type = type;
 
-       MMSOUND_LEAVE_CRITICAL_SECTION( &_volume_mutex );
+       MMSOUND_LEAVE_CRITICAL_SECTION( &g_volume_mutex );
 
-       return _mm_sound_volume_remove_callback(type, volume_changed_cb);
+       return mm_sound_util_volume_remove_callback(type, _volume_changed_cb);
 }
 
 EXPORT_API
@@ -178,7 +198,7 @@ int mm_sound_add_volume_changed_callback(mm_sound_volume_changed_cb func, void*
                return MM_ERROR_INVALID_ARGUMENT;
        }
 
-       ret = _mm_sound_client_add_volume_changed_callback(func, user_data);
+       ret = mm_sound_client_add_volume_changed_callback(func, user_data);
        if (ret < 0) {
                debug_error("Can not add volume changed callback, ret = %x\n", ret);
        }
@@ -191,7 +211,7 @@ int mm_sound_remove_volume_changed_callback(void)
 {
        int ret = MM_ERROR_NONE;
 
-       ret = _mm_sound_client_remove_volume_changed_callback();
+       ret = mm_sound_client_remove_volume_changed_callback();
        if (ret < 0) {
                debug_error("Can not remove volume changed callback, ret = %x\n", ret);
        }
@@ -200,85 +220,29 @@ int mm_sound_remove_volume_changed_callback(void)
 }
 
 EXPORT_API
-int mm_sound_muteall_add_callback(muteall_callback_fn func)
-{
-       debug_msg("func = %p", func);
-
-       if (!func) {
-               debug_warning("callback function is null\n");
-               return MM_ERROR_INVALID_ARGUMENT;
-       }
-
-       return _mm_sound_muteall_add_callback(func);
-}
-
-EXPORT_API
-int mm_sound_muteall_remove_callback(muteall_callback_fn func)
-{
-       debug_msg("func = %p", func);
-
-       if (!func) {
-               debug_warning("callback function is null\n");
-               return MM_ERROR_INVALID_ARGUMENT;
-       }
-
-       return _mm_sound_muteall_remove_callback(func);
-}
-
-EXPORT_API
-int mm_sound_get_volume_step(volume_type_t type, int *step)
-{
-       debug_error("\n**********\n\nTHIS FUNCTION HAS DEFPRECATED\n\n \
-                       use mm_sound_volume_get_step() instead\n\n**********\n");
-       return mm_sound_volume_get_step(type, step);
-}
-
-EXPORT_API
 int mm_sound_volume_get_step(volume_type_t type, int *step)
 {
-       int err;
-
-       /* Check input param */
-       if (step == NULL) {
-               debug_error("second parameter is null\n");
-               return MM_ERROR_INVALID_ARGUMENT;
-       }
-       if (type < 0 || type >= VOLUME_TYPE_MAX) {
-               debug_error("Invalid type value %d\n", (int)type);
-               return MM_ERROR_INVALID_ARGUMENT;
-       }
-
-       if(MM_ERROR_NONE != mm_sound_pa_get_volume_max(type, step)) {
-               err = MM_ERROR_INVALID_ARGUMENT;
-       }
-
-       debug_msg("type = (%d)%15s, step = %d", type, __get_volume_str(type), *step);
-
-       return MM_ERROR_NONE;
+       return MM_ERROR_SOUND_NOT_SUPPORTED_OPERATION;
 }
 
 EXPORT_API
-int mm_sound_volume_set_value(volume_type_t type, const unsigned int value)
+int mm_sound_volume_set_value(volume_type_t volume_type, const unsigned int volume_level)
 {
        int ret = MM_ERROR_NONE;
 
-       debug_msg("type = (%d)%s, value = %d", type, __get_volume_str(type), value);
+       debug_msg("type = (%d)%s, value = %d", volume_type, _get_volume_str(volume_type), volume_level);
 
        /* Check input param */
-       if (0 > __validate_volume(type, (int)value)) {
-               debug_error("invalid volume type %d, value %u\n", type, value);
+       if (0 > _validate_volume(volume_type, (int)volume_level)) {
+               debug_error("invalid volume type %d, value %u\n", volume_type, volume_level);
                return MM_ERROR_INVALID_ARGUMENT;
        }
 
-       ret = _mm_sound_volume_set_value_by_type(type, value);
+       ret = mm_sound_util_volume_set_value_by_type(volume_type, volume_level);
        if (ret == MM_ERROR_NONE) {
                /* update shared memory value */
-               int muteall;
-               _mm_sound_get_muteall(&muteall);
-               if(!muteall) {
-                       if(MM_ERROR_NONE != mm_sound_pa_set_volume_by_type(type, (int)value)) {
-                               debug_error("Can not set volume to shared memory 0x%x\n", ret);
-                       }
+               if(MM_ERROR_NONE != mm_sound_client_set_volume_by_type(volume_type, volume_level)) {
+                       debug_error("Can not set volume to shared memory 0x%x\n", ret);
                }
        }
 
@@ -286,41 +250,6 @@ int mm_sound_volume_set_value(volume_type_t type, const unsigned int value)
 }
 
 EXPORT_API
-int mm_sound_mute_all(int muteall)
-{
-       int ret = MM_ERROR_NONE;
-
-       debug_msg("** deprecated API ** muteall = %d", muteall);
-
-       return ret;
-}
-
-
-EXPORT_API
-int mm_sound_set_call_mute(volume_type_t type, int mute)
-{
-       int ret = MM_ERROR_NONE;
-
-       debug_error("Unsupported API\n");
-
-       return ret;
-}
-
-
-EXPORT_API
-int mm_sound_get_call_mute(volume_type_t type, int *mute)
-{
-       int ret = MM_ERROR_NONE;
-
-       if(!mute)
-               return MM_ERROR_INVALID_ARGUMENT;
-
-       debug_error("Unsupported API\n");
-
-       return ret;
-}
-
-EXPORT_API
 int mm_sound_volume_get_value(volume_type_t type, unsigned int *value)
 {
        int ret = MM_ERROR_NONE;
@@ -335,9 +264,9 @@ int mm_sound_volume_get_value(volume_type_t type, unsigned int *value)
                return MM_ERROR_INVALID_ARGUMENT;
        }
 
-       ret = _mm_sound_volume_get_value_by_type(type, value);
+       ret = mm_sound_util_volume_get_value_by_type(type, value);
 
-       debug_msg("returned %s = %d", __get_volume_str(type), *value);
+       debug_msg("returned %s = %d", _get_volume_str(type), *value);
        return ret;
 }
 
@@ -348,43 +277,26 @@ int mm_sound_volume_primary_type_set(volume_type_t type)
        int ret = MM_ERROR_NONE;
 
        /* Check input param */
-       if(type < 0 || type >= VOLUME_TYPE_MAX) {
+       if(type < VOLUME_TYPE_UNKNOWN || type >= VOLUME_TYPE_MAX) {
                debug_error("invalid argument\n");
                return MM_ERROR_INVALID_ARGUMENT;
        }
 
-       if (vconf_set_int(VCONFKEY_SOUND_PRIMARY_VOLUME_TYPE_FORCE, type)) {
-               debug_error("could not set vconf for RIMARY_VOLUME_TYPE_FORCE\n");
+       if (vconf_set_int(VCONFKEY_SOUND_PRIMARY_VOLUME_TYPE, type)) {
+               debug_error("could not set vconf for RIMARY_VOLUME_TYPE\n");
                ret = MM_ERROR_SOUND_INTERNAL;
        } else {
-               debug_msg("set primary volume type forcibly %d(%s)", type, __get_volume_str(type));
+               debug_msg("set primary volume type forcibly %d(%s)", type, _get_volume_str(type));
        }
 
        return ret;
 }
 
 EXPORT_API
-int mm_sound_volume_primary_type_clear(void)
-{
-       pid_t mypid;
-       int ret = MM_ERROR_NONE;
-
-       if (vconf_set_int(VCONFKEY_SOUND_PRIMARY_VOLUME_TYPE_FORCE, -1)) {
-               debug_error("could not reset vconf for RIMARY_VOLUME_TYPE_FORCE\n");
-               ret = MM_ERROR_SOUND_INTERNAL;
-       } else {
-               debug_msg("clear primary volume type forcibly %d(%s)", -1, "none");
-       }
-
-       return ret;
-}
-
-EXPORT_API
-int mm_sound_volume_get_current_playing_type(volume_type_t *type)
+int mm_sound_volume_primary_type_get(volume_type_t *type)
 {
        int ret = MM_ERROR_NONE;
        int voltype = VOLUME_TYPE_RINGTONE;
-       int fvoltype = -1;
 
        /* Check input param */
        if(type == NULL) {
@@ -393,133 +305,34 @@ int mm_sound_volume_get_current_playing_type(volume_type_t *type)
        }
 
        /* check force set */
-       if (vconf_get_int(VCONFKEY_SOUND_PRIMARY_VOLUME_TYPE_FORCE, &fvoltype)) {
-               debug_error("could not get vconf for RIMARY_VOLUME_TYPE_FORCE\n");
+       if (vconf_get_int(VCONFKEY_SOUND_PRIMARY_VOLUME_TYPE, &voltype)) {
+               debug_error("could not get vconf for PRIMARY_VOLUME_TYPE\n");
                ret = MM_ERROR_SOUND_INTERNAL;
        } else {
-               if(fvoltype >= 0) {
-                       *type = fvoltype;
-                       return MM_ERROR_NONE;
-               }
-       }
-
-       /* If primary volume is not set by user, get current playing volume */
-       if(vconf_get_int(VCONFKEY_SOUND_PRIMARY_VOLUME_TYPE, &voltype)) {
-               debug_error("get vconf(VCONFKEY_SOUND_PRIMARY_VOLUME_TYPE) failed voltype(%d)\n", voltype);
-       } else {
-               debug_error("get vconf(VCONFKEY_SOUND_PRIMARY_VOLUME_TYPE) voltype(%d)\n", voltype);
-       }
-
-       if(voltype >= 0) {
+               debug_msg("get primary volume type %d(%s)", voltype, _get_volume_str(voltype));
                *type = voltype;
-               ret = MM_ERROR_NONE;
-       }
-       else if(voltype == -1)
-               ret = MM_ERROR_SOUND_VOLUME_NO_INSTANCE;
-       else if(voltype == -2)
-               ret = MM_ERROR_SOUND_VOLUME_CAPTURE_ONLY;
-       else
-               ret = MM_ERROR_SOUND_INTERNAL;
-
-       debug_msg("returned type = (%d)%15s, ret = 0x%x", *type, __get_volume_str(*type), ret);
-
-       return ret;
-}
-
-EXPORT_API
-int mm_sound_volume_set_balance (float balance)
-{
-       debug_msg("balance = %f", balance);
-
-       /* Check input param */
-       if (balance < -1.0 || balance > 1.0) {
-               debug_error("invalid balance value [%f]\n", balance);
-               return MM_ERROR_INVALID_ARGUMENT;
-       }
-
-       return _mm_sound_volume_set_balance(balance);
-}
-
-EXPORT_API
-int mm_sound_volume_get_balance (float *balance)
-{
-       int ret = MM_ERROR_NONE;
-
-       /* Check input param */
-       if (balance == NULL) {
-               debug_error("invalid argument\n");
-               return MM_ERROR_INVALID_ARGUMENT;
-       }
-
-       ret = _mm_sound_volume_get_balance(balance);
-       debug_msg("returned balance = %f", *balance);
-
-       return ret;
-}
-
-EXPORT_API
-int mm_sound_set_muteall (int muteall)
-{
-       debug_msg("muteall = %d", muteall);
-
-       /* Check input param */
-       if (muteall < 0 || muteall > 1) {
-               debug_error("invalid muteall value [%f]\n", muteall);
-               return MM_ERROR_INVALID_ARGUMENT;
-       }
-
-       return _mm_sound_set_muteall(muteall);
-}
-
-EXPORT_API
-int mm_sound_get_muteall (int *muteall)
-{
-       int ret = MM_ERROR_NONE;
-
-       /* Check input param */
-       if (muteall == NULL) {
-               debug_error("invalid argument\n");
-               return MM_ERROR_INVALID_ARGUMENT;
        }
 
-       ret = _mm_sound_get_muteall(muteall);
-       debug_msg("returned muteall = %d", *muteall);
-
        return ret;
 }
 
+/* it will be removed */
 EXPORT_API
-int mm_sound_set_stereo_to_mono (int ismono)
-{
-       debug_msg("ismono = %d", ismono);
-
-       /* Check input param */
-       if (ismono < 0 || ismono > 1) {
-               debug_error("invalid ismono value [%f]\n", ismono);
-               return MM_ERROR_INVALID_ARGUMENT;
-       }
-
-       return __mm_sound_set_stereo_to_mono(ismono);
-}
-
-EXPORT_API
-int mm_sound_get_stereo_to_mono (int *ismono)
+int mm_sound_volume_primary_type_clear(void)
 {
+       pid_t mypid;
        int ret = MM_ERROR_NONE;
 
-       /* Check input param */
-       if (ismono == NULL) {
-               debug_error("invalid argument\n");
-               return MM_ERROR_INVALID_ARGUMENT;
+       if (vconf_set_int(VCONFKEY_SOUND_PRIMARY_VOLUME_TYPE, -1)) {
+               debug_error("could not reset vconf for PRIMARY_VOLUME_TYPE\n");
+               ret = MM_ERROR_SOUND_INTERNAL;
+       } else {
+               debug_msg("clear primary volume type forcibly %d(%s)", -1, "none");
        }
 
-       ret = __mm_sound_get_stereo_to_mono(ismono);
-       debug_msg("returned ismono = %d", *ismono);
-
        return ret;
 }
 
-
 ///////////////////////////////////
 ////     MMSOUND PLAY APIs
 ///////////////////////////////////
@@ -607,7 +420,7 @@ int mm_sound_play_sound_ex(MMSoundPlayParam *param, int *handle)
        debug_warning ("play sound : priority=[%d], handle_route=[%d]\n", param->priority, param->handle_route);
 
        /* Play sound */
-       err = MMSoundClientPlaySound(param, 0, 0, &lhandle);
+       err = mm_sound_client_play_sound(param, 0, 0, &lhandle);
        if (err < 0) {
                debug_error("Failed to play sound\n");
                return err;
@@ -625,6 +438,32 @@ int mm_sound_play_sound_ex(MMSoundPlayParam *param, int *handle)
        return MM_ERROR_NONE;
 }
 
+EXPORT_API
+int mm_sound_play_sound_with_stream_info(const char *filename, char *stream_type, int stream_id, mm_sound_stop_callback_func callback, void *data, int *handle)
+{
+       MMSoundPlayParam param = { 0, };
+       int err;
+
+       param.filename = filename;
+       param.volume = 0; //volume value dose not effect anymore
+       param.callback = callback;
+       param.data = data;
+       param.loop = 1;
+       param.priority = HANDLE_PRIORITY_NORMAL;
+       param.handle_route = MM_SOUND_HANDLE_ROUTE_USING_CURRENT;
+
+       err = mm_sound_client_play_sound_with_stream_info(&param, handle, stream_type, stream_id);
+       if (err < 0) {
+               debug_error("Failed to play sound\n");
+               return err;
+       }
+
+       debug_warning ("success : handle=[%p]\n", handle);
+
+       return MM_ERROR_NONE;
+
+}
+
 
 EXPORT_API
 int mm_sound_stop_sound(int handle)
@@ -633,7 +472,7 @@ int mm_sound_stop_sound(int handle)
 
        debug_warning ("enter : handle=[%p]\n", handle);
        /* Stop sound */
-       err = MMSoundClientStopSound(handle);
+       err = mm_sound_client_stop_sound(handle);
        if (err < 0) {
                debug_error("Fail to stop sound\n");
                return err;
@@ -675,7 +514,7 @@ int mm_sound_play_tone_ex (MMSoundTone_t num, int volume_config, const double vo
 
        /* Play tone */
        debug_msg("Call MMSoundClientPlayTone\n");
-       err = MMSoundClientPlayTone(num, volume_config, volume, duration, &lhandle, enable_session);
+       err = mm_sound_client_play_tone(num, volume_config, volume, duration, &lhandle, enable_session);
        if (err < 0) {
                debug_error("Failed to play sound\n");
                return err;
@@ -692,32 +531,31 @@ int mm_sound_play_tone_ex (MMSoundTone_t num, int volume_config, const double vo
 }
 
 EXPORT_API
-int mm_sound_play_tone (MMSoundTone_t num, int volume_config, const double volume, const int duration, int *handle)
+int mm_sound_play_tone_with_stream_info(MMSoundTone_t tone, char *stream_type, int stream_id, const double volume, const int duration, int *handle)
 {
-       return mm_sound_play_tone_ex (num, volume_config, volume, duration, handle, true);
-}
 
-///////////////////////////////////
-////     MMSOUND ROUTING APIs
-///////////////////////////////////
-#ifdef PULSE_CLIENT
-enum {
-       USE_PA_SINK_ALSA = 0,
-       USE_PA_SINK_A2DP,
-};
-EXPORT_API
-int mm_sound_route_set_system_policy (system_audio_route_t route)
-{
-       return MM_ERROR_NONE;
+       int err = MM_ERROR_NONE;
+
+       err = mm_sound_client_play_tone_with_stream_info(tone, stream_type, stream_id, volume, duration, handle);
+       if (err <0) {
+               debug_error("Failed to play sound\n");
+               return err;
+       }
+
+       return err;
+
 }
 
 
 EXPORT_API
-int mm_sound_route_get_system_policy (system_audio_route_t *route)
+int mm_sound_play_tone (MMSoundTone_t num, int volume_config, const double volume, const int duration, int *handle)
 {
-       return MM_ERROR_NONE;
+       return mm_sound_play_tone_ex (num, volume_config, volume, duration, handle, true);
 }
 
+///////////////////////////////////
+////     MMSOUND ROUTING APIs
+///////////////////////////////////
 
 EXPORT_API
 int mm_sound_route_get_a2dp_status (bool *connected, char **bt_name)
@@ -729,7 +567,7 @@ int mm_sound_route_get_a2dp_status (bool *connected, char **bt_name)
                return MM_ERROR_INVALID_ARGUMENT;
        }
 
-       ret = MMSoundClientIsBtA2dpOn (connected, bt_name);
+       ret = mm_sound_client_is_bt_a2dp_on (connected, bt_name);
        debug_msg ("connected=[%d] bt_name[%s]\n", *connected, *bt_name);
        if (ret < 0) {
                debug_error("MMSoundClientIsBtA2dpOn() Failed\n");
@@ -740,84 +578,13 @@ int mm_sound_route_get_a2dp_status (bool *connected, char **bt_name)
 }
 
 EXPORT_API
-int mm_sound_route_get_playing_device(system_audio_route_device_t *dev)
-{
-       mm_sound_device_in device_in = MM_SOUND_DEVICE_IN_NONE;
-       mm_sound_device_out device_out = MM_SOUND_DEVICE_OUT_NONE;
-
-       if(!dev)
-               return MM_ERROR_INVALID_ARGUMENT;
-
-       if(MM_ERROR_NONE != mm_sound_get_active_device(&device_in, &device_out)) {
-               debug_error("Can not get active device info\n");
-               return MM_ERROR_SOUND_INTERNAL;
-       }
-
-       switch(device_out)
-       {
-       case MM_SOUND_DEVICE_OUT_SPEAKER:
-               *dev = SYSTEM_AUDIO_ROUTE_PLAYBACK_DEVICE_HANDSET;
-               break;
-       case MM_SOUND_DEVICE_OUT_BT_A2DP:
-               *dev = SYSTEM_AUDIO_ROUTE_PLAYBACK_DEVICE_BLUETOOTH;
-               break;
-       case MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY:
-               *dev = SYSTEM_AUDIO_ROUTE_PLAYBACK_DEVICE_EARPHONE;
-               break;
-       default:
-               *dev = SYSTEM_AUDIO_ROUTE_PLAYBACK_DEVICE_NONE;
-               break;
-       }
-
-       return MM_ERROR_NONE;
-}
-
-EXPORT_API
-int mm_sound_route_add_change_callback(audio_route_policy_changed_callback_fn func, void *user_data)
-{
-       /* Deprecated */
-       return MM_ERROR_NONE;
-}
-
-EXPORT_API
-int mm_sound_route_remove_change_callback(void)
-{
-       /* Deprecated */
-       return MM_ERROR_NONE;
-}
-
-#endif /* PULSE_CLIENT */
-
-EXPORT_API
-int mm_sound_system_get_capture_status(system_audio_capture_status_t *status)
-{
-       int err = MM_ERROR_NONE;
-       int on_capture = 0;
-
-       if(!status) {
-               debug_error("invalid argument\n");
-               return MM_ERROR_INVALID_ARGUMENT;
-       }
-
-       /*  Check whether sound is capturing */
-//     vconf_get_int(VCONFKEY_SOUND_CAPTURE_STATUS, &on_capture); // need to check where it is set
-
-       if(on_capture)
-               *status = SYSTEM_AUDIO_CAPTURE_ACTIVE;
-       else
-               *status = SYSTEM_AUDIO_CAPTURE_NONE;
-
-       return MM_ERROR_NONE;
-}
-
-EXPORT_API
 int mm_sound_is_route_available(mm_sound_route route, bool *is_available)
 {
        int ret = MM_ERROR_NONE;
 
        debug_warning ("enter : route=[%x], is_available=[%p]\n", route, is_available);
 
-       if (!_mm_sound_is_route_valid(route)) {
+       if (!mm_sound_util_is_route_valid(route)) {
                debug_error("route is invalid %d\n", route);
                return MM_ERROR_INVALID_ARGUMENT;
        }
@@ -826,7 +593,7 @@ int mm_sound_is_route_available(mm_sound_route route, bool *is_available)
                return MM_ERROR_INVALID_ARGUMENT;
        }
 
-       ret = _mm_sound_client_is_route_available(route, is_available);
+       ret = mm_sound_client_is_route_available(route, is_available);
        if (ret < 0) {
                debug_error("Can not check given route is available, ret = %x\n", ret);
        } else {
@@ -846,7 +613,7 @@ int mm_sound_foreach_available_route_cb(mm_sound_available_route_cb available_ro
                return MM_ERROR_INVALID_ARGUMENT;
        }
 
-       ret = _mm_sound_client_foreach_available_route_cb(available_route_cb, user_data);
+       ret = mm_sound_client_foreach_available_route_cb(available_route_cb, user_data);
        if (ret < 0) {
                debug_error("Can not set foreach available route callback, ret = %x\n", ret);
        }
@@ -860,12 +627,12 @@ int mm_sound_set_active_route(mm_sound_route route)
        int ret = MM_ERROR_NONE;
 
        debug_warning ("enter : route=[%x]\n", route);
-       if (!_mm_sound_is_route_valid(route)) {
+       if (!mm_sound_util_is_route_valid(route)) {
                debug_error("route is invalid %d\n", route);
                return MM_ERROR_INVALID_ARGUMENT;
        }
 
-       ret = _mm_sound_client_set_active_route(route, true);
+       ret = mm_sound_client_set_active_route(route, true);
        if (ret < 0) {
                debug_error("Can not set active route, ret = %x\n", ret);
        } else {
@@ -880,7 +647,7 @@ int mm_sound_set_active_route_auto(void)
 {
        int ret = MM_ERROR_NONE;
 
-       ret = _mm_sound_client_set_active_route_auto();
+       ret = mm_sound_client_set_active_route_auto();
        if (ret < 0) {
                debug_error("fail to set active route auto, ret = %x\n", ret);
        } else {
@@ -896,12 +663,12 @@ int mm_sound_set_active_route_without_broadcast(mm_sound_route route)
        int ret = MM_ERROR_NONE;
 
        debug_warning ("enter : route=[%x]\n", route);
-       if (!_mm_sound_is_route_valid(route)) {
+       if (!mm_sound_util_is_route_valid(route)) {
                debug_error("route is invalid %d\n", route);
                return MM_ERROR_INVALID_ARGUMENT;
        }
 
-       ret = _mm_sound_client_set_active_route(route, false);
+       ret = mm_sound_client_set_active_route(route, false);
        if (ret < 0) {
                debug_error("Can not set active route, ret = %x\n", ret);
        } else {
@@ -921,7 +688,7 @@ int mm_sound_get_active_device(mm_sound_device_in *device_in, mm_sound_device_ou
                return MM_ERROR_INVALID_ARGUMENT;
        }
 
-       ret = _mm_sound_client_get_active_device(device_in, device_out);
+       ret = mm_sound_client_get_active_device(device_in, device_out);
        if (ret < 0) {
                debug_error("Can not add active device callback, ret = %x\n", ret);
        } else {
@@ -941,7 +708,7 @@ int mm_sound_get_audio_path(mm_sound_device_in *device_in, mm_sound_device_out *
                return MM_ERROR_INVALID_ARGUMENT;
        }
 
-       ret = _mm_sound_client_get_audio_path(device_in, device_out);
+       ret = mm_sound_client_get_audio_path(device_in, device_out);
        if (ret < 0) {
                debug_error("Can not add active device callback, ret = %x\n", ret);
        } else {
@@ -962,7 +729,7 @@ int mm_sound_add_active_device_changed_callback(const char *name, mm_sound_activ
                return MM_ERROR_INVALID_ARGUMENT;
        }
 
-       ret = _mm_sound_client_add_active_device_changed_callback(name, func, user_data);
+       ret = mm_sound_client_add_active_device_changed_callback(name, func, user_data);
        if (ret < 0) {
                debug_error("Can not add active device changed callback, ret = %x\n", ret);
        }
@@ -976,7 +743,7 @@ int mm_sound_remove_active_device_changed_callback(const char *name)
        int ret = MM_ERROR_NONE;
 
        debug_warning ("enter name %s \n", name);
-       ret = _mm_sound_client_remove_active_device_changed_callback(name);
+       ret = mm_sound_client_remove_active_device_changed_callback(name);
        if (ret < 0) {
                debug_error("Can not remove active device changed callback, ret = %x\n", ret);
        }
@@ -994,7 +761,7 @@ int mm_sound_add_available_route_changed_callback(mm_sound_available_route_chang
                return MM_ERROR_INVALID_ARGUMENT;
        }
 
-       ret = _mm_sound_client_add_available_route_changed_callback(func, user_data);
+       ret = mm_sound_client_add_available_route_changed_callback(func, user_data);
        if (ret < 0) {
                debug_error("Can not add available route changed callback, ret = %x\n", ret);
        }
@@ -1007,7 +774,7 @@ int mm_sound_remove_available_route_changed_callback(void)
 {
        int ret = MM_ERROR_NONE;
 
-       ret = _mm_sound_client_remove_available_route_changed_callback();
+       ret = mm_sound_client_remove_available_route_changed_callback();
        if (ret < 0) {
                debug_error("Can not remove available route changed callback, ret = %x\n", ret);
        }
@@ -1020,7 +787,7 @@ int mm_sound_set_sound_path_for_active_device(mm_sound_device_out device_out, mm
 {
        int ret = MM_ERROR_NONE;
 
-       ret = _mm_sound_client_set_sound_path_for_active_device(device_out, device_in);
+       ret = mm_sound_client_set_sound_path_for_active_device(device_out, device_in);
        if (ret < 0) {
                debug_error("Can not mm sound set sound path for active device, ret = %x\n", ret);
        }
@@ -1028,14 +795,332 @@ int mm_sound_set_sound_path_for_active_device(mm_sound_device_out device_out, mm
        return ret;
 }
 
-__attribute__ ((destructor))
-void __mmfsnd_finalize(void)
+
+EXPORT_API
+int mm_sound_test(int a, int b, int* getv)
 {
-       MMSoundClientCallbackFini();
+       int ret = MM_ERROR_NONE;
+
+       debug_log("mm_sound_test enter");
+       if (!getv) {
+               debug_error("argu null");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+       ret = mm_sound_client_test(a, b, getv);
+       if (ret < 0) {
+               debug_error("Can not mm sound test, ret = %x\n", ret);
+       }
+       debug_log("mm_sound_test leave");
+
+       return ret;
+}
+
+EXPORT_API
+int mm_sound_add_test_callback(mm_sound_test_cb func, void *user_data)
+{
+       int ret = MM_ERROR_NONE;
+
+       debug_log("mm_sound_add_test_callback enter");
+       if (!func) {
+               debug_error("argument is not valid\n");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       ret = mm_sound_client_add_test_callback(func, user_data);
+       if (ret < 0) {
+               debug_error("Can not add test callback, ret = %x\n", ret);
+       }
+       debug_log("mm_sound_add_test_callback leave");
+
+       return ret;
+}
+
+EXPORT_API
+int mm_sound_remove_test_callback(void)
+{
+       int ret = MM_ERROR_NONE;
+
+       debug_log("mm_sound_remove_test_callback enter");
+       ret = mm_sound_client_remove_test_callback();
+       if (ret < 0) {
+               debug_error("Can not remove test callback, ret = %x\n", ret);
+       }
+       debug_log("mm_sound_remove_test_callback leave");
+
+       return ret;
+}
+
+static void signal_callback(GDBusConnection *conn,
+                                                          const gchar *sender_name,
+                                                          const gchar *object_path,
+                                                          const gchar *interface_name,
+                                                          const gchar *signal_name,
+                                                          GVariant *parameters,
+                                                          gpointer user_data)
+{
+       int value=0;
+       const GVariantType* value_type;
+
+       debug_msg ("sender : %s, object : %s, interface : %s, signal : %s",
+                       sender_name, object_path, interface_name, signal_name);
+       if(g_variant_is_of_type(parameters, G_VARIANT_TYPE("(i)"))) {
+               g_variant_get(parameters, "(i)",&value);
+               debug_msg(" - value : %d\n", value);
+               _dbus_signal_callback (signal_name, value, user_data);
+       } else  {
+               value_type = g_variant_get_type(parameters);
+               debug_warning("signal type is %s", value_type);
+       }
+}
+
+int _convert_signal_name_str_to_enum (const char *name_str, mm_sound_signal_name_t *name_enum) {
+       int ret = MM_ERROR_NONE;
+
+       if (!name_str || !name_enum)
+               return MM_ERROR_INVALID_ARGUMENT;
+
+       if (!strncmp(name_str, "ReleaseInternalFocus", strlen("ReleaseInternalFocus"))) {
+               *name_enum = MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS;
+       } else {
+               ret = MM_ERROR_INVALID_ARGUMENT;
+               LOGE("not supported signal name(%s), err(0x%08x)", name_str, ret);
+       }
+       return ret;
+}
+
+void _dbus_signal_callback (const char *signal_name, int value, void *user_data)
+{
+       int ret = MM_ERROR_NONE;
+       mm_sound_signal_name_t signal;
+       subscribe_cb_t *subscribe_cb = (subscribe_cb_t*)user_data;
+
+       debug_fenter();
+
+       if (!subscribe_cb)
+               return;
+
+       ret = _convert_signal_name_str_to_enum(signal_name, &signal);
+       if (ret)
+               return;
+
+       debug_msg ("signal_name[%s], value[%d], user_data[0x%x]\n", signal_name, value, user_data);
+
+       if (subscribe_cb->signal_type == MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS) {
+               /* trigger the signal callback when it comes from the same process */
+               if (getpid() == ((value & 0xFFFF0000) >> 16)) {
+                       subscribe_cb->callback(signal, (value & 0x0000FFFF), subscribe_cb->user_data);
+               }
+       } else {
+               subscribe_cb->callback(signal, value, subscribe_cb->user_data);
+       }
+
+       debug_fleave();
+
+       return;
+}
+
+EXPORT_API
+int mm_sound_subscribe_signal(mm_sound_signal_name_t signal, unsigned int *subscribe_id, mm_sound_signal_callback callback, void *user_data)
+{
+       int ret = MM_ERROR_NONE;
+       GError *err = NULL;
+
+       subscribe_cb_t *subscribe_cb = NULL;
+
+       debug_fenter();
+
+       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_subscribe_cb_list_mutex, MM_ERROR_SOUND_INTERNAL);
+
+       if (signal < 0 || signal >= MM_SOUND_SIGNAL_MAX || !subscribe_id) {
+               debug_error ("invalid argument, signal(%d), subscribe_id(0x%p)", signal, subscribe_id);
+               ret = MM_ERROR_INVALID_ARGUMENT;
+               goto error;
+       }
+
+       subscribe_cb = malloc(sizeof(subscribe_cb_t));
+       if (!subscribe_cb) {
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto error;
+       }
+       memset(subscribe_cb, 0, sizeof(subscribe_cb_t));
+
+       g_type_init();
+
+       g_dbus_conn_mmsound = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+       if (!g_dbus_conn_mmsound && err) {
+               debug_error ("g_bus_get_sync() error (%s) ", err->message);
+               g_error_free (err);
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto error;
+       }
+
+       subscribe_cb->signal_type = signal;
+       subscribe_cb->callback = callback;
+       subscribe_cb->user_data = user_data;
+
+       *subscribe_id = g_dbus_connection_signal_subscribe(g_dbus_conn_mmsound,
+                       NULL, MM_SOUND_DBUS_INTERFACE, dbus_signal_name_str[signal], MM_SOUND_DBUS_OBJECT_PATH, NULL, 0,
+                       signal_callback, subscribe_cb, NULL);
+       if (*subscribe_id == 0) {
+               debug_error ("g_dbus_connection_signal_subscribe() error (%d)", *subscribe_id);
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto sig_error;
+       }
+
+       subscribe_cb->id = *subscribe_id;
+
+       g_subscribe_cb_list = g_list_append(g_subscribe_cb_list, subscribe_cb);
+       if (g_subscribe_cb_list) {
+               debug_log("new subscribe_cb(0x%x)[user_callback(0x%x), subscribe_id(%u)] is added\n", subscribe_cb, subscribe_cb->callback, subscribe_cb->id);
+       } else {
+               debug_error("g_list_append failed\n");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto error;
+       }
+
+       MMSOUND_LEAVE_CRITICAL_SECTION(&g_subscribe_cb_list_mutex);
+
+       debug_fleave();
+
+       return ret;
+
+sig_error:
+       g_dbus_connection_signal_unsubscribe(g_dbus_conn_mmsound, *subscribe_id);
+       g_object_unref(g_dbus_conn_mmsound);
+
+error:
+       if (subscribe_cb)
+               free (subscribe_cb);
+
+       MMSOUND_LEAVE_CRITICAL_SECTION(&g_subscribe_cb_list_mutex);
+
+       return ret;
+}
+
+EXPORT_API
+void mm_sound_unsubscribe_signal(unsigned int subscribe_id)
+{
+       GList *list = NULL;
+       subscribe_cb_t *subscribe_cb = NULL;
+
+       debug_fenter();
+
+       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_subscribe_cb_list_mutex, MM_ERROR_SOUND_INTERNAL);
+
+       if (g_dbus_conn_mmsound && subscribe_id) {
+               g_dbus_connection_signal_unsubscribe(g_dbus_conn_mmsound, subscribe_id);
+               g_object_unref(g_dbus_conn_mmsound);
+               for (list = g_subscribe_cb_list; list != NULL; list = list->next) {
+                       subscribe_cb = (subscribe_cb_t *)list->data;
+                       if (subscribe_cb && (subscribe_cb->id == subscribe_id)) {
+                               g_subscribe_cb_list = g_list_remove(g_subscribe_cb_list, subscribe_cb);
+                               debug_log("subscribe_cb(0x%x) is removed\n", subscribe_cb);
+                               free (subscribe_cb);
+                       }
+               }
+       }
+
+       MMSOUND_LEAVE_CRITICAL_SECTION(&g_subscribe_cb_list_mutex);
+
+       debug_fleave();
+}
+
+EXPORT_API
+int mm_sound_send_signal(mm_sound_signal_name_t signal, int value)
+{
+       int ret = MM_ERROR_NONE;
+       GError *err = NULL;
+       GDBusConnection *conn = NULL;
+       gboolean dbus_ret = TRUE;
+
+       debug_fenter();
+
+       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_subscribe_cb_list_mutex, MM_ERROR_SOUND_INTERNAL);
+
+       if (signal < 0 || signal >= MM_SOUND_SIGNAL_MAX) {
+               debug_error ("invalid argument, signal(%d)", signal);
+               ret = MM_ERROR_INVALID_ARGUMENT;
+               goto error;
+       }
+
+       conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+       if (!conn && err) {
+               debug_error ("g_bus_get_sync() error (%s)", err->message);
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto error;
+       }
+
+       g_dbus_signal_values[signal] = value;
+       if (signal == MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS) {
+               /* trigger the signal callback when it comes from the same process */
+               value |= ((int)getpid() << 16);
+       }
+       dbus_ret = g_dbus_connection_emit_signal (conn,
+                               NULL, MM_SOUND_DBUS_OBJECT_PATH, MM_SOUND_DBUS_INTERFACE, dbus_signal_name_str[signal],
+                               g_variant_new ("(i)", value),
+                               &err);
+       if (!dbus_ret && err) {
+               debug_error ("g_dbus_connection_emit_signal() error (%s)", err->message);
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto error;
+       }
+
+       dbus_ret = g_dbus_connection_flush_sync(conn, NULL, &err);
+       if (!dbus_ret && err) {
+               debug_error ("g_dbus_connection_flush_sync() error (%s)", err->message);
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto error;
+       }
+
+       g_object_unref(conn);
+       debug_msg ("sending signal[%s], value[%d] success", dbus_signal_name_str[signal], value);
+
+       MMSOUND_LEAVE_CRITICAL_SECTION(&g_subscribe_cb_list_mutex);
+
+       debug_fleave();
+
+       return ret;
+
+error:
+       if (err)
+               g_error_free (err);
+       if (conn)
+               g_object_unref(conn);
+
+       MMSOUND_LEAVE_CRITICAL_SECTION(&g_subscribe_cb_list_mutex);
+
+       return ret;
+}
+
+EXPORT_API
+int mm_sound_get_signal_value(mm_sound_signal_name_t signal, int *value)
+{
+       int ret = MM_ERROR_NONE;
+
+       debug_fenter();
+
+       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_subscribe_cb_list_mutex, MM_ERROR_SOUND_INTERNAL);
+
+       *value = g_dbus_signal_values[signal];
+
+       MMSOUND_LEAVE_CRITICAL_SECTION(&g_subscribe_cb_list_mutex);
+
+       debug_fleave();
+
+       return ret;
 }
 
 __attribute__ ((constructor))
-void __mmfsnd_initialize(void)
+static void _mm_sound_initialize(void)
 {
+       mm_sound_client_initialize();
        /* Will be Fixed */
 }
+
+__attribute__ ((destructor))
+static void _mm_sound_finalize(void)
+{
+       mm_sound_client_finalize();
+}
+
+
index 74c7bb6..043edee 100644 (file)
 #include <mm_sound.h>
 #include <mm_sound_private.h>
 
-#define VCONF_BOOTING "memory/private/sound/booting"
+#define KEYTONE_PATH        "/tmp/keytone"  /* Keytone pipe path */
+#define FILE_FULL_PATH 1024                            /* File path lenth */
 #define MAX_RETRY 40
 #define RETRY_INTERVAL_USEC 50000
 
+#define ROLE_NAME_LEN 64                               /* Role name length */
+#define VOLUME_GAIN_TYPE_LEN 64                /* Volume gain type length */
+
+typedef struct {
+       char filename[FILE_FULL_PATH];
+       char role[ROLE_NAME_LEN];
+       char volume_gain_type[VOLUME_GAIN_TYPE_LEN];
+} ipc_t;
+
+#define MMSOUND_STRNCPY(dst,src,size)\
+do { \
+       if(src != NULL && dst != NULL && size > 0) {\
+               strncpy(dst,src,size); \
+               dst[size-1] = '\0';\
+       } else if(dst == NULL) {       \
+               debug_error("STRNCPY ERROR: Destination String is NULL\n"); \
+       }       \
+       else if(size <= 0) {      \
+               debug_error("STRNCPY ERROR: Destination String is NULL\n"); \
+       }       \
+       else {    \
+               debug_error("STRNCPY ERROR: Destination String is NULL\n"); \
+       }       \
+} while(0)
+
 EXPORT_API
 int mm_sound_boot_ready(int timeout_sec)
 {
-    struct timespec ts;
-    sem_t* sem = NULL;
-
-    debug_msg("[BOOT] check for sync....");
-    if ((sem = sem_open ("booting-sound", O_CREAT, 0660, 0))== SEM_FAILED) {
-        debug_error ("error creating sem : %d", errno);
-        return -1;
-    }
-
-    debug_msg("[BOOT] start to wait ready....timeout is set to %d sec", timeout_sec);
-    clock_gettime(CLOCK_REALTIME, &ts);
-    ts.tv_sec += timeout_sec;
-
-    if (sem_timedwait(sem, &ts) == -1) {
-        if (errno == ETIMEDOUT)
-            debug_warning("[BOOT] timeout!\n");
-    } else {
-        debug_msg("[BOOT] ready wait success!!!!");
-        sem_post(sem);
-    }
-
-    return 0;
+       struct timespec ts;
+       sem_t* sem = NULL;
+
+       debug_msg("[BOOT] check for sync....");
+       if ((sem = sem_open ("booting-sound", O_CREAT, 0660, 0))== SEM_FAILED) {
+               debug_error ("error creating sem : %d", errno);
+               return -1;
+       }
+
+       debug_msg("[BOOT] start to wait ready....timeout is set to %d sec", timeout_sec);
+       clock_gettime(CLOCK_REALTIME, &ts);
+       ts.tv_sec += timeout_sec;
+
+       if (sem_timedwait(sem, &ts) == -1) {
+               if (errno == ETIMEDOUT)
+                       debug_warning("[BOOT] timeout!\n");
+       } else {
+               debug_msg("[BOOT] ready wait success!!!!");
+               sem_post(sem);
+       }
+
+       return 0;
 }
 
 EXPORT_API
 int mm_sound_boot_play_sound(char* path)
 {
-    debug_msg("[BOOT] set vconf to play boot sound [%s]!!!!", path);
-    if (path == NULL)
-        return -1;
+       int err = 0;
+       int fd = -1;
+       int size = 0;
+       ipc_t data = {{0,},{0,},{0,}};
 
-    return vconf_set_str(VCONF_BOOTING, path);
-}
+       debug_msg("[BOOT] play boot sound [%s]!!!!", path);
+       if (path == NULL)
+               return MM_ERROR_SOUND_INVALID_FILE;
+
+       /* Check whether file exists */
+       fd = open(path, O_RDONLY);
+       if (fd == -1) {
+               debug_error("file open failed with [%s][%d]\n", strerror(errno), errno);
+               switch (errno) {
+               case ENOENT:
+                       return MM_ERROR_SOUND_FILE_NOT_FOUND;
+               default:
+                       return MM_ERROR_SOUND_INTERNAL;
+               }
+       }
+       close(fd);
+       fd = -1;
+
+       /* Open PIPE */
+       fd = open(KEYTONE_PATH, O_WRONLY | O_NONBLOCK);
+       if (fd == -1) {
+               debug_error("Fail to open pipe\n");
+               return MM_ERROR_SOUND_FILE_NOT_FOUND;
+       }
 
+       MMSOUND_STRNCPY(data.filename, path, FILE_FULL_PATH);
+       MMSOUND_STRNCPY(data.role, "system", ROLE_NAME_LEN);
+       MMSOUND_STRNCPY(data.volume_gain_type, "booting", VOLUME_GAIN_TYPE_LEN);
 
+       debug_msg("filepath=[%s], role=[%s], volume_gain_type=[%s]\n", data.filename, data.role, data.volume_gain_type);
+       size = sizeof(ipc_t);
+
+       /* Write to PIPE */
+       err = write(fd, &data, size);
+       if (err < 0) {
+               debug_error("Fail to write data: [%s][%d]\n", strerror(errno), errno);
+               close(fd);
+               return MM_ERROR_SOUND_INTERNAL;
+       }
+       /* Close PIPE */
+       close(fd);
+
+       return MM_ERROR_NONE;
+}
index 6450f6d..100fc46 100644 (file)
 
 #include <mm_error.h>
 #include <mm_debug.h>
+//#include <glib.h>
 
 #include "include/mm_sound.h"
 #include "include/mm_sound_msg.h"
 #include "include/mm_sound_client.h"
+#include "include/mm_sound_client_dbus.h"
 #include "include/mm_sound_common.h"
 #include "include/mm_sound_device.h"
+#ifdef USE_FOCUS
+#include "include/mm_sound_focus.h"
+#endif
 
 #include <mm_session.h>
 #include <mm_session_private.h>
 #include <sys/poll.h>
 #endif
 
-#define MEMTYPE_SUPPORT_MAX (1024 * 1024) /* 1MB */
-#define MEMTYPE_TRANS_PER_MAX (128 * 1024) /* 128K */
-
-int g_msg_scsnd;       /* global msg queue id sound client snd */
-int g_msg_scrcv;       /* global msg queue id sound client rcv */
-int g_msg_sccb;                /* global msg queue id sound client callback */
+#define CLIENT_HANDLE_MAX 256
 
 /* global variables for device list */
-static GList *g_device_list = NULL;
+//static GList *g_device_list = NULL;
 static mm_sound_device_list_t g_device_list_t;
 static pthread_mutex_t g_device_list_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t g_id_mutex = PTHREAD_MUTEX_INITIALIZER;
 
-/* callback */
-struct __callback_param
-{
-       mm_sound_stop_callback_func     callback;
-    void                    *data;
-};
-
-pthread_t g_thread;
-static int g_exit_thread = 0;
-int g_thread_id = -1;
-int g_mutex_initted = -1;
-pthread_mutex_t g_thread_mutex;
-
-static void* callbackfunc(void *param);
-
-/* manage IPC (msg contorl) */
-static int __MMIpcCBSndMsg(mm_ipc_msg_t *msg);
-static int __MMIpcRecvMsg(int msgtype, mm_ipc_msg_t *msg);
-static int __MMIpcSndMsg(mm_ipc_msg_t *msg);
-static int __MMIpcCBRecvMsg(int msgtype, mm_ipc_msg_t *msg);
-static int __MMSoundGetMsg(void);
-
-int MMSoundClientInit(void)
+int mm_sound_client_initialize(void)
 {
        int ret = MM_ERROR_NONE;
        debug_fenter();
 
+       g_type_init();
+       mm_sound_client_dbus_initialize();
+
        debug_fleave();
        return ret;
 }
 
-int MMSoundClientCallbackFini(void)
+int mm_sound_client_finalize(void)
 {
-       mm_ipc_msg_t msgsnd={0,};
        int ret = MM_ERROR_NONE;
 
        debug_fenter();
 
-       /* When the the callback thread is not created, do not wait destroy thread */
-       /* g_thread_id is initialized : -1 */
-       /* g_thread_id is set to 0, when the callback thread is created */
-       if (g_thread_id != -1)
-       {
-               msgsnd.sound_msg.msgtype = MM_SOUND_MSG_INF_DESTROY_CB;
-               msgsnd.sound_msg.msgid = getpid();
-               ret = __MMIpcCBSndMsg(&msgsnd);
-               if (ret != MM_ERROR_NONE)
-               {
-                       debug_critical("[Client] Fail to send message\n");
-               }
-               pthread_join(g_thread, 0);
-       }
+       mm_sound_client_dbus_finalize();
 
-       if (g_mutex_initted != -1)
-       {
-               pthread_mutex_destroy(&g_thread_mutex);
-               g_mutex_initted = -1;
-       }
        debug_fleave();
        return MM_ERROR_NONE;
 }
 
-#if defined(__GSOURCE_CALLBACK__)
-gboolean sndcb_fd_check(GSource * source)
+int mm_sound_client_is_route_available(mm_sound_route route, bool *is_available)
 {
-       GSList *fd_list;
-       fd_list = source->poll_fds;
-       GPollFD* temp;
+       int ret = MM_ERROR_NONE;
+       debug_fenter();
 
-       do
-       {
-               temp = (GPollFD*)fd_list->data;
-               if (temp->revents & (POLLIN|POLLPRI))
-                       return TRUE;
-               fd_list = fd_list->next;
-       }while(fd_list);
+       ret = mm_sound_client_dbus_is_route_available(route, is_available);
 
-       return FALSE; /* there is no change in any fd state */
-}
+       debug_fleave();
+       return ret;
 
-gboolean sndcb_fd_prepare(GSource *source, gint *timeout)
-{
-       return FALSE;
 }
 
-gboolean sndcb_fd_dispatch(GSource *source,    GSourceFunc callback, gpointer user_data)
-{
-       callback(user_data);
-       return TRUE;
-}
-#endif
-gboolean RunCallback(gpointer data)
+int mm_sound_client_foreach_available_route_cb(mm_sound_available_route_cb available_route_cb, void *user_data)
 {
-       mm_ipc_msg_t* msg = NULL;
-
-       debug_msg("[Client] execute mm_sound stop callback function\n");
+       int ret = MM_ERROR_NONE;
+       debug_fenter();
 
-       msg = (mm_ipc_msg_t*)data;
-       ((mm_sound_stop_callback_func)msg->sound_msg.callback)(msg->sound_msg.cbdata, msg->sound_msg.handle);
+       ret = mm_sound_client_dbus_foreach_available_route_cb(available_route_cb, user_data);
 
-       return FALSE;
+       debug_fleave();
+       return ret;
 }
 
-gboolean _volume_change_cb(gpointer data)
+int mm_sound_client_set_active_route(mm_sound_route route, bool need_broadcast)
 {
-       mm_ipc_msg_t* msg = NULL;
+       int ret = MM_ERROR_NONE;
+       debug_fenter();
 
-       if (!data) {
-               debug_error("[Client] NULL param\n");
-               return FALSE;
-       }
-       msg = (mm_ipc_msg_t*)data;
+       ret = mm_sound_client_dbus_set_active_route(route, need_broadcast);
 
-       ((mm_sound_volume_changed_cb)msg->sound_msg.callback)(msg->sound_msg.type, msg->sound_msg.val, msg->sound_msg.cbdata);
+       debug_fleave();
+       return ret;
 
-       if(msg != NULL) {
-               free(msg);
-               msg = NULL;
-       }
-       return FALSE;
 }
 
-static void* callbackfunc(void *param)
+int mm_sound_client_set_active_route_auto(void)
 {
-       int ret = MM_ERROR_SOUND_INTERNAL;
-       mm_ipc_msg_t *msgrcv = NULL;
-       int run = 1;
-       int instance;
-
+       int ret = MM_ERROR_NONE;
        debug_fenter();
 
-       instance = getpid();
-       debug_msg("[Client] callback thread for [%d] is created\n", instance);
-
-       msgrcv = (mm_ipc_msg_t*)malloc(sizeof(mm_ipc_msg_t));
-       if(NULL == msgrcv)
-       {
-               debug_critical("[Client] Failed to memory allocation\n");
-               return NULL;
-       }
+       ret = mm_sound_client_dbus_set_active_route_auto();
 
-       while(run)
-       {
-#if defined(__GSOURCE_CALLBACK__)
-               int eventFd = 0;
-               gchar* eventFile = NULL;
-               GSource* cmd_fd_gsrc = NULL;
-               GSourceFuncs *src_funcs = NULL;         // handler function
-               guint gsource_handle;
-               GPollFD *g_fd_cmd = NULL;                       // file descriptor
-#endif
+       debug_fleave();
+       return ret;
 
-               debug_msg("[Client] Waiting message\n");
-               ret = __MMIpcCBRecvMsg(instance, msgrcv);
-               if (ret != MM_ERROR_NONE)
-               {
-                       debug_error("[Client] Fail to receive msg in callback\n");
-                       continue;
-               }
+}
 
-               debug_msg("[Client] Receive msgtype : [%d]\n", msgrcv->sound_msg.msgtype);
+int mm_sound_client_get_active_device(mm_sound_device_in *device_in, mm_sound_device_out *device_out)
+{
 
-               switch (msgrcv->sound_msg.msgtype)
-               {
-               case MM_SOUND_MSG_INF_STOP_CB:
-                       debug_msg("[Client] callback : %p, data : %p\n", msgrcv->sound_msg.callback, msgrcv->sound_msg.cbdata);
+       int ret = MM_ERROR_NONE;
+       debug_fenter();
 
-                       if (msgrcv->sound_msg.callback)
-                       {
-#if defined(__DIRECT_CALLBACK__)
-                               ((mm_sound_stop_callback_func)msgrcv->sound_msg.callback)(msgrcv->sound_msg.cbdata, msgrcv->sound_msg.handle);
-#elif defined(__GIDLE_CALLBACK__)
-                               guint eventid = 0;
-                               eventid = g_idle_add((GSourceFunc)RunCallback, (gpointer)msgrcv);
-                               debug_msg("[Client] Event Source ID : %d\n", eventid);
-
-#elif defined(__GSOURCE_CALLBACK__)
-                               char eventBuf[3]="OK";
-                               ////////////////////////
-                               // 0. Make event source
-                               eventFile = g_strdup_printf("/tmp/%d_0x%08x_0x%08x", instance, (unsigned int)msgrcv->sound_msg.callback, (unsigned int)msgrcv->sound_msg.cbdata);
-                               eventFd = open(eventFile, O_RDWR|O_CREAT);
-                               if(eventFd == -1)
-                               {
-                                       debug_critical("Event File creation failed\n");
-                                       break;
-                               }
-
-                               // 1. make GSource Object
-                               src_funcs = (GSourceFuncs *)g_malloc(sizeof(GSourceFuncs));
-                               if(!src_funcs){
-                                       debug_error("MMSoundCallback :  g_malloc failed on g_src_funcs");
-                                       break;
-                               }
-                               src_funcs->prepare = sndcb_fd_prepare;
-                               src_funcs->check = sndcb_fd_check;
-                               src_funcs->dispatch = sndcb_fd_dispatch;
-                               src_funcs->finalize = NULL;
-                               cmd_fd_gsrc = g_source_new(src_funcs,sizeof(GSource));
-                               if(!cmd_fd_gsrc){
-                                       debug_error("MMSoundCallback : g_malloc failed on m_readfd");
-                                       break;
-                               }
-
-                               // 2. add file description which used in g_loop()
-                               g_fd_cmd = (GPollFD*)g_malloc(sizeof(GPollFD));
-                               g_fd_cmd->fd = eventFd;
-                               g_fd_cmd->events = POLLIN|POLLPRI;
-
-                               // 3. combine g_source object and file descriptor
-                               g_source_add_poll(cmd_fd_gsrc,g_fd_cmd);
-                               gsource_handle = g_source_attach(cmd_fd_gsrc, NULL);
-                               if(!gsource_handle){
-                                       debug_error("MMSoundCallback : Error: Failed to attach the source to context");
-                                       break;
-                               }
-
-                               // 4. set callback
-                               g_source_set_callback(cmd_fd_gsrc,RunCallback,(gpointer)g_fd_cmd,NULL);
-                               debug_msg("MMSoundCallback : g_source_set_callback() done\n")
-
-                               // 5. Set Event
-                               write(eventFd, eventBuf, sizeof(eventBuf));
-                               sleep(1);
-                               // 6. Cleanup
-                               close(eventFd);
-                               unlink(eventFile);
-                               g_source_remove_poll(cmd_fd_gsrc, g_fd_cmd);
-                               g_source_remove(gsource_handle);
-                               if(g_fd_cmd)
-                                       free(g_fd_cmd);
-                               if(src_funcs)
-                                       free(src_funcs);
-                               if(eventFile)
-                                       g_free(eventFile);
-                               ////////////////////////
-#endif
-                       }
-                       break;
-               case MM_SOUND_MSG_INF_DESTROY_CB:
-                       run = 0;
-                       break;
-
-               case MM_SOUND_MSG_INF_DEVICE_CONNECTED_CB:
-                       debug_msg("[Client] device handle : %x, is_connected : %d, callback : %p, data : %p\n",
-                               &msgrcv->sound_msg.device_handle, msgrcv->sound_msg.is_connected, msgrcv->sound_msg.callback, msgrcv->sound_msg.cbdata);
-                       if (msgrcv->sound_msg.callback) {
-                               ((mm_sound_device_connected_cb)msgrcv->sound_msg.callback)(&msgrcv->sound_msg.device_handle, msgrcv->sound_msg.is_connected, msgrcv->sound_msg.cbdata);
-                       }
-                       break;
+       ret = mm_sound_client_dbus_get_active_device(device_in, device_out);
 
-               case MM_SOUND_MSG_INF_DEVICE_INFO_CHANGED_CB:
-                       debug_msg("[Client] device handle : %x, changed_info_type : %d, callback : %p, data : %p\n",
-                               &msgrcv->sound_msg.device_handle, msgrcv->sound_msg.changed_device_info_type, msgrcv->sound_msg.callback, msgrcv->sound_msg.cbdata);
-                       if (msgrcv->sound_msg.callback) {
-                               ((mm_sound_device_info_changed_cb)msgrcv->sound_msg.callback)(&msgrcv->sound_msg.device_handle, msgrcv->sound_msg.changed_device_info_type, msgrcv->sound_msg.cbdata);
-                       }
-                       break;
+       debug_fleave();
+       return ret;
+}
 
-               case MM_SOUND_MSG_INF_ACTIVE_DEVICE_CB:
-                       debug_msg("[Client] device_in : %d, device_out : %d\n", msgrcv->sound_msg.device_in, msgrcv->sound_msg.device_out);
-                       debug_log("[Client] callback : %p, data : %p\n", msgrcv->sound_msg.callback, msgrcv->sound_msg.cbdata);
+int mm_sound_client_add_active_device_changed_callback(const char *name, mm_sound_active_device_changed_cb func, void* user_data)
+{
+       int ret = MM_ERROR_NONE;
+       debug_fenter();
 
-                       if (msgrcv->sound_msg.callback)
-                       {
-                               ((mm_sound_active_device_changed_cb)msgrcv->sound_msg.callback)(msgrcv->sound_msg.device_in, msgrcv->sound_msg.device_out, msgrcv->sound_msg.cbdata);
-                       }
-                       break;
-               case MM_SOUND_MSG_INF_AVAILABLE_ROUTE_CB:
-                       debug_log("[Client] callback : %p, data : %p\n", msgrcv->sound_msg.callback, msgrcv->sound_msg.cbdata);
+       ret = mm_sound_client_dbus_add_active_device_changed_callback(name, func, user_data);
 
-                       if (msgrcv->sound_msg.callback)
-                       {
-                               int route_index;
-                               mm_sound_route route;
-
-                               int list_count = sizeof(msgrcv->sound_msg.route_list) / sizeof(int);
-
-                               for (route_index = list_count-1; route_index >= 0; route_index--) {
-                                       route = msgrcv->sound_msg.route_list[route_index];
-                                       if (route == 0)
-                                               continue;
-                                       if (msgrcv->sound_msg.is_available) {
-                                               debug_msg("[Client] available route : 0x%x\n", route);
-                                       } else {
-                                               debug_msg("[Client] unavailable route : 0x%x\n", route);
-                                       }
-                                       ((mm_sound_available_route_changed_cb)msgrcv->sound_msg.callback)(route, msgrcv->sound_msg.is_available, msgrcv->sound_msg.cbdata);
-
-                                       if (route == MM_SOUND_ROUTE_INOUT_HEADSET || route == MM_SOUND_ROUTE_IN_MIC_OUT_HEADPHONE) {
-                                               debug_msg("[Client] no need to proceed further more....\n");
-                                               break;
-                                       }
-                               }
-                       }
-                       break;
-               case MM_SOUND_MSG_INF_VOLUME_CB:
-                       debug_msg("[Client] type: %d, volume value : %d, callback : %p, data : %p\n", msgrcv->sound_msg.type, msgrcv->sound_msg.val, msgrcv->sound_msg.callback, msgrcv->sound_msg.cbdata);
+       debug_fleave();
+       return ret;
+}
 
-                       if (msgrcv->sound_msg.callback)
-                       {
-                               mm_ipc_msg_t* tmp = NULL;
-                               tmp = (mm_ipc_msg_t*)malloc(sizeof(mm_ipc_msg_t));
-                               if(tmp == NULL) {
-                                       debug_critical("Fail malloc");
-                                       break;
-                               }
-                               memcpy(tmp, msgrcv, sizeof(mm_ipc_msg_t));
-                               g_idle_add((GSourceFunc)_volume_change_cb, (gpointer)tmp);
-                       }
-                       break;
+int mm_sound_client_remove_active_device_changed_callback(const char *name)
+{
+       int ret = MM_ERROR_NONE;
+       debug_fenter();
 
-               default:
-                       /* Unexpected msg */
-                       debug_msg("Receive wrong msg in callback func\n");
-                       break;
-               }
-       }
-       if(msgrcv) {
-               free(msgrcv);
-       }
+       ret = mm_sound_client_dbus_remove_active_device_changed_callback(name);
 
-       g_exit_thread = 1;
-       debug_msg("[Client] callback [%d] is leaved\n", instance);
        debug_fleave();
-       return NULL;
+       return ret;
 }
-
-static int __mm_sound_client_get_msg_queue(void)
+int mm_sound_client_add_available_route_changed_callback(mm_sound_available_route_changed_cb func, void* user_data)
 {
        int ret = MM_ERROR_NONE;
+       debug_fenter();
 
-       if (g_mutex_initted == -1)
-       {
-               if(pthread_mutex_init(&g_thread_mutex, NULL)) {
-                       debug_error("pthread_mutex_init failed\n");
-                       return MM_ERROR_SOUND_INTERNAL;
-               }
-               debug_log("[Client] mutex initialized. \n");
-               g_mutex_initted = 1;
-
-               /* Get msg queue id */
-               ret = __MMSoundGetMsg();
-               if(ret != MM_ERROR_NONE)
-               {
-                       debug_error("[Client] Fail to get message queue id. sound_server is not initialized.\n");
-                       pthread_mutex_destroy(&g_thread_mutex);
-                       g_mutex_initted = -1;
-               }
-       }
+       ret = mm_sound_client_dbus_add_available_route_changed_callback(func, user_data);
 
+       debug_fleave();
        return ret;
 }
 
-int MMSoundClientPlayTone(int number, int volume_config, double volume, int time, int *handle, bool enable_session)
+int mm_sound_client_remove_available_route_changed_callback(void)
 {
-       mm_ipc_msg_t msgrcv = {0,};
-       mm_ipc_msg_t msgsnd = {0,};
-
        int ret = MM_ERROR_NONE;
-       int instance = -1;      /* instance is unique to communicate with server : client message queue filter type */
-
        debug_fenter();
 
-       ret = __mm_sound_client_get_msg_queue();
-       if (ret  != MM_ERROR_NONE) {
-               return ret;
-       }
-       /* read session information */
-       int session_type = MM_SESSION_TYPE_MEDIA;
-       int session_options = 0;
-       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;
-                       }
-               }
-       }
+       ret = mm_sound_client_dbus_remove_available_route_changed_callback();
 
-       instance = getpid();
-       debug_log("[Client] pid for client ::: [%d]\n", instance);
+       debug_fleave();
+       return ret;
+}
 
-       pthread_mutex_lock(&g_thread_mutex);
+int mm_sound_client_set_sound_path_for_active_device(mm_sound_device_out device_out, mm_sound_device_in device_in)
+{
+       int ret = MM_ERROR_NONE;
+       debug_fenter();
 
-       /* Send msg */
-       debug_msg("[Client] Input number : %d\n", number);
-       /* Send req memory */
-       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_DTMF;
-       msgsnd.sound_msg.msgid = instance;
-       msgsnd.sound_msg.session_type = session_type;       //session type
-       msgsnd.sound_msg.session_options = session_options; //session options
-       msgsnd.sound_msg.volume = volume;                   //This does not effect anymore
-       msgsnd.sound_msg.volume_config = volume_config;
-       msgsnd.sound_msg.tone = number;
-       msgsnd.sound_msg.handle = -1;
-       msgsnd.sound_msg.repeat = time;
-       msgsnd.sound_msg.enable_session = enable_session;
-
-       ret = __MMIpcSndMsg(&msgsnd);
-       if (ret != MM_ERROR_NONE)
-       {
-               debug_error("[Client] Fail to send msg\n");
-               goto cleanup;
-       }
+       ret = mm_sound_client_dbus_set_sound_path_for_active_device(device_out, device_in);
 
-       /* Receive */
-       ret = __MMIpcRecvMsg(instance, &msgrcv);
-       if (ret != MM_ERROR_NONE)
-       {
-               debug_error("[Client] Fail to recieve msg\n");
-               goto cleanup;
-       }
+       debug_fleave();
+       return ret;
+}
 
-       switch (msgrcv.sound_msg.msgtype)
-       {
-       case MM_SOUND_MSG_RES_DTMF:
-               *handle = msgrcv.sound_msg.handle;
-               if(*handle == -1) {
-                       debug_error("[Client] The handle is not get\n");
-               } else {
-                       debug_msg("[Client] Success to play sound sound handle : [%d]\n", *handle);
-               }
+void mm_sound_convert_volume_type_to_stream_type(int volume_type, char *stream_type)
+{
+       switch (volume_type) {
+       case VOLUME_TYPE_SYSTEM:
+               strncpy(stream_type, "system", MM_SOUND_STREAM_TYPE_LEN);
                break;
-
-       case MM_SOUND_MSG_RES_ERROR:
-               debug_error("[Client] Error occurred \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
+       case VOLUME_TYPE_NOTIFICATION:
+               strncpy(stream_type, "notification", MM_SOUND_STREAM_TYPE_LEN);
+               break;
+       case VOLUME_TYPE_ALARM:
+               strncpy(stream_type, "alarm", MM_SOUND_STREAM_TYPE_LEN);
+               break;
+       case VOLUME_TYPE_RINGTONE:
+               strncpy(stream_type, "ringtone-voip", MM_SOUND_STREAM_TYPE_LEN);
+               break;
+       case VOLUME_TYPE_MEDIA:
+               strncpy(stream_type, "media", MM_SOUND_STREAM_TYPE_LEN);
+               break;
+       case VOLUME_TYPE_CALL:
+               strncpy(stream_type, "system", MM_SOUND_STREAM_TYPE_LEN);
+               break;
+       case VOLUME_TYPE_VOIP:
+               strncpy(stream_type, "voip", MM_SOUND_STREAM_TYPE_LEN);
+               break;
+       case VOLUME_TYPE_VOICE:
+               strncpy(stream_type, "voice-recognition", MM_SOUND_STREAM_TYPE_LEN);
                break;
-
        default:
-               debug_critical("[Client] Unexpected state with communication \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
+               strncpy(stream_type, "media", MM_SOUND_STREAM_TYPE_LEN);
                break;
        }
-cleanup:
-       pthread_mutex_unlock(&g_thread_mutex);
 
-       debug_fleave();
-       return ret;
+       debug_error("volume type (%d) converted to stream type (%s)", volume_type, stream_type);
+
 }
 
+/*****************************************************************************************
+                           DBUS SUPPORTED FUNCTIONS
+******************************************************************************************/
 
-int MMSoundClientPlaySound(MMSoundPlayParam *param, int tone, int keytone, int *handle)
+int mm_sound_client_play_tone(int number, int volume_config, double volume, int time, int *handle, bool enable_session)
 {
-       mm_ipc_msg_t msgrcv = {0,};
-       mm_ipc_msg_t msgsnd = {0,};
-       unsigned char* sharedmem = NULL;
-
        int ret = MM_ERROR_NONE;
-       int instance = -1;      /* instance is unique to communicate with server : client message queue filter type */
+//      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;
+        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;
+                        }
+                }
+        }
+
+        // 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_client_dbus_play_tone(number, time, volume, volume_config,
+                                       session_type, session_options, getpid(), enable_session, handle, stream_type, -1);
+
+       debug_fleave();
+       return ret;
+}
 
-       char shm_name[512];
-       void *mmap_buf = NULL;
-       static int keybase = 0;
-       int shm_fd = -1;
+int mm_sound_client_play_tone_with_stream_info(int tone, char *stream_type, int stream_id, double volume, int duration, int *handle)
+{
+       int ret = MM_ERROR_NONE;
 
        debug_fenter();
-       memset(shm_name, 0, sizeof(shm_name));
 
-       ret = __mm_sound_client_get_msg_queue();
-       if (ret  != MM_ERROR_NONE) {
-               return ret;
-       }
-       /* read session information */
+       ret = mm_sound_client_dbus_play_tone_with_stream_info(getpid(), tone, stream_type, stream_id, volume, duration, handle);
+
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_client_play_sound(MMSoundPlayParam *param, int tone, int keytone, int *handle)
+{
+       int ret = MM_ERROR_NONE;
        int session_type = MM_SESSION_TYPE_MEDIA;
        int session_options = 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, };
+
+       debug_fenter();
+
+       /* read session information */
 
        if (param->skip_session == false) {
                if(MM_ERROR_NONE != _mm_session_util_read_information(-1, &session_type, &session_options))
@@ -554,383 +323,109 @@ int MMSoundClientPlaySound(MMSoundPlayParam *param, int tone, int keytone, int *
                }
        }
 
-       instance = getpid();
-       debug_msg("[Client] pid for client ::: [%d]\n", instance);
-
-       /* callback */
-       /* callback thread is created just once & when the callback is exist */
-       if (param->callback)
-       {
-               if (g_thread_id == -1)
-               {
-                       g_thread_id = pthread_create(&g_thread, NULL, callbackfunc, NULL);
-                       if (g_thread_id == -1)
-                       {
-                               debug_critical("[Client] Fail to create thread %s\n", strerror(errno));
-                               return MM_ERROR_SOUND_INTERNAL;
-                       }
-               }
-       }
-
-       pthread_mutex_lock(&g_thread_mutex);
+//     instance = getpid();
+//     debug_msg("[Client] pid for client ::: [%d]\n", instance);
 
        /* Send msg */
        if ((param->mem_ptr && param->mem_size))
        {
-               debug_msg("The memptr : [%p]\n", param->mem_ptr);
-               debug_msg("The memptr : [%d]\n", param->mem_size);
-               /* Limited memory size */
-               if (param->mem_ptr && param->mem_size > MEMTYPE_SUPPORT_MAX)
-               {
-                       debug_msg("[Client] Memory size is too big. We support size of media to 1MB\n");
-                       goto cleanup;
-               }
-
-               debug_msg("[Client] memory size : %d\n", param->mem_size);
-               snprintf(shm_name, sizeof(shm_name)-1, "%d_%d", instance, keybase);
-               debug_msg("[Client] The shm_path : [%s]\n", shm_name);
-               keybase++;
-
-               shm_fd = shm_open(shm_name, O_RDWR |O_CREAT, 0666);
-               if(shm_fd < 0)
-               {
-                       perror("[Client] Fail create shm_open\n");
-                       debug_error("[Client] Fail to create shm_open\n");
-                       goto cleanup;
-               }
-
-               if(ftruncate(shm_fd, param->mem_size) == -1)
-               {
-                       debug_error("[Client] Fail to ftruncate\n");
-                       goto cleanup;
-               }
-
-               mmap_buf = mmap (0, MEMTYPE_SUPPORT_MAX, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0);
-               if (mmap_buf == MAP_FAILED)
-               {
-                       debug_error("[Client] MMAP failed (%s)\n", strerror(errno));
-                       goto cleanup;
-               }
-
-               sharedmem = mmap_buf;
-
-               debug_msg("[Client] Sheared mem ptr : %p\n", sharedmem);
-               debug_msg("[Client] Sheared key : [%d]\n", 1);
-               /* Send req memory */
-               msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_MEMORY;
-               msgsnd.sound_msg.msgid = instance;
-               msgsnd.sound_msg.callback = (void*)(param->callback);
-               msgsnd.sound_msg.cbdata = (void*)(param->data);
-               msgsnd.sound_msg.memptr = (int)sharedmem;
-               msgsnd.sound_msg.sharedkey = 1;         /* In case of shared memory file name */
-               msgsnd.sound_msg.session_type = session_type;       //session type
-               msgsnd.sound_msg.session_options = session_options; //session options
-               msgsnd.sound_msg.priority = param->priority;
-
-               MMSOUND_STRNCPY(msgsnd.sound_msg.filename, shm_name, FILE_PATH);
-               debug_msg("[Client] shm_name : %s\n", msgsnd.sound_msg.filename);
-
-               msgsnd.sound_msg.memsize = param->mem_size;
-               msgsnd.sound_msg.volume = param->volume;
-               msgsnd.sound_msg.tone = tone;
-               msgsnd.sound_msg.handle = -1;
-               msgsnd.sound_msg.repeat = param->loop;
-               msgsnd.sound_msg.volume_config = param->volume_config;
-               msgsnd.sound_msg.keytone = keytone;
-               msgsnd.sound_msg.handle_route = param->handle_route;
-               msgsnd.sound_msg.enable_session = !param->skip_session;
-
-               /* Send req memory */
-               debug_msg("[Client] Shared mem ptr %p, %p, size %d\n", sharedmem, param->mem_ptr, param->mem_size);
-               memcpy(sharedmem, param->mem_ptr, param->mem_size);
-
-
-               if (close(shm_fd) == -1)
-               {
-                       debug_error("[Client] Fail to close file\n");
-                       ret = MM_ERROR_SOUND_INTERNAL;
-                       goto cleanup;
-               }
-
-               ret = __MMIpcSndMsg(&msgsnd);
-               if (ret != MM_ERROR_NONE)
-               {
-                       debug_error("[Client] Fail to send msg\n");
-                       goto cleanup;
-               }
+               // Play memory, deprecated
+               return MM_ERROR_INVALID_ARGUMENT;
        }
-       else
-       {
-               /* File type set for send msg */
-               msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_FILE;
-               msgsnd.sound_msg.msgid = instance;
-               msgsnd.sound_msg.callback = (void*)(param->callback);
-               msgsnd.sound_msg.cbdata = (void*)(param->data);
-               msgsnd.sound_msg.volume = param->volume;
-               msgsnd.sound_msg.tone = tone;
-               msgsnd.sound_msg.handle = -1;
-               msgsnd.sound_msg.repeat = param->loop;
-               msgsnd.sound_msg.volume_config = param->volume_config;
-               msgsnd.sound_msg.session_type = session_type;       //session type
-               msgsnd.sound_msg.session_options = session_options; //session options
-               msgsnd.sound_msg.priority = param->priority;
-               msgsnd.sound_msg.handle_route = param->handle_route;
-               msgsnd.sound_msg.enable_session = !param->skip_session;
-
-               if((strlen(param->filename)) < FILE_PATH)
-               {
-                       MMSOUND_STRNCPY(msgsnd.sound_msg.filename, param->filename, FILE_PATH);
-               }
-               else
-               {
-                       debug_error("File name is over count\n");
-                       ret = MM_ERROR_SOUND_INVALID_PATH;
-               }
-
-               msgsnd.sound_msg.keytone = keytone;
 
-               debug_msg("[Client] callback : %p\n", msgsnd.sound_msg.callback);
-               debug_msg("[Client] cbdata : %p\n", msgsnd.sound_msg.cbdata);
-
-               ret = __MMIpcSndMsg(&msgsnd);
-               if (ret != MM_ERROR_NONE)
-               {
-                       debug_error("[Client] Fail to send msg\n");
-                       goto cleanup;
+       mm_sound_convert_volume_type_to_stream_type(volume_type, stream_type);
+       ret = mm_sound_client_dbus_play_sound(param->filename, tone, param->loop, param->volume, param->volume_config,
+                                        param->priority, session_type, session_options, getpid(), keytone, param->handle_route,
+                                        !param->skip_session, handle, stream_type, -1);
+       if (ret != MM_ERROR_NONE) {
+               debug_error("Play Sound Failed");
+               goto failed;
+       } 
+       if (param->callback) {
+               ret = mm_sound_client_dbus_add_play_sound_end_callback(*handle, param->callback, param->data);
+               if (ret != MM_ERROR_NONE) {
+                       debug_error("Add callback for play sound(%d) Failed", *handle);
                }
        }
 
-
-       /* Receive */
-       ret = __MMIpcRecvMsg(instance, &msgrcv);
-       if (ret != MM_ERROR_NONE)
-       {
-               debug_error("[Client] Fail to recieve msg\n");
-               goto cleanup;
-       }
-
-       switch (msgrcv.sound_msg.msgtype)
-       {
-       case MM_SOUND_MSG_RES_FILE:
-               *handle = msgrcv.sound_msg.handle;
-               debug_msg("[Client] Success to play sound sound handle : [%d]\n", *handle);
-               break;
-       case MM_SOUND_MSG_RES_MEMORY:
-               *handle = msgrcv.sound_msg.handle;
-               if(*handle == -1) {
-                       debug_error("[Client] The handle is not get\n");
-               }
-               int r = shm_unlink(shm_name);
-               if (r == -1)
-               {
-                       debug_critical("[Client] Fail to remove shared memory, must be checked\n");
-                       goto cleanup;
-               }
-               debug_msg("[Client] Success to play sound sound handle : [%d]\n", *handle);
-               break;
-       case MM_SOUND_MSG_RES_ERROR:
-               debug_error("[Client] Error occurred \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       default:
-               debug_critical("[Client] Unexpected state with communication \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       }
-cleanup:
-       pthread_mutex_unlock(&g_thread_mutex);
+failed:
 
        debug_fleave();
        return ret;
 }
 
-int MMSoundClientStopSound(int handle)
+int mm_sound_client_play_sound_with_stream_info(MMSoundPlayParam *param, int *handle, char* stream_type, int stream_id)
 {
-       mm_ipc_msg_t msgrcv = {0,};
-       mm_ipc_msg_t msgsnd = {0,};
        int ret = MM_ERROR_NONE;
-       int instance;
-
-       debug_fenter();
-       debug_msg("[Client] The stop audio handle ::: [%d]\n", handle);
-
-       instance = getpid();
-
-       if (handle < 0)
-       {
-               ret = MM_ERROR_INVALID_ARGUMENT;
-               return ret;
-       }
-
-       ret = __mm_sound_client_get_msg_queue();
-       if (ret  != MM_ERROR_NONE) {
-               return ret;
-       }
-
-       pthread_mutex_lock(&g_thread_mutex);
-
-       /* Send req STOP */
-       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_STOP;
-       msgsnd.sound_msg.msgid = instance;
-       msgsnd.sound_msg.handle = handle;               /* handle means audio handle slot id */
-
-       ret = __MMIpcSndMsg(&msgsnd);
-       if (ret != MM_ERROR_NONE)
-       {
-               debug_error("Fail to send msg\n");
-               goto cleanup;
-       }
 
-       /* Receive */
-       ret = __MMIpcRecvMsg(instance, &msgrcv);
-       if (ret != MM_ERROR_NONE)
-       {
-               debug_error("[Client] Fail to recieve msg\n");
-               goto cleanup;
+       ret = mm_sound_client_dbus_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;
        }
-       switch (msgrcv.sound_msg.msgtype)
-       {
-       case MM_SOUND_MSG_RES_STOP:
-               debug_msg("[Client] Success to stop sound\n");
-               break;
-       case MM_SOUND_MSG_RES_ERROR:
-               debug_error("[Client] Error occurred \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       default:
-               debug_critical("[Client] Unexpected state with communication \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
+       if (param->callback) {
+               ret = mm_sound_client_dbus_add_play_sound_end_callback(param->callback, param->data, *handle);
+               if (ret != MM_ERROR_NONE) {
+                       debug_error("Add callback for play sound(%d) Failed", *handle);
+               }
        }
 
-cleanup:
-       pthread_mutex_unlock(&g_thread_mutex);
-
+failed:
 
        debug_fleave();
        return ret;
-}
-
-static int __mm_sound_device_check_flags_to_append (int device_flags, mm_sound_device_t *device_h, bool *is_good_to_append)
-{
-       bool need_to_append = false;
-       int need_to_check_for_io_direction = device_flags & DEVICE_IO_DIRECTION_FLAGS;
-       int need_to_check_for_state = device_flags & DEVICE_STATE_FLAGS;
-       int need_to_check_for_type = device_flags & DEVICE_TYPE_FLAGS;
-
-       debug_warning("device_h[0x%x], device_flags[0x%x], need_to_check(io_direction[0x%x],state[0x%x],type[0x%x])\n",
-                       device_h, device_flags, need_to_check_for_io_direction, need_to_check_for_state, need_to_check_for_type);
-
-       if(!device_h) {
-               return MM_ERROR_INVALID_ARGUMENT;
-       }
-       if (device_flags == DEVICE_ALL_FLAG) {
-               *is_good_to_append = true;
-               return MM_ERROR_NONE;
-       }
 
-       if (need_to_check_for_io_direction) {
-               if ((device_h->io_direction == DEVICE_IO_DIRECTION_IN) && (device_flags & DEVICE_IO_DIRECTION_IN_FLAG)) {
-                       need_to_append = true;
-               } else if ((device_h->io_direction == DEVICE_IO_DIRECTION_OUT) && (device_flags & DEVICE_IO_DIRECTION_OUT_FLAG)) {
-                       need_to_append = true;
-               } else if ((device_h->io_direction == DEVICE_IO_DIRECTION_BOTH) && (device_flags & DEVICE_IO_DIRECTION_BOTH_FLAG)) {
-                       need_to_append = true;
-               }
-               if (need_to_append) {
-                       if (!need_to_check_for_state && !need_to_check_for_type) {
-                               *is_good_to_append = true;
-                               return MM_ERROR_NONE;
-                       }
-               } else {
-                       *is_good_to_append = false;
-                       return MM_ERROR_NONE;
-               }
-       }
-       if (need_to_check_for_state) {
-               need_to_append = false;
-               if ((device_h->state == DEVICE_STATE_DEACTIVATED) && (device_flags & DEVICE_STATE_DEACTIVATED_FLAG)) {
-                       need_to_append = true;
-               } else if ((device_h->state == DEVICE_STATE_ACTIVATED) && (device_flags & DEVICE_STATE_ACTIVATED_FLAG)) {
-                       need_to_append = true;
-               }
-               if (need_to_append) {
-                       if (!need_to_check_for_type) {
-                               *is_good_to_append = true;
-                               return MM_ERROR_NONE;
-                       }
-               } else {
-                       *is_good_to_append = false;
-                       return MM_ERROR_NONE;
-               }
-       }
-       if (need_to_check_for_type) {
-               need_to_append = false;
-               bool is_internal_device = IS_INTERNAL_DEVICE(device_h->type);
-               if (is_internal_device && (device_flags & DEVICE_TYPE_INTERNAL_FLAG)) {
-                       need_to_append = true;
-               } else if (!is_internal_device && (device_flags & DEVICE_TYPE_EXTERNAL_FLAG)) {
-                       need_to_append = true;
-               }
-               if (need_to_append) {
-                       *is_good_to_append = true;
-                       return MM_ERROR_NONE;
-               } else {
-                       *is_good_to_append = false;
-                       return MM_ERROR_NONE;
-               }
-       }
-       return MM_ERROR_NONE;
 }
 
-int __mm_sound_client_device_list_clear ()
+int mm_sound_client_stop_sound(int handle)
 {
        int ret = MM_ERROR_NONE;
+       debug_fenter();
 
-       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_device_list_mutex, MM_ERROR_SOUND_INTERNAL);
-
-       if (g_device_list) {
-               g_list_free_full(g_device_list, g_free);
-               g_device_list = NULL;
+       if (handle < 0 || handle > CLIENT_HANDLE_MAX) {
+               ret = MM_ERROR_INVALID_ARGUMENT;
+               return ret;
        }
 
-       MMSOUND_LEAVE_CRITICAL_SECTION(&g_device_list_mutex);
+       ret = mm_sound_client_dbus_stop_sound(handle);
 
+       debug_fleave();
        return ret;
 }
 
-int __mm_sound_client_device_list_append_item (mm_sound_device_t *device_h)
+static int _mm_sound_client_device_list_clear ()
 {
        int ret = MM_ERROR_NONE;
-       mm_sound_device_t *device_node = g_malloc0(sizeof(mm_sound_device_t));
-       memcpy(device_node, device_h, sizeof(mm_sound_device_t));
 
        MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_device_list_mutex, MM_ERROR_SOUND_INTERNAL);
 
-       g_device_list = g_list_append(g_device_list, device_node);
-       debug_log("[Client] g_device_list[0x%x], new device_node[0x%x] is appended, type[%d], id[%d]\n", g_device_list, device_node, device_node->type, device_node->id);
+       if (g_device_list_t.list) {
+               g_list_free_full(g_device_list_t.list, g_free);
+               g_device_list_t.list = NULL;
+       }
 
        MMSOUND_LEAVE_CRITICAL_SECTION(&g_device_list_mutex);
 
        return ret;
 }
 
-int _mm_sound_client_device_list_dump (GList *device_list)
+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_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[%02d], id[%02d], io_direction[%d], state[%d], name[%s]\n",
+                       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);
                }
        }
@@ -939,1331 +434,266 @@ int _mm_sound_client_device_list_dump (GList *device_list)
        return ret;
 }
 
-int _mm_sound_client_get_current_connected_device_list(int device_flags, mm_sound_device_list_t **device_list)
+int mm_sound_client_get_current_connected_device_list(int device_flags, mm_sound_device_list_t **device_list)
 {
-       mm_ipc_msg_t msgrcv = {0,};
-       mm_ipc_msg_t msgsnd = {0,};
        int ret = MM_ERROR_NONE;
-       int instance;
-
        debug_fenter();
 
-       ret = __mm_sound_client_get_msg_queue();
-       if (ret  != MM_ERROR_NONE) {
+       ret = _mm_sound_client_device_list_clear();
+       if (ret) {
+               debug_error("[Client] failed to __mm_sound_client_device_list_clear(), ret[0x%x]\n", ret);
                return ret;
        }
-       pthread_mutex_lock(&g_thread_mutex);
-
-       instance = getpid();
 
-       /* Send REQ_ADD_ACTIVE_DEVICE_CB */
-       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_GET_CONNECTED_DEVICE_LIST;
-       msgsnd.sound_msg.msgid = instance;
-       msgsnd.sound_msg.device_flags = device_flags;
-
-       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
-               goto cleanup;
+       if((ret = mm_sound_client_dbus_get_current_connected_device_list(device_flags, &g_device_list_t))!=MM_ERROR_NONE){
+               debug_error("[Client] failed to get current connected device list with dbus, ret[0x%x]", ret);
+               goto failed;
        }
-
-       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
-               goto cleanup;
+       if (!g_device_list_t.list) {
+               debug_error("Got device list null");
+               ret = MM_ERROR_SOUND_NO_DATA;
+               goto failed;
        }
+//             g_device_list_t.list = g_device_list;
+       _mm_sound_client_device_list_dump(g_device_list_t.list);
+       *device_list = &g_device_list_t;
 
-       switch (msgrcv.sound_msg.msgtype)
-       {
-       case MM_SOUND_MSG_RES_GET_CONNECTED_DEVICE_LIST:
-       {
-               int i = 0;
-               int ret = MM_ERROR_NONE;
-               int total_device_num = msgrcv.sound_msg.total_device_num;
-               bool is_good_to_append = false;
-               mm_sound_device_t* device_h = &msgrcv.sound_msg.device_handle;
-
-               ret = __mm_sound_client_device_list_clear();
-               if (ret) {
-                       debug_error("[Client] failed to __mm_sound_client_device_list_clear(), ret[0x%x]\n", ret);
-                       goto cleanup;
-               }
-
-               debug_msg("[Client] supposed to receive %d messages\n", total_device_num);
-               for (i = 0; i < total_device_num; i++) {
-                       /* check if this device_handle is suitable according to flags */
-                       ret = __mm_sound_device_check_flags_to_append (device_flags, device_h, &is_good_to_append);
-                       if (is_good_to_append) {
-                               ret = __mm_sound_client_device_list_append_item(device_h);
-                               if (ret) {
-                                       debug_error("[Client] failed to __mm_sound_client_device_list_append_item(), ret[0x%x]\n", ret);
-                               }
-                       }
-                       if (total_device_num-i > 1) {
-                               if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
-                                       debug_error("[Client] failed to [%d]th of __MMIpcRecvMsg()\n", i);
-                                       goto cleanup;
-                               }
-                               switch (msgrcv.sound_msg.msgtype)
-                               {
-                               case MM_SOUND_MSG_RES_GET_CONNECTED_DEVICE_LIST:
-                                       break;
-                               default:
-                                       debug_error("[Client] failed to [%d]th of __MMIpcRecvMsg(), msgtype[%d] is not expected\n", msgrcv.sound_msg.msgtype);
-                                       goto cleanup;
-                                       break;
-                               }
-                       }
-               }
-               g_device_list_t.list = g_device_list;
-               *device_list = &g_device_list_t;
-               debug_msg("[Client] Success to get connected device list, g_device_list_t[0x%x]->list[0x%x], device_list[0x%x]\n", &g_device_list_t, g_device_list_t.list, *device_list);
-               _mm_sound_client_device_list_dump((*device_list)->list);
-       }
-               break;
-       case MM_SOUND_MSG_RES_ERROR:
-               debug_error("[Client] Error occurred \n");
-               ret = msgrcv.sound_msg.code; // no data is possible
-               goto cleanup;
-               break;
-       default:
-               debug_error("[Client] Unexpected state with communication \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       }
-
-cleanup:
-       pthread_mutex_unlock(&g_thread_mutex);
-
+failed:
        debug_fleave();
        return ret;
 }
 
-int _mm_sound_client_add_device_connected_callback(int device_flags, mm_sound_device_connected_cb func, void* user_data)
+int mm_sound_client_add_device_connected_callback(int device_flags, mm_sound_device_connected_cb func, void* user_data)
 {
-       mm_ipc_msg_t msgrcv = {0,};
-       mm_ipc_msg_t msgsnd = {0,};
        int ret = MM_ERROR_NONE;
-       int instance;
 
        debug_fenter();
 
-       ret = __mm_sound_client_get_msg_queue();
-       if (ret  != MM_ERROR_NONE) {
-               return ret;
-       }
-
-       pthread_mutex_lock(&g_thread_mutex);
-
-       instance = getpid();
-       /* Send REQ_ADD_ACTIVE_DEVICE_CB */
-       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_ADD_DEVICE_CONNECTED_CB;
-       msgsnd.sound_msg.msgid = instance;
-       msgsnd.sound_msg.device_flags = device_flags;
-       msgsnd.sound_msg.callback = func;
-       msgsnd.sound_msg.cbdata = user_data;
-
-       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
-               goto cleanup;
-       }
-
-       /* Recieve */
-       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
-               goto cleanup;
-       }
-
-       switch (msgrcv.sound_msg.msgtype)
-       {
-       case MM_SOUND_MSG_RES_ADD_DEVICE_CONNECTED_CB:
-               debug_msg("[Client] Success to add device connected callback\n");
-               if (g_thread_id == -1)
-               {
-                       g_thread_id = pthread_create(&g_thread, NULL, callbackfunc, NULL);
-                       if (g_thread_id == -1)
-                       {
-                               debug_critical("[Client] Fail to create thread %s\n", strerror(errno));
-                               ret = MM_ERROR_SOUND_INTERNAL;
-                               goto cleanup;
-                       }
-               }
-               break;
-       case MM_SOUND_MSG_RES_ERROR:
-               debug_error("[Client] Error occurred \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       default:
-               debug_critical("[Client] Unexpected state with communication \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       }
-
-cleanup:
-       pthread_mutex_unlock(&g_thread_mutex);
+       ret = mm_sound_client_dbus_add_device_connected_callback(device_flags, func, user_data);
 
        debug_fleave();
        return ret;
+
 }
 
-int _mm_sound_client_remove_device_connected_callback(void)
+int mm_sound_client_remove_device_connected_callback(void)
 {
-       mm_ipc_msg_t msgrcv = {0,};
-       mm_ipc_msg_t msgsnd = {0,};
        int ret = MM_ERROR_NONE;
-       int instance;
-
        debug_fenter();
 
-       ret = __mm_sound_client_get_msg_queue();
-       if (ret  != MM_ERROR_NONE) {
-               return ret;
-       }
-
-       pthread_mutex_lock(&g_thread_mutex);
-
-       instance = getpid();
-       /* Send REQ_REMOVE_ACTIVE_DEVICE_CB */
-       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_REMOVE_DEVICE_CONNECTED_CB;
-       msgsnd.sound_msg.msgid = instance;
-
-       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
-               goto cleanup;
-       }
-       /* Recieve */
-       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
-               goto cleanup;
-       }
-       switch (msgrcv.sound_msg.msgtype)
-       {
-       case MM_SOUND_MSG_RES_REMOVE_DEVICE_CONNECTED_CB:
-               debug_msg("[Client] Success to remove device connected callback\n");
-               break;
-       case MM_SOUND_MSG_RES_ERROR:
-               debug_error("[Client] Error occurred \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       default:
-               debug_critical("[Client] Unexpected state with communication \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       }
-
-cleanup:
-       pthread_mutex_unlock(&g_thread_mutex);
+       ret = mm_sound_client_dbus_remove_device_connected_callback();
 
        debug_fleave();
        return ret;
 }
 
-int _mm_sound_client_add_device_info_changed_callback(int device_flags, mm_sound_device_info_changed_cb func, void* user_data)
+int mm_sound_client_add_device_info_changed_callback(int device_flags, mm_sound_device_info_changed_cb func, void* user_data)
 {
-       mm_ipc_msg_t msgrcv = {0,};
-       mm_ipc_msg_t msgsnd = {0,};
        int ret = MM_ERROR_NONE;
-       int instance;
 
        debug_fenter();
 
-       ret = __mm_sound_client_get_msg_queue();
-       if (ret  != MM_ERROR_NONE) {
-               return ret;
-       }
-
-       pthread_mutex_lock(&g_thread_mutex);
-
-       instance = getpid();
-       /* Send REQ_ADD_ACTIVE_DEVICE_CB */
-       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_ADD_DEVICE_INFO_CHANGED_CB;
-       msgsnd.sound_msg.msgid = instance;
-       msgsnd.sound_msg.device_flags = device_flags;
-       msgsnd.sound_msg.callback = func;
-       msgsnd.sound_msg.cbdata = user_data;
-
-       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
-               goto cleanup;
-       }
-
-       /* Recieve */
-       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
-               goto cleanup;
-       }
-
-       switch (msgrcv.sound_msg.msgtype)
-       {
-       case MM_SOUND_MSG_RES_ADD_DEVICE_INFO_CHANGED_CB:
-               debug_msg("[Client] Success to add device connected callback\n");
-               if (g_thread_id == -1)
-               {
-                       g_thread_id = pthread_create(&g_thread, NULL, callbackfunc, NULL);
-                       if (g_thread_id == -1)
-                       {
-                               debug_critical("[Client] Fail to create thread %s\n", strerror(errno));
-                               ret = MM_ERROR_SOUND_INTERNAL;
-                               goto cleanup;
-                       }
-               }
-               break;
-       case MM_SOUND_MSG_RES_ERROR:
-               debug_error("[Client] Error occurred \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       default:
-               debug_critical("[Client] Unexpected state with communication \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       }
-
-cleanup:
-       pthread_mutex_unlock(&g_thread_mutex);
+       ret = mm_sound_client_dbus_add_device_info_changed_callback(device_flags, func, user_data);
 
        debug_fleave();
        return ret;
 }
 
-int _mm_sound_client_remove_device_info_changed_callback(void)
+int mm_sound_client_remove_device_info_changed_callback(void)
 {
-       mm_ipc_msg_t msgrcv = {0,};
-       mm_ipc_msg_t msgsnd = {0,};
        int ret = MM_ERROR_NONE;
-       int instance;
-
        debug_fenter();
 
-       ret = __mm_sound_client_get_msg_queue();
-       if (ret  != MM_ERROR_NONE) {
-               return ret;
-       }
-
-       pthread_mutex_lock(&g_thread_mutex);
-
-       instance = getpid();
-       /* Send REQ_REMOVE_ACTIVE_DEVICE_CB */
-       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_REMOVE_DEVICE_INFO_CHANGED_CB;
-       msgsnd.sound_msg.msgid = instance;
-
-       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
-               goto cleanup;
-       }
-
-       /* Recieve */
-       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
-               goto cleanup;
-       }
-
-       switch (msgrcv.sound_msg.msgtype)
-       {
-       case MM_SOUND_MSG_RES_REMOVE_DEVICE_INFO_CHANGED_CB:
-               debug_msg("[Client] Success to remove device info changed callback\n");
-               break;
-       case MM_SOUND_MSG_RES_ERROR:
-               debug_error("[Client] Error occurred \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       default:
-               debug_critical("[Client] Unexpected state with communication \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       }
-
-cleanup:
-       pthread_mutex_unlock(&g_thread_mutex);
+       ret =  mm_sound_client_dbus_remove_device_info_changed_callback();
 
        debug_fleave();
        return ret;
-}
 
-int _mm_sound_client_is_route_available(mm_sound_route route, bool *is_available)
+}
+int mm_sound_client_is_bt_a2dp_on (bool *connected, char** bt_name)
 {
-       mm_ipc_msg_t msgrcv = {0,};
-       mm_ipc_msg_t msgsnd = {0,};
        int ret = MM_ERROR_NONE;
-       int instance;
 
        debug_fenter();
 
-       *is_available = FALSE;
-
-       ret = __mm_sound_client_get_msg_queue();
-       if (ret  != MM_ERROR_NONE) {
-               return ret;
-       }
-
-       pthread_mutex_lock(&g_thread_mutex);
-
-       instance = getpid();
-       /* Send REQ_IS_ROUTE_AVAILABLE */
-       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_IS_ROUTE_AVAILABLE;
-       msgsnd.sound_msg.msgid = instance;
-       msgsnd.sound_msg.route = route;
-
-       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
-               goto cleanup;
-       }
-
-       /* Receive */
-       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
-               goto cleanup;
-       }
-
-       switch (msgrcv.sound_msg.msgtype)
-       {
-       case MM_SOUND_MSG_RES_IS_ROUTE_AVAILABLE:
-               *is_available = msgrcv.sound_msg.is_available;
-               debug_msg("[Client] Success to check given route is available %d\n", *is_available);
-               break;
-       case MM_SOUND_MSG_RES_ERROR:
-               debug_error("[Client] Error occurred \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       default:
-               debug_critical("[Client] Unexpected state with communication \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       }
-
-cleanup:
-       pthread_mutex_unlock(&g_thread_mutex);
+       ret = mm_sound_client_dbus_is_bt_a2dp_on(connected, bt_name);
 
        debug_fleave();
        return ret;
 }
 
-static int _handle_foreach_callback(mm_ipc_msg_t *msg)
-{
-       int route_index;
-       mm_sound_route route;
-
-       debug_fenter();
-
-       if (msg->sound_msg.callback == NULL) {
-               debug_error ("[Client] Foreach callback is [%p], cbdata = %p => exit",
-                               msg->sound_msg.callback, msg->sound_msg.cbdata);
-               return MM_ERROR_SOUND_INTERNAL;
-       }
-
-       for (route_index = 0; route_index < MM_SOUND_ROUTE_NUM; route_index++) {
-               route = msg->sound_msg.route_list[route_index];
-               if (route == 0) {
-                       break;
-               }
-               debug_msg("[Client] available route : %d\n", route);
-               if (((mm_sound_available_route_cb)msg->sound_msg.callback)(route, msg->sound_msg.cbdata) == false) {
-                       debug_msg ("[Client] user doesn't want anymore. quit loop!!\n");
-                       break;
-               }
-       }
-
-       debug_fleave();
-
-       return MM_ERROR_NONE;
-}
-
-int _mm_sound_client_foreach_available_route_cb(mm_sound_available_route_cb available_route_cb, void *user_data)
+int mm_sound_client_set_volume_by_type(const int volume_type, const unsigned int volume_level)
 {
-       mm_ipc_msg_t msgrcv = {0,};
-       mm_ipc_msg_t msgsnd = {0,};
        int ret = MM_ERROR_NONE;
-       int instance;
 
        debug_fenter();
 
-       ret = __mm_sound_client_get_msg_queue();
-       if (ret  != MM_ERROR_NONE) {
-               return ret;
-       }
-
-       pthread_mutex_lock(&g_thread_mutex);
-
-       instance = getpid();
-       /* Send REQ_FOREACH_AVAILABLE_ROUTE_CB */
-       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_FOREACH_AVAILABLE_ROUTE_CB;
-       msgsnd.sound_msg.msgid = instance;
-       msgsnd.sound_msg.callback = (void *)available_route_cb;
-       msgsnd.sound_msg.cbdata = (void *)user_data;
-
-       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
-               goto cleanup;
-       }
-
-       /* Recieve */
-       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
-               goto cleanup;
-       }
-
-       switch (msgrcv.sound_msg.msgtype)
-       {
-       case MM_SOUND_MSG_RES_FOREACH_AVAILABLE_ROUTE_CB:
-               debug_msg("[Client] Success to set foreach available route callback\n");
-               msgrcv.sound_msg.callback = (void *)available_route_cb;
-               msgrcv.sound_msg.cbdata = (void *)user_data;
-               ret = _handle_foreach_callback (&msgrcv);
-               break;
-       case MM_SOUND_MSG_RES_ERROR:
-               debug_error("[Client] Error occurred \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       default:
-               debug_critical("[Client] Unexpected state with communication \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       }
-
-cleanup:
-       pthread_mutex_unlock(&g_thread_mutex);
+       ret = mm_sound_client_dbus_set_volume_by_type(volume_type, volume_level);
 
        debug_fleave();
        return ret;
 }
 
-int _mm_sound_client_set_active_route(mm_sound_route route, bool need_broadcast)
+int mm_sound_client_add_volume_changed_callback(mm_sound_volume_changed_cb func, void* user_data)
 {
-       mm_ipc_msg_t msgrcv = {0,};
-       mm_ipc_msg_t msgsnd = {0,};
        int ret = MM_ERROR_NONE;
-       int instance;
 
        debug_fenter();
 
-       ret = __mm_sound_client_get_msg_queue();
-       if (ret  != MM_ERROR_NONE) {
-               return ret;
-       }
-
-       pthread_mutex_lock(&g_thread_mutex);
-
-       instance = getpid();
-       /* Send REQ_SET_ACTIVE_ROUTE */
-       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_SET_ACTIVE_ROUTE;
-       msgsnd.sound_msg.msgid = instance;
-       msgsnd.sound_msg.route = route;
-       msgsnd.sound_msg.need_broadcast = need_broadcast;
-
-       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE)
-               goto cleanup;
-
-       /* Recieve */
-       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
-               goto cleanup;
-       }
-
-       switch (msgrcv.sound_msg.msgtype)
-       {
-       case MM_SOUND_MSG_RES_SET_ACTIVE_ROUTE:
-               debug_msg("[Client] Success to add active device callback\n");
-               break;
-       case MM_SOUND_MSG_RES_ERROR:
-               debug_error("[Client] Error occurred \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       default:
-               debug_critical("[Client] Unexpected state with communication \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       }
-
-cleanup:
-       pthread_mutex_unlock(&g_thread_mutex);
+       ret = mm_sound_client_dbus_add_volume_changed_callback(func, user_data);
 
        debug_fleave();
        return ret;
 }
 
-int _mm_sound_client_set_active_route_auto(void)
+int mm_sound_client_remove_volume_changed_callback(void)
 {
-       mm_ipc_msg_t msgrcv = {0,};
-       mm_ipc_msg_t msgsnd = {0,};
        int ret = MM_ERROR_NONE;
-       int instance;
-
        debug_fenter();
 
-       ret = __mm_sound_client_get_msg_queue();
-       if (ret  != MM_ERROR_NONE) {
-               return ret;
-       }
-
-       pthread_mutex_lock(&g_thread_mutex);
-
-       instance = getpid();
-       /* Send REQ_SET_ACTIVE_ROUTE */
-       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_SET_ACTIVE_ROUTE_AUTO;
-       msgsnd.sound_msg.msgid = instance;
-
-       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
-               goto cleanup;
-       }
-
-       /* Recieve */
-       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
-               goto cleanup;
-       }
-
-       switch (msgrcv.sound_msg.msgtype)
-       {
-       case MM_SOUND_MSG_RES_SET_ACTIVE_ROUTE_AUTO:
-               debug_msg("[Client] Success to set active device auto\n");
-               break;
-       case MM_SOUND_MSG_RES_ERROR:
-               debug_error("[Client] Error occurred \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       default:
-               debug_critical("[Client] Unexpected state with communication \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       }
-
-cleanup:
-       pthread_mutex_unlock(&g_thread_mutex);
+       ret = mm_sound_client_dbus_remove_volume_changed_callback();
 
        debug_fleave();
        return ret;
 }
 
-int _mm_sound_client_get_active_device(mm_sound_device_in *device_in, mm_sound_device_out *device_out)
+
+int mm_sound_client_get_audio_path(mm_sound_device_in *device_in, mm_sound_device_out *device_out)
 {
-       mm_ipc_msg_t msgrcv = {0,};
-       mm_ipc_msg_t msgsnd = {0,};
        int ret = MM_ERROR_NONE;
-       int instance;
 
        debug_fenter();
 
-       ret = __mm_sound_client_get_msg_queue();
-       if (ret  != MM_ERROR_NONE) {
-               return ret;
-       }
-
-       pthread_mutex_lock(&g_thread_mutex);
-
-       instance = getpid();
-       /* Send REQ_GET_ACTIVE_DEVICE */
-       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_GET_ACTIVE_DEVICE;
-       msgsnd.sound_msg.msgid = instance;
-
-       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
-               goto cleanup;
-       }
-
-       /* Recieve */
-       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
-               goto cleanup;
-       }
-
-       switch (msgrcv.sound_msg.msgtype)
-       {
-       case MM_SOUND_MSG_RES_GET_ACTIVE_DEVICE:
-               *device_in = msgrcv.sound_msg.device_in;
-               *device_out = msgrcv.sound_msg.device_out;
-               debug_log("[Client] Success to get active device in=[%x], out=[%x]\n", *device_in, *device_out);
-               break;
-       case MM_SOUND_MSG_RES_ERROR:
-               debug_error("[Client] Error occurred \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       default:
-               debug_critical("[Client] Unexpected state with communication \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       }
-
-cleanup:
-       pthread_mutex_unlock(&g_thread_mutex);
+       ret = mm_sound_client_dbus_get_audio_path(device_in, device_out);
 
        debug_fleave();
+
        return ret;
 }
 
-int _mm_sound_client_get_audio_path(mm_sound_device_in *device_in, mm_sound_device_out *device_out)
+
+#ifdef USE_FOCUS
+int mm_sound_client_get_uniq_id(int *id)
 {
-       mm_ipc_msg_t msgrcv = {0,};
-       mm_ipc_msg_t msgsnd = {0,};
+       static int uniq_id = 0;
        int ret = MM_ERROR_NONE;
-       int instance;
 
+       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_id_mutex, MM_ERROR_SOUND_INTERNAL);
        debug_fenter();
 
-       ret = __mm_sound_client_get_msg_queue();
-       if (ret  != MM_ERROR_NONE) {
-               return ret;
-       }
-
-       pthread_mutex_lock(&g_thread_mutex);
-
-       instance = getpid();
-       /* Send REQ_GET_AUDIO_PATH */
-       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_GET_AUDIO_PATH;
-       msgsnd.sound_msg.msgid = instance;
-
-       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
-               goto cleanup;
-       }
-
-       /* Recieve */
-       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
-               goto cleanup;
-       }
-
-       switch (msgrcv.sound_msg.msgtype)
-       {
-       case MM_SOUND_MSG_RES_GET_AUDIO_PATH:
-               *device_in = msgrcv.sound_msg.device_in;
-               *device_out = msgrcv.sound_msg.device_out;
-               debug_log("[Client] Success to get active device in=[%x], out=[%x]\n", *device_in, *device_out);
-               break;
-       case MM_SOUND_MSG_RES_ERROR:
-               debug_error("[Client] Error occurred \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       default:
-               debug_critical("[Client] Unexpected state with communication \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       }
-
-cleanup:
-       pthread_mutex_unlock(&g_thread_mutex);
+       if (!id)
+               ret = MM_ERROR_INVALID_ARGUMENT;
+       else
+               *id = ++uniq_id;
 
        debug_fleave();
+       MMSOUND_LEAVE_CRITICAL_SECTION(&g_id_mutex);
+
        return ret;
 }
 
-int _mm_sound_client_add_active_device_changed_callback(const char *name, mm_sound_active_device_changed_cb func, void* user_data)
+int mm_sound_client_register_focus(int id, const char *stream_type, mm_sound_focus_changed_cb callback, void* user_data)
 {
-       mm_ipc_msg_t msgrcv = {0,};
-       mm_ipc_msg_t msgsnd = {0,};
        int ret = MM_ERROR_NONE;
-       int instance;
-
        debug_fenter();
 
-       ret = __mm_sound_client_get_msg_queue();
-       if (ret  != MM_ERROR_NONE) {
-               return ret;
-       }
-
-       pthread_mutex_lock(&g_thread_mutex);
-
-       instance = getpid();
-       /* Send REQ_ADD_ACTIVE_DEVICE_CB */
-       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_ADD_ACTIVE_DEVICE_CB;
-       msgsnd.sound_msg.msgid = instance;
-       msgsnd.sound_msg.callback = func;
-       msgsnd.sound_msg.cbdata = user_data;
-       MMSOUND_STRNCPY(msgsnd.sound_msg.name, name, MM_SOUND_NAME_NUM);
-
-       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
-               goto cleanup;
-       }
-
-       /* Recieve */
-       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
-               goto cleanup;
-       }
-
-       switch (msgrcv.sound_msg.msgtype)
-       {
-       case MM_SOUND_MSG_RES_ADD_ACTIVE_DEVICE_CB:
-               debug_msg("[Client] Success to add active device callback\n");
-               if (g_thread_id == -1)
-               {
-                       g_thread_id = pthread_create(&g_thread, NULL, callbackfunc, NULL);
-                       if (g_thread_id == -1)
-                       {
-                               debug_critical("[Client] Fail to create thread %s\n", strerror(errno));
-                               ret = MM_ERROR_SOUND_INTERNAL;
-                               goto cleanup;
-                       }
-               }
-               break;
-       case MM_SOUND_MSG_RES_ERROR:
-               debug_error("[Client] Error occurred \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       default:
-               debug_critical("[Client] Unexpected state with communication \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       }
-
-cleanup:
-       pthread_mutex_unlock(&g_thread_mutex);
+       ret = mm_sound_client_dbus_register_focus(id, stream_type, callback, user_data);
 
        debug_fleave();
        return ret;
 }
 
-int _mm_sound_client_remove_active_device_changed_callback(const char *name)
+int mm_sound_client_unregister_focus(int id)
 {
-       mm_ipc_msg_t msgrcv = {0,};
-       mm_ipc_msg_t msgsnd = {0,};
        int ret = MM_ERROR_NONE;
-       int instance;
-
        debug_fenter();
 
-       ret = __mm_sound_client_get_msg_queue();
-       if (ret  != MM_ERROR_NONE) {
-               return ret;
-       }
-
-       pthread_mutex_lock(&g_thread_mutex);
-
-       instance = getpid();
-       /* Send REQ_REMOVE_ACTIVE_DEVICE_CB */
-       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_REMOVE_ACTIVE_DEVICE_CB;
-       msgsnd.sound_msg.msgid = instance;
-       MMSOUND_STRNCPY(msgsnd.sound_msg.name, name, MM_SOUND_NAME_NUM);
-
-       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
-               goto cleanup;
-       }
-
-       /* Recieve */
-       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
-               goto cleanup;
-       }
-
-       switch (msgrcv.sound_msg.msgtype)
-       {
-       case MM_SOUND_MSG_RES_REMOVE_ACTIVE_DEVICE_CB:
-               debug_msg("[Client] Success to remove active device callback\n");
-               break;
-       case MM_SOUND_MSG_RES_ERROR:
-               debug_error("[Client] Error occurred \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       default:
-               debug_critical("[Client] Unexpected state with communication \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       }
-
-cleanup:
-       pthread_mutex_unlock(&g_thread_mutex);
+       ret = mm_sound_client_dbus_unregister_focus(id);
 
        debug_fleave();
        return ret;
 }
 
-int _mm_sound_client_add_volume_changed_callback(mm_sound_volume_changed_cb func, void* user_data)
+int mm_sound_client_acquire_focus(int id, mm_sound_focus_type_e type, const char *option)
 {
-       mm_ipc_msg_t msgrcv = {0,};
-       mm_ipc_msg_t msgsnd = {0,};
        int ret = MM_ERROR_NONE;
-       int instance;
-
        debug_fenter();
 
-       ret = __mm_sound_client_get_msg_queue();
-       if (ret  != MM_ERROR_NONE) {
-               return ret;
-       }
-
-       pthread_mutex_lock(&g_thread_mutex);
-
-       instance = getpid();
-       /* Send REQ_ADD_VOLUME_CB */
-       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_ADD_VOLUME_CB;
-       msgsnd.sound_msg.msgid = instance;
-       msgsnd.sound_msg.callback = func;
-       msgsnd.sound_msg.cbdata = user_data;
-
-       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
-               goto cleanup;
-       }
-
-       /* Recieve */
-       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
-               goto cleanup;
-       }
-
-       switch (msgrcv.sound_msg.msgtype)
-       {
-       case MM_SOUND_MSG_RES_ADD_VOLUME_CB:
-               debug_msg("[Client] Success to add volume callback\n");
-               if (g_thread_id == -1)
-               {
-                       g_thread_id = pthread_create(&g_thread, NULL, callbackfunc, NULL);
-                       if (g_thread_id == -1)
-                       {
-                               debug_critical("[Client] Fail to create thread %s\n", strerror(errno));
-                               ret = MM_ERROR_SOUND_INTERNAL;
-                               goto cleanup;
-                       }
-               }
-               break;
-       case MM_SOUND_MSG_RES_ERROR:
-               debug_error("[Client] Error occurred \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       default:
-               debug_critical("[Client] Unexpected state with communication \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       }
-
-cleanup:
-       pthread_mutex_unlock(&g_thread_mutex);
+       ret = mm_sound_client_dbus_acquire_focus(id, type, option);
 
        debug_fleave();
        return ret;
 }
 
-int _mm_sound_client_remove_volume_changed_callback(void)
+int mm_sound_client_release_focus(int id, mm_sound_focus_type_e type, const char *option)
 {
-       mm_ipc_msg_t msgrcv = {0,};
-       mm_ipc_msg_t msgsnd = {0,};
        int ret = MM_ERROR_NONE;
-       int instance;
-
        debug_fenter();
 
-       ret = __mm_sound_client_get_msg_queue();
-       if (ret  != MM_ERROR_NONE) {
-               return ret;
-       }
-
-       pthread_mutex_lock(&g_thread_mutex);
-
-       instance = getpid();
-       /* Send REQ_REMOVE_VOLUME_CB */
-       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_REMOVE_VOLUME_CB;
-       msgsnd.sound_msg.msgid = instance;
-
-       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
-               goto cleanup;
-       }
-
-       /* Recieve */
-       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
-               goto cleanup;
-       }
-
-       switch (msgrcv.sound_msg.msgtype)
-       {
-       case MM_SOUND_MSG_RES_REMOVE_VOLUME_CB:
-               debug_msg("[Client] Success to remove volume callback\n");
-               break;
-       case MM_SOUND_MSG_RES_ERROR:
-               debug_error("[Client] Error occurred \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       default:
-               debug_critical("[Client] Unexpected state with communication \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       }
-
-cleanup:
-       pthread_mutex_unlock(&g_thread_mutex);
+       mm_sound_client_dbus_release_focus(id, type, option);
 
        debug_fleave();
        return ret;
 }
 
-int _mm_sound_client_add_available_route_changed_callback(mm_sound_available_route_changed_cb func, void* user_data)
+int mm_sound_client_set_focus_watch_callback(mm_sound_focus_type_e focus_type, mm_sound_focus_changed_watch_cb callback, void* user_data, int *id)
 {
-       mm_ipc_msg_t msgrcv = {0,};
-       mm_ipc_msg_t msgsnd = {0,};
        int ret = MM_ERROR_NONE;
-       int instance;
-
        debug_fenter();
 
-       ret = __mm_sound_client_get_msg_queue();
-       if (ret  != MM_ERROR_NONE) {
-               return ret;
-       }
-
-       pthread_mutex_lock(&g_thread_mutex);
-
-       instance = getpid();
-       /* Send REQ_ADD_AVAILABLE_ROUTE_CB */
-       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_ADD_AVAILABLE_ROUTE_CB;
-       msgsnd.sound_msg.msgid = instance;
-       msgsnd.sound_msg.callback = func;
-       msgsnd.sound_msg.cbdata = user_data;
-
-       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
-               goto cleanup;
-       }
-
-       /* Recieve */
-       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
-               goto cleanup;
-       }
-
-       switch (msgrcv.sound_msg.msgtype)
-       {
-       case MM_SOUND_MSG_RES_ADD_AVAILABLE_ROUTE_CB:
-               debug_msg("[Client] Success to add available route callback\n");
-               if (g_thread_id == -1)
-               {
-                       g_thread_id = pthread_create(&g_thread, NULL, callbackfunc, NULL);
-                       if (g_thread_id == -1)
-                       {
-                               debug_critical("[Client] Fail to create thread %s\n", strerror(errno));
-                               ret = MM_ERROR_SOUND_INTERNAL;
-                               goto cleanup;
-                       }
-               }
-               break;
-       case MM_SOUND_MSG_RES_ERROR:
-               debug_error("[Client] Error occurred \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       default:
-               debug_critical("[Client] Unexpected state with communication \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       }
-
-cleanup:
-       pthread_mutex_unlock(&g_thread_mutex);
+       mm_sound_client_dbus_set_focus_watch_callback(focus_type, callback, user_data, id);
 
        debug_fleave();
        return ret;
 }
 
-int _mm_sound_client_remove_available_route_changed_callback(void)
+int mm_sound_client_unset_focus_watch_callback(int id)
 {
-       mm_ipc_msg_t msgrcv = {0,};
-       mm_ipc_msg_t msgsnd = {0,};
        int ret = MM_ERROR_NONE;
-       int instance;
-
        debug_fenter();
 
-       ret = __mm_sound_client_get_msg_queue();
-       if (ret  != MM_ERROR_NONE) {
-               return ret;
-       }
-
-       pthread_mutex_lock(&g_thread_mutex);
-
-       instance = getpid();
-       /* Send REQ_REMOVE_AVAILABLE_ROUTE_CB */
-       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_REMOVE_AVAILABLE_ROUTE_CB;
-       msgsnd.sound_msg.msgid = instance;
-
-       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
-               goto cleanup;
-       }
-
-       /* Recieve */
-       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
-               goto cleanup;
-       }
-
-       switch (msgrcv.sound_msg.msgtype)
-       {
-       case MM_SOUND_MSG_RES_REMOVE_AVAILABLE_ROUTE_CB:
-               debug_msg("[Client] Success to remove available route callback\n");
-               break;
-       case MM_SOUND_MSG_RES_ERROR:
-               debug_error("[Client] Error occurred \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       default:
-               debug_critical("[Client] Unexpected state with communication \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       }
-
-cleanup:
-       pthread_mutex_unlock(&g_thread_mutex);
+       ret = mm_sound_client_dbus_unset_focus_watch_callback(id);
 
        debug_fleave();
        return ret;
 }
+#endif
 
-static int __MMIpcCBSndMsg(mm_ipc_msg_t *msg)
-{
-       /* rcv message */
-       msg->msg_type = msg->sound_msg.msgid;
-       if (msgsnd(g_msg_sccb, msg,DSIZE, 0)== -1)
-       {
-               debug_error("[Client] Fail to callback send message msgid : [%d], [%d][%s]", g_msg_sccb, errno, strerror(errno));
-               return MM_ERROR_COMMON_UNKNOWN;
-       }
-       return MM_ERROR_NONE;
-}
-
-static int __MMIpcCBRecvMsg(int msgtype, mm_ipc_msg_t *msg)
-{
-       /* rcv message */
-       if(msgrcv(g_msg_sccb, msg, DSIZE, msgtype, 0) == -1)
-       {
-               debug_error("[Client] Fail to callback receive message msgid : [%d], [%d][%s]", g_msg_sccb, errno, strerror(errno));
-               return MM_ERROR_COMMON_UNKNOWN;
-       }
-       return MM_ERROR_NONE;
-}
-
-#define MAX_RCV_RETRY 20000
-
-static int __MMIpcRecvMsg(int msgtype, mm_ipc_msg_t *msg)
-{
-       int retry_count = 0;
-
-       /* rcv message */
-       while (msgrcv(g_msg_scrcv, msg, DSIZE, msgtype, IPC_NOWAIT) == -1) {
-               if (errno == ENOMSG) {
-                       if (retry_count < MAX_RCV_RETRY) { /* usec is 10^-6 sec so, 5ms * 20000 = 10sec. */
-                               usleep(5000);
-                               retry_count++;
-                               continue;
-                       } else {
-                               debug_error("[Client] retry(%d) is over : [%d] \n", MAX_RCV_RETRY, g_msg_scrcv);
-                               return MM_ERROR_SOUND_INTERNAL;
-                       }
-               } else if (errno == EINTR) {
-                       debug_warning("[Client] Interrupted by signal, continue loop");
-                       continue;
-               }
-
-               debug_error("[Client] Fail to receive msgid : [%d], [%d][%s]", g_msg_scrcv, errno, strerror(errno));
-
-               return MM_ERROR_COMMON_UNKNOWN;
-       }
-       debug_log("[Client] Retry %d times when receive msg\n", retry_count);
-       return MM_ERROR_NONE;
-}
-
-static int __MMIpcSndMsg(mm_ipc_msg_t *msg)
-{
-       /* rcv message */
-       int try_again = 0;
-
-       msg->msg_type = msg->sound_msg.msgid;
-       while (msgsnd(g_msg_scsnd, msg,DSIZE, IPC_NOWAIT) == -1)
-       {
-               if(errno == EACCES) {
-                       debug_warning("Not acces.\n");
-               } else if(errno == EAGAIN || errno == ENOMEM) {
-                       mm_ipc_msg_t msgdata = {0,};
-                       debug_warning("Blocked process [msgflag & IPC_NOWAIT != 0]\n");
-                       debug_warning("The system does not have enough memory to make a copy of the message pointed to by msgp\n");
-                       /* wait 10 msec ,then it will try again */
-                       usleep(10000);
-                       /*  it will try 5 times, after 5 times ,if it still fail ,then it will clear the message queue */
-                       if (try_again <= 5) {
-                               try_again ++;
-                               continue;
-                       }
-                       /* message queue is full ,it need to clear the queue */
-                       while( msgrcv(g_msg_scsnd, &msgdata, DSIZE, 0, IPC_NOWAIT) != -1 ) {
-                               debug_warning("msg queue is full ,remove msgtype:[%d] from the queue",msgdata.sound_msg.msgtype);
-                       }
-                       try_again++;
-                       continue;
-               } else if(errno == EIDRM) {
-                       debug_warning("Removed msgid from system\n");
-               } else if(errno == EINTR) {
-                       debug_warning("Iterrrupted by singnal\n");
-               } else if(errno == EINVAL) {
-                       debug_warning("Invalid msgid or msgtype < 1 or out of data size \n");
-               } else if(errno == EFAULT) {
-                       debug_warning("The address pointed to by msgp isn't accessible \n");
-               }
-               debug_error("[Client] Fail to send message msgid : [%d], [%d][%s]", g_msg_scsnd, errno, strerror(errno));
-               return MM_ERROR_SOUND_INTERNAL;
-       }
-       return MM_ERROR_NONE;
-}
 
-static int __MMSoundGetMsg(void)
+int mm_sound_client_add_test_callback(mm_sound_test_cb func, void* user_data)
 {
-       /* Init message queue, generate msgid for communication to server */
-       /* The key value to get msgid is defined "mm_sound_msg.h". Shared with server */
-       int i = 0;
+       int ret = MM_ERROR_NONE;
 
        debug_fenter();
 
-       /* get msg queue rcv, snd, cb */
-       g_msg_scsnd = msgget(ftok(KEY_BASE_PATH, RCV_MSG), 0666);
-       g_msg_scrcv = msgget(ftok(KEY_BASE_PATH, SND_MSG), 0666);
-       g_msg_sccb = msgget(ftok(KEY_BASE_PATH, CB_MSG), 0666);
-
-       if ((g_msg_scsnd == -1 || g_msg_scrcv == -1 || g_msg_sccb == -1) != MM_ERROR_NONE) {
-               if (errno == EACCES) {
-                       debug_warning("Require ROOT permission.\n");
-               } else if (errno == ENOMEM) {
-                       debug_warning("System memory is empty.\n");
-               } else if(errno == ENOSPC) {
-                       debug_warning("Resource is empty.\n");
-               }
-               /* Some app would start before Sound Server IPC ready. */
-               /* Let's try it again in 50ms later by 10 times */
-               for (i=0;i<10;i++) {
-                       usleep(50000);
-                       g_msg_scsnd = msgget(ftok(KEY_BASE_PATH, RCV_MSG), 0666);
-                       g_msg_scrcv = msgget(ftok(KEY_BASE_PATH, SND_MSG), 0666);
-                       g_msg_sccb = msgget(ftok(KEY_BASE_PATH, CB_MSG), 0666);
-                       if ((g_msg_scsnd == -1 || g_msg_scrcv == -1 || g_msg_sccb == -1) != MM_ERROR_NONE) {
-                               debug_error("Fail to GET msgid by retrying %d times\n", i+1);
-                       } else
-                               break;
-               }
-               if ((g_msg_scsnd == -1 || g_msg_scrcv == -1 || g_msg_sccb == -1) != MM_ERROR_NONE) {
-                       debug_error("Fail to GET msgid finally, just return internal error.\n");
-                       return MM_ERROR_SOUND_INTERNAL;
-               }
-       }
-
-       debug_log("Get msg queue id from server : snd[%d], rcv[%d], cb[%d]\n", g_msg_scsnd, g_msg_scrcv, g_msg_sccb);
+       ret = mm_sound_client_dbus_add_test_callback(func, user_data);
 
        debug_fleave();
-       return MM_ERROR_NONE;
+       return ret;
 }
 
-#ifdef PULSE_CLIENT
-
-int MMSoundClientIsBtA2dpOn (bool *connected, char** bt_name)
+int mm_sound_client_remove_test_callback(void)
 {
-       mm_ipc_msg_t msgrcv = {0,};
-       mm_ipc_msg_t msgsnd = {0,};
        int ret = MM_ERROR_NONE;
-       int instance;
-
        debug_fenter();
 
-       instance = getpid();
-
-       ret = __mm_sound_client_get_msg_queue();
-       if (ret  != MM_ERROR_NONE)
-               return ret;
-
-       pthread_mutex_lock(&g_thread_mutex);
-
-       /* Send req  */
-       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_IS_BT_A2DP_ON;
-       msgsnd.sound_msg.msgid = instance;
-
-       ret = __MMIpcSndMsg(&msgsnd);
-       if (ret != MM_ERROR_NONE)
-       {
-               debug_error("Fail to send msg\n");
-               goto cleanup;
-       }
-
-       /* Receive */
-       ret = __MMIpcRecvMsg(instance, &msgrcv);
-       if (ret != MM_ERROR_NONE)
-       {
-               debug_error("Fail to recieve msg\n");
-               goto cleanup;
-       }
-       switch (msgrcv.sound_msg.msgtype)
-       {
-               case MM_SOUND_MSG_RES_IS_BT_A2DP_ON:
-                       debug_msg("Success to get IS_BT_A2DP_ON [%d][%s]\n", msgrcv.sound_msg.code, msgrcv.sound_msg.filename);
-                       *connected  = (bool)msgrcv.sound_msg.code;
-                       if (*connected)
-                               *bt_name = strdup (msgrcv.sound_msg.filename);
-                       else
-                               *bt_name = NULL;
-                       break;
-               case MM_SOUND_MSG_RES_ERROR:
-                       debug_error("Error occurred \n");
-                       ret = msgrcv.sound_msg.code;
-                       goto cleanup;
-                       break;
-               default:
-                       debug_critical("Unexpected state with communication \n");
-                       ret = msgrcv.sound_msg.code;
-                       goto cleanup;
-                       break;
-       }
-
-cleanup:
-               pthread_mutex_unlock(&g_thread_mutex);
+       ret = mm_sound_client_dbus_remove_test_callback();
 
        debug_fleave();
        return ret;
 }
 
-int _mm_sound_client_set_sound_path_for_active_device(mm_sound_device_out device_out, mm_sound_device_in device_in)
+
+int mm_sound_client_test(int a, int b, int* getv)
 {
-       mm_ipc_msg_t msgrcv = {0,};
-       mm_ipc_msg_t msgsnd = {0,};
        int ret = MM_ERROR_NONE;
-       int instance;
 
        debug_fenter();
 
-       ret = __mm_sound_client_get_msg_queue();
-       if (ret  != MM_ERROR_NONE)
-               return ret;
-
-       pthread_mutex_lock(&g_thread_mutex);
-
-       instance = getpid();
-       /* Send MM_SOUND_MSG_REQ_SET_PATH_FOR_ACTIVE_DEVICE */
-       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_SET_PATH_FOR_ACTIVE_DEVICE;
-       msgsnd.sound_msg.msgid = instance;
-       msgsnd.sound_msg.device_in =  device_in;
-       msgsnd.sound_msg.device_out = device_out;
-
-       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE)
-               goto cleanup;
-
-       /* Recieve */
-       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE)
-               goto cleanup;
-
-       switch (msgrcv.sound_msg.msgtype)
-       {
-       case MM_SOUND_MSG_RES_SET_PATH_FOR_ACTIVE_DEVICE:
-               debug_msg("[Client] Success to setsound path for active device\n");
-               break;
-       case MM_SOUND_MSG_RES_ERROR:
-               debug_error("[Client] Error occurred \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       default:
-               debug_critical("[Client] Unexpected state with communication \n");
-               ret = msgrcv.sound_msg.code;
-               goto cleanup;
-               break;
-       }
-
-cleanup:
-       pthread_mutex_unlock(&g_thread_mutex);
+       ret = mm_sound_client_dbus_test(a, b, getv);
+       debug_log("%d * %d -> result : %d", a, b, *getv);
 
        debug_fleave();
+
        return ret;
 }
-
-
-#endif // PULSE_CLIENT
diff --git a/mm_sound_client_dbus.c b/mm_sound_client_dbus.c
new file mode 100644 (file)
index 0000000..f654c8d
--- /dev/null
@@ -0,0 +1,2412 @@
+#include <gio/gio.h>
+#include <glib.h>
+#include <poll.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#include <mm_error.h>
+#include <mm_debug.h>
+
+#include "include/mm_sound_client_dbus.h"
+#include "include/mm_sound_device.h"
+#include "include/mm_sound_msg.h"
+#include "include/mm_sound_common.h"
+
+#ifdef USE_SECURITY
+#include <security-server.h>
+#define COOKIE_SIZE 20
+#endif
+
+#define VOLUME_TYPE_LEN 64
+
+#define BUS_NAME_PULSEAUDIO "org.pulseaudio.Server"
+#define OBJECT_PULSE_MODULE_POLICY "/org/pulseaudio/policy1"
+#define INTERFACE_PULSE_MODULE_POLICY "org.PulseAudio.Ext.Policy1"
+#define OBJECT_PULSE_MODULE_DEVICE_MANAGER "/org/pulseaudio/DeviceManager"
+#define INTERFACE_PULSE_MODULE_DEVICE_MANAGER "org.pulseaudio.DeviceManager"
+#define OBJECT_PULSE_MODULE_STREAM_MANAGER "/org/pulseaudio/Ext/StreamManager"
+#define INTERFACE_PULSE_MODULE_STREAM_MANAGER "org.pulseaudio.Ext.StreamManager"
+
+#define BUS_NAME_SOUND_SERVER "org.tizen.SoundServer"
+#define OBJECT_SOUND_SERVER "/org/tizen/SoundServer1"
+#define INTERFACE_SOUND_SERVER "org.tizen.SoundServer1"
+
+#define INTERFACE_DBUS                 "org.freedesktop.DBus.Properties"
+#define SIGNAL_PROP_CHANGED "PropertiesChanged"
+#define METHOD_GET                     "Get"
+#define METHOD_SET                     "Set"
+#define DBUS_NAME_MAX                   32
+#define DBUS_SIGNATURE_MAX              32
+#define ERR_MSG_MAX                     100
+
+#define FOCUS_HANDLE_MAX 512
+#define FOCUS_HANDLE_INIT_VAL -1
+
+#define CONFIG_ENABLE_RETCB
+
+enum {
+       DBUS_TO_SOUND_SERVER,
+       DBUS_TO_PULSE_MODULE_DEVICE_MANAGER,
+       DBUS_TO_PULSE_MODULE_STREAM_MANAGER,
+       DBUS_TO_PULSE_MODULE_POLICY,
+};
+
+
+
+struct user_callback {
+       int sig_type;
+       void *cb;
+       void *userdata;
+       int mask;
+};
+
+typedef gboolean (*focus_gLoopPollHandler_t)(gpointer d);
+
+typedef struct {
+       int focus_tid;
+       int handle;
+       int focus_fd;
+       GSourceFuncs* g_src_funcs;
+       GPollFD* g_poll_fd;
+       GSource* focus_src;
+       bool is_used;
+       GMutex* focus_lock;
+       mm_sound_focus_changed_cb focus_callback;
+       mm_sound_focus_changed_watch_cb watch_callback;
+       void* user_data;
+} 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;
+
+
+GThread *g_focus_thread;
+GMainLoop *g_focus_loop;
+focus_sound_info_t g_focus_sound_handle[FOCUS_HANDLE_MAX];
+guint g_dbus_subs_ids[SIGNAL_MAX];
+guint g_dbus_prop_subs_ids[PULSEAUDIO_PROP_MAX];
+
+const struct mm_sound_dbus_method_info g_methods[METHOD_CALL_MAX] = {
+       [METHOD_CALL_TEST] = {
+               .name = "MethodTest1",
+       },
+       [METHOD_CALL_PLAY_FILE_START] = {
+               .name = "PlayFileStart",
+       },
+       [METHOD_CALL_PLAY_FILE_START_WITH_STREAM_INFO] = {
+               .name = "PlayFileStartWithStreamInfo",
+       },
+       [METHOD_CALL_PLAY_FILE_STOP] = {
+               .name = "PlayFileStop",
+       },
+       [METHOD_CALL_PLAY_DTMF] = {
+               .name = "PlayDTMF",
+       },
+       [METHOD_CALL_PLAY_DTMF_WITH_STREAM_INFO] = {
+               .name = "PlayDTMFWithStreamInfo",
+       },
+       [METHOD_CALL_GET_BT_A2DP_STATUS] = {
+               .name = "GetBTA2DPStatus",
+       },
+       [METHOD_CALL_SET_PATH_FOR_ACTIVE_DEVICE] = {
+               .name = "SetPathForActiveDevice",
+       },
+       [METHOD_CALL_GET_AUDIO_PATH] = {
+               .name = "GetAudioPath",
+       },
+       [METHOD_CALL_SET_VOLUME_LEVEL] = {
+               .name = "SetVolumeLevel",
+       },
+       [METHOD_CALL_GET_CONNECTED_DEVICE_LIST] = {
+               .name = "GetConnectedDeviceList",
+       },
+       [METHOD_CALL_REGISTER_FOCUS] = {
+               .name = "RegisterFocus",
+       },
+       [METHOD_CALL_UNREGISTER_FOCUS] = {
+               .name = "UnregisterFocus",
+       },
+       [METHOD_CALL_ACQUIRE_FOCUS] = {
+               .name = "AcquireFocus",
+       },
+       [METHOD_CALL_RELEASE_FOCUS] = {
+               .name = "ReleaseFocus",
+       },
+       [METHOD_CALL_WATCH_FOCUS] = {
+               .name = "WatchFocus",
+       },
+       [METHOD_CALL_UNWATCH_FOCUS] = {
+               .name = "UnwatchFocus",
+       },
+};
+
+const struct mm_sound_dbus_signal_info g_signals[SIGNAL_MAX] = {
+    [SIGNAL_TEST] = {
+               .name = "SignalTest1",
+       },
+       [SIGNAL_PLAY_FILE_END] = {
+               .name = "PlayFileEnd",
+       },
+       [SIGNAL_VOLUME_CHANGED] = {
+               .name = "VolumeChanged",
+       },
+       [SIGNAL_DEVICE_CONNECTED] = {
+               .name = "DeviceConnected",
+       },
+       [SIGNAL_DEVICE_INFO_CHANGED] = {
+               .name = "DeviceInfoChanged",
+       },
+       [SIGNAL_FOCUS_CHANGED] = {
+               .name = "FocusChanged",
+       },
+       [SIGNAL_FOCUS_WATCH] = {
+               .name = "FocusWatch",
+       }
+};
+
+const struct pulseaudio_dbus_property_info g_pulseaudio_properties[PULSEAUDIO_PROP_MAX] = {
+       [PULSEAUDIO_PROP_AUDIO_BALANCE] = {
+               .name = "AudioBalance",
+       },
+       [PULSEAUDIO_PROP_MONO_AUDIO] = {
+               .name = "MonoAudio",
+       },
+       [PULSEAUDIO_PROP_MUTE_ALL] = {
+               .name = "MuteAll",
+       },
+};
+
+/*
+static const GDBusErrorEntry mm_sound_client_error_entries[] =
+{
+       {MM_ERROR_SOUND_INTERNAL, "org.tizen.mm.sound.Error.Internal"},
+       {MM_ERROR_INVALID_ARGUMENT, "org.tizen.mm.sound.Error.InvalidArgument"},
+};
+*/
+
+
+/* Only For error types which is currently being used in server-side */
+static const GDBusErrorEntry mm_sound_error_entries[] =
+{
+       {MM_ERROR_OUT_OF_MEMORY, "org.tizen.multimedia.OutOfMemory"},
+       {MM_ERROR_OUT_OF_STORAGE, "org.tizen.multimedia.OutOfStorage"},
+       {MM_ERROR_INVALID_ARGUMENT, "org.tizen.multimedia.InvalidArgument"},
+       {MM_ERROR_POLICY_INTERNAL, "org.tizen.multimedia.PolicyInternal"},
+       {MM_ERROR_NOT_SUPPORT_API, "org.tizen.multimedia.NotSupportAPI"},
+       {MM_ERROR_POLICY_BLOCKED, "org.tizen.multimedia.PolicyBlocked"},
+       {MM_ERROR_END_OF_FILE, "org.tizen.multimedia.EndOfFile"},
+       {MM_ERROR_COMMON_OUT_OF_RANGE, "org.tizen.multimedia.common.OutOfRange"},
+       {MM_ERROR_COMMON_UNKNOWN, "org.tizen.multimedia.common.Unknown"},
+       {MM_ERROR_COMMON_NO_FREE_SPACE, "org.tizen.multimedia.common.NoFreeSpace"},
+       {MM_ERROR_SOUND_INTERNAL, "org.tizen.multimedia.audio.Internal"},
+       {MM_ERROR_SOUND_INVALID_STATE, "org.tizen.multimedia.audio.InvalidState"},
+       {MM_ERROR_SOUND_NO_FREE_SPACE, "org.tizen.multimedia.audio.NoFreeSpace"},
+       {MM_ERROR_SOUND_UNSUPPORTED_MEDIA_TYPE, "org.tizen.multimedia.audio.UnsupportedMediaType"},
+       {MM_ERROR_SOUND_INVALID_POINTER, "org.tizen.multimedia.audio.InvalidPointer"},
+       {MM_ERROR_SOUND_INVALID_FILE, "org.tizen.multimedia.audio.InvalidFile"},
+       {MM_ERROR_SOUND_FILE_NOT_FOUND, "org.tizen.multimedia.audio.FileNotFound"},
+       {MM_ERROR_SOUND_NO_DATA, "org.tizen.multimedia.audio.NoData"},
+       {MM_ERROR_SOUND_INVALID_PATH, "org.tizen.multimedia.audio.InvalidPath"},
+};
+
+
+/******************************************************************************************
+               Wrapper Functions of GDbus
+******************************************************************************************/
+
+
+static int _parse_error_msg(const char *full_err_msg, char **err_name, char **err_msg)
+{
+       char *save_p, *domain, *_err_name, *_err_msg;
+
+       if (!(domain = strtok_r(full_err_msg, ":", &save_p))) {
+               debug_error("get domain failed");
+               return -1;
+       }
+       if (!(_err_name = strtok_r(NULL, ":", &save_p))) {
+               debug_error("get err name failed");
+               return -1;
+       }
+       if (!(_err_msg = strtok_r(NULL, ":", &save_p))) {
+               debug_error("get err msg failed");
+               return -1;
+       }
+
+       *err_name = _err_name;
+       *err_msg = _err_msg;
+
+       return 0;
+}
+
+static int _convert_error_name(const char *err_name)
+{
+       int i = 0;
+
+       for (i = 0; i < G_N_ELEMENTS(mm_sound_error_entries); i++) {
+               if (!strcmp(mm_sound_error_entries[i].dbus_error_name, err_name)) {
+                       return mm_sound_error_entries[i].error_code;
+               }
+       }
+
+       return MM_ERROR_COMMON_UNKNOWN;
+}
+
+int __convert_volume_type_to_str(int volume_type, char **volume_type_str)
+{
+       int ret = MM_ERROR_NONE;
+
+       if (!volume_type_str) {
+               return MM_ERROR_COMMON_INVALID_ARGUMENT;
+       }
+
+       switch (volume_type) {
+       case VOLUME_TYPE_SYSTEM:
+               *volume_type_str = "system";
+               break;
+       case VOLUME_TYPE_NOTIFICATION:
+               *volume_type_str = "notification";
+               break;
+       case VOLUME_TYPE_ALARM:
+               *volume_type_str = "alarm";
+               break;
+       case VOLUME_TYPE_RINGTONE:
+               *volume_type_str = "ringtone";
+               break;
+       case VOLUME_TYPE_MEDIA:
+               *volume_type_str = "media";
+               break;
+       case VOLUME_TYPE_CALL:
+               *volume_type_str = "call";
+               break;
+       case VOLUME_TYPE_VOIP:
+               *volume_type_str = "voip";
+               break;
+       case VOLUME_TYPE_VOICE:
+               *volume_type_str = "voice";
+               break;
+       }
+       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);
+       }
+       return ret;
+}
+
+int __convert_volume_type_to_int(char *volume_type_str, unsigned int *volume_type)
+{
+       int ret = MM_ERROR_NONE;
+
+       if (!volume_type || !volume_type_str) {
+               return MM_ERROR_COMMON_INVALID_ARGUMENT;
+       }
+
+       if (!strncmp(volume_type_str, "system", VOLUME_TYPE_LEN)) {
+               *volume_type = VOLUME_TYPE_SYSTEM;
+       } else if (!strncmp(volume_type_str, "notification", VOLUME_TYPE_LEN)) {
+               *volume_type = VOLUME_TYPE_NOTIFICATION;
+       } else if (!strncmp(volume_type_str, "alarm", VOLUME_TYPE_LEN)) {
+               *volume_type = VOLUME_TYPE_ALARM;
+       } else if (!strncmp(volume_type_str, "ringtone", VOLUME_TYPE_LEN)) {
+               *volume_type = VOLUME_TYPE_RINGTONE;
+       } else if (!strncmp(volume_type_str, "media", VOLUME_TYPE_LEN)) {
+               *volume_type = VOLUME_TYPE_MEDIA;
+       } else if (!strncmp(volume_type_str, "call", VOLUME_TYPE_LEN)) {
+               *volume_type = VOLUME_TYPE_CALL;
+       } else if (!strncmp(volume_type_str, "voip", VOLUME_TYPE_LEN)) {
+               *volume_type = VOLUME_TYPE_VOIP;
+       } else if (!strncmp(volume_type_str, "voice", VOLUME_TYPE_LEN)) {
+               *volume_type = VOLUME_TYPE_VOICE;
+       } else {
+               debug_log("Invalid volume type : [%s]", volume_type_str);
+               ret = MM_ERROR_SOUND_INTERNAL;
+       }
+
+       return ret;
+}
+
+
+static int _dbus_method_call(GDBusConnection* conn, const char* bus_name, const char* object, const char* intf,
+                                                       const char* method, GVariant* args, GVariant** result)
+{
+       int ret = MM_ERROR_NONE;
+       GError *err = NULL;
+       GVariant* dbus_reply = NULL;
+
+       if (!conn || !object || !intf || !method) {
+               debug_error("Invalid Argument");
+               if (!conn)
+                       debug_error("conn null");
+               else if (!object)
+                       debug_error("object null");
+               else if (!intf)
+                       debug_error("intf null");
+               else if (!method)
+                       debug_error("method null");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       debug_log("Dbus call with obj'%s' intf'%s' method'%s'", object, intf, method);
+
+       dbus_reply = g_dbus_connection_call_sync(conn, bus_name, object , intf, \
+                            method, args ,\
+                            NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err );
+       if (dbus_reply && !err) {
+               debug_log("Method Call '%s.%s' Success", intf, method);
+               *result = dbus_reply;
+       } else {
+               char *err_name = NULL, *err_msg = NULL;
+               debug_log("Method Call '%s.%s' Failed", intf, method);
+
+               if (_parse_error_msg(err->message,  &err_name, &err_msg) < 0) {
+                       debug_error("failed to parse error message");
+                       g_error_free(err);
+                       return MM_ERROR_SOUND_INTERNAL;
+               }
+               ret = _convert_error_name(err_name);
+               g_error_free(err);
+       }
+
+       return ret;
+}
+
+static int _dbus_set_property(GDBusConnection* conn, const char* bus_name, const char* object, const char* intf,
+                                                       const char* prop, GVariant* args, GVariant** result)
+{
+       int ret = MM_ERROR_NONE;
+
+       if (!conn || !object || !intf || !prop) {
+               debug_error("Invalid Argument");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       debug_log("Dbus set property with obj'%s' intf'%s' prop'%s'", object, intf, prop);
+
+       if ((ret = _dbus_method_call(conn, bus_name, object, INTERFACE_DBUS, METHOD_SET,
+                                                               g_variant_new("(ssv)", intf, prop, args), result)) != MM_ERROR_NONE) {
+               debug_error("Dbus call for set property failed");
+       }
+
+       return ret;
+}
+
+static int _dbus_get_property(GDBusConnection *conn, const char* bus_name, const char* object_name,
+                                                       const char* intf_name, const char* prop, GVariant** result)
+{
+       int ret = MM_ERROR_NONE;
+
+       if (!conn || !object_name || !intf_name || !prop) {
+               debug_error("Invalid Argument");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       debug_log("Dbus get property with obj'%s' intf'%s' prop'%s'", object_name, intf_name, prop);
+
+       if ((ret = _dbus_method_call(conn,
+                                      bus_name, object_name, INTERFACE_DBUS, METHOD_GET,
+                                      g_variant_new("(ss)", intf_name, prop), result)) != MM_ERROR_NONE) {
+               debug_error("Dbus call for get property failed");
+       }
+
+       return ret;
+}
+
+static int _dbus_subscribe_signal(GDBusConnection *conn, const char* object_name, const char* intf_name,
+                                       const char* signal_name, GDBusSignalCallback signal_cb, guint *subscribe_id, void* userdata)
+{
+       guint subs_id = 0;
+
+       if (!conn || !object_name || !intf_name || !signal_name || !signal_cb || !subscribe_id) {
+               debug_error("Invalid Argument");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       debug_log("Dbus subscirbe signal with Obj'%s' Intf'%s' sig'%s'", object_name, intf_name, signal_name);
+
+       subs_id = g_dbus_connection_signal_subscribe(conn, NULL, intf_name, signal_name, object_name, \
+                        NULL , G_DBUS_SIGNAL_FLAGS_NONE , signal_cb, userdata, NULL );
+
+       if (!subs_id) {
+               debug_error ("g_dbus_connection_signal_subscribe() failed ");
+               return MM_ERROR_SOUND_INTERNAL;
+       } else {
+               *subscribe_id = subs_id;
+       }
+
+       return MM_ERROR_NONE;
+}
+
+static void _dbus_unsubscribe_signal(GDBusConnection *conn, guint subs_id)
+{
+       if (!conn || !subs_id) {
+               debug_error("Invalid Argument");
+       }
+
+       g_dbus_connection_signal_unsubscribe(conn, subs_id);
+}
+
+static GDBusConnection* _dbus_get_connection(GBusType bustype)
+{
+       static GDBusConnection *conn_system = NULL;
+       static GDBusConnection *conn_session = NULL;
+
+       if (bustype == G_BUS_TYPE_SYSTEM) {
+               if (conn_system) {
+                       debug_log("Already connected to system bus");
+               } else {
+                       debug_log("Get new connection on system bus");
+                       conn_system = g_bus_get_sync(bustype, NULL, NULL);
+               }
+               return conn_system;
+       } else if (bustype == G_BUS_TYPE_SESSION) {
+               if (conn_session) {
+                       debug_log("Already connected to session bus");
+               } else {
+                       debug_log("Get new connection on session bus");
+                       conn_session = g_bus_get_sync(bustype, NULL, NULL);
+               }
+               return conn_session;
+       } else {
+               debug_error("Invalid bus type");
+               return NULL;
+       }
+
+}
+
+static void _dbus_disconnect(GDBusConnection* conn)
+{
+       debug_fenter ();
+       g_object_unref(conn);
+       debug_fleave ();
+}
+
+/******************************************************************************************
+               Simple Functions For Communicate with Sound-Server
+******************************************************************************************/
+
+/* Hardcoded method call Just for communicating with Sound-server*/
+static int _sound_server_dbus_method_call(int method_type, GVariant* args, GVariant **result)
+{
+       int ret = MM_ERROR_NONE;
+       GDBusConnection *conn = NULL;
+
+       if (method_type < 0 || method_type > METHOD_CALL_MAX) {
+               debug_error("Invalid method type");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+/*
+       if (sound_server_methods[method_type].argument && !args) {
+               debug_error("Argument for Method Null");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       if (sound_server_methods[method_type].argument && !g_variant_is_of_type(args, G_VARIANT_TYPE(sound_server_methods[method_type].argument))) {
+               debug_error("Wrong Argument for Method");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+       */
+
+       if ((conn = _dbus_get_connection(G_BUS_TYPE_SYSTEM))) {
+               if((ret = _dbus_method_call(conn, BUS_NAME_SOUND_SERVER,
+                                             OBJECT_SOUND_SERVER,
+                                             INTERFACE_SOUND_SERVER,
+                                             g_methods[method_type].name,
+                                             args, result)) != MM_ERROR_NONE) {
+                       debug_error("Dbus Call on Client Error");
+                       return ret;
+               }
+       } else {
+               debug_error("Get Dbus Connection Error");
+               return MM_ERROR_SOUND_INTERNAL;
+       }
+
+       return MM_ERROR_NONE;
+}
+
+static int _dbus_method_call_to(int dbus_to, int method_type, GVariant *args, GVariant **result)
+{
+       int ret = MM_ERROR_NONE;
+       GDBusConnection *conn = NULL;
+       const char *bus_name, *object, *interface;
+
+       if (method_type < 0 || method_type > METHOD_CALL_MAX) {
+               debug_error("Invalid method type");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       if (dbus_to == DBUS_TO_SOUND_SERVER) {
+               bus_name = BUS_NAME_SOUND_SERVER;
+               object = OBJECT_SOUND_SERVER;
+               interface = INTERFACE_SOUND_SERVER;
+       } else if (dbus_to == DBUS_TO_PULSE_MODULE_DEVICE_MANAGER) {
+               bus_name = BUS_NAME_PULSEAUDIO;
+        object = OBJECT_PULSE_MODULE_DEVICE_MANAGER;
+        interface = INTERFACE_PULSE_MODULE_DEVICE_MANAGER;
+       } else if (dbus_to == DBUS_TO_PULSE_MODULE_STREAM_MANAGER) {
+               bus_name = BUS_NAME_PULSEAUDIO;
+               object = OBJECT_PULSE_MODULE_STREAM_MANAGER;
+               interface = INTERFACE_PULSE_MODULE_STREAM_MANAGER;
+       } else if (dbus_to == DBUS_TO_PULSE_MODULE_POLICY) {
+               bus_name = BUS_NAME_PULSEAUDIO;
+        object = OBJECT_PULSE_MODULE_POLICY;
+        interface = INTERFACE_PULSE_MODULE_POLICY;
+       } else {
+               debug_error("Invalid case, dbus_to %d", dbus_to);
+               return MM_ERROR_SOUND_INTERNAL;
+       }
+
+       if ((conn = _dbus_get_connection(G_BUS_TYPE_SYSTEM))) {
+               if((ret = _dbus_method_call(conn, bus_name,
+                                             object,
+                                             interface,
+                                             g_methods[method_type].name,
+                                             args, result)) != MM_ERROR_NONE) {
+                       debug_error("Dbus Call on Client Error");
+                       return ret;
+               }
+       } else {
+               debug_error("Get Dbus Connection Error");
+               return MM_ERROR_SOUND_INTERNAL;
+       }
+
+       return MM_ERROR_NONE;
+}
+
+static void _sound_server_dbus_signal_callback (GDBusConnection  *connection,
+                                     const gchar      *sender_name,
+                                     const gchar      *object_path,
+                                     const gchar      *interface_name,
+                                     const gchar      *signal_name,
+                                     GVariant         *params,
+                                     gpointer          user_data)
+{
+       struct user_callback* user_cb = NULL;
+       GVariantIter *iter = NULL;
+
+       user_cb = (struct user_callback*) user_data;
+
+       if (!user_cb || !user_cb->cb) {
+               debug_error("User callback data Null");
+               return;
+       }
+
+       if (user_cb->sig_type < 0 || user_cb->sig_type >= SIGNAL_MAX) {
+               debug_error("Wrong Signal Type");
+               return;
+       }
+
+       if (!params) {
+               debug_error("Parameter Null");
+               return;
+       }
+
+       debug_log("Signal(%s.%s) Received , Let's call real User-Callback", interface_name, signal_name);
+
+       if (user_cb->sig_type == SIGNAL_VOLUME_CHANGED) {
+               volume_type_t volume_type = 0;
+               char *volume_type_str = NULL, *direction = NULL;
+               unsigned int volume_level;
+
+               g_variant_get(params, "(&s&su)", &direction, &volume_type_str, &volume_level);
+               if (__convert_volume_type_to_int(volume_type_str, &volume_type) != MM_ERROR_NONE) {
+                       debug_error("volume type convert failed");
+                       return;
+               }
+               debug_log("Call usercallback for %s, direction : %s, vol_type : %s(%d), level : %u", g_signals[user_cb->sig_type].name, direction, volume_type_str, volume_type, volume_level);
+               ((mm_sound_volume_changed_cb)(user_cb->cb))(volume_type, volume_level, user_cb->userdata);
+       } else if (user_cb->sig_type == SIGNAL_DEVICE_CONNECTED) {
+               mm_sound_device_t device_h;
+               const char *name = NULL, *device_type = NULL;
+               gboolean is_connected = FALSE;
+
+               g_variant_get(params, "((i&sii&s)b)", &device_h.id, &device_type, &device_h.io_direction,
+                                       &device_h.state, &name, &is_connected);
+               MMSOUND_STRNCPY(device_h.name, name, MAX_DEVICE_NAME_NUM);
+               MMSOUND_STRNCPY(device_h.type, device_type, MAX_DEVICE_TYPE_STR_LEN);
+               ((mm_sound_device_connected_cb)(user_cb->cb))(&device_h, is_connected, user_cb->userdata);
+
+       } else if (user_cb->sig_type == SIGNAL_DEVICE_INFO_CHANGED) {
+               mm_sound_device_t device_h;
+               const char *name = NULL, *device_type = NULL;
+               int changed_device_info_type = 0;
+
+               g_variant_get(params, "((i&sii&s)i)", &device_h.id, &device_type, &device_h.io_direction,
+                                       &device_h.state, &name, &changed_device_info_type);
+               MMSOUND_STRNCPY(device_h.name, name, MAX_DEVICE_NAME_NUM);
+               MMSOUND_STRNCPY(device_h.type, device_type, MAX_DEVICE_TYPE_STR_LEN);
+               ((mm_sound_device_info_changed_cb)(user_cb->cb))(&device_h, changed_device_info_type, user_cb->userdata);
+       } else if (user_cb->sig_type == SIGNAL_FOCUS_CHANGED) {
+       } else if (user_cb->sig_type == SIGNAL_FOCUS_WATCH) {
+       } else if (user_cb->sig_type == SIGNAL_TEST) {
+               int test_var = 0;
+               g_variant_get(params, "(i)", &test_var);
+               ((mm_sound_test_cb)(user_cb->cb))(test_var, user_cb->userdata);
+       } else if (user_cb->sig_type == SIGNAL_PLAY_FILE_END) {
+               int ended_handle = 0;
+               g_variant_get(params, "(i)", &ended_handle);
+               if (ended_handle == user_cb->mask) {
+                       debug_log("Interested playing handle end : %d", ended_handle);
+                       ((mm_sound_stop_callback_func)(user_cb->cb))(user_cb->userdata, ended_handle);
+               } else {
+                       debug_log("Not interested playing handle : %d", ended_handle);
+               }
+
+       }
+}
+
+static int _sound_server_dbus_signal_subscribe(sound_server_signal_t signaltype, void *cb, void *userdata, int mask)
+{
+       GDBusConnection *conn = NULL;
+       guint subs_id = 0;
+       int instance = 0;
+       struct user_callback *user_cb  = NULL;
+
+       if (!cb) {
+               debug_error("Callback data Null");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       if (signaltype < 0 || signaltype >= SIGNAL_MAX) {
+               debug_error("Wrong Signal Type");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       if (!(user_cb = g_malloc0(sizeof(struct user_callback)))) {
+               debug_error("Allocate Memory for User CB data Failed");
+               return MM_ERROR_SOUND_INTERNAL;
+       }
+
+       user_cb->sig_type = signaltype;
+       user_cb->cb = cb;
+       user_cb->userdata = userdata;
+       user_cb->mask = mask;
+
+       if ((conn = _dbus_get_connection(G_BUS_TYPE_SYSTEM))) {
+               if(_dbus_subscribe_signal(conn, OBJECT_SOUND_SERVER, INTERFACE_SOUND_SERVER, g_signals[signaltype].name,
+                                                               _sound_server_dbus_signal_callback, &subs_id, user_cb) != MM_ERROR_NONE){
+                       debug_error("Dbus Subscribe on Client Error");
+                       return MM_ERROR_SOUND_INTERNAL;
+               } else {
+                       g_dbus_subs_ids[signaltype] = subs_id;
+               }
+       } else {
+               debug_error("Get Dbus Connection Error");
+               return MM_ERROR_SOUND_INTERNAL;
+       }
+       return MM_ERROR_NONE;
+}
+
+static int _dbus_signal_subscribe_to(int dbus_to, sound_server_signal_t signaltype, void *cb, void *userdata, int mask)
+{
+       GDBusConnection *conn = NULL;
+       guint subs_id = 0;
+       int instance = 0;
+       struct user_callback *user_cb  = NULL;
+       const char *object, *interface;
+
+       if (!cb) {
+               debug_error("Callback data Null");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       if (signaltype < 0 || signaltype >= SIGNAL_MAX) {
+               debug_error("Wrong Signal Type");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       if (!(user_cb = g_malloc0(sizeof(struct user_callback)))) {
+               debug_error("Allocate Memory for User CB data Failed");
+               return MM_ERROR_SOUND_INTERNAL;
+       }
+
+       user_cb->sig_type = signaltype;
+       user_cb->cb = cb;
+       user_cb->userdata = userdata;
+       user_cb->mask = mask;
+
+
+       if (dbus_to == DBUS_TO_SOUND_SERVER) {
+               object = OBJECT_SOUND_SERVER;
+               interface = INTERFACE_SOUND_SERVER;
+       } else if (dbus_to == DBUS_TO_PULSE_MODULE_DEVICE_MANAGER) {
+               object = OBJECT_PULSE_MODULE_DEVICE_MANAGER;
+               interface = INTERFACE_PULSE_MODULE_DEVICE_MANAGER;
+       } else if (dbus_to == DBUS_TO_PULSE_MODULE_STREAM_MANAGER) {
+               object = OBJECT_PULSE_MODULE_STREAM_MANAGER;
+               interface = INTERFACE_PULSE_MODULE_STREAM_MANAGER;
+       } else if (dbus_to == DBUS_TO_PULSE_MODULE_POLICY) {
+               object = OBJECT_PULSE_MODULE_POLICY;
+               interface = INTERFACE_PULSE_MODULE_POLICY;
+       } else {
+               debug_error("Invalid case, dbus_to %d", dbus_to);
+               return MM_ERROR_SOUND_INTERNAL;
+       }
+
+
+       if ((conn = _dbus_get_connection(G_BUS_TYPE_SYSTEM))) {
+               if(_dbus_subscribe_signal(conn, object, interface, g_signals[signaltype].name,
+                                                               _sound_server_dbus_signal_callback, &subs_id, user_cb) != MM_ERROR_NONE){
+                       debug_error("Dbus Subscribe on Client Error");
+                       return MM_ERROR_SOUND_INTERNAL;
+               } else {
+                       g_dbus_subs_ids[signaltype] = subs_id;
+               }
+       } else {
+               debug_error("Get Dbus Connection Error");
+               return MM_ERROR_SOUND_INTERNAL;
+       }
+       return MM_ERROR_NONE;
+}
+
+static int _sound_server_dbus_signal_unsubscribe(sound_server_signal_t signaltype)
+{
+       GDBusConnection *conn = NULL;
+
+       if (signaltype < 0 || signaltype >= SIGNAL_MAX) {
+               debug_error("Wrong Signal Type");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       if ((conn = _dbus_get_connection(G_BUS_TYPE_SYSTEM))) {
+               _dbus_unsubscribe_signal(conn, g_dbus_subs_ids[signaltype]);
+       } else {
+               debug_error("Get Dbus Connection Error");
+               return MM_ERROR_SOUND_INTERNAL;
+       }
+}
+
+static int _pulseaudio_dbus_set_property(pulseaudio_property_t property, GVariant* args, GVariant **result)
+{
+       int ret = MM_ERROR_NONE;
+       GDBusConnection *conn = NULL;
+
+       if (property < 0 || property > PULSEAUDIO_PROP_MAX) {
+               debug_error("Invalid property [%d]", property);
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       if (args == NULL) {
+               debug_error("Invalid args");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       if ((conn = _dbus_get_connection(G_BUS_TYPE_SYSTEM))) {
+               if((ret = _dbus_set_property(conn, BUS_NAME_PULSEAUDIO, OBJECT_PULSE_MODULE_POLICY, INTERFACE_PULSE_MODULE_POLICY,
+                                                                       g_pulseaudio_properties[property].name, args, result)) != MM_ERROR_NONE) {
+                       debug_error("Dbus Call on Client Error");
+                       return ret;
+               }
+       } else {
+               debug_error("Get Dbus Connection Error");
+               return MM_ERROR_SOUND_INTERNAL;
+       }
+
+       return MM_ERROR_NONE;
+}
+
+static int _pulseaudio_dbus_get_property(pulseaudio_property_t property, GVariant **result)
+{
+       int ret = MM_ERROR_NONE;
+       GDBusConnection *conn = NULL;
+
+       if (property < 0 || property > PULSEAUDIO_PROP_MAX) {
+               debug_error("Invalid property [%d]", property);
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       if ((conn = _dbus_get_connection(G_BUS_TYPE_SYSTEM))) {
+               if((ret = _dbus_get_property(conn, BUS_NAME_PULSEAUDIO, OBJECT_PULSE_MODULE_POLICY, INTERFACE_PULSE_MODULE_POLICY,
+                                                                       g_pulseaudio_properties[property].name, result)) != MM_ERROR_NONE) {
+                       debug_error("Dbus Call on Client Error");
+                       return ret;
+               }
+       } else {
+               debug_error("Get Dbus Connection Error");
+               return MM_ERROR_SOUND_INTERNAL;
+       }
+
+       return MM_ERROR_NONE;
+}
+
+/******************************************************************************************
+               Implementation of each dbus client code (Construct Params,..)
+******************************************************************************************/
+
+int mm_sound_client_dbus_add_test_callback(mm_sound_test_cb func, void* user_data)
+{
+       int ret = MM_ERROR_NONE;
+
+       debug_fenter();
+
+       if ((ret = _dbus_signal_subscribe_to(DBUS_TO_SOUND_SERVER, SIGNAL_TEST, func, user_data, 0)) != MM_ERROR_NONE) {
+               debug_error("add test callback failed");
+       }
+
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_client_dbus_remove_test_callback(void)
+{
+       int ret = MM_ERROR_NONE;
+       debug_fenter();
+
+       if ((ret = _sound_server_dbus_signal_unsubscribe(SIGNAL_TEST)) != MM_ERROR_NONE) {
+               debug_error("remove test callback failed");
+       }
+
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_client_dbus_test(int a, int b, int *get)
+{
+       int ret = MM_ERROR_NONE;
+       int reply = 0;
+       GVariant *params = NULL, *result = NULL;
+
+       debug_fenter();
+
+       params = g_variant_new("(ii)", a, b);
+       if (params) {
+               if ((ret = _dbus_method_call_to(DBUS_TO_SOUND_SERVER, METHOD_CALL_TEST, params, &result)) != MM_ERROR_NONE) {
+                       debug_error("dbus test call failed");
+                       goto cleanup;
+               }
+       } else {
+               debug_error("Construct Param for method call failed");
+               return MM_ERROR_SOUND_INTERNAL;
+       }
+
+       if (result) {
+               g_variant_get(result, "(i)",  &reply);
+               debug_log("reply : %d", reply);
+               *get = reply;
+       } else {
+               debug_error("reply null");
+       }
+
+cleanup:
+       if (result)
+               g_variant_unref(result);
+
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_client_dbus_get_current_connected_device_list(int device_flags, GList** device_list)
+{
+       int ret = MM_ERROR_NONE;
+       GVariant *result = NULL, *child = NULL;
+       GVariant *params;
+       GVariantIter iter;
+       mm_sound_device_t* device_item;
+       GList* g_device_list = NULL;
+       const gchar *device_name_tmp = NULL, *device_type_tmp = NULL;
+
+       debug_fenter();
+
+       if (!device_list) {
+               debug_error("Invalid Parameter, device_list null");
+               ret = MM_ERROR_INVALID_ARGUMENT;
+               goto cleanup;
+       }
+
+       params = g_variant_new("(i)", device_flags);
+
+       if (params) {
+               if ((ret = _dbus_method_call_to(DBUS_TO_PULSE_MODULE_DEVICE_MANAGER, METHOD_CALL_GET_CONNECTED_DEVICE_LIST, params, &result)) != MM_ERROR_NONE) {
+                       debug_error("Get current connected device list failed");
+                       goto cleanup;
+               }
+       } else {
+               debug_error("Construct Param for get current connected device failed");
+               return MM_ERROR_SOUND_INTERNAL;
+       }
+
+       child = g_variant_get_child_value(result, 0);
+       g_variant_iter_init(&iter, child);
+       while (1) {
+               device_item = g_malloc0(sizeof(mm_sound_device_t));
+               if (device_item && g_variant_iter_loop(&iter, "(i&sii&s)", &device_item->id, &device_type_tmp, &device_item->io_direction, &device_item->state, &device_name_tmp)) {
+                       MMSOUND_STRNCPY(device_item->name, device_name_tmp, MAX_DEVICE_NAME_NUM);
+                       MMSOUND_STRNCPY(device_item->type, device_type_tmp, MAX_DEVICE_TYPE_STR_LEN);
+                       *device_list = g_list_append(*device_list, device_item);
+                       debug_log("Added device id(%d) type(%17s) direction(%d) state(%d) name(%s)", device_item->id, device_item->type,device_item->io_direction, device_item->state, device_item->name);
+               } else {
+                       if (device_item)
+                               g_free(device_item);
+                       break;
+               }
+       }
+
+cleanup:
+       if (result)
+               g_variant_unref(result);
+
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_client_dbus_add_device_connected_callback(int device_flags, mm_sound_device_connected_cb func, void* user_data)
+{
+       int ret = MM_ERROR_NONE;
+
+       debug_fenter();
+
+       if ((ret = _dbus_signal_subscribe_to(DBUS_TO_PULSE_MODULE_DEVICE_MANAGER, SIGNAL_DEVICE_CONNECTED, func, user_data, device_flags)) != MM_ERROR_NONE) {
+               debug_error("add device connected callback failed");
+       }
+
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_client_dbus_remove_device_connected_callback(void)
+{
+       int ret = MM_ERROR_NONE;
+       debug_fenter();
+
+       if ((ret = _sound_server_dbus_signal_unsubscribe(SIGNAL_DEVICE_CONNECTED)) != MM_ERROR_NONE) {
+               debug_error("remove device connected callback failed");
+       }
+
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_client_dbus_add_device_info_changed_callback(int device_flags, mm_sound_device_info_changed_cb func, void* user_data)
+{
+       int ret = MM_ERROR_NONE;
+       debug_fenter();
+
+       if ((ret = _dbus_signal_subscribe_to(DBUS_TO_PULSE_MODULE_DEVICE_MANAGER, SIGNAL_DEVICE_INFO_CHANGED, func, user_data, device_flags)) != MM_ERROR_NONE) {
+               debug_error("Add device info changed callback failed");
+       }
+
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_client_dbus_remove_device_info_changed_callback(void)
+{
+       int ret = MM_ERROR_NONE;
+       debug_fenter();
+
+       if ((ret = _sound_server_dbus_signal_unsubscribe(SIGNAL_DEVICE_INFO_CHANGED)) != MM_ERROR_NONE) {
+               debug_error("remove device info changed callback failed");
+       }
+
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_client_dbus_is_bt_a2dp_on (bool *connected, char** bt_name)
+{
+       int ret = MM_ERROR_NONE;
+       GVariant* result = NULL;
+       gboolean _connected;
+       gchar* _bt_name = NULL;
+
+       debug_fenter();
+
+       if((ret = _dbus_method_call_to(DBUS_TO_PULSE_MODULE_DEVICE_MANAGER, METHOD_CALL_GET_BT_A2DP_STATUS, NULL, &result)) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+       g_variant_get(result, "(bs)", &_connected, &_bt_name);
+
+       *connected = _connected;
+       *bt_name = (_connected)? _bt_name : NULL;
+
+cleanup:
+       if (result)
+               g_variant_unref(result);
+
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_client_dbus_set_volume_by_type(const int volume_type, const unsigned int volume_level)
+{
+       int ret = MM_ERROR_NONE;
+       char *reply = NULL, *type_str = NULL, *direction = "out";
+       GVariant *params = NULL, *result = NULL;
+
+       debug_fenter();
+
+       if (ret = __convert_volume_type_to_str(volume_type, &type_str) != MM_ERROR_NONE) {
+               debug_error("volume type convert failed");
+               return ret;
+       }
+
+       params = g_variant_new("(ssu)", direction, type_str, volume_level);
+       if (params) {
+               if ((ret = _dbus_method_call_to(DBUS_TO_PULSE_MODULE_STREAM_MANAGER, METHOD_CALL_SET_VOLUME_LEVEL, params, &result)) != MM_ERROR_NONE) {
+                       debug_error("dbus test call failed");
+                       goto cleanup;
+               }
+       } else {
+               debug_error("Construct Param for method call failed");
+               return MM_ERROR_SOUND_INTERNAL;
+       }
+
+       if (result) {
+               g_variant_get(result, "(&s)",  &reply);
+               debug_log("reply : %s", reply);
+               if (!strcmp(reply, "STREAM_MANAGER_RETURN_ERROR"))
+                       ret = MM_ERROR_SOUND_INTERNAL;
+       } else {
+               debug_error("reply null");
+       }
+
+cleanup:
+       if (result)
+               g_variant_unref(result);
+
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_client_dbus_add_volume_changed_callback(mm_sound_volume_changed_cb func, void* user_data)
+{
+       int ret = MM_ERROR_NONE;
+
+       debug_fenter();
+
+       if ((ret = _dbus_signal_subscribe_to(DBUS_TO_PULSE_MODULE_STREAM_MANAGER, SIGNAL_VOLUME_CHANGED, func, user_data, 0)) != MM_ERROR_NONE) {
+               debug_error("Add Volume changed callback failed");
+       }
+
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_client_dbus_remove_volume_changed_callback(void)
+{
+       int ret = MM_ERROR_NONE;
+       debug_fenter();
+
+       if ((ret = _sound_server_dbus_signal_unsubscribe(SIGNAL_VOLUME_CHANGED)) != MM_ERROR_NONE) {
+               debug_error("Remove Volume changed callback failed");
+       }
+
+       debug_fleave();
+       return ret;
+}
+
+
+int mm_sound_client_dbus_get_audio_path(mm_sound_device_in *device_in, mm_sound_device_out *device_out)
+{
+       int ret = MM_ERROR_NONE;
+       GVariant *result = NULL;
+
+       debug_fenter();
+
+       if ((ret = _dbus_method_call_to(DBUS_TO_SOUND_SERVER, METHOD_CALL_GET_AUDIO_PATH, NULL, &result)) != MM_ERROR_NONE) {
+               debug_error("add device connected callback failed");
+               goto cleanup;
+       }
+
+       g_variant_get(result, "(ii)", device_in, device_out );
+
+cleanup:
+       if (result)
+               g_variant_unref(result);
+
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_client_dbus_play_tone(int tone, int repeat, int volume, int volume_config,
+                          int session_type, int session_options, int client_pid,
+                          bool enable_session, int *codechandle, char *stream_type, int stream_index)
+{
+       int ret = MM_ERROR_NONE;
+       int handle = 0;
+       GVariant* params = NULL, *result = NULL;
+       gboolean _enable_session = enable_session;
+
+       if (!codechandle) {
+               debug_error("Param for play is null");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       debug_fenter();
+
+       params = g_variant_new("(iiiiiiibsi)", tone, repeat, volume,
+                     volume_config, session_type, session_options, client_pid , _enable_session, stream_type, stream_index);
+       if (params) {
+               if ((ret = _dbus_method_call_to(DBUS_TO_SOUND_SERVER, METHOD_CALL_PLAY_DTMF, params, &result)) != MM_ERROR_NONE) {
+                       debug_error("dbus play tone failed");
+                       goto cleanup;
+               }
+       } else {
+               debug_error("Construct Param for method call failed");
+       }
+
+       if (result) {
+               g_variant_get(result, "(i)",  &handle);
+               debug_log("handle : %d", handle);
+               *codechandle = handle;
+       } else {
+               debug_error("reply null");
+       }
+
+cleanup:
+       if (result)
+               g_variant_unref(result);
+
+       debug_fleave();
+       return ret;
+
+
+}
+
+int mm_sound_client_dbus_play_tone_with_stream_info(int client_pid, int tone, char *stream_type, int stream_index, int volume, int repeat, int *codechandle)
+{
+       int ret = MM_ERROR_NONE;
+       int handle = 0;
+       GVariant* params = NULL, *result = NULL;
+
+       debug_fenter();
+
+       if (!codechandle) {
+               debug_error("Param for play is null");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       params = g_variant_new("(iiiisi)", tone, repeat, volume, client_pid, stream_type, stream_index);
+       if (params) {
+               if ((ret = _dbus_method_call_to(DBUS_TO_SOUND_SERVER, METHOD_CALL_PLAY_DTMF_WITH_STREAM_INFO, params, &result)) != MM_ERROR_NONE) {
+                       debug_error("dbus play tone failed");
+                       goto cleanup;
+               }
+       } else {
+               debug_error("Construct Param for method call failed");
+       }
+
+       if (result) {
+               g_variant_get(result, "(i)",  &handle);
+               debug_log("handle : %d", handle);
+               *codechandle = handle;
+       } else {
+               debug_error("reply null");
+       }
+
+cleanup:
+       if (result)
+               g_variant_unref(result);
+
+       debug_fleave();
+       return ret;
+
+
+}
+
+int mm_sound_client_dbus_play_sound(char* filename, int tone, int repeat, int volume, int volume_config,
+                          int priority, int session_type, int session_options, int client_pid, int keytone,  int handle_route,
+                          bool enable_session, int *codechandle, char *stream_type, int stream_index)
+{
+       int ret = MM_ERROR_NONE;
+       int handle = 0;
+       GVariant* params = NULL, *result = NULL;
+       gboolean _enable_session = enable_session;
+
+       if (!filename || !codechandle) {
+               debug_error("Param for play is null");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       debug_fenter();
+
+       params = g_variant_new("(siiiiiiiiiibsi)", filename, tone, repeat, volume,
+                     volume_config, priority, session_type, session_options, client_pid, keytone, handle_route, _enable_session, stream_type, stream_index);
+       if (params) {
+               if ((ret = _dbus_method_call_to(DBUS_TO_SOUND_SERVER, METHOD_CALL_PLAY_FILE_START, params, &result)) != MM_ERROR_NONE) {
+                       debug_error("dbus play file failed");
+                       goto cleanup;
+               }
+       } else {
+               debug_error("Construct Param for method call failed");
+       }
+
+       if (result) {
+               g_variant_get(result, "(i)",  &handle);
+               debug_log("handle : %d", handle);
+               *codechandle = handle;
+       } else {
+               debug_error("reply null");
+       }
+
+cleanup:
+       if (result)
+               g_variant_unref(result);
+
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_client_dbus_play_sound_with_stream_info(char* filename, int repeat, int volume,
+                          int priority, int client_pid, int handle_route, int *codechandle, char *stream_type, int stream_index)
+{
+       int ret = MM_ERROR_NONE;
+       int handle = 0;
+       GVariant* params = NULL, *result = NULL;
+
+       if (!filename || !codechandle) {
+               debug_error("Param for play is null");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       debug_fenter();
+
+       params = g_variant_new("(siiiiisi)", filename, repeat, volume,
+                     priority, client_pid, handle_route, stream_type, stream_index);
+       if (params) {
+               if ((ret = _dbus_method_call_to(DBUS_TO_SOUND_SERVER, METHOD_CALL_PLAY_FILE_START_WITH_STREAM_INFO, params, &result)) != MM_ERROR_NONE) {
+                       debug_error("dbus play file failed");
+                       goto cleanup;
+               }
+       } else {
+               debug_error("Construct Param for method call failed");
+       }
+
+       if (result) {
+               g_variant_get(result, "(i)",  &handle);
+               debug_log("handle : %d", handle);
+               *codechandle = handle;
+       } else {
+               debug_error("reply null");
+       }
+
+cleanup:
+       if (result)
+               g_variant_unref(result);
+
+       debug_fleave();
+       return ret;
+
+
+}
+
+
+int mm_sound_client_dbus_stop_sound(int handle)
+{
+       int ret = MM_ERROR_NONE;
+       GVariant *result = NULL;
+
+       debug_fenter();
+
+       if ((ret = _dbus_method_call_to(DBUS_TO_SOUND_SERVER, METHOD_CALL_PLAY_FILE_STOP, g_variant_new("(i)", handle), &result)) != MM_ERROR_NONE) {
+               debug_error("dbus stop file playing failed");
+               goto cleanup;
+       }
+
+cleanup:
+       if (result)
+               g_variant_unref(result);
+
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_client_dbus_is_route_available(mm_sound_route route, bool *is_available)
+{
+       int ret = MM_ERROR_NONE;
+
+       debug_fenter();
+       ret = MM_ERROR_SOUND_NOT_SUPPORTED_OPERATION;
+       debug_fleave();
+
+       return ret;
+}
+
+int mm_sound_client_dbus_foreach_available_route_cb(mm_sound_available_route_cb avail_cb, void *user_data)
+{
+       int ret = MM_ERROR_NONE;
+
+       debug_fenter();
+       ret = MM_ERROR_SOUND_NOT_SUPPORTED_OPERATION;
+       debug_fleave();
+
+       return ret;
+}
+
+int mm_sound_client_dbus_set_active_route(mm_sound_route route, bool need_broadcast)
+{
+       int ret = MM_ERROR_NONE;
+
+       debug_fenter();
+       ret = MM_ERROR_SOUND_NOT_SUPPORTED_OPERATION;
+       debug_fleave();
+
+       return ret;
+}
+
+int mm_sound_client_dbus_get_active_device(mm_sound_device_in *device_in, mm_sound_device_out *device_out)
+{
+       int ret = MM_ERROR_NONE;
+
+       debug_fenter();
+       ret = MM_ERROR_SOUND_NOT_SUPPORTED_OPERATION;
+       debug_fleave();
+
+       return ret;
+}
+
+int mm_sound_client_dbus_add_play_sound_end_callback(int handle, mm_sound_stop_callback_func stop_cb, void* userdata)
+{
+       int ret = MM_ERROR_NONE;
+
+       debug_fenter();
+
+       if ((ret = _dbus_signal_subscribe_to(DBUS_TO_SOUND_SERVER, SIGNAL_PLAY_FILE_END, stop_cb, userdata, handle)) != MM_ERROR_NONE) {
+               debug_error("add play sound end callback failed");
+       }
+
+       debug_fleave();
+
+       return ret;
+}
+
+int mm_sound_client_dbus_add_active_device_changed_callback(const char *name, mm_sound_active_device_changed_cb func, void* user_data)
+{
+       int ret = MM_ERROR_NONE;
+
+       debug_fenter();
+       ret = MM_ERROR_SOUND_NOT_SUPPORTED_OPERATION;
+       debug_fleave();
+
+       return ret;
+}
+
+int mm_sound_client_dbus_remove_active_device_changed_callback(const char *name)
+{
+       int ret = MM_ERROR_NONE;
+
+       debug_fenter();
+       ret = MM_ERROR_SOUND_NOT_SUPPORTED_OPERATION;
+       debug_fleave();
+
+       return ret;
+}
+
+int mm_sound_client_dbus_add_available_route_changed_callback(mm_sound_available_route_changed_cb func, void* user_data)
+{
+       int ret = MM_ERROR_NONE;
+
+       debug_fenter();
+       ret = MM_ERROR_SOUND_NOT_SUPPORTED_OPERATION;
+       debug_fleave();
+
+       return ret;
+}
+
+int mm_sound_client_dbus_remove_available_route_changed_callback(void)
+{
+       int ret = MM_ERROR_NONE;
+
+       debug_fenter();
+       ret = MM_ERROR_SOUND_NOT_SUPPORTED_OPERATION;
+       debug_fleave();
+
+       return ret;
+}
+
+int mm_sound_client_dbus_set_sound_path_for_active_device(mm_sound_device_out device_out, mm_sound_device_in device_in)
+{
+       int ret = MM_ERROR_NONE;
+
+       debug_fenter();
+       ret = MM_ERROR_SOUND_NOT_SUPPORTED_OPERATION;
+       debug_fleave();
+
+       return ret;
+}
+
+int mm_sound_client_dbus_set_active_route_auto(void)
+{
+       int ret = MM_ERROR_NONE;
+
+       debug_fenter();
+       ret = MM_ERROR_SOUND_NOT_SUPPORTED_OPERATION;
+       debug_fleave();
+
+       return ret;
+}
+
+/*------------------------------------------ FOCUS --------------------------------------------------*/
+#ifdef USE_FOCUS
+
+#ifdef SUPPORT_CONTAINER
+#ifdef USE_SECURITY
+char* _get_cookie(int cookie_size)
+{
+       int retval = -1;
+       char* cookie = NULL;
+
+       if (security_server_get_cookie_size() != cookie_size) {
+               debug_error ("[Security] security_server_get_cookie_size() != COOKIE_SIZE(%d)\n", cookie_size);
+               return false;
+       }
+
+       cookie = (char*)malloc (cookie_size);
+
+       retval = security_server_request_cookie (cookie, cookie_size);
+       if (retval == SECURITY_SERVER_API_SUCCESS) {
+               debug_msg ("[Security] security_server_request_cookie() returns [%d]\n", retval);
+       } else {
+               debug_error ("[Security] security_server_request_cookie() returns [%d]\n", retval);
+       }
+
+       return cookie;
+}
+
+static GVariant* _get_cookie_variant ()
+{
+       int i;
+       GVariantBuilder builder;
+       char* cookie = NULL;
+
+       cookie = _get_cookie(COOKIE_SIZE);
+
+       if (cookie == NULL)
+               return NULL;
+
+       g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
+       for (i = 0; i < COOKIE_SIZE; i++)
+               g_variant_builder_add(&builder, "y", cookie[i]);
+
+       free (cookie);
+       return g_variant_builder_end(&builder);
+}
+
+#endif /* USE_SECURITY */
+#endif /* SUPPORT_CONTAINER */
+
+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 bool _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 (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("Can not find index");
+                       return FALSE;
+               }
+
+               if (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;
+
+               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..");
+                       }
+                       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]");
+               }
+#ifdef CONFIG_ENABLE_RETCB
+
+                               int rett = 0;
+                               int tmpfd = -1;
+                               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);
+                                       if (g_focus_sound_handle[focus_index].focus_lock) {
+                                               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 (g_focus_sound_handle[focus_index].focus_lock) {
+               g_mutex_unlock(g_focus_sound_handle[focus_index].focus_lock);
+       }
+
+       return TRUE;
+}
+
+static gboolean _focus_watch_callback_handler( gpointer d)
+{
+       GPollFD *data = (GPollFD*)d;
+       int count;
+       int tid = 0;
+       int focus_index = 0;
+       focus_cb_data_lib cb_data;
+
+       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 = cb_data.handle - 1;
+               if (focus_index < 0) {
+                       debug_error("index is not valid, %d", focus_index);
+                       return FALSE;
+               }
+
+               if (g_focus_sound_handle[focus_index].focus_lock) {
+                       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..");
+                       if (g_focus_sound_handle[focus_index].focus_lock) {
+                               g_mutex_unlock(g_focus_sound_handle[focus_index].focus_lock);
+                       }
+                       return FALSE;
+               }
+
+               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]");
+
+#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);
+                               if (g_focus_sound_handle[focus_index].focus_lock) {
+                                       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 (g_focus_sound_handle[focus_index].focus_lock) {
+               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);
+       }
+
+       debug_fleave();
+
+
+       return TRUE;
+}
+
+static void _focus_open_callback(int index, bool is_for_watching)
+{
+       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;
+
+       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);
+       }
+       pre_mask = umask(0);
+       if (mknod(filename2, S_IFIFO | 0666, 0)) {
+               debug_error("mknod() failure, errno(%d)", errno);
+       }
+       umask(pre_mask);
+       g_free(filename2);
+       filename2 = NULL;
+#endif
+       debug_fleave();
+
+}
+
+void _focus_close_callback(int index, bool is_for_watching)
+{
+       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;
+       }
+
+#ifdef CONFIG_ENABLE_RETCB
+       char *filename2;
+
+       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);
+       }
+
+       /* 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;
+
+       tmpfd = open(filename2, O_WRONLY | O_NONBLOCK);
+       if (tmpfd < 0) {
+               char str_error[256];
+               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 {
+               debug_msg("write MM_ERROR_NONE(tid:%d) for waiting server", g_focus_sound_handle[index].focus_tid);
+               write(tmpfd, &buf, sizeof(buf));
+               close(tmpfd);
+       }
+
+       if (remove(filename2)) {
+               debug_error("remove() failure, filename(%s), errno(%d)", filename2, errno);
+       }
+       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 )
+{
+       GSource* g_src = NULL;
+       GSourceFuncs *g_src_funcs = NULL;               /* handler function */
+       guint gsource_handle;
+       GPollFD *g_poll_fd = NULL;                      /* file descriptor */
+
+       debug_fenter();
+
+       g_focus_sound_handle[index].focus_lock = g_mutex_new();
+       if (!g_focus_sound_handle[index].focus_lock) {
+               debug_error("failed to g_mutex_new() for index(%d)", index);
+               return false;
+       }
+
+       /* 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;
+       }
+
+       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);
+
+       /* 4. set callback */
+       g_source_set_callback(g_src, p_gloop_poll_handler,(gpointer)g_poll_fd, NULL);
+
+       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);
+
+       debug_fleave();
+       return true;
+
+
+}
+
+static bool _focus_remove_sound_callback(int index, gushort events)
+{
+       bool ret = true;
+       gboolean gret = TRUE;
+
+       debug_fenter();
+
+       if (g_focus_sound_handle[index].focus_lock) {
+               g_mutex_free(g_focus_sound_handle[index].focus_lock);
+               g_focus_sound_handle[index].focus_lock = NULL;
+       }
+
+       GSourceFunc *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;
+
+       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);
+
+init_handle:
+
+       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(), asm_src(0x%p)", g_focus_sound_handle[index].focus_src);
+               }
+       }
+       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;
+       }
+
+       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;
+
+       debug_fleave();
+       return ret;
+}
+
+
+static void _focus_add_callback(int index, bool is_for_watching)
+{
+       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 __ASM_add_sound_callback(asm_callback_handler)");
+                       //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 __ASM_add_sound_callback(watch_callback_handler)");
+                       //return false;
+               }
+       }
+       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;
+       }
+       debug_fleave();
+}
+
+static void _focus_init_callback(int index, bool is_for_watching)
+{
+       debug_fenter();
+       _focus_open_callback(index, is_for_watching);
+       _focus_add_callback(index, is_for_watching);
+       debug_fleave();
+}
+
+static void _focus_destroy_callback(int index, bool is_for_watching)
+{
+       debug_fenter();
+       _focus_remove_callback(index);
+       _focus_close_callback(index, is_for_watching);
+       debug_fleave();
+}
+
+int mm_sound_client_dbus_register_focus(int id, const char *stream_type, mm_sound_focus_changed_cb callback, void* user_data)
+{
+       int ret = MM_ERROR_NONE;
+       int instance;
+       int index = 0;
+       GVariant* params = NULL, *result = NULL;
+#ifdef SUPPORT_CONTAINER
+       char container[128];
+#endif
+
+       debug_fenter();
+
+//     pthread_mutex_lock(&g_thread_mutex2);
+
+       instance = getpid();
+
+       for (index = 0; index < FOCUS_HANDLE_MAX; index++) {
+               if (g_focus_sound_handle[index].is_used == false) {
+                       g_focus_sound_handle[index].is_used = true;
+                       break;
+               }
+       }
+
+       g_focus_sound_handle[index].focus_tid = instance;
+       g_focus_sound_handle[index].handle = id;
+       g_focus_sound_handle[index].focus_callback = callback;
+       g_focus_sound_handle[index].user_data = user_data;
+
+#ifdef SUPPORT_CONTAINER
+#ifdef USE_SECURITY
+       params = g_variant_new("(@ayiis)", _get_cookie_variant(), instance, id, stream_type);
+#else /* USE_SECURITY */
+       gethostname(container, sizeof(container));
+       debug_error("container = %s", container);
+       params = g_variant_new("(siis)", container, instance, id, stream_type);
+#endif /* USE_SECURITY */
+
+#else /* SUPPORT_CONTAINER */
+       params = g_variant_new("(iis)", instance, id, stream_type);
+
+#endif /* SUPPORT_CONTAINER */
+
+       if (params) {
+               if ((ret = _dbus_method_call_to(DBUS_TO_SOUND_SERVER, METHOD_CALL_REGISTER_FOCUS, params, &result)) != MM_ERROR_NONE) {
+                       debug_error("dbus register focus failed");
+                       goto cleanup;
+               }
+       } else {
+               debug_error("Construct Param for method call failed");
+       }
+
+       if (ret == MM_ERROR_NONE) {
+               debug_msg("[Client] Success to register focus\n");
+               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_create(_focus_thread_func, NULL, TRUE, 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;
+                       }
+               }
+       } else {
+               g_variant_get(result, "(i)",  &ret);
+               debug_error("[Client] Error occurred : %d \n",ret);
+               g_focus_sound_handle[index].is_used = false;
+               goto cleanup;
+       }
+
+       _focus_init_callback(index, false);
+
+cleanup:
+       //pthread_mutex_unlock(&g_thread_mutex2);
+       if (result) {
+               g_variant_unref(result);
+       }
+
+       debug_fleave();
+
+       return ret;
+
+}
+
+int mm_sound_client_dbus_unregister_focus(int id)
+{
+       int ret = MM_ERROR_NONE;
+       int instance;
+       int index = -1;
+       GVariant* params = NULL, *result = NULL;
+
+       debug_fenter();
+
+       //pthread_mutex_lock(&g_thread_mutex2);
+
+       instance = getpid();
+       index = _focus_find_index_by_handle(id);
+
+       if (g_focus_sound_handle[index].focus_lock) {
+               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)) {
+                               debug_msg("finally got asm_lock");
+                       }
+               }
+       }
+
+       params = g_variant_new("(ii)", instance, id);
+       if (params) {
+               if ((ret = _dbus_method_call_to(DBUS_TO_SOUND_SERVER, METHOD_CALL_UNREGISTER_FOCUS, params, &result)) != MM_ERROR_NONE) {
+                       debug_error("dbus unregister focus failed");
+                       goto cleanup;
+               }
+       } else {
+               debug_error("Construct Param for method call failed");
+       }
+
+       if (ret == MM_ERROR_NONE) {
+               debug_msg("[Client] Success to unregister focus\n");
+       } else {
+               g_variant_get(result, "(i)",  &ret);
+               debug_error("[Client] Error occurred : %d \n",ret);
+               goto cleanup;
+       }
+
+
+cleanup:
+       //pthread_mutex_unlock(&g_thread_mutex2);
+       if (g_focus_sound_handle[index].focus_lock) {
+               g_mutex_unlock(g_focus_sound_handle[index].focus_lock);
+       }
+
+       _focus_destroy_callback(index, false);
+       g_focus_sound_handle[index].focus_fd = 0;
+       g_focus_sound_handle[index].focus_tid = 0;
+       g_focus_sound_handle[index].handle = 0;
+       g_focus_sound_handle[index].is_used = false;
+
+       if (result) {
+               g_variant_unref(result);
+       }
+
+       debug_fleave();
+
+       return ret;
+}
+
+int mm_sound_client_dbus_acquire_focus(int id, mm_sound_focus_type_e type, const char *option)
+{
+       int ret = MM_ERROR_NONE;
+       int instance;
+       GVariant* params = NULL, *result = NULL;
+
+       debug_fenter();
+
+       //pthread_mutex_lock(&g_thread_mutex2);
+
+       instance = getpid();
+
+       params = g_variant_new("(iiis)", instance, id, type, option);
+       if (params) {
+               if ((ret = _dbus_method_call_to(DBUS_TO_SOUND_SERVER, METHOD_CALL_ACQUIRE_FOCUS, params, &result)) != MM_ERROR_NONE) {
+                       debug_error("dbus acquire focus failed");
+                       goto cleanup;
+               }
+       } else {
+               debug_error("Construct Param for method call failed");
+       }
+
+       if (ret == MM_ERROR_NONE) {
+               debug_msg("[Client] Success to acquire focus\n");
+       } else {
+               g_variant_get(result, "(i)",  &ret);
+               debug_error("[Client] Error occurred : %d \n",ret);
+       }
+
+cleanup:
+       //pthread_mutex_unlock(&g_thread_mutex2);
+
+       if (result) {
+               g_variant_unref(result);
+       }
+
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_client_dbus_release_focus(int id, mm_sound_focus_type_e type, const char *option)
+{
+       int ret = MM_ERROR_NONE;
+       int instance;
+       GVariant* params = NULL, *result = NULL;
+
+       debug_fenter();
+
+       //pthread_mutex_lock(&g_thread_mutex2);
+
+       instance = getpid();;
+
+       params = g_variant_new("(iiis)", instance, id, type, option);
+       if (params) {
+               if ((ret = _dbus_method_call_to(DBUS_TO_SOUND_SERVER, METHOD_CALL_RELEASE_FOCUS, params, &result)) != MM_ERROR_NONE) {
+                       debug_error("dbus release focus failed");
+                       goto cleanup;
+               }
+       } else {
+               debug_error("Construct Param for method call failed");
+       }
+
+       if (ret == MM_ERROR_NONE) {
+               debug_msg("[Client] Success to release focus\n");
+       } else {
+               g_variant_get(result, "(i)",  &ret);
+               debug_error("[Client] Error occurred : %d \n",ret);
+       }
+
+cleanup:
+       //pthread_mutex_unlock(&g_thread_mutex2);
+
+       if (result) {
+               g_variant_unref(result);
+       }
+
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_client_dbus_set_focus_watch_callback(mm_sound_focus_type_e type, mm_sound_focus_changed_watch_cb callback, void* user_data, int *id)
+{
+       int ret = MM_ERROR_NONE;
+       int instance;
+       int index = 0;
+       GVariant* params = NULL, *result = NULL;
+#ifdef SUPPORT_CONTAINER
+       char container[128];
+#endif
+
+       debug_fenter();
+
+       if (!id)
+               return MM_ERROR_INVALID_ARGUMENT;
+
+       //pthread_mutex_lock(&g_thread_mutex2);
+
+       instance = getpid();
+
+       for (index = 0; index < FOCUS_HANDLE_MAX; index++) {
+               if (g_focus_sound_handle[index].is_used == false) {
+                       g_focus_sound_handle[index].is_used = true;
+                       break;
+               }
+       }
+
+       g_focus_sound_handle[index].focus_tid = instance;
+       g_focus_sound_handle[index].handle = index + 1;
+       g_focus_sound_handle[index].watch_callback = callback;
+       g_focus_sound_handle[index].user_data = user_data;
+
+#ifdef SUPPORT_CONTAINER
+#ifdef USE_SECURITY
+       params = g_variant_new("(@ayiii)", _get_cookie_variant(), instance, g_focus_sound_handle[index].handle, type);
+#else /* USE_SECURITY */
+       gethostname(container, sizeof(container));
+       debug_error("container = %s", container);
+       params = g_variant_new("(siii)", container, instance, g_focus_sound_handle[index].handle, type);
+#endif /* USE_SECURITY */
+
+#else /* SUPPORT_CONTAINER */
+       params = g_variant_new("(iii)", instance, g_focus_sound_handle[index].handle, type);
+
+#endif /* SUPPORT_CONTAINER */
+
+       if (params) {
+               if ((ret = _dbus_method_call_to(DBUS_TO_SOUND_SERVER, METHOD_CALL_WATCH_FOCUS, params, &result)) != MM_ERROR_NONE) {
+                       debug_error("dbus set watch focus failed");
+                       goto cleanup;
+               }
+       } else {
+               debug_error("Construct Param for method call failed");
+       }
+
+       if (ret == MM_ERROR_NONE) {
+               debug_msg("[Client] Success to watch focus");
+               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_create(_focus_thread_func, NULL, TRUE, 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;
+                       }
+               }
+       } else {
+               g_variant_get(result, "(i)",  &ret);
+               debug_error("[Client] Error occurred : %d",ret);
+               goto cleanup;
+       }
+
+       _focus_init_callback(index, true);
+
+       *id = g_focus_sound_handle[index].handle;
+
+cleanup:
+       if (ret) {
+               g_focus_sound_handle[index].is_used = false;
+       }
+       //pthread_mutex_unlock(&g_thread_mutex2);
+
+       if (result) {
+               g_variant_unref(result);
+       }
+
+       debug_fleave();
+
+       return ret;
+
+}
+
+int mm_sound_client_dbus_unset_focus_watch_callback(int id)
+{
+       int ret = MM_ERROR_NONE;
+       int index = -1;
+       GVariant* params = NULL, *result = NULL;
+
+       debug_fenter();
+
+       //pthread_mutex_lock(&g_thread_mutex2);
+
+       index = id - 1;
+       if (index < 0 || FOCUS_HANDLE_MAX <= index) {
+               debug_error("index is not valid, %d", index);
+               return FALSE;
+       }
+
+       if (g_focus_sound_handle[index].focus_lock) {
+               g_mutex_lock(g_focus_sound_handle[index].focus_lock);
+       }
+
+       params = g_variant_new("(ii)", g_focus_sound_handle[index].focus_tid, g_focus_sound_handle[index].handle);
+       if (params) {
+               if ((ret = _dbus_method_call_to(DBUS_TO_SOUND_SERVER, METHOD_CALL_UNWATCH_FOCUS, params, &result)) != MM_ERROR_NONE) {
+                       debug_error("dbus unset watch focus failed");
+                       goto cleanup;
+               }
+       } else {
+               debug_error("Construct Param for method call failed");
+       }
+
+       if (ret == MM_ERROR_NONE) {
+               debug_msg("[Client] Success to unwatch focus\n");
+       } else {
+               g_variant_get(result, "(i)",  &ret);
+               debug_error("[Client] Error occurred : %d \n",ret);
+       }
+
+cleanup:
+       //pthread_mutex_unlock(&g_thread_mutex2);
+
+       if (g_focus_sound_handle[index].focus_lock) {
+               g_mutex_unlock(g_focus_sound_handle[index].focus_lock);
+       }
+       _focus_destroy_callback(index, true);
+       g_focus_sound_handle[index].focus_fd = 0;
+       g_focus_sound_handle[index].focus_tid = 0;
+       g_focus_sound_handle[index].handle = 0;
+       g_focus_sound_handle[index].is_used = false;
+
+       if (result) {
+               g_variant_unref(result);
+       }
+
+       debug_fleave();
+
+       return ret;
+}
+
+#endif /* USE_FOCUS */
+/*------------------------------------------ FOCUS --------------------------------------------------*/
+
+int mm_sound_client_dbus_initialize(void)
+{
+       int ret = MM_ERROR_NONE;
+
+       debug_fenter();
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_client_dbus_finalize(void)
+{
+       int ret = MM_ERROR_NONE;
+
+       debug_fenter();
+
+       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;
+       }
+
+       debug_fleave();
+
+       return ret;
+}
diff --git a/mm_sound_client_msgq.c b/mm_sound_client_msgq.c
new file mode 100644 (file)
index 0000000..33d9359
--- /dev/null
@@ -0,0 +1,2646 @@
+/*
+ * libmm-sound
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Seungbae Shin <seungbae.shin@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <sys/shm.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/msg.h>
+#include <assert.h>
+#include <errno.h>
+
+#include <pthread.h>
+#include <semaphore.h>
+
+#include <mm_error.h>
+#include <mm_debug.h>
+
+#include "include/mm_sound.h"
+#include "include/mm_sound_msg.h"
+#include "include/mm_sound_client.h"
+#include "include/mm_sound_client_msgq.h"
+#include "include/mm_sound_common.h"
+#include "include/mm_sound_device.h"
+#ifdef USE_FOCUS
+#include "include/mm_sound_focus.h"
+#endif
+
+#include <mm_session.h>
+#include <mm_session_private.h>
+
+#define __DIRECT_CALLBACK__
+//#define __GIDLE_CALLBACK__
+
+#include <glib.h>
+#if defined(__GSOURCE_CALLBACK__)
+#include <sys/poll.h>
+#endif
+
+#define MEMTYPE_SUPPORT_MAX (1024 * 1024) /* 1MB */
+#define MEMTYPE_TRANS_PER_MAX (128 * 1024) /* 128K */
+
+int g_msg_scsnd;     /* global msg queue id for sending msg to sound client */
+int g_msg_scrcv;     /* global msg queue id for receiving msg from sound client */
+int g_msg_sccb;      /* global msg queue id for triggering callback to sound client */
+int g_msg_scsndcb;   /* global msg queue id for triggering callback to sound client in case of synchronous API */
+int g_msg_scrcvcb;   /* global msg queue id for replying callback result from sound client in case of synchronous API */
+
+/* global variables for device list */
+static GList *g_device_list = NULL;
+static mm_sound_device_list_t g_device_list_t;
+static pthread_mutex_t g_device_list_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+/* callback */
+struct __callback_param
+{
+       mm_sound_stop_callback_func     callback;
+    void                    *data;
+};
+
+pthread_t g_thread;
+pthread_t g_thread2;
+static int g_exit_thread = 0;
+int g_thread_id = -1;
+int g_thread_id2 = -1;
+pthread_mutex_t g_thread_mutex = PTHREAD_MUTEX_INITIALIZER;
+pthread_mutex_t g_thread_mutex2 = PTHREAD_MUTEX_INITIALIZER;
+
+static void* callbackfunc(void *param);
+
+/* manage IPC (msg contorl) */
+static int __MMIpcCBSndMsg(mm_ipc_msg_t *msg);
+static int __MMIpcRecvMsg(int msgtype, mm_ipc_msg_t *msg);
+static int __MMIpcSndMsg(mm_ipc_msg_t *msg);
+static int __MMIpcCBRecvMsg(int msgtype, mm_ipc_msg_t *msg);
+static int __MMIpcCBRecvMsgForReply(int msgtype, mm_ipc_msg_t *msg);
+static int __MMIpcCBSndMsgReply(mm_ipc_msg_t *msg);
+static int __MMSoundGetMsg(void);
+
+int MMSoundClientMsgqInit(void)
+{
+       int ret = MM_ERROR_NONE;
+       debug_fenter();
+
+       debug_fleave();
+       return ret;
+}
+
+int MMSoundClientMsgqCallbackFini(void)
+{
+       mm_ipc_msg_t msgsnd={0,};
+       int ret = MM_ERROR_NONE;
+
+       debug_fenter();
+
+       /* When the the callback thread is not created, do not wait destroy thread */
+       /* g_thread_id is initialized : -1 */
+       /* g_thread_id is set to 0, when the callback thread is created */
+       if (g_thread_id != -1) {
+               msgsnd.sound_msg.msgtype = MM_SOUND_MSG_INF_DESTROY_CB;
+               msgsnd.sound_msg.msgid = getpid();
+               ret = __MMIpcCBSndMsg(&msgsnd);
+               if (ret != MM_ERROR_NONE)
+               {
+                       debug_critical("[Client] Fail to send message\n");
+               }
+               pthread_join(g_thread, 0);
+       }
+       if (g_thread_id2 != -1) {
+               pthread_join(g_thread2, 0);
+       }
+
+       pthread_mutex_destroy(&g_thread_mutex);
+       pthread_mutex_destroy(&g_thread_mutex2);
+
+       debug_fleave();
+       return MM_ERROR_NONE;
+}
+
+#if defined(__GSOURCE_CALLBACK__)
+gboolean sndcb_fd_check(GSource * source)
+{
+       GSList *fd_list;
+       fd_list = source->poll_fds;
+       GPollFD* temp;
+
+       do
+       {
+               temp = (GPollFD*)fd_list->data;
+               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 */
+}
+
+gboolean sndcb_fd_prepare(GSource *source, gint *timeout)
+{
+       return FALSE;
+}
+
+gboolean sndcb_fd_dispatch(GSource *source,    GSourceFunc callback, gpointer user_data)
+{
+       callback(user_data);
+       return TRUE;
+}
+#endif
+gboolean RunCallback(gpointer data)
+{
+       mm_ipc_msg_t* msg = NULL;
+
+       debug_msg("[Client] execute mm_sound stop callback function\n");
+
+       msg = (mm_ipc_msg_t*)data;
+       ((mm_sound_stop_callback_func)msg->sound_msg.callback)(msg->sound_msg.cbdata, msg->sound_msg.handle);
+
+       return FALSE;
+}
+
+gboolean _volume_change_cb(gpointer data)
+{
+       mm_ipc_msg_t* msg = NULL;
+
+       if (!data) {
+               debug_error("[Client] NULL param\n");
+               return FALSE;
+       }
+       msg = (mm_ipc_msg_t*)data;
+
+       ((mm_sound_volume_changed_cb)msg->sound_msg.callback)(msg->sound_msg.type, msg->sound_msg.val, msg->sound_msg.cbdata);
+
+       if(msg != NULL) {
+               free(msg);
+               msg = NULL;
+       }
+       return FALSE;
+}
+
+static void* callbackfunc(void *param)
+{
+       int ret = MM_ERROR_SOUND_INTERNAL;
+       mm_ipc_msg_t *msgrcv = NULL;
+       int run = 1;
+       int instance;
+
+       debug_fenter();
+
+       instance = getpid();
+       debug_msg("[Client] callback thread for [%d] is created\n", instance);
+
+       msgrcv = (mm_ipc_msg_t*)malloc(sizeof(mm_ipc_msg_t));
+       if(NULL == msgrcv)
+       {
+               debug_critical("[Client] Failed to memory allocation\n");
+               return NULL;
+       }
+
+       while(run)
+       {
+#if defined(__GSOURCE_CALLBACK__)
+               int eventFd = 0;
+               gchar* eventFile = NULL;
+               GSource* cmd_fd_gsrc = NULL;
+               GSourceFuncs *src_funcs = NULL;         // handler function
+               guint gsource_handle;
+               GPollFD *g_fd_cmd = NULL;                       // file descriptor
+#endif
+
+               debug_msg("[Client] Waiting message\n");
+               ret = __MMIpcCBRecvMsg(instance, msgrcv);
+               if (ret != MM_ERROR_NONE)
+               {
+                       debug_error("[Client] Fail to receive msg in callback\n");
+                       continue;
+               }
+
+               debug_msg("[Client] Receive msgtype : [%d]\n", msgrcv->sound_msg.msgtype);
+
+               switch (msgrcv->sound_msg.msgtype)
+               {
+               case MM_SOUND_MSG_INF_STOP_CB:
+                       debug_msg("[Client] callback : %p, data : %p\n", msgrcv->sound_msg.callback, msgrcv->sound_msg.cbdata);
+
+                       if (msgrcv->sound_msg.callback)
+                       {
+#if defined(__DIRECT_CALLBACK__)
+                               ((mm_sound_stop_callback_func)msgrcv->sound_msg.callback)(msgrcv->sound_msg.cbdata, msgrcv->sound_msg.handle);
+#elif defined(__GIDLE_CALLBACK__)
+                               guint eventid = 0;
+                               eventid = g_idle_add((GSourceFunc)RunCallback, (gpointer)msgrcv);
+                               debug_msg("[Client] Event Source ID : %d\n", eventid);
+
+#elif defined(__GSOURCE_CALLBACK__)
+                               char eventBuf[3]="OK";
+                               ////////////////////////
+                               // 0. Make event source
+                               eventFile = g_strdup_printf("/tmp/%d_0x%08x_0x%08x", instance, (unsigned int)msgrcv->sound_msg.callback, (unsigned int)msgrcv->sound_msg.cbdata);
+                               eventFd = open(eventFile, O_RDWR|O_CREAT);
+                               if(eventFd == -1)
+                               {
+                                       debug_critical("Event File creation failed\n");
+                                       break;
+                               }
+
+                               // 1. make GSource Object
+                               src_funcs = (GSourceFuncs *)g_malloc(sizeof(GSourceFuncs));
+                               if(!src_funcs){
+                                       debug_error("MMSoundCallback :  g_malloc failed on g_src_funcs");
+                                       break;
+                               }
+                               src_funcs->prepare = sndcb_fd_prepare;
+                               src_funcs->check = sndcb_fd_check;
+                               src_funcs->dispatch = sndcb_fd_dispatch;
+                               src_funcs->finalize = NULL;
+                               cmd_fd_gsrc = g_source_new(src_funcs,sizeof(GSource));
+                               if(!cmd_fd_gsrc){
+                                       debug_error("MMSoundCallback : g_malloc failed on m_readfd");
+                                       break;
+                               }
+
+                               // 2. add file description which used in g_loop()
+                               g_fd_cmd = (GPollFD*)g_malloc(sizeof(GPollFD));
+                               g_fd_cmd->fd = eventFd;
+                               g_fd_cmd->events = POLLIN|POLLPRI;
+
+                               // 3. combine g_source object and file descriptor
+                               g_source_add_poll(cmd_fd_gsrc,g_fd_cmd);
+                               gsource_handle = g_source_attach(cmd_fd_gsrc, NULL);
+                               if(!gsource_handle){
+                                       debug_error("MMSoundCallback : Error: Failed to attach the source to context");
+                                       break;
+                               }
+
+                               // 4. set callback
+                               g_source_set_callback(cmd_fd_gsrc,RunCallback,(gpointer)g_fd_cmd,NULL);
+                               debug_msg("MMSoundCallback : g_source_set_callback() done\n")
+
+                               // 5. Set Event
+                               write(eventFd, eventBuf, sizeof(eventBuf));
+                               sleep(1);
+                               // 6. Cleanup
+                               close(eventFd);
+                               unlink(eventFile);
+                               g_source_remove_poll(cmd_fd_gsrc, g_fd_cmd);
+                               g_source_remove(gsource_handle);
+                               if(g_fd_cmd)
+                                       free(g_fd_cmd);
+                               if(src_funcs)
+                                       free(src_funcs);
+                               if(eventFile)
+                                       g_free(eventFile);
+                               ////////////////////////
+#endif
+                       }
+                       break;
+               case MM_SOUND_MSG_INF_DESTROY_CB:
+                       run = 0;
+                       break;
+
+               case MM_SOUND_MSG_INF_DEVICE_CONNECTED_CB:
+                       debug_msg("[Client] device handle : %x, is_connected : %d, callback : %p, data : %p\n",
+                               &msgrcv->sound_msg.device_handle, msgrcv->sound_msg.is_connected, msgrcv->sound_msg.callback, msgrcv->sound_msg.cbdata);
+                       if (msgrcv->sound_msg.callback) {
+                               ((mm_sound_device_connected_cb)msgrcv->sound_msg.callback)(&msgrcv->sound_msg.device_handle, msgrcv->sound_msg.is_connected, msgrcv->sound_msg.cbdata);
+                       }
+                       break;
+
+               case MM_SOUND_MSG_INF_DEVICE_INFO_CHANGED_CB:
+                       debug_msg("[Client] device handle : %x, changed_info_type : %d, callback : %p, data : %p\n",
+                               &msgrcv->sound_msg.device_handle, msgrcv->sound_msg.changed_device_info_type, msgrcv->sound_msg.callback, msgrcv->sound_msg.cbdata);
+                       if (msgrcv->sound_msg.callback) {
+                               ((mm_sound_device_info_changed_cb)msgrcv->sound_msg.callback)(&msgrcv->sound_msg.device_handle, msgrcv->sound_msg.changed_device_info_type, msgrcv->sound_msg.cbdata);
+                       }
+                       break;
+
+               case MM_SOUND_MSG_INF_ACTIVE_DEVICE_CB:
+                       debug_msg("[Client] device_in : %d, device_out : %d\n", msgrcv->sound_msg.device_in, msgrcv->sound_msg.device_out);
+                       debug_log("[Client] callback : %p, data : %p\n", msgrcv->sound_msg.callback, msgrcv->sound_msg.cbdata);
+
+                       if (msgrcv->sound_msg.callback)
+                       {
+                               ((mm_sound_active_device_changed_cb)msgrcv->sound_msg.callback)(msgrcv->sound_msg.device_in, msgrcv->sound_msg.device_out, msgrcv->sound_msg.cbdata);
+                       }
+                       break;
+               case MM_SOUND_MSG_INF_AVAILABLE_ROUTE_CB:
+                       debug_log("[Client] callback : %p, data : %p\n", msgrcv->sound_msg.callback, msgrcv->sound_msg.cbdata);
+
+                       if (msgrcv->sound_msg.callback)
+                       {
+                               int route_index;
+                               mm_sound_route route;
+
+                               int list_count = sizeof(msgrcv->sound_msg.route_list) / sizeof(int);
+
+                               for (route_index = list_count-1; route_index >= 0; route_index--) {
+                                       route = msgrcv->sound_msg.route_list[route_index];
+                                       if (route == 0)
+                                               continue;
+                                       if (msgrcv->sound_msg.is_available) {
+                                               debug_msg("[Client] available route : 0x%x\n", route);
+                                       } else {
+                                               debug_msg("[Client] unavailable route : 0x%x\n", route);
+                                       }
+                                       ((mm_sound_available_route_changed_cb)msgrcv->sound_msg.callback)(route, msgrcv->sound_msg.is_available, msgrcv->sound_msg.cbdata);
+
+                                       if (route == MM_SOUND_ROUTE_INOUT_HEADSET || route == MM_SOUND_ROUTE_IN_MIC_OUT_HEADPHONE) {
+                                               debug_msg("[Client] no need to proceed further more....\n");
+                                               break;
+                                       }
+                               }
+                       }
+                       break;
+               case MM_SOUND_MSG_INF_VOLUME_CB:
+                       debug_msg("[Client] type: %d, volume value : %d, callback : %p, data : %p\n", msgrcv->sound_msg.type, msgrcv->sound_msg.val, msgrcv->sound_msg.callback, msgrcv->sound_msg.cbdata);
+
+                       if (msgrcv->sound_msg.callback)
+                       {
+                               mm_ipc_msg_t* tmp = NULL;
+                               tmp = (mm_ipc_msg_t*)malloc(sizeof(mm_ipc_msg_t));
+                               if(tmp == NULL) {
+                                       debug_critical("Fail malloc");
+                                       break;
+                               }
+                               memcpy(tmp, msgrcv, sizeof(mm_ipc_msg_t));
+                               g_idle_add((GSourceFunc)_volume_change_cb, (gpointer)tmp);
+                       }
+                       break;
+
+               default:
+                       /* Unexpected msg */
+                       debug_msg("Receive wrong msg in callback func\n");
+                       break;
+               }
+       }
+       if(msgrcv) {
+               free(msgrcv);
+       }
+
+       g_exit_thread = 1;
+       debug_msg("[Client] callback [%d] is leaved\n", instance);
+       debug_fleave();
+       return NULL;
+}
+
+static void* callbackfunc_send_reply(void *param)
+{
+       int ret = MM_ERROR_SOUND_INTERNAL;
+       mm_ipc_msg_t *msgrcv = NULL;
+       mm_ipc_msg_t *msgret = NULL;
+       int run = 1;
+       int instance;
+#ifdef USE_FOCUS
+       struct timeval time;
+       int starttime = 0;
+       int endtime = 0;
+#endif
+
+       debug_fenter();
+
+       instance = getpid();
+       debug_msg("[Client] callback thread for [%d] is created\n", instance);
+
+       msgrcv = (mm_ipc_msg_t*)malloc(sizeof(mm_ipc_msg_t));
+       msgret = (mm_ipc_msg_t*)malloc(sizeof(mm_ipc_msg_t));
+       memset (msgret, 0, sizeof(mm_ipc_msg_t));
+       if(msgrcv == NULL || msgret == NULL) {
+               debug_error("[Client] Failed to memory allocation\n");
+               return NULL;
+       }
+
+       while(run) {
+               debug_msg("[Client] Waiting message\n");
+               ret = __MMIpcCBRecvMsgForReply(instance, msgrcv);
+               if (ret != MM_ERROR_NONE) {
+                       debug_error("[Client] Fail to receive msg in callback\n");
+                       continue;
+               }
+
+               debug_msg("[Client] Receive msgtype : [%d]\n", msgrcv->sound_msg.msgtype);
+
+               switch (msgrcv->sound_msg.msgtype) {
+#ifdef USE_FOCUS
+               case MM_SOUND_MSG_INF_FOCUS_CHANGED_CB:
+                       /* Set start time */
+                       gettimeofday(&time, NULL);
+                       starttime = time.tv_sec * 1000000 + time.tv_usec;
+                       debug_warning("[Client][Focus Callback(0x%x) START][handle_id(%d),focus_type(%d), state(%d),reason(%s),info(%s)][Time:%.3f]\n",
+                               msgrcv->sound_msg.callback, msgrcv->sound_msg.focus_type, msgrcv->sound_msg.changed_state, msgrcv->sound_msg.stream_type, msgrcv->sound_msg.name, starttime/1000000.);
+                       if (msgrcv->sound_msg.callback) {
+                               ((mm_sound_focus_changed_cb)msgrcv->sound_msg.callback)(msgrcv->sound_msg.handle_id, msgrcv->sound_msg.focus_type, msgrcv->sound_msg.changed_state, msgrcv->sound_msg.stream_type, msgrcv->sound_msg.name, msgrcv->sound_msg.cbdata);
+                       }
+                       /* Calculate endtime and display*/
+                       gettimeofday(&time, NULL);
+                       endtime = time.tv_sec * 1000000 + time.tv_usec;
+                       debug_warning("[Client][Focus Callback END][Time:%.3f, TimeLab=%3.3f(sec)]\n", endtime/1000000., (endtime-starttime)/1000000.);
+
+                       /* send reply */
+                       msgret->sound_msg.msgtype = msgrcv->sound_msg.msgtype;
+                       msgret->sound_msg.msgid = msgrcv->sound_msg.msgid;
+                       msgret->sound_msg.handle_id = msgrcv->sound_msg.handle_id;
+                       ret = __MMIpcCBSndMsgReply(msgret);
+                       if (ret != MM_ERROR_NONE) {
+                               debug_error("[Client] Fail to send reply msg in callback\n");
+                               continue;
+                       }
+                       break;
+
+               case MM_SOUND_MSG_INF_FOCUS_WATCH_CB:
+                       /* Set start time */
+                       gettimeofday(&time, NULL);
+                       starttime = time.tv_sec * 1000000 + time.tv_usec;
+                       debug_warning("[Client][Focus Watch Callback(0x%x) START][focus_type(%d),state(%d),reason(%s),info(%s)][Time:%.3f]\n",
+                               msgrcv->sound_msg.callback, msgrcv->sound_msg.focus_type, msgrcv->sound_msg.changed_state, msgrcv->sound_msg.stream_type, msgrcv->sound_msg.name, starttime/1000000.);
+                       if (msgrcv->sound_msg.callback) {
+                               ((mm_sound_focus_changed_watch_cb)msgrcv->sound_msg.callback)(msgrcv->sound_msg.focus_type, msgrcv->sound_msg.changed_state, msgrcv->sound_msg.stream_type, msgrcv->sound_msg.name, msgrcv->sound_msg.cbdata);
+                       }
+                       /* Calculate endtime and display*/
+                       gettimeofday(&time, NULL);
+                       endtime = time.tv_sec * 1000000 + time.tv_usec;
+                       debug_warning("[Client][Focus Watch Callback END][Time:%.3f, TimeLab=%3.3f(sec)]\n", endtime/1000000., (endtime-starttime)/1000000.);
+
+                       /* send reply */
+                       msgret->sound_msg.msgtype = msgrcv->sound_msg.msgtype;
+                       msgret->sound_msg.msgid = msgrcv->sound_msg.msgid;
+                       ret = __MMIpcCBSndMsgReply(msgret);
+                       if (ret != MM_ERROR_NONE) {
+                               debug_error("[Client] Fail to send reply msg in callback\n");
+                               continue;
+                       }
+                       break;
+#endif
+
+               default:
+                       /* Unexpected msg */
+                       debug_msg("Receive wrong msg in callback func\n");
+                       break;
+               }
+       }
+       if(msgrcv) {
+               free(msgrcv);
+       }
+       if(msgret) {
+               free(msgret);
+       }
+
+       debug_msg("[Client] callback [%d] is leaved\n", instance);
+       debug_fleave();
+       return NULL;
+
+}
+
+static int __mm_sound_client_get_msg_queue(void)
+{
+       int ret = MM_ERROR_NONE;
+
+       if(pthread_mutex_init(&g_thread_mutex, NULL)) {
+               debug_error("pthread_mutex_init failed\n");
+               return MM_ERROR_SOUND_INTERNAL;
+       }
+       if(pthread_mutex_init(&g_thread_mutex2, NULL)) {
+               debug_error("pthread_mutex_init failed\n");
+               return MM_ERROR_SOUND_INTERNAL;
+       }
+       debug_log("[Client] mutex initialized. \n");
+
+       /* Get msg queue id */
+       ret = __MMSoundGetMsg();
+       if(ret != MM_ERROR_NONE) {
+               debug_error("[Client] Fail to get message queue id. sound_server is not initialized.\n");
+               pthread_mutex_destroy(&g_thread_mutex);
+               pthread_mutex_destroy(&g_thread_mutex2);
+       }
+
+       return ret;
+}
+
+int MMSoundClientMsgqPlayTone(int number, int volume_config, double volume, int time, int *handle, bool enable_session)
+{
+       mm_ipc_msg_t msgrcv = {0,};
+       mm_ipc_msg_t msgsnd = {0,};
+
+       int ret = MM_ERROR_NONE;
+       int instance = -1;      /* instance is unique to communicate with server : client message queue filter type */
+
+       debug_fenter();
+
+       ret = __mm_sound_client_get_msg_queue();
+       if (ret  != MM_ERROR_NONE) {
+               return ret;
+       }
+       /* read session information */
+       int session_type = MM_SESSION_TYPE_MEDIA;
+       int session_options = 0;
+       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;
+                       }
+               }
+       }
+
+       instance = getpid();
+       debug_log("[Client] pid for client ::: [%d]\n", instance);
+
+       pthread_mutex_lock(&g_thread_mutex);
+
+       /* Send msg */
+       debug_msg("[Client] Input number : %d\n", number);
+       /* Send req memory */
+       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_DTMF;
+       msgsnd.sound_msg.msgid = instance;
+       msgsnd.sound_msg.session_type = session_type;       //session type
+       msgsnd.sound_msg.session_options = session_options; //session options
+       msgsnd.sound_msg.volume = volume;                   //This does not effect anymore
+       msgsnd.sound_msg.volume_config = volume_config;
+       msgsnd.sound_msg.tone = number;
+       msgsnd.sound_msg.handle = -1;
+       msgsnd.sound_msg.repeat = time;
+       msgsnd.sound_msg.enable_session = enable_session;
+
+       ret = __MMIpcSndMsg(&msgsnd);
+       if (ret != MM_ERROR_NONE)
+       {
+               debug_error("[Client] Fail to send msg\n");
+               goto cleanup;
+       }
+
+       /* Receive */
+       ret = __MMIpcRecvMsg(instance, &msgrcv);
+       if (ret != MM_ERROR_NONE)
+       {
+               debug_error("[Client] Fail to recieve msg\n");
+               goto cleanup;
+       }
+
+       switch (msgrcv.sound_msg.msgtype)
+       {
+       case MM_SOUND_MSG_RES_DTMF:
+               *handle = msgrcv.sound_msg.handle;
+               if(*handle == -1) {
+                       debug_error("[Client] The handle is not get\n");
+               } else {
+                       debug_msg("[Client] Success to play sound sound handle : [%d]\n", *handle);
+               }
+               break;
+
+       case MM_SOUND_MSG_RES_ERROR:
+               debug_error("[Client] Error occurred \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+
+       default:
+               debug_critical("[Client] Unexpected state with communication \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       }
+cleanup:
+       pthread_mutex_unlock(&g_thread_mutex);
+
+       debug_fleave();
+       return ret;
+}
+
+
+int MMSoundClientMsgqPlaySound(MMSoundPlayParam *param, int tone, int keytone, int *handle)
+{
+       mm_ipc_msg_t msgrcv = {0,};
+       mm_ipc_msg_t msgsnd = {0,};
+
+       int ret = MM_ERROR_NONE;
+       int instance = -1;      /* instance is unique to communicate with server : client message queue filter type */
+
+       debug_fenter();
+
+       ret = __mm_sound_client_get_msg_queue();
+       if (ret  != MM_ERROR_NONE) {
+               return ret;
+       }
+       /* read session information */
+       int session_type = MM_SESSION_TYPE_MEDIA;
+       int session_options = 0;
+
+       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;
+
+                       if(MM_ERROR_NONE != mm_session_init(session_type))
+                       {
+                               debug_critical("[Client] MMSessionInit() failed\n");
+                               return MM_ERROR_POLICY_INTERNAL;
+                       }
+               }
+       }
+
+       instance = getpid();
+       debug_msg("[Client] pid for client ::: [%d]\n", instance);
+
+       /* Send msg */
+       if ((param->mem_ptr && param->mem_size))
+       {
+               // memory play
+       }
+       else
+       {
+               /* File type set for send msg */
+               msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_FILE;
+               msgsnd.sound_msg.msgid = instance;
+               msgsnd.sound_msg.callback = (void*)(param->callback);
+               msgsnd.sound_msg.cbdata = (void*)(param->data);
+               msgsnd.sound_msg.volume = param->volume;
+               msgsnd.sound_msg.tone = tone;
+               msgsnd.sound_msg.handle = -1;
+               msgsnd.sound_msg.repeat = param->loop;
+               msgsnd.sound_msg.volume_config = param->volume_config;
+               msgsnd.sound_msg.session_type = session_type;       //session type
+               msgsnd.sound_msg.session_options = session_options; //session options
+               msgsnd.sound_msg.priority = param->priority;
+               msgsnd.sound_msg.handle_route = param->handle_route;
+               msgsnd.sound_msg.enable_session = !param->skip_session;
+
+               if((strlen(param->filename)) < FILE_PATH)
+               {
+                       MMSOUND_STRNCPY(msgsnd.sound_msg.filename, param->filename, FILE_PATH);
+               }
+               else
+               {
+                       debug_error("File name is over count\n");
+                       ret = MM_ERROR_SOUND_INVALID_PATH;
+               }
+
+               msgsnd.sound_msg.keytone = keytone;
+
+               debug_msg("[Client] callback : %p\n", msgsnd.sound_msg.callback);
+               debug_msg("[Client] cbdata : %p\n", msgsnd.sound_msg.cbdata);
+
+               ret = __MMIpcSndMsg(&msgsnd);
+               if (ret != MM_ERROR_NONE)
+               {
+                       debug_error("[Client] Fail to send msg\n");
+                       goto cleanup;
+               }
+       }
+
+
+       /* Receive */
+       ret = __MMIpcRecvMsg(instance, &msgrcv);
+       if (ret != MM_ERROR_NONE)
+       {
+               debug_error("[Client] Fail to recieve msg\n");
+               goto cleanup;
+       }
+
+       switch (msgrcv.sound_msg.msgtype)
+       {
+       case MM_SOUND_MSG_RES_FILE:
+               *handle = msgrcv.sound_msg.handle;
+               debug_msg("[Client] Success to play sound sound handle : [%d]\n", *handle);
+               break;
+       case MM_SOUND_MSG_RES_MEMORY:
+               // deprecated
+               break;
+       case MM_SOUND_MSG_RES_ERROR:
+               debug_error("[Client] Error occurred \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       default:
+               debug_critical("[Client] Unexpected state with communication \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       }
+cleanup:
+
+       debug_fleave();
+       return ret;
+}
+
+int MMSoundClientMsgqStopSound(int handle)
+{
+       mm_ipc_msg_t msgrcv = {0,};
+       mm_ipc_msg_t msgsnd = {0,};
+       int ret = MM_ERROR_NONE;
+       int instance;
+
+       debug_fenter();
+       debug_msg("[Client] The stop audio handle ::: [%d]\n", handle);
+
+       instance = getpid();
+
+       if (handle < 0)
+       {
+               ret = MM_ERROR_INVALID_ARGUMENT;
+               return ret;
+       }
+
+       ret = __mm_sound_client_get_msg_queue();
+       if (ret  != MM_ERROR_NONE) {
+               return ret;
+       }
+
+       pthread_mutex_lock(&g_thread_mutex);
+
+       /* Send req STOP */
+       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_STOP;
+       msgsnd.sound_msg.msgid = instance;
+       msgsnd.sound_msg.handle = handle;               /* handle means audio handle slot id */
+
+       ret = __MMIpcSndMsg(&msgsnd);
+       if (ret != MM_ERROR_NONE)
+       {
+               debug_error("Fail to send msg\n");
+               goto cleanup;
+       }
+
+       /* Receive */
+       ret = __MMIpcRecvMsg(instance, &msgrcv);
+       if (ret != MM_ERROR_NONE)
+       {
+               debug_error("[Client] Fail to recieve msg\n");
+               goto cleanup;
+       }
+       switch (msgrcv.sound_msg.msgtype)
+       {
+       case MM_SOUND_MSG_RES_STOP:
+               debug_msg("[Client] Success to stop sound\n");
+               break;
+       case MM_SOUND_MSG_RES_ERROR:
+               debug_error("[Client] Error occurred \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       default:
+               debug_critical("[Client] Unexpected state with communication \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       }
+
+cleanup:
+       pthread_mutex_unlock(&g_thread_mutex);
+
+
+       debug_fleave();
+       return ret;
+}
+
+static int __mm_sound_device_check_flags_to_append (int device_flags, mm_sound_device_t *device_h, bool *is_good_to_append)
+{
+       bool need_to_append = false;
+       int need_to_check_for_io_direction = device_flags & DEVICE_IO_DIRECTION_FLAGS;
+       int need_to_check_for_state = device_flags & DEVICE_STATE_FLAGS;
+       int need_to_check_for_type = device_flags & DEVICE_TYPE_FLAGS;
+
+       debug_warning("device_h[0x%x], device_flags[0x%x], need_to_check(io_direction[0x%x],state[0x%x],type[0x%x])\n",
+                       device_h, device_flags, need_to_check_for_io_direction, need_to_check_for_state, need_to_check_for_type);
+
+       if(!device_h) {
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+       if (device_flags == DEVICE_ALL_FLAG) {
+               *is_good_to_append = true;
+               return MM_ERROR_NONE;
+       }
+
+       if (need_to_check_for_io_direction) {
+               if ((device_h->io_direction == DEVICE_IO_DIRECTION_IN) && (device_flags & DEVICE_IO_DIRECTION_IN_FLAG)) {
+                       need_to_append = true;
+               } else if ((device_h->io_direction == DEVICE_IO_DIRECTION_OUT) && (device_flags & DEVICE_IO_DIRECTION_OUT_FLAG)) {
+                       need_to_append = true;
+               } else if ((device_h->io_direction == DEVICE_IO_DIRECTION_BOTH) && (device_flags & DEVICE_IO_DIRECTION_BOTH_FLAG)) {
+                       need_to_append = true;
+               }
+               if (need_to_append) {
+                       if (!need_to_check_for_state && !need_to_check_for_type) {
+                               *is_good_to_append = true;
+                               return MM_ERROR_NONE;
+                       }
+               } else {
+                       *is_good_to_append = false;
+                       return MM_ERROR_NONE;
+               }
+       }
+       if (need_to_check_for_state) {
+               need_to_append = false;
+               if ((device_h->state == DEVICE_STATE_DEACTIVATED) && (device_flags & DEVICE_STATE_DEACTIVATED_FLAG)) {
+                       need_to_append = true;
+               } else if ((device_h->state == DEVICE_STATE_ACTIVATED) && (device_flags & DEVICE_STATE_ACTIVATED_FLAG)) {
+                       need_to_append = true;
+               }
+               if (need_to_append) {
+                       if (!need_to_check_for_type) {
+                               *is_good_to_append = true;
+                               return MM_ERROR_NONE;
+                       }
+               } else {
+                       *is_good_to_append = false;
+                       return MM_ERROR_NONE;
+               }
+       }
+       if (need_to_check_for_type) {
+               need_to_append = false;
+               bool is_internal_device = IS_INTERNAL_DEVICE(device_h->type);
+               if (is_internal_device && (device_flags & DEVICE_TYPE_INTERNAL_FLAG)) {
+                       need_to_append = true;
+               } else if (!is_internal_device && (device_flags & DEVICE_TYPE_EXTERNAL_FLAG)) {
+                       need_to_append = true;
+               }
+               if (need_to_append) {
+                       *is_good_to_append = true;
+                       return MM_ERROR_NONE;
+               } else {
+                       *is_good_to_append = false;
+                       return MM_ERROR_NONE;
+               }
+       }
+       return MM_ERROR_NONE;
+}
+
+static int __mm_sound_client_device_list_clear ()
+{
+       int ret = MM_ERROR_NONE;
+
+       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_device_list_mutex, MM_ERROR_SOUND_INTERNAL);
+
+       if (g_device_list) {
+               g_list_free_full(g_device_list, g_free);
+               g_device_list = NULL;
+       }
+
+       MMSOUND_LEAVE_CRITICAL_SECTION(&g_device_list_mutex);
+
+       return ret;
+}
+
+static int __mm_sound_client_device_list_append_item (mm_sound_device_t *device_h)
+{
+       int ret = MM_ERROR_NONE;
+       mm_sound_device_t *device_node = g_malloc0(sizeof(mm_sound_device_t));
+       memcpy(device_node, device_h, sizeof(mm_sound_device_t));
+
+       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_device_list_mutex, MM_ERROR_SOUND_INTERNAL);
+
+       g_device_list = g_list_append(g_device_list, device_node);
+       debug_log("[Client] g_device_list[0x%x], new device_node[0x%x] is appended, type[%d], id[%d]\n", g_device_list, device_node, device_node->type, device_node->id);
+
+       MMSOUND_LEAVE_CRITICAL_SECTION(&g_device_list_mutex);
+
+       return ret;
+}
+
+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;
+
+       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[%02d], 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);
+               }
+       }
+       debug_log("======================== device list : end ============================\n");
+
+       return ret;
+}
+
+int _mm_sound_client_msgq_get_current_connected_device_list(int device_flags, mm_sound_device_list_t **device_list)
+{
+       mm_ipc_msg_t msgrcv = {0,};
+       mm_ipc_msg_t msgsnd = {0,};
+       int ret = MM_ERROR_NONE;
+       int instance;
+
+       debug_fenter();
+
+       ret = __mm_sound_client_get_msg_queue();
+       if (ret  != MM_ERROR_NONE) {
+               return ret;
+       }
+       pthread_mutex_lock(&g_thread_mutex);
+
+       instance = getpid();
+
+       /* Send REQ_ADD_ACTIVE_DEVICE_CB */
+       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_GET_CONNECTED_DEVICE_LIST;
+       msgsnd.sound_msg.msgid = instance;
+       msgsnd.sound_msg.device_flags = device_flags;
+
+       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       switch (msgrcv.sound_msg.msgtype)
+       {
+       case MM_SOUND_MSG_RES_GET_CONNECTED_DEVICE_LIST:
+       {
+               int i = 0;
+               int ret = MM_ERROR_NONE;
+               int total_device_num = msgrcv.sound_msg.total_device_num;
+               bool is_good_to_append = false;
+               mm_sound_device_t* device_h = &msgrcv.sound_msg.device_handle;
+
+               ret = __mm_sound_client_device_list_clear();
+               if (ret) {
+                       debug_error("[Client] failed to __mm_sound_client_device_list_clear(), ret[0x%x]\n", ret);
+                       goto cleanup;
+               }
+
+               debug_msg("[Client] supposed to receive %d messages\n", total_device_num);
+               for (i = 0; i < total_device_num; i++) {
+                       /* check if this device_handle is suitable according to flags */
+                       ret = __mm_sound_device_check_flags_to_append (device_flags, device_h, &is_good_to_append);
+                       if (is_good_to_append) {
+                               ret = __mm_sound_client_device_list_append_item(device_h);
+                               if (ret) {
+                                       debug_error("[Client] failed to __mm_sound_client_device_list_append_item(), ret[0x%x]\n", ret);
+                               }
+                       }
+                       if (total_device_num-i > 1) {
+                               if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
+                                       debug_error("[Client] failed to [%d]th of __MMIpcRecvMsg()\n", i);
+                                       goto cleanup;
+                               }
+                               switch (msgrcv.sound_msg.msgtype)
+                               {
+                               case MM_SOUND_MSG_RES_GET_CONNECTED_DEVICE_LIST:
+                                       break;
+                               default:
+                                       debug_error("[Client] failed to [%d]th of __MMIpcRecvMsg(), msgtype[%d] is not expected\n", msgrcv.sound_msg.msgtype);
+                                       goto cleanup;
+                                       break;
+                               }
+                       }
+               }
+               g_device_list_t.list = g_device_list;
+               *device_list = &g_device_list_t;
+               debug_msg("[Client] Success to get connected device list, g_device_list_t[0x%x]->list[0x%x], device_list[0x%x]\n", &g_device_list_t, g_device_list_t.list, *device_list);
+               _mm_sound_client_device_list_dump((*device_list)->list);
+       }
+               break;
+       case MM_SOUND_MSG_RES_ERROR:
+               debug_error("[Client] Error occurred \n");
+               ret = msgrcv.sound_msg.code; // no data is possible
+               goto cleanup;
+               break;
+       default:
+               debug_error("[Client] Unexpected state with communication \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       }
+
+cleanup:
+       pthread_mutex_unlock(&g_thread_mutex);
+
+       debug_fleave();
+       return ret;
+}
+
+int _mm_sound_client_msgq_add_device_connected_callback(int device_flags, mm_sound_device_connected_cb func, void* user_data)
+{
+       mm_ipc_msg_t msgrcv = {0,};
+       mm_ipc_msg_t msgsnd = {0,};
+       int ret = MM_ERROR_NONE;
+       int instance;
+
+       debug_fenter();
+
+       ret = __mm_sound_client_get_msg_queue();
+       if (ret  != MM_ERROR_NONE) {
+               return ret;
+       }
+
+       pthread_mutex_lock(&g_thread_mutex);
+
+       instance = getpid();
+       /* Send REQ_ADD_ACTIVE_DEVICE_CB */
+       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_ADD_DEVICE_CONNECTED_CB;
+       msgsnd.sound_msg.msgid = instance;
+       msgsnd.sound_msg.device_flags = device_flags;
+       msgsnd.sound_msg.callback = func;
+       msgsnd.sound_msg.cbdata = user_data;
+
+       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       /* Recieve */
+       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       switch (msgrcv.sound_msg.msgtype)
+       {
+       case MM_SOUND_MSG_RES_ADD_DEVICE_CONNECTED_CB:
+               debug_msg("[Client] Success to add device connected callback\n");
+               if (g_thread_id == -1)
+               {
+                       g_thread_id = pthread_create(&g_thread, NULL, callbackfunc, NULL);
+                       if (g_thread_id == -1)
+                       {
+                               debug_critical("[Client] Fail to create thread %s\n", strerror(errno));
+                               ret = MM_ERROR_SOUND_INTERNAL;
+                               goto cleanup;
+                       }
+               }
+               break;
+       case MM_SOUND_MSG_RES_ERROR:
+               debug_error("[Client] Error occurred \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       default:
+               debug_critical("[Client] Unexpected state with communication \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       }
+
+cleanup:
+       pthread_mutex_unlock(&g_thread_mutex);
+
+       debug_fleave();
+       return ret;
+}
+
+int _mm_sound_client_msgq_remove_device_connected_callback(void)
+{
+       mm_ipc_msg_t msgrcv = {0,};
+       mm_ipc_msg_t msgsnd = {0,};
+       int ret = MM_ERROR_NONE;
+       int instance;
+
+       debug_fenter();
+
+       ret = __mm_sound_client_get_msg_queue();
+       if (ret  != MM_ERROR_NONE) {
+               return ret;
+       }
+
+       pthread_mutex_lock(&g_thread_mutex);
+
+       instance = getpid();
+       /* Send REQ_REMOVE_ACTIVE_DEVICE_CB */
+       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_REMOVE_DEVICE_CONNECTED_CB;
+       msgsnd.sound_msg.msgid = instance;
+
+       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+       /* Recieve */
+       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+       switch (msgrcv.sound_msg.msgtype)
+       {
+       case MM_SOUND_MSG_RES_REMOVE_DEVICE_CONNECTED_CB:
+               debug_msg("[Client] Success to remove device connected callback\n");
+               break;
+       case MM_SOUND_MSG_RES_ERROR:
+               debug_error("[Client] Error occurred \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       default:
+               debug_critical("[Client] Unexpected state with communication \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       }
+
+cleanup:
+       pthread_mutex_unlock(&g_thread_mutex);
+
+       debug_fleave();
+       return ret;
+}
+
+int _mm_sound_client_msgq_add_device_info_changed_callback(int device_flags, mm_sound_device_info_changed_cb func, void* user_data)
+{
+       mm_ipc_msg_t msgrcv = {0,};
+       mm_ipc_msg_t msgsnd = {0,};
+       int ret = MM_ERROR_NONE;
+       int instance;
+
+       debug_fenter();
+
+       ret = __mm_sound_client_get_msg_queue();
+       if (ret  != MM_ERROR_NONE) {
+               return ret;
+       }
+
+       pthread_mutex_lock(&g_thread_mutex);
+
+       instance = getpid();
+       /* Send REQ_ADD_ACTIVE_DEVICE_CB */
+       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_ADD_DEVICE_INFO_CHANGED_CB;
+       msgsnd.sound_msg.msgid = instance;
+       msgsnd.sound_msg.device_flags = device_flags;
+       msgsnd.sound_msg.callback = func;
+       msgsnd.sound_msg.cbdata = user_data;
+
+       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       /* Recieve */
+       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       switch (msgrcv.sound_msg.msgtype)
+       {
+       case MM_SOUND_MSG_RES_ADD_DEVICE_INFO_CHANGED_CB:
+               debug_msg("[Client] Success to add device connected callback\n");
+               if (g_thread_id == -1)
+               {
+                       g_thread_id = pthread_create(&g_thread, NULL, callbackfunc, NULL);
+                       if (g_thread_id == -1)
+                       {
+                               debug_critical("[Client] Fail to create thread %s\n", strerror(errno));
+                               ret = MM_ERROR_SOUND_INTERNAL;
+                               goto cleanup;
+                       }
+               }
+               break;
+       case MM_SOUND_MSG_RES_ERROR:
+               debug_error("[Client] Error occurred \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       default:
+               debug_critical("[Client] Unexpected state with communication \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       }
+
+cleanup:
+       pthread_mutex_unlock(&g_thread_mutex);
+
+       debug_fleave();
+       return ret;
+}
+
+int _mm_sound_client_msgq_remove_device_info_changed_callback(void)
+{
+       mm_ipc_msg_t msgrcv = {0,};
+       mm_ipc_msg_t msgsnd = {0,};
+       int ret = MM_ERROR_NONE;
+       int instance;
+
+       debug_fenter();
+
+       ret = __mm_sound_client_get_msg_queue();
+       if (ret  != MM_ERROR_NONE) {
+               return ret;
+       }
+
+       pthread_mutex_lock(&g_thread_mutex);
+
+       instance = getpid();
+       /* Send REQ_REMOVE_ACTIVE_DEVICE_CB */
+       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_REMOVE_DEVICE_INFO_CHANGED_CB;
+       msgsnd.sound_msg.msgid = instance;
+
+       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       /* Recieve */
+       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       switch (msgrcv.sound_msg.msgtype)
+       {
+       case MM_SOUND_MSG_RES_REMOVE_DEVICE_INFO_CHANGED_CB:
+               debug_msg("[Client] Success to remove device info changed callback\n");
+               break;
+       case MM_SOUND_MSG_RES_ERROR:
+               debug_error("[Client] Error occurred \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       default:
+               debug_critical("[Client] Unexpected state with communication \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       }
+
+cleanup:
+       pthread_mutex_unlock(&g_thread_mutex);
+
+       debug_fleave();
+       return ret;
+}
+
+#ifdef USE_FOCUS
+int _mm_sound_client_msgq_register_focus(int id, const char *stream_type, mm_sound_focus_changed_cb callback, void* user_data)
+{
+       mm_ipc_msg_t msgrcv = {0,};
+       mm_ipc_msg_t msgsnd = {0,};
+       int ret = MM_ERROR_NONE;
+       int instance;
+
+       debug_fenter();
+
+       ret = __mm_sound_client_get_msg_queue();
+       if (ret  != MM_ERROR_NONE) {
+               return ret;
+       }
+
+       pthread_mutex_lock(&g_thread_mutex2);
+
+       instance = getpid();
+       /* Send REQ_REGISTER_FOCUS */
+       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_REGISTER_FOCUS;
+       msgsnd.sound_msg.msgid = instance;
+       msgsnd.sound_msg.handle_id = id;
+       msgsnd.sound_msg.callback = callback;
+       msgsnd.sound_msg.cbdata = user_data;
+       MMSOUND_STRNCPY(msgsnd.sound_msg.stream_type, stream_type, MAX_STREAM_TYPE_LEN);
+
+       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       /* Recieve */
+       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       switch (msgrcv.sound_msg.msgtype)       {
+       case MM_SOUND_MSG_RES_REGISTER_FOCUS:
+               debug_msg("[Client] Success to register focus\n");
+               if (g_thread_id2 == -1) {
+                       g_thread_id2 = pthread_create(&g_thread2, NULL, callbackfunc_send_reply, NULL);
+                       if (g_thread_id2 == -1) {
+                               debug_error("[Client] Fail to create thread %s\n", strerror(errno));
+                               ret = MM_ERROR_SOUND_INTERNAL;
+                               goto cleanup;
+                       }
+               }
+               break;
+       case MM_SOUND_MSG_RES_ERROR:
+               debug_error("[Client] Error occurred \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       default:
+               debug_error("[Client] Unexpected state with communication \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       }
+
+cleanup:
+       pthread_mutex_unlock(&g_thread_mutex2);
+
+       debug_fleave();
+       return ret;
+}
+
+int _mm_sound_client_msgq_unregister_focus(int id)
+{
+       mm_ipc_msg_t msgrcv = {0,};
+       mm_ipc_msg_t msgsnd = {0,};
+       int ret = MM_ERROR_NONE;
+       int instance;
+
+       debug_fenter();
+
+       ret = __mm_sound_client_get_msg_queue();
+       if (ret  != MM_ERROR_NONE) {
+               return ret;
+       }
+
+       pthread_mutex_lock(&g_thread_mutex2);
+
+       instance = getpid();
+       /* Send REQ_UNREGISTER_FOCUS */
+       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_UNREGISTER_FOCUS;
+       msgsnd.sound_msg.msgid = instance;
+       msgsnd.sound_msg.handle_id = id;
+
+       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       /* Recieve */
+       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       switch (msgrcv.sound_msg.msgtype)       {
+       case MM_SOUND_MSG_RES_UNREGISTER_FOCUS:
+               debug_msg("[Client] Success to unregister focus\n");
+               break;
+       case MM_SOUND_MSG_RES_ERROR:
+               debug_error("[Client] Error occurred \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       default:
+               debug_error("[Client] Unexpected state with communication \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       }
+
+cleanup:
+       pthread_mutex_unlock(&g_thread_mutex2);
+
+       debug_fleave();
+       return ret;
+}
+
+int _mm_sound_client_msgq_acquire_focus(int id, mm_sound_focus_type_e type, const char *option)
+{
+       mm_ipc_msg_t msgrcv = {0,};
+       mm_ipc_msg_t msgsnd = {0,};
+       int ret = MM_ERROR_NONE;
+       int instance;
+
+       debug_fenter();
+
+       ret = __mm_sound_client_get_msg_queue();
+       if (ret  != MM_ERROR_NONE) {
+               return ret;
+       }
+
+       pthread_mutex_lock(&g_thread_mutex2);
+
+       instance = getpid();
+       /* Send REQ_ACQUIRE_FOCUS */
+       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_ACQUIRE_FOCUS;
+       msgsnd.sound_msg.msgid = instance;
+       msgsnd.sound_msg.handle_id = id;
+       msgsnd.sound_msg.focus_type = (int)type;
+       MMSOUND_STRNCPY(msgsnd.sound_msg.name, option, MM_SOUND_NAME_NUM);
+
+       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       /* Recieve */
+       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       switch (msgrcv.sound_msg.msgtype)       {
+       case MM_SOUND_MSG_RES_ACQUIRE_FOCUS:
+               debug_msg("[Client] Success to acquire focus\n");
+               break;
+       case MM_SOUND_MSG_RES_ERROR:
+               debug_error("[Client] Error occurred \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       default:
+               debug_error("[Client] Unexpected state with communication \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       }
+
+cleanup:
+       pthread_mutex_unlock(&g_thread_mutex2);
+
+       debug_fleave();
+       return ret;
+}
+
+int _mm_sound_client_msgq_release_focus(int id, mm_sound_focus_type_e type, const char *option)
+{
+       mm_ipc_msg_t msgrcv = {0,};
+       mm_ipc_msg_t msgsnd = {0,};
+       int ret = MM_ERROR_NONE;
+       int instance;
+
+       debug_fenter();
+
+       ret = __mm_sound_client_get_msg_queue();
+       if (ret  != MM_ERROR_NONE) {
+               return ret;
+       }
+
+       pthread_mutex_lock(&g_thread_mutex2);
+
+       instance = getpid();
+       /* Send REQ_RELEASE_FOCUS */
+       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_RELEASE_FOCUS;
+       msgsnd.sound_msg.msgid = instance;
+       msgsnd.sound_msg.handle_id = id;
+       msgsnd.sound_msg.focus_type = (int)type;
+       MMSOUND_STRNCPY(msgsnd.sound_msg.name, option, MM_SOUND_NAME_NUM);
+
+       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       /* Recieve */
+       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       switch (msgrcv.sound_msg.msgtype)       {
+       case MM_SOUND_MSG_RES_RELEASE_FOCUS:
+               debug_msg("[Client] Success to release focus\n");
+               break;
+       case MM_SOUND_MSG_RES_ERROR:
+               debug_error("[Client] Error occurred \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       default:
+               debug_error("[Client] Unexpected state with communication \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       }
+
+cleanup:
+       pthread_mutex_unlock(&g_thread_mutex2);
+
+       debug_fleave();
+       return ret;
+}
+
+int _mm_sound_client_msgq_set_focus_watch_callback(mm_sound_focus_type_e focus_type, mm_sound_focus_changed_watch_cb callback, void* user_data)
+{
+       mm_ipc_msg_t msgrcv = {0,};
+       mm_ipc_msg_t msgsnd = {0,};
+       int ret = MM_ERROR_NONE;
+       int instance;
+
+       debug_fenter();
+
+       ret = __mm_sound_client_get_msg_queue();
+       if (ret  != MM_ERROR_NONE) {
+               return ret;
+       }
+
+       pthread_mutex_lock(&g_thread_mutex2);
+
+       instance = getpid();
+       /* Send REQ_SET_FOCUS_WATCH_CB */
+       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_SET_FOCUS_WATCH_CB;
+       msgsnd.sound_msg.msgid = instance;
+       msgsnd.sound_msg.focus_type = focus_type;
+       msgsnd.sound_msg.callback = callback;
+       msgsnd.sound_msg.cbdata = user_data;
+
+       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       /* Recieve */
+       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       switch (msgrcv.sound_msg.msgtype)       {
+       case MM_SOUND_MSG_RES_SET_FOCUS_WATCH_CB:
+               debug_msg("[Client] Success to set focus watch callback\n");
+               if (g_thread_id2 == -1) {
+                       g_thread_id2 = pthread_create(&g_thread2, NULL, callbackfunc_send_reply, NULL);
+                       if (g_thread_id2 == -1) {
+                               debug_error("[Client] Fail to create thread %s\n", strerror(errno));
+                               ret = MM_ERROR_SOUND_INTERNAL;
+                               goto cleanup;
+                       }
+               }
+               break;
+       case MM_SOUND_MSG_RES_ERROR:
+               debug_error("[Client] Error occurred \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       default:
+               debug_error("[Client] Unexpected state with communication \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       }
+
+cleanup:
+       pthread_mutex_unlock(&g_thread_mutex2);
+
+       debug_fleave();
+       return ret;
+}
+
+int _mm_sound_client_msgq_unset_focus_watch_callback(void)
+{
+       mm_ipc_msg_t msgrcv = {0,};
+       mm_ipc_msg_t msgsnd = {0,};
+       int ret = MM_ERROR_NONE;
+       int instance;
+
+       debug_fenter();
+
+       ret = __mm_sound_client_get_msg_queue();
+       if (ret  != MM_ERROR_NONE) {
+               return ret;
+       }
+
+       pthread_mutex_lock(&g_thread_mutex2);
+
+       instance = getpid();
+       /* Send REQ_UNREGISTER_FOCUS */
+       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_UNSET_FOCUS_WATCH_CB;
+       msgsnd.sound_msg.msgid = instance;
+
+       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       /* Recieve */
+       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       switch (msgrcv.sound_msg.msgtype)       {
+       case MM_SOUND_MSG_RES_UNSET_FOCUS_WATCH_CB:
+               debug_msg("[Client] Success to unset focus watch callback\n");
+               break;
+       case MM_SOUND_MSG_RES_ERROR:
+               debug_error("[Client] Error occurred \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       default:
+               debug_error("[Client] Unexpected state with communication \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       }
+
+cleanup:
+       pthread_mutex_unlock(&g_thread_mutex2);
+
+       debug_fleave();
+       return ret;
+}
+#endif
+
+int _mm_sound_client_msgq_is_route_available(mm_sound_route route, bool *is_available)
+{
+       mm_ipc_msg_t msgrcv = {0,};
+       mm_ipc_msg_t msgsnd = {0,};
+       int ret = MM_ERROR_NONE;
+       int instance;
+
+       debug_fenter();
+
+       *is_available = FALSE;
+
+       ret = __mm_sound_client_get_msg_queue();
+       if (ret  != MM_ERROR_NONE) {
+               return ret;
+       }
+
+       pthread_mutex_lock(&g_thread_mutex);
+
+       instance = getpid();
+       /* Send REQ_IS_ROUTE_AVAILABLE */
+       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_IS_ROUTE_AVAILABLE;
+       msgsnd.sound_msg.msgid = instance;
+       msgsnd.sound_msg.route = route;
+
+       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       /* Receive */
+       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       switch (msgrcv.sound_msg.msgtype)
+       {
+       case MM_SOUND_MSG_RES_IS_ROUTE_AVAILABLE:
+               *is_available = msgrcv.sound_msg.is_available;
+               debug_msg("[Client] Success to check given route is available %d\n", *is_available);
+               break;
+       case MM_SOUND_MSG_RES_ERROR:
+               debug_error("[Client] Error occurred \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       default:
+               debug_critical("[Client] Unexpected state with communication \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       }
+
+cleanup:
+       pthread_mutex_unlock(&g_thread_mutex);
+
+       debug_fleave();
+       return ret;
+}
+
+static int _handle_foreach_callback(mm_ipc_msg_t *msg)
+{
+       int route_index;
+       mm_sound_route route;
+
+       debug_fenter();
+
+       if (msg->sound_msg.callback == NULL) {
+               debug_error ("[Client] Foreach callback is [%p], cbdata = %p => exit",
+                               msg->sound_msg.callback, msg->sound_msg.cbdata);
+               return MM_ERROR_SOUND_INTERNAL;
+       }
+
+       for (route_index = 0; route_index < MM_SOUND_ROUTE_NUM; route_index++) {
+               route = msg->sound_msg.route_list[route_index];
+               if (route == 0) {
+                       break;
+               }
+               debug_msg("[Client] available route : %d\n", route);
+               if (((mm_sound_available_route_cb)msg->sound_msg.callback)(route, msg->sound_msg.cbdata) == false) {
+                       debug_msg ("[Client] user doesn't want anymore. quit loop!!\n");
+                       break;
+               }
+       }
+
+       debug_fleave();
+
+       return MM_ERROR_NONE;
+}
+
+int _mm_sound_client_msgq_foreach_available_route_cb(mm_sound_available_route_cb available_route_cb, void *user_data)
+{
+       mm_ipc_msg_t msgrcv = {0,};
+       mm_ipc_msg_t msgsnd = {0,};
+       int ret = MM_ERROR_NONE;
+       int instance;
+
+       debug_fenter();
+
+       ret = __mm_sound_client_get_msg_queue();
+       if (ret  != MM_ERROR_NONE) {
+               return ret;
+       }
+
+       pthread_mutex_lock(&g_thread_mutex);
+
+       instance = getpid();
+       /* Send REQ_FOREACH_AVAILABLE_ROUTE_CB */
+       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_FOREACH_AVAILABLE_ROUTE_CB;
+       msgsnd.sound_msg.msgid = instance;
+       msgsnd.sound_msg.callback = (void *)available_route_cb;
+       msgsnd.sound_msg.cbdata = (void *)user_data;
+
+       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       /* Recieve */
+       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       switch (msgrcv.sound_msg.msgtype)
+       {
+       case MM_SOUND_MSG_RES_FOREACH_AVAILABLE_ROUTE_CB:
+               debug_msg("[Client] Success to set foreach available route callback\n");
+               msgrcv.sound_msg.callback = (void *)available_route_cb;
+               msgrcv.sound_msg.cbdata = (void *)user_data;
+               ret = _handle_foreach_callback (&msgrcv);
+               break;
+       case MM_SOUND_MSG_RES_ERROR:
+               debug_error("[Client] Error occurred \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       default:
+               debug_critical("[Client] Unexpected state with communication \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       }
+
+cleanup:
+       pthread_mutex_unlock(&g_thread_mutex);
+
+       debug_fleave();
+       return ret;
+}
+
+int _mm_sound_client_msgq_set_active_route(mm_sound_route route, bool need_broadcast)
+{
+       mm_ipc_msg_t msgrcv = {0,};
+       mm_ipc_msg_t msgsnd = {0,};
+       int ret = MM_ERROR_NONE;
+       int instance;
+
+       debug_fenter();
+
+       ret = __mm_sound_client_get_msg_queue();
+       if (ret  != MM_ERROR_NONE) {
+               return ret;
+       }
+
+       pthread_mutex_lock(&g_thread_mutex);
+
+       instance = getpid();
+       /* Send REQ_SET_ACTIVE_ROUTE */
+       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_SET_ACTIVE_ROUTE;
+       msgsnd.sound_msg.msgid = instance;
+       msgsnd.sound_msg.route = route;
+       msgsnd.sound_msg.need_broadcast = need_broadcast;
+
+       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE)
+               goto cleanup;
+
+       /* Recieve */
+       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       switch (msgrcv.sound_msg.msgtype)
+       {
+       case MM_SOUND_MSG_RES_SET_ACTIVE_ROUTE:
+               debug_msg("[Client] Success to add active device callback\n");
+               break;
+       case MM_SOUND_MSG_RES_ERROR:
+               debug_error("[Client] Error occurred \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       default:
+               debug_critical("[Client] Unexpected state with communication \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       }
+
+cleanup:
+       pthread_mutex_unlock(&g_thread_mutex);
+
+       debug_fleave();
+       return ret;
+}
+
+int _mm_sound_client_msgq_set_active_route_auto(void)
+{
+       mm_ipc_msg_t msgrcv = {0,};
+       mm_ipc_msg_t msgsnd = {0,};
+       int ret = MM_ERROR_NONE;
+       int instance;
+
+       debug_fenter();
+
+       ret = __mm_sound_client_get_msg_queue();
+       if (ret  != MM_ERROR_NONE) {
+               return ret;
+       }
+
+       pthread_mutex_lock(&g_thread_mutex);
+
+       instance = getpid();
+       /* Send REQ_SET_ACTIVE_ROUTE */
+       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_SET_ACTIVE_ROUTE_AUTO;
+       msgsnd.sound_msg.msgid = instance;
+
+       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       /* Recieve */
+       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       switch (msgrcv.sound_msg.msgtype)
+       {
+       case MM_SOUND_MSG_RES_SET_ACTIVE_ROUTE_AUTO:
+               debug_msg("[Client] Success to set active device auto\n");
+               break;
+       case MM_SOUND_MSG_RES_ERROR:
+               debug_error("[Client] Error occurred \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       default:
+               debug_critical("[Client] Unexpected state with communication \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       }
+
+cleanup:
+       pthread_mutex_unlock(&g_thread_mutex);
+
+       debug_fleave();
+       return ret;
+}
+
+int _mm_sound_client_msgq_get_active_device(mm_sound_device_in *device_in, mm_sound_device_out *device_out)
+{
+       mm_ipc_msg_t msgrcv = {0,};
+       mm_ipc_msg_t msgsnd = {0,};
+       int ret = MM_ERROR_NONE;
+       int instance;
+
+       debug_fenter();
+
+       ret = __mm_sound_client_get_msg_queue();
+       if (ret  != MM_ERROR_NONE) {
+               return ret;
+       }
+
+       pthread_mutex_lock(&g_thread_mutex);
+
+       instance = getpid();
+       /* Send REQ_GET_ACTIVE_DEVICE */
+       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_GET_ACTIVE_DEVICE;
+       msgsnd.sound_msg.msgid = instance;
+
+       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       /* Recieve */
+       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       switch (msgrcv.sound_msg.msgtype)
+       {
+       case MM_SOUND_MSG_RES_GET_ACTIVE_DEVICE:
+               *device_in = msgrcv.sound_msg.device_in;
+               *device_out = msgrcv.sound_msg.device_out;
+               debug_log("[Client] Success to get active device in=[%x], out=[%x]\n", *device_in, *device_out);
+               break;
+       case MM_SOUND_MSG_RES_ERROR:
+               debug_error("[Client] Error occurred \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       default:
+               debug_critical("[Client] Unexpected state with communication \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       }
+
+cleanup:
+       pthread_mutex_unlock(&g_thread_mutex);
+
+       debug_fleave();
+       return ret;
+}
+
+int _mm_sound_client_msgq_get_audio_path(mm_sound_device_in *device_in, mm_sound_device_out *device_out)
+{
+       mm_ipc_msg_t msgrcv = {0,};
+       mm_ipc_msg_t msgsnd = {0,};
+       int ret = MM_ERROR_NONE;
+       int instance;
+
+       debug_fenter();
+
+       ret = __mm_sound_client_get_msg_queue();
+       if (ret  != MM_ERROR_NONE) {
+               return ret;
+       }
+
+       pthread_mutex_lock(&g_thread_mutex);
+
+       instance = getpid();
+       /* Send REQ_GET_AUDIO_PATH */
+       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_GET_AUDIO_PATH;
+       msgsnd.sound_msg.msgid = instance;
+
+       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       /* Recieve */
+       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       switch (msgrcv.sound_msg.msgtype)
+       {
+       case MM_SOUND_MSG_RES_GET_AUDIO_PATH:
+               *device_in = msgrcv.sound_msg.device_in;
+               *device_out = msgrcv.sound_msg.device_out;
+               debug_log("[Client] Success to get active device in=[%x], out=[%x]\n", *device_in, *device_out);
+               break;
+       case MM_SOUND_MSG_RES_ERROR:
+               debug_error("[Client] Error occurred \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       default:
+               debug_critical("[Client] Unexpected state with communication \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       }
+
+cleanup:
+       pthread_mutex_unlock(&g_thread_mutex);
+
+       debug_fleave();
+       return ret;
+}
+
+int _mm_sound_client_msgq_add_active_device_changed_callback(const char *name, mm_sound_active_device_changed_cb func, void* user_data)
+{
+       mm_ipc_msg_t msgrcv = {0,};
+       mm_ipc_msg_t msgsnd = {0,};
+       int ret = MM_ERROR_NONE;
+       int instance;
+
+       debug_fenter();
+
+       ret = __mm_sound_client_get_msg_queue();
+       if (ret  != MM_ERROR_NONE) {
+               return ret;
+       }
+
+       pthread_mutex_lock(&g_thread_mutex);
+
+       instance = getpid();
+       /* Send REQ_ADD_ACTIVE_DEVICE_CB */
+       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_ADD_ACTIVE_DEVICE_CB;
+       msgsnd.sound_msg.msgid = instance;
+       msgsnd.sound_msg.callback = func;
+       msgsnd.sound_msg.cbdata = user_data;
+       MMSOUND_STRNCPY(msgsnd.sound_msg.name, name, MM_SOUND_NAME_NUM);
+
+       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       /* Recieve */
+       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       switch (msgrcv.sound_msg.msgtype)
+       {
+       case MM_SOUND_MSG_RES_ADD_ACTIVE_DEVICE_CB:
+               debug_msg("[Client] Success to add active device callback\n");
+               if (g_thread_id == -1)
+               {
+                       g_thread_id = pthread_create(&g_thread, NULL, callbackfunc, NULL);
+                       if (g_thread_id == -1)
+                       {
+                               debug_critical("[Client] Fail to create thread %s\n", strerror(errno));
+                               ret = MM_ERROR_SOUND_INTERNAL;
+                               goto cleanup;
+                       }
+               }
+               break;
+       case MM_SOUND_MSG_RES_ERROR:
+               debug_error("[Client] Error occurred \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       default:
+               debug_critical("[Client] Unexpected state with communication \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       }
+
+cleanup:
+       pthread_mutex_unlock(&g_thread_mutex);
+
+       debug_fleave();
+       return ret;
+}
+
+int _mm_sound_client_msgq_remove_active_device_changed_callback(const char *name)
+{
+       mm_ipc_msg_t msgrcv = {0,};
+       mm_ipc_msg_t msgsnd = {0,};
+       int ret = MM_ERROR_NONE;
+       int instance;
+
+       debug_fenter();
+
+       ret = __mm_sound_client_get_msg_queue();
+       if (ret  != MM_ERROR_NONE) {
+               return ret;
+       }
+
+       pthread_mutex_lock(&g_thread_mutex);
+
+       instance = getpid();
+       /* Send REQ_REMOVE_ACTIVE_DEVICE_CB */
+       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_REMOVE_ACTIVE_DEVICE_CB;
+       msgsnd.sound_msg.msgid = instance;
+       MMSOUND_STRNCPY(msgsnd.sound_msg.name, name, MM_SOUND_NAME_NUM);
+
+       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       /* Recieve */
+       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       switch (msgrcv.sound_msg.msgtype)
+       {
+       case MM_SOUND_MSG_RES_REMOVE_ACTIVE_DEVICE_CB:
+               debug_msg("[Client] Success to remove active device callback\n");
+               break;
+       case MM_SOUND_MSG_RES_ERROR:
+               debug_error("[Client] Error occurred \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       default:
+               debug_critical("[Client] Unexpected state with communication \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       }
+
+cleanup:
+       pthread_mutex_unlock(&g_thread_mutex);
+
+       debug_fleave();
+       return ret;
+}
+
+int _mm_sound_client_msgq_add_volume_changed_callback(mm_sound_volume_changed_cb func, void* user_data)
+{
+       mm_ipc_msg_t msgrcv = {0,};
+       mm_ipc_msg_t msgsnd = {0,};
+       int ret = MM_ERROR_NONE;
+       int instance;
+
+       debug_fenter();
+
+       ret = __mm_sound_client_get_msg_queue();
+       if (ret  != MM_ERROR_NONE) {
+               return ret;
+       }
+
+       pthread_mutex_lock(&g_thread_mutex);
+
+       instance = getpid();
+       /* Send REQ_ADD_VOLUME_CB */
+       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_ADD_VOLUME_CB;
+       msgsnd.sound_msg.msgid = instance;
+       msgsnd.sound_msg.callback = func;
+       msgsnd.sound_msg.cbdata = user_data;
+
+       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       /* Recieve */
+       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       switch (msgrcv.sound_msg.msgtype)
+       {
+       case MM_SOUND_MSG_RES_ADD_VOLUME_CB:
+               debug_msg("[Client] Success to add volume callback\n");
+               if (g_thread_id == -1)
+               {
+                       g_thread_id = pthread_create(&g_thread, NULL, callbackfunc, NULL);
+                       if (g_thread_id == -1)
+                       {
+                               debug_critical("[Client] Fail to create thread %s\n", strerror(errno));
+                               ret = MM_ERROR_SOUND_INTERNAL;
+                               goto cleanup;
+                       }
+               }
+               break;
+       case MM_SOUND_MSG_RES_ERROR:
+               debug_error("[Client] Error occurred \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       default:
+               debug_critical("[Client] Unexpected state with communication \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       }
+
+cleanup:
+       pthread_mutex_unlock(&g_thread_mutex);
+
+       debug_fleave();
+       return ret;
+}
+
+int _mm_sound_client_msgq_remove_volume_changed_callback(void)
+{
+       mm_ipc_msg_t msgrcv = {0,};
+       mm_ipc_msg_t msgsnd = {0,};
+       int ret = MM_ERROR_NONE;
+       int instance;
+
+       debug_fenter();
+
+       ret = __mm_sound_client_get_msg_queue();
+       if (ret  != MM_ERROR_NONE) {
+               return ret;
+       }
+
+       pthread_mutex_lock(&g_thread_mutex);
+
+       instance = getpid();
+       /* Send REQ_REMOVE_VOLUME_CB */
+       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_REMOVE_VOLUME_CB;
+       msgsnd.sound_msg.msgid = instance;
+
+       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       /* Recieve */
+       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       switch (msgrcv.sound_msg.msgtype)
+       {
+       case MM_SOUND_MSG_RES_REMOVE_VOLUME_CB:
+               debug_msg("[Client] Success to remove volume callback\n");
+               break;
+       case MM_SOUND_MSG_RES_ERROR:
+               debug_error("[Client] Error occurred \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       default:
+               debug_critical("[Client] Unexpected state with communication \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       }
+
+cleanup:
+       pthread_mutex_unlock(&g_thread_mutex);
+
+       debug_fleave();
+       return ret;
+}
+
+int _mm_sound_client_msgq_add_available_route_changed_callback(mm_sound_available_route_changed_cb func, void* user_data)
+{
+       mm_ipc_msg_t msgrcv = {0,};
+       mm_ipc_msg_t msgsnd = {0,};
+       int ret = MM_ERROR_NONE;
+       int instance;
+
+       debug_fenter();
+
+       ret = __mm_sound_client_get_msg_queue();
+       if (ret  != MM_ERROR_NONE) {
+               return ret;
+       }
+
+       pthread_mutex_lock(&g_thread_mutex);
+
+       instance = getpid();
+       /* Send REQ_ADD_AVAILABLE_ROUTE_CB */
+       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_ADD_AVAILABLE_ROUTE_CB;
+       msgsnd.sound_msg.msgid = instance;
+       msgsnd.sound_msg.callback = func;
+       msgsnd.sound_msg.cbdata = user_data;
+
+       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       /* Recieve */
+       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       switch (msgrcv.sound_msg.msgtype)
+       {
+       case MM_SOUND_MSG_RES_ADD_AVAILABLE_ROUTE_CB:
+               debug_msg("[Client] Success to add available route callback\n");
+               if (g_thread_id == -1)
+               {
+                       g_thread_id = pthread_create(&g_thread, NULL, callbackfunc, NULL);
+                       if (g_thread_id == -1)
+                       {
+                               debug_critical("[Client] Fail to create thread %s\n", strerror(errno));
+                               ret = MM_ERROR_SOUND_INTERNAL;
+                               goto cleanup;
+                       }
+               }
+               break;
+       case MM_SOUND_MSG_RES_ERROR:
+               debug_error("[Client] Error occurred \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       default:
+               debug_critical("[Client] Unexpected state with communication \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       }
+
+cleanup:
+       pthread_mutex_unlock(&g_thread_mutex);
+
+       debug_fleave();
+       return ret;
+}
+
+int _mm_sound_client_msgq_remove_available_route_changed_callback(void)
+{
+       mm_ipc_msg_t msgrcv = {0,};
+       mm_ipc_msg_t msgsnd = {0,};
+       int ret = MM_ERROR_NONE;
+       int instance;
+
+       debug_fenter();
+
+       ret = __mm_sound_client_get_msg_queue();
+       if (ret  != MM_ERROR_NONE) {
+               return ret;
+       }
+
+       pthread_mutex_lock(&g_thread_mutex);
+
+       instance = getpid();
+       /* Send REQ_REMOVE_AVAILABLE_ROUTE_CB */
+       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_REMOVE_AVAILABLE_ROUTE_CB;
+       msgsnd.sound_msg.msgid = instance;
+
+       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       /* Recieve */
+       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE) {
+               goto cleanup;
+       }
+
+       switch (msgrcv.sound_msg.msgtype)
+       {
+       case MM_SOUND_MSG_RES_REMOVE_AVAILABLE_ROUTE_CB:
+               debug_msg("[Client] Success to remove available route callback\n");
+               break;
+       case MM_SOUND_MSG_RES_ERROR:
+               debug_error("[Client] Error occurred \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       default:
+               debug_critical("[Client] Unexpected state with communication \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       }
+
+cleanup:
+       pthread_mutex_unlock(&g_thread_mutex);
+
+       debug_fleave();
+       return ret;
+}
+
+static int __MMIpcCBSndMsg(mm_ipc_msg_t *msg)
+{
+       /* rcv message */
+       msg->msg_type = msg->sound_msg.msgid;
+       if (msgsnd(g_msg_sccb, msg,DSIZE, 0)== -1)
+       {
+               debug_error("[Client] Fail to callback send message msgid : [%d], [%d][%s]", g_msg_sccb, errno, strerror(errno));
+               return MM_ERROR_COMMON_UNKNOWN;
+       }
+       return MM_ERROR_NONE;
+}
+
+static int __MMIpcCBRecvMsg(int msgtype, mm_ipc_msg_t *msg)
+{
+       /* rcv message */
+       if(msgrcv(g_msg_sccb, msg, DSIZE, msgtype, 0) == -1)
+       {
+               debug_error("[Client] Fail to callback receive message msgid : [%d], [%d][%s]", g_msg_sccb, errno, strerror(errno));
+               return MM_ERROR_COMMON_UNKNOWN;
+       }
+       return MM_ERROR_NONE;
+}
+
+static int __MMIpcCBSndMsgReply(mm_ipc_msg_t *msg)
+{
+       /* rcv message */
+       msg->msg_type = msg->sound_msg.msgid;
+       if (msgsnd(g_msg_scsndcb, msg, DSIZE, 0)== -1) {
+               debug_error("[Client] Fail to callback send message msgid : [%d], [%d][%s]", g_msg_scsndcb, errno, strerror(errno));
+               return MM_ERROR_COMMON_UNKNOWN;
+       }
+       return MM_ERROR_NONE;
+}
+
+static int __MMIpcCBRecvMsgForReply(int msgtype, mm_ipc_msg_t *msg)
+{
+       /* rcv message */
+       if(msgrcv(g_msg_scrcvcb, msg, DSIZE, msgtype, 0) == -1) {
+               debug_error("[Client] Fail to callback receive message msgid : [%d], [%d][%s]", g_msg_scrcvcb, errno, strerror(errno));
+               return MM_ERROR_COMMON_UNKNOWN;
+       }
+       return MM_ERROR_NONE;
+}
+
+#define MAX_RCV_RETRY 20000
+
+static int __MMIpcRecvMsg(int msgtype, mm_ipc_msg_t *msg)
+{
+       int retry_count = 0;
+
+       /* rcv message */
+       while (msgrcv(g_msg_scrcv, msg, DSIZE, msgtype, IPC_NOWAIT) == -1) {
+               if (errno == ENOMSG) {
+                       if (retry_count < MAX_RCV_RETRY) { /* usec is 10^-6 sec so, 5ms * 20000 = 10sec. */
+                               usleep(5000);
+                               retry_count++;
+                               continue;
+                       } else {
+                               debug_error("[Client] retry(%d) is over : [%d] \n", MAX_RCV_RETRY, g_msg_scrcv);
+                               return MM_ERROR_SOUND_INTERNAL;
+                       }
+               } else if (errno == EINTR) {
+                       debug_warning("[Client] Interrupted by signal, continue loop");
+                       continue;
+               }
+
+               debug_error("[Client] Fail to receive msgid : [%d], [%d][%s]", g_msg_scrcv, errno, strerror(errno));
+
+               return MM_ERROR_COMMON_UNKNOWN;
+       }
+       debug_log("[Client] Retry %d times when receive msg\n", retry_count);
+       return MM_ERROR_NONE;
+}
+
+static int __MMIpcSndMsg(mm_ipc_msg_t *msg)
+{
+       /* rcv message */
+       int try_again = 0;
+
+       msg->msg_type = msg->sound_msg.msgid;
+       while (msgsnd(g_msg_scsnd, msg,DSIZE, IPC_NOWAIT) == -1)
+       {
+               if(errno == EACCES) {
+                       debug_warning("Not acces.\n");
+               } else if(errno == EAGAIN || errno == ENOMEM) {
+                       mm_ipc_msg_t msgdata = {0,};
+                       debug_warning("Blocked process [msgflag & IPC_NOWAIT != 0]\n");
+                       debug_warning("The system does not have enough memory to make a copy of the message pointed to by msgp\n");
+                       /* wait 10 msec ,then it will try again */
+                       usleep(10000);
+                       /*  it will try 5 times, after 5 times ,if it still fail ,then it will clear the message queue */
+                       if (try_again <= 5) {
+                               try_again ++;
+                               continue;
+                       }
+                       /* message queue is full ,it need to clear the queue */
+                       while( msgrcv(g_msg_scsnd, &msgdata, DSIZE, 0, IPC_NOWAIT) != -1 ) {
+                               debug_warning("msg queue is full ,remove msgtype:[%d] from the queue",msgdata.sound_msg.msgtype);
+                       }
+                       try_again++;
+                       continue;
+               } else if(errno == EIDRM) {
+                       debug_warning("Removed msgid from system\n");
+               } else if(errno == EINTR) {
+                       debug_warning("Iterrrupted by singnal\n");
+               } else if(errno == EINVAL) {
+                       debug_warning("Invalid msgid or msgtype < 1 or out of data size \n");
+               } else if(errno == EFAULT) {
+                       debug_warning("The address pointed to by msgp isn't accessible \n");
+               }
+               debug_error("[Client] Fail to send message msgid : [%d], [%d][%s]", g_msg_scsnd, errno, strerror(errno));
+               return MM_ERROR_SOUND_INTERNAL;
+       }
+       return MM_ERROR_NONE;
+}
+
+static int __MMSoundGetMsg(void)
+{
+       /* Init message queue, generate msgid for communication to server */
+       /* The key value to get msgid is defined "mm_sound_msg.h". Shared with server */
+       int i = 0;
+
+       debug_fenter();
+
+       /* get msg queue rcv, snd, cb */
+       g_msg_scsnd = msgget(ftok(KEY_BASE_PATH, RCV_MSG), 0666);
+       g_msg_scrcv = msgget(ftok(KEY_BASE_PATH, SND_MSG), 0666);
+       g_msg_sccb = msgget(ftok(KEY_BASE_PATH, CB_MSG), 0666);
+       g_msg_scsndcb = msgget(ftok(KEY_BASE_PATH, RCV_CB_MSG), 0666);
+       g_msg_scrcvcb = msgget(ftok(KEY_BASE_PATH, SND_CB_MSG), 0666);
+
+       if ((g_msg_scsnd == -1 || g_msg_scrcv == -1 || g_msg_sccb == -1 || g_msg_scsndcb == -1 || g_msg_scrcvcb == -1) != MM_ERROR_NONE) {
+               if (errno == EACCES) {
+                       debug_warning("Require ROOT permission.\n");
+               } else if (errno == ENOMEM) {
+                       debug_warning("System memory is empty.\n");
+               } else if(errno == ENOSPC) {
+                       debug_warning("Resource is empty.\n");
+               }
+               /* Some app would start before Sound Server IPC ready. */
+               /* Let's try it again in 50ms later by 10 times */
+               for (i=0;i<10;i++) {
+                       usleep(50000);
+                       g_msg_scsnd = msgget(ftok(KEY_BASE_PATH, RCV_MSG), 0666);
+                       g_msg_scrcv = msgget(ftok(KEY_BASE_PATH, SND_MSG), 0666);
+                       g_msg_sccb = msgget(ftok(KEY_BASE_PATH, CB_MSG), 0666);
+                       g_msg_scsndcb = msgget(ftok(KEY_BASE_PATH, RCV_CB_MSG), 0666);
+                       g_msg_scrcvcb = msgget(ftok(KEY_BASE_PATH, SND_CB_MSG), 0666);
+                       if ((g_msg_scsnd == -1 || g_msg_scrcv == -1 || g_msg_sccb == -1 || g_msg_scsndcb == -1 || g_msg_scrcvcb == -1) != MM_ERROR_NONE) {
+                               debug_error("Fail to GET msgid by retrying %d times\n", i+1);
+                       } else
+                               break;
+               }
+               if ((g_msg_scsnd == -1 || g_msg_scrcv == -1 || g_msg_sccb == -1 || g_msg_scsndcb == -1 || g_msg_scrcvcb == -1) != MM_ERROR_NONE) {
+                       debug_error("Fail to GET msgid finally, just return internal error.\n");
+                       return MM_ERROR_SOUND_INTERNAL;
+               }
+       }
+
+       debug_log("Get msg queue id from server : snd[%d], rcv[%d], cb[%d], snd_cb[%d], rcv_cb[%d]\n",
+                       g_msg_scsnd, g_msg_scrcv, g_msg_sccb, g_msg_scsndcb, g_msg_scrcvcb);
+
+       debug_fleave();
+       return MM_ERROR_NONE;
+}
+
+#ifdef PULSE_CLIENT
+
+int MMSoundClientMsgqIsBtA2dpOn (bool *connected, char** bt_name)
+{
+       mm_ipc_msg_t msgrcv = {0,};
+       mm_ipc_msg_t msgsnd = {0,};
+       int ret = MM_ERROR_NONE;
+       int instance;
+
+       debug_fenter();
+
+       instance = getpid();
+
+       ret = __mm_sound_client_get_msg_queue();
+       if (ret  != MM_ERROR_NONE)
+               return ret;
+
+       pthread_mutex_lock(&g_thread_mutex);
+
+       /* Send req  */
+       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_IS_BT_A2DP_ON;
+       msgsnd.sound_msg.msgid = instance;
+
+       ret = __MMIpcSndMsg(&msgsnd);
+       if (ret != MM_ERROR_NONE)
+       {
+               debug_error("Fail to send msg\n");
+               goto cleanup;
+       }
+
+       /* Receive */
+       ret = __MMIpcRecvMsg(instance, &msgrcv);
+       if (ret != MM_ERROR_NONE)
+       {
+               debug_error("Fail to recieve msg\n");
+               goto cleanup;
+       }
+       switch (msgrcv.sound_msg.msgtype)
+       {
+               case MM_SOUND_MSG_RES_IS_BT_A2DP_ON:
+                       debug_msg("Success to get IS_BT_A2DP_ON [%d][%s]\n", msgrcv.sound_msg.code, msgrcv.sound_msg.filename);
+                       *connected  = (bool)msgrcv.sound_msg.code;
+                       if (*connected)
+                               *bt_name = strdup (msgrcv.sound_msg.filename);
+                       else
+                               *bt_name = NULL;
+                       break;
+               case MM_SOUND_MSG_RES_ERROR:
+                       debug_error("Error occurred \n");
+                       ret = msgrcv.sound_msg.code;
+                       goto cleanup;
+                       break;
+               default:
+                       debug_critical("Unexpected state with communication \n");
+                       ret = msgrcv.sound_msg.code;
+                       goto cleanup;
+                       break;
+       }
+
+cleanup:
+               pthread_mutex_unlock(&g_thread_mutex);
+
+       debug_fleave();
+       return ret;
+}
+
+int _mm_sound_client_msgq_set_sound_path_for_active_device(mm_sound_device_out device_out, mm_sound_device_in device_in)
+{
+       mm_ipc_msg_t msgrcv = {0,};
+       mm_ipc_msg_t msgsnd = {0,};
+       int ret = MM_ERROR_NONE;
+       int instance;
+
+       debug_fenter();
+
+       ret = __mm_sound_client_get_msg_queue();
+       if (ret  != MM_ERROR_NONE)
+               return ret;
+
+       pthread_mutex_lock(&g_thread_mutex);
+
+       instance = getpid();
+       /* Send MM_SOUND_MSG_REQ_SET_PATH_FOR_ACTIVE_DEVICE */
+       msgsnd.sound_msg.msgtype = MM_SOUND_MSG_REQ_SET_PATH_FOR_ACTIVE_DEVICE;
+       msgsnd.sound_msg.msgid = instance;
+       msgsnd.sound_msg.device_in =  device_in;
+       msgsnd.sound_msg.device_out = device_out;
+
+       if (__MMIpcSndMsg(&msgsnd) != MM_ERROR_NONE)
+               goto cleanup;
+
+       /* Recieve */
+       if (__MMIpcRecvMsg(instance, &msgrcv) != MM_ERROR_NONE)
+               goto cleanup;
+
+       switch (msgrcv.sound_msg.msgtype)
+       {
+       case MM_SOUND_MSG_RES_SET_PATH_FOR_ACTIVE_DEVICE:
+               debug_msg("[Client] Success to setsound path for active device\n");
+               break;
+       case MM_SOUND_MSG_RES_ERROR:
+               debug_error("[Client] Error occurred \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       default:
+               debug_critical("[Client] Unexpected state with communication \n");
+               ret = msgrcv.sound_msg.code;
+               goto cleanup;
+               break;
+       }
+
+cleanup:
+       pthread_mutex_unlock(&g_thread_mutex);
+
+       debug_fleave();
+       return ret;
+}
+
+
+#endif // PULSE_CLIENT
index e6d3b26..83c987a 100644 (file)
 #include "include/mm_sound.h"
 #include "include/mm_sound_device.h"
 
-bool is_new_device_list = true;
+#define VOLUME_TYPE_LEN 64
 
-static int check_for_valid_mask (mm_sound_device_flags_e flags)
+bool g_is_new_device_list = true;
+
+static int _check_for_valid_mask (mm_sound_device_flags_e flags)
 {
        int ret = MM_ERROR_NONE;
        bool at_least_cond = false;
@@ -63,6 +65,38 @@ static int check_for_valid_mask (mm_sound_device_flags_e flags)
        return ret;
 }
 
+static int __convert_device_type_to_enum (char *device_type, mm_sound_device_type_e *device_type_enum)
+{
+       int ret = MM_ERROR_NONE;
+
+       if (!device_type || !device_type_enum) {
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       if (!strncmp(device_type, "builtin-speaker", VOLUME_TYPE_LEN)) {
+               *device_type_enum = MM_SOUND_DEVICE_TYPE_BUILTIN_SPEAKER;
+       } else if (!strncmp(device_type, "builtin-receiver", VOLUME_TYPE_LEN)) {
+               *device_type_enum = MM_SOUND_DEVICE_TYPE_BUILTIN_RECEIVER;
+       } else if (!strncmp(device_type, "builtin-mic", VOLUME_TYPE_LEN)) {
+               *device_type_enum = MM_SOUND_DEVICE_TYPE_BUILTIN_MIC;
+       } else if (!strncmp(device_type, "audio-jack", VOLUME_TYPE_LEN)) {
+               *device_type_enum = MM_SOUND_DEVICE_TYPE_AUDIOJACK;
+       } else if (!strncmp(device_type, "bt", VOLUME_TYPE_LEN)) {
+               *device_type_enum = MM_SOUND_DEVICE_TYPE_BLUETOOTH;
+       } else if (!strncmp(device_type, "hdmi", VOLUME_TYPE_LEN)) {
+               *device_type_enum = MM_SOUND_DEVICE_TYPE_HDMI;
+       } else if (!strncmp(device_type, "forwarding", VOLUME_TYPE_LEN)) {
+               *device_type_enum = MM_SOUND_DEVICE_TYPE_MIRRORING;
+       } else if (!strncmp(device_type, "usb-audio", VOLUME_TYPE_LEN)) {
+               *device_type_enum = MM_SOUND_DEVICE_TYPE_USB_AUDIO;
+       } else {
+               ret = MM_ERROR_INVALID_ARGUMENT;
+               debug_error("not supported device_type(%s), err(0x%08x)", device_type, ret);
+       }
+
+       return ret;
+}
+
 EXPORT_API
 int mm_sound_add_device_connected_callback(mm_sound_device_flags_e flags, mm_sound_device_connected_cb func, void *user_data)
 {
@@ -72,9 +106,9 @@ int mm_sound_add_device_connected_callback(mm_sound_device_flags_e flags, mm_sou
                debug_error("argument is not valid\n");
                return MM_ERROR_INVALID_ARGUMENT;
        }
-       ret = check_for_valid_mask(flags);
+       ret = _check_for_valid_mask(flags);
        if (ret == MM_ERROR_NONE) {
-               ret = _mm_sound_client_add_device_connected_callback(flags, func, user_data);
+               ret = mm_sound_client_add_device_connected_callback(flags, func, user_data);
                if (ret < 0) {
                        debug_error("Could not add device connected callback, ret = %x\n", ret);
                }
@@ -88,7 +122,7 @@ int mm_sound_remove_device_connected_callback(void)
 {
        int ret = MM_ERROR_NONE;
 
-       ret = _mm_sound_client_remove_device_connected_callback();
+       ret = mm_sound_client_remove_device_connected_callback();
        if (ret < 0) {
                debug_error("Could not remove device connected callback, ret = %x\n", ret);
        }
@@ -105,9 +139,9 @@ int mm_sound_add_device_information_changed_callback(mm_sound_device_flags_e fla
                debug_error("argument is not valid\n");
                return MM_ERROR_INVALID_ARGUMENT;
        }
-       ret = check_for_valid_mask(flags);
+       ret = _check_for_valid_mask(flags);
        if (ret == MM_ERROR_NONE) {
-               ret = _mm_sound_client_add_device_info_changed_callback(flags, func, user_data);
+               ret = mm_sound_client_add_device_info_changed_callback(flags, func, user_data);
                if (ret < 0) {
                        debug_error("Could not add device information changed callback, ret = %x\n", ret);
                }
@@ -121,7 +155,7 @@ int mm_sound_remove_device_information_changed_callback()
 {
        int ret = MM_ERROR_NONE;
 
-       ret = _mm_sound_client_remove_device_info_changed_callback();
+       ret = mm_sound_client_remove_device_info_changed_callback();
        if (ret < 0) {
                debug_error("Could not remove device information changed callback, ret = %x\n", ret);
        }
@@ -137,13 +171,13 @@ int mm_sound_get_current_device_list(mm_sound_device_flags_e flags, MMSoundDevic
        if (!device_list) {
                return MM_ERROR_INVALID_ARGUMENT;
        }
-       ret = check_for_valid_mask(flags);
+       ret = _check_for_valid_mask(flags);
        if (ret == MM_ERROR_NONE) {
-               ret = _mm_sound_client_get_current_connected_device_list(flags, (mm_sound_device_list_t**)device_list);
+               ret = mm_sound_client_get_current_connected_device_list(flags, (mm_sound_device_list_t**)device_list);
                if (ret < 0) {
                        debug_error("Could not get current connected device list, ret = %x\n", ret);
                } else {
-                       is_new_device_list = true;
+                       g_is_new_device_list = true;
                }
        }
 
@@ -161,7 +195,7 @@ int mm_sound_get_next_device (MMSoundDeviceList_t device_list, MMSoundDevice_t *
                return MM_ERROR_INVALID_ARGUMENT;
        }
        device_list_t = (mm_sound_device_list_t*) device_list;
-       if (is_new_device_list) {
+       if (g_is_new_device_list) {
                node = g_list_first(device_list_t->list);
        } else {
                node = g_list_next(device_list_t->list);
@@ -169,8 +203,8 @@ int mm_sound_get_next_device (MMSoundDeviceList_t device_list, MMSoundDevice_t *
        if (!node) {
                ret = MM_ERROR_SOUND_NO_DATA;
        } else {
-               if (is_new_device_list) {
-                       is_new_device_list = false;
+               if (g_is_new_device_list) {
+                       g_is_new_device_list = false;
                } else {
                        device_list_t->list = node;
                }
@@ -207,11 +241,11 @@ EXPORT_API
 int mm_sound_get_device_type(MMSoundDevice_t device_h, mm_sound_device_type_e *type)
 {
        mm_sound_device_t *device = (mm_sound_device_t*)device_h;
-       if(!device) {
-               debug_error("invalid handle\n");
+       if(!device || !type) {
+               debug_error("invalid argument\n");
                return MM_ERROR_INVALID_ARGUMENT;
        }
-       *type = device->type;
+       __convert_device_type_to_enum(device->type, type);
        debug_log("device_handle:0x%x, type:%d\n", device, *type);
 
        return MM_ERROR_NONE;
@@ -226,7 +260,7 @@ int mm_sound_get_device_io_direction(MMSoundDevice_t device_h, mm_sound_device_i
                return MM_ERROR_INVALID_ARGUMENT;
        }
        *io_direction = device->io_direction;
-       debug_log("device_handle:0x%x, io_direction:%d (0:IN,1:OUT,2:INOUT)\n", device, *io_direction);
+       debug_log("device_handle:0x%x, io_direction:%d (1:IN,2:OUT,3:INOUT)\n", device, *io_direction);
 
        return MM_ERROR_NONE;
 }
@@ -239,8 +273,8 @@ int mm_sound_get_device_id(MMSoundDevice_t device_h, int *id)
                debug_error("invalid handle\n");
                return MM_ERROR_INVALID_ARGUMENT;
        }
-       debug_log("device_handle:0x%x, id:%d\n", device, *id);
        *id = device->id;
+       debug_log("device_handle:0x%x, id:%d\n", device, *id);
 
        return MM_ERROR_NONE;
 }
@@ -253,8 +287,8 @@ int mm_sound_get_device_state(MMSoundDevice_t device_h, mm_sound_device_state_e
                debug_error("invalid handle\n");
                return MM_ERROR_INVALID_ARGUMENT;
        }
-       debug_log("device_handle:0x%x, state:%d (0:INACTIVATED,1:ACTIVATED)\n", device, *state);
        *state = device->state;
+       debug_log("device_handle:0x%x, state:%d (0:INACTIVATED,1:ACTIVATED)\n", device, *state);
 
        return MM_ERROR_NONE;
 }
diff --git a/mm_sound_focus.c b/mm_sound_focus.c
new file mode 100644 (file)
index 0000000..c1ee81d
--- /dev/null
@@ -0,0 +1,182 @@
+/*
+ * libmm-sound
+ *
+ * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Sangchul Lee <sc11.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <vconf.h>
+
+#include <mm_debug.h>
+
+#include "include/mm_sound.h"
+#include "include/mm_sound_focus.h"
+#include "server/include/mm_sound_mgr_focus.h"
+
+EXPORT_API
+int mm_sound_focus_get_id(int *id)
+{
+       int ret = MM_ERROR_NONE;
+
+       debug_fenter();
+
+       ret = mm_sound_client_get_uniq_id(id);
+       if (ret) {
+               debug_error("Failed to mm_sound_client_get_uniq_id(), ret[0x%x]\n", ret);
+       }
+
+       debug_fleave();
+
+       return ret;
+}
+
+EXPORT_API
+int mm_sound_register_focus(int id, const char *stream_type, mm_sound_focus_changed_cb callback, void *user_data)
+{
+       int ret = MM_ERROR_NONE;
+
+       debug_fenter();
+
+       if (id < 0 || callback == NULL) {
+               debug_error("argument is not valid\n");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       ret = mm_sound_client_register_focus(id, stream_type, callback, user_data);
+       if (ret) {
+               debug_error("Could not register focus, ret[0x%x]\n", ret);
+       }
+
+       debug_fleave();
+
+       return ret;
+}
+
+EXPORT_API
+int mm_sound_unregister_focus(int id)
+{
+       int ret = MM_ERROR_NONE;
+
+       debug_fenter();
+
+       if (id < 0) {
+               debug_error("argument is not valid\n");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       ret = mm_sound_client_unregister_focus(id);
+       if (ret) {
+               debug_error("Could not unregister focus, ret = %x\n", ret);
+       }
+
+       debug_fleave();
+
+       return ret;
+}
+
+EXPORT_API
+int mm_sound_acquire_focus(int id, mm_sound_focus_type_e focus_type, const char *additional_info)
+{
+       int ret = MM_ERROR_NONE;
+
+       debug_fenter();
+
+       if (id < 0) {
+               debug_error("argument is not valid\n");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+       if (focus_type < FOCUS_FOR_PLAYBACK || focus_type > FOCUS_FOR_BOTH) {
+               debug_error("argument is not valid\n");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       ret = mm_sound_client_acquire_focus(id, focus_type, additional_info);
+       if (ret) {
+               debug_error("Could not acquire focus, ret[0x%x]\n", ret);
+       }
+
+       debug_fleave();
+
+       return ret;
+}
+
+EXPORT_API
+int mm_sound_release_focus(int id, mm_sound_focus_type_e focus_type, const char *additional_info)
+{
+       int ret = MM_ERROR_NONE;
+
+       debug_fenter();
+
+       if (id < 0) {
+               debug_error("argument is not valid\n");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+       if (focus_type < FOCUS_FOR_PLAYBACK || focus_type > FOCUS_FOR_BOTH) {
+               debug_error("argument is not valid\n");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       ret = mm_sound_client_release_focus(id, focus_type, additional_info);
+       if (ret) {
+               debug_error("Could not release focus, ret[0x%x]\n", ret);
+       }
+
+       debug_fleave();
+
+       return ret;
+}
+
+EXPORT_API
+int mm_sound_set_focus_watch_callback(mm_sound_focus_type_e focus_type, mm_sound_focus_changed_watch_cb callback, void *user_data, int *id)
+{
+       int ret = MM_ERROR_NONE;
+
+       debug_fenter();
+
+       if (callback == NULL || id == NULL) {
+               debug_error("argument is not valid\n");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+       ret = mm_sound_client_set_focus_watch_callback(focus_type, callback, user_data, id);
+       if (ret) {
+               debug_error("Could not set focus watch callback, ret[0x%x]\n", ret);
+       }
+
+       debug_fleave();
+
+       return ret;
+}
+
+EXPORT_API
+int mm_sound_unset_focus_watch_callback(int id)
+{
+       int ret = MM_ERROR_NONE;
+
+       debug_fenter();
+
+       ret = mm_sound_client_unset_focus_watch_callback(id);
+       if (ret) {
+               debug_error("Could not unset focus watch callback, id(%d), ret = %x\n", id, ret);
+       }
+
+       debug_fleave();
+
+       return ret;
+}
index d551378..becd843 100644 (file)
 #include "include/mm_sound_common.h"
 
 #define KEYTONE_PATH "/tmp/keytone"            /* Keytone pipe path */
-#define FILE_FULL_PATH 1024                            /* File path lenth */
+#define FILE_FULL_PATH 1024                            /* File path length */
+#define ROLE_NAME_LEN 64                               /* Role name length */
+#define VOLUME_GAIN_TYPE_LEN 64                /* Volume gain type length */
 
-typedef struct {
-       char filename[FILE_FULL_PATH];
-       int volume_config;
-} ipc_t;
+#define AUDIO_VOLUME_CONFIG_TYPE(vol) (vol & 0x00FF)
+#define AUDIO_VOLUME_CONFIG_GAIN(vol) (vol & 0xFF00)
+
+typedef struct ipc_data {
+    char filename[FILE_FULL_PATH];
+    char role[ROLE_NAME_LEN];
+    char volume_gain_type[VOLUME_GAIN_TYPE_LEN];
+}ipc_t;
+
+static const char* convert_volume_type_to_role(int volume_type)
+{
+       debug_warning ("volume_type(%d)", volume_type);
+       switch(volume_type) {
+       case VOLUME_TYPE_SYSTEM:
+               return "system";
+       case VOLUME_TYPE_NOTIFICATION:
+               return "notification";
+       case VOLUME_TYPE_ALARM:
+               return "alarm";
+       case VOLUME_TYPE_RINGTONE:
+               return "ringtone";
+       case VOLUME_TYPE_CALL:
+               return "call";
+       case VOLUME_TYPE_VOIP:
+               return "voip";
+       case VOLUME_TYPE_VOICE:
+               return "voice";
+       default:
+               return NULL;
+       }
+}
+
+static const char* convert_volume_gain_type_to_string(int volume_gain_type)
+{
+       debug_warning ("volume_gain_type(0x%x)", volume_gain_type);
+       switch(volume_gain_type) {
+       case VOLUME_GAIN_DEFAULT:
+               return NULL;
+       case VOLUME_GAIN_DIALER:
+               return "dialer";
+       case VOLUME_GAIN_TOUCH:
+               return "touch";
+       case VOLUME_GAIN_AF:
+               return "af";
+       case VOLUME_GAIN_SHUTTER1:
+               return "shutter1";
+       case VOLUME_GAIN_SHUTTER2:
+               return "shutter2";
+       case VOLUME_GAIN_CAMCORDING:
+               return "camcording";
+       case VOLUME_GAIN_MIDI:
+               return "midi";
+       case VOLUME_GAIN_BOOTING:
+               return "booting";
+       case VOLUME_GAIN_VIDEO:
+               return "video";
+       case VOLUME_GAIN_TTS:
+               return "tts";
+       default:
+               return NULL;
+       }
+}
 
 EXPORT_API
 int mm_sound_play_keysound(const char *filename, int volume_config)
@@ -54,8 +114,10 @@ int mm_sound_play_keysound(const char *filename, int volume_config)
        int err = MM_ERROR_NONE;
        int fd = -1;
        int size = 0;
-       ipc_t data = {{0,},};
+       ipc_t data = {{0,},{0,},{0,}};
        int capture_status = 0;
+       char *role = NULL;
+       char *vol_gain_type = NULL;
 
        if (!filename)
                return MM_ERROR_SOUND_INVALID_FILE;
@@ -80,10 +142,18 @@ int mm_sound_play_keysound(const char *filename, int volume_config)
                debug_error("Fail to open pipe\n");
                return MM_ERROR_SOUND_FILE_NOT_FOUND;
        }
-       data.volume_config = volume_config;
+
+       /* convert volume type to role */
+       role = convert_volume_type_to_role(AUDIO_VOLUME_CONFIG_TYPE(volume_config));
+       if (role) {
+               MMSOUND_STRNCPY(data.role, role, ROLE_NAME_LEN);
+               vol_gain_type = convert_volume_gain_type_to_string(AUDIO_VOLUME_CONFIG_GAIN(volume_config));
+               if (vol_gain_type)
+                       MMSOUND_STRNCPY(data.volume_gain_type, vol_gain_type, VOLUME_GAIN_TYPE_LEN);
+       }
        MMSOUND_STRNCPY(data.filename, filename, FILE_FULL_PATH);
 
-       debug_msg("filepath=[%s], volume_config=[0x%x]\n", data.filename, volume_config);
+       debug_msg("filepath=[%s], role=[%s], volume_gain_type=[%s]\n", data.filename, data.role, data.volume_gain_type);
        size = sizeof(ipc_t);
 
        /* Write to PIPE */
@@ -98,5 +168,3 @@ int mm_sound_play_keysound(const char *filename, int volume_config)
 
        return MM_ERROR_NONE;
 }
-
-
index 3a4cefb..104ee66 100644 (file)
@@ -142,7 +142,6 @@ static const pa_tizen_volume_type_t mm_sound_volume_type_to_pa[VOLUME_TYPE_MAX]
        [VOLUME_TYPE_VOIP] = PA_TIZEN_VOLUME_TYPE_VOIP,
        [VOLUME_TYPE_VOICE] = PA_TIZEN_VOLUME_TYPE_VOICE,
        [VOLUME_TYPE_FIXED] = PA_TIZEN_VOLUME_TYPE_FIXED,
-//     [VOLUME_TYPE_EXT_SYSTEM_JAVA] = PA_TIZEN_VOLUME_TYPE_EXT_JAVA,
 };
 
 #define PA_SIMPLE_FADE_INTERVAL_USEC                                           20000
@@ -206,7 +205,7 @@ gint __mm_sound_handle_comparefunc(gconstpointer a, gconstpointer b)
 }
 
 EXPORT_API
-int mm_sound_pa_open(MMSoundHandleMode mode, mm_sound_handle_route_info *route_info, MMSoundHandlePriority priority, int volume_config, pa_sample_spec* ss, pa_channel_map* channel_map, int* size)
+int mm_sound_pa_open(MMSoundHandleMode mode, mm_sound_handle_route_info *route_info, MMSoundHandlePriority priority, int volume_config, pa_sample_spec* ss, pa_channel_map* channel_map, int* size, char *stream_type, int stream_index)
 {
     pa_simple *s = NULL;
     pa_channel_map maps;
@@ -257,15 +256,18 @@ int mm_sound_pa_open(MMSoundHandleMode mode, mm_sound_handle_route_info *route_i
     }
 
     /* Set volume type of stream */
-    vol_conf_type = volume_config & 0x000000FF;
-    prop_vol_type = mm_sound_volume_type_to_pa[vol_conf_type];
-    pa_proplist_setf(proplist, PA_PROP_MEDIA_TIZEN_VOLUME_TYPE, "%d", prop_vol_type);
+    if(volume_config > 0) {
+        debug_log("setting gain type");
+        vol_conf_type = volume_config & 0x000000FF;
+        prop_vol_type = mm_sound_volume_type_to_pa[vol_conf_type];
+//          pa_proplist_setf(proplist, PA_PROP_MEDIA_TIZEN_VOLUME_TYPE, "%d", prop_vol_type);
 
-    /* Set gain type of stream */
-    prop_gain_type = (volume_config >> 8) & 0x000000FF;
-
-    pa_proplist_setf(proplist, PA_PROP_MEDIA_TIZEN_GAIN_TYPE, "%d", prop_gain_type);
+        /* Set gain type of stream */
+        prop_gain_type = (volume_config >> 8) & 0x000000FF;
 
+        pa_proplist_setf(proplist, PA_PROP_MEDIA_TIZEN_GAIN_TYPE, "%d", prop_gain_type);
+    }
+#if 0
     IS_INPUT_HANDLE(handle_mode) {
         handle_inout = HANDLE_DIRECTION_IN;
 
@@ -330,10 +332,18 @@ int mm_sound_pa_open(MMSoundHandleMode mode, mm_sound_handle_route_info *route_i
     }
     pa_proplist_sets(proplist, PA_PROP_MEDIA_POLICY, prop_policy);
 
-    if (priority) {
-        debug_msg("Set HIGH priority [%d]", priority);
-        pa_proplist_sets(proplist, PA_PROP_MEDIA_ROLE, "solo");
+#endif
+
+    if (stream_index != -1) {
+        char stream_index_s[11];
+        debug_msg("Set stream index [%d]", stream_index);
+
+        snprintf(stream_index_s, sizeof(stream_index_s)-1, "%d", stream_index);
+        debug_msg("stream_index[%d] converted to string[%s]", stream_index, stream_index_s);
+        pa_proplist_sets(proplist, PA_PROP_MEDIA_PARENT_ID, stream_index_s);
     }
+    /* Set stream type */
+    pa_proplist_sets(proplist, PA_PROP_MEDIA_ROLE, stream_type);
 
     memset(&attr, '\0', sizeof(attr));
 
@@ -441,8 +451,8 @@ int mm_sound_pa_open(MMSoundHandleMode mode, mm_sound_handle_route_info *route_i
         samples_per_period = (ss->rate * period_time) / 1000;
         periods_per_buffer = PA_SIMPLE_PERIODS_PER_BUFFER_VOIP;
         attr.prebuf = -1;
-        attr.minreq = pa_usec_to_bytes(20*PA_USEC_PER_MSEC, &ss);
-        attr.tlength = pa_usec_to_bytes(100*PA_USEC_PER_MSEC, &ss);
+        attr.minreq = pa_usec_to_bytes(20*PA_USEC_PER_MSEC, ss);
+        attr.tlength = pa_usec_to_bytes(100*PA_USEC_PER_MSEC, ss);
         attr.maxlength = -1;
         attr.fragsize = 0;
 
@@ -809,27 +819,6 @@ static void __mm_sound_pa_success_cb(pa_context *c, int success, void *userdata)
 }
 
 EXPORT_API
-int mm_sound_pa_set_volume_by_type(const int type, const int value)
-{
-    pa_operation *o = NULL;
-
-    CHECK_VOLUME_TYPE_RANGE(type);
-    CHECK_CONNECT_TO_PULSEAUDIO();
-
-    pa_threaded_mainloop_lock(mm_sound_handle_mgr.mainloop);
-
-    o = pa_ext_policy_set_volume_level(mm_sound_handle_mgr.context, -1, type, value, __mm_sound_pa_success_cb, (void*)mm_sound_handle_mgr.mainloop);
-    WAIT_PULSEAUDIO_OPERATION(mm_sound_handle_mgr, o);
-
-    if(o)
-        pa_operation_unref(o);
-
-    pa_threaded_mainloop_unlock(mm_sound_handle_mgr.mainloop);
-
-    return MM_ERROR_NONE;
-}
-
-EXPORT_API
 int mm_sound_pa_set_call_mute(const int type, const int mute, int direction)
 {
     pa_operation *o = NULL;
@@ -870,38 +859,6 @@ static void __mm_sound_pa_get_cb(pa_context *c, uint32_t value, void *userdata)
 
 
 EXPORT_API
-int mm_sound_pa_get_volume_max(const int type, int* step)
-{
-    get_volume_max_userdata_t userdata;
-    pa_operation *o = NULL;
-
-    CHECK_VOLUME_TYPE_RANGE(type);
-    CHECK_CONNECT_TO_PULSEAUDIO();
-
-    pa_threaded_mainloop_lock(mm_sound_handle_mgr.mainloop);
-
-    userdata.mainloop = mm_sound_handle_mgr.mainloop;
-    userdata.value = -1;
-
-    o = pa_ext_policy_get_volume_level_max(mm_sound_handle_mgr.context, type, __mm_sound_pa_get_cb, (void *)&userdata);
-    WAIT_PULSEAUDIO_OPERATION(mm_sound_handle_mgr, o);
-
-    if(userdata.value < 0) {
-        debug_error("pa_ext_policy_get_volume_level_max() failed, userdata.value(%d)", userdata.value);
-        *step = -1;
-        pa_threaded_mainloop_unlock(mm_sound_handle_mgr.mainloop);
-        return MM_ERROR_SOUND_INTERNAL;
-    } else
-        pa_operation_unref(o);
-
-    *step = userdata.value;
-
-    pa_threaded_mainloop_unlock(mm_sound_handle_mgr.mainloop);
-
-    return MM_ERROR_NONE;
-}
-
-EXPORT_API
 int mm_sound_pa_get_volume_level(int handle, const int type, int* level)
 {
     mm_sound_handle_t* phandle = NULL;
index c1f13bc..c907ef3 100644 (file)
@@ -96,10 +96,10 @@ typedef struct {
 static int _pcm_sound_start (MMSoundPcmHandle_t handle);
 static int _pcm_sound_stop_internal (MMSoundPcmHandle_t handle);
 static int _pcm_sound_stop(MMSoundPcmHandle_t handle);
-static void __sound_pcm_send_message (mm_sound_pcm_t *pcmHandle, int message, int code);
+static void _sound_pcm_send_message (mm_sound_pcm_t *pcmHandle, int message, int code);
 static int _pcm_sound_ignore_session (MMSoundPcmHandle_t handle, MMSound_session_type_e type);
 
-static char* __get_channel_str(MMSoundPcmChannel_t channel)
+static char* _get_channel_str(MMSoundPcmChannel_t channel)
 {
        if (channel == MMSOUND_PCM_MONO)
                return "Mono";
@@ -109,7 +109,7 @@ static char* __get_channel_str(MMSoundPcmChannel_t channel)
                return "Unknown";
 }
 
-static char* __get_format_str(MMSoundPcmFormat_t format)
+static char* _get_format_str(MMSoundPcmFormat_t format)
 {
        if (format == MMSOUND_PCM_S16_LE)
                return "S16LE";
@@ -237,7 +237,7 @@ static bool _check_skip_session_type_for_capture(mm_sound_pcm_t *pcmHandle, mm_s
        return ret;
 }
 
-static void __sound_pcm_send_message (mm_sound_pcm_t *pcmHandle, int message, int code)
+static void _sound_pcm_send_message (mm_sound_pcm_t *pcmHandle, int message, int code)
 {
        int ret = 0;
        if (pcmHandle->msg_cb) {
@@ -290,7 +290,7 @@ static ASM_cb_result_t sound_pcm_asm_callback(int handle, ASM_event_sources_t ev
        }
 
        /* execute user callback if callback available */
-       __sound_pcm_send_message (pcmHandle, message, event_src);
+       _sound_pcm_send_message (pcmHandle, message, event_src);
 
        return cb_res;
 }
@@ -359,6 +359,7 @@ int mm_sound_pcm_capture_open(MMSoundPcmHandle_t *handle, const unsigned int rat
 
        int volume_config = 0;
        pa_sample_spec ss;
+       char stream_type[MM_SOUND_STREAM_TYPE_LEN] = {0, };
 
        mm_sound_handle_route_info route_info;
        route_info.policy = HANDLE_ROUTE_POLICY_DEFAULT;
@@ -450,7 +451,8 @@ int mm_sound_pcm_capture_open(MMSoundPcmHandle_t *handle, const unsigned int rat
        else
                volume_config = VOLUME_TYPE_SYSTEM; //dose not effect at capture mode
 
-       pcmHandle->handle = mm_sound_pa_open(HANDLE_MODE_INPUT, &route_info, 0, volume_config, &ss, NULL, &size);
+       mm_sound_convert_volume_type_to_stream_type(volume_config, stream_type);
+       pcmHandle->handle = mm_sound_pa_open(HANDLE_MODE_INPUT, &route_info, 0, volume_config, &ss, NULL, &size, stream_type, -1);
        if(pcmHandle->handle<0) {
                result = pcmHandle->handle;
                debug_error("Device Open Error 0x%x\n", result);
@@ -487,9 +489,10 @@ int mm_sound_pcm_capture_open_ex(MMSoundPcmHandle_t *handle, const unsigned int
        pa_sample_spec ss;
        mm_sound_handle_route_info route_info;
        route_info.policy = HANDLE_ROUTE_POLICY_DEFAULT;
+       char stream_type[MM_SOUND_STREAM_TYPE_LEN] = {0, };
 
        debug_warning ("enter : rate=[%d Hz], channel=[%x][%s], format=[%x][%s], source_type=[%x]\n",
-                               rate, channel, __get_channel_str(channel), format, __get_format_str(format), source_type);
+                               rate, channel, _get_channel_str(channel), format, _get_format_str(format), source_type);
 
        if (rate < _MIN_SYSTEM_SAMPLERATE || rate > _MAX_SYSTEM_SAMPLERATE) {
                debug_error("unsupported sample rate %u", rate);
@@ -594,7 +597,13 @@ int mm_sound_pcm_capture_open_ex(MMSoundPcmHandle_t *handle, const unsigned int
        else
                volume_config = VOLUME_TYPE_SYSTEM; //dose not effect at capture mode
 
-       pcmHandle->handle = mm_sound_pa_open(HANDLE_MODE_INPUT, &route_info, 0, volume_config, &ss, NULL, &size);
+       mm_sound_convert_volume_type_to_stream_type(volume_config, stream_type);
+       if (result) {
+               debug_error("mm_sound_convert_volume_type_to_stream_type failed (0x%x)", result);
+               return result;
+       }
+
+       pcmHandle->handle = mm_sound_pa_open(HANDLE_MODE_INPUT, &route_info, 0, volume_config, &ss, NULL, &size, stream_type, -1);
        if(pcmHandle->handle<0) {
                result = pcmHandle->handle;
                debug_error("Device Open Error 0x%x\n", result);
@@ -918,11 +927,12 @@ int mm_sound_pcm_play_open_ex (MMSoundPcmHandle_t *handle, const unsigned int ra
        int ret_mutex = 0;
        mm_sound_handle_route_info route_info;
        route_info.policy = HANDLE_ROUTE_POLICY_OUT_AUTO;
+       char stream_type[MM_SOUND_STREAM_TYPE_LEN] = {0, };
 
        pa_sample_spec ss;
 
        debug_warning ("enter : rate=[%d], channel=[%x][%s], format=[%x][%s], volconf=[%d], event=[%d]\n",
-                       rate, channel, __get_channel_str(channel), format, __get_format_str(format), volume_config, asm_event);
+                       rate, channel, _get_channel_str(channel), format, _get_format_str(format), volume_config, asm_event);
 
        /* Check input param */
        if (volume_type < 0 || volume_type >= VOLUME_TYPE_MAX) {
@@ -1024,7 +1034,8 @@ int mm_sound_pcm_play_open_ex (MMSoundPcmHandle_t *handle, const unsigned int ra
 
 
        /* Open */
-       pcmHandle->handle = mm_sound_pa_open(HANDLE_MODE_OUTPUT, &route_info, 0, volume_config, &ss, NULL, &size);
+       mm_sound_convert_volume_type_to_stream_type(volume_type, stream_type);
+       pcmHandle->handle = mm_sound_pa_open(HANDLE_MODE_OUTPUT, &route_info, 0, volume_config, &ss, NULL, &size, stream_type, -1);
        if(!pcmHandle->handle) {
                debug_error("Device Open Error 0x%x\n");
                result = MM_ERROR_SOUND_DEVICE_NOT_OPENED;
index 151080a..f2c102d 100644 (file)
@@ -964,11 +964,10 @@ int mm_sound_pcm_play_write_async(MMSoundPcmHandle_t handle, void* ptr, unsigned
 #endif
        /* Write */
 
-    ret = pa_stream_write(pcmHandle->s, ptr, length_byte, NULL, 0LL, PA_SEEK_RELATIVE);
+       ret = pa_stream_write(pcmHandle->s, ptr, length_byte, NULL, 0LL, PA_SEEK_RELATIVE);
        if (ret == 0) {
                ret = length_byte;
        }
-
 EXIT:
 //     PCM_UNLOCK_INTERNAL(&pcmHandle->pcm_mutex_internal);
 NULL_HANDLE:
@@ -1288,7 +1287,6 @@ static const pa_tizen_volume_type_t mm_sound_volume_type_to_pa[VOLUME_TYPE_MAX]
        [VOLUME_TYPE_CALL] = PA_TIZEN_VOLUME_TYPE_CALL,
        [VOLUME_TYPE_VOIP] = PA_TIZEN_VOLUME_TYPE_VOIP,
        [VOLUME_TYPE_FIXED] = PA_TIZEN_VOLUME_TYPE_FIXED,
-//     [VOLUME_TYPE_EXT_SYSTEM_JAVA] = PA_TIZEN_VOLUME_TYPE_EXT_JAVA,
 };
 
 static int mm_sound_pa_open(mm_sound_pcm_async_t* handle, int is_capture, int policy, int priority, int volume_config, pa_sample_spec* ss,
index 83cf43e..b7fc2a0 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-sound
 Summary:    MMSound Package contains client lib and sound_server binary
-Version:    0.9.185
+Version:    0.9.237
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
@@ -19,9 +19,10 @@ BuildRequires: pkgconfig(gio-2.0)
 BuildRequires: pkgconfig(vconf)
 BuildRequires: pkgconfig(libpulse)
 BuildRequires: pkgconfig(iniparser)
-%ifarch %{arm}
+%if "%{?tizen_profile_name}" != "tv"
+BuildRequires: pkgconfig(capi-network-bluetooth)
 %endif
-%if "%{?tizen_profile_name}" == "wearable"
+%ifarch %{arm}
 %endif
 BuildRequires: pkgconfig(libtremolo)
 
@@ -58,40 +59,35 @@ MMSound utility package - contians mm_sound_testsuite, sound_check for sound sys
 
 %build
 %define tizen_audio_feature_ogg_enable 1
-%define tizen_audio_feature_bluetooth_enable 1
 
-%if "%{?tizen_profile_name}" == "wearable"
-%define tizen_audio_feature_hfp 1
-%else if
-%define tizen_audio_feature_hfp 0
+%if "%{?tizen_profile_name}" == "tv"
+%define tizen_audio_feature_bluetooth_enable 0
+%else
+%define tizen_audio_feature_bluetooth_enable 1
 %endif
 
 %ifarch %{arm}
-       CFLAGS="%{optflags} -fvisibility=hidden -D_TIZEN_PUBLIC_ -DMM_DEBUG_FLAG -DEXPORT_API=\"__attribute__((visibility(\\\"default\\\")))\"" ;export CFLAGS
+       CFLAGS="%{optflags} -fvisibility=hidden -DSUPPORT_CONTAINER -D_TIZEN_PUBLIC_ -DUSE_FOCUS -DMM_DEBUG_FLAG -DEXPORT_API=\"__attribute__((visibility(\\\"default\\\")))\"" ;export CFLAGS
 %else
-       CFLAGS="%{optflags} -fvisibility=hidden -D_TIZEN_PUBLIC_ -DMM_DEBUG_FLAG -DEXPORT_API=\"__attribute__((visibility(\\\"default\\\")))\"" ;export CFLAGS
+       CFLAGS="%{optflags} -fvisibility=hidden -DSUPPORT_CONTAINER -D_TIZEN_PUBLIC_ -DUSE_FOCUS -DMM_DEBUG_FLAG -DEXPORT_API=\"__attribute__((visibility(\\\"default\\\")))\"" ;export CFLAGS
 %endif
 
 %if "%{?tizen_profile_name}" == "wearable"
        CFLAGS+=" -DTIZEN_MICRO";export CFLAGS
-%else if "%{?tizen_profile_name}" == "mobile"
+%endif
+%if "%{?tizen_profile_name}" == "tv"
+        CFLAGS+=" -DTIZEN_TV";export CFLAGS
 %endif
 
 ./autogen.sh
 %configure \
-%if 0%{?tizen_audio_feature_hfp}
-       --enable-hfp \
-%endif
 %if 0%{?tizen_audio_feature_ogg_enable}
        --enable-ogg \
 %endif
-%if 0%{?tizen_audio_feature_bluetooth_enable}
-       --disable-bluetooth \
-%endif
 %ifarch %{arm}
-       --prefix=/usr --enable-pulse
+       --prefix=/usr --enable-pulse --enable-focus --disable-security
 %else
-       --prefix=/usr --enable-pulse
+       --prefix=/usr --enable-pulse --enable-focus --disable-security
 %endif
 
 make %{?_smp_mflags}
@@ -113,35 +109,20 @@ ln -sf ../sound-server.path %{buildroot}%{_unitdir}/multi-user.target.wants/soun
 %post
 /sbin/ldconfig
 
-/usr/bin/vconftool set -t int memory/private/Sound/ASMReady 0 -g 29 -f -i
-/usr/bin/vconftool set -t double file/private/sound/volume/balance 0.0 -g 29 -f -s User
-/usr/bin/vconftool set -t int file/private/sound/volume/muteall 0 -g 29 -f -s User
-/usr/bin/vconftool set -t int memory/private/Sound/VoiceControlOn 0 -g 29 -f -i
-/usr/bin/vconftool set -t string memory/private/sound/booting "/usr/share/keysound/poweron.wav" -g 29 -f -i
-#SPK REC EAR BTS BTA DOCK HDMI MIR USB MDOCK
-#/usr/bin/vconftool set -t string file/private/sound/volume/system "09090909090909090909" -g 29 -f
-#/usr/bin/vconftool set -t string file/private/sound/volume/notification "11" -g 29 -f
-#/usr/bin/vconftool set -t string file/private/sound/volume/alarm "7" -g 29 -f
-#/usr/bin/vconftool set -t string file/private/sound/volume/ringtone "11" -g 29 -f
-#/usr/bin/vconftool set -t string file/private/sound/volume/media "07070907070707070707" -g 29 -f
-#/usr/bin/vconftool set -t string file/private/sound/volume/call "04040404040404040404" -g 29 -f
-#/usr/bin/vconftool set -t string file/private/sound/volume/voip "04040404040404040404" -g 29 -f
-#/usr/bin/vconftool set -t string file/private/sound/volume/voice "07070707070707070707" -g 29 -f
-#/usr/bin/vconftool set -t string file/private/sound/volume/fixed "00000000000000000000" -g 29 -f
-/usr/bin/vconftool set -t int memory/private/sound/PrimaryVolumetypeForce -1 -g 29 -f -i
-/usr/bin/vconftool set -t int memory/private/sound/PrimaryVolumetype -1 -g 29 -f -i
-/usr/bin/vconftool set -t int memory/private/sound/hdmisupport 0 -g 29 -f -i
-/usr/bin/vconftool set -t int memory/factory/loopback 0 -g 29 -f -i
-
-/usr/bin/vconftool set -t int file/private/sound/volume/system 9 -g 29 -f -s User
-/usr/bin/vconftool set -t int file/private/sound/volume/notification 11 -g 29 -f -s User
-/usr/bin/vconftool set -t int file/private/sound/volume/alarm 7 -g 29 -f -s User
-/usr/bin/vconftool set -t int file/private/sound/volume/ringtone 11 -g 29 -f -s User
-/usr/bin/vconftool set -t int file/private/sound/volume/media 7 -g 29 -f -s User
-/usr/bin/vconftool set -t int file/private/sound/volume/call 4 -g 29 -f -s User
-/usr/bin/vconftool set -t int file/private/sound/volume/voip 4 -g 29 -f -s User
-/usr/bin/vconftool set -t int file/private/sound/volume/voice 7 -g 29 -f -s User
-/usr/bin/vconftool set -t int file/private/sound/volume/fixed 0 -g 29 -f -s User
+/usr/bin/vconftool set -t int memory/private/Sound/ASMReady 0 -g 29 -f -i -s system::vconf_multimedia
+/usr/bin/vconftool set -t int memory/private/Sound/VoiceControlOn 0 -g 29 -f -i -s system::vconf_multimedia
+/usr/bin/vconftool set -t string memory/private/sound/booting "/usr/share/keysound/poweron.wav" -g 29 -f -i -s system::vconf_multimedia
+/usr/bin/vconftool set -t int memory/private/sound/PrimaryVolumetypeForce -1 -g 29 -f -i -s system::vconf_multimedia
+/usr/bin/vconftool set -t int memory/private/sound/PrimaryVolumetype -1 -g 29 -f -i -s system::vconf_multimedia
+
+/usr/bin/vconftool set -t int file/private/sound/volume/system 9 -g 29 -f -s system::vconf_multimedia
+/usr/bin/vconftool set -t int file/private/sound/volume/notification 11 -g 29 -f -s system::vconf_multimedia
+/usr/bin/vconftool set -t int file/private/sound/volume/alarm 7 -g 29 -f -s system::vconf_multimedia
+/usr/bin/vconftool set -t int file/private/sound/volume/ringtone 11 -g 29 -f -s system::vconf_multimedia
+/usr/bin/vconftool set -t int file/private/sound/volume/media 7 -g 29 -f -s system::vconf_multimedia
+/usr/bin/vconftool set -t int file/private/sound/volume/call 4 -g 29 -f -s system::vconf_multimedia
+/usr/bin/vconftool set -t int file/private/sound/volume/voip 4 -g 29 -f -s system::vconf_multimedia
+/usr/bin/vconftool set -t int file/private/sound/volume/voice 7 -g 29 -f -s system::vconf_multimedia
 
 
 %postun -p /sbin/ldconfig
@@ -150,7 +131,7 @@ ln -sf ../sound-server.path %{buildroot}%{_unitdir}/multi-user.target.wants/soun
 %files
 %manifest libmm-sound.manifest
 %defattr(-,root,root,-)
-%{_bindir}/sound_server
+%caps(cap_chown,cap_dac_override,cap_fowner,cap_mac_override,cap_lease=eip) %{_bindir}/sound_server
 %{_libdir}/libmmfsound.so.*
 %{_libdir}/libmmfsoundcommon.so.*
 %{_libdir}/libmmfkeysound.so.*
@@ -189,6 +170,7 @@ ln -sf ../sound-server.path %{buildroot}%{_unitdir}/multi-user.target.wants/soun
 %defattr(-,root,root,-)
 %{_includedir}/mmf/mm_sound.h
 %{_includedir}/mmf/mm_sound_pcm_async.h
+%{_includedir}/mmf/mm_sound_focus.h
 %exclude %{_includedir}/mmf/mm_sound_pa_client.h
 %{_libdir}/pkgconfig/mm-keysound.pc
 %{_libdir}/pkgconfig/mm-bootsound.pc
index 97ce14e..d1052a4 100644 (file)
@@ -2,6 +2,9 @@
 Description=Start the sound profile service
 
 [Service]
+User=system
+Group=system
+SmackProcessLabel=sound_server
 ExecStart=/usr/bin/sound_server -S
 Restart=always
 RestartSec=0
index ba383f3..405ce50 100644 (file)
@@ -3,6 +3,7 @@ SUBDIRS = plugin
 bin_PROGRAMS = sound_server
 sound_server_SOURCES = mm_sound_mgr_codec.c \
                                                mm_sound_mgr_ipc.c \
+                                               mm_sound_mgr_ipc_dbus.c \
                                                mm_sound_mgr_pulse.c \
                                                mm_sound_mgr_asm.c \
                                                mm_sound_mgr_device.c \
@@ -42,19 +43,20 @@ sound_server_LDADD = $(MMLOGSVR_LIBS) \
                     $(srcdir)/../libmmfsound.la \
                     $(srcdir)/../common/libmmfsoundcommon.la
 
-sound_server_CFLAGS += $(BLUETOOTH_API_CFLAGS)
-sound_server_LDADD += $(BLUETOOTH_API_LIBS)
-
-if SUPPORT_BT_SCO
-sound_server_CFLAGS += $(BLUETOOTH_CFLAGS)
-sound_server_LDADD += $(BLUETOOTH_LIBS)
-endif
-
 if USE_PULSE
 sound_server_CFLAGS += -DPULSE_CLIENT $(PA_CFLAGS) $(PASIMPLE_CFLAGS)
 sound_server_LDADD += $(PA_LIBS) $(PASIMPLE_CFLAGS)
 endif
 
+if USE_SECURITY
+sound_server_CFLAGS += $(SECURITY_CFLAGS) -DUSE_SECURITY
+sound_server_LDADD += $(SECURITY_LIBS)
+endif
+
+if USE_FOCUS
+sound_server_SOURCES += mm_sound_mgr_focus.c
+endif
+
 sound_server_DEPENDENCIES = $(srcdir)/../common/libmmfsoundcommon.la
 sound_server_CFLAGS += -fPIC -pie
 installsounddir = $(prefix)/share/sounds/sound-server
index 3bd9f94..d07471d 100644 (file)
 int MMSoundMgrASMInit(void);
 int MMSoundMgrASMFini(void);
 
+int _mm_sound_mgr_asm_register_sound(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state, int rcv_resource,
+                                     int *snd_pid, int *snd_alloc_handle, int *snd_cmd_handle, int *snd_request_id, int *snd_sound_command, int *snd_sound_state);
+int _mm_sound_mgr_asm_unregister_sound(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state, int rcv_resource);
+int _mm_sound_mgr_asm_register_watcher(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state, int rcv_resource,
+                                       int *snd_pid, int *snd_alloc_handle, int *snd_cmd_handle, int *snd_request_id, int *snd_sound_command, int *snd_sound_state);
+int _mm_sound_mgr_asm_unregister_watcher(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state, int rcv_resource);
+int _mm_sound_mgr_asm_get_mystate(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state, int rcv_resource,
+                                  int *snd_pid, int *snd_alloc_handle, int *snd_cmd_handle, int *snd_request_id, int *snd_sound_state);
+int _mm_sound_mgr_asm_set_state(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state, int rcv_resource,
+                               int *snd_pid, int *snd_alloc_handle, int *snd_cmd_handle, int *snd_request_id, int *snd_sound_command, int *snd_sound_state, int *snd_error_code);
+int _mm_sound_mgr_asm_get_state(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state, int rcv_resource,
+                               int *snd_pid, int *snd_alloc_handle, int *snd_cmd_handle, int *snd_request_id, int *snd_sound_state);
+int _mm_sound_mgr_asm_set_subsession(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state, int rcv_resource,
+                                     int *snd_pid, int *snd_alloc_handle, int *snd_cmd_handle, int *snd_request_id);
+int _mm_sound_mgr_asm_get_subsession(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state, int rcv_resource,
+                                     int *snd_pid, int *snd_alloc_handle, int *snd_cmd_handle, int *snd_request_id, int *snd_sound_command);
+int _mm_sound_mgr_asm_set_subevent(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state, int rcv_resource,
+                                   int *snd_pid, int *snd_alloc_handle, int *snd_cmd_handle, int *snd_request_id, int *snd_sound_command, int *snd_sound_state);
+int _mm_sound_mgr_asm_get_subevent(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state, int rcv_resource,
+                                   int *snd_pid, int *snd_alloc_handle, int *snd_cmd_handle, int *snd_request_id, int *snd_sound_command);
+int _mm_sound_mgr_asm_set_session_option(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state, int rcv_resource,
+                                         int *snd_pid, int *snd_alloc_handle, int *snd_cmd_handle, int *snd_request_id, int *snd_sound_command, int *snd_error_code);
+int _mm_sound_mgr_asm_get_session_option(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state, int rcv_resource,
+                                         int *snd_pid, int *snd_alloc_handle, int *snd_cmd_handle, int *snd_request_id, int *snd_sound_command, int *snd_option_flag);
+int _mm_sound_mgr_asm_reset_resume_tag(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state, int rcv_resource,
+                                       int *snd_pid, int *snd_alloc_handle, int *snd_cmd_handle, int *snd_request_id, int *snd_sound_command, int *snd_sound_state);
+int _mm_sound_mgr_asm_dump(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state, int rcv_resource);
+int _mm_sound_mgr_asm_emergent_exit(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state);
+
 int __asm_process_message (void *asm_rcv_msg, void *asm_ret_msg);
 
+#ifdef SUPPORT_CONTAINER
+void _mm_sound_mgr_asm_update_container_data(int instance_id, const char* container_name, int container_pid);
+#endif
 
 #endif /* __MM_SOUND_MGR_ASM_H__ */
 
index 549d47d..1e79ae2 100644 (file)
@@ -45,6 +45,8 @@ typedef struct {
        int priority;
        int handle_route;
        bool enable_session;
+       char stream_type[MM_SOUND_STREAM_TYPE_LEN];
+       int stream_index;
 } mmsound_mgr_codec_param_t;
 
 enum
@@ -57,10 +59,12 @@ int MMSoundMgrCodecInit(const char *targetdir);
 int MMSoundMgrCodecFini(void);
 
 int MMSoundMgrCodecPlay(int *slotid, const mmsound_mgr_codec_param_t *param);
+int MMSoundMgrCodecPlayWithStreamInfo(int *slotid, const mmsound_mgr_codec_param_t *param);
 int MMSoundMgrCodecStop(const int slotid);
 int MMSoundMgrCodecCreate(int *slotid, const mmsound_mgr_codec_param_t *param);
 int MMSoundMgrCodecPlayWave(int slotid, const mmsound_mgr_codec_param_t *param);
 int MMSoundMgrCodecPlayDtmf(int *slotid, const mmsound_mgr_codec_param_t *param);
+int MMSoundMgrCodecPlayDtmfWithStreamInfo(int *slotid, const mmsound_mgr_codec_param_t *param);
 int MMSoundMgrCodecDestroy(const int slotid);
 
 
index e5f16ec..5daf64d 100644 (file)
@@ -23,6 +23,7 @@
 #ifndef __MM_SOUND_MGR_DEVICE_H__
 #define __MM_SOUND_MGR_DEVICE_H__
 
+#if 0
 #include "../include/mm_sound.h"
 #include "../include/mm_sound_device.h"
 #include "../include/mm_ipc.h"
@@ -56,22 +57,15 @@ int _mm_sound_mgr_device_init(void);
 int _mm_sound_mgr_device_fini(void);
 int _mm_sound_mgr_device_is_route_available(const _mm_sound_mgr_device_param_t *param, bool *is_available);
 int _mm_sound_mgr_device_foreach_available_route_cb(mm_ipc_msg_t *msg);
-int _mm_sound_mgr_device_set_active_route(const _mm_sound_mgr_device_param_t *param);
-int _mm_sound_mgr_device_get_active_device(const _mm_sound_mgr_device_param_t *param, mm_sound_device_in *device_in, mm_sound_device_out *device_out);
-int _mm_sound_mgr_device_add_active_device_callback(const _mm_sound_mgr_device_param_t *param);
-int _mm_sound_mgr_device_remove_active_device_callback(const _mm_sound_mgr_device_param_t *param);
 int _mm_sound_mgr_device_active_device_callback(mm_sound_device_in device_in, mm_sound_device_out device_out);
-int _mm_sound_mgr_device_add_available_route_callback(const _mm_sound_mgr_device_param_t *param);
-int _mm_sound_mgr_device_remove_available_route_callback(const _mm_sound_mgr_device_param_t *param);
 int _mm_sound_mgr_device_available_device_callback(mm_sound_device_in device_in, mm_sound_device_out device_out, bool available);
 int _mm_sound_mgr_device_get_volume_value_by_active_device(char *buf, mm_sound_device_out device_out, unsigned int *value);
 int _mm_sound_mgr_device_set_volume_value_by_active_device(char *buf, mm_sound_device_out device_out, int value);
-int _mm_sound_mgr_device_set_active_route_auto(void);
 int _mm_sound_mgr_device_set_sound_path_for_active_device(mm_sound_device_out playback, mm_sound_device_in capture);
 int _mm_sound_mgr_device_add_volume_callback(const _mm_sound_mgr_device_param_t *param);
 int _mm_sound_mgr_device_remove_volume_callback(const _mm_sound_mgr_device_param_t *param);
 int _mm_sound_mgr_device_get_audio_path(mm_sound_device_in *device_in, mm_sound_device_out *device_out);
-int _mm_sound_mgr_device_get_current_connected_dev_list(const _mm_sound_mgr_device_param_t *param, GList **device_list);
+int _mm_sound_mgr_device_get_current_connected_dev_list(int device_flags, mm_sound_device_t **device_list, int *dev_num);
 int _mm_sound_mgr_device_add_connected_callback(const _mm_sound_mgr_device_param_t *param);
 int _mm_sound_mgr_device_remove_connected_callback(const _mm_sound_mgr_device_param_t *param);
 int _mm_sound_mgr_device_add_info_changed_callback(const _mm_sound_mgr_device_param_t *param);
@@ -80,5 +74,6 @@ int MMSoundMgrDeviceGetIoDirectionById (int id, device_io_direction_e *io_direct
 int MMSoundMgrDeviceUpdateStatus (device_update_status_e update_status, device_type_e device_type, device_io_direction_e io_direction, int id, const char* name, device_state_e state, int *alloc_id);
 int MMSoundMgrDeviceUpdateStatusWithoutNotification (device_update_status_e update_status, device_type_e device_type, device_io_direction_e io_direction, int id, const char* name, device_state_e state, int *alloc_id);
 
+#endif
 #endif /* __MM_SOUND_MGR_DEVICE_H__ */
 
index 7f53bc1..c7f9a13 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "../../include/mm_ipc.h"
 
+#if 0
 typedef enum
 {
        DOCK_NONE      = 0,
@@ -35,6 +36,7 @@ typedef enum
 
 int MMSoundMgrDockInit(void);
 int MMSoundMgrDockFini(void);
+#endif
 
 
 #endif /* __MM_SOUND_MGR_DOCK_H__ */
index 84d56dd..73403cc 100644 (file)
 #ifndef __MM_SOUND_MGR_HDMI_H__
 #define __MM_SOUND_MGR_HDMI_H__
 
+#if 0
 int MMSoundMgrHdmiInit(void);
 int MMSoundMgrHdmiFini(void);
+#endif
 
 
 #endif /* __MM_SOUND_MGR_HDMI_H__ */
index 5db2105..c20f694 100644 (file)
 
 #include "../../include/mm_ipc.h"
 
+#if 0
 int MMSoundMgrHeadsetInit(void);
 int MMSoundMgrHeadsetFini(void);
+#endif
 
 #endif /* __MM_SOUND_MGR_HEADSET_H__ */
 
index e4d7365..14f30ed 100644 (file)
 #ifndef __MM_SOUND_MGR_WFD_H__
 #define __MM_SOUND_MGR_WFD_H__
 
+#if 0
 int MMSoundMgrWfdInit(void);
 int MMSoundMgrWfdFini(void);
+#endif
 
 
 #endif /* __MM_SOUND_MGR_WFD_H__ */
diff --git a/server/include/mm_sound_mgr_focus.h b/server/include/mm_sound_mgr_focus.h
new file mode 100644 (file)
index 0000000..941d056
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * libmm-sound
+ *
+ * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Sangchul Lee <sc11.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __MM_SOUND_MGR_FOCUS_H__
+#define __MM_SOUND_MGR_FOCUS_H__
+
+#include "../include/mm_sound.h"
+#include "../include/mm_sound_focus.h"
+#include "../include/mm_sound_stream.h"
+#include "../include/mm_ipc.h"
+#include "mm_sound_mgr_ipc.h"
+
+typedef enum
+{
+       FOCUS_COMMAND_RELEASE,
+       FOCUS_COMMAND_ACQUIRE,
+} focus_command_e;
+
+typedef enum
+{
+       FOCUS_TYPE_PLAYBACK = 1,
+       FOCUS_TYPE_CAPTURE,
+       FOCUS_TYPE_BOTH,
+} focus_type_e;
+
+typedef enum
+{
+       FOCUS_STATUS_DEACTIVATED,
+       FOCUS_STATUS_ACTIVATED_PLAYBACK,
+       FOCUS_STATUS_ACTIVATED_CAPTURE,
+       FOCUS_STATUS_ACTIVATED_BOTH,
+} focus_status_e;
+
+typedef struct {
+       int pid;
+       int handle_id;
+       char stream_type[MAX_STREAM_TYPE_LEN];
+       char option[MM_SOUND_NAME_NUM];
+       focus_type_e request_type;
+       void *callback;
+       void *cbdata;
+} _mm_sound_mgr_focus_param_t;
+
+typedef struct _taken_by_id
+{
+       int pid;
+       int handle_id;
+} _focus_taken_by_id_t;
+
+typedef struct {
+       int pid;
+       int handle_id;
+       int priority;
+       bool is_for_watch;
+       char stream_type[MAX_STREAM_TYPE_LEN];
+       focus_status_e status;
+       _focus_taken_by_id_t taken_by_id[NUM_OF_STREAM_IO_TYPE];
+       void *callback;
+       void *cbdata;
+
+#ifdef SUPPORT_CONTAINER
+       container_info_t container;
+#endif
+} focus_node_t;
+
+int MMSoundMgrFocusInit(void);
+int MMSoundMgrFocusFini(void);
+int mm_sound_mgr_focus_create_node (const _mm_sound_mgr_focus_param_t *param);
+int mm_sound_mgr_focus_destroy_node (const _mm_sound_mgr_focus_param_t *param);
+int mm_sound_mgr_focus_request_acquire (const _mm_sound_mgr_focus_param_t *param);
+int mm_sound_mgr_focus_request_release (const _mm_sound_mgr_focus_param_t *param);
+int mm_sound_mgr_focus_set_watch_cb (const _mm_sound_mgr_focus_param_t *param);
+int mm_sound_mgr_focus_unset_watch_cb (const _mm_sound_mgr_focus_param_t *param);
+
+
+#endif /* __MM_SOUND_MGR_FOCUS_H__ */
+
index d087b6e..ba62808 100644 (file)
@@ -36,12 +36,129 @@ do { \
 #define FREEZE_COMMAND_INCLUDE "include"
 #define FREEZE_COMMAND_WAKEUP  "wakeup"
 
+#ifdef SUPPORT_CONTAINER
+typedef struct container_info
+{
+       int pid;
+       char name[64];
+} container_info_t;
+#endif
+
 int MMSoundMgrIpcInit(void);
 int MMSoundMgrIpcFini(void);
-int MMSoundMgrIpcReady(void);
 
+/* Msg processing */
+int _MMSoundMgrIpcPlayFile(char* filename, int tone, int repeat, int volume, int volume_config,
+                          int priority, int session_type, int session_options, int client_pid, int keytone,  int handle_route,
+                          gboolean enable_session, int *codechandle, char *stream_type, int stream_index);
+int _MMSoundMgrIpcPlayFileWithStreamInfo(char* filename, int repeat, int volume,
+                          int priority, int client_pid, int handle_route, int *codechandle, char *stream_type, int stream_index);
+//int _MMSoundMgrIpcStop(mm_ipc_msg_t *msg);
+int _MMSoundMgrIpcStop(int handle);
+//int _MMSoundMgrIpcPlayDTMF(int *codechandle, mm_ipc_msg_t *msg);
+int _MMSoundMgrIpcPlayDTMF(int tone, int repeat, int volume, int volume_config,
+                          int session_type, int session_options, int client_pid,
+                          gboolean enable_session, int *codechandle, char *stream_type, int stream_index);
+int _MMSoundMgrIpcPlayDTMFWithStreamInfo(int tone, int repeat, int volume, int client_pid, int *codechandle, char *stream_type, int stream_index);
+
+/*
+int _MMSoundMgrIpcPlayMemory(int *codechandle, mm_ipc_msg_t *msg);
+int __mm_sound_mgr_ipc_is_route_available(mm_ipc_msg_t *msg, bool *is_available);
+int __mm_sound_mgr_ipc_foreach_available_route_cb(mm_ipc_msg_t *msg);
+int __mm_sound_mgr_ipc_set_active_route(mm_ipc_msg_t *msg);
+int __mm_sound_mgr_ipc_set_active_route_auto(void);
+int __mm_sound_mgr_ipc_get_active_device(mm_ipc_msg_t *msg, mm_sound_device_in *device_in, mm_sound_device_out *device_out);
+int __mm_sound_mgr_ipc_add_active_device_changed_cb(mm_ipc_msg_t *msg);
+int __mm_sound_mgr_ipc_remove_active_device_changed_cb(mm_ipc_msg_t *msg);
+int __mm_sound_mgr_ipc_add_available_device_changed_cb(mm_ipc_msg_t *msg);
+int __mm_sound_mgr_ipc_remove_available_device_changed_cb(mm_ipc_msg_t *msg);
+*/
+int __mm_sound_mgr_ipc_set_sound_path_for_active_device(mm_sound_device_in _device_in, mm_sound_device_out _device_out);
+int __mm_sound_mgr_ipc_get_audio_path(mm_sound_device_in *device_in, mm_sound_device_out *device_out);
+//int __mm_sound_mgr_ipc_get_current_connected_device_list(mm_ipc_msg_t *msg, GList **device_list, int *total_num);
+int __mm_sound_mgr_ipc_get_current_connected_device_list(int device_flags, mm_sound_device_t **device_list, int *total_num);
+#ifdef USE_FOCUS
+//int __mm_sound_mgr_ipc_create_focus_node(mm_ipc_msg_t *msg);
+#ifdef SUPPORT_CONTAINER
+int __mm_sound_mgr_ipc_register_focus(int client_pid, int handle_id, char* stream_type ,const char* container_name, int container_pid);
+#else
+int __mm_sound_mgr_ipc_register_focus(int client_pid, int handle_id, char* stream_type);
+#endif
+//int __mm_sound_mgr_ipc_destroy_focus_node(mm_ipc_msg_t *msg);
+int __mm_sound_mgr_ipc_unregister_focus(int pid, int handle_id);
+
+int __mm_sound_mgr_ipc_acquire_focus(int pid, int handle_id, int focus_type, const char* name );
+
+int __mm_sound_mgr_ipc_release_focus(int pid, int handle_id, int focus_type, const char* name);
+//int __mm_sound_mgr_ipc_set_focus_watch_cb(mm_ipc_msg_t *msg);
+#ifdef SUPPORT_CONTAINER
+int __mm_sound_mgr_ipc_watch_focus(int pid, int handle_id, int focus_type, const char* container_name, int container_pid);
+#else
+int __mm_sound_mgr_ipc_watch_focus(int pid, int handle_id, int focus_type);
+#endif
+//int __mm_sound_mgr_ipc_unset_focus_watch_cb(mm_ipc_msg_t *msg);
+int __mm_sound_mgr_ipc_unwatch_focus(int pid, int handle_id);
+#endif
+int __mm_sound_mgr_ipc_asm_register_sound(int pid, int handle, int sound_event, int request_id, int sound_state, int resource,
+#ifdef SUPPORT_CONTAINER
+                                               const char* container_name, int container_pid,
+#endif
+                                         int* pid_r, int* alloc_handle_r, int* cmd_handle_r,
+                                         int* request_id_r, int* sound_command_r, int* sound_state_r );
+int __mm_sound_mgr_ipc_asm_unregister_sound(int pid, int handle, int sound_event, int request_id, int sound_state, int resource);
+int __mm_sound_mgr_ipc_asm_register_watcher(int pid, int handle, int sound_event, int request_id, int sound_state, int resource,
+#ifdef SUPPORT_CONTAINER
+                                               const char* container_name, int container_pid,
+#endif
+                                           int* pid_r, int* alloc_handle_r, int* cmd_handle_r,
+                                           int* request_id_r, int* sound_cmd_r, int* sound_state_r );
+int __mm_sound_mgr_ipc_asm_unregister_watcher(int pid, int handle, int sound_event, int request_id, int sound_state, int resource);
+int __mm_sound_mgr_ipc_asm_get_mystate(int pid, int handle, int sound_event, int request_id, int sound_state, int resource,
+                                           int* pid_r, int* alloc_handle_r, int* cmd_handle_r,
+                                           int* request_id_r, int* sound_state_r );
+int __mm_sound_mgr_ipc_asm_set_state(int pid, int handle, int sound_event, int request_id, int sound_state, int resource,
+                                           int* pid_r, int* alloc_handle_r, int* cmd_handle_r,
+                                           int* request_id_r, int* sound_command_r, int* sound_state_r , int* error_code_r);
+int __mm_sound_mgr_ipc_asm_get_state(int pid, int handle, int sound_event, int request_id, int sound_state, int resource,
+                                           int* pid_r, int* alloc_handle_r, int* cmd_handle_r,
+                                           int* request_id_r, int* sound_state_r );
+int __mm_sound_mgr_ipc_asm_set_subsession(int pid, int handle, int sound_event, int request_id, int sound_state, int resource,
+                                           int* pid_r, int* alloc_handle_r, int* cmd_handle_r, int* request_id_r);
+int __mm_sound_mgr_ipc_asm_get_subsession(int pid, int handle, int sound_event, int request_id, int sound_state, int resource,
+                                           int* pid_r, int* alloc_handle_r, int* cmd_handle_r, int* request_id_r, int* sound_command_r);
+
+int __mm_sound_mgr_ipc_asm_set_subevent(int pid, int handle, int sound_event, int request_id, int sound_state, int resource,
+                                           int* pid_r, int* alloc_handle_r, int* cmd_handle_r,
+                                           int* request_id_r, int* sound_cmd_r, int* sound_state_r );
+int __mm_sound_mgr_ipc_asm_get_subevent(int pid, int handle, int sound_event, int request_id, int sound_state, int resource,
+                                           int* pid_r, int* alloc_handle_r, int* cmd_handle_r,
+                                           int* request_id_r, int* sound_cmd_r);
+int __mm_sound_mgr_ipc_asm_set_session_option(int pid, int handle, int sound_event, int request_id, int sound_state, int resource,
+                                           int* pid_r, int* alloc_handle_r, int* cmd_handle_r,
+                                           int* request_id_r, int* sound_cmd_r, int* error_code_r );
+int __mm_sound_mgr_ipc_asm_get_session_option(int pid, int handle, int sound_event, int request_id, int sound_state, int resource,
+                                           int* pid_r, int* alloc_handle_r, int* cmd_handle_r,
+                                           int* request_id_r, int* sound_cmd_r, int* option_flag_r );
+int __mm_sound_mgr_ipc_asm_reset_resume_tag(int pid, int handle, int sound_event, int request_id, int sound_state, int resource,
+                                           int* pid_r, int* alloc_handle_r, int* cmd_handle_r,
+                                           int* request_id_r, int* sound_cmd_r, int* sound_state_r );
+int __mm_sound_mgr_ipc_asm_dump(int pid, int handle, int sound_event, int request_id, int sound_state, int resource);
+int __mm_sound_mgr_ipc_asm_emergent_exit(int pid, int handle, int sound_event, int request_id, int sound_state);
+
+
+/* send signal : mgr_xxx -> mgr_ipc_dbus */
 int _MMIpcCBSndMsg(mm_ipc_msg_t *msg);
+int _MMIpcCBRecvMsg(mm_ipc_msg_t *msg);
+int _MMIpcCBMsgEnQueueAgain(mm_ipc_msg_t *msg);
+
 int __mm_sound_mgr_ipc_freeze_send (char* command, int pid);
 
+int __mm_sound_mgr_ipc_notify_play_file_end (int handle);
+int __mm_sound_mgr_ipc_notify_device_connected (mm_sound_device_t *device, gboolean is_connected);
+int __mm_sound_mgr_ipc_notify_device_info_changed (mm_sound_device_t *device, int changed_device_info_type);
+int __mm_sound_mgr_ipc_notify_volume_changed(unsigned int vol_type, unsigned int value);
+int __mm_sound_mgr_ipc_notify_active_device_changed(int device_in, int device_out);
+int __mm_sound_mgr_ipc_notify_available_device_changed(int device_in, int device_out, int available);
+
 #endif /* __MM_SOUND_MGR_H__ */
 
diff --git a/server/include/mm_sound_mgr_ipc_dbus.h b/server/include/mm_sound_mgr_ipc_dbus.h
new file mode 100644 (file)
index 0000000..6ff3c97
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef __MM_SOUND_MGR_IPC_DBUS_H__
+#define __MM_SOUND_MGR_IPC_DBUS_H__
+
+#include <gio/gio.h>
+#include "../include/mm_sound_device.h"
+#include "../include/mm_sound_stream.h"
+
+
+int mm_sound_mgr_ipc_dbus_send_signal_freeze (char* command, int pid);
+
+int __mm_sound_mgr_ipc_dbus_notify_play_file_end(int handle);
+int __mm_sound_mgr_ipc_dbus_notify_device_connected (mm_sound_device_t *device, gboolean is_connected);
+int __mm_sound_mgr_ipc_dbus_notify_device_info_changed (mm_sound_device_t *device, int changed_device_info_type);
+int __mm_sound_mgr_ipc_dbus_notify_volume_changed(unsigned int vol_type, unsigned int value);
+int __mm_sound_mgr_ipc_dbus_notify_active_device_changed(int device_in, int device_out);
+int __mm_sound_mgr_ipc_dbus_notify_available_device_changed(int device_in, int device_out, int available);
+int __mm_sound_mgr_ipc_dbus_get_stream_list(stream_list_t* stream_list);
+
+int MMSoundMgrDbusInit(void);
+void MMSoundMgrDbusFini(void);
+
+
+#endif /* __MM_SOUND_MGR_DBUS_H__ */
diff --git a/server/include/mm_sound_mgr_ipc_msgq.h b/server/include/mm_sound_mgr_ipc_msgq.h
new file mode 100644 (file)
index 0000000..1d6fa76
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * libmm-sound
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Seungbae Shin <seungbae.shin@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __MM_SOUND_MGR_IPC_MSGQ_H__
+#define __MM_SOUND_MGR_IPC_MSGQ_H__
+
+#include "../../include/mm_sound_msg.h"
+
+#define SOUND_MSG_SET(sound_msg, x_msgtype, x_handle, x_code, x_msgid) \
+do { \
+       sound_msg.msgtype = x_msgtype; \
+       sound_msg.handle = x_handle; \
+       sound_msg.code = x_code; \
+       sound_msg.msgid = x_msgid; \
+} while(0)
+
+
+int MMSoundMgrIpcMsgqInit(void);
+int MMSoundMgrIpcMsgqFini(void);
+int MMSoundMgrIpcMsgqReady(void);
+
+int _MMIpcMsgqCBSndMsg(mm_ipc_msg_t *msg);
+int _MMIpcMsgqCBRecvMsg(mm_ipc_msg_t *msg);
+int _MMIpcMsgqCBMsgEnQueueAgain(mm_ipc_msg_t *msg);
+
+#endif /* __MM_SOUND_MGR_H__ */
+
index 5a9bf75..be4fdad 100644 (file)
 #ifndef __MM_SOUND_MGR_PULSE_H__
 #define __MM_SOUND_MGR_PULSE_H__
 
+#if 0
 
 #include "../../include/mm_ipc.h"
 #include "mm_sound_mgr_session.h"
 
-void* MMSoundMgrPulseInit(void);
-int MMSoundMgrPulseFini(void* handle);
+typedef void (*pa_disconnect_cb)(void* user_data);
+
 
 void MMSoundMgrPulseSetUSBDefaultSink (int usb_device);
 void MMSoundMgrPulseSetDefaultSink (char* device_api_name, char* device_bus_name);
 void MMSoundMgrPulseSetDefaultSinkByName (char* name);
 void MMSoundMgrPulseSetSourcemutebyname (char* sourcename, int mute);
 
-int MMSoundMgrPulseHandleRegisterMonoAudio (void* pinfo);
-int MMSoundMgrPulseHandleRegisterAudioBalance (void* pinfo);
 int MMSoundMgrPulseHandleRegisterBluetoothStatus (void* pinfo);
-int MMSoundMgrPulseHandleRegisterSurroundSoundStatus(void *pinfo);
 
-int MMSoundMgrPulseHandleIsBtA2DPOnReq (mm_ipc_msg_t *msg, int (*sendfunc)(mm_ipc_msg_t*));
+int MMSoundMgrPulseHandleIsBtA2DPOnReq (bool* is_bt_on, char** bt_name);
 void MMSoundMgrPulseGetInitialBTStatus (bool *a2dp, bool *sco);
 int MMSoundMgrPulseGetBluetoothInfo(bool* is_nrec, int* bandwidth);
 
-void MMSoundMgrPulseUpdateBluetoothAGCodec (void);
-bool MMSoundMgrPulseBTSCONRECStatus(void);
-bool MMSoundMgrPulseBTSCOWBStatus(void);
-
 void MMSoundMgrPulseSetSession(session_t session, session_state_t state);
 void MMSoundMgrPulseSetSubsession(subsession_t subsession, int subsession_opt);
 void MMSoundMgrPulseSetActiveDevice(mm_sound_device_in device_in, mm_sound_device_out device_out);
-void MMSoundMgrPulseUpdateVolume(void);
 
 void MMSoundMgrPulseSetCorkAll (bool cork);
 void MMSoundMgrPulseUnLoadHDMI();
 void MMSoundMgrPulseGetPathInfo(mm_sound_device_out *device_out, mm_sound_device_in *device_in);
 #ifdef TIZEN_MICRO
-void MMSoundMgrPulseSetMuteall(int mute);
 void MMSoundMgrPulseSetVolumeLevel(volume_type_t volume_type, unsigned int volume_level);
 #endif
 void MMSoundMgrPulseSetVoicecontrolState (bool state);
 
+void* MMSoundMgrPulseInit(pa_disconnect_cb cb, void* user_data);
+int MMSoundMgrPulseFini(void* handle);
+#endif
+
 #endif /* __MM_SOUND_MGR_PULSE_H__ */
 
index afca283..3527a34 100644 (file)
 #ifndef __MM_SOUND_MGR_SESSION_H__
 #define __MM_SOUND_MGR_SESSION_H__
 
-//#include <pulse/pulseaudio.h>
-#include "../../include/mm_ipc.h"
-#include "include/mm_sound.h"
-//#include <vconf.h>
-
 typedef enum
 {
        SESSION_END = 0,
        SESSION_START,
 } session_state_t;
 
-typedef enum
-{
-       NOT_AVAILABLE = 0,
-       AVAILABLE,
-} device_status_t;
-
 /* MMSoundMgrPulseSetSession & pa_tizen_session_t should be updated for PA */
 typedef enum
 {
@@ -68,6 +57,19 @@ typedef enum
        SUBSESSION_NUM
 } subsession_t;
 
+#if 0
+//#include <pulse/pulseaudio.h>
+#include "../../include/mm_ipc.h"
+#include "include/mm_sound.h"
+//#include <vconf.h>
+
+typedef enum
+{
+       NOT_AVAILABLE = 0,
+       AVAILABLE,
+} device_status_t;
+
+
 typedef enum
 {
        DEVICE_BUILTIN = 0,
@@ -140,5 +142,6 @@ int MMSoundMgrSessionMediaPause();
 int MMSoundMgrSessionSetDuplicateSubSession(void);
 const char* MMSoundMgrSessionGetSessionString(session_t session);
 #endif
+#endif
 #endif /* __MM_SOUND_MGR_SESSION_H__ */
 
index 8248165..b11914c 100644 (file)
@@ -26,6 +26,8 @@
 #include <mm_source.h>
 #include <mm_types.h>
 
+#define MM_SOUND_STREAM_TYPE_LEN 64
+
 enum MMSoundSupportedCodec {
        MM_SOUND_SUPPORTED_CODEC_INVALID = -1,  /**< Invalid codec type */
        MM_SOUND_SUPPORTED_CODEC_WAVE,                  /**< WAVE codec         */
@@ -57,6 +59,8 @@ typedef struct {
        int keytone;
        MMSourceType *source;
        int handle_route;
+       char stream_type[MM_SOUND_STREAM_TYPE_LEN];
+       int stream_index;
        pthread_mutex_t *codec_wave_mutex;
 } mmsound_codec_param_t;
 
index dd8cc31..4d958ed 100644 (file)
@@ -69,7 +69,6 @@ pthread_mutex_t g_mutex_asm = PTHREAD_MUTEX_INITIALIZER;
 #include <string.h>
 #include <errno.h>
 
-
 #define USE_SYSTEM_SERVER_PROCESS_MONITORING
 
 #define ROW_NUM_OF_SUB_EVENT           12 /* it should be exactly same with number of ASM_CASE_SUB_EVENT in ASM_sound_case table */
@@ -168,6 +167,11 @@ typedef struct _list
        unsigned short                  monitor_active;
        unsigned short                  monitor_dirty;
        bool                                    is_registered_for_watching;
+
+#ifdef SUPPORT_CONTAINER
+       container_info_t                container;
+#endif
+
        struct _list                    *next;
 } asm_instance_list_t;
 
@@ -396,7 +400,7 @@ subsession_t g_camcorder_ex_subsession = SUBSESSION_NUM;
 
 #define MAX_WATCH_CALLBACK_CALCUL_NUM 128
 
-void ___select_sleep(int secs)
+static void ___select_sleep(int secs)
 {
        struct timeval timeout;
        timeout.tv_sec = (secs < 1 || secs > 10) ? 3 : secs;
@@ -405,7 +409,7 @@ void ___select_sleep(int secs)
        return;
 }
 
-int __get_adv_event_idx_for_subtable(ASM_sound_events_t sound_event, int *index)
+static int __get_adv_event_idx_for_subtable(ASM_sound_events_t sound_event, int *index)
 {
        int ret = MM_ERROR_NONE;
        if (!index) {
@@ -432,7 +436,7 @@ int __get_adv_event_idx_for_subtable(ASM_sound_events_t sound_event, int *index)
        return ret;
 }
 
-int __get_sub_case_table_idx(ASM_sound_events_t sound_event, int *index)
+static int __get_sub_case_table_idx(ASM_sound_events_t sound_event, int *index)
 {
        int ret = MM_ERROR_NONE;
        if (!index) {
@@ -476,7 +480,7 @@ int __get_sub_case_table_idx(ASM_sound_events_t sound_event, int *index)
        return ret;
 }
 
-gboolean __is_media_session (ASM_sound_events_t sound_event)
+static gboolean __is_media_session (ASM_sound_events_t sound_event)
 {
        gboolean result = FALSE;
        switch (sound_event) {
@@ -494,7 +498,8 @@ gboolean __is_media_session (ASM_sound_events_t sound_event)
        return result;
 }
 
-ASM_event_sources_t __mapping_sound_event_to_event_src(ASM_sound_events_t sound_event, ASM_resource_t resource, ASM_sound_cases_t sound_case)
+static ASM_event_sources_t __mapping_sound_event_to_event_src(ASM_sound_events_t sound_event,
+                                                                                                               ASM_resource_t resource, ASM_sound_cases_t sound_case)
 {
        ASM_event_sources_t event_src = ASM_EVENT_SOURCE_MEDIA;
 
@@ -538,7 +543,7 @@ ASM_event_sources_t __mapping_sound_event_to_event_src(ASM_sound_events_t sound_
        return event_src;
 }
 
-ASM_event_sources_t __convert_eventsrc_interrupted_to_completed(ASM_event_sources_t eventsrc)
+static ASM_event_sources_t __convert_eventsrc_interrupted_to_completed(ASM_event_sources_t eventsrc)
 {
        ASM_event_sources_t completed_eventsrc = ASM_EVENT_SOURCE_MEDIA;
 
@@ -563,7 +568,7 @@ ASM_event_sources_t __convert_eventsrc_interrupted_to_completed(ASM_event_source
        return completed_eventsrc;
 }
 
-gboolean __is_valid_session_options(ASM_sound_events_t sound_event, int option_flags, int *error_code)
+static gboolean __is_valid_session_options(ASM_sound_events_t sound_event, int option_flags, int *error_code)
 {
        gboolean result = true;
        *error_code = ERR_ASM_ERROR_NONE;
@@ -587,7 +592,8 @@ gboolean __is_valid_session_options(ASM_sound_events_t sound_event, int option_f
        return result;
 }
 
-gboolean __is_need_resume (ASM_sound_events_t incoming_sound_event, ASM_resource_t incoming_resource, ASM_sound_events_t current_sound_event, int current_handle)
+static gboolean __is_need_resume (ASM_sound_events_t incoming_sound_event, ASM_resource_t incoming_resource,
+                                                               ASM_sound_events_t current_sound_event, int current_handle)
 {
        gboolean result = FALSE;
        switch (incoming_sound_event) {
@@ -652,7 +658,7 @@ gboolean __is_session_using_media_volume (ASM_sound_events_t sound_event)
        return result;
 }
 
-gboolean __find_clean_monitor_handle(int instance_id, int *handle)
+static gboolean __find_clean_monitor_handle(int instance_id, int *handle)
 {
        asm_instance_list_t *temp_list = head_list_ptr;
        int lhandle = ASM_HANDLE_INIT_VAL;
@@ -676,7 +682,7 @@ gboolean __find_clean_monitor_handle(int instance_id, int *handle)
        }
 }
 
-void __update_monitor_active(int instance_id)
+static void __update_monitor_active(int instance_id)
 {
        asm_instance_list_t *temp_list = head_list_ptr;
        asm_instance_list_t *monitor_list = NULL;
@@ -710,7 +716,7 @@ void __update_monitor_active(int instance_id)
        monitor_list->monitor_active = active;
 }
 
-void __set_all_monitor_clean()
+static void __set_all_monitor_clean()
 {
        asm_instance_list_t *temp_list = head_list_ptr;
 
@@ -722,7 +728,7 @@ void __set_all_monitor_clean()
        }
 }
 
-void __set_monitor_dirty(int instance_id)
+static void __set_monitor_dirty(int instance_id)
 {
        asm_instance_list_t *temp_list = head_list_ptr;
 
@@ -735,11 +741,70 @@ void __set_monitor_dirty(int instance_id)
        }
 }
 
+#ifdef SUPPORT_CONTAINER
+static void __set_container_data(int handle, const char* container_name, int container_pid)
+{
+       asm_instance_list_t *temp_list = head_list_ptr;
+
+       while (temp_list != NULL) {
+               if (temp_list->sound_handle == handle) {
+                       debug_error("Set container [%s][%d] to handle[%d] instanceID[%d]",
+                                               container_name, container_pid, handle, temp_list->instance_id);
+                       if (container_name)
+                               strcpy (temp_list->container.name, container_name);
+                       temp_list->container.pid = container_pid;
+                       break;
+               }
+               temp_list = temp_list->next;
+       }
+}
+
+static container_info_t* __get_container_info(int instance_id)
+{
+       asm_instance_list_t *temp_list = head_list_ptr;
+
+       while (temp_list != NULL) {
+               if (temp_list->instance_id == instance_id) {
+                       return &temp_list->container;
+               }
+               temp_list = temp_list->next;
+       }
+}
+#endif /* SUPPORT_CONTAINER */
+
+static char* __get_asm_pipe_path(int instance_id, int handle, const char* postfix)
+{
+       char* path = NULL;
+       char* path2 = NULL;
+
+#ifdef SUPPORT_CONTAINER
+       container_info_t* container_info = __get_container_info(instance_id);
+
+       if (instance_id == container_info->pid) {
+               debug_error ("This might be in the HOST(%s)[%d], let's form normal path",
+                                       container_info->name, instance_id);
+               path = g_strdup_printf("/tmp/ASM.%d.%d", instance_id, handle);
+       } else {
+               path = g_strdup_printf("/var/lib/lxc/%s/rootfs/tmp/ASM.%d.%d",
+                                                               container_info->name, container_info->pid, handle);
+       }
+#else
+       path = g_strdup_printf("/tmp/ASM.%d.%d", instance_id, handle);
+#endif
+       if (path && postfix) {
+               path2 = g_strconcat(path, postfix, NULL);
+               g_free(path);
+               path = path2;
+       }
+
+       return path;
+}
+
 /* callback without retcb */
 void __do_callback_wo_retcb(int instance_id,int handle,int command)
 {
        int fd_ASM = -1, cur_handle = 0;
-       char *filename = g_strdup_printf("/tmp/ASM.%d.%d", instance_id, handle);
+       char *filename = __get_asm_pipe_path(instance_id, handle, NULL);
 
        if ((fd_ASM = open(filename,O_WRONLY|O_NONBLOCK)) < 0) {
                debug_log("[CallCB] %s open error",filename);
@@ -785,7 +850,7 @@ int __do_callback(int instance_id, int handle, int command, ASM_event_sources_t
         * Open callback cmd pipe
         *
         **************************************/
-       filename = g_strdup_printf("/tmp/ASM.%d.%d", instance_id, handle);
+       filename = __get_asm_pipe_path(instance_id, handle, NULL);
        if ((fd_ASM = open(filename, O_WRONLY|O_NONBLOCK)) < 0) {
                debug_error("[CallCB] %s open error\n", filename);
                goto fail;
@@ -797,7 +862,7 @@ int __do_callback(int instance_id, int handle, int command, ASM_event_sources_t
         * before writing callback cmd to pipe
         *
         ******************************************/
-       filename2 = g_strdup_printf("/tmp/ASM.%d.%dr", instance_id, handle);
+       filename2 = __get_asm_pipe_path(instance_id, handle, "r");
        if ((fd=open(filename2,O_RDONLY|O_NONBLOCK))== -1) {
                char str_error[256];
                strerror_r (errno, str_error, sizeof(str_error));
@@ -974,7 +1039,7 @@ int __do_watch_callback(ASM_sound_events_t sound_event, ASM_sound_states_t updat
                 * Open callback cmd pipe
                 *
                 **************************************/
-               filename = g_strdup_printf("/tmp/ASM.%d.%d", instance_id_list[num], handle_list[num]);
+               filename = __get_asm_pipe_path(instance_id_list[num], handle_list[num], NULL);
                if ((fd_ASM = open(filename, O_WRONLY|O_NONBLOCK)) < 0) {
                        debug_error("[CallCB] %s open error\n", filename);
                        goto fail;
@@ -986,7 +1051,7 @@ int __do_watch_callback(ASM_sound_events_t sound_event, ASM_sound_states_t updat
                 * before writing callback cmd to pipe
                 *
                 ******************************************/
-               filename2 = g_strdup_printf("/tmp/ASM.%d.%dr", instance_id_list[num], handle_list[num]);
+               filename2 = __get_asm_pipe_path(instance_id_list[num], handle_list[num], "r");
                if ((fd=open(filename2,O_RDONLY|O_NONBLOCK))== -1) {
                        char str_error[256];
                        strerror_r (errno, str_error, sizeof(str_error));
@@ -1111,6 +1176,29 @@ void __temp_print_list(char * msg)
        }
        while (temp_list != NULL) {
                if (!temp_list->is_registered_for_watching) {
+#ifdef SUPPORT_CONTAINER
+                       if (!ASM_IS_ADVANCED_ASM_EVENT(temp_list->sound_event)) {
+                               debug_msg(" List[%02d] ( %10s, %5d(%5d), %2d, %-22s, %-15s, %9s checked by%5d/%d, 0x%04x, 0x%04x)\n" , i,
+                                                                                               temp_list->container.name,
+                                                                                               temp_list->instance_id, temp_list->container.pid, temp_list->sound_handle,
+                                                                                               ASM_sound_event_str[temp_list->sound_event],
+                                                                                               ASM_sound_state_str[temp_list->sound_state],
+                                                                                               ASM_sound_resume_str[temp_list->need_resume],
+                                                                                               temp_list->paused_by_id.pid,
+                                                                                               temp_list->paused_by_id.sound_handle,
+                                                                                               temp_list->mm_resource,
+                                                                                               temp_list->option_flags);
+                       } else {
+                               debug_msg(" List[%02d] ( %10s, %5d(%5d), %2d, %-22s, %-15s, %-15s, 0x%04x)\n", i,
+                                                                                               temp_list->container.name,
+                                                                                               temp_list->instance_id, temp_list->container.pid,
+                                                                                               temp_list->sound_handle,
+                                                                                               ASM_sound_event_str[temp_list->sound_event],
+                                                                                               ASM_sound_state_str[temp_list->sound_state],
+                                                                                               ASM_sound_sub_event_str[temp_list->sound_sub_event],
+                                                                                               temp_list->mm_resource);
+                       }
+#else
                        if (!ASM_IS_ADVANCED_ASM_EVENT(temp_list->sound_event)) {
                                debug_msg(" List[%02d] ( %5d, %2d, %-22s, %-15s, %9s checked by%5d/%d, 0x%04x, 0x%04x)\n" , i,
                                                                                                temp_list->instance_id, temp_list->sound_handle,
@@ -1130,6 +1218,7 @@ void __temp_print_list(char * msg)
                                                                                                ASM_sound_sub_event_str[temp_list->sound_sub_event],
                                                                                                temp_list->mm_resource);
                        }
+#endif
                        i++;
                }
                temp_list = temp_list->next;
@@ -1138,10 +1227,18 @@ void __temp_print_list(char * msg)
        debug_log(" listed below are requests for watching session\n");
        while (temp_list != NULL) {
                if (temp_list->is_registered_for_watching) {
+#ifdef SUPPORT_CONTAINER
+                       debug_msg(" List[%02d] ( %10s, %5d(%5d), %2d, %-22s, %-15s, %5s)\n", i, temp_list->container.name,
+                                                                                               temp_list->instance_id, temp_list->container.pid, temp_list->sound_handle,
+                                                                                               ASM_sound_event_str[temp_list->sound_event],
+                                                                                               ASM_sound_state_str[temp_list->sound_state],
+                                                                                               "WATCHING");
+#else
                        debug_msg(" List[%02d] ( %5d, %2d, %-22s, %-15s, %5s)\n", i, temp_list->instance_id, temp_list->sound_handle,
                                                                                                ASM_sound_event_str[temp_list->sound_event],
                                                                                                ASM_sound_state_str[temp_list->sound_state],
                                                                                                "WATCHING");
+#endif
                        i++;
                }
                temp_list = temp_list->next;
@@ -1176,9 +1273,9 @@ void ___update_phone_status()
                temp_list = temp_list->next;
        }
 
-       if (vconf_set_int(SOUND_STATUS_KEY, g_sound_status_playing)) {
+       if ((error = vconf_set_int(SOUND_STATUS_KEY, g_sound_status_playing))) {
                debug_error("[ASM_Server[Error = %d][1st try] phonestatus_set \n", error);
-               if (vconf_set_int(SOUND_STATUS_KEY, g_sound_status_playing)) {
+               if ((error = vconf_set_int(SOUND_STATUS_KEY, g_sound_status_playing))) {
                        debug_error("[Error = %d][2nd try]  phonestatus_set \n", error);
                }
        }
@@ -1208,6 +1305,12 @@ asm_instance_list_t* __asm_register_list(int instance_id, int handle, ASM_sound_
        temp_list->monitor_active = 0;
        temp_list->monitor_dirty = 0;
        temp_list->is_registered_for_watching = is_requested_for_watching;
+#ifdef SUPPORT_CONTAINER
+       memset (&temp_list->container, 0, sizeof (container_info_t));
+       strcpy (temp_list->container.name, "NONAME");
+       temp_list->container.pid = instance_id;
+#endif
+
        temp_list->next = head_list_ptr;
        head_list_ptr = temp_list;
        if (tail_list_ptr == NULL) {
@@ -1262,31 +1365,14 @@ int __asm_unregister_list(int handle)
 }
 
 /* -------------------------
- * if PID exist return true, else return false
- */
-gboolean ___is_pid_exist(int pid)
-{
-       if (pid > 999999 || pid < 2)
-               return FALSE;
-       gchar *tmp = g_malloc0(25);
-       g_sprintf(tmp, "/proc/%d", pid);
-       if (access(tmp, R_OK)==0) {
-               g_free(tmp);
-               return TRUE;
-       }
-       g_free(tmp);
-       return FALSE;
-}
-
-/* -------------------------
  *
  */
-void __check_dead_process()
+static void __check_dead_process()
 {
        asm_instance_list_t *temp_list = head_list_ptr;
        asm_instance_list_t *temp_list_prev = head_list_ptr;
        while (temp_list != NULL) {
-               if (!___is_pid_exist(temp_list->instance_id)) {
+               if (!mm_sound_util_is_process_alive(temp_list->instance_id)) {
                        debug_warning(" PID(%d) not exist! -> ASM_Server resource of pid(%d) will be cleared \n", temp_list->instance_id, temp_list->instance_id);
                        g_handle_info[temp_list->sound_handle].is_registered = 0;
                        g_handle_info[temp_list->sound_handle].option_flags = 0;
@@ -1309,7 +1395,7 @@ void __check_dead_process()
                        }
                } else {
                        if (temp_list->paused_by_id.pid) {
-                               if (!___is_pid_exist(temp_list->paused_by_id.pid)) {
+                               if (!mm_sound_util_is_process_alive(temp_list->paused_by_id.pid)) {
                                        temp_list->need_resume = ASM_NEED_NOT_RESUME;
                                        temp_list->paused_by_id.pid = 0;
                                        temp_list->paused_by_id.sound_handle = ASM_HANDLE_INIT_VAL;
@@ -1339,7 +1425,7 @@ void __reset_resume_check(int instance_id, int handle)
        }
 }
 
-void __emergent_exit(int exit_pid)
+static void __emergent_exit(int exit_pid)
 {
        asm_instance_list_t *temp_list = head_list_ptr;
        int handle = ASM_HANDLE_INIT_VAL;
@@ -1348,13 +1434,10 @@ void __emergent_exit(int exit_pid)
        while (temp_list != NULL) {
                if (temp_list->instance_id == exit_pid) {
                        handle = temp_list->sound_handle;
-
-                       instance_id = __asm_unregister_list(handle);
-
-                       if (instance_id != -1) {
+                       if (temp_list->instance_id != -1) {
                                char str_error[256];
-                               char* filename = g_strdup_printf("/tmp/ASM.%d.%d", instance_id, handle);
-                               char* filename2 = g_strdup_printf("/tmp/ASM.%d.%dr", instance_id, handle);
+                               char* filename = __get_asm_pipe_path(temp_list->instance_id, handle, NULL);
+                               char* filename2 = __get_asm_pipe_path(temp_list->instance_id, handle, "r");
                                if (!remove(filename)) {
                                        debug_log(" remove %s success\n", filename);
                                } else {
@@ -1372,6 +1455,7 @@ void __emergent_exit(int exit_pid)
                                g_free(filename);
                                g_free(filename2);
                        }
+                       instance_id = __asm_unregister_list(handle);
                        temp_list = head_list_ptr;
                } else {
                        temp_list = temp_list->next;
@@ -1549,44 +1633,6 @@ void __asm_change_need_resume_list(int instance_id, int handle, ASM_resume_state
        }
 }
 
-void __asm_create_message_queue()
-{
-       asm_rcv_msgid = msgget((key_t)2014, 0666 | IPC_CREAT);
-       asm_snd_msgid = msgget((key_t)4102, 0666 | IPC_CREAT);
-       asm_cb_msgid = msgget((key_t)4103, 0666 | IPC_CREAT);
-
-       if (asm_snd_msgid == -1 || asm_rcv_msgid == -1 || asm_cb_msgid == -1) {
-               debug_error(" msgget failed with error(%d,%s) \n", errno, strerror(errno));
-               exit(EXIT_FAILURE);
-       }
-}
-
-void __asm_snd_message(ASM_msg_asm_to_lib_t *asm_snd_msg)
-{
-       if (msgsnd(asm_snd_msgid, (void *)asm_snd_msg, sizeof(asm_snd_msg->data), 0) == -1) {
-               debug_error(" msgsnd failed with error %d\n", errno);
-               exit(EXIT_FAILURE);
-       } else {
-               debug_warning(" success : handle(%d), pid(%d), result_state(%s), result_command(%s), source_request(%s)",
-                       asm_snd_msg->data.alloc_handle, asm_snd_msg->instance_id,
-                       ASM_sound_state_str[asm_snd_msg->data.result_sound_state],
-                       ASM_sound_command_str[asm_snd_msg->data.result_sound_command],
-                       ASM_sound_request_str[asm_snd_msg->data.source_request_id]);
-               asm_snd_msg->data.result_sound_state = ASM_STATE_NONE;
-               asm_snd_msg->data.result_sound_command = ASM_COMMAND_NONE;
-       }
-}
-
-void __asm_rcv_message(ASM_msg_lib_to_asm_t *asm_rcv_msg)
-{
-       if (msgrcv(asm_rcv_msgid, (void *)asm_rcv_msg, sizeof(asm_rcv_msg->data), 0, 0) == -1) {
-               debug_error(" msgrcv failed with error %d\n", errno);
-               exit(EXIT_FAILURE);
-       } else {
-               debug_log(" success");
-       }
-}
-
 void __asm_get_empty_handle(int instance_id, int *handle)
 {
        asm_instance_list_t *temp_list = head_list_ptr;
@@ -1654,8 +1700,8 @@ gboolean __need_to_compare_again(ASM_sound_events_t current_playing_event, int c
                mm_sound_device_in device_in = MM_SOUND_DEVICE_IN_NONE;
                bool available = false;
 
-               if (incoming_playing_event == ASM_EVENT_NOTIFY && (_mm_sound_is_recording() || _mm_sound_is_mute_policy()) ) {
-                       ret = MMSoundMgrSessionIsDeviceAvailable (device_out_wired_accessory, device_in, &available);
+               if (incoming_playing_event == ASM_EVENT_NOTIFY && (mm_sound_util_is_recording() || mm_sound_util_is_mute_policy()) ) {
+//                     ret = MMSoundMgrSessionIsDeviceAvailable (device_out_wired_accessory, device_in, &available);
                        if (ret) {
                                debug_error("Failed to IsDeviceAvailable()\n");
                        } else {
@@ -1684,7 +1730,7 @@ gboolean __need_to_compare_again(ASM_sound_events_t current_playing_event, int c
                        }
                } else if (current_playing_event == ASM_EVENT_NOTIFY &&
                        (incoming_playing_event != ASM_EVENT_EARJACK_UNPLUG && __is_session_using_media_volume(incoming_playing_event))) {
-                       ret = MMSoundMgrSessionGetDeviceActive(&device_out, &device_in);
+//                     ret = MMSoundMgrSessionGetDeviceActive(&device_out, &device_in);
                        if (ret) {
                                debug_error("Failed to GetDeviceActive()\n");
                        } else {
@@ -1700,7 +1746,7 @@ gboolean __need_to_compare_again(ASM_sound_events_t current_playing_event, int c
                                }
                        }
                } else if (current_playing_event == ASM_EVENT_ALARM && incoming_playing_event == ASM_EVENT_NOTIFY) {
-                       if ((_mm_sound_is_recording() || _mm_sound_is_mute_policy())) {
+                       if ((mm_sound_util_is_recording() || mm_sound_util_is_mute_policy())) {
                                debug_warning("EXCEPTION case for notification on alarm in 1PAUSE_2PLAY => go to 1PLAY_2STOP\n");
                                *sound_case = ASM_CASE_1PLAY_2STOP;
                                *blocked_reason = ERR_ASM_POLICY_CANNOT_PLAY_BY_PROFILE;
@@ -2474,7 +2520,7 @@ int __asm_change_session (ASM_requests_t rcv_request, ASM_sound_events_t rcv_sou
        int ret = MM_ERROR_NONE;
        session_t cur_session;
 
-       MMSoundMgrSessionGetSession(&cur_session);
+//     MMSoundMgrSessionGetSession(&cur_session);
        debug_warning (" cur_session[%d] (0:MEDIA 1:VC 2:VT 3:VOIP 4:FM 5:NOTI 6:ALARM 7:EMER 8:VR)\n",cur_session);
        if (is_for_recovery) {
                if (need_to_resume) {
@@ -2492,21 +2538,21 @@ int __asm_change_session (ASM_requests_t rcv_request, ASM_sound_events_t rcv_sou
                        switch (rcv_sound_event) {
                        case ASM_EVENT_CALL:
                                debug_warning (" ****** SESSION_VOICECALL start ******\n");
-                               ret = MMSoundMgrSessionSetSession(SESSION_VOICECALL, SESSION_START);
+//                             ret = MMSoundMgrSessionSetSession(SESSION_VOICECALL, SESSION_START);
                                if (ret) {
                                        goto ERROR_CASE;
                                }
                                break;
                        case ASM_EVENT_VIDEOCALL:
                                debug_warning (" ****** SESSION_VIDEOCALL start ******\n");
-                               ret = MMSoundMgrSessionSetSession(SESSION_VIDEOCALL, SESSION_START);
+//                             ret = MMSoundMgrSessionSetSession(SESSION_VIDEOCALL, SESSION_START);
                                if (ret) {
                                        goto ERROR_CASE;
                                }
                                break;
                        case ASM_EVENT_VOIP:
                                debug_warning (" ****** SESSION_VOIP start ******\n");
-                               ret = MMSoundMgrSessionSetSession(SESSION_VOIP, SESSION_START);
+//                             ret = MMSoundMgrSessionSetSession(SESSION_VOIP, SESSION_START);
                                if (ret) {
                                        goto ERROR_CASE;
                                }
@@ -2514,7 +2560,7 @@ int __asm_change_session (ASM_requests_t rcv_request, ASM_sound_events_t rcv_sou
                        case ASM_EVENT_EXCLUSIVE_RESOURCE:
                                if ( rcv_resource & ASM_RESOURCE_VOICECONTROL ) {
                                        debug_warning (" ****** ASM_RESOURCE_VOICECONTROL START ******\n");
-                                       MMSoundMgrSessionSetVoiceControlState(true);
+//                                     MMSoundMgrSessionSetVoiceControlState(true);
                                }
                                break;
                        default:
@@ -2535,7 +2581,7 @@ int __asm_change_session (ASM_requests_t rcv_request, ASM_sound_events_t rcv_sou
                                        debug_warning (" ****** Notify starts on Call/Voip session ******\n");
                                } else {
                                        debug_warning (" ****** SESSION_NOTIFICATION start ******\n");
-                                       ret = MMSoundMgrSessionSetSession(SESSION_NOTIFICATION, SESSION_START);
+//                                     ret = MMSoundMgrSessionSetSession(SESSION_NOTIFICATION, SESSION_START);
                                        if (ret) {
                                                goto ERROR_CASE;
                                        }
@@ -2551,7 +2597,7 @@ int __asm_change_session (ASM_requests_t rcv_request, ASM_sound_events_t rcv_sou
                                        debug_warning (" ****** Alarm starts on Call/Voip session ******\n");
                                } else {
                                        debug_warning (" ****** SESSION_ALARM start ******\n");
-                                       ret = MMSoundMgrSessionSetSession(SESSION_ALARM, SESSION_START);
+//                                     ret = MMSoundMgrSessionSetSession(SESSION_ALARM, SESSION_START);
                                        if (ret) {
                                                goto ERROR_CASE;
                                        }
@@ -2565,7 +2611,7 @@ int __asm_change_session (ASM_requests_t rcv_request, ASM_sound_events_t rcv_sou
                                        SESSION_REF(cur_session);
                                } else {
                                        debug_warning (" ****** SESSION_EMERGENCY start ******\n");
-                                       ret = MMSoundMgrSessionSetSession(SESSION_EMERGENCY, SESSION_START);
+//                                     ret = MMSoundMgrSessionSetSession(SESSION_EMERGENCY, SESSION_START);
                                        if (ret) {
                                                goto ERROR_CASE;
                                        }
@@ -2579,7 +2625,7 @@ int __asm_change_session (ASM_requests_t rcv_request, ASM_sound_events_t rcv_sou
                                        SESSION_REF(cur_session);
                                } else {
                                        debug_warning (" ****** SESSION_FMRADIO start ******\n");
-                                       ret = MMSoundMgrSessionSetSession(SESSION_FMRADIO, SESSION_START);
+//                                     ret = MMSoundMgrSessionSetSession(SESSION_FMRADIO, SESSION_START);
                                        if (ret) {
                                                goto ERROR_CASE;
                                        }
@@ -2622,7 +2668,7 @@ int __asm_change_session (ASM_requests_t rcv_request, ASM_sound_events_t rcv_sou
                                        SESSION_REF(cur_session);
                                } else {
                                        debug_warning (" ****** SESSION_VOICE_RECOGNITION start ******\n");
-                                       ret = MMSoundMgrSessionSetSession(SESSION_VOICE_RECOGNITION, SESSION_START);
+//                                     ret = MMSoundMgrSessionSetSession(SESSION_VOICE_RECOGNITION, SESSION_START);
                                        if (ret) {
                                                goto ERROR_CASE;
                                        }
@@ -2652,7 +2698,7 @@ int __asm_change_session (ASM_requests_t rcv_request, ASM_sound_events_t rcv_sou
                                /* wakeup mode */
                                if (cur_session == SESSION_VOICE_RECOGNITION) {
                                        subsession_t subsession = 0;
-                                       MMSoundMgrSessionGetSubSession(&subsession);
+//                                     MMSoundMgrSessionGetSubSession(&subsession);
                                        if (subsession == SUBSESSION_VR_NORMAL || subsession == SUBSESSION_VR_DRIVE) {
                                                /* do nothing */
                                        }
@@ -2662,7 +2708,7 @@ int __asm_change_session (ASM_requests_t rcv_request, ASM_sound_events_t rcv_sou
                                /* command mode */
                                if (cur_session == SESSION_VOICE_RECOGNITION) {
                                        subsession_t subsession = 0;
-                                       MMSoundMgrSessionGetSubSession(&subsession);
+//                                     MMSoundMgrSessionGetSubSession(&subsession);
                                        if (subsession == SUBSESSION_VR_NORMAL || subsession == SUBSESSION_VR_DRIVE) {
                                                /* do nothing */
                                        }
@@ -2683,7 +2729,7 @@ int __asm_change_session (ASM_requests_t rcv_request, ASM_sound_events_t rcv_sou
                        switch (rcv_sound_event) {
                        case ASM_EVENT_CALL:
                                debug_warning (" ****** SESSION_VOICECALL end ******\n");
-                               ret = MMSoundMgrSessionSetSession(SESSION_VOICECALL, SESSION_END);
+//                             ret = MMSoundMgrSessionSetSession(SESSION_VOICECALL, SESSION_END);
                                if (ret) {
                                        goto ERROR_CASE;
                                }
@@ -2691,7 +2737,7 @@ int __asm_change_session (ASM_requests_t rcv_request, ASM_sound_events_t rcv_sou
                                break;
                        case ASM_EVENT_VIDEOCALL:
                                debug_warning (" ****** SESSION_VIDEOCALL end ******\n");
-                               ret = MMSoundMgrSessionSetSession(SESSION_VIDEOCALL, SESSION_END);
+//                             ret = MMSoundMgrSessionSetSession(SESSION_VIDEOCALL, SESSION_END);
                                if (ret) {
                                        goto ERROR_CASE;
                                }
@@ -2699,7 +2745,7 @@ int __asm_change_session (ASM_requests_t rcv_request, ASM_sound_events_t rcv_sou
                                break;
                        case ASM_EVENT_VOIP:
                                debug_warning (" ****** SESSION_VOIP end ******\n");
-                               ret = MMSoundMgrSessionSetSession(SESSION_VOIP, SESSION_END);
+//                             ret = MMSoundMgrSessionSetSession(SESSION_VOIP, SESSION_END);
                                if (ret) {
                                        goto ERROR_CASE;
                                }
@@ -2718,7 +2764,7 @@ int __asm_change_session (ASM_requests_t rcv_request, ASM_sound_events_t rcv_sou
                                                debug_warning (" ****** KEEP GOING SESSION_VOICE_RECOGNITION ****** current ref.count(%d)\n", g_session_ref_count);
                                        } else {
                                                debug_warning (" ****** SESSION_VOICE_RECOGNITION end ******\n");
-                                               ret = MMSoundMgrSessionSetSession(SESSION_VOICE_RECOGNITION, SESSION_END);
+//                                             ret = MMSoundMgrSessionSetSession(SESSION_VOICE_RECOGNITION, SESSION_END);
                                                if (ret) {
                                                        goto ERROR_CASE;
                                                }
@@ -2730,7 +2776,7 @@ int __asm_change_session (ASM_requests_t rcv_request, ASM_sound_events_t rcv_sou
                        case ASM_EVENT_MMCAMCORDER_VIDEO:
                                if (cur_session == SESSION_MEDIA) {
                                        debug_warning (" ****** SESSION_MEDIA for MMCAMCORDER end ******\n");
-                                       ret = MMSoundMgrSessionSetSession(SESSION_MEDIA, SESSION_END);
+//                                     ret = MMSoundMgrSessionSetSession(SESSION_MEDIA, SESSION_END);
                                        if (ret) {
                                                goto ERROR_CASE;
                                        }
@@ -2738,8 +2784,8 @@ int __asm_change_session (ASM_requests_t rcv_request, ASM_sound_events_t rcv_sou
                                break;
                        case ASM_EVENT_EXCLUSIVE_RESOURCE:
                                if ( rcv_resource & ASM_RESOURCE_VOICECONTROL ) {
+//                                     MMSoundMgrSessionSetVoiceControlState(false);
                                        debug_warning (" ****** ASM_RESOURCE_VOICECONTROL END ******\n");
-                                       MMSoundMgrSessionSetVoiceControlState(false);
                                }
                                break;
                        default:
@@ -2758,7 +2804,7 @@ int __asm_change_session (ASM_requests_t rcv_request, ASM_sound_events_t rcv_sou
                                                        debug_warning (" ****** KEEP GOING SESSION_NOTIFICATION ****** current ref.count(%d)\n", g_session_ref_count);
                                                } else {
                                                        debug_warning (" ****** SESSION_NOTIFICATON end ******\n");
-                                                       ret = MMSoundMgrSessionSetSession(SESSION_NOTIFICATION, SESSION_END);
+//                                                     ret = MMSoundMgrSessionSetSession(SESSION_NOTIFICATION, SESSION_END);
                                                        if (ret) {
                                                                goto ERROR_CASE;
                                                        }
@@ -2769,7 +2815,7 @@ int __asm_change_session (ASM_requests_t rcv_request, ASM_sound_events_t rcv_sou
                                                        debug_warning (" ****** KEEP GOING SESSION_ALARM ****** current ref.count(%d)\n", g_session_ref_count);
                                                } else {
                                                        debug_warning (" ****** SESSION_ALARM end ******\n");
-                                                       ret = MMSoundMgrSessionSetSession(SESSION_ALARM, SESSION_END);
+//                                                     ret = MMSoundMgrSessionSetSession(SESSION_ALARM, SESSION_END);
                                                        if (ret) {
                                                                goto ERROR_CASE;
                                                        }
@@ -2786,7 +2832,7 @@ int __asm_change_session (ASM_requests_t rcv_request, ASM_sound_events_t rcv_sou
                                                        debug_warning (" ****** KEEP GOING SESSION_ALARM ****** current ref.count(%d)\n", g_session_ref_count);
                                                } else {
                                                        debug_warning (" ****** SESSION_ALARM end ******\n");
-                                                       ret = MMSoundMgrSessionSetSession(SESSION_ALARM, SESSION_END);
+//                                                     ret = MMSoundMgrSessionSetSession(SESSION_ALARM, SESSION_END);
                                                        if (ret) {
                                                                goto ERROR_CASE;
                                                        }
@@ -2805,7 +2851,7 @@ int __asm_change_session (ASM_requests_t rcv_request, ASM_sound_events_t rcv_sou
                                                        debug_warning (" ****** KEEP GOING SESSION_EMERGENCY ****** current ref.count(%d)\n", g_session_ref_count);
                                                } else {
                                                        debug_warning (" ****** SESSION_EMERGENCY end ******\n");
-                                                       ret = MMSoundMgrSessionSetSession(SESSION_EMERGENCY, SESSION_END);
+//                                                     ret = MMSoundMgrSessionSetSession(SESSION_EMERGENCY, SESSION_END);
                                                        if (ret) {
                                                                goto ERROR_CASE;
                                                        }
@@ -2822,7 +2868,7 @@ int __asm_change_session (ASM_requests_t rcv_request, ASM_sound_events_t rcv_sou
                                                        debug_warning (" ****** KEEP GOING SESSION_FMRADIO ****** current ref.count(%d)\n", g_session_ref_count);
                                                } else {
                                                        debug_warning (" ****** SESSION_FMRADIO end ******");
-                                                       ret = MMSoundMgrSessionSetSession(SESSION_FMRADIO, SESSION_END);
+//                                                     ret = MMSoundMgrSessionSetSession(SESSION_FMRADIO, SESSION_END);
                                                        if (ret) {
                                                                goto ERROR_CASE;
                                                        }
@@ -2845,7 +2891,7 @@ int __asm_change_session (ASM_requests_t rcv_request, ASM_sound_events_t rcv_sou
                                                        debug_warning (" ****** KEEP GOING SESSION_VOICE_RECOGNITION ****** current ref.count(%d)\n", g_session_ref_count);
                                                } else {
                                                        debug_warning (" ****** SESSION_VOICE_RECOGNITION end ******\n");
-                                                       ret = MMSoundMgrSessionSetSession(SESSION_VOICE_RECOGNITION, SESSION_END);
+//                                                     ret = MMSoundMgrSessionSetSession(SESSION_VOICE_RECOGNITION, SESSION_END);
                                                        if (ret) {
                                                                goto ERROR_CASE;
                                                        }
@@ -2874,14 +2920,14 @@ int __asm_change_session (ASM_requests_t rcv_request, ASM_sound_events_t rcv_sou
                debug_warning (" need_to_resume[%d]", *need_to_resume);
        }
 
-       MMSoundMgrSessionGetSession(&cur_session);
+//     MMSoundMgrSessionGetSession(&cur_session);
        debug_msg (" cur_session[%d] : leave", cur_session);
 
        return ret;
 
 RECOVERY_CASE:
        debug_warning (" ****** recovery case : current session(%d) end ******\n", cur_session);
-       ret = MMSoundMgrSessionSetSession(cur_session, SESSION_END);
+//     ret = MMSoundMgrSessionSetSession(cur_session, SESSION_END);
        if (ret) {
                goto ERROR_CASE;
        }
@@ -2893,6 +2939,407 @@ ERROR_CASE:
        return ret;
 }
 
+int _mm_sound_mgr_asm_register_sound(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state, int rcv_resource,
+                                           int *snd_pid, int *snd_alloc_handle, int *snd_cmd_handle, int *snd_request_id, int *snd_sound_command, int *snd_sound_state)
+{
+       ASM_msg_lib_to_asm_t asm_rcv_gvariant;
+       ASM_msg_asm_to_lib_t asm_snd_gvariant;
+       int ret = MM_ERROR_NONE;
+
+       asm_rcv_gvariant.instance_id = rcv_pid;
+       asm_rcv_gvariant.data.handle = rcv_handle;
+       asm_rcv_gvariant.data.sound_event = rcv_sound_event;
+       asm_rcv_gvariant.data.request_id = rcv_request_id;
+       asm_rcv_gvariant.data.sound_state = rcv_sound_state;
+       asm_rcv_gvariant.data.system_resource = rcv_resource;
+
+       ret = __asm_process_message(&asm_rcv_gvariant, &asm_snd_gvariant);
+
+       *snd_pid = asm_snd_gvariant.instance_id;
+       *snd_alloc_handle = asm_snd_gvariant.data.alloc_handle;
+       *snd_cmd_handle = asm_snd_gvariant.data.cmd_handle;
+       *snd_request_id = asm_snd_gvariant.data.source_request_id;
+       *snd_sound_command = asm_snd_gvariant.data.result_sound_command;
+       *snd_sound_state = asm_snd_gvariant.data.result_sound_state;
+
+       return ret;
+
+}
+
+int _mm_sound_mgr_asm_unregister_sound(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state, int rcv_resource)
+{
+       ASM_msg_lib_to_asm_t asm_rcv_gvariant;
+       ASM_msg_asm_to_lib_t asm_snd_gvariant;
+       int ret = MM_ERROR_NONE;
+
+       asm_rcv_gvariant.instance_id = rcv_pid;
+       asm_rcv_gvariant.data.handle = rcv_handle;
+       asm_rcv_gvariant.data.sound_event = rcv_sound_event;
+       asm_rcv_gvariant.data.request_id = rcv_request_id;
+       asm_rcv_gvariant.data.sound_state = rcv_sound_state;
+       asm_rcv_gvariant.data.system_resource = rcv_resource;
+
+       ret = __asm_process_message(&asm_rcv_gvariant, &asm_snd_gvariant);
+
+       return ret;
+
+}
+
+int _mm_sound_mgr_asm_register_watcher(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state, int rcv_resource,
+                                             int *snd_pid, int *snd_alloc_handle, int *snd_cmd_handle, int *snd_request_id, int *snd_sound_command, int *snd_sound_state)
+{
+       ASM_msg_lib_to_asm_t asm_rcv_gvariant;
+       ASM_msg_asm_to_lib_t asm_snd_gvariant;
+       int ret = MM_ERROR_NONE;
+
+       asm_rcv_gvariant.instance_id = rcv_pid;
+       asm_rcv_gvariant.data.handle = rcv_handle;
+       asm_rcv_gvariant.data.sound_event = rcv_sound_event;
+       asm_rcv_gvariant.data.request_id = rcv_request_id;
+       asm_rcv_gvariant.data.sound_state = rcv_sound_state;
+       asm_rcv_gvariant.data.system_resource = rcv_resource;
+
+       ret = __asm_process_message(&asm_rcv_gvariant, &asm_snd_gvariant);
+
+       *snd_pid = asm_snd_gvariant.instance_id;
+       *snd_alloc_handle = asm_snd_gvariant.data.alloc_handle;
+       *snd_cmd_handle = asm_snd_gvariant.data.cmd_handle;
+       *snd_request_id = asm_snd_gvariant.data.source_request_id;
+       *snd_sound_command = asm_snd_gvariant.data.result_sound_command;
+       *snd_sound_state = asm_snd_gvariant.data.result_sound_state;
+
+       return ret;
+
+}
+
+int _mm_sound_mgr_asm_unregister_watcher(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state, int rcv_resource)
+{
+       ASM_msg_lib_to_asm_t asm_rcv_gvariant;
+       ASM_msg_asm_to_lib_t asm_snd_gvariant;
+       int ret = MM_ERROR_NONE;
+
+       asm_rcv_gvariant.instance_id = rcv_pid;
+       asm_rcv_gvariant.data.handle = rcv_handle;
+       asm_rcv_gvariant.data.sound_event = rcv_sound_event;
+       asm_rcv_gvariant.data.request_id = rcv_request_id;
+       asm_rcv_gvariant.data.sound_state = rcv_sound_state;
+       asm_rcv_gvariant.data.system_resource = rcv_resource;
+
+       ret = __asm_process_message(&asm_rcv_gvariant, &asm_snd_gvariant);
+
+       return ret;
+
+}
+
+int _mm_sound_mgr_asm_get_mystate(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state, int rcv_resource,
+                                        int *snd_pid, int *snd_alloc_handle, int *snd_cmd_handle, int *snd_request_id, int *snd_sound_state)
+{
+       ASM_msg_lib_to_asm_t asm_rcv_gvariant;
+       ASM_msg_asm_to_lib_t asm_snd_gvariant;
+       int ret = MM_ERROR_NONE;
+
+       asm_rcv_gvariant.instance_id = rcv_pid;
+       asm_rcv_gvariant.data.handle = rcv_handle;
+       asm_rcv_gvariant.data.sound_event = rcv_sound_event;
+       asm_rcv_gvariant.data.request_id = rcv_request_id;
+       asm_rcv_gvariant.data.sound_state = rcv_sound_state;
+       asm_rcv_gvariant.data.system_resource = rcv_resource;
+
+       ret = __asm_process_message(&asm_rcv_gvariant, &asm_snd_gvariant);
+
+       *snd_pid = asm_snd_gvariant.instance_id;
+       *snd_alloc_handle = asm_snd_gvariant.data.alloc_handle;
+       *snd_cmd_handle = asm_snd_gvariant.data.cmd_handle;
+       *snd_request_id = asm_snd_gvariant.data.source_request_id;
+       *snd_sound_state = asm_snd_gvariant.data.result_sound_state;
+
+       return ret;
+
+}
+
+int _mm_sound_mgr_asm_get_state(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state, int rcv_resource,
+                                      int *snd_pid, int *snd_alloc_handle, int *snd_cmd_handle, int *snd_request_id, int *snd_sound_state)
+{
+       ASM_msg_lib_to_asm_t asm_rcv_gvariant;
+       ASM_msg_asm_to_lib_t asm_snd_gvariant;
+       int ret = MM_ERROR_NONE;
+
+       asm_rcv_gvariant.instance_id = rcv_pid;
+       asm_rcv_gvariant.data.handle = rcv_handle;
+       asm_rcv_gvariant.data.sound_event = rcv_sound_event;
+       asm_rcv_gvariant.data.request_id = rcv_request_id;
+       asm_rcv_gvariant.data.sound_state = rcv_sound_state;
+       asm_rcv_gvariant.data.system_resource = rcv_resource;
+
+       ret = __asm_process_message(&asm_rcv_gvariant, &asm_snd_gvariant);
+
+       *snd_pid = asm_snd_gvariant.instance_id;
+       *snd_alloc_handle = asm_snd_gvariant.data.alloc_handle;
+       *snd_cmd_handle = asm_snd_gvariant.data.cmd_handle;
+       *snd_request_id = asm_snd_gvariant.data.source_request_id;
+       *snd_sound_state = asm_snd_gvariant.data.result_sound_state;
+
+       return ret;
+
+}
+
+int _mm_sound_mgr_asm_set_state(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state, int rcv_resource,
+                                      int *snd_pid, int *snd_alloc_handle, int *snd_cmd_handle, int *snd_request_id, int *snd_sound_command, int *snd_sound_state, int *snd_error_code)
+{
+       ASM_msg_lib_to_asm_t asm_rcv_gvariant;
+       ASM_msg_asm_to_lib_t asm_snd_gvariant;
+       int ret = MM_ERROR_NONE;
+
+       asm_rcv_gvariant.instance_id = rcv_pid;
+       asm_rcv_gvariant.data.handle = rcv_handle;
+       asm_rcv_gvariant.data.sound_event = rcv_sound_event;
+       asm_rcv_gvariant.data.request_id = rcv_request_id;
+       asm_rcv_gvariant.data.sound_state = rcv_sound_state;
+       asm_rcv_gvariant.data.system_resource = rcv_resource;
+
+       ret = __asm_process_message(&asm_rcv_gvariant, &asm_snd_gvariant);
+
+       *snd_pid = asm_snd_gvariant.instance_id;
+       *snd_alloc_handle = asm_snd_gvariant.data.alloc_handle;
+       *snd_cmd_handle = asm_snd_gvariant.data.cmd_handle;
+       *snd_request_id = asm_snd_gvariant.data.source_request_id;
+       *snd_sound_command = asm_snd_gvariant.data.result_sound_command;
+       *snd_sound_state = asm_snd_gvariant.data.result_sound_state;
+       *snd_error_code = asm_snd_gvariant.data.error_code;
+
+       return ret;
+
+}
+
+int _mm_sound_mgr_asm_set_subsession(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state, int rcv_resource,
+                                           int *snd_pid, int *snd_alloc_handle, int *snd_cmd_handle, int *snd_request_id)
+{
+       ASM_msg_lib_to_asm_t asm_rcv_gvariant;
+       ASM_msg_asm_to_lib_t asm_snd_gvariant;
+       int ret = MM_ERROR_NONE;
+
+       asm_rcv_gvariant.instance_id = rcv_pid;
+       asm_rcv_gvariant.data.handle = rcv_handle;
+       asm_rcv_gvariant.data.sound_event = rcv_sound_event;
+       asm_rcv_gvariant.data.request_id = rcv_request_id;
+       asm_rcv_gvariant.data.sound_state = rcv_sound_state;
+       asm_rcv_gvariant.data.system_resource = rcv_resource;
+
+       ret = __asm_process_message(&asm_rcv_gvariant, &asm_snd_gvariant);
+
+       *snd_pid = asm_snd_gvariant.instance_id;
+       *snd_alloc_handle = asm_snd_gvariant.data.alloc_handle;
+       *snd_cmd_handle = asm_snd_gvariant.data.cmd_handle;
+       *snd_request_id = asm_snd_gvariant.data.source_request_id;
+
+       return ret;
+
+}
+
+int _mm_sound_mgr_asm_get_subsession(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state, int rcv_resource,
+                                           int *snd_pid, int *snd_alloc_handle, int *snd_cmd_handle, int *snd_request_id, int *snd_sound_command)
+{
+       ASM_msg_lib_to_asm_t asm_rcv_gvariant;
+       ASM_msg_asm_to_lib_t asm_snd_gvariant;
+       int ret = MM_ERROR_NONE;
+
+       asm_rcv_gvariant.instance_id = rcv_pid;
+       asm_rcv_gvariant.data.handle = rcv_handle;
+       asm_rcv_gvariant.data.sound_event = rcv_sound_event;
+       asm_rcv_gvariant.data.request_id = rcv_request_id;
+       asm_rcv_gvariant.data.sound_state = rcv_sound_state;
+       asm_rcv_gvariant.data.system_resource = rcv_resource;
+
+       ret = __asm_process_message(&asm_rcv_gvariant, &asm_snd_gvariant);
+
+       *snd_pid = asm_snd_gvariant.instance_id;
+       *snd_alloc_handle = asm_snd_gvariant.data.alloc_handle;
+       *snd_cmd_handle = asm_snd_gvariant.data.cmd_handle;
+       *snd_request_id = asm_snd_gvariant.data.source_request_id;
+       *snd_sound_command = asm_snd_gvariant.data.result_sound_command;
+
+       return ret;
+
+}
+
+int _mm_sound_mgr_asm_set_subevent(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state, int rcv_resource,
+                                         int *snd_pid, int *snd_alloc_handle, int *snd_cmd_handle, int *snd_request_id, int *snd_sound_command, int *snd_sound_state)
+{
+       ASM_msg_lib_to_asm_t asm_rcv_gvariant;
+       ASM_msg_asm_to_lib_t asm_snd_gvariant;
+       int ret = MM_ERROR_NONE;
+
+       asm_rcv_gvariant.instance_id = rcv_pid;
+       asm_rcv_gvariant.data.handle = rcv_handle;
+       asm_rcv_gvariant.data.sound_event = rcv_sound_event;
+       asm_rcv_gvariant.data.request_id = rcv_request_id;
+       asm_rcv_gvariant.data.sound_state = rcv_sound_state;
+       asm_rcv_gvariant.data.system_resource = rcv_resource;
+
+       ret = __asm_process_message(&asm_rcv_gvariant, &asm_snd_gvariant);
+
+       *snd_pid = asm_snd_gvariant.instance_id;
+       *snd_alloc_handle = asm_snd_gvariant.data.alloc_handle;
+       *snd_cmd_handle = asm_snd_gvariant.data.cmd_handle;
+       *snd_request_id = asm_snd_gvariant.data.source_request_id;
+       *snd_sound_command = asm_snd_gvariant.data.result_sound_command;
+       *snd_sound_state = asm_snd_gvariant.data.result_sound_state;
+
+       return ret;
+
+}
+
+int _mm_sound_mgr_asm_get_subevent(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state, int rcv_resource,
+                                         int *snd_pid, int *snd_alloc_handle, int *snd_cmd_handle, int *snd_request_id, int *snd_sound_command)
+{
+       ASM_msg_lib_to_asm_t asm_rcv_gvariant;
+       ASM_msg_asm_to_lib_t asm_snd_gvariant;
+       int ret = MM_ERROR_NONE;
+
+       asm_rcv_gvariant.instance_id = rcv_pid;
+       asm_rcv_gvariant.data.handle = rcv_handle;
+       asm_rcv_gvariant.data.sound_event = rcv_sound_event;
+       asm_rcv_gvariant.data.request_id = rcv_request_id;
+       asm_rcv_gvariant.data.sound_state = rcv_sound_state;
+       asm_rcv_gvariant.data.system_resource = rcv_resource;
+
+       ret = __asm_process_message(&asm_rcv_gvariant, &asm_snd_gvariant);
+
+       *snd_pid = asm_snd_gvariant.instance_id;
+       *snd_alloc_handle = asm_snd_gvariant.data.alloc_handle;
+       *snd_cmd_handle = asm_snd_gvariant.data.cmd_handle;
+       *snd_request_id = asm_snd_gvariant.data.source_request_id;
+       *snd_sound_command = asm_snd_gvariant.data.result_sound_command;
+
+       return ret;
+
+}
+
+int _mm_sound_mgr_asm_set_session_option(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state, int rcv_resource,
+                                               int *snd_pid, int *snd_alloc_handle, int *snd_cmd_handle, int *snd_request_id, int *snd_sound_command, int *snd_error_code)
+{
+       ASM_msg_lib_to_asm_t asm_rcv_gvariant;
+       ASM_msg_asm_to_lib_t asm_snd_gvariant;
+       int ret = MM_ERROR_NONE;
+
+       asm_rcv_gvariant.instance_id = rcv_pid;
+       asm_rcv_gvariant.data.handle = rcv_handle;
+       asm_rcv_gvariant.data.sound_event = rcv_sound_event;
+       asm_rcv_gvariant.data.request_id = rcv_request_id;
+       asm_rcv_gvariant.data.sound_state = rcv_sound_state;
+       asm_rcv_gvariant.data.system_resource = rcv_resource;
+
+       ret = __asm_process_message(&asm_rcv_gvariant, &asm_snd_gvariant);
+
+       *snd_pid = asm_snd_gvariant.instance_id;
+       *snd_alloc_handle = asm_snd_gvariant.data.alloc_handle;
+       *snd_cmd_handle = asm_snd_gvariant.data.cmd_handle;
+       *snd_request_id = asm_snd_gvariant.data.source_request_id;
+       *snd_sound_command = asm_snd_gvariant.data.result_sound_command;
+       *snd_error_code = asm_snd_gvariant.data.error_code;
+
+       return ret;
+
+}
+
+int _mm_sound_mgr_asm_get_session_option(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state, int rcv_resource,
+                                               int *snd_pid, int *snd_alloc_handle, int *snd_cmd_handle, int *snd_request_id, int *snd_sound_command, int *snd_option_flag)
+{
+       ASM_msg_lib_to_asm_t asm_rcv_gvariant;
+       ASM_msg_asm_to_lib_t asm_snd_gvariant;
+       int ret = MM_ERROR_NONE;
+
+       asm_rcv_gvariant.instance_id = rcv_pid;
+       asm_rcv_gvariant.data.handle = rcv_handle;
+       asm_rcv_gvariant.data.sound_event = rcv_sound_event;
+       asm_rcv_gvariant.data.request_id = rcv_request_id;
+       asm_rcv_gvariant.data.sound_state = rcv_sound_state;
+       asm_rcv_gvariant.data.system_resource = rcv_resource;
+
+       ret = __asm_process_message(&asm_rcv_gvariant, &asm_snd_gvariant);
+
+       *snd_pid = asm_snd_gvariant.instance_id;
+       *snd_alloc_handle = asm_snd_gvariant.data.alloc_handle;
+       *snd_cmd_handle = asm_snd_gvariant.data.cmd_handle;
+       *snd_request_id = asm_snd_gvariant.data.source_request_id;
+       *snd_sound_command = asm_snd_gvariant.data.result_sound_command;
+       *snd_option_flag = asm_snd_gvariant.data.error_code;
+
+       return ret;
+
+}
+
+int _mm_sound_mgr_asm_reset_resume_tag(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state, int rcv_resource,
+                                             int *snd_pid, int *snd_alloc_handle, int *snd_cmd_handle, int *snd_request_id, int *snd_sound_command, int *snd_sound_state)
+{
+       ASM_msg_lib_to_asm_t asm_rcv_gvariant;
+       ASM_msg_asm_to_lib_t asm_snd_gvariant;
+       int ret = MM_ERROR_NONE;
+
+       asm_rcv_gvariant.instance_id = rcv_pid;
+       asm_rcv_gvariant.data.handle = rcv_handle;
+       asm_rcv_gvariant.data.sound_event = rcv_sound_event;
+       asm_rcv_gvariant.data.request_id = rcv_request_id;
+       asm_rcv_gvariant.data.sound_state = rcv_sound_state;
+       asm_rcv_gvariant.data.system_resource = rcv_resource;
+
+       ret = __asm_process_message(&asm_rcv_gvariant, &asm_snd_gvariant);
+
+       *snd_pid = asm_snd_gvariant.instance_id;
+       *snd_alloc_handle = asm_snd_gvariant.data.alloc_handle;
+       *snd_cmd_handle = asm_snd_gvariant.data.cmd_handle;
+       *snd_request_id = asm_snd_gvariant.data.source_request_id;
+       *snd_sound_command = asm_snd_gvariant.data.result_sound_command;
+       *snd_sound_state = asm_snd_gvariant.data.error_code;
+
+       return ret;
+
+}
+
+int _mm_sound_mgr_asm_dump(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state, int rcv_resource)
+{
+       ASM_msg_lib_to_asm_t asm_rcv_gvariant;
+       ASM_msg_asm_to_lib_t asm_snd_gvariant;
+       int ret = MM_ERROR_NONE;
+
+       asm_rcv_gvariant.instance_id = rcv_pid;
+       asm_rcv_gvariant.data.handle = rcv_handle;
+       asm_rcv_gvariant.data.sound_event = rcv_sound_event;
+       asm_rcv_gvariant.data.request_id = rcv_request_id;
+       asm_rcv_gvariant.data.sound_state = rcv_sound_state;
+       asm_rcv_gvariant.data.system_resource = rcv_resource;
+
+       ret = __asm_process_message(&asm_rcv_gvariant, &asm_snd_gvariant);
+
+       return ret;
+
+}
+
+int _mm_sound_mgr_asm_emergent_exit(int rcv_pid, int rcv_handle, int rcv_sound_event, int rcv_request_id, int rcv_sound_state)
+{
+       ASM_msg_lib_to_asm_t asm_rcv_gvariant;
+       ASM_msg_asm_to_lib_t asm_snd_gvariant;
+       int ret = MM_ERROR_NONE;
+
+       asm_rcv_gvariant.instance_id = rcv_pid;
+       asm_rcv_gvariant.data.handle = rcv_handle;
+       asm_rcv_gvariant.data.sound_event = rcv_sound_event;
+       asm_rcv_gvariant.data.request_id = rcv_request_id;
+       asm_rcv_gvariant.data.sound_state = rcv_sound_state;
+
+       ret = __asm_process_message(&asm_rcv_gvariant, &asm_snd_gvariant);
+
+       return ret;
+
+}
+
+#ifdef SUPPORT_CONTAINER
+void _mm_sound_mgr_asm_update_container_data(int handle, const char* container_name, int container_pid)
+{
+       __set_container_data(handle, container_name, container_pid);
+       __temp_print_list(NULL);
+}
+#endif
 
 int __asm_process_message (void *rcv_msg, void *ret_msg)
 {
@@ -2948,9 +3395,6 @@ int __asm_process_message (void *rcv_msg, void *ret_msg)
                __asm_get_empty_handle(rcv_instance_id, &rcv_sound_handle);
                if (rcv_sound_handle == ASM_HANDLE_INIT_VAL) {
                        ASM_SND_MSG_SET_DEFAULT(asm_snd_msg, rcv_instance_id, ASM_HANDLE_INIT_VAL, ASM_HANDLE_INIT_VAL, rcv_request_id);
-                       if (asm_ret_msg == NULL) {
-                               __asm_snd_message(&asm_snd_msg);
-                       }
                } else {
                        asm_compare_result_t compare_result = __asm_compare_priority_matrix(&asm_snd_msg, asm_ret_msg,
                                                                        rcv_instance_id, rcv_sound_handle, rcv_request_id, rcv_sound_event, rcv_sound_state, rcv_resource);
@@ -2963,9 +3407,6 @@ int __asm_process_message (void *rcv_msg, void *ret_msg)
                                }
                        }
                        ASM_SND_MSG_SET_DEFAULT(asm_snd_msg, rcv_instance_id, rcv_sound_handle, rcv_sound_handle, rcv_request_id);
-                       if (asm_ret_msg == NULL) {
-                               __asm_snd_message(&asm_snd_msg);
-                       }
                        ASM_DO_WATCH_CALLBACK_FROM_RESULT(compare_result);
                }
 
@@ -3007,18 +3448,12 @@ int __asm_process_message (void *rcv_msg, void *ret_msg)
                                __asm_change_state_list(rcv_instance_id, rcv_sound_handle, rcv_sound_state, rcv_resource);
                                asm_snd_msg.data.result_sound_command = ASM_COMMAND_NONE;
                                asm_snd_msg.data.result_sound_state = rcv_sound_state;
-                               if (asm_ret_msg == NULL && rcv_sound_state == ASM_STATE_PLAYING) {
-                                       __asm_snd_message(&asm_snd_msg);
-                               }
-                       } else if (_mm_sound_is_mute_policy() && (ASM_EVENT_NOTIFY == rcv_sound_event)) {
+                       } else if (mm_sound_util_is_mute_policy() && (ASM_EVENT_NOTIFY == rcv_sound_event)) {
                                /*do not play notify sound in mute profile.*/
                                asm_snd_msg.data.result_sound_command = ASM_COMMAND_STOP;
                                asm_snd_msg.data.result_sound_state   = ASM_STATE_STOP;
                                asm_snd_msg.data.error_code           = ERR_ASM_POLICY_CANNOT_PLAY_BY_PROFILE;
                                __asm_change_state_list(rcv_instance_id, rcv_sound_handle, ASM_STATE_STOP, rcv_resource);
-                               if (asm_ret_msg == NULL) {
-                                       __asm_snd_message(&asm_snd_msg);
-                               }
                                __temp_print_list("Set State (Not Play)");
                                break;
                        } else {
@@ -3034,9 +3469,6 @@ int __asm_process_message (void *rcv_msg, void *ret_msg)
                                                debug_error (" failed to __asm_change_session(), error(0x%x)", ret);
                                        }
                                }
-                               if (asm_ret_msg == NULL && rcv_sound_state == ASM_STATE_PLAYING) {
-                                       __asm_snd_message(&asm_snd_msg);
-                               }
 
                                ASM_DO_WATCH_CALLBACK_FROM_RESULT(compare_result);
                        }
@@ -3096,9 +3528,6 @@ int __asm_process_message (void *rcv_msg, void *ret_msg)
                        asm_snd_msg.data.source_request_id = rcv_request_id;
                }
                ASM_SND_MSG_SET_DEFAULT(asm_snd_msg, rcv_instance_id, rcv_sound_handle, rcv_sound_handle, rcv_request_id);
-               if (asm_ret_msg == NULL) {
-                       __asm_snd_message(&asm_snd_msg);
-               }
                break;
        }
 
@@ -3106,9 +3535,6 @@ int __asm_process_message (void *rcv_msg, void *ret_msg)
                __check_dead_process();
                ASM_SND_MSG_SET_DEFAULT(asm_snd_msg, rcv_instance_id, rcv_sound_handle, rcv_sound_handle, rcv_request_id);
                asm_snd_msg.data.result_sound_state = __asm_find_process_status(rcv_instance_id);
-               if (asm_ret_msg == NULL) {
-                       __asm_snd_message(&asm_snd_msg);
-               }
                break;
 
        case ASM_REQUEST_DUMP:
@@ -3151,7 +3577,7 @@ int __asm_process_message (void *rcv_msg, void *ret_msg)
                                int session_order = -1;
 
                                session_t cur_session;
-                               MMSoundMgrSessionGetSession(&cur_session);
+//                             MMSoundMgrSessionGetSession(&cur_session);
                                debug_warning (" cur_session[%d] (0:MEDIA 1:VC 2:VT 3:VOIP 4:FM 5:NOTI 6:ALARM 7:EMER 8:VR)\n",cur_session);
                                if (cur_session == SESSION_VOICECALL ||
                                        cur_session == SESSION_VIDEOCALL ||
@@ -3171,7 +3597,7 @@ int __asm_process_message (void *rcv_msg, void *ret_msg)
                                        session_order = SESSION_END;
                                }
                                if (session_order != -1) {
-                                       ret = MMSoundMgrSessionSetSession(SESSION_VOICE_RECOGNITION, session_order);
+//                                     ret = MMSoundMgrSessionSetSession(SESSION_VOICE_RECOGNITION, session_order);
                                        if (ret) {
                                                debug_error (" failed to MMSoundMgrSessionSetSession() for VOICE_RECOGNITION\n");
                                                do_set_subsession = false;
@@ -3184,7 +3610,7 @@ int __asm_process_message (void *rcv_msg, void *ret_msg)
                                                }
                                        }
                                }
-                               MMSoundMgrSessionGetSession(&cur_session);
+//                             MMSoundMgrSessionGetSession(&cur_session);
                                debug_msg (" cur_session[%d] : leave", cur_session);
                                break;
                        }
@@ -3194,7 +3620,7 @@ int __asm_process_message (void *rcv_msg, void *ret_msg)
                                int ret = 0;
                                int session_order = -1;
                                session_t cur_session;
-                               MMSoundMgrSessionGetSession(&cur_session);
+//                             MMSoundMgrSessionGetSession(&cur_session);
                                debug_warning (" cur_session[%d] (0:MEDIA 1:VC 2:VT 3:VOIP 4:FM 5:NOTI 6:ALARM 7:EMER 8:VR)\n",cur_session);
                                if (cur_session == SESSION_VOICECALL ||
                                        cur_session == SESSION_VIDEOCALL ||
@@ -3213,13 +3639,13 @@ int __asm_process_message (void *rcv_msg, void *ret_msg)
                                        session_order = SESSION_END;
                                }
                                if (session_order != -1) {
-                                       ret = MMSoundMgrSessionSetSession(SESSION_MEDIA, session_order);
+//                                     ret = MMSoundMgrSessionSetSession(SESSION_MEDIA, session_order);
                                        if (ret) {
                                                debug_error (" failed to MMSoundMgrSessionSetSession() for MMCAMCORDER_AUDIO/VIDEO\n");
                                                do_set_subsession = false;
                                        }
                                }
-                               MMSoundMgrSessionGetSession(&cur_session);
+//                             MMSoundMgrSessionGetSession(&cur_session);
                                debug_msg (" cur_session[%d] : leave", cur_session);
 
                                break;
@@ -3249,7 +3675,7 @@ int __asm_process_message (void *rcv_msg, void *ret_msg)
                                        }
                                }
 
-                               ret = MMSoundMgrSessionSetSubSession(rcv_subsession, result_resource);
+//                             ret = MMSoundMgrSessionSetSubSession(rcv_subsession, result_resource);
                                if (ret != MM_ERROR_NONE) {
                                        /* TODO : Error Handling */
                                        debug_error (" MMSoundMgrSessionSetSubSession failed....ret = [%x]\n", ret);
@@ -3268,9 +3694,6 @@ int __asm_process_message (void *rcv_msg, void *ret_msg)
 
                        /* Return result msg */
                        ASM_SND_MSG_SET_DEFAULT(asm_snd_msg, rcv_instance_id, rcv_sound_handle, rcv_sound_handle, rcv_request_id);
-                       if (asm_ret_msg == NULL) {
-                               __asm_snd_message(&asm_snd_msg);
-                       }
                }
                break;
 
@@ -3280,7 +3703,7 @@ int __asm_process_message (void *rcv_msg, void *ret_msg)
 
                        /* FIXME: have to check only call instance with playing stsate can request this */
                        debug_warning (" ****** GET SUB-SESSION ******\n");
-                       ret = MMSoundMgrSessionGetSubSession(&subsession);
+//                     ret = MMSoundMgrSessionGetSubSession(&subsession);
                        if (ret != MM_ERROR_NONE) {
                                /* TODO : Error Handling */
                                debug_error (" MMSoundMgrSessionGetSubSession failed....ret = [%x]\n", ret);
@@ -3289,9 +3712,6 @@ int __asm_process_message (void *rcv_msg, void *ret_msg)
                        /* Return result msg */
                        asm_snd_msg.data.result_sound_command = subsession;
                        ASM_SND_MSG_SET_DEFAULT(asm_snd_msg, rcv_instance_id, rcv_sound_handle, rcv_sound_handle, rcv_request_id);
-                       if (asm_ret_msg == NULL) {
-                               __asm_snd_message(&asm_snd_msg);
-                       }
                }
                break;
 
@@ -3346,9 +3766,6 @@ int __asm_process_message (void *rcv_msg, void *ret_msg)
                                        debug_error (" failed to __asm_change_session(), error(0x%x)", ret);
                                }
                        }
-                       if (asm_ret_msg == NULL) {
-                               __asm_snd_message(&asm_snd_msg);
-                       }
                }
 
                __temp_print_list("Set Sub-event");
@@ -3360,9 +3777,6 @@ int __asm_process_message (void *rcv_msg, void *ret_msg)
                /* Return result msg */
                asm_instance_h = __asm_find_list(rcv_sound_handle);
                asm_snd_msg.data.result_sound_command = (asm_instance_h ? asm_instance_h->sound_sub_event : ASM_SUB_EVENT_NONE);
-               if (asm_ret_msg == NULL) {
-                       __asm_snd_message(&asm_snd_msg);
-               }
                break;
 
        case ASM_REQUEST_SET_SESSION_OPTIONS:
@@ -3391,9 +3805,6 @@ int __asm_process_message (void *rcv_msg, void *ret_msg)
                }
 
                ASM_SND_MSG_SET_DEFAULT(asm_snd_msg, rcv_instance_id, rcv_sound_handle, rcv_sound_handle, rcv_request_id);
-               if (asm_ret_msg == NULL) {
-                       __asm_snd_message(&asm_snd_msg);
-               }
                break;
        }
 
@@ -3405,9 +3816,6 @@ int __asm_process_message (void *rcv_msg, void *ret_msg)
                if (!asm_instance_h) {
                        asm_snd_msg.data.result_sound_command = ASM_COMMAND_STOP;
                }
-               if (asm_ret_msg == NULL) {
-                       __asm_snd_message(&asm_snd_msg);
-               }
                break;
 
        case ASM_REQUEST_EMERGENT_EXIT:
@@ -3461,16 +3869,10 @@ int __asm_process_message (void *rcv_msg, void *ret_msg)
                __asm_get_empty_handle(rcv_instance_id, &rcv_sound_handle);
                if (rcv_sound_handle == ASM_HANDLE_INIT_VAL) {
                        ASM_SND_MSG_SET_DEFAULT(asm_snd_msg, rcv_instance_id, ASM_HANDLE_INIT_VAL, ASM_HANDLE_INIT_VAL, rcv_request_id);
-                       if (asm_ret_msg == NULL) {
-                               __asm_snd_message(&asm_snd_msg);
-                       }
                } else {
                        ASM_SND_MSG_SET_DEFAULT(asm_snd_msg, rcv_instance_id, rcv_sound_handle, rcv_sound_handle, rcv_request_id);
                        asm_snd_msg.data.result_sound_command = ASM_COMMAND_PLAY;
                        asm_snd_msg.data.result_sound_state = rcv_sound_state;
-                       if (asm_ret_msg == NULL) {
-                               __asm_snd_message(&asm_snd_msg);
-                       }
                        __asm_register_list(rcv_instance_id, rcv_sound_handle, rcv_sound_event, rcv_sound_state, 0, true);
                }
                break;
@@ -3493,9 +3895,6 @@ int __asm_process_message (void *rcv_msg, void *ret_msg)
                ASM_SND_MSG_SET_DEFAULT(asm_snd_msg, rcv_instance_id, rcv_sound_handle, rcv_sound_handle, rcv_request_id);
                asm_snd_msg.data.result_sound_command = ASM_COMMAND_PLAY;
                asm_snd_msg.data.result_sound_state = rcv_sound_state;
-               if (asm_ret_msg == NULL) {
-                       __asm_snd_message(&asm_snd_msg);
-               }
                break;
        }
 
@@ -3510,33 +3909,15 @@ int __asm_process_message (void *rcv_msg, void *ret_msg)
        pthread_mutex_unlock(&g_mutex_asm);
        debug_log (" ===================================================================== End (UNLOCKED) ");
 
-       return 0;
+       return ret;
 }
 
 void __asm_main_run (void* param)
 {
-       ASM_msg_lib_to_asm_t asm_rcv_msg;
+       //ASM_msg_lib_to_asm_t asm_rcv_msg;
 
        signal(SIGPIPE, SIG_IGN);
 
-       /* Init Msg Queue */
-       __asm_create_message_queue();
-
-       int temp_msgctl_id1 = msgctl(asm_snd_msgid, IPC_RMID, 0);
-       int temp_msgctl_id2 = msgctl(asm_rcv_msgid, IPC_RMID, 0);
-       int temp_msgctl_id3 = msgctl(asm_cb_msgid, IPC_RMID, 0);
-
-       if (temp_msgctl_id1 == -1 || temp_msgctl_id2 == -1 || temp_msgctl_id3 == -1) {
-               debug_error(" msgctl failed with error(%d,%s) \n", errno, strerror(errno));
-               exit(EXIT_FAILURE);
-       }
-       //-------------------------------------------------------------------
-       /*
-               This is unnessasry finaly, but nessasary during implement.
-       */
-       /* FIXME: Do we need to do this again ? */
-       __asm_create_message_queue();
-
        /*
         * Init Vconf
         */
@@ -3551,21 +3932,6 @@ void __asm_main_run (void* param)
        if (vconf_set_int(ASM_READY_KEY, 1)) {
                debug_error(" vconf_set_int fail\n");
        }
-
-       /* Msg Loop */
-       while (true) {
-               debug_log(" asm_Server is waiting message(%d)!!!\n", asm_is_send_msg_to_cb);
-               if (asm_is_send_msg_to_cb)
-                       continue;
-
-               /* Receive Msg */
-               __asm_rcv_message(&asm_rcv_msg);
-
-               /* Do msg handling */
-               __asm_process_message (&asm_rcv_msg, NULL);
-
-               /* TODO : Error Handling */
-       }
 }
 
 
index feb1f5a..598de46 100644 (file)
@@ -237,6 +237,8 @@ int MMSoundMgrCodecPlay(int *slotid, const mmsound_mgr_codec_param_t *param)
        codec_param.pid = (int)param->param;
        codec_param.handle_route = param->handle_route;
        codec_param.codec_wave_mutex = &codec_wave_mutex;
+       codec_param.stream_index = param->stream_index;
+       strncpy(codec_param.stream_type, param->stream_type, MM_SOUND_STREAM_TYPE_LEN);
        pthread_mutex_lock(&g_slot_mutex);
 #ifdef DEBUG_DETAIL
        debug_msg("After Slot_mutex LOCK\n");
@@ -283,9 +285,6 @@ int MMSoundMgrCodecPlay(int *slotid, const mmsound_mgr_codec_param_t *param)
 
        /* Codec id WAV or MP3 */
        g_slots[*slotid].pluginid = count;
-       g_slots[*slotid].callback = param->callback;
-       g_slots[*slotid].msgcallback = param->msgcallback;
-       g_slots[*slotid].msgdata = param->msgdata;
        g_slots[*slotid].param    = param->param;               /* This arg is used callback data */
        g_slots[*slotid].session_type = param->session_type;
        g_slots[*slotid].session_options = param->session_options;
@@ -344,6 +343,93 @@ cleanup:
        return err;
 }
 
+int MMSoundMgrCodecPlayWithStreamInfo(int *slotid, const mmsound_mgr_codec_param_t *param)
+{
+       int count = 0;
+       mmsound_codec_info_t info;
+       mmsound_codec_param_t codec_param;
+       int err = MM_ERROR_NONE;
+       int errorcode = 0;
+
+#ifdef DEBUG_DETAIL
+       debug_enter("\n");
+#endif
+
+       for (count = 0; g_plugins[count].GetSupportTypes; count++) {
+               /* Find codec */
+               if (g_plugins[count].Parse(param->source, &info) == MM_ERROR_NONE)
+                       break;
+       }
+
+       /*The count num means codec type WAV, MP3 */
+       debug_msg("Repeat[%d] Volume[%f] plugin_codec[%d]\n", param->repeat_count, param->volume, count);
+
+       if (g_plugins[count].GetSupportTypes == NULL) { /* Codec not found */
+               debug_error("unsupported file type %d\n", count);
+               err = MM_ERROR_SOUND_UNSUPPORTED_MEDIA_TYPE;
+               goto cleanup;
+       }
+
+       err = _MMSoundMgrCodecGetEmptySlot(slotid);
+       if (err != MM_ERROR_NONE) {
+               debug_error("Empty g_slot is not found\n");
+               goto cleanup;
+       }
+
+       codec_param.volume_config = -1; //setting volume config to -1 since using stream info instead of volume type
+       codec_param.repeat_count = param->repeat_count;
+       codec_param.volume = param->volume;
+       codec_param.source = param->source;
+       codec_param.priority = param->priority;
+       codec_param.stop_cb = _MMSoundMgrCodecStopCallback;
+       codec_param.param = *slotid;
+       codec_param.pid = (int)param->param;
+       codec_param.handle_route = param->handle_route;
+       codec_param.codec_wave_mutex = &codec_wave_mutex;
+       codec_param.stream_index = param->stream_index;
+       strncpy(codec_param.stream_type, param->stream_type, MM_SOUND_STREAM_TYPE_LEN);
+       pthread_mutex_lock(&g_slot_mutex);
+#ifdef DEBUG_DETAIL
+       debug_msg("After Slot_mutex LOCK\n");
+#endif
+
+       /* Codec id WAV or MP3 */
+       g_slots[*slotid].pluginid = count;
+       g_slots[*slotid].param    = param->param;               /* This arg is used callback data */
+
+       debug_msg("Using Slotid : [%d] Slot Status : [%d]\n", *slotid, g_slots[*slotid].status);
+
+       err = g_plugins[g_slots[*slotid].pluginid].Create(&codec_param, &info, &(g_slots[*slotid].plughandle));
+       debug_msg("Created audio handle : [%d]\n", g_slots[*slotid].plughandle);
+       if (err != MM_ERROR_NONE) {
+               debug_error("Plugin create fail : 0x%08X\n", err);
+               g_slots[*slotid].status = STATUS_IDLE;
+               pthread_mutex_unlock(&g_slot_mutex);
+               debug_warning("After Slot_mutex UNLOCK\n");
+               goto cleanup;
+       }
+
+       err = g_plugins[g_slots[*slotid].pluginid].Play(g_slots[*slotid].plughandle);
+       if (err != MM_ERROR_NONE) {
+               debug_error("Fail to play : 0x%08X\n", err);
+               g_plugins[g_slots[*slotid].pluginid].Destroy(g_slots[*slotid].plughandle);
+       }
+
+       pthread_mutex_unlock(&g_slot_mutex);
+#ifdef DEBUG_DETAIL
+       debug_msg("After Slot_mutex UNLOCK\n");
+#endif
+
+cleanup:
+
+#ifdef DEBUG_DETAIL
+       debug_leave("\n");
+#endif
+
+       return err;
+
+}
+
 #define DTMF_PLUGIN_COUNT 2
 int MMSoundMgrCodecPlayDtmf(int *slotid, const mmsound_mgr_codec_param_t *param)
 {
@@ -396,6 +482,8 @@ int MMSoundMgrCodecPlayDtmf(int *slotid, const mmsound_mgr_codec_param_t *param)
        codec_param.stop_cb = _MMSoundMgrCodecStopCallback;
        codec_param.param = *slotid;
        codec_param.pid = (int)param->param;
+       codec_param.stream_index = param->stream_index;
+       strncpy(codec_param.stream_type, param->stream_type, MM_SOUND_STREAM_TYPE_LEN);
 
        pthread_mutex_lock(&g_slot_mutex);
 #ifdef DEBUG_DETAIL
@@ -434,7 +522,6 @@ int MMSoundMgrCodecPlayDtmf(int *slotid, const mmsound_mgr_codec_param_t *param)
        }
 
        g_slots[*slotid].pluginid = count;
-       g_slots[*slotid].callback = param->callback;
        g_slots[*slotid].param    = param->param;               /* This arg is used callback data */
        g_slots[*slotid].session_type = param->session_type;
        g_slots[*slotid].session_options = param->session_options;
@@ -490,6 +577,102 @@ cleanup:
        return err;
 }
 
+MMSoundMgrCodecPlayDtmfWithStreamInfo(int *slotid, const mmsound_mgr_codec_param_t *param)
+{
+       int count = 0;
+       int *codec_type;
+       mmsound_codec_info_t info;
+       mmsound_codec_param_t codec_param;
+       int err = MM_ERROR_NONE;
+       int errorcode = 0;
+
+#ifdef DEBUG_DETAIL
+       debug_enter("\n");
+#endif
+
+       for (count = 0; g_plugins[count].GetSupportTypes; count++) {
+               /* Find codec */
+               codec_type = g_plugins[count].GetSupportTypes();
+               if(codec_type && (MM_SOUND_SUPPORTED_CODEC_DTMF == codec_type[0]))
+                       break;
+       }
+
+       /*The count num means codec type DTMF */
+       debug_msg("DTMF[%d] Repeat[%d] Volume[%f] plugin_codec[%d]\n", param->tone, param->repeat_count, param->volume, count);
+
+       if (g_plugins[count].GetSupportTypes == NULL) { /* Codec not found */
+               debug_error("unsupported file type %d\n", count);
+               printf("unsupported file type %d\n", count);
+               err = MM_ERROR_SOUND_UNSUPPORTED_MEDIA_TYPE;
+               goto cleanup;
+       }
+
+#ifdef DEBUG_DETAIL
+       debug_msg("Get New handle\n");
+#endif
+       codec_param.keytone = 0;
+
+       err = _MMSoundMgrCodecGetEmptySlot(slotid);
+       if(err != MM_ERROR_NONE)
+       {
+               debug_error("Empty g_slot is not found\n");
+               goto cleanup;
+       }
+
+       codec_param.tone = param->tone;
+       codec_param.priority = 0;
+       codec_param.repeat_count = param->repeat_count;
+       codec_param.volume = param->volume;
+       codec_param.stop_cb = _MMSoundMgrCodecStopCallback;
+       codec_param.param = *slotid;
+       codec_param.pid = (int)param->param;
+       codec_param.volume_config = -1; //setting volume config to -1 since using stream info instead of volume type
+       codec_param.stream_index = param->stream_index;
+       strncpy(codec_param.stream_type, param->stream_type, MM_SOUND_STREAM_TYPE_LEN);
+
+       pthread_mutex_lock(&g_slot_mutex);
+#ifdef DEBUG_DETAIL
+       debug_msg("After Slot_mutex LOCK\n");
+#endif
+               g_slots[*slotid].pluginid = count;
+               g_slots[*slotid].param    = param->param;               /* This arg is used callback data */
+               g_slots[*slotid].enable_session = param->enable_session;
+
+#ifdef DEBUG_DETAIL
+               debug_msg("Using Slotid : [%d] Slot Status : [%d]\n", *slotid, g_slots[*slotid].status);
+#endif
+
+               err = g_plugins[g_slots[*slotid].pluginid].Create(&codec_param, &info, &(g_slots[*slotid].plughandle));
+               debug_msg("Created audio handle : [%d]\n", g_slots[*slotid].plughandle);
+               if (err != MM_ERROR_NONE) {
+                       debug_error("Plugin create fail : 0x%08X\n", err);
+                       g_slots[*slotid].status = STATUS_IDLE;
+                       pthread_mutex_unlock(&g_slot_mutex);
+                       debug_warning("After Slot_mutex UNLOCK\n");
+                       goto cleanup;
+               }
+
+               err = g_plugins[g_slots[*slotid].pluginid].Play(g_slots[*slotid].plughandle);
+               if (err != MM_ERROR_NONE) {
+                       debug_error("Fail to play : 0x%08X\n", err);
+                       g_plugins[g_slots[*slotid].pluginid].Destroy(g_slots[*slotid].plughandle);
+               }
+
+               pthread_mutex_unlock(&g_slot_mutex);
+
+               debug_msg("Using Slotid : [%d] Slot Status : [%d]\n", *slotid, g_slots[*slotid].status);
+#ifdef DEBUG_DETAIL
+               debug_msg("After Slot_mutex UNLOCK\n");
+#endif
+
+       cleanup:
+#ifdef DEBUG_DETAIL
+               debug_leave("\n");
+#endif
+
+               return err;
+
+}
 
 int MMSoundMgrCodecStop(const int slotid)
 {
@@ -562,12 +745,8 @@ static int _MMSoundMgrCodecStopCallback(int param)
                }
        }
 
-       if (g_slots[param].msgcallback) {
-               debug_msg("[CODEC MGR] msgcallback : %p\n", g_slots[param].msgcallback);
-               debug_msg("[CODEC MGR] msg data : %p\n", g_slots[param].msgdata);
-               debug_msg("[CODEC MGR] mgr codec callback : %p\n", g_slots[param].callback);
-               g_slots[param].callback((int)g_slots[param].param, g_slots[param].msgcallback, g_slots[param].msgdata, param);          /*param means client msg_type */
-       }
+       __mm_sound_mgr_ipc_notify_play_file_end(param);
+
        debug_msg("Client callback msg_type (instance) : [%d]\n", (int)g_slots[param].param);
        debug_msg("Handle allocated handle : [0x%08X]\n", g_slots[param].plughandle);
        err = g_plugins[g_slots[param].pluginid].Destroy(g_slots[param].plughandle);
@@ -733,7 +912,7 @@ static int _MMSoundMgrCodecRegisterInterface(MMSoundPluginType *plugin)
                debug_error("Get Symbol CODEC_GET_INTERFACE_FUNC_NAME is fail : %x\n", err);
                goto cleanup;
        }
-       debug_msg("interface[%s] empty_slot[%d]\n", (char*)getinterface, count);
+       debug_msg("interface[%p] empty_slot[%d]\n", getinterface, count);
 
        err = MMSoundPlugCodecCastGetInterface(getinterface)(&g_plugins[count]);
        if (err != MM_ERROR_NONE) {
index b4cc936..287af97 100644 (file)
@@ -19,6 +19,7 @@
  *
  */
 
+#if 0
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -55,7 +56,7 @@
 #define MAX_SUPPORT_DEVICE_NUM    256
 static char g_device_id_array[MAX_SUPPORT_DEVICE_NUM];
 
-void _mm_sound_get_devices_from_route(mm_sound_route route, mm_sound_device_in *device_in, mm_sound_device_out *device_out);
+void mm_sound_util_get_devices_from_route(mm_sound_route route, mm_sound_device_in *device_in, mm_sound_device_out *device_out);
 
 static GList *g_active_device_cb_list = NULL;
 static pthread_mutex_t g_active_device_cb_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -136,7 +137,7 @@ int _mm_sound_mgr_device_is_route_available(const _mm_sound_mgr_device_param_t *
 
        debug_fenter();
 
-       _mm_sound_get_devices_from_route(route, &device_in, &device_out);
+       mm_sound_util_get_devices_from_route(route, &device_in, &device_out);
 
        /* check given input & output device is available */
        ret = MMSoundMgrSessionIsDeviceAvailable(device_out, device_in, is_available);
@@ -156,12 +157,12 @@ int _mm_sound_mgr_device_foreach_available_route_cb(mm_ipc_msg_t *msg)
 
        debug_fenter();
 
-       route_list_count = _mm_sound_get_valid_route_list(&route_list);
+       route_list_count = mm_sound_util_get_valid_route_list(&route_list);
        for (route_index = 0; route_index < route_list_count; route_index++) {
                mm_sound_device_in device_in = MM_SOUND_DEVICE_IN_NONE;
                mm_sound_device_out device_out = MM_SOUND_DEVICE_OUT_NONE;
 
-               _mm_sound_get_devices_from_route(route_list[route_index], &device_in, &device_out);
+               mm_sound_util_get_devices_from_route(route_list[route_index], &device_in, &device_out);
                /* check input & output device of given route is available */
                ret = MMSoundMgrSessionIsDeviceAvailable(device_out, device_in, &is_available);
                if (ret != MM_ERROR_NONE) {
@@ -184,61 +185,6 @@ FINISH:
        return ret;
 }
 
-int _mm_sound_mgr_device_set_active_route(const _mm_sound_mgr_device_param_t *param)
-{
-       mm_sound_route route = param->route;
-       mm_sound_device_in device_in = MM_SOUND_DEVICE_IN_NONE;
-       mm_sound_device_out device_out = MM_SOUND_DEVICE_OUT_NONE;
-       bool is_available = 0;
-       int ret = MM_ERROR_NONE;
-
-       debug_fenter();
-
-       _mm_sound_get_devices_from_route(route, &device_in, &device_out);
-       /* check specific route is available */
-       ret = _mm_sound_mgr_device_is_route_available(param, &is_available);
-       if ((ret != MM_ERROR_NONE) || (!is_available)) {
-
-       }
-
-       ret = MMSoundMgrSessionSetDeviceActive(device_out, device_in, param->need_broadcast);
-
-       debug_fleave();
-       return ret;
-}
-
-int _mm_sound_mgr_device_set_active_route_auto(void)
-{
-       int ret = MM_ERROR_NONE;
-
-       debug_fenter();
-
-       ret = MMSoundMgrSessionSetDeviceActiveAuto();
-       if (ret != MM_ERROR_NONE) {
-               debug_error("fail to _mm_sound_mgr_device_set_active_route_auto.\n");
-       } else {
-               debug_msg ("success : _mm_sound_mgr_device_set_active_route_auto\n");
-       }
-
-       debug_fleave();
-       return ret;
-}
-int _mm_sound_mgr_device_get_active_device(const _mm_sound_mgr_device_param_t *param, mm_sound_device_in *device_in, mm_sound_device_out *device_out)
-{
-       int ret = MM_ERROR_NONE;
-
-#ifdef DEBUG_DETAIL
-       debug_fenter();
-#endif
-
-       ret = MMSoundMgrSessionGetDeviceActive(device_out, device_in);
-
-#ifdef DEBUG_DETAIL
-       debug_fleave();
-#endif
-       return ret;
-}
-
 int _mm_sound_mgr_device_get_audio_path(mm_sound_device_in *device_in, mm_sound_device_out *device_out)
 {
        int ret = MM_ERROR_NONE;
@@ -255,89 +201,6 @@ int _mm_sound_mgr_device_get_audio_path(mm_sound_device_in *device_in, mm_sound_
        return ret;
 }
 
-int _mm_sound_mgr_device_add_active_device_callback(const _mm_sound_mgr_device_param_t *param)
-{
-       int ret = MM_ERROR_NONE;
-       GList *list = NULL;
-       _mm_sound_mgr_device_param_t *cb_param = NULL;
-       bool is_already_set = FALSE;
-
-#ifdef DEBUG_DETAIL
-       debug_fenter();
-#endif
-
-       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_active_device_cb_mutex, MM_ERROR_SOUND_INTERNAL);
-
-       for (list = g_active_device_cb_list; list != NULL; list = list->next) {
-               cb_param = (_mm_sound_mgr_device_param_t *)list->data;
-               if ((cb_param) && (cb_param->pid == param->pid) && (!strcmp(cb_param->name, param->name))) {
-                       cb_param->callback = param->callback;
-                       cb_param->cbdata = param->cbdata;
-                       is_already_set = TRUE;
-                       break;
-               }
-       }
-
-       if (!is_already_set) {
-               cb_param = g_malloc(sizeof(_mm_sound_mgr_device_param_t));
-               memcpy(cb_param, param, sizeof(_mm_sound_mgr_device_param_t));
-               g_active_device_cb_list = g_list_append(g_active_device_cb_list, cb_param);
-               if (g_active_device_cb_list) {
-                       debug_log("active device cb registered for pid [%d]", cb_param->pid);
-               } else {
-                       debug_error("g_list_append failed\n");
-                       ret = MM_ERROR_SOUND_INTERNAL;
-                       goto FINISH;
-               }
-
-               __mm_sound_mgr_ipc_freeze_send (FREEZE_COMMAND_EXCLUDE, param->pid);
-       }
-
-FINISH:
-       MMSOUND_LEAVE_CRITICAL_SECTION(&g_active_device_cb_mutex);
-#ifdef DEBUG_DETAIL
-       debug_fleave();
-#endif
-       return ret;
-}
-
-int _mm_sound_mgr_device_remove_active_device_callback(const _mm_sound_mgr_device_param_t *param)
-{
-       int ret = MM_ERROR_NONE;
-       GList *list = NULL;
-       bool is_same_pid_exists = false;
-       _mm_sound_mgr_device_param_t *cb_param = NULL;
-
-       debug_fenter();
-
-       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_active_device_cb_mutex, MM_ERROR_SOUND_INTERNAL);
-
-       for (list = g_active_device_cb_list; list != NULL; list = list->next) {
-               cb_param = (_mm_sound_mgr_device_param_t *)list->data;
-               if ((cb_param) && (cb_param->pid == param->pid) && (!strcmp(cb_param->name, param->name))) {
-                       g_active_device_cb_list = g_list_remove(g_active_device_cb_list, cb_param);
-                       g_free(cb_param);
-                       break;
-               }
-       }
-
-       /* Check for PID still exists in the list, if not include freeze */
-       for (list = g_active_device_cb_list; list != NULL; list = list->next) {
-               cb_param = (_mm_sound_mgr_device_param_t *)list->data;
-               if ((cb_param) && (cb_param->pid == param->pid)) {
-                       is_same_pid_exists = true;
-                       break;
-               }
-       }
-       if (!is_same_pid_exists) {
-               __mm_sound_mgr_ipc_freeze_send (FREEZE_COMMAND_INCLUDE, param->pid);
-       }
-       MMSOUND_LEAVE_CRITICAL_SECTION(&g_active_device_cb_mutex);
-
-       debug_fleave();
-       return ret;
-}
-
 int _mm_sound_mgr_device_add_volume_callback(const _mm_sound_mgr_device_param_t *param)
 {
        int ret = MM_ERROR_NONE;
@@ -448,19 +311,126 @@ int __mm_sound_mgr_device_check_process(int pid)
        return exist;
 }
 
-int _mm_sound_mgr_device_get_current_connected_dev_list(const _mm_sound_mgr_device_param_t *param, GList **device_list)
+
+static int __mm_sound_mgr_device_check_flags_to_append (int device_flags, mm_sound_device_t *device_h, bool *is_good_to_append)
+{
+       bool need_to_append = false;
+       int need_to_check_for_io_direction = device_flags & DEVICE_IO_DIRECTION_FLAGS;
+       int need_to_check_for_state = device_flags & DEVICE_STATE_FLAGS;
+       int need_to_check_for_type = device_flags & DEVICE_TYPE_FLAGS;
+
+       debug_warning("device_h[0x%x], device_flags[0x%x], need_to_check(io_direction[0x%x],state[0x%x],type[0x%x])\n",
+                       device_h, device_flags, need_to_check_for_io_direction, need_to_check_for_state, need_to_check_for_type);
+
+       if(!device_h) {
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+       if (device_flags == DEVICE_ALL_FLAG) {
+               *is_good_to_append = true;
+               return MM_ERROR_NONE;
+       }
+
+       if (need_to_check_for_io_direction) {
+               if ((device_h->io_direction == DEVICE_IO_DIRECTION_IN) && (device_flags & DEVICE_IO_DIRECTION_IN_FLAG)) {
+                       need_to_append = true;
+               } else if ((device_h->io_direction == DEVICE_IO_DIRECTION_OUT) && (device_flags & DEVICE_IO_DIRECTION_OUT_FLAG)) {
+                       need_to_append = true;
+               } else if ((device_h->io_direction == DEVICE_IO_DIRECTION_BOTH) && (device_flags & DEVICE_IO_DIRECTION_BOTH_FLAG)) {
+                       need_to_append = true;
+               }
+               if (need_to_append) {
+                       if (!need_to_check_for_state && !need_to_check_for_type) {
+                               *is_good_to_append = true;
+                               return MM_ERROR_NONE;
+                       }
+               } else {
+                       *is_good_to_append = false;
+                       return MM_ERROR_NONE;
+               }
+       }
+       if (need_to_check_for_state) {
+               need_to_append = false;
+               if ((device_h->state == DEVICE_STATE_DEACTIVATED) && (device_flags & DEVICE_STATE_DEACTIVATED_FLAG)) {
+                       need_to_append = true;
+               } else if ((device_h->state == DEVICE_STATE_ACTIVATED) && (device_flags & DEVICE_STATE_ACTIVATED_FLAG)) {
+                       need_to_append = true;
+               }
+               if (need_to_append) {
+                       if (!need_to_check_for_type) {
+                               *is_good_to_append = true;
+                               return MM_ERROR_NONE;
+                       }
+               } else {
+                       *is_good_to_append = false;
+                       return MM_ERROR_NONE;
+               }
+       }
+       if (need_to_check_for_type) {
+               need_to_append = false;
+               bool is_internal_device = IS_INTERNAL_DEVICE(device_h->type);
+               if (is_internal_device && (device_flags & DEVICE_TYPE_INTERNAL_FLAG)) {
+                       need_to_append = true;
+               } else if (!is_internal_device && (device_flags & DEVICE_TYPE_EXTERNAL_FLAG)) {
+                       need_to_append = true;
+               }
+               if (need_to_append) {
+                       *is_good_to_append = true;
+                       return MM_ERROR_NONE;
+               } else {
+                       *is_good_to_append = false;
+                       return MM_ERROR_NONE;
+               }
+       }
+       return MM_ERROR_NONE;
+}
+
+//int _mm_sound_mgr_device_get_current_connected_dev_list(const _mm_sound_mgr_device_param_t *param, GList **device_list)
+int _mm_sound_mgr_device_get_current_connected_dev_list(int device_flags, mm_sound_device_t **device_list, int *dev_num)
 {
        int ret = MM_ERROR_NONE;
-       mm_sound_device_t *device_node = NULL;
+       int _dev_num = 0, dev_idx = 0;
+       int dev_list_match_quary[MAX_SUPPORT_DEVICE_NUM] = {-1,};
+       mm_sound_device_t *device_node = NULL, *_device_node = NULL;
+       GList *list = NULL;
+       bool is_good_to_append = FALSE;
+
 
 #ifdef DEBUG_DETAIL
        debug_fenter();
 #endif
+       _mm_sound_mgr_device_connected_dev_list_dump();
+
+       if (!device_list || !dev_num) {
+               debug_error("Parameter Null");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
        MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_connected_device_list_mutex, MM_ERROR_SOUND_INTERNAL);
 
-       *device_list = g_connected_device_list;
        debug_msg("address of g_connected_device_list[0x%x]", g_connected_device_list);
 
+       for (_dev_num = 0, list = g_connected_device_list; list != NULL; _dev_num++, list = list->next) {
+               _device_node = (mm_sound_device_t *)list->data;
+               if (_device_node) {
+                       __mm_sound_mgr_device_check_flags_to_append(device_flags, _device_node, &is_good_to_append);
+                       if (is_good_to_append) {
+                               debug_warning("[DEBUG] is_good_to_append true : %d", dev_idx);
+                               dev_list_match_quary[dev_idx++] = _dev_num;
+                       }
+               }
+       }
+
+       *device_list = g_malloc(sizeof(mm_sound_device_t)*dev_idx);
+       *dev_num = dev_idx;
+       dev_idx = 0;
+
+       for (_dev_num =0, list = g_connected_device_list; list != NULL; _dev_num++, list = list->next) {
+               _device_node = (mm_sound_device_t *)list->data;
+               if (_device_node && dev_list_match_quary[dev_idx] == _dev_num) {
+                       memcpy(*device_list + dev_idx, _device_node, sizeof(mm_sound_device_t));
+                       dev_idx++;
+               }
+       }
+
 FINISH:
        MMSOUND_LEAVE_CRITICAL_SECTION(&g_connected_device_list_mutex);
 #ifdef DEBUG_DETAIL
@@ -637,26 +607,20 @@ int _mm_sound_mgr_device_remove_info_changed_callback(const _mm_sound_mgr_device
        return ret;
 }
 
-/* debug_warning ("cb_list = %p, cb_param = %p, pid=[%d]", x, cb_param, (cb_param)? cb_param->pid : -1); \ remove logs*/
 #define CLEAR_DEAD_CB_LIST(x)  do { \
-       debug_warning ("cb_list = %p, cb_param = %p, pid=[%d]", x, cb_param, (cb_param)? cb_param->pid : -1); \
-       if (x && cb_param && __mm_sound_mgr_device_check_process (cb_param->pid) != 0) { \
-               debug_warning("PID:%d does not exist now! remove from device cb list\n", cb_param->pid); \
-               g_free (cb_param); \
-               x = g_list_remove (x, cb_param); \
+       if (x && cb_param) { \
+               bool is_exist = mm_sound_util_is_process_alive(cb_param->pid); \
+               debug_msg ("cb_list = %p, cb_param = %p, pid=[%d] : exist[%d]", x, cb_param, cb_param->pid, is_exist); \
+               if (!is_exist) { \
+                       debug_warning("PID:%d does not exist now! remove from device cb list\n", cb_param->pid); \
+                       g_free (cb_param); \
+                       x = g_list_remove (x, cb_param); \
+               } \
+       } else { \
+               debug_error ("Invalid list or param"); \
        } \
 }while(0)
 
-static void _clear_available_cb_list_func (_mm_sound_mgr_device_param_t * cb_param, gpointer user_data)
-{
-       CLEAR_DEAD_CB_LIST(g_available_route_cb_list);
-}
-
-static void _clear_active_cb_list_func (_mm_sound_mgr_device_param_t * cb_param, gpointer user_data)
-{
-       CLEAR_DEAD_CB_LIST(g_active_device_cb_list);
-}
-
 static void _clear_volume_cb_list_func (_mm_sound_mgr_device_param_t * cb_param, gpointer user_data)
 {
        CLEAR_DEAD_CB_LIST(g_volume_cb_list);
@@ -697,25 +661,7 @@ static int _mm_sound_mgr_device_volume_callback(keynode_t* node, void* data)
        }
 
        /* Update list for dead process */
-       g_list_foreach (g_volume_cb_list, (GFunc)_clear_volume_cb_list_func, NULL);
-
-       for (list = g_volume_cb_list; list != NULL; list = list->next) {
-               cb_param = (_mm_sound_mgr_device_param_t *)list->data;
-               if ((cb_param) && (cb_param->callback)) {
-                       memset(&msg, 0, sizeof(mm_ipc_msg_t));
-                       SOUND_MSG_SET(msg.sound_msg, MM_SOUND_MSG_INF_VOLUME_CB, 0, MM_ERROR_NONE, cb_param->pid);
-                       msg.sound_msg.type = type;
-                       msg.sound_msg.val = value;
-                       msg.sound_msg.callback = cb_param->callback;
-                       msg.sound_msg.cbdata = cb_param->cbdata;
-
-                       ret = _MMIpcCBSndMsg(&msg);
-                       if (ret != MM_ERROR_NONE) {
-                               debug_error("Fail to send callback message (%x)\n", ret);
-                               goto FINISH;
-                       }
-               }
-       }
+       __mm_sound_mgr_ipc_notify_volume_changed(type, value);
 
 FINISH:
        MMSOUND_LEAVE_CRITICAL_SECTION(&g_volume_cb_mutex);
@@ -727,105 +673,6 @@ FINISH:
 int _mm_sound_mgr_device_active_device_callback(mm_sound_device_in device_in, mm_sound_device_out device_out)
 {
        int ret = MM_ERROR_NONE;
-       GList *list = NULL;
-       _mm_sound_mgr_device_param_t *cb_param = NULL;
-       mm_ipc_msg_t msg;
-
-       debug_fenter();
-
-       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_active_device_cb_mutex, MM_ERROR_SOUND_INTERNAL);
-
-       /* Update list for dead process */
-        g_list_foreach (g_active_device_cb_list, (GFunc)_clear_active_cb_list_func, NULL);
-
-       for (list = g_active_device_cb_list; list != NULL; list = list->next) {
-               cb_param = (_mm_sound_mgr_device_param_t *)list->data;
-               if ((cb_param) && (cb_param->callback)) {
-                       memset(&msg, 0, sizeof(mm_ipc_msg_t));
-                       SOUND_MSG_SET(msg.sound_msg, MM_SOUND_MSG_INF_ACTIVE_DEVICE_CB, 0, MM_ERROR_NONE, cb_param->pid);
-                       msg.sound_msg.device_in = device_in;
-                       msg.sound_msg.device_out = device_out;
-                       msg.sound_msg.callback = cb_param->callback;
-                       msg.sound_msg.cbdata = cb_param->cbdata;
-
-                       ret = _MMIpcCBSndMsg(&msg);
-                       if (ret != MM_ERROR_NONE) {
-                               debug_error("Fail to send callback message (%x)\n", ret);
-                               goto FINISH;
-                       }
-               }
-       }
-FINISH:
-       MMSOUND_LEAVE_CRITICAL_SECTION(&g_active_device_cb_mutex);
-
-       debug_fleave();
-       return ret;
-}
-
-int _mm_sound_mgr_device_add_available_route_callback(const _mm_sound_mgr_device_param_t *param)
-{
-       int ret = MM_ERROR_NONE;
-       GList *list = NULL;
-       _mm_sound_mgr_device_param_t *cb_param = NULL;
-       bool is_already_set = FALSE;
-
-       debug_fenter();
-
-       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_available_route_cb_mutex, MM_ERROR_SOUND_INTERNAL);
-
-       for (list = g_available_route_cb_list; list != NULL; list = list->next) {
-               cb_param = (_mm_sound_mgr_device_param_t *)list->data;
-               if ((cb_param) && (cb_param->pid == param->pid)) {
-                       cb_param->callback = param->callback;
-                       cb_param->cbdata = param->cbdata;
-                       is_already_set = TRUE;
-                       break;
-               }
-       }
-       if (!is_already_set) {
-               cb_param = g_malloc(sizeof(_mm_sound_mgr_device_param_t));
-               memcpy(cb_param, param, sizeof(_mm_sound_mgr_device_param_t));
-               g_available_route_cb_list = g_list_append(g_available_route_cb_list, cb_param);
-               if (g_available_route_cb_list) {
-                       debug_log("available route cb registered for pid [%d]", cb_param->pid);
-               } else {
-                       debug_error("g_list_append failed\n");
-                       ret = MM_ERROR_SOUND_INTERNAL;
-                       goto FINISH;
-               }
-
-               __mm_sound_mgr_ipc_freeze_send (FREEZE_COMMAND_EXCLUDE, param->pid);
-       }
-FINISH:
-       MMSOUND_LEAVE_CRITICAL_SECTION(&g_available_route_cb_mutex);
-
-       debug_fleave();
-       return ret;
-}
-
-int _mm_sound_mgr_device_remove_available_route_callback(const _mm_sound_mgr_device_param_t *param)
-{
-       int ret = MM_ERROR_NONE;
-       GList *list = NULL;
-       _mm_sound_mgr_device_param_t *cb_param = NULL;
-
-       debug_fenter();
-
-       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_available_route_cb_mutex, MM_ERROR_SOUND_INTERNAL);
-
-       for (list = g_available_route_cb_list; list != NULL; list = list->next) {
-               cb_param = (_mm_sound_mgr_device_param_t *)list->data;
-               if ((cb_param) && (cb_param->pid == param->pid)) {
-                       g_available_route_cb_list = g_list_remove(g_available_route_cb_list, cb_param);
-                       __mm_sound_mgr_ipc_freeze_send (FREEZE_COMMAND_INCLUDE, param->pid);
-                       g_free(cb_param);
-                       break;
-               }
-       }
-
-       MMSOUND_LEAVE_CRITICAL_SECTION(&g_available_route_cb_mutex);
-
-       debug_fleave();
        return ret;
 }
 
@@ -843,116 +690,13 @@ int _mm_sound_mgr_device_set_sound_path_for_active_device(mm_sound_device_out pl
 int _mm_sound_mgr_device_available_device_callback(mm_sound_device_in device_in, mm_sound_device_out device_out, bool available)
 {
        int ret = MM_ERROR_NONE;
-       _mm_sound_mgr_device_param_t *cb_param = NULL;
-       mm_ipc_msg_t msg;
-       int route_list_count = 0;
-       int route_index = 0;
-       int available_count = 0;
-       mm_sound_route *route_list = NULL;
-       GList *list = NULL;
-
-       debug_fenter();
-
-       memset (&msg, 0, sizeof(mm_ipc_msg_t));
-
-       route_list_count = _mm_sound_get_valid_route_list(&route_list);
-       debug_log("in=[%x], out=[%x], route_list_count = [%d], available = [%d]", device_in, device_out, route_list_count, available);
-       for (route_index = 0; route_index < route_list_count; route_index++) {
-               mm_sound_device_in route_device_in = MM_SOUND_DEVICE_IN_NONE;
-               mm_sound_device_out route_device_out = MM_SOUND_DEVICE_OUT_NONE;
-               bool is_changed = 0;
-
-               _mm_sound_get_devices_from_route(route_list[route_index], &route_device_in, &route_device_out);
-
-               if ((device_in != MM_SOUND_DEVICE_IN_NONE) && (device_in == route_device_in)) {
-                       /* device(in&out) changed together & they can be combined as this route */
-                       if ((device_out != MM_SOUND_DEVICE_OUT_NONE) && (device_out == route_device_out)) {
-                               is_changed = 1;
-                       /* device(in) changed & this route has device(in) only */
-                       } else if (route_device_out == MM_SOUND_DEVICE_OUT_NONE) {
-                               is_changed = 1;
-                       /* device(in) changed & this route have device(in&out), we need to check availability of output device of this route */
-                       } else {
-                               MMSoundMgrSessionIsDeviceAvailableNoLock(route_device_out, MM_SOUND_DEVICE_IN_NONE, &is_changed);
-                       }
-               }
-               if ((is_changed == 0) && (device_out != MM_SOUND_DEVICE_OUT_NONE) && (device_out == route_device_out)) {
-                       /* device(out) changed & this route has device(out) only */
-                       if (route_device_in == MM_SOUND_DEVICE_IN_NONE) {
-                               is_changed = 1;
-                       /* device(out) changed & this route have device(in&out), we need to check availability of input device of this route */
-                       } else {
-                               MMSoundMgrSessionIsDeviceAvailableNoLock(MM_SOUND_DEVICE_OUT_NONE, route_device_in, &is_changed);
-                       }
-               }
-               /* add route to avaiable route list */
-               if (is_changed) {
-                       if (available_count >= (sizeof(msg.sound_msg.route_list) / sizeof(int))) {
-                               debug_error("Cannot add available route, list is full\n");
-                               return MM_ERROR_SOUND_INTERNAL;
-                       }
-                       debug_log("route_index [%d] is added to route_list [%d]", route_index, available_count);
-                       msg.sound_msg.route_list[available_count++] = route_list[route_index];
-               }
-       }
-
-       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_available_route_cb_mutex, MM_ERROR_SOUND_INTERNAL);
-
-       /* Update list for dead process */
-       g_list_foreach (g_available_route_cb_list, (GFunc)_clear_available_cb_list_func, NULL);
-
-       for (list = g_available_route_cb_list; list != NULL; list = list->next) {
-               cb_param = (_mm_sound_mgr_device_param_t *)list->data;
-               if ((cb_param) && (cb_param->callback)) {
-                       SOUND_MSG_SET(msg.sound_msg, MM_SOUND_MSG_INF_AVAILABLE_ROUTE_CB, 0, MM_ERROR_NONE, cb_param->pid);
-                       msg.sound_msg.is_available = available;
-                       msg.sound_msg.callback = cb_param->callback;
-                       msg.sound_msg.cbdata = cb_param->cbdata;
-
-                       ret = _MMIpcCBSndMsg(&msg);
-                       if (ret != MM_ERROR_NONE) {
-                               debug_error("Fail to send callback message\n");
-                               goto FINISH;
-                       }
-               }
-       }
-FINISH:
-       MMSOUND_LEAVE_CRITICAL_SECTION(&g_available_route_cb_mutex);
-
-       debug_fleave();
-       return ret;
-}
-
-int _mm_sound_mgr_device_update_volume()
-{
-       int i=0;
-       char* str = NULL;
-       int ret = MM_ERROR_NONE;
-
-       for (i=0; i<VOLUME_TYPE_MAX; i++) {
-               /* Update vconf */
-               str = vconf_get_str(g_volume_vconf[i]);
-               /* FIXME : Need to check history */
-               /*
-               if (vconf_set_str_no_fdatasync(g_volume_vconf[i], str) != 0) {
-                       debug_error("vconf_set_str_no_fdatasync(%s) failed", g_volume_vconf[i]);
-                       ret = MM_ERROR_SOUND_INTERNAL;
-                       continue;
-               }
-               */
-               if(str != NULL) {
-                       free(str);
-                       str = NULL;
-               }
-       }
-
        return ret;
 }
 
 #define RELEASE_DEVICE_INFO_ID(x_id) \
 do { \
-       if (g_device_id_array[x_id] == 1) { \
-               g_device_id_array[x_id] = 0; \
+       if (g_device_id_array[x_id-1] == 1) { \
+               g_device_id_array[x_id-1] = 0; \
        } else { \
                debug_error("could not release the id[%d]\n", x_id); \
        } \
@@ -961,22 +705,22 @@ do { \
 #define SET_DEVICE_INFO_ID_AUTO(x_device_h) \
 do { \
        int device_id = 0; \
-       int cnt = 0; \
+       int cnt = 1; \
        if (!x_device_h) { \
                debug_error("device_h is null, could not set device id"); \
                break; \
        } \
-       for (cnt = 0; cnt < MAX_SUPPORT_DEVICE_NUM; cnt++) { \
-               if (g_device_id_array[cnt] == 0) { \
+       for (cnt = 1; cnt < MAX_SUPPORT_DEVICE_NUM+1; cnt++) { \
+               if (g_device_id_array[cnt-1] == 0) { \
                        break; \
                } \
        } \
-       if (cnt == MAX_SUPPORT_DEVICE_NUM) { \
+       if (cnt == MAX_SUPPORT_DEVICE_NUM+1) { \
                debug_error("could not get a new id, device array is full\n"); \
                device_id = -1; \
        } else { \
                device_id = cnt; \
-               g_device_id_array[cnt] = 1; \
+               g_device_id_array[cnt-1] = 1; \
        } \
        x_device_h->id = device_id; \
 } while(0)
@@ -1162,46 +906,10 @@ int _mm_sound_mgr_device_connected_callback(mm_sound_device_t *device_h, bool is
        bool is_good_to_go = true;
 
        debug_fenter();
+       // need to check this in client
+//     ret = __mm_sound_mgr_device_check_flags_to_trigger (cb_param->device_flags, device_h, &is_good_to_go);
 
-       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_device_connected_cb_mutex, MM_ERROR_SOUND_INTERNAL);
-
-       /* Update list for dead process */
-        g_list_foreach (g_device_connected_cb_list, (GFunc)_clear_device_connected_cb_list_func, NULL);
-
-       for (list = g_device_connected_cb_list; list != NULL; list = list->next) {
-               cb_param = (_mm_sound_mgr_device_param_t *)list->data;
-               if (!cb_param) {
-                       continue;
-               }
-               /* check flags */
-               ret = __mm_sound_mgr_device_check_flags_to_trigger (cb_param->device_flags, device_h, &is_good_to_go);
-               if (!ret && is_good_to_go) {
-                       if (cb_param->callback) {
-                               memset(&msg, 0, sizeof(mm_ipc_msg_t));
-                               SOUND_MSG_SET(msg.sound_msg, MM_SOUND_MSG_INF_DEVICE_CONNECTED_CB, 0, MM_ERROR_NONE, cb_param->pid);
-                               //msg.sound_msg.device_handle = device_h;
-                               memcpy (&(msg.sound_msg.device_handle), device_h, sizeof(mm_sound_device_t));
-                               msg.sound_msg.is_connected = is_connected;
-                               msg.sound_msg.callback = cb_param->callback;
-                               msg.sound_msg.cbdata = cb_param->cbdata;
-
-                               ret = _MMIpcCBSndMsg(&msg);
-                               if (ret != MM_ERROR_NONE) {
-                                       debug_error("Fail to send callback message (%x)\n", ret);
-                                       goto FINISH;
-                               }
-                       }
-               } else {
-                       if (ret) {
-                               debug_error("failed to __mm_sound_mgr_device_check_flags_to_trigger(), ret[0x%x], is_good_to_go[%d]\n", ret, is_good_to_go);
-                       } else {
-                               debug_warning("No need to trigger the callback, is_good_to_go[%d]\n", ret, is_good_to_go);
-                       }
-               }
-       }
-
-FINISH:
-       MMSOUND_LEAVE_CRITICAL_SECTION(&g_device_connected_cb_mutex);
+       __mm_sound_mgr_ipc_notify_device_connected (device_h, is_connected);
 
        debug_fleave();
        return ret;
@@ -1217,40 +925,9 @@ int _mm_sound_mgr_device_info_changed_callback(mm_sound_device_t *device_h, int
 
        debug_fenter();
 
-       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_device_info_changed_cb_mutex, MM_ERROR_SOUND_INTERNAL);
-
-       /* Update list for dead process */
-        g_list_foreach (g_device_info_changed_cb_list, (GFunc)_clear_device_info_changed_cb_list_func, NULL);
-
-       for (list = g_device_info_changed_cb_list; list != NULL; list = list->next) {
-               cb_param = (_mm_sound_mgr_device_param_t *)list->data;
-               if (!cb_param) {
-                       continue;
-               }
-               /* check flags */
-               ret = __mm_sound_mgr_device_check_flags_to_trigger (cb_param->device_flags, device_h, &is_good_to_go);
-               if (!ret && is_good_to_go) {
-                       if (cb_param->callback) {
-                               memset(&msg, 0, sizeof(mm_ipc_msg_t));
-                               SOUND_MSG_SET(msg.sound_msg, MM_SOUND_MSG_INF_DEVICE_INFO_CHANGED_CB, 0, MM_ERROR_NONE, cb_param->pid);
-                               memcpy (&(msg.sound_msg.device_handle), device_h, sizeof(mm_sound_device_t));
-                               msg.sound_msg.changed_device_info_type = changed_info_type;
-                               msg.sound_msg.callback = cb_param->callback;
-                               msg.sound_msg.cbdata = cb_param->cbdata;
-
-                               ret = _MMIpcCBSndMsg(&msg);
-                               if (ret != MM_ERROR_NONE) {
-                                       debug_error("Fail to send callback message (%x)\n", ret);
-                                       goto FINISH;
-                               }
-                       }
-               } else {
-                       debug_error("failed to __mm_sound_mgr_device_check_flags_to_trigger(), ret[0x%x], is_good_to_go[%d]\n", ret, is_good_to_go);
-               }
-       }
-
-FINISH:
-       MMSOUND_LEAVE_CRITICAL_SECTION(&g_device_info_changed_cb_mutex);
+       // need to check this in client
+       // ret = __mm_sound_mgr_device_check_flags_to_trigger (cb_param->device_flags, device_h, &is_good_to_go);
+       __mm_sound_mgr_ipc_notify_device_info_changed (device_h, changed_info_type);
 
        debug_fleave();
        return ret;
@@ -1659,3 +1336,4 @@ int MMSoundMgrDeviceUpdateStatusWithoutNotification (device_update_status_e upda
 
        return MM_ERROR_NONE;
 }
+#endif
index c76b2a2..727d2a8 100644 (file)
@@ -69,6 +69,8 @@
 
 int g_saved_dock_status;
 
+#if 0
+
 static void __dock_sound_finished_cb(void *data , int id)
 {
        bool* is_finish = (bool*)data;
@@ -215,3 +217,4 @@ int MMSoundMgrDockFini(void)
        return MM_ERROR_NONE;
 }
 
+#endif
index 54ad42e..af325c8 100644 (file)
@@ -48,6 +48,7 @@
 
 #include "mm_sound.h"
 
+#if 0
 #define SUPPORT_DBUS_HDMI_AUDIO
 #ifdef SUPPORT_DBUS_HDMI_AUDIO
 
@@ -211,3 +212,4 @@ int MMSoundMgrHdmiFini(void)
        return MM_ERROR_NONE;
 }
 
+#endif
index 8cb7121..af4b1b9 100644 (file)
@@ -58,6 +58,7 @@
 #include <vconf.h>
 #include <vconf-keys.h>
 
+#if 0
 /* earjack status value */
 static void _earjack_status_changed_cb(keynode_t* node, void* data)
 {
@@ -105,3 +106,4 @@ int MMSoundMgrHeadsetFini(void)
        return MM_ERROR_NONE;
 }
 
+#endif
index c36aa4f..300d186 100644 (file)
@@ -49,6 +49,7 @@
 #include <vconf.h>
 #include <vconf-keys.h>
 
+#if 0
 
 /* WFD status value */
 static void _miracast_wfd_status_changed_cb(keynode_t* node, void* data)
@@ -91,4 +92,5 @@ int MMSoundMgrWfdFini(void)
        debug_leave("\n");
        return MM_ERROR_NONE;
 }
+#endif
 
diff --git a/server/mm_sound_mgr_focus.c b/server/mm_sound_mgr_focus.c
new file mode 100644 (file)
index 0000000..9da72f6
--- /dev/null
@@ -0,0 +1,958 @@
+/*
+ * libmm-sound
+ *
+ * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Sangchul Lee <sc11.lee@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+
+#include "include/mm_sound_mgr_focus.h"
+#include "include/mm_sound_thread_pool.h"
+#include "../include/mm_sound_common.h"
+#include "../include/mm_sound_stream.h"
+
+#include <mm_error.h>
+#include <mm_debug.h>
+#include <glib.h>
+#include <poll.h>
+#include <fcntl.h>
+
+#include "include/mm_sound_mgr_ipc.h"
+#include "../include/mm_sound_utils.h"
+#include <sys/time.h>
+#include <sys/stat.h>
+
+static GList *g_focus_node_list = NULL;
+static pthread_mutex_t g_focus_node_list_mutex = PTHREAD_MUTEX_INITIALIZER;
+stream_list_t g_stream_list;
+
+static const char* focus_status_str[] =
+{
+       "DEACTIVATED",
+       "P ACTIVATED",
+       "C ACTIVATED",
+       "B ACTIVATED",
+};
+
+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;
+
+#define CLEAR_DEAD_NODE_LIST(x)  do { \
+       debug_warning ("list = %p, node = %p, pid=[%d]", x, node, (node)? node->pid : -1); \
+       if (x && node && (mm_sound_util_is_process_alive(node->pid) == FALSE)) { \
+               debug_warning("PID:%d does not exist now! remove from device cb list\n", node->pid); \
+               g_free (node); \
+               x = g_list_remove (x, node); \
+       } \
+}while(0)
+
+#ifdef SUPPORT_CONTAINER
+static void __set_container_data(int pid, int handle, const char* container_name, int container_pid)
+{
+       GList *list = NULL;
+       focus_node_t *node = NULL;
+
+       for (list = g_focus_node_list; list != NULL; list = list->next) {
+               node = (focus_node_t *)list->data;
+               if (!node->is_for_watch && node->pid == pid && node->handle_id == handle) {
+                       debug_error("Set container [%s][%d] to handle[%d] instanceID[%d]",
+                                               container_name, container_pid, handle, node->pid);
+                       if (container_name)
+                               strcpy (node->container.name, container_name);
+                       node->container.pid = container_pid;
+                       break;
+               }
+               else if (node->is_for_watch && node->pid == pid) {
+                       debug_error("Set container [%s][%d] to instanceID[%d]",
+                                               container_name, container_pid, pid);
+                       if (container_name)
+                               strcpy (node->container.name, container_name);
+                       node->container.pid = container_pid;
+                       break;
+               }
+       }
+}
+
+static container_info_t* __get_container_info(int instance_id)
+{
+       GList *list = NULL;
+       focus_node_t *node = NULL;
+
+       for (list = g_focus_node_list; list != NULL; list = list->next) {
+               node = (focus_node_t *)list->data;
+               if (node->pid == instance_id) {
+                       return &node->container;
+               }
+       }
+}
+#endif /* SUPPORT_CONTAINER */
+
+static char* __get_focus_pipe_path(int instance_id, int handle, const char* postfix, bool is_watch)
+{
+       gchar* path = NULL;
+       gchar* path2 = NULL;
+
+#ifdef SUPPORT_CONTAINER
+       container_info_t* container_info = __get_container_info(instance_id);
+
+       if (instance_id == container_info->pid) {
+               debug_error ("This might be in the HOST(%s)[%d], let's form normal path",
+                                       container_info->name, instance_id);
+               if (is_watch) {
+                       path = g_strdup_printf("/tmp/FOCUS.%d.wch", instance_id);
+               } else {
+                       path = g_strdup_printf("/tmp/FOCUS.%d.%d", instance_id, handle);
+               }
+       } else {
+               if (is_watch) {
+                       path = g_strdup_printf("/var/lib/lxc/%s/rootfs/tmp/FOCUS.%d.wch",
+                                                                       container_info->name, container_info->pid);
+               } else {
+                       path = g_strdup_printf("/var/lib/lxc/%s/rootfs/tmp/FOCUS.%d.%d",
+                                                                       container_info->name, container_info->pid, handle);
+               }
+       }
+#else
+       if (is_watch) {
+               path = g_strdup_printf("/tmp/FOCUS.%d.wch", instance_id);
+       } else {
+               path = g_strdup_printf("/tmp/FOCUS.%d.%d", instance_id, handle);
+       }
+#endif
+
+       if (postfix) {
+               path2 = g_strconcat(path, postfix, NULL);
+               g_free (path);
+               path = NULL;
+               return path2;
+       }
+
+       return path;
+}
+
+static void _clear_focus_node_list_func (focus_node_t *node, gpointer user_data)
+{
+       CLEAR_DEAD_NODE_LIST(g_focus_node_list);
+}
+
+static int _mm_sound_mgr_focus_get_priority_from_stream_type(int *priority, const char *stream_type)
+{
+       int ret = MM_ERROR_NONE;
+       int i = 0;
+
+       debug_fenter();
+
+       if (priority == NULL || stream_type == NULL) {
+               ret = MM_ERROR_INVALID_ARGUMENT;
+               debug_error("invalid argument, priority[0x%x], stream_type[%s], ret[0x%x]\n", priority, stream_type, ret);
+       } else {
+               for (i = 0; i < AVAIL_STREAMS_MAX; i++) {
+                       if (!strncmp(g_stream_list.stream_types[i], stream_type, strlen(stream_type))) {
+                               *priority = g_stream_list.priorities[i];
+                               break;
+                       }
+               }
+               if (i == AVAIL_STREAMS_MAX) {
+                       ret = MM_ERROR_INVALID_ARGUMENT;
+                       debug_error("not supported stream_type[%s], ret[0x%x]\n", stream_type, ret);
+               } else {
+                       debug_log("[%s] has priority of [%d]\n", stream_type, *priority);
+               }
+       }
+
+       debug_fleave();
+       return ret;
+}
+
+static int _mm_sound_mgr_focus_do_watch_callback(focus_type_e focus_type, focus_command_e command,
+                                                                                               focus_node_t *my_node, _mm_sound_mgr_focus_param_t *param)
+{
+       char *filename = NULL;
+       char *filename2 = NULL;
+       struct timeval time;
+       int starttime = 0;
+       int endtime = 0;
+       int fd_FOCUS_R = -1;
+       int fd_FOCUS = -1;
+       int ret = -1;
+       struct pollfd pfd;
+       int pret = 0;
+       int pollingTimeout = 2500; /* NOTE : This is temporary code, because of Deadlock issues. If you fix that issue, remove this comment */
+
+       GList *list = NULL;
+       focus_node_t *node = NULL;
+
+       int i = 0;
+
+       focus_cb_data cb_data;
+
+       debug_fenter();
+
+       for (list = g_focus_node_list; list != NULL; list = list->next) {
+               node = (focus_node_t *)list->data;
+               if (node == my_node) {
+                       /* skip my own */
+               } else {
+                       if (node->is_for_watch && (node->status & focus_type)) {
+                               memset(&cb_data, 0, sizeof(focus_cb_data));
+                               cb_data.pid = node->pid;
+                               cb_data.handle = node->handle_id;
+                               cb_data.type = focus_type & node->status;
+                               cb_data.state = (command == FOCUS_COMMAND_ACQUIRE) ? !FOCUS_STATUS_DEACTIVATED : FOCUS_STATUS_DEACTIVATED;
+                               MMSOUND_STRNCPY(cb_data.stream_type, my_node->stream_type, MAX_STREAM_TYPE_LEN);
+                               MMSOUND_STRNCPY(cb_data.name, param->option, MM_SOUND_NAME_NUM);
+
+                               /* Set start time */
+                               gettimeofday(&time, NULL);
+                               starttime = time.tv_sec * 1000000 + time.tv_usec;
+
+                               /**************************************
+                                *
+                                * Open callback cmd pipe
+                                *
+                                **************************************/
+                               filename = __get_focus_pipe_path(cb_data.pid, -1, NULL, true);
+                               if ((fd_FOCUS = open(filename, O_WRONLY|O_NONBLOCK)) == -1) {
+                                       debug_error("[CallCB] %s open error\n", filename);
+                                       goto fail;
+                               }
+
+                               /******************************************
+                                *
+                                * Open callback result pipe
+                                * before writing callback cmd to pipe
+                                *
+                                ******************************************/
+                                filename2 = __get_focus_pipe_path(cb_data.pid, -1, "r", true);
+                               if ((fd_FOCUS_R= open(filename2,O_RDONLY|O_NONBLOCK)) == -1) {
+                                       char str_error[256];
+                                       strerror_r (errno, str_error, sizeof(str_error));
+                                       debug_error("[RETCB] Fail to open fifo (%s)\n", str_error);
+                                       goto fail;
+                               }
+                               debug_log(" open return cb %s\n", filename2);
+
+                               /*******************************************
+                                * Write Callback msg
+                                *******************************************/
+                               if (write(fd_FOCUS, &cb_data ,sizeof(cb_data)) == -1) {
+                                       debug_error("[CallCB] %s fprintf error\n", filename);
+                                       goto fail;
+                               }
+
+                               /**************************************
+                                *
+                                * Close callback cmd pipe
+                                *
+                                **************************************/
+                               if (fd_FOCUS != -1) {
+                                       close(fd_FOCUS);
+                                       fd_FOCUS = -1;
+                               }
+                               g_free(filename);
+                               filename = NULL;
+
+                               pfd.fd = fd_FOCUS_R;
+                               pfd.events = POLLIN;
+
+                               /*********************************************
+                                *
+                                * Wait callback result msg
+                                *
+                                ********************************************/
+                               debug_error("[RETCB]wait callback(tid=%d, cmd=%d, timeout=%d)\n", cb_data.pid, command, pollingTimeout);
+                               pret = poll(&pfd, 1, pollingTimeout); /* timeout 7sec */
+                               debug_error("after poll");
+                               if (pret < 0) {
+                                       debug_error("[RETCB]poll failed (%d)\n", pret);
+                                       goto fail;
+                               }
+                               if (pfd.revents & POLLIN) {
+                                       if (read(fd_FOCUS_R, &ret, sizeof(ret)) == -1) {
+                                               debug_error("fscanf error\n");
+                                               goto fail;
+                                       }
+                               }
+
+                               g_free(filename2);
+                               filename2 = NULL;
+
+                               /* Calculate endtime and display*/
+                               gettimeofday(&time, NULL);
+                               endtime = time.tv_sec * 1000000 + time.tv_usec;
+                               debug_error("[RETCB] ASM_CB_END cbtimelab=%3.3f(second), timeout=%d(milli second) (reciever=%d) Return value = (handle_id=%d)\n", ((endtime-starttime)/1000000.), pollingTimeout, cb_data.pid, ret);
+
+                               /**************************************
+                                *
+                                * Close callback result pipe
+                                *
+                                **************************************/
+                               if (fd_FOCUS_R != -1) {
+                                       close(fd_FOCUS_R);
+                                       fd_FOCUS_R = -1;
+                               }
+                       }
+               }
+       }
+       debug_fleave();
+       return MM_ERROR_NONE;
+
+fail:
+       if (filename) {
+               g_free (filename);
+               filename = NULL;
+       }
+       if (filename2) {
+               g_free (filename2);
+               filename2 = NULL;
+       }
+       if (fd_FOCUS != -1) {
+               close(fd_FOCUS);
+               fd_FOCUS = -1;
+       }
+       if (fd_FOCUS_R != -1) {
+               close (fd_FOCUS_R);
+               fd_FOCUS_R = -1;
+       }
+       debug_fleave();
+       return -1;
+}
+
+int _mm_sound_mgr_focus_do_callback(focus_command_e command, focus_node_t *victim_node, _mm_sound_mgr_focus_param_t *assaulter_param, const char *assaulter_stream_type)
+{
+       char *filename = NULL;
+       char *filename2 = NULL;
+       struct timeval time;
+       int starttime = 0;
+       int endtime = 0;
+       int fd_FOCUS_R = -1;
+       int fd_FOCUS = -1;
+       int ret = -1;
+       struct pollfd pfd;
+       int pret = 0;
+       int pollingTimeout = 2500; /* NOTE : This is temporary code, because of Deadlock issues. If you fix that issue, remove this comment */
+
+       int i = 0;
+       int flag_for_focus_type = 0;
+       int flag_for_taken_index = 0;
+       int taken_pid = 0;
+       int taken_hid = 0;
+
+       focus_cb_data cb_data;
+
+       debug_error(" __mm_sound_mgr_focus_do_callback_ for pid(%d) handle(%d)\n", victim_node->pid, victim_node->handle_id);
+
+       memset(&cb_data, 0, sizeof(focus_cb_data));
+       cb_data.pid= victim_node->pid;
+       cb_data.handle= victim_node->handle_id;
+       if (command == FOCUS_COMMAND_RELEASE) {
+               /* client will lost the acquired focus */
+               cb_data.type= assaulter_param->request_type & victim_node->status;
+               cb_data.state= FOCUS_STATUS_DEACTIVATED;
+       } else {
+               /* client will gain the lost focus */
+               for (i = 0; i < NUM_OF_STREAM_IO_TYPE; i++) {
+                       if ((victim_node->taken_by_id[i].pid == assaulter_param->pid) && (victim_node->taken_by_id[i].handle_id == assaulter_param->handle_id)) {
+                               flag_for_focus_type |= i+1; /* playback:1, capture:2 */
+                       }
+               }
+               cb_data.type = flag_for_focus_type & assaulter_param->request_type;
+               cb_data.state = !FOCUS_STATUS_DEACTIVATED;
+       }
+       MMSOUND_STRNCPY(cb_data.stream_type, assaulter_stream_type, MAX_STREAM_TYPE_LEN);
+       MMSOUND_STRNCPY(cb_data.name, assaulter_param->option, MM_SOUND_NAME_NUM);
+
+       /* Set start time */
+       gettimeofday(&time, NULL);
+       starttime = time.tv_sec * 1000000 + time.tv_usec;
+
+       /**************************************
+        *
+        * Open callback cmd pipe
+        *
+        **************************************/
+       filename = __get_focus_pipe_path(cb_data.pid, cb_data.handle, NULL, false);
+       if ((fd_FOCUS = open(filename, O_WRONLY|O_NONBLOCK)) == -1) {
+               debug_error("[CallCB] %s open error\n", filename);
+               goto fail;
+       }
+
+       /******************************************
+        *
+        * Open callback result pipe
+        * before writing callback cmd to pipe
+        *
+        ******************************************/
+       filename2 = __get_focus_pipe_path(cb_data.pid, cb_data.handle, "r", false);
+       if ((fd_FOCUS_R = open(filename2,O_RDONLY|O_NONBLOCK)) == -1) {
+               char str_error[256];
+               strerror_r (errno, str_error, sizeof(str_error));
+               debug_error("[RETCB] Fail to open fifo (%s)\n", str_error);
+               goto fail;
+       }
+       debug_log(" open return cb %s\n", filename2);
+
+
+       /*******************************************
+        * Write Callback msg
+        *******************************************/
+       if (write(fd_FOCUS, &cb_data, sizeof(cb_data)) == -1) {
+               debug_error("[CallCB] %s write error\n", filename);
+               goto fail;
+       }
+       /**************************************
+        *
+        * Close callback cmd pipe
+        *
+        **************************************/
+       if (fd_FOCUS != -1) {
+               close(fd_FOCUS);
+               fd_FOCUS = -1;
+       }
+       g_free(filename);
+       filename = NULL;
+
+       pfd.fd = fd_FOCUS_R;
+       pfd.events = POLLIN;
+
+       /*********************************************
+        *
+        * Wait callback result msg
+        *
+        ********************************************/
+       debug_error("[RETCB]wait callback(tid=%d, handle=%d, cmd=%d, timeout=%d)\n",cb_data.pid, cb_data.handle, command, pollingTimeout);
+       pret = poll(&pfd, 1, pollingTimeout);
+       if (pret < 0) {
+               debug_error("[RETCB]poll failed (%d)\n", pret);
+               goto fail;
+       }
+       if (pfd.revents & POLLIN) {
+               if (read(fd_FOCUS_R, &ret, sizeof(ret)) == -1) {
+                       debug_error("read error\n");
+                       goto fail;
+               }
+       }
+       g_free(filename2);
+       filename2 = NULL;
+
+       /* Calculate endtime and display*/
+       gettimeofday(&time, NULL);
+       endtime = time.tv_sec * 1000000 + time.tv_usec;
+       debug_error("[RETCB] ASM_CB_END cbtimelab=%3.3f(second), timeout=%d(milli second) (reciever=%d) Return value = (handle_id=%d)\n", ((endtime-starttime)/1000000.), pollingTimeout, cb_data.pid, ret);
+
+       /**************************************
+        *
+        * Close callback result pipe
+        *
+        **************************************/
+       if (fd_FOCUS_R != -1) {
+               close(fd_FOCUS_R);
+               fd_FOCUS_R = -1;
+       }
+       //debug_log("[RETCB] Return value 0x%x\n", buf);
+
+       /* update victim node */
+       taken_pid = (command == FOCUS_COMMAND_RELEASE) ? assaulter_param->pid : 0;
+       taken_hid = (command == FOCUS_COMMAND_RELEASE) ? assaulter_param->handle_id : 0;
+       flag_for_taken_index = (command == FOCUS_COMMAND_RELEASE) ? assaulter_param->request_type & victim_node->status : assaulter_param->request_type;
+       for (i = 0; i < NUM_OF_STREAM_IO_TYPE; i++) {
+               if (flag_for_taken_index & (i+1)) {
+                       if (command == FOCUS_COMMAND_ACQUIRE && (victim_node->taken_by_id[i].pid != assaulter_param->pid || victim_node->taken_by_id[i].handle_id != assaulter_param->handle_id)) {
+                               /* skip */
+                               continue;
+                       }
+                       victim_node->taken_by_id[i].pid = taken_pid;
+                       victim_node->taken_by_id[i].handle_id = taken_hid;
+               }
+       }
+       if(ret == victim_node->handle_id) {
+               /* return from client is success, ret will be its handle_id */
+               victim_node->status = (command == FOCUS_COMMAND_RELEASE) ? (victim_node->status &= ~(cb_data.type)) : (victim_node->status |= cb_data.type);
+       } else {
+               victim_node->status = FOCUS_STATUS_DEACTIVATED;
+       }
+
+       if (strncmp(assaulter_stream_type, victim_node->stream_type, MAX_STREAM_TYPE_LEN))
+               _mm_sound_mgr_focus_do_watch_callback((focus_type_e)assaulter_param->request_type, command, victim_node, assaulter_param);
+
+
+       return MM_ERROR_NONE;
+
+fail:
+       if (filename) {
+               g_free (filename);
+               filename = NULL;
+       }
+       if (filename2) {
+               g_free (filename2);
+               filename2 = NULL;
+       }
+       if (fd_FOCUS != -1) {
+               close(fd_FOCUS);
+               fd_FOCUS = -1;
+       }
+       if (fd_FOCUS_R != -1) {
+               close (fd_FOCUS_R);
+               fd_FOCUS_R = -1;
+       }
+
+       return -1;
+}
+
+static int _mm_sound_mgr_focus_list_dump ()
+{
+       int ret = MM_ERROR_NONE;
+       GList *list = NULL;
+       focus_node_t *node = NULL;
+
+       debug_log("============================================ focus node list : start ===============================================\n");
+       for (list = g_focus_node_list; list != NULL; list = list->next) {
+               node = (focus_node_t *)list->data;
+               if (node && !node->is_for_watch) {
+                       debug_log("*** pid[%5d]/handle_id[%d]/[%15s]: priority[%2d], status[%s], taken_by[P(%5d/%2d)C(%5d/%2d)]\n",
+                                       node->pid, node->handle_id, node->stream_type, node->priority, focus_status_str[node->status],
+                                       node->taken_by_id[0].pid, node->taken_by_id[0].handle_id, node->taken_by_id[1].pid, node->taken_by_id[1].handle_id);
+               }
+       }
+       debug_log("============================================ focus node list : end =================================================\n");
+
+       return ret;
+}
+
+static int _mm_sound_mgr_focus_watch_list_dump ()
+{
+       int ret = MM_ERROR_NONE;
+       GList *list = NULL;
+       focus_node_t *node = NULL;
+
+       debug_log("========================================== focus watch node list : start =============================================\n");
+       for (list = g_focus_node_list; list != NULL; list = list->next) {
+               node = (focus_node_t *)list->data;
+               if (node && node->is_for_watch) {
+                       debug_log("*** pid[%5d]/handle_id[%d]/watch on focus status[%s]\n", node->pid, node->handle_id, focus_status_str[node->status]);
+               }
+       }
+       debug_log("========================================== focus watch node list : end ===============================================\n");
+
+       return ret;
+}
+
+static void _mm_sound_mgr_focus_fill_info_from_msg (focus_node_t *node, const _mm_sound_mgr_focus_param_t *msg)
+{
+       debug_fenter();
+       node->pid = msg->pid;
+       node->handle_id = msg->handle_id;
+       node->callback = msg->callback;
+       node->cbdata = msg->cbdata;
+#ifdef SUPPORT_CONTAINER
+       memset (&node->container, 0, sizeof (container_info_t));
+       strcpy(node->container.name, "NONAME");
+       node->container.pid = msg->pid;
+#endif
+
+       debug_fleave();
+       return;
+}
+
+#ifdef SUPPORT_CONTAINER
+void _mm_sound_mgr_focus_update_container_data(int pid,int handle, const char* container_name, int container_pid)
+{
+       __set_container_data(pid, handle, container_name, container_pid);
+       //__temp_print_list(NULL);
+}
+#endif
+
+int mm_sound_mgr_focus_create_node (const _mm_sound_mgr_focus_param_t *param)
+{
+       int ret = MM_ERROR_NONE;
+       GList *list = NULL;
+       focus_node_t *node = NULL;
+       int priority = 0;
+
+       debug_fenter();
+
+       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_focus_node_list_mutex, MM_ERROR_SOUND_INTERNAL);
+
+       /* Update list for dead process */
+       g_list_foreach (g_focus_node_list, (GFunc)_clear_focus_node_list_func, NULL);
+
+       for (list = g_focus_node_list; list != NULL; list = list->next) {
+               node = (focus_node_t *)list->data;
+               if (node && !node->is_for_watch && (node->pid == param->pid) && (node->handle_id == param->handle_id)) {
+                       debug_error("the node of pid[%d]/handle_id[%d] is already created\n", param->pid, param->handle_id);
+                       ret = MM_ERROR_INVALID_ARGUMENT;
+                       goto FINISH;
+               }
+       }
+
+       /* get priority from stream type */
+       ret = _mm_sound_mgr_focus_get_priority_from_stream_type(&priority, param->stream_type);
+       if (ret) {
+               goto FINISH;
+       }
+       node = g_malloc0(sizeof(focus_node_t));
+
+       /* fill up information to the node */
+       _mm_sound_mgr_focus_fill_info_from_msg(node, param);
+       node->priority = priority;
+       node->status = FOCUS_STATUS_DEACTIVATED;
+       MMSOUND_STRNCPY(node->stream_type, param->stream_type, MAX_STREAM_TYPE_LEN);
+
+       g_focus_node_list = g_list_append(g_focus_node_list, node);
+       if (g_focus_node_list) {
+               debug_log("new focus node is added\n");
+       } else {
+               debug_error("g_list_append failed\n");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               g_free(node);
+       }
+
+       _mm_sound_mgr_focus_list_dump();
+FINISH:
+       MMSOUND_LEAVE_CRITICAL_SECTION(&g_focus_node_list_mutex);
+
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_mgr_focus_destroy_node (const _mm_sound_mgr_focus_param_t *param)
+{
+       int ret = MM_ERROR_SOUND_INTERNAL;
+       GList *list = NULL;
+       focus_node_t *node = NULL;
+       int i = 0;
+
+       debug_fenter();
+
+       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_focus_node_list_mutex, MM_ERROR_SOUND_INTERNAL);
+
+       /* Update list for dead process */
+       g_list_foreach (g_focus_node_list, (GFunc)_clear_focus_node_list_func, NULL);
+
+       for (list = g_focus_node_list; list != NULL; list = list->next) {
+               node = (focus_node_t *)list->data;
+               if (node && !node->is_for_watch && (node->pid == param->pid) && (node->handle_id == param->handle_id)) {
+                       debug_log("found the node of pid[%d]/handle_id[%d]\n", param->pid, param->handle_id);
+                       g_focus_node_list = g_list_remove(g_focus_node_list, node);
+                       g_free(node);
+                       ret = MM_ERROR_NONE;
+                       break;
+               }
+       }
+       if (list == NULL) {
+               debug_error("could not find any node of pid[%d]/handle_id[%d]\n", param->pid, param->handle_id);
+               ret = MM_ERROR_INVALID_ARGUMENT;
+               goto FINISH;
+       }
+       for (list = g_focus_node_list; list != NULL; list = list->next) {
+               node = (focus_node_t *)list->data;
+               for (i = 0; i < NUM_OF_STREAM_IO_TYPE; i++) {
+                       if (node && (node->taken_by_id[i].pid == param->pid && node->taken_by_id[i].handle_id == param->handle_id)) {
+                               node->taken_by_id[i].pid = 0;
+                               node->taken_by_id[i].handle_id = 0;
+                       }
+               }
+       }
+       _mm_sound_mgr_focus_list_dump();
+FINISH:
+       MMSOUND_LEAVE_CRITICAL_SECTION(&g_focus_node_list_mutex);
+
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_mgr_focus_request_acquire (const _mm_sound_mgr_focus_param_t *param)
+{
+       int ret = MM_ERROR_NONE;
+       GList *list = NULL;
+       focus_node_t *node = NULL;
+       focus_node_t *my_node = NULL;
+       bool need_to_trigger = false;
+       bool need_to_trigger_watch_cb = true;
+
+       debug_fenter();
+
+       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_focus_node_list_mutex, MM_ERROR_SOUND_INTERNAL);
+
+       /* Update list for dead process */
+       g_list_foreach (g_focus_node_list, (GFunc)_clear_focus_node_list_func, NULL);
+
+       for (list = g_focus_node_list; list != NULL; list = list->next) {
+               node = (focus_node_t *)list->data;
+               if (node && !node->is_for_watch && (node->pid == param->pid) && (node->handle_id == param->handle_id)) {
+                       my_node = node;
+                       if ((my_node->status > FOCUS_STATUS_DEACTIVATED) && (my_node->status & param->request_type)) {
+                               ret = MM_ERROR_SOUND_INVALID_STATE;
+                               goto FINISH;
+                       }
+               }
+       }
+
+       if (my_node == NULL) {
+               ret = MM_ERROR_INVALID_ARGUMENT;
+               goto FINISH;
+       }
+
+       /* check if the priority of any node is higher than its based on io direction */
+       for (list = g_focus_node_list; list != NULL; list = list->next) {
+               node = (focus_node_t *)list->data;
+               if (my_node == node || node->is_for_watch) {
+                       /* skip */
+               } else if (node && (param->request_type == FOCUS_TYPE_BOTH || node->status == FOCUS_STATUS_ACTIVATED_BOTH ||
+                                       (node->status & param->request_type))) {
+                       if (node->status > FOCUS_STATUS_DEACTIVATED) {
+                               if ((my_node->priority < node->priority)) {
+                                       ret = MM_ERROR_POLICY_BLOCKED;
+                                       need_to_trigger = false;
+                                       break;
+                               } else {
+                                       need_to_trigger = true;
+                               }
+                       }
+               }
+       }
+
+       if (need_to_trigger) {
+               for (list = g_focus_node_list; list != NULL; list = list->next) {
+                       node = (focus_node_t *)list->data;
+                       if (node == my_node || node->is_for_watch) {
+                               /* skip */
+                       } else if (node && (param->request_type == FOCUS_TYPE_BOTH || node->status == FOCUS_STATUS_ACTIVATED_BOTH ||
+                                       (node->status & param->request_type))) {
+                               if (node->status > FOCUS_STATUS_DEACTIVATED) {
+                                       if (my_node->priority >= node->priority) {
+                                               /* do callback for interruption */
+                                               ret = _mm_sound_mgr_focus_do_callback(FOCUS_COMMAND_RELEASE, node, param, my_node->stream_type);
+                                               if (ret) {
+                                                       debug_error("Fail to _focus_do_callback for COMMAND RELEASE to node[%x], ret[0x%x]\n", node, ret);
+                                                       /* but, keep going */
+                                                       ret = MM_ERROR_NONE;
+                                               }
+                                               if (!strncmp(my_node->stream_type, node->stream_type, MAX_STREAM_TYPE_LEN)) {
+                                                       need_to_trigger_watch_cb = false;
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+
+       if (ret != MM_ERROR_POLICY_BLOCKED) {
+               /* update status */
+               my_node->status |= param->request_type;
+               /* do watch callback due to the status of mine */
+               if (need_to_trigger_watch_cb)
+                       _mm_sound_mgr_focus_do_watch_callback((focus_type_e)param->request_type, FOCUS_COMMAND_ACQUIRE, my_node, param);
+       }
+       _mm_sound_mgr_focus_list_dump();
+       _mm_sound_mgr_focus_watch_list_dump ();
+FINISH:
+       MMSOUND_LEAVE_CRITICAL_SECTION(&g_focus_node_list_mutex);
+
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_mgr_focus_request_release (const _mm_sound_mgr_focus_param_t *param)
+{
+       int ret = MM_ERROR_NONE;
+       GList *list = NULL;
+       focus_node_t *node = NULL;
+       focus_node_t *my_node = NULL;
+       bool need_to_trigger_watch_cb = true;
+
+       debug_fenter();
+
+       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_focus_node_list_mutex, MM_ERROR_SOUND_INTERNAL);
+
+       /* Update list for dead process */
+       g_list_foreach (g_focus_node_list, (GFunc)_clear_focus_node_list_func, NULL);
+
+       for (list = g_focus_node_list; list != NULL; list = list->next) {
+               node = (focus_node_t *)list->data;
+               if (node && !node->is_for_watch && (node->pid == param->pid) && (node->handle_id == param->handle_id)) {
+                       my_node = node;
+                       if (my_node->status == FOCUS_STATUS_DEACTIVATED) {
+                               ret = MM_ERROR_SOUND_INVALID_STATE;
+                               goto FINISH;
+                       } else if ((my_node->status != FOCUS_STATUS_ACTIVATED_BOTH) && (my_node->status != param->request_type)) {
+                               ret = MM_ERROR_SOUND_INVALID_STATE;
+                               goto FINISH;
+                       }
+               }
+       }
+
+       if (my_node == NULL) {
+               ret = MM_ERROR_INVALID_ARGUMENT;
+               goto FINISH;
+       }
+
+       for (list = g_focus_node_list; list != NULL; list = list->next) {
+               node = (focus_node_t *)list->data;
+               if (node == my_node || node->is_for_watch) {
+                       /* skip */
+               } else {
+                       int i = 0;
+                       for (i = 0; i < NUM_OF_STREAM_IO_TYPE; i++) {
+                               if (param->request_type & (i+1)) {
+                                       if (node && (node->taken_by_id[i].pid == param->pid && node->taken_by_id[i].handle_id == param->handle_id)) {
+                                               /* do callback for resumption */
+                                               ret = _mm_sound_mgr_focus_do_callback(FOCUS_COMMAND_ACQUIRE, node, param, my_node->stream_type);
+                                               if (ret) {
+                                                       debug_error("Fail to _focus_do_callback for COMMAND ACQUIRE to node[%x], ret[0x%x]\n", node, ret);
+                                               }
+                                               if (!strncmp(my_node->stream_type, node->stream_type, MAX_STREAM_TYPE_LEN)) {
+                                                       need_to_trigger_watch_cb = false;
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+       /* update status */
+       my_node->status &= ~(param->request_type);
+       /* do watch callback due to the status of mine */
+       if (need_to_trigger_watch_cb)
+               _mm_sound_mgr_focus_do_watch_callback((focus_type_e)param->request_type, FOCUS_COMMAND_RELEASE, my_node, param);
+
+       _mm_sound_mgr_focus_list_dump();
+       _mm_sound_mgr_focus_watch_list_dump ();
+FINISH:
+       MMSOUND_LEAVE_CRITICAL_SECTION(&g_focus_node_list_mutex);
+
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_mgr_focus_set_watch_cb (const _mm_sound_mgr_focus_param_t *param)
+{
+       int ret = MM_ERROR_NONE;
+       GList *list = NULL;
+       focus_node_t *node = NULL;
+
+       debug_fenter();
+
+       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_focus_node_list_mutex, MM_ERROR_SOUND_INTERNAL);
+
+       /* Update list for dead process */
+       g_list_foreach (g_focus_node_list, (GFunc)_clear_focus_node_list_func, NULL);
+
+       for (list = g_focus_node_list; list != NULL; list = list->next) {
+               node = (focus_node_t *)list->data;
+               if (node && (node->pid == param->pid) && (node->handle_id == param->handle_id) && node->is_for_watch) {
+                       debug_error("the node of pid[%d]/handle_id[%d] for watch focus is already created\n", param->pid, param->handle_id);
+                       ret = MM_ERROR_INVALID_ARGUMENT;
+                       goto FINISH;
+               }
+       }
+
+       node = g_malloc0(sizeof(focus_node_t));
+
+       /* fill up information to the node */
+       _mm_sound_mgr_focus_fill_info_from_msg(node, param);
+       node->is_for_watch = true;
+       node->status = param->request_type;
+
+       g_focus_node_list = g_list_append(g_focus_node_list, node);
+       if (g_focus_node_list) {
+               debug_log("new focus node is added\n");
+       } else {
+               debug_error("g_list_append failed\n");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               g_free(node);
+       }
+
+       _mm_sound_mgr_focus_watch_list_dump();
+FINISH:
+       MMSOUND_LEAVE_CRITICAL_SECTION(&g_focus_node_list_mutex);
+
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_mgr_focus_unset_watch_cb (const _mm_sound_mgr_focus_param_t *param)
+{
+       int ret = MM_ERROR_SOUND_INTERNAL;
+       GList *list = NULL;
+       focus_node_t *node = NULL;
+
+       debug_fenter();
+
+       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_focus_node_list_mutex, MM_ERROR_SOUND_INTERNAL);
+
+       /* Update list for dead process */
+       g_list_foreach (g_focus_node_list, (GFunc)_clear_focus_node_list_func, NULL);
+
+       for (list = g_focus_node_list; list != NULL; list = list->next) {
+               node = (focus_node_t *)list->data;
+               if (node && (node->pid == param->pid) && (node->handle_id == param->handle_id) && (node->is_for_watch)) {
+                       debug_log("found the node of pid[%d]/handle_id[%d] for watch focus\n", param->pid, param->handle_id);
+                       g_focus_node_list = g_list_remove(g_focus_node_list, node);
+                       g_free(node);
+                       ret = MM_ERROR_NONE;
+                       break;
+               }
+       }
+       if (list == NULL) {
+               debug_error("could not find any node of pid[%d]/handle_id[%d] for watch focus\n", param->pid, param->handle_id);
+               ret = MM_ERROR_INVALID_ARGUMENT;
+               goto FINISH;
+       }
+
+       _mm_sound_mgr_focus_watch_list_dump();
+FINISH:
+       MMSOUND_LEAVE_CRITICAL_SECTION(&g_focus_node_list_mutex);
+
+       debug_fleave();
+       return ret;
+}
+
+int MMSoundMgrFocusInit(void)
+{
+       int ret = MM_ERROR_NONE;
+       debug_fenter();
+
+       ret = __mm_sound_mgr_ipc_dbus_get_stream_list(&g_stream_list);
+       if (ret)
+               debug_error("failed to __mm_sound_mgr_ipc_dbus_get_stream_list()\n");
+
+       debug_fleave();
+       return ret;
+}
+
+int MMSoundMgrFocusFini(void)
+{
+       int i = 0;
+       debug_fenter();
+
+       for (i = 0; i < AVAIL_STREAMS_MAX; i++) {
+               if (g_stream_list.stream_types[i]) {
+                       free (g_stream_list.stream_types[i]);
+               }
+       }
+
+       debug_fleave();
+       return MM_ERROR_NONE;
+}
+
index 70876fb..4a5c3cc 100644 (file)
 #include <fcntl.h>
 
 #include <errno.h>
-#include <pthread.h>
+//#include <pthread.h>
 #include "include/mm_sound_mgr_common.h"
 #include "include/mm_sound_mgr_ipc.h"
+#include "include/mm_sound_mgr_ipc_dbus.h"
 
 #include "../include/mm_sound_common.h"
 #include "../include/mm_sound_msg.h"
-#include "include/mm_sound_thread_pool.h"
+//#include "include/mm_sound_thread_pool.h"
 #include "include/mm_sound_mgr_codec.h"
 #include "include/mm_sound_mgr_device.h"
+#include "include/mm_sound_mgr_asm.h"
+#ifdef USE_FOCUS
+#include "include/mm_sound_mgr_focus.h"
+#endif
 #include <mm_error.h>
 #include <mm_debug.h>
 
 
 /* workaround for AF volume gain tuning */
 #define MM_SOUND_AF_FILE_PREFIX "/opt/ug/res/sounds/ug-camera-efl/sounds/af_"
-#define PROC_DBUS_OBJECT       "/Org/Tizen/ResourceD/Process"
-#define PROC_DBUS_INTERFACE    "org.tizen.resourced.process"
-#define PROC_DBUS_METHOD       "ProcExclude"
-
-/* message id */
-int g_rcvid;
-int g_sndid;
-int g_cbid;
-static pthread_mutex_t g_msg_snd_cb_mutex = PTHREAD_MUTEX_INITIALIZER;
-
-
-/* Msg processing */
-static void _MMSoundMgrRun(void *data);
-static int _MMSoundMgrStopCB(int msgid, void* msgcallback, void *msgdata, int id);     /* msg_type means instance for client */
-static int _MMSoundMgrIpcPlayFile(int *codechandle, mm_ipc_msg_t *msg);        /* codechandle means codec slotid */
-static int _MMSoundMgrIpcPlayMemory(int *codechandle, mm_ipc_msg_t *msg);
-static int _MMSoundMgrIpcStop(mm_ipc_msg_t *msg);
-static int _MMSoundMgrIpcPlayDTMF(int *codechandle, mm_ipc_msg_t *msg);
-static int __mm_sound_mgr_ipc_is_route_available(mm_ipc_msg_t *msg, bool *is_available);
-static int __mm_sound_mgr_ipc_foreach_available_route_cb(mm_ipc_msg_t *msg);
-static int __mm_sound_mgr_ipc_set_active_route(mm_ipc_msg_t *msg);
-static int __mm_sound_mgr_ipc_set_active_route_auto(void);
-static int __mm_sound_mgr_ipc_get_active_device(mm_ipc_msg_t *msg, mm_sound_device_in *device_in, mm_sound_device_out *device_out);
-static int __mm_sound_mgr_ipc_add_active_device_changed_cb(mm_ipc_msg_t *msg);
-static int __mm_sound_mgr_ipc_remove_active_device_changed_cb(mm_ipc_msg_t *msg);
-static int __mm_sound_mgr_ipc_add_available_device_changed_cb(mm_ipc_msg_t *msg);
-static int __mm_sound_mgr_ipc_remove_available_device_changed_cb(mm_ipc_msg_t *msg);
-static int __mm_sound_mgr_ipc_add_volume_changed_cb(mm_ipc_msg_t *msg);
-static int __mm_sound_mgr_ipc_remove_volume_changed_cb(mm_ipc_msg_t *msg);
-static int _MMIpcRecvMsg(int msgtype, mm_ipc_msg_t *msg);
-static int _MMIpcSndMsg(mm_ipc_msg_t *msg);
-static int __mm_sound_mgr_ipc_set_sound_path_for_active_device(mm_ipc_msg_t *msg);
-static int __mm_sound_mgr_ipc_get_audio_path(mm_sound_device_in *device_in, mm_sound_device_out *device_out);
-static int __mm_sound_mgr_ipc_get_current_connected_device_list(mm_ipc_msg_t *msg, GList **device_list, int *total_num);
-static int __mm_sound_mgr_ipc_add_device_connected_cb(mm_ipc_msg_t *msg);
-static int __mm_sound_mgr_ipc_remove_device_connected_cb(mm_ipc_msg_t *msg);
-static int __mm_sound_mgr_ipc_add_device_info_changed_cb(mm_ipc_msg_t *msg);
-static int __mm_sound_mgr_ipc_remove_device_info_changed_cb(mm_ipc_msg_t *msg);
-
-
-int MMSoundMgrIpcInit(void)
-{
-       debug_fenter();
-
-       /* create msg queue rcv, snd, cb */
-       /* This func is called only once */
-       g_rcvid = msgget(ftok(KEY_BASE_PATH, RCV_MSG), IPC_CREAT |0666);
-       g_sndid = msgget(ftok(KEY_BASE_PATH, SND_MSG), IPC_CREAT |0666);
-       g_cbid = msgget(ftok(KEY_BASE_PATH, CB_MSG), IPC_CREAT |0666);
-
-       if ((g_rcvid == -1 || g_sndid == -1 || g_cbid == -1) != MM_ERROR_NONE) {
-               if(errno == EACCES) {
-                       printf("Require ROOT permission.\n");
-               } else if(errno == EEXIST) {
-                       printf("System memory is empty.\n");
-               } else if(errno == ENOMEM) {
-                       printf("System memory is empty.\n");
-               } else if(errno == ENOSPC) {
-                       printf("Resource is empty.\n");
-               }
-               debug_error("Fail to create msgid\n");
-               exit(1);
-               return MM_ERROR_SOUND_INTERNAL;
-       }                       
-
-       debug_msg("Created server msg queue id : rcv[%d], snd[%d], cb[%d]\n", g_rcvid, g_sndid, g_cbid );
-
-       g_type_init();
-
-       debug_fleave();
-       return MM_ERROR_NONE;
-}
-
-int MMSoundMgrIpcFini(void)
-{
-       return MM_ERROR_NONE;
-}
-
-int MMSoundMgrIpcReady(void)
-{
-       int ret = MM_ERROR_NONE;
-       int err1, err2, err3;
-       mm_ipc_msg_t msg = {0,};
-       mm_ipc_msg_t resp  = {0,};
-
-       debug_msg("Created server msg queue id : rcv[%d], snd[%d], cb[%d]\n", g_rcvid, g_sndid, g_cbid );
-
-       /* Ready to recive message */
-       while(1) {
-               ret = _MMIpcRecvMsg(0, &msg);           
-               if (ret != MM_ERROR_NONE) {
-                       debug_critical("Fail recieve message. \n");
-                       exit(1);
-               }
-                       
-               debug_msg("[ type:%d, id:%d, h:%d, vol:%d, vol_conf:%x keytone:%d, tone:%d, cb:%p, data:%p, prio:%d, route:%d ]\n",
-                               msg.sound_msg.msgtype, msg.sound_msg.msgid, msg.sound_msg.handle, msg.sound_msg.volume, msg.sound_msg.volume_config,
-                               msg.sound_msg.keytone, msg.sound_msg.tone, msg.sound_msg.callback, msg.sound_msg.cbdata, msg.sound_msg.priority, msg.sound_msg.handle_route);
-               
-               switch (msg.sound_msg.msgtype)
-               {
-               case MM_SOUND_MSG_REQ_FILE:
-               case MM_SOUND_MSG_REQ_MEMORY:
-               case MM_SOUND_MSG_REQ_STOP:
-#ifdef PULSE_CLIENT
-               case MM_SOUND_MSG_REQ_GET_AUDIO_ROUTE:
-               case MM_SOUND_MSG_REQ_SET_AUDIO_ROUTE:
-#endif
-               case MM_SOUND_MSG_REQ_IS_BT_A2DP_ON:
-               case MM_SOUND_MSG_REQ_DTMF:
-               case MM_SOUND_MSG_REQ_IS_ROUTE_AVAILABLE:
-               case MM_SOUND_MSG_REQ_FOREACH_AVAILABLE_ROUTE_CB:
-               case MM_SOUND_MSG_REQ_SET_ACTIVE_ROUTE:
-               case MM_SOUND_MSG_REQ_SET_ACTIVE_ROUTE_AUTO:
-               case MM_SOUND_MSG_REQ_GET_ACTIVE_DEVICE:
-               case MM_SOUND_MSG_REQ_ADD_ACTIVE_DEVICE_CB:
-               case MM_SOUND_MSG_REQ_REMOVE_ACTIVE_DEVICE_CB:
-               case MM_SOUND_MSG_REQ_ADD_AVAILABLE_ROUTE_CB:
-               case MM_SOUND_MSG_REQ_REMOVE_AVAILABLE_ROUTE_CB:
-               case MM_SOUND_MSG_REQ_ADD_VOLUME_CB:
-               case MM_SOUND_MSG_REQ_REMOVE_VOLUME_CB:
-               case MM_SOUND_MSG_REQ_SET_PATH_FOR_ACTIVE_DEVICE:
-               case MM_SOUND_MSG_REQ_GET_AUDIO_PATH:
-               case MM_SOUND_MSG_REQ_GET_CONNECTED_DEVICE_LIST:
-               case MM_SOUND_MSG_REQ_ADD_DEVICE_CONNECTED_CB:
-               case MM_SOUND_MSG_REQ_REMOVE_DEVICE_CONNECTED_CB:
-               case MM_SOUND_MSG_REQ_ADD_DEVICE_INFO_CHANGED_CB:
-               case MM_SOUND_MSG_REQ_REMOVE_DEVICE_INFO_CHANGED_CB:
-                       {
-                               /* Create msg to queue : this will be freed inside thread function after use */
-                               mm_ipc_msg_t* msg_to_queue = malloc (sizeof(mm_ipc_msg_t));
-                               if (msg_to_queue) {
-                                       memcpy (msg_to_queue, &msg, sizeof (mm_ipc_msg_t));
-                                       debug_log ("func = %p, alloc param(msg_to_queue) = %p\n", _MMSoundMgrRun, msg_to_queue);
-                                       ret = MMSoundThreadPoolRun(msg_to_queue, _MMSoundMgrRun);
-                                       /* In case of error condition */
-                                       if (ret != MM_ERROR_NONE) {
-                                               /* Do not send msg in Ready, Just print log */
-                                               debug_critical("Fail to run thread [MgrRun]");
-       
-                                               SOUND_MSG_SET(resp.sound_msg, MM_SOUND_MSG_RES_ERROR, ret, -1, msg.sound_msg.msgid);
-                                               ret = _MMIpcSndMsg(&resp);
-                                               if (ret != MM_ERROR_NONE) {
-                                                       debug_error("Fail to send message in IPC ready\n");
-                                       }
-                                       }
-                               } else {
-                                       debug_error ("failed to alloc msg\n");
-                               }
-                       }
-                       break;
-
-               default:
-                       /*response err unknown operation*/;
-                       debug_critical("Error condition\n");
-                       debug_msg("The message Msg [%d] client id [%d]\n", msg.sound_msg.msgtype, msg.sound_msg.msgid);
-                       SOUND_MSG_SET(resp.sound_msg, MM_SOUND_MSG_RES_ERROR, ret, -1, msg.sound_msg.msgid);
-                       ret = _MMIpcSndMsg(&resp);
-                       if (ret != MM_ERROR_NONE) {
-                                       debug_error("Fail to send message in IPC ready\n");
-                       }
-                       break;
-               } /* end : switch (msg.sound_msg.msgtype) */
-       }
-
-       /* destroy msg queue */
-       err1 = msgctl(g_rcvid, IPC_RMID, NULL);
-       err2 = msgctl(g_sndid, IPC_RMID, NULL);
-       err3 = msgctl(g_cbid, IPC_RMID, NULL);
-       
-       if (err1 == -1 ||err2 == -1 ||err3 ==-1) {
-               debug_error("Base message node destroy fail");
-               return MM_ERROR_SOUND_INTERNAL;
-       }
-       
-       return MM_ERROR_NONE;
-}
-
-static void _MMSoundMgrRun(void *data)
-{
-       mm_ipc_msg_t respmsg = {0,};
-       int ret = MM_ERROR_NONE;
-       int instance;
-       int handle = -1;
-       bool is_available = 0;
-       mm_sound_device_in device_in = MM_SOUND_DEVICE_IN_NONE;
-       mm_sound_device_out device_out = MM_SOUND_DEVICE_OUT_NONE;
-       mm_ipc_msg_t *msg = (mm_ipc_msg_t *)data;
-
-       instance = msg->sound_msg.msgid;
-
-       switch (msg->sound_msg.msgtype)
-       {
-       case MM_SOUND_MSG_REQ_FILE:
-               debug_msg("==================== Recv REQUEST FILE MSG from pid(%d) ====================\n", instance);
-               ret = _MMSoundMgrIpcPlayFile(&handle, msg);
-               if ( ret != MM_ERROR_NONE)      {
-                       debug_error("Error to MM_SOUND_MSG_REQ_FILE\n");
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_ERROR, -1, ret, instance);
-               } else {
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_FILE, handle, MM_ERROR_NONE, instance);
-               }
-               break;
-
-       case MM_SOUND_MSG_REQ_MEMORY:
-               debug_msg("==================== Recv REQUEST MEMORY MSG from pid(%d) ====================\n", instance);
-               ret =_MMSoundMgrIpcPlayMemory(&handle, msg);
-               if (ret != MM_ERROR_NONE) {
-                       debug_error("Error to MM_SOUND_MSG_REQ_MEMORY.\n");
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_ERROR, -1, ret, instance);
-               } else {
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_MEMORY, handle, MM_ERROR_NONE, instance);
-               }
-               break;
-               
-       case MM_SOUND_MSG_REQ_STOP:
-               debug_msg("==================== Recv STOP msg from pid(%d) ====================\n", instance);
-               debug_msg("STOP Handle(codec slot ID) %d \n", msg->sound_msg.handle);
-               ret = _MMSoundMgrIpcStop(msg);
-               if ( ret != MM_ERROR_NONE) {
-                       debug_error("Error to MM_SOUND_MSG_REQ_STOP.\n");
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_ERROR, -1, ret, instance);
-               } else {
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_STOP, msg->sound_msg.handle, MM_ERROR_NONE, instance);
-               }
-               break;
-               
-#ifdef PULSE_CLIENT
-       case MM_SOUND_MSG_REQ_IS_BT_A2DP_ON:
-               debug_msg("==================== Recv REQ_IS_BT_A2DP_ON msg from pid(%d) ====================\n", instance);
-               MMSoundMgrPulseHandleIsBtA2DPOnReq (msg,_MMIpcSndMsg);
-               return;
-#endif // PULSE_CLIENT
-
-       case MM_SOUND_MSG_REQ_DTMF:
-               debug_msg("==================== Recv DTMF msg from pid(%d) ====================\n", instance);
-               debug_msg(" Handle(codec slot ID) %d \n", msg->sound_msg.handle);
-               ret = _MMSoundMgrIpcPlayDTMF(&handle, msg);
-               if ( ret != MM_ERROR_NONE) {
-                       debug_error("Error to MM_SOUND_MSG_REQ_STOP.\n");
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_ERROR, -1, ret, instance);
-               } else {
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_DTMF, handle, MM_ERROR_NONE, instance);
-               }
-               break;
-
-       case MM_SOUND_MSG_REQ_IS_ROUTE_AVAILABLE:
-               debug_msg("==================== Recv MM_SOUND_MSG_REQ_IS_ROUTE_AVAILABLE msg from pid(%d) ====================\n", instance);
-               ret = __mm_sound_mgr_ipc_is_route_available(msg, &is_available);
-               if (ret != MM_ERROR_NONE) {
-                       debug_error("Error to MM_SOUND_MSG_REQ_IS_ROUTE_AVAILABLE.\n");
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_ERROR, -1, ret, instance);
-               } else {
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_IS_ROUTE_AVAILABLE, 0, MM_ERROR_NONE, instance);
-                       respmsg.sound_msg.is_available = is_available;
-               }
-               break;
-
-       case MM_SOUND_MSG_REQ_FOREACH_AVAILABLE_ROUTE_CB:
-               debug_msg("==================== Recv REQ_FOREACH_AVAILABLE_ROUTE_CB msg from pid(%d) ====================\n", instance);
-               ret = __mm_sound_mgr_ipc_foreach_available_route_cb(&respmsg);
-               if (ret != MM_ERROR_NONE) {
-                       debug_error("Error to MM_SOUND_MSG_REQ_FOREACH_AVAILABLE_ROUTE_CB.\n");
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_ERROR, -1, ret, instance);
-               } else {
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_FOREACH_AVAILABLE_ROUTE_CB, 0, MM_ERROR_NONE, instance);
-               }
-               break;
-
-       case MM_SOUND_MSG_REQ_SET_ACTIVE_ROUTE:
-               debug_msg("==================== Recv REQ_SET_ACTIVE_ROUTE msg from pid(%d) ====================\n", instance);
-               ret = __mm_sound_mgr_ipc_set_active_route(msg);
-               if (ret != MM_ERROR_NONE) {
-                       debug_error("Error to MM_SOUND_MSG_REQ_SET_ACTIVE_ROUTE.\n");
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_ERROR, -1, ret, instance);
-               } else {
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_SET_ACTIVE_ROUTE, 0, MM_ERROR_NONE, instance);
-               }
-               break;
-       case MM_SOUND_MSG_REQ_SET_ACTIVE_ROUTE_AUTO:
-               debug_msg("==================== Recv REQ_SET_ACTIVE_ROUTE_AUTO msg from pid(%d) ====================\n", instance);
-               ret = __mm_sound_mgr_ipc_set_active_route_auto();
-               if (ret != MM_ERROR_NONE) {
-                       debug_error("Error to MM_SOUND_MSG_REQ_SET_ACTIVE_ROUTE_AUTO.\n");
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_ERROR, -1, ret, instance);
-               } else {
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_SET_ACTIVE_ROUTE_AUTO, 0, MM_ERROR_NONE, instance);
-               }
-               break;
-
-       case MM_SOUND_MSG_REQ_GET_ACTIVE_DEVICE:
-               debug_msg("==================== Recv REQ_GET_ACTIVE_DEVICE msg from pid(%d) ====================\n", instance);
-               ret = __mm_sound_mgr_ipc_get_active_device(msg, &device_in, &device_out);
-               if (ret != MM_ERROR_NONE) {
-                       debug_error("Error to MM_SOUND_MSG_REQ_GET_ACTIVE_DEVICE.\n");
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_ERROR, -1, ret, instance);
-               } else {
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_GET_ACTIVE_DEVICE, 0, MM_ERROR_NONE, instance);
-                       respmsg.sound_msg.device_in = device_in;
-                       respmsg.sound_msg.device_out = device_out;
-               }
-               break;
-
-       case MM_SOUND_MSG_REQ_ADD_ACTIVE_DEVICE_CB:
-               debug_msg("==================== Recv REQ_ADD_ACTIVE_DEVICE_CB msg from pid(%d) ====================\n", instance);
-               ret = __mm_sound_mgr_ipc_add_active_device_changed_cb(msg);
-               if (ret != MM_ERROR_NONE) {
-                       debug_error("Error to MM_SOUND_MSG_REQ_ADD_DEVICE_CB.\n");
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_ERROR, -1, ret, instance);
-               } else {
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_ADD_ACTIVE_DEVICE_CB, 0, MM_ERROR_NONE, instance);
-               }
-               break;
-
-       case MM_SOUND_MSG_REQ_REMOVE_ACTIVE_DEVICE_CB:
-               debug_msg("==================== Recv REQ_REMOVE_ACTIVE_DEVICE_CB msg from pid(%d) ====================\n", instance);
-               ret = __mm_sound_mgr_ipc_remove_active_device_changed_cb(msg);
-               if (ret != MM_ERROR_NONE) {
-                       debug_error("Error to MM_SOUND_MSG_REQ_REMOVE_DEVICE_CB.\n");
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_ERROR, -1, ret, instance);
-               } else {
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_REMOVE_ACTIVE_DEVICE_CB, 0, MM_ERROR_NONE, instance);
-               }
-               break;
-
-       case MM_SOUND_MSG_REQ_ADD_VOLUME_CB:
-               debug_msg("==================== Recv REQ_ADD_VOLUME_CB msg from pid(%d) ====================\n", instance);
-               ret = __mm_sound_mgr_ipc_add_volume_changed_cb(msg);
-               if (ret != MM_ERROR_NONE) {
-                       debug_error("Error to MM_SOUND_MSG_REQ_VOLUME_CB.\n");
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_ERROR, -1, ret, instance);
-               } else {
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_ADD_VOLUME_CB, 0, MM_ERROR_NONE, instance);
-               }
-               break;
-
-       case MM_SOUND_MSG_REQ_REMOVE_VOLUME_CB:
-               debug_msg("==================== Recv REQ_REMOVE_VOLUME_CB msg from pid(%d) ====================\n", instance);
-               ret = __mm_sound_mgr_ipc_remove_volume_changed_cb(msg);
-               if (ret != MM_ERROR_NONE) {
-                       debug_error("Error to MM_SOUND_MSG_REQ_REMOVE_VOLUME_CB.\n");
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_ERROR, -1, ret, instance);
-               } else {
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_REMOVE_VOLUME_CB, 0, MM_ERROR_NONE, instance);
-               }
-               break;
-
-       case MM_SOUND_MSG_REQ_ADD_AVAILABLE_ROUTE_CB:
-               debug_msg("==================== Recv REQ_ADD_AVAILABLE_ROUTE_CB msg from pid(%d)====================\n", instance);
-               ret = __mm_sound_mgr_ipc_add_available_device_changed_cb(msg);
-               if (ret != MM_ERROR_NONE) {
-                       debug_error("Error to MM_SOUND_MSG_REQ_ADD_DEVICE_CB.\n");
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_ERROR, -1, ret, instance);
-               } else {
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_ADD_AVAILABLE_ROUTE_CB, 0, MM_ERROR_NONE, instance);
-               }
-               break;
-
-       case MM_SOUND_MSG_REQ_REMOVE_AVAILABLE_ROUTE_CB:
-               debug_msg("==================== Recv REQ_REMOVE_AVAILABLE_ROUTE_CB msg from pid(%d)====================\n", instance);
-               ret = __mm_sound_mgr_ipc_remove_available_device_changed_cb(msg);
-               if (ret != MM_ERROR_NONE) {
-                       debug_error("Error to MM_SOUND_MSG_REQ_REMOVE_DEVICE_CB.\n");
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_ERROR, -1, ret, instance);
-               } else {
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_REMOVE_AVAILABLE_ROUTE_CB, 0, MM_ERROR_NONE, instance);
-               }
-               break;
-
-       case MM_SOUND_MSG_REQ_SET_PATH_FOR_ACTIVE_DEVICE:
-               debug_msg("Recv MM_SOUND_MSG_REQ_SET_PATH_FOR_ACTIVE_DEVICE msg\n");
-               ret = __mm_sound_mgr_ipc_set_sound_path_for_active_device(msg);
-               if (ret != MM_ERROR_NONE) {
-                       debug_error("Error to MM_SOUND_MSG_REQ_SET_PATH_FOR_ACTIVE_DEVICE.\n");
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_ERROR, -1, ret, instance);
-               } else {
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_SET_PATH_FOR_ACTIVE_DEVICE, 0, MM_ERROR_NONE, instance);
-               }
-               break;
-       case MM_SOUND_MSG_REQ_GET_AUDIO_PATH:
-               debug_msg("Recv MM_SOUND_MSG_REQ_GET_AUDIO_PATH msg\n");
-               ret = __mm_sound_mgr_ipc_get_audio_path(&device_in, &device_out);
-               if (ret != MM_ERROR_NONE) {
-                       debug_error("Error to MM_SOUND_MSG_REQ_GET_AUDIO_PATH.\n");
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_ERROR, -1, ret, instance);
-               } else {
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_GET_AUDIO_PATH, 0, MM_ERROR_NONE, instance);
-                       respmsg.sound_msg.device_in = device_in;
-                       respmsg.sound_msg.device_out = device_out;
-               }
-               break;
-
-       case MM_SOUND_MSG_REQ_GET_CONNECTED_DEVICE_LIST:
-       {
-               GList *device_list = NULL;
-               GList *list = NULL;
-               int total_num_of_device = 0;
-               int i = 0;
-               debug_msg("==================== Recv REQ_GET_CONNECTED_DEVICE_LIST msg from pid(%d) ====================\n", instance);
-               ret = __mm_sound_mgr_ipc_get_current_connected_device_list(msg, &device_list, &total_num_of_device);
-               if (ret != MM_ERROR_NONE) {
-                       debug_error("Error to REQ_GET_CONNECTED_DEVICE_LIST. ret[0x%x]\n", ret);
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_ERROR, -1, ret, instance);
-               } else {
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_GET_CONNECTED_DEVICE_LIST, 0, MM_ERROR_NONE, instance);
-                       respmsg.sound_msg.total_device_num = total_num_of_device;
-                       for (list = device_list; list != NULL; list = list->next) {
-                               memcpy(&(respmsg.sound_msg.device_handle), (mm_sound_device_t*)list->data, sizeof(mm_sound_device_t));
-                               debug_msg("[Server] memory copied to msg device handle(handle[0x%x], type[%d], id[%d]), before sending device info, total [%d] msg remains\n",
-                                               &(respmsg.sound_msg.device_handle), ((mm_sound_device_t*)list->data)->type, ((mm_sound_device_t*)list->data)->id, total_num_of_device);
-                               if (total_num_of_device-- > 1) {
-                                       ret = _MMIpcSndMsg(&respmsg);
-                                       if (ret != MM_ERROR_NONE) {
-                                               debug_error ("Fail to send message \n");
-                                       }
-                               }
-                       }
-               }
-       }
-               break;
-
-       case MM_SOUND_MSG_REQ_ADD_DEVICE_CONNECTED_CB:
-               debug_msg("==================== Recv REQ_ADD_DEVICE_CONNECTED_CB msg from pid(%d) ====================\n", instance);
-               ret = __mm_sound_mgr_ipc_add_device_connected_cb(msg);
-               if (ret != MM_ERROR_NONE) {
-                       debug_error("Error to MM_SOUND_MSG_REQ_ADD_DEVICE_CONNECTED_CB.\n");
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_ERROR, -1, ret, instance);
-               } else {
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_ADD_DEVICE_CONNECTED_CB, 0, MM_ERROR_NONE, instance);
-               }
-               break;
-
-       case MM_SOUND_MSG_REQ_REMOVE_DEVICE_CONNECTED_CB:
-               debug_msg("==================== Recv REQ_REMOVE_DEVICE_CONNECTED_CB msg from pid(%d) ====================\n", instance);
-               ret = __mm_sound_mgr_ipc_remove_device_connected_cb(msg);
-               if (ret != MM_ERROR_NONE) {
-                       debug_error("Error to MM_SOUND_MSG_REQ_REMOVE_DEVICE_CONNECTED_CB.\n");
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_ERROR, -1, ret, instance);
-               } else {
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_REMOVE_DEVICE_CONNECTED_CB, 0, MM_ERROR_NONE, instance);
-               }
-               break;
-
-       case MM_SOUND_MSG_REQ_ADD_DEVICE_INFO_CHANGED_CB:
-               debug_msg("==================== Recv REQ_ADD_DEVICE_INFO_CHANGED_CB msg from pid(%d) ====================\n", instance);
-               ret = __mm_sound_mgr_ipc_add_device_info_changed_cb(msg);
-               if (ret != MM_ERROR_NONE) {
-                       debug_error("Error to MM_SOUND_MSG_REQ_ADD_DEVICE_INFO_CHANGED_CB.\n");
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_ERROR, -1, ret, instance);
-               } else {
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_ADD_DEVICE_INFO_CHANGED_CB, 0, MM_ERROR_NONE, instance);
-               }
-               break;
-
-       case MM_SOUND_MSG_REQ_REMOVE_DEVICE_INFO_CHANGED_CB:
-               debug_msg("==================== Recv REQ_REMOVE_DEVICE_INFO_CHANGED_CB msg from pid(%d) ====================\n", instance);
-               ret = __mm_sound_mgr_ipc_remove_device_info_changed_cb(msg);
-               if (ret != MM_ERROR_NONE) {
-                       debug_error("Error to MM_SOUND_MSG_REQ_REMOVE_DEVICE_INFO_CHANGED_CB.\n");
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_ERROR, -1, ret, instance);
-               } else {
-                       SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_REMOVE_DEVICE_INFO_CHANGED_CB, 0, MM_ERROR_NONE, instance);
-               }
-               break;
-
-       default:
-               /* Response error unknown operation */;
-               debug_critical("Unexpected msg. %d for PID:%d\n", msg->sound_msg.msgtype, msg->sound_msg.msgid );               
-               SOUND_MSG_SET(respmsg.sound_msg, MM_SOUND_MSG_RES_ERROR, -1, MM_ERROR_SOUND_INTERNAL, instance);
-               break;
-       } /* switch (msg->sound_msg.msgtype) */
-
-       ret = _MMIpcSndMsg(&respmsg);
-       if (ret != MM_ERROR_NONE) {
-               debug_error ("Fail to send message \n");
-       }
-
-       debug_log("Sent msg to client msgid [%d] [codechandle %d][message type %d] (code 0x%08X)\n",
-               msg->sound_msg.msgid, respmsg.sound_msg.handle, respmsg.sound_msg.msgtype, respmsg.sound_msg.code);
 
-       if (msg) {
-#ifdef DEBUG_DETAIL
-               debug_log ("Free mm_ipc_msg_t [%p]\n", msg);
-#endif
-               free (msg);
-       }
-}
-
-static int _MMSoundMgrStopCB(int msgid, void* msgcallback, void *msgdata, int id)
-{
-       /* msgid means client instance(msg_type) must be unique */
-       mm_ipc_msg_t resp = {0,};
-       int ret = MM_ERROR_SOUND_INTERNAL;
-       
-       SOUND_MSG_SET(resp.sound_msg, MM_SOUND_MSG_INF_STOP_CB, 0, MM_ERROR_NONE, msgid);
-       resp.sound_msg.callback = msgcallback;
-       resp.sound_msg.cbdata = msgdata;
-       resp.sound_msg.handle = id;
-       
-       ret = _MMIpcCBSndMsg(&resp);
-       if (ret != MM_ERROR_NONE) {
-               debug_error("Fail to send callback message\n");
-       }
-
-       return MM_ERROR_NONE;
-}
 
-static int _MMSoundMgrIpcPlayFile(int *codechandle, mm_ipc_msg_t *msg)
+/******************************************************************************************
+       Functions For handling request from client
+******************************************************************************************/
+// except msgid
+int _MMSoundMgrIpcPlayFile(char* filename,int tone, int repeat, int volume, int volume_config,
+                          int priority, int session_type, int session_options, int client_pid, int keytone, int handle_route,
+                          gboolean enable_session, int *codechandle, char *stream_type, int stream_index)
 {
        mmsound_mgr_codec_param_t param = {0,};
        MMSourceType *source = NULL;
        int ret = MM_ERROR_NONE;
        int mm_session_type = MM_SESSION_TYPE_MEDIA;
-       
+
        /* Set source */
        source = (MMSourceType*)malloc(sizeof(MMSourceType));
        if (!source) {
@@ -575,41 +81,42 @@ static int _MMSoundMgrIpcPlayFile(int *codechandle, mm_ipc_msg_t *msg)
                return MM_ERROR_OUT_OF_MEMORY;
        }
 
-       ret = mm_source_open_file(msg->sound_msg.filename, source, MM_SOURCE_CHECK_DRM_CONTENTS);
+       ret = mm_source_open_file(filename, source, MM_SOURCE_CHECK_DRM_CONTENTS);
        if(ret != MM_ERROR_NONE) {
                debug_error("Fail to open file\n");
                if (source) {
                        free(source);
                }
-               return ret;             
+               return ret;
        }
 
        /* Set sound player parameter */
-       param.tone = msg->sound_msg.tone;
-       param.repeat_count = msg->sound_msg.repeat;
-       param.param = (void*)msg->sound_msg.msgid; //this is pid of client
-       param.volume = msg->sound_msg.volume;
-       param.volume_config = msg->sound_msg.volume_config;
-       param.priority = msg->sound_msg.priority;
-       mm_session_type = msg->sound_msg.session_type;
-       param.callback = _MMSoundMgrStopCB;
-       param.keytone =  msg->sound_msg.keytone;
-       param.msgcallback = msg->sound_msg.callback;
-       param.msgdata = msg->sound_msg.cbdata;
+       param.tone = tone;
+       param.repeat_count = repeat;
+       param.volume = volume;
+       param.volume_config = volume_config;
+       param.priority = priority;
+       mm_session_type = session_type;
+       param.keytone =  keytone;
+       param.param = client_pid;
        param.source = source;
-       param.handle_route = msg->sound_msg.handle_route;
-       param.enable_session = msg->sound_msg.enable_session;
+       param.handle_route = handle_route;
+       param.enable_session = enable_session;
+       param.stream_index = stream_index;
+       strncpy(param.stream_type, stream_type, MM_SOUND_STREAM_TYPE_LEN);
 
        /* workaround for AF volume gain tuning */
-       if (strncmp(msg->sound_msg.filename, MM_SOUND_AF_FILE_PREFIX, strlen(MM_SOUND_AF_FILE_PREFIX)) == 0) {
+       if (strncmp(filename, MM_SOUND_AF_FILE_PREFIX, strlen(MM_SOUND_AF_FILE_PREFIX)) == 0) {
                param.volume_config |= VOLUME_GAIN_AF;
                debug_msg("Volume Gain AF\n");
        }
 
+/*
        debug_msg("File[%s] DTMF[%d] Loop[%d] Volume[%f] Priority[%d] VolCfg[0x%x] callback[%p] param[%d] src_type[%d] src_ptr[%p] keytone[%d] route[%d] enable_session[%d]",
-                       msg->sound_msg.filename,
+                       filename,
                        param.tone, param.repeat_count, param.volume, param.priority, param.volume_config, param.callback,
                        (int)param.param, param.source->type, param.source->ptr, param.keytone, param.handle_route, param.enable_session);
+                       */
 
        //convert mm_session_type to asm_event_type
        switch(mm_session_type)
@@ -626,9 +133,6 @@ static int _MMSoundMgrIpcPlayFile(int *codechandle, mm_ipc_msg_t *msg)
        case MM_SESSION_TYPE_EMERGENCY:
                param.session_type = ASM_EVENT_EMERGENCY;
                break;
-       case MM_SESSION_TYPE_CALL:
-               param.session_type = ASM_EVENT_CALL;
-               break;
        case MM_SESSION_TYPE_VIDEOCALL:
                param.session_type = ASM_EVENT_VIDEOCALL;
                break;
@@ -641,9 +145,8 @@ static int _MMSoundMgrIpcPlayFile(int *codechandle, mm_ipc_msg_t *msg)
                break;
        }
 
-
        ret = MMSoundMgrCodecPlay(codechandle, &param);
-       if ( ret != MM_ERROR_NONE) {
+       if (ret != MM_ERROR_NONE) {
                debug_error("Will be closed a sources, codechandle : 0x%08X\n", *codechandle);
                mm_source_close(source);
                if (source) {
@@ -655,11 +158,12 @@ static int _MMSoundMgrIpcPlayFile(int *codechandle, mm_ipc_msg_t *msg)
 
        return MM_ERROR_NONE;
 }
-static int _MMSoundMgrIpcStop(mm_ipc_msg_t *msg)
+
+int _MMSoundMgrIpcStop(int handle)
 {
        int ret = MM_ERROR_NONE;
 
-       ret = MMSoundMgrCodecStop(msg->sound_msg.handle);
+       ret = MMSoundMgrCodecStop(handle);
 
        if (ret != MM_ERROR_NONE) {
                debug_error("Fail to stop sound\n");
@@ -669,137 +173,81 @@ static int _MMSoundMgrIpcStop(mm_ipc_msg_t *msg)
        return MM_ERROR_NONE;
 }
 
-static int _MMSoundMgrIpcPlayMemory(int *codechandle, mm_ipc_msg_t *msg)
+_MMSoundMgrIpcPlayFileWithStreamInfo(char* filename, int repeat, int volume,
+                          int priority, int client_pid, int handle_route, int *codechandle, char *stream_type, int stream_index)
 {
        mmsound_mgr_codec_param_t param = {0,};
        MMSourceType *source = NULL;
        int ret = MM_ERROR_NONE;
-       int shm_fd = -1;
-       void* mmap_buf = NULL;
-
-#ifndef SHM_OPEN
-       if ((shmid = shmget((key_t)(msg->sound_msg.sharedkey), msg->sound_msg.memsize, 0)) == -1)
-       {
-               if(errno == ENOENT)
-               {
-                       debug_error("Not initialized.\n");
-               }
-               else if(errno == EACCES)
-               {
-                       debug_error("Require ROOT permission.\n");
-               }
-               else if(errno == ENOSPC)
-               {
-                       debug_critical("Resource is empty.\n");
-               }
-               return MM_ERROR_SOUND_INTERNAL;
-       }
-
-       source = (MMSourceType*)malloc(sizeof(MMSourceType));
-
-       if (mm_source_open_full_memory(shmat(shmid, 0, 0), msg->sound_msg.memsize, 0, source) != MM_ERROR_NONE)
-       {
-               debug_error("Fail to set source\n");
-               free(source);
-               return MM_ERROR_SOUND_INTERNAL;
-       }
-#else
-
-       debug_msg("Shm file name : %s\n", msg->sound_msg.filename);
-
-       if(msg->sound_msg.sharedkey != 1) {
-               debug_error("NOT memory interface\n");
-               return MM_ERROR_SOUND_INVALID_PATH;
-       }
-
-       shm_fd = shm_open(msg->sound_msg.filename, O_RDONLY, 0666);
-       if(shm_fd < 0) {
-               debug_error("Fail to open\n");
-               return MM_ERROR_SOUND_INTERNAL;
-       }
-
-       mmap_buf = mmap (0, MEMTYPE_SUPPORT_MAX, PROT_READ , MAP_SHARED, shm_fd, 0);
-       if (mmap_buf == MAP_FAILED) {
-               perror("Fail to mmap\n");
-               debug_error("MMAP failed \n");
-               return MM_ERROR_SOUND_INTERNAL;
-       }
 
        /* Set source */
        source = (MMSourceType*)malloc(sizeof(MMSourceType));
-       if(!source) {
-               debug_error("Can not allocate memory");
-               munmap(mmap_buf, MEMTYPE_SUPPORT_MAX);
-               mmap_buf = NULL;
+       if (!source) {
+               debug_error("malloc fail!!\n");
                return MM_ERROR_OUT_OF_MEMORY;
        }
 
-       if (mm_source_open_full_memory(mmap_buf, msg->sound_msg.memsize, 0, source) != MM_ERROR_NONE) {
-               debug_error("Fail to set source\n");
-               free(source);
-               return MM_ERROR_SOUND_INTERNAL;
+       ret = mm_source_open_file(filename, source, MM_SOURCE_CHECK_DRM_CONTENTS);
+       if(ret != MM_ERROR_NONE) {
+               debug_error("Fail to open file\n");
+               if (source) {
+                       free(source);
+               }
+               return ret;
        }
-#endif 
 
        /* Set sound player parameter */
-       param.tone = msg->sound_msg.tone;
-       param.repeat_count = msg->sound_msg.repeat;
-       param.param = (void*)msg->sound_msg.msgid;
-       param.volume = msg->sound_msg.volume;
-       param.volume_config = msg->sound_msg.volume_config;
-       param.callback = _MMSoundMgrStopCB;
-       param.keytone =  msg->sound_msg.keytone;
-       param.msgcallback = msg->sound_msg.callback;
-       param.msgdata = msg->sound_msg.cbdata;
-       param.priority = msg->sound_msg.priority;
+       param.repeat_count = repeat;
+       param.volume = volume;
+       param.priority = priority;
+       param.param = client_pid;
        param.source = source;
-       param.enable_session = msg->sound_msg.enable_session;
+       param.handle_route = handle_route;
+       param.stream_index = stream_index;
+       strncpy(param.stream_type, stream_type, MM_SOUND_STREAM_TYPE_LEN);
 
-       debug_msg("DTMF %d\n", param.tone);
-       debug_msg("Loop %d\n", param.repeat_count);
-       debug_msg("Volume %d\n",param.volume);
-       debug_msg("Priority %d\n",param.priority);
-       debug_msg("VolumeConfig %x\n",param.volume_config);
-       debug_msg("callback %p\n", param.callback);
-       debug_msg("param %d\n", (int)param.param);
-       debug_msg("source type %d\n", param.source->type);
-       debug_msg("source ptr %p\n", param.source->ptr);
-       debug_msg("keytone %d\n", param.keytone);
-       debug_msg("enable_session %d\n", param.enable_session);
+       /* workaround for AF volume gain tuning */
+       if (strncmp(filename, MM_SOUND_AF_FILE_PREFIX, strlen(MM_SOUND_AF_FILE_PREFIX)) == 0) {
+               param.volume_config |= VOLUME_GAIN_AF;
+               debug_msg("Volume Gain AF\n");
+       }
 
-       ret = MMSoundMgrCodecPlay(codechandle, &param);
-       if ( ret != MM_ERROR_NONE) {
-               debug_error("Will be closed a sources, codec handle : [0x%d]\n", *codechandle);
+       ret = MMSoundMgrCodecPlayWithStreamInfo(codechandle, &param);
+       if (ret != MM_ERROR_NONE) {
+               debug_error("Will be closed a sources, codechandle : 0x%08X\n", *codechandle);
                mm_source_close(source);
                if (source) {
                        free(source);
+                       source = NULL;
                }
-               return ret;             
+               return ret;
        }
 
-       return ret;
+       return MM_ERROR_NONE;
+
 }
 
-static int _MMSoundMgrIpcPlayDTMF(int *codechandle, mm_ipc_msg_t *msg)
+int _MMSoundMgrIpcPlayDTMF(int tone, int repeat, int volume, int volume_config,
+                          int session_type, int session_options, int client_pid,
+                          gboolean enable_session, int *codechandle, char *stream_type, int stream_index)
 {
        mmsound_mgr_codec_param_t param = {0,};
        int ret = MM_ERROR_NONE;
 
        /* Set sound player parameter */
-       param.tone = msg->sound_msg.tone;
-       param.repeat_count = msg->sound_msg.repeat;
-       param.param = (void*)msg->sound_msg.msgid;
-       param.volume = msg->sound_msg.volume;
-       param.volume_config = msg->sound_msg.volume_config;
-       param.priority = msg->sound_msg.priority;
-       param.callback = _MMSoundMgrStopCB;
-       param.msgcallback = msg->sound_msg.callback;
-       param.msgdata = msg->sound_msg.cbdata;
-       param.session_options = msg->sound_msg.session_options;
-       param.enable_session = msg->sound_msg.enable_session;
+       param.tone = tone;
+       param.repeat_count = repeat;
+       param.volume = volume;
+       param.volume_config = volume_config;
+       param.priority = 0;
+       param.param = client_pid;
+       param.session_options = session_options;
+       param.enable_session = enable_session;
+       param.stream_index = stream_index;
+       strncpy(param.stream_type, stream_type, MM_SOUND_STREAM_TYPE_LEN);
 
        //convert mm_session_type to asm_event_type
-       switch(msg->sound_msg.session_type)
+       switch(session_type)
        {
                case MM_SESSION_TYPE_MEDIA:
                        param.session_type = ASM_EVENT_MEDIA_MMSOUND;
@@ -833,8 +281,6 @@ static int _MMSoundMgrIpcPlayDTMF(int *codechandle, mm_ipc_msg_t *msg)
        debug_msg("Volume %d\n",param.volume);
        debug_msg("VolumeConfig %x\n",param.volume_config);
        debug_msg("Priority %d\n", param.priority);
-       debug_msg("callback %p\n", param.callback);
-       debug_msg("param %d\n", (int)param.param);
        debug_msg("session %d\n", param.session_type);
        debug_msg("session options %x\n", param.session_options);
        debug_msg("enable_session %d\n", param.enable_session);
@@ -842,409 +288,457 @@ static int _MMSoundMgrIpcPlayDTMF(int *codechandle, mm_ipc_msg_t *msg)
        ret = MMSoundMgrCodecPlayDtmf(codechandle, &param);
        if ( ret != MM_ERROR_NONE) {
                debug_error("Will be closed a sources, codec handle : [0x%d]\n", *codechandle);
-               return ret;             
+               return ret;
        }
 
        return ret;
 }
 
-static int __mm_sound_mgr_ipc_is_route_available(mm_ipc_msg_t *msg, bool *is_available)
+int _MMSoundMgrIpcPlayDTMFWithStreamInfo(int tone, int repeat, int volume, int client_pid, int *codechandle, char *stream_type, int stream_index)
 {
-       _mm_sound_mgr_device_param_t param;
+       mmsound_mgr_codec_param_t param = {0,};
        int ret = MM_ERROR_NONE;
 
-       param.route = msg->sound_msg.route;
-       ret = _mm_sound_mgr_device_is_route_available(&param, is_available);
+       /* Set sound player parameter */
+       param.tone = tone;
+       param.repeat_count = repeat;
+       param.volume = volume;
+       param.priority = 0;
+       param.param = client_pid;
+       param.stream_index = stream_index;
+       strncpy(param.stream_type, stream_type, MM_SOUND_STREAM_TYPE_LEN);
+
+       debug_msg("DTMF %d\n", param.tone);
+       debug_msg("Loop %d\n", param.repeat_count);
+       debug_msg("Volume %d\n",param.volume);
+       debug_msg("Priority %d\n", param.priority);
+       debug_msg("stream type %s\n", param.stream_type);
+       debug_msg("stream index %d\n", param.stream_index);
+
+
+       ret = MMSoundMgrCodecPlayDtmfWithStreamInfo(codechandle, &param);
+       if ( ret != MM_ERROR_NONE) {
+               debug_error("Will be closed a sources, codec handle : [0x%d]\n", *codechandle);
+               return ret;
+       }
 
        return ret;
 }
 
-static int __mm_sound_mgr_ipc_foreach_available_route_cb(mm_ipc_msg_t *msg)
+
+int __mm_sound_mgr_ipc_set_sound_path_for_active_device(mm_sound_device_in _device_in, mm_sound_device_out _device_out)
 {
        int ret = MM_ERROR_NONE;
+       mm_sound_device_in device_in = MM_SOUND_DEVICE_IN_NONE;
+       mm_sound_device_out device_out = MM_SOUND_DEVICE_OUT_NONE;
 
-       ret = _mm_sound_mgr_device_foreach_available_route_cb(msg);
+       device_in = _device_in;
+       device_out = _device_out;
+//     ret = _mm_sound_mgr_device_set_sound_path_for_active_device(device_out, device_in);
 
        return ret;
 }
 
-static int __mm_sound_mgr_ipc_set_active_route(mm_ipc_msg_t *msg)
+int __mm_sound_mgr_ipc_get_audio_path(mm_sound_device_in *device_in, mm_sound_device_out *device_out)
 {
-       _mm_sound_mgr_device_param_t param;
        int ret = MM_ERROR_NONE;
 
-       param.pid = msg->sound_msg.msgid;
-       param.route = msg->sound_msg.route;
-       param.need_broadcast = msg->sound_msg.need_broadcast;
-
-       ret = _mm_sound_mgr_device_set_active_route(&param);
+//     ret = _mm_sound_mgr_device_get_audio_path(device_in, device_out);
 
        return ret;
 }
 
-static int __mm_sound_mgr_ipc_set_active_route_auto(void)
+int __mm_sound_mgr_ipc_get_current_connected_device_list(int device_flags, mm_sound_device_t **device_list, int *total_num)
 {
        int ret = MM_ERROR_NONE;
 
-       ret = _mm_sound_mgr_device_set_active_route_auto();
+//     ret = _mm_sound_mgr_device_get_current_connected_dev_list(device_flags, device_list, total_num);
 
        return ret;
 }
+#ifdef USE_FOCUS
 
-static int __mm_sound_mgr_ipc_get_active_device(mm_ipc_msg_t *msg, mm_sound_device_in *device_in, mm_sound_device_out *device_out)
+#ifdef SUPPORT_CONTAINER
+// method + add callback
+int __mm_sound_mgr_ipc_register_focus(int client_pid, int handle_id, char* stream_type, const char* container_name, int container_pid)
 {
-       _mm_sound_mgr_device_param_t param;
+       _mm_sound_mgr_focus_param_t param;
        int ret = MM_ERROR_NONE;
 
-       memset(&param, 0x00, sizeof(_mm_sound_mgr_device_param_t));
-       param.pid = msg->sound_msg.msgid;
+       memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
+       param.pid = client_pid;
+       param.handle_id = handle_id;
+//     param.callback = msg->sound_msg.callback;
+//     param.cbdata = msg->sound_msg.cbdata;
+       memcpy(param.stream_type, stream_type, MAX_STREAM_TYPE_LEN);
 
-       ret = _mm_sound_mgr_device_get_active_device(&param, device_in, device_out);
+       ret = mm_sound_mgr_focus_create_node(&param);
+
+       _mm_sound_mgr_focus_update_container_data(client_pid, handle_id, container_name, container_pid);
 
        return ret;
 }
-
-static int __mm_sound_mgr_ipc_add_active_device_changed_cb(mm_ipc_msg_t *msg)
+#else
+int __mm_sound_mgr_ipc_register_focus(int client_pid, int handle_id, char* stream_type)
 {
-       _mm_sound_mgr_device_param_t param;
+       _mm_sound_mgr_focus_param_t param;
        int ret = MM_ERROR_NONE;
 
-       memset(&param, 0x00, sizeof(_mm_sound_mgr_device_param_t));
-       param.pid = msg->sound_msg.msgid;
-       param.callback = msg->sound_msg.callback;
-       param.cbdata = msg->sound_msg.cbdata;
-       MMSOUND_STRNCPY(param.name, msg->sound_msg.name, MM_SOUND_NAME_NUM);
+       memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
+       param.pid = client_pid;
+       param.handle_id = handle_id;
+//     param.callback = msg->sound_msg.callback;
+//     param.cbdata = msg->sound_msg.cbdata;
+       memcpy(param.stream_type, stream_type, MAX_STREAM_TYPE_LEN);
 
-       ret = _mm_sound_mgr_device_add_active_device_callback(&param);
+       ret = mm_sound_mgr_focus_create_node(&param);
 
        return ret;
 }
+#endif
 
-static int __mm_sound_mgr_ipc_remove_active_device_changed_cb(mm_ipc_msg_t *msg)
+// method + remove callback
+int __mm_sound_mgr_ipc_unregister_focus(int pid, int handle_id)
 {
-       _mm_sound_mgr_device_param_t param;
+       _mm_sound_mgr_focus_param_t param;
        int ret = MM_ERROR_NONE;
 
-       memset(&param, 0x00, sizeof(_mm_sound_mgr_device_param_t));
-       param.pid = msg->sound_msg.msgid;
-       MMSOUND_STRNCPY(param.name, msg->sound_msg.name, MM_SOUND_NAME_NUM);
+       memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
+       param.pid = pid;
+       param.handle_id = handle_id;
 
-       ret = _mm_sound_mgr_device_remove_active_device_callback(&param);
+       ret = mm_sound_mgr_focus_destroy_node(&param);
 
        return ret;
 }
 
-static int __mm_sound_mgr_ipc_add_volume_changed_cb(mm_ipc_msg_t *msg)
+// method -> callback
+int __mm_sound_mgr_ipc_acquire_focus(int pid, int handle_id, int focus_type, const char* name )
 {
-       _mm_sound_mgr_device_param_t param;
+       _mm_sound_mgr_focus_param_t param;
        int ret = MM_ERROR_NONE;
 
-       memset(&param, 0x00, sizeof(_mm_sound_mgr_device_param_t));
-       param.pid = msg->sound_msg.msgid;
-       param.callback = msg->sound_msg.callback;
-       param.cbdata = msg->sound_msg.cbdata;
-       MMSOUND_STRNCPY(param.name, msg->sound_msg.name, MM_SOUND_NAME_NUM);
-
-       ret = _mm_sound_mgr_device_add_volume_callback(&param);
+       memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
+       param.pid = pid;
+       param.handle_id = handle_id;
+       param.request_type = focus_type;
+       memcpy(param.option, name, MM_SOUND_NAME_NUM);
+       ret = mm_sound_mgr_focus_request_acquire(&param);
 
        return ret;
 }
 
-static int __mm_sound_mgr_ipc_remove_volume_changed_cb(mm_ipc_msg_t *msg)
+// method -> callback
+int __mm_sound_mgr_ipc_release_focus(int pid, int handle_id, int focus_type, const char* name)
 {
-       _mm_sound_mgr_device_param_t param;
+       _mm_sound_mgr_focus_param_t param;
        int ret = MM_ERROR_NONE;
 
-       memset(&param, 0x00, sizeof(_mm_sound_mgr_device_param_t));
-       param.pid = msg->sound_msg.msgid;
-       MMSOUND_STRNCPY(param.name, msg->sound_msg.name, MM_SOUND_NAME_NUM);
+       memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
+       param.pid = pid;
+       param.handle_id = handle_id;
+       param.request_type = focus_type;
+       memcpy(param.option, name, MM_SOUND_NAME_NUM);
 
-       ret = _mm_sound_mgr_device_remove_volume_callback(&param);
+       ret = mm_sound_mgr_focus_request_release(&param);
 
        return ret;
 }
 
+#ifdef SUPPORT_CONTAINER
+// method + add callback
+int __mm_sound_mgr_ipc_watch_focus(int pid, int handle_id, int focus_type, const char* container_name, int container_pid)
+{
+       _mm_sound_mgr_focus_param_t param;
+       int ret = MM_ERROR_NONE;
 
-static int __mm_sound_mgr_ipc_add_available_device_changed_cb(mm_ipc_msg_t *msg)
+       memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
+       param.pid = pid;
+       param.handle_id = handle_id;
+       param.request_type = focus_type;
+//     param.callback = msg->sound_msg.callback;
+//     param.cbdata = msg->sound_msg.cbdata;
+
+       ret = mm_sound_mgr_focus_set_watch_cb(&param);
+       _mm_sound_mgr_focus_update_container_data(pid, -1, container_name, container_pid);
+
+       return ret;
+}
+#else
+int __mm_sound_mgr_ipc_watch_focus(int pid, int handle_id, int focus_type)
 {
-       _mm_sound_mgr_device_param_t param;
+       _mm_sound_mgr_focus_param_t param;
        int ret = MM_ERROR_NONE;
 
-       memset(&param, 0x00, sizeof(_mm_sound_mgr_device_param_t));
-       param.pid = msg->sound_msg.msgid;
-       param.callback = msg->sound_msg.callback;
-       param.cbdata = msg->sound_msg.cbdata;
+       memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
+       param.pid = pid;
+       param.handle_id = handle_id;
+       param.request_type = focus_type;
+//     param.callback = msg->sound_msg.callback;
+//     param.cbdata = msg->sound_msg.cbdata;
 
-       ret = _mm_sound_mgr_device_add_available_route_callback(&param);
+       ret = mm_sound_mgr_focus_set_watch_cb(&param);
 
        return ret;
 }
+#endif
 
-static int __mm_sound_mgr_ipc_remove_available_device_changed_cb(mm_ipc_msg_t *msg)
+// method + remove callback
+int __mm_sound_mgr_ipc_unwatch_focus(int pid, int handle_id)
 {
-       _mm_sound_mgr_device_param_t param;
+       _mm_sound_mgr_focus_param_t param;
        int ret = MM_ERROR_NONE;
 
-       memset(&param, 0x00, sizeof(_mm_sound_mgr_device_param_t));
-       param.pid = msg->sound_msg.msgid;
+       memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
+       param.pid = pid;
+       param.handle_id = handle_id;
 
-       ret = _mm_sound_mgr_device_remove_available_route_callback(&param);
+       ret = mm_sound_mgr_focus_unset_watch_cb(&param);
 
        return ret;
 }
+#endif
 
-static int __mm_sound_mgr_ipc_set_sound_path_for_active_device(mm_ipc_msg_t *msg)
+/************************************** ASM ***************************************/
+int __mm_sound_mgr_ipc_asm_register_sound(int pid, int handle, int sound_event, int request_id, int sound_state, int resource,
+#ifdef SUPPORT_CONTAINER
+                                               const char* container_name, int container_pid,
+#endif
+                                         int* pid_r, int* alloc_handle_r, int* cmd_handle_r,
+                                         int* request_id_r, int* sound_command_r, int* sound_state_r )
 {
        int ret = MM_ERROR_NONE;
-       mm_sound_device_in device_in = MM_SOUND_DEVICE_IN_NONE;
-       mm_sound_device_out device_out = MM_SOUND_DEVICE_OUT_NONE;
-       device_in = msg->sound_msg.device_in;
-       device_out = msg->sound_msg.device_out;
-       ret = _mm_sound_mgr_device_set_sound_path_for_active_device(device_out, device_in);
-
+       ret = _mm_sound_mgr_asm_register_sound(pid, handle, sound_event, request_id, sound_state, resource,
+                                                     pid_r, alloc_handle_r, cmd_handle_r, request_id_r, sound_command_r, sound_state_r);
+#ifdef SUPPORT_CONTAINER
+       _mm_sound_mgr_asm_update_container_data(*alloc_handle_r, container_name, container_pid);
+#endif
        return ret;
 }
 
-static int __mm_sound_mgr_ipc_get_audio_path(mm_sound_device_in *device_in, mm_sound_device_out *device_out)
+int __mm_sound_mgr_ipc_asm_unregister_sound(int pid, int handle, int sound_event, int request_id, int sound_state, int resource)
 {
        int ret = MM_ERROR_NONE;
+       ret = _mm_sound_mgr_asm_unregister_sound(pid, handle, sound_event, request_id, sound_state, resource);
+       return ret;
+}
 
-       ret = _mm_sound_mgr_device_get_audio_path(device_in, device_out);
+int __mm_sound_mgr_ipc_asm_register_watcher(int pid, int handle, int sound_event, int request_id, int sound_state, int resource,
+#ifdef SUPPORT_CONTAINER
+                                               const char* container_name, int container_pid,
+#endif
+                                           int* pid_r, int* alloc_handle_r, int* cmd_handle_r,
+                                           int* request_id_r, int* sound_command_r, int* sound_state_r )
+{
+       int ret = MM_ERROR_NONE;
+       ret = _mm_sound_mgr_asm_register_watcher(pid, handle, sound_event, request_id, sound_state, resource,
+                                                 pid_r, alloc_handle_r, cmd_handle_r, request_id_r, sound_command_r, sound_state_r);
+#ifdef SUPPORT_CONTAINER
+       _mm_sound_mgr_asm_update_container_data(*alloc_handle_r, container_name, container_pid);
+#endif
 
        return ret;
 }
 
-static int __mm_sound_mgr_ipc_get_current_connected_device_list(mm_ipc_msg_t *msg, GList **device_list, int *total_num)
+int __mm_sound_mgr_ipc_asm_unregister_watcher(int pid, int handle, int sound_event, int request_id, int sound_state, int resource)
 {
-       _mm_sound_mgr_device_param_t param;
        int ret = MM_ERROR_NONE;
-       int num = 0;
+       ret = _mm_sound_mgr_asm_unregister_watcher(pid, handle, sound_event, request_id, sound_state, resource);
 
-       memset(&param, 0x00, sizeof(_mm_sound_mgr_device_param_t));
-       param.pid = msg->sound_msg.msgid;
-       param.device_flags = msg->sound_msg.device_flags;
-
-       ret = _mm_sound_mgr_device_get_current_connected_dev_list(&param, device_list);
+       return ret;
+}
 
-       num = g_list_length(*device_list);
-       if (num) {
-               *total_num = num;
-       } else {
-               *device_list = NULL;
-               ret = MM_ERROR_SOUND_NO_DATA;
-       }
-       debug_msg("address of device_list[0x%x], number of device [%d]", *device_list, num);
+int __mm_sound_mgr_ipc_asm_get_mystate(int pid, int handle, int sound_event, int request_id, int sound_state, int resource,
+                                           int* pid_r, int* alloc_handle_r, int* cmd_handle_r,
+                                           int* request_id_r, int* sound_state_r )
+{
+       int ret = MM_ERROR_NONE;
+       ret = _mm_sound_mgr_asm_get_mystate(pid, handle, sound_event, request_id, sound_state, resource,
+                                                     pid_r, alloc_handle_r, cmd_handle_r, request_id_r, sound_state_r);
 
        return ret;
 }
 
-static int __mm_sound_mgr_ipc_add_device_connected_cb(mm_ipc_msg_t *msg)
+int __mm_sound_mgr_ipc_asm_set_state(int pid, int handle, int sound_event, int request_id, int sound_state, int resource,
+                                           int* pid_r, int* alloc_handle_r, int* cmd_handle_r,
+                                           int* request_id_r, int* sound_command_r, int* sound_state_r , int* error_code_r)
 {
-       _mm_sound_mgr_device_param_t param;
        int ret = MM_ERROR_NONE;
+       ret = _mm_sound_mgr_asm_set_state(pid, handle, sound_event, request_id, sound_state, resource,
+                                                     pid_r, alloc_handle_r, cmd_handle_r, request_id_r, sound_command_r, sound_state_r, error_code_r);
+
+       return ret;
+}
 
-       memset(&param, 0x00, sizeof(_mm_sound_mgr_device_param_t));
-       param.pid = msg->sound_msg.msgid;
-       param.callback = msg->sound_msg.callback;
-       param.cbdata = msg->sound_msg.cbdata;
-       param.device_flags = msg->sound_msg.device_flags;
 
-       ret = _mm_sound_mgr_device_add_connected_callback(&param);
+int __mm_sound_mgr_ipc_asm_get_state(int pid, int handle, int sound_event, int request_id, int sound_state, int resource,
+                                           int* pid_r, int* alloc_handle_r, int* cmd_handle_r,
+                                           int* request_id_r, int* sound_state_r )
+{
+       int ret = MM_ERROR_NONE;
+       ret = _mm_sound_mgr_asm_get_state(pid, handle, sound_event, request_id, sound_state, resource,
+                                                     pid_r, alloc_handle_r, cmd_handle_r, request_id_r, sound_state_r);
 
        return ret;
 }
+int __mm_sound_mgr_ipc_asm_set_subsession(int pid, int handle, int sound_event, int request_id, int sound_state, int resource,
+                                           int* pid_r, int* alloc_handle_r, int* cmd_handle_r, int* request_id_r)
+{
+       int ret = MM_ERROR_NONE;
+       ret = _mm_sound_mgr_asm_set_subsession(pid, handle, sound_event, request_id, sound_state, resource,
+                                                     pid_r, alloc_handle_r, cmd_handle_r, request_id_r);
 
-static int __mm_sound_mgr_ipc_remove_device_connected_cb(mm_ipc_msg_t *msg)
+       return ret;
+}
+
+int __mm_sound_mgr_ipc_asm_get_subsession(int pid, int handle, int sound_event, int request_id, int sound_state, int resource,
+                                           int* pid_r, int* alloc_handle_r, int* cmd_handle_r, int* request_id_r, int* sound_command_r)
 {
-       _mm_sound_mgr_device_param_t param;
        int ret = MM_ERROR_NONE;
+       ret = _mm_sound_mgr_asm_get_subsession(pid, handle, sound_event, request_id, sound_state, resource,
+                                                     pid_r, alloc_handle_r, cmd_handle_r, request_id_r, sound_command_r);
 
-       memset(&param, 0x00, sizeof(_mm_sound_mgr_device_param_t));
-       param.pid = msg->sound_msg.msgid;
+       return ret;
+}
 
-       ret = _mm_sound_mgr_device_remove_connected_callback(&param);
+int __mm_sound_mgr_ipc_asm_set_subevent(int pid, int handle, int sound_event, int request_id, int sound_state, int resource,
+                                           int* pid_r, int* alloc_handle_r, int* cmd_handle_r,
+                                           int* request_id_r, int* sound_command_r, int* sound_state_r )
+{
+       int ret = MM_ERROR_NONE;
+       ret = _mm_sound_mgr_asm_set_subevent(pid, handle, sound_event, request_id, sound_state, resource,
+                                                  pid_r, alloc_handle_r, cmd_handle_r, request_id_r, sound_command_r, sound_state_r);
 
        return ret;
 }
 
-static int __mm_sound_mgr_ipc_add_device_info_changed_cb(mm_ipc_msg_t *msg)
+int __mm_sound_mgr_ipc_asm_get_subevent(int pid, int handle, int sound_event, int request_id, int sound_state, int resource,
+                                           int* pid_r, int* alloc_handle_r, int* cmd_handle_r,
+                                           int* request_id_r, int* sound_command_r)
 {
-       _mm_sound_mgr_device_param_t param;
        int ret = MM_ERROR_NONE;
+       ret = _mm_sound_mgr_asm_get_subevent(pid, handle, sound_event, request_id, sound_state, resource,
+                                                  pid_r, alloc_handle_r, cmd_handle_r, request_id_r, sound_command_r);
 
-       memset(&param, 0x00, sizeof(_mm_sound_mgr_device_param_t));
-       param.pid = msg->sound_msg.msgid;
-       param.callback = msg->sound_msg.callback;
-       param.cbdata = msg->sound_msg.cbdata;
-       param.device_flags = msg->sound_msg.device_flags;
+       return ret;
+}
 
-       ret = _mm_sound_mgr_device_add_info_changed_callback(&param);
+int __mm_sound_mgr_ipc_asm_set_session_option(int pid, int handle, int sound_event, int request_id, int sound_state, int resource,
+                                           int* pid_r, int* alloc_handle_r, int* cmd_handle_r,
+                                           int* request_id_r, int* sound_command_r, int* error_code_r )
+{
+       int ret = MM_ERROR_NONE;
+       ret = _mm_sound_mgr_asm_set_session_option(pid, handle, sound_event, request_id, sound_state, resource,
+                                               pid_r, alloc_handle_r, cmd_handle_r, request_id_r, sound_command_r, error_code_r);
 
        return ret;
 }
 
-static int __mm_sound_mgr_ipc_remove_device_info_changed_cb(mm_ipc_msg_t *msg)
+int __mm_sound_mgr_ipc_asm_get_session_option(int pid, int handle, int sound_event, int request_id, int sound_state, int resource,
+                                           int* pid_r, int* alloc_handle_r, int* cmd_handle_r,
+                                           int* request_id_r, int* sound_command_r, int* option_flag_r )
 {
-       _mm_sound_mgr_device_param_t param;
        int ret = MM_ERROR_NONE;
+       ret = _mm_sound_mgr_asm_get_session_option(pid, handle, sound_event, request_id, sound_state, resource,
+                                            pid_r, alloc_handle_r, cmd_handle_r, request_id_r, sound_command_r, option_flag_r);
 
-       memset(&param, 0x00, sizeof(_mm_sound_mgr_device_param_t));
-       param.pid = msg->sound_msg.msgid;
+       return ret;
+}
 
-       ret = _mm_sound_mgr_device_remove_info_changed_callback(&param);
+int __mm_sound_mgr_ipc_asm_reset_resume_tag(int pid, int handle, int sound_event, int request_id, int sound_state, int resource,
+                                           int* pid_r, int* alloc_handle_r, int* cmd_handle_r,
+                                           int* request_id_r, int* sound_command_r, int* sound_state_r )
+{
+       int ret = MM_ERROR_NONE;
+       ret = _mm_sound_mgr_asm_reset_resume_tag(pid, handle, sound_event, request_id, sound_state, resource,
+                                         pid_r, alloc_handle_r, cmd_handle_r, request_id_r, sound_command_r, sound_state_r);
 
        return ret;
 }
 
-int __mm_sound_mgr_ipc_freeze_send (char* command, int pid)
+int __mm_sound_mgr_ipc_asm_dump(int pid, int handle, int sound_event, int request_id, int sound_state, int resource)
 {
-       GError *err = NULL;
-       GDBusConnection *conn = NULL;
-       gboolean ret;
+       int ret = MM_ERROR_NONE;
+       ret = _mm_sound_mgr_asm_dump(pid, handle, sound_event, request_id, sound_state, resource);
 
-       if (command == NULL || pid <= 0) {
-               debug_error ("invalid arguments [%s][%d]", command, pid);
-               return -1;
-       }
+       return ret;
+}
 
-       conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
-       if (!conn && err) {
-               debug_error ("g_bus_get_sync() error (%s) ", err->message);
-               g_error_free (err);
-               return -1;
-       }
+int __mm_sound_mgr_ipc_asm_emergent_exit(int pid, int handle, int sound_event, int request_id, int sound_state)
+{
+       int ret = MM_ERROR_NONE;
+       ret = _mm_sound_mgr_asm_emergent_exit(pid, handle, sound_event, request_id, sound_state);
 
-       ret = g_dbus_connection_emit_signal (conn,
-                               NULL, PROC_DBUS_OBJECT, PROC_DBUS_INTERFACE, PROC_DBUS_METHOD,
-                               g_variant_new ("(si)", command, pid),
-                               &err);
-       if (!ret && err) {
-               debug_error ("g_dbus_connection_emit_signal() error (%s) ", err->message);
-               goto error;
-       }
+       return ret;
+}
 
-       ret = g_dbus_connection_flush_sync(conn, NULL, &err);
-       if (!ret && err) {
-               debug_error ("g_dbus_connection_flush_sync() error (%s) ", err->message);
-               goto error;
-       }
+/**********************************************************************************/
 
-       g_object_unref(conn);
-       debug_msg ("sending [%s] for pid (%d) success", command, pid);
 
-       return 0;
+/******************************************************************************************
+       Functions For Server-Side to notify Clients
+******************************************************************************************/
 
-error:
-       g_error_free (err);
-       g_object_unref(conn);
-       return -1;
+int __mm_sound_mgr_ipc_notify_play_file_end (int handle)
+{
+       return __mm_sound_mgr_ipc_dbus_notify_play_file_end(handle);
 }
 
-static int _MMIpcRecvMsg(int msgtype, mm_ipc_msg_t *msg)
+int __mm_sound_mgr_ipc_notify_device_connected (mm_sound_device_t *device, gboolean is_connected)
 {
-       /* rcv message */
-       if(msgrcv(g_rcvid, msg, DSIZE, 0, 0) == -1)
-       {
-               if(errno == E2BIG) {
-                       debug_warning("Not acces.\n");
-               } else if(errno == EACCES) {
-                       debug_warning("Access denied\n");
-               } else if(errno == ENOMSG) {
-                       debug_warning("Blocked process [msgflag & IPC_NOWAIT != 0]\n");
-               } else if(errno == EIDRM) {
-                       debug_warning("Removed msgid from system\n");
-               } else if(errno == EINTR) {
-                       debug_warning("Iterrrupted by singnal\n");
-               } else if(errno == EINVAL) {
-                       debug_warning("Invalid msgid \n");
-               }
+       return __mm_sound_mgr_ipc_dbus_notify_device_connected(device, is_connected);
+}
 
-               debug_warning("Fail to recive msg queue : [%d] \n", g_rcvid);
-               return MM_ERROR_COMMON_UNKNOWN;
-       }
-       return MM_ERROR_NONE;
+int __mm_sound_mgr_ipc_notify_device_info_changed (mm_sound_device_t *device, int changed_device_info_type)
+{
+       return __mm_sound_mgr_ipc_dbus_notify_device_info_changed(device, changed_device_info_type);
 }
 
-int _MMIpcSndMsg(mm_ipc_msg_t *msg)
+int __mm_sound_mgr_ipc_notify_volume_changed(unsigned int vol_type, unsigned int value)
 {
-       /* snd message */
-       int error = MM_ERROR_NONE;
+       return __mm_sound_mgr_ipc_dbus_notify_volume_changed(vol_type, value);
+}
 
-       msg->msg_type = msg->sound_msg.msgid;
+int __mm_sound_mgr_ipc_notify_active_device_changed(int device_in, int device_out)
+{
+       /* Not Implemented */
+       return __mm_sound_mgr_ipc_dbus_notify_active_device_changed(device_in, device_out);
+}
 
-       debug_log("Send message type (for client) : [%ld]\n",msg->msg_type);
-       error = msgsnd(g_sndid, msg,DSIZE, 0);
-       if ( error == -1)
-       {
-               if(errno == EACCES) {
-                       debug_warning("Not acces.\n");
-               } else if(errno == EAGAIN) {
-                       debug_warning("Blocked process [msgflag & IPC_NOWAIT != 0]\n");
-               } else if(errno == EIDRM) {
-                       debug_warning("Removed msgid from system\n");
-               } else if(errno == EINTR) {
-                       debug_warning("Iterrrupted by singnal\n");
-               } else if(errno == EINVAL) {
-                       debug_warning("Invalid msgid or msgtype < 1 or out of data size \n");
-               } else if(errno == EFAULT) {
-                       debug_warning("The address pointed to by msgp isn't accessible \n");
-               } else if(errno == ENOMEM) {
-                       debug_warning("The system does not have enough memory to make a copy of the message pointed to by msgp\n");
-               }
-               debug_critical("Fail to send message msg queue : [%d] \n", g_sndid);
-               debug_critical("Fail to send message msg queue : [%d] \n", errno);
-               return MM_ERROR_SOUND_INTERNAL;
-       }
-       return MM_ERROR_NONE;
+int __mm_sound_mgr_ipc_notify_available_device_changed(int device_in, int device_out, int available)
+{
+       /* Not Implemented */
+       return __mm_sound_mgr_ipc_dbus_notify_available_device_changed(device_in, device_out, available);
 }
 
-int _MMIpcCBSndMsg(mm_ipc_msg_t *msg)
+int __mm_sound_mgr_ipc_freeze_send (char* command, int pid)
 {
-       /* rcv message */
-       int try_again = 0;
-
-       MMSOUND_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_msg_snd_cb_mutex, MM_ERROR_SOUND_INTERNAL);
-       msg->msg_type = msg->sound_msg.msgid;
-       debug_log("Send CB message type (for client) : [%ld]\n",msg->msg_type);
-       /* message queue is full ,we try to send it again*/
-       while(try_again <= 10) {
-               if (msgsnd(g_cbid, msg, DSIZE, IPC_NOWAIT) == -1)
-               {
-                       if (errno == EACCES) {
-                               debug_warning("Not acces.\n");
-                       } else if (errno == EAGAIN) {
-                               mm_ipc_msg_t msgdata = {0,};
-                               debug_warning("Blocked process [msgflag & IPC_NOWAIT != 0]\n");
-                               /* wait 10 msec ,then it will try again */
-                               usleep(10000);
-                               /*  it will try 5 times, after 5 times ,if it still fail ,then it will clear the message queue */
-                               if (try_again <= 5) {
-                                       try_again ++;
-                                       continue;
-                               }
-                               /* message queue is full ,it need to clear the queue */
-                               while( msgrcv(g_cbid, &msgdata, DSIZE, 0, IPC_NOWAIT) != -1 ) {
-                                       debug_warning("msg queue is full ,remove msgtype:[%d] from the queue",msgdata.sound_msg.msgtype);
-                               }
-                               try_again++;
-                               continue;
-                       } else if (errno == EIDRM) {
-                               debug_warning("Removed msgid from system\n");
-                       } else if (errno == EINTR) {
-                               debug_warning("Iterrrupted by singnal\n");
-                       } else if (errno == EINVAL) {
-                               debug_warning("Invalid msgid or msgtype < 1 or out of data size \n");
-                       }
-                       debug_critical("Fail to callback send message msg queue : [%d] \n", g_cbid);
-                       MMSOUND_LEAVE_CRITICAL_SECTION(&g_msg_snd_cb_mutex);
-                       return MM_ERROR_SOUND_INTERNAL;
-               } else {
-                       break;
-               }
-       }
+       return mm_sound_mgr_ipc_dbus_send_signal_freeze ( command, pid);
+}
 
-       MMSOUND_LEAVE_CRITICAL_SECTION(&g_msg_snd_cb_mutex);
+/* should be converted to general type */
+int _MMIpcCBSndMsg(mm_ipc_msg_t *msg)
+{
+//     return _MMIpcMsgqCBSndMsg(msg);
+       return MM_ERROR_NONE;
+}
+int _MMIpcCBRecvMsg(mm_ipc_msg_t *msg)
+{
+//     return _MMIpcMsgqCBRecvMsg(msg);
+       return MM_ERROR_NONE;
+}
+int _MMIpcCBMsgEnQueueAgain(mm_ipc_msg_t *msg)
+{
+//     return _MMIpcMsgqCBMsgEnQueueAgain(msg);
        return MM_ERROR_NONE;
 }
 
+int MMSoundMgrIpcInit(void)
+{
+       return MM_ERROR_NONE;
+}
 
+int MMSoundMgrIpcFini(void)
+{
+       return MM_ERROR_NONE;
+}
diff --git a/server/mm_sound_mgr_ipc_dbus.c b/server/mm_sound_mgr_ipc_dbus.c
new file mode 100644 (file)
index 0000000..e1c5b60
--- /dev/null
@@ -0,0 +1,2217 @@
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <mm_types.h>
+#include <mm_error.h>
+#include <mm_debug.h>
+
+#include <gio/gio.h>
+#include <glib.h>
+
+#ifdef USE_SECURITY
+#include <security-server.h>
+#define COOKIE_SIZE 20
+#endif
+
+#include "include/mm_sound_mgr_ipc_dbus.h"
+#include "include/mm_sound_mgr_ipc.h"
+
+
+#define BUS_NAME_SOUND_SERVER "org.tizen.SoundServer"
+#define OBJECT_SOUND_SERVER "/org/tizen/SoundServer1"
+#define INTERFACE_SOUND_SERVER "org.tizen.SoundServer1"
+
+/* workaround for AF volume gain tuning */
+#define PROC_DBUS_OBJECT       "/Org/Tizen/ResourceD/Process"
+#define PROC_DBUS_INTERFACE    "org.tizen.resourced.process"
+#define PROC_DBUS_METHOD       "ProcExclude"
+
+#define OBJECT_ASM "/org/tizen/asm"
+#define INTERFACE_ASM "org.tizen.asm"
+
+/* Introspection data for the service we are exporting */
+  static const gchar introspection_xml[] =
+  "<node>"
+  "  <interface name='org.tizen.SoundServer1'>"
+  "    <method name='MethodTest1'>"
+  "      <arg type='i' name='num1' direction='in'/>"
+  "      <arg type='i' name='num2' direction='in'/>"
+  "      <arg type='i' name='multiple' direction='out'/>"
+  "    </method>"
+  "    <method name='GetBTA2DPStatus'>"
+  "      <arg type='b' name='is_bt_on' direction='out'/>"
+  "      <arg type='s' name='bt_name' direction='out'/>"
+  "    </method>"
+  "    <method name='PlayFileStart'>"
+  "      <arg type='s' name='filename' direction='in'/>"
+  "      <arg type='i' name='tone' direction='in'/>"
+  "      <arg type='i' name='repeat' direction='in'/>"
+  "      <arg type='i' name='volume' direction='in'/>"
+  "      <arg type='i' name='vol_config' direction='in'/>"
+  "      <arg type='i' name='priority' direction='in'/>"
+  "      <arg type='i' name='session_type' direction='in'/>"
+  "      <arg type='i' name='session_option' direction='in'/>"
+  "      <arg type='i' name='client_pid' direction='in'/>"
+  "      <arg type='i' name='keytone' direction='in'/>"
+  "      <arg type='i' name='handle_route' direction='in'/>"
+  "      <arg type='b' name='enable_session' direction='in'/>"
+  "      <arg type='s' name='stream_type' direction='in'/>"
+  "      <arg type='i' name='stream_index' direction='in'/>"
+  "      <arg type='i' name='handle' direction='out'/>"
+  "    </method>"
+  "     <method name='PlayFileStartWithStreamInfo'>"
+  "       <arg type='s' name='filename' direction='in'/>"
+  "       <arg type='i' name='repeat' direction='in'/>"
+  "       <arg type='i' name='volume' direction='in'/>"
+  "       <arg type='i' name='priority' direction='in'/>"
+  "       <arg type='i' name='client_pid' direction='in'/>"
+  "       <arg type='i' name='handle_route' direction='in'/>"
+  "       <arg type='s' name='stream_type' direction='in'/>"
+  "       <arg type='i' name='stream_index' direction='in'/>"
+  "       <arg type='i' name='handle' direction='out'/>"
+  "     </method>"
+  "    <method name='PlayFileStop'>"
+  "      <arg type='i' name='handle' direction='in'/>"
+  "    </method>"
+  "    <method name='PlayDTMF'>"
+  "      <arg type='i' name='tone' direction='in'/>"
+  "      <arg type='i' name='repeat' direction='in'/>"
+  "      <arg type='i' name='volume' direction='in'/>"
+  "      <arg type='i' name='vol_config' direction='in'/>"
+  "      <arg type='i' name='session_type' direction='in'/>"
+  "      <arg type='i' name='session_option' direction='in'/>"
+  "      <arg type='i' name='client_pid' direction='in'/>"
+  "      <arg type='b' name='enable_session' direction='in'/>"
+  "         <arg type='s' name='stream_type' direction='in'/>"
+  "         <arg type='i' name='stream_index' direction='in'/>"
+  "      <arg type='i' name='handle' direction='out'/>"
+  "    </method>"
+  "     <method name='PlayDTMFWithStreamInfo'>"
+  "       <arg type='i' name='tone' direction='in'/>"
+  "       <arg type='i' name='repeat' direction='in'/>"
+  "       <arg type='i' name='volume' direction='in'/>"
+  "       <arg type='i' name='client_pid' direction='in'/>"
+  "       <arg type='s' name='stream_type' direction='in'/>"
+  "       <arg type='i' name='stream_index' direction='in'/>"
+  "       <arg type='i' name='handle' direction='out'/>"
+  "     </method>"
+  "    <method name='SetPathForActiveDevice'>"
+  "    </method>"
+  "    <method name='GetConnectedDeviceList'>"
+  "      <arg type='i' name='device_mask' direction='in'/>"
+  "      <arg type='a(iiiis)' name='device_list' direction='out'/>"
+  "    </method>"
+  "    <method name='GetAudioPath'>"
+  "      <arg type='i' name='device_in' direction='out'/>"
+  "      <arg type='i' name='device_out' direction='out'/>"
+  "    </method>"
+  "    <method name='RegisterFocus'>"
+#ifdef SUPPORT_CONTAINER
+#ifdef USE_SECURITY
+  "      <arg name='container' type='ay' direction='in'/>"
+#else
+  "      <arg name='container' type='s' direction='in'/>"
+#endif
+#endif
+  "      <arg name='pid' type='i' direction='in'/>"
+  "      <arg name='handle_id' type='i' direction='in'/>"
+  "      <arg name='stream_type' type='s' direction='in'/>"
+  "    </method>"
+  "    <method name='UnregisterFocus'>"
+  "      <arg name='pid' type='i' direction='in'/>"
+  "      <arg name='handle_id' type='i' direction='in'/>"
+  "    </method>"
+  "    <method name='AcquireFocus'>"
+  "      <arg name='pid' type='i' direction='in'/>"
+  "      <arg name='handle_id' type='i' direction='in'/>"
+  "      <arg name='focus_type' type='i' direction='in'/>"
+  "      <arg name='name' type='s' direction='in'/>"
+  "    </method>"
+  "    <method name='ReleaseFocus'>"
+  "      <arg name='pid' type='i' direction='in'/>"
+  "      <arg name='handle_id' type='i' direction='in'/>"
+  "      <arg name='focus_type' type='i' direction='in'/>"
+  "      <arg name='name' type='s' direction='in'/>"
+  "    </method>"
+  "    <method name='WatchFocus'>"
+#ifdef SUPPORT_CONTAINER
+#ifdef USE_SECURITY
+         "      <arg name='container' type='ay' direction='in'/>"
+#else
+         "      <arg name='container' type='s' direction='in'/>"
+#endif
+#endif
+  "      <arg name='pid' type='i' direction='in'/>"
+  "      <arg name='handle_id' type='i' direction='in'/>"
+  "      <arg name='focus_type' type='i' direction='in'/>"
+  "    </method>"
+  "    <method name='UnwatchFocus'>"
+  "      <arg name='pid' type='i' direction='in'/>"
+  "      <arg name='handle_id' type='i' direction='in'/>"
+  "    </method>"
+  "    <method name='ASMRegisterSound'>"
+#ifdef SUPPORT_CONTAINER
+#ifdef USE_SECURITY
+  "      <arg name='container' type='ay' direction='in'/>"
+#else
+  "      <arg name='container' type='s' direction='in'/>"
+#endif
+#endif
+  "      <arg name='rcv_pid' type='i' direction='in'/>"
+  "      <arg name='rcv_handle' type='i' direction='in'/>"
+  "      <arg name='rcv_sound_event' type='i' direction='in'/>"
+  "      <arg name='rcv_request_id' type='i' direction='in'/>"
+  "      <arg name='rcv_sound_state' type='i' direction='in'/>"
+  "      <arg name='rcv_resource' type='i' direction='in'/>"
+  "      <arg name='snd_pid' type='i' direction='out'/>"
+  "      <arg name='snd_alloc_handle' type='i' direction='out'/>"
+  "      <arg name='snd_cmd_handle' type='i' direction='out'/>"
+  "      <arg name='snd_request_id' type='i' direction='out'/>"
+  "      <arg name='snd_sound_command' type='i' direction='out'/>"
+  "      <arg name='snd_sound_state' type='i' direction='out'/>"
+  "    </method>"
+  "    <method name='ASMUnregisterSound'>"
+  "      <arg name='rcv_pid' type='i' direction='in'/>"
+  "      <arg name='rcv_handle' type='i' direction='in'/>"
+  "      <arg name='rcv_sound_event' type='i' direction='in'/>"
+  "      <arg name='rcv_request_id' type='i' direction='in'/>"
+  "      <arg name='rcv_sound_state' type='i' direction='in'/>"
+  "      <arg name='rcv_resource' type='i' direction='in'/>"
+  "    </method>"
+  "    <method name='ASMRegisterWatcher'>"
+#ifdef SUPPORT_CONTAINER
+#ifdef USE_SECURITY
+  "      <arg name='container' type='ay' direction='in'/>"
+#else
+  "      <arg name='container' type='s' direction='in'/>"
+#endif
+#endif
+  "      <arg name='rcv_pid' type='i' direction='in'/>"
+  "      <arg name='rcv_handle' type='i' direction='in'/>"
+  "      <arg name='rcv_sound_event' type='i' direction='in'/>"
+  "      <arg name='rcv_request_id' type='i' direction='in'/>"
+  "      <arg name='rcv_sound_state' type='i' direction='in'/>"
+  "      <arg name='rcv_resource' type='i' direction='in'/>"
+  "      <arg name='snd_pid' type='i' direction='out'/>"
+  "      <arg name='snd_alloc_handle' type='i' direction='out'/>"
+  "      <arg name='snd_cmd_handle' type='i' direction='out'/>"
+  "      <arg name='snd_request_id' type='i' direction='out'/>"
+  "      <arg name='snd_sound_command' type='i' direction='out'/>"
+  "      <arg name='snd_sound_state' type='i' direction='out'/>"
+  "    </method>"
+  "    <method name='ASMUnregisterWatcher'>"
+  "      <arg name='rcv_pid' type='i' direction='in'/>"
+  "      <arg name='rcv_handle' type='i' direction='in'/>"
+  "      <arg name='rcv_sound_event' type='i' direction='in'/>"
+  "      <arg name='rcv_request_id' type='i' direction='in'/>"
+  "      <arg name='rcv_sound_state' type='i' direction='in'/>"
+  "      <arg name='rcv_resource' type='i' direction='in'/>"
+  "    </method>"
+  "    <method name='ASMGetMyState'>"
+  "      <arg name='rcv_pid' type='i' direction='in'/>"
+  "      <arg name='rcv_handle' type='i' direction='in'/>"
+  "      <arg name='rcv_sound_event' type='i' direction='in'/>"
+  "      <arg name='rcv_request_id' type='i' direction='in'/>"
+  "      <arg name='rcv_sound_state' type='i' direction='in'/>"
+  "      <arg name='rcv_resource' type='i' direction='in'/>"
+  "      <arg name='snd_pid' type='i' direction='out'/>"
+  "      <arg name='snd_alloc_handle' type='i' direction='out'/>"
+  "      <arg name='snd_cmd_handle' type='i' direction='out'/>"
+  "      <arg name='snd_request_id' type='i' direction='out'/>"
+  "      <arg name='snd_sound_state' type='i' direction='out'/>"
+  "    </method>"
+  "    <method name='ASMGetState'>"
+  "      <arg name='rcv_pid' type='i' direction='in'/>"
+  "      <arg name='rcv_handle' type='i' direction='in'/>"
+  "      <arg name='rcv_sound_event' type='i' direction='in'/>"
+  "      <arg name='rcv_request_id' type='i' direction='in'/>"
+  "      <arg name='rcv_sound_state' type='i' direction='in'/>"
+  "      <arg name='rcv_resource' type='i' direction='in'/>"
+  "      <arg name='snd_pid' type='i' direction='out'/>"
+  "      <arg name='snd_alloc_handle' type='i' direction='out'/>"
+  "      <arg name='snd_cmd_handle' type='i' direction='out'/>"
+  "      <arg name='snd_request_id' type='i' direction='out'/>"
+  "      <arg name='snd_sound_state' type='i' direction='out'/>"
+  "    </method>"
+  "    <method name='ASMSetState'>"
+  "      <arg name='rcv_pid' type='i' direction='in'/>"
+  "      <arg name='rcv_handle' type='i' direction='in'/>"
+  "      <arg name='rcv_sound_event' type='i' direction='in'/>"
+  "      <arg name='rcv_request_id' type='i' direction='in'/>"
+  "      <arg name='rcv_sound_state' type='i' direction='in'/>"
+  "      <arg name='rcv_resource' type='i' direction='in'/>"
+  "      <arg name='snd_pid' type='i' direction='out'/>"
+  "      <arg name='snd_alloc_handle' type='i' direction='out'/>"
+  "      <arg name='snd_cmd_handle' type='i' direction='out'/>"
+  "      <arg name='snd_request_id' type='i' direction='out'/>"
+  "      <arg name='snd_sound_command' type='i' direction='out'/>"
+  "      <arg name='snd_sound_state' type='i' direction='out'/>"
+  "      <arg name='snd_error_code' type='i' direction='out'/>"
+  "    </method>"
+  "    <method name='ASMSetSubsession'>"
+  "      <arg name='rcv_pid' type='i' direction='in'/>"
+  "      <arg name='rcv_handle' type='i' direction='in'/>"
+  "      <arg name='rcv_sound_event' type='i' direction='in'/>"
+  "      <arg name='rcv_request_id' type='i' direction='in'/>"
+  "      <arg name='rcv_sound_state' type='i' direction='in'/>"
+  "      <arg name='rcv_resource' type='i' direction='in'/>"
+  "      <arg name='snd_pid' type='i' direction='out'/>"
+  "      <arg name='snd_alloc_handle' type='i' direction='out'/>"
+  "      <arg name='snd_cmd_handle' type='i' direction='out'/>"
+  "      <arg name='snd_request_id' type='i' direction='out'/>"
+  "    </method>"
+  "    <method name='ASMGetSubsession'>"
+  "      <arg name='rcv_pid' type='i' direction='in'/>"
+  "      <arg name='rcv_handle' type='i' direction='in'/>"
+  "      <arg name='rcv_sound_event' type='i' direction='in'/>"
+  "      <arg name='rcv_request_id' type='i' direction='in'/>"
+  "      <arg name='rcv_sound_state' type='i' direction='in'/>"
+  "      <arg name='rcv_resource' type='i' direction='in'/>"
+  "      <arg name='snd_pid' type='i' direction='out'/>"
+  "      <arg name='snd_alloc_handle' type='i' direction='out'/>"
+  "      <arg name='snd_cmd_handle' type='i' direction='out'/>"
+  "      <arg name='snd_request_id' type='i' direction='out'/>"
+  "      <arg name='snd_sound_command' type='i' direction='out'/>"
+  "    </method>"
+  "    <method name='ASMSetSubevent'>"
+  "      <arg name='rcv_pid' type='i' direction='in'/>"
+  "      <arg name='rcv_handle' type='i' direction='in'/>"
+  "      <arg name='rcv_sound_event' type='i' direction='in'/>"
+  "      <arg name='rcv_request_id' type='i' direction='in'/>"
+  "      <arg name='rcv_sound_state' type='i' direction='in'/>"
+  "      <arg name='rcv_resource' type='i' direction='in'/>"
+  "      <arg name='snd_pid' type='i' direction='out'/>"
+  "      <arg name='snd_alloc_handle' type='i' direction='out'/>"
+  "      <arg name='snd_cmd_handle' type='i' direction='out'/>"
+  "      <arg name='snd_request_id' type='i' direction='out'/>"
+  "      <arg name='snd_sound_command' type='i' direction='out'/>"
+  "      <arg name='snd_sound_state' type='i' direction='out'/>"
+  "    </method>"
+  "    <method name='ASMGetSubevent'>"
+  "      <arg name='rcv_pid' type='i' direction='in'/>"
+  "      <arg name='rcv_handle' type='i' direction='in'/>"
+  "      <arg name='rcv_sound_event' type='i' direction='in'/>"
+  "      <arg name='rcv_request_id' type='i' direction='in'/>"
+  "      <arg name='rcv_sound_state' type='i' direction='in'/>"
+  "      <arg name='rcv_resource' type='i' direction='in'/>"
+  "      <arg name='snd_pid' type='i' direction='out'/>"
+  "      <arg name='snd_alloc_handle' type='i' direction='out'/>"
+  "      <arg name='snd_cmd_handle' type='i' direction='out'/>"
+  "      <arg name='snd_request_id' type='i' direction='out'/>"
+  "      <arg name='snd_sound_command' type='i' direction='out'/>"
+  "    </method>"
+  "    <method name='ASMSetSessionOption'>"
+  "      <arg name='rcv_pid' type='i' direction='in'/>"
+  "      <arg name='rcv_handle' type='i' direction='in'/>"
+  "      <arg name='rcv_sound_event' type='i' direction='in'/>"
+  "      <arg name='rcv_request_id' type='i' direction='in'/>"
+  "      <arg name='rcv_sound_state' type='i' direction='in'/>"
+  "      <arg name='rcv_resource' type='i' direction='in'/>"
+  "      <arg name='snd_pid' type='i' direction='out'/>"
+  "      <arg name='snd_alloc_handle' type='i' direction='out'/>"
+  "      <arg name='snd_cmd_handle' type='i' direction='out'/>"
+  "      <arg name='snd_request_id' type='i' direction='out'/>"
+  "      <arg name='snd_sound_command' type='i' direction='out'/>"
+  "      <arg name='snd_sound_state' type='i' direction='out'/>"
+  "    </method>"
+  "    <method name='ASMGetSessionOption'>"
+  "      <arg name='rcv_pid' type='i' direction='in'/>"
+  "      <arg name='rcv_handle' type='i' direction='in'/>"
+  "      <arg name='rcv_sound_event' type='i' direction='in'/>"
+  "      <arg name='rcv_request_id' type='i' direction='in'/>"
+  "      <arg name='rcv_sound_state' type='i' direction='in'/>"
+  "      <arg name='rcv_resource' type='i' direction='in'/>"
+  "      <arg name='snd_pid' type='i' direction='out'/>"
+  "      <arg name='snd_alloc_handle' type='i' direction='out'/>"
+  "      <arg name='snd_cmd_handle' type='i' direction='out'/>"
+  "      <arg name='snd_request_id' type='i' direction='out'/>"
+  "      <arg name='snd_sound_command' type='i' direction='out'/>"
+  "      <arg name='snd_option_flag' type='i' direction='out'/>"
+  "    </method>"
+  "    <method name='ASMResetResumeTag'>"
+  "      <arg name='rcv_pid' type='i' direction='in'/>"
+  "      <arg name='rcv_handle' type='i' direction='in'/>"
+  "      <arg name='rcv_sound_event' type='i' direction='in'/>"
+  "      <arg name='rcv_request_id' type='i' direction='in'/>"
+  "      <arg name='rcv_sound_state' type='i' direction='in'/>"
+  "      <arg name='rcv_resource' type='i' direction='in'/>"
+  "      <arg name='snd_pid' type='i' direction='out'/>"
+  "      <arg name='snd_alloc_handle' type='i' direction='out'/>"
+  "      <arg name='snd_cmd_handle' type='i' direction='out'/>"
+  "      <arg name='snd_request_id' type='i' direction='out'/>"
+  "      <arg name='snd_sound_command' type='i' direction='out'/>"
+  "      <arg name='snd_sound_state' type='i' direction='out'/>"
+  "    </method>"
+  "    <method name='ASMDump'>"
+  "      <arg name='rcv_pid' type='i' direction='in'/>"
+  "      <arg name='rcv_handle' type='i' direction='in'/>"
+  "      <arg name='rcv_sound_event' type='i' direction='in'/>"
+  "      <arg name='rcv_request_id' type='i' direction='in'/>"
+  "      <arg name='rcv_sound_state' type='i' direction='in'/>"
+  "      <arg name='rcv_resource' type='i' direction='in'/>"
+  "    </method>"
+  "  </interface>"
+  "</node>";
+GDBusConnection* conn_g;
+
+typedef void (*dbus_method_handler)(GDBusMethodInvocation *invocation);
+typedef int (*dbus_signal_sender)(GDBusConnection *conn, GVariant *parameter);
+
+struct mm_sound_dbus_method{
+       struct mm_sound_dbus_method_info info;
+        dbus_method_handler handler;
+};
+
+struct mm_sound_dbus_signal{
+       struct mm_sound_dbus_signal_info info;
+       dbus_signal_sender sender;
+};
+
+static void handle_method_play_file_start(GDBusMethodInvocation* invocation);
+static void handle_method_play_file_start_with_stream_info(GDBusMethodInvocation* invocation);
+static void handle_method_play_file_stop(GDBusMethodInvocation* invocation);
+static void handle_method_play_dtmf(GDBusMethodInvocation* invocation);
+static void handle_method_play_dtmf_with_stream_info(GDBusMethodInvocation* invocation);
+static void handle_method_get_bt_a2dp_status(GDBusMethodInvocation* invocation);
+static void handle_method_test(GDBusMethodInvocation* invocation);
+static void handle_method_set_sound_path_for_active_device(GDBusMethodInvocation* invocation);
+static void handle_method_get_audio_path(GDBusMethodInvocation* invocation);
+static void handle_method_get_connected_device_list(GDBusMethodInvocation* invocation);
+
+static void handle_method_register_focus(GDBusMethodInvocation* invocation);
+static void handle_method_unregister_focus(GDBusMethodInvocation* invocation);
+static void handle_method_acquire_focus(GDBusMethodInvocation* invocation);
+static void handle_method_release_focus(GDBusMethodInvocation* invocation);
+static void handle_method_watch_focus(GDBusMethodInvocation* invocation);
+static void handle_method_unwatch_focus(GDBusMethodInvocation* invocation);
+
+static void handle_method_asm_register_sound(GDBusMethodInvocation* invocation);
+static void handle_method_asm_unregister_sound(GDBusMethodInvocation* invocation);
+static void handle_method_asm_register_watcher(GDBusMethodInvocation* invocation);
+static void handle_method_asm_unregister_watcher(GDBusMethodInvocation* invocation);
+static void handle_method_asm_get_mystate(GDBusMethodInvocation* invocation);
+static void handle_method_asm_get_state(GDBusMethodInvocation* invocation);
+static void handle_method_asm_set_state(GDBusMethodInvocation* invocation);
+static void handle_method_asm_set_subsession(GDBusMethodInvocation* invocation);
+static void handle_method_asm_get_subsession(GDBusMethodInvocation* invocation);
+static void handle_method_asm_set_subevent(GDBusMethodInvocation* invocation);
+static void handle_method_asm_get_subevent(GDBusMethodInvocation* invocation);
+static void handle_method_asm_set_session_option(GDBusMethodInvocation* invocation);
+static void handle_method_asm_get_session_option(GDBusMethodInvocation* invocation);
+static void handle_method_asm_reset_resume_tag(GDBusMethodInvocation* invocation);
+static void handle_method_asm_dump(GDBusMethodInvocation* invocation);
+
+/* Currently , Just using method's name and handler */
+/* TODO : generate introspection xml automatically, with these value include argument and reply */
+/* TODO : argument check with these information */
+/* TODO : divide object and interface with features (ex. play, path, device, focus, asm) */
+struct mm_sound_dbus_method methods[METHOD_CALL_MAX] = {
+       [METHOD_CALL_TEST] = {
+               .info = {
+                       .name = "MethodTest1",
+               },
+               .handler = handle_method_test
+       },
+       [METHOD_CALL_PLAY_FILE_START] = {
+               .info = {
+                       .name = "PlayFileStart",
+               },
+               .handler = handle_method_play_file_start
+       },
+       [METHOD_CALL_PLAY_FILE_START_WITH_STREAM_INFO] = {
+               .info = {
+                       .name = "PlayFileStartWithStreamInfo",
+               },
+               .handler = handle_method_play_file_start_with_stream_info
+       },
+       [METHOD_CALL_PLAY_FILE_STOP] = {
+               .info = {
+                       .name = "PlayFileStop",
+               },
+               .handler = handle_method_play_file_stop
+       },
+       [METHOD_CALL_PLAY_DTMF] = {
+               .info = {
+                       .name = "PlayDTMF",
+               },
+               .handler = handle_method_play_dtmf
+       },
+       [METHOD_CALL_PLAY_DTMF_WITH_STREAM_INFO] = {
+               .info = {
+                       .name = "PlayDTMFWithStreamInfo",
+               },
+               .handler = handle_method_play_dtmf_with_stream_info
+       },
+       [METHOD_CALL_GET_BT_A2DP_STATUS] = {
+               .info = {
+                       .name = "GetBTA2DPStatus",
+               },
+               .handler = handle_method_get_bt_a2dp_status
+       },
+       [METHOD_CALL_SET_PATH_FOR_ACTIVE_DEVICE] = {
+               .info = {
+                       .name = "SetPathForActiveDevice",
+               },
+               .handler = handle_method_set_sound_path_for_active_device
+       },
+       [METHOD_CALL_GET_AUDIO_PATH] = {
+               .info = {
+                       .name = "GetAudioPath",
+               },
+               .handler = handle_method_get_audio_path
+       },
+       [METHOD_CALL_GET_CONNECTED_DEVICE_LIST] = {
+               .info = {
+                       .name = "GetConnectedDeviceList",
+               },
+               .handler = handle_method_get_connected_device_list
+       },
+       [METHOD_CALL_REGISTER_FOCUS] = {
+               .info = {
+                       .name = "RegisterFocus",
+               },
+               .handler = handle_method_register_focus
+       },
+       [METHOD_CALL_UNREGISTER_FOCUS] = {
+               .info = {
+                       .name = "UnregisterFocus",
+               },
+               .handler = handle_method_unregister_focus
+       },
+       [METHOD_CALL_ACQUIRE_FOCUS] = {
+               .info = {
+                       .name = "AcquireFocus",
+               },
+               .handler = handle_method_acquire_focus
+       },
+       [METHOD_CALL_RELEASE_FOCUS] = {
+               .info = {
+                       .name = "ReleaseFocus",
+               },
+               .handler = handle_method_release_focus
+       },
+       [METHOD_CALL_WATCH_FOCUS] = {
+               .info = {
+                       .name = "WatchFocus",
+               },
+               .handler = handle_method_watch_focus
+       },
+       [METHOD_CALL_UNWATCH_FOCUS] = {
+               .info = {
+                       .name = "UnwatchFocus",
+               },
+               .handler = handle_method_unwatch_focus
+       },
+       [METHOD_CALL_ASM_REGISTER_SOUND] = {
+               .info = {
+                       .name = "ASMRegisterSound",
+               },
+               .handler = handle_method_asm_register_sound
+       },
+       [METHOD_CALL_ASM_UNREGISTER_SOUND] = {
+               .info = {
+                       .name = "ASMUnregisterSound",
+               },
+               .handler = handle_method_asm_unregister_sound
+       },
+       [METHOD_CALL_ASM_REGISTER_WATCHER] = {
+               .info = {
+                       .name = "ASMRegisterWatcher",
+               },
+               .handler = handle_method_asm_register_watcher
+       },
+       [METHOD_CALL_ASM_UNREGISTER_WATCHER] = {
+               .info = {
+                       .name = "ASMUnregisterWatcher",
+               },
+               .handler = handle_method_asm_unregister_watcher
+       },
+       [METHOD_CALL_ASM_GET_MYSTATE] = {
+               .info = {
+                       .name = "ASMGetMyState",
+               },
+               .handler = handle_method_asm_get_mystate
+       },
+       [METHOD_CALL_ASM_GET_STATE] = {
+               .info = {
+                       .name = "ASMGetState",
+               },
+               .handler = handle_method_asm_get_state
+       },
+       [METHOD_CALL_ASM_SET_STATE] = {
+               .info = {
+                       .name = "ASMSetState",
+               },
+               .handler = handle_method_asm_set_state
+       },
+       [METHOD_CALL_ASM_SET_SUBSESSION] = {
+               .info = {
+                       .name = "ASMSetSubsession",
+               },
+               .handler = handle_method_asm_set_subsession
+       },
+       [METHOD_CALL_ASM_GET_SUBSESSION] = {
+               .info = {
+                       .name = "ASMGetSubsession",
+               },
+               .handler = handle_method_asm_get_subsession
+       },
+       [METHOD_CALL_ASM_SET_SUBEVENT] = {
+               .info = {
+                       .name = "ASMSetSubevent",
+               },
+               .handler = handle_method_asm_set_subevent
+       },
+       [METHOD_CALL_ASM_GET_SUBEVENT] = {
+               .info = {
+                       .name = "ASMGetSubevent",
+               },
+               .handler = handle_method_asm_get_subevent
+       },
+       [METHOD_CALL_ASM_SET_SESSION_OPTION] = {
+               .info = {
+                       .name = "ASMSetSessionOption",
+               },
+               .handler = handle_method_asm_set_session_option
+       },
+       [METHOD_CALL_ASM_GET_SESSION_OPTION] = {
+               .info = {
+                       .name = "ASMGetSessionOption",
+               },
+               .handler = handle_method_asm_get_session_option
+       },
+       [METHOD_CALL_ASM_RESET_RESUME_TAG] = {
+               .info = {
+                       .name = "ASMResetResumeTag",
+               },
+               .handler = handle_method_asm_reset_resume_tag
+       },
+       [METHOD_CALL_ASM_DUMP] = {
+               .info = {
+                       .name = "ASMDump",
+               },
+               .handler = handle_method_asm_dump
+       },
+};
+
+struct mm_sound_dbus_signal signals[SIGNAL_MAX] = {
+       [SIGNAL_TEST] = {
+               .info = {
+                       .name = "SignalTest1",
+               },
+       },
+       [SIGNAL_PLAY_FILE_END] = {
+               .info = {
+                       .name = "PlayFileEnd",
+               },
+       },
+       [SIGNAL_VOLUME_CHANGED] = {
+               .info = {
+                       .name = "VolumeChanged",
+               },
+       },
+       [SIGNAL_DEVICE_CONNECTED] = {
+               .info = {
+                       .name = "DeviceConnected",
+               },
+       },
+       [SIGNAL_DEVICE_INFO_CHANGED] = {
+               .info = {
+                       .name = "DeviceInfoChanged",
+               },
+       },
+       [SIGNAL_FOCUS_CHANGED] = {
+               .info = {
+                       .name = "FocusChanged",
+               },
+       },
+       [SIGNAL_FOCUS_WATCH] = {
+               .info = {
+                       .name = "FocusWatch",
+               },
+       }
+};
+
+
+
+static GDBusNodeInfo *introspection_data = NULL;
+guint sound_server_owner_id ;
+
+/*
+        For pass error code with 'g_dbus_method_invocation_return_error'
+        We have to use some glib features like GError, GQuark
+*/
+/* Only For error types which is currently being used in server-side */
+static const GDBusErrorEntry mm_sound_error_entries[] =
+{
+       {MM_ERROR_OUT_OF_MEMORY, "org.tizen.multimedia.OutOfMemory"},
+       {MM_ERROR_OUT_OF_STORAGE, "org.tizen.multimedia.OutOfStorage"},
+       {MM_ERROR_INVALID_ARGUMENT, "org.tizen.multimedia.InvalidArgument"},
+       {MM_ERROR_POLICY_INTERNAL, "org.tizen.multimedia.PolicyInternal"},
+       {MM_ERROR_NOT_SUPPORT_API, "org.tizen.multimedia.NotSupportAPI"},
+       {MM_ERROR_POLICY_BLOCKED, "org.tizen.multimedia.PolicyBlocked"},
+       {MM_ERROR_END_OF_FILE, "org.tizen.multimedia.EndOfFile"},
+       {MM_ERROR_COMMON_OUT_OF_RANGE, "org.tizen.multimedia.common.OutOfRange"},
+       {MM_ERROR_COMMON_UNKNOWN, "org.tizen.multimedia.common.Unknown"},
+       {MM_ERROR_COMMON_NO_FREE_SPACE, "org.tizen.multimedia.common.NoFreeSpace"},
+       {MM_ERROR_SOUND_INTERNAL, "org.tizen.multimedia.audio.Internal"},
+       {MM_ERROR_SOUND_INVALID_STATE, "org.tizen.multimedia.audio.InvalidState"},
+       {MM_ERROR_SOUND_NO_FREE_SPACE, "org.tizen.multimedia.audio.NoFreeSpace"},
+       {MM_ERROR_SOUND_UNSUPPORTED_MEDIA_TYPE, "org.tizen.multimedia.audio.UnsupportedMediaType"},
+       {MM_ERROR_SOUND_INVALID_POINTER, "org.tizen.multimedia.audio.InvalidPointer"},
+       {MM_ERROR_SOUND_INVALID_FILE, "org.tizen.multimedia.audio.InvalidFile"},
+       {MM_ERROR_SOUND_FILE_NOT_FOUND, "org.tizen.multimedia.audio.FileNotFound"},
+       {MM_ERROR_SOUND_NO_DATA, "org.tizen.multimedia.audio.NoData"},
+       {MM_ERROR_SOUND_INVALID_PATH, "org.tizen.multimedia.audio.InvalidPath"},
+};
+
+static const char* _convert_error_code(int err_code)
+{
+       int i = 0;
+
+       for (i = 0; i < G_N_ELEMENTS(mm_sound_error_entries); i++) {
+               if (err_code == mm_sound_error_entries[i].error_code) {
+                       return mm_sound_error_entries[i].dbus_error_name;
+               }
+       }
+
+       return "org.tizen.multimedia.common.Unknown";
+}
+
+static int mm_sound_mgr_ipc_dbus_send_signal(int signal_type, GVariant *parameter)
+{
+       int ret = MM_ERROR_NONE;
+       GDBusConnection *conn = NULL;
+       GError* err = NULL;
+       gboolean emit_success = FALSE;
+
+       if (signal_type < 0 || signal_type >= SIGNAL_MAX || !parameter) {
+               debug_error("Invalid Argument");
+               return MM_ERROR_SOUND_INTERNAL;
+       }
+
+       debug_log("Signal Emit : %s", signals[signal_type].info.name);
+
+       if (!conn_g) {
+               conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+               if (!conn && err) {
+                       debug_error ("g_bus_get_sync() error (%s) ", err->message);
+                       g_error_free (err);
+                       return MM_ERROR_SOUND_INTERNAL;
+               }
+               conn_g = conn;
+       }
+/*
+       if (!g_variant_is_of_type(parameter, G_VARIANT_TYPE(signals[signal_type].info.argument))) {
+               debug_error("Invalid Signal Parameter");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+       */
+
+       emit_success = g_dbus_connection_emit_signal(conn_g, NULL, OBJECT_SOUND_SERVER, INTERFACE_SOUND_SERVER,
+                                                                                               signals[signal_type].info.name, parameter, &err);
+       if (!emit_success && err) {
+               debug_error("Emit signal (%s) failed, (%s)", signals[signal_type].info.name, err->message);
+               g_error_free(err);
+               return MM_ERROR_SOUND_INTERNAL;
+       }
+
+       return ret;
+}
+
+static int _get_sender_pid(GDBusMethodInvocation* invocation)
+{
+       GVariant* value;
+       guint pid;
+       const gchar* sender;
+       GDBusConnection * connection = NULL;
+       GError* err = NULL;
+
+       connection = g_dbus_method_invocation_get_connection(invocation);
+       sender = g_dbus_method_invocation_get_sender(invocation);
+
+       debug_error ("connection = %p, sender = %s", connection, sender);
+
+       value = g_dbus_connection_call_sync (connection, "org.freedesktop.DBus", "/org/freedesktop/DBus",
+                                                                               "org.freedesktop.DBus", "GetConnectionUnixProcessID",
+                                                                               g_variant_new("(s)", sender, NULL), NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
+       if (value) {
+               g_variant_get(value, "(u)", &pid);
+               debug_error ("Sender PID = [%d]", pid);
+       } else {
+               debug_error ("err code = %d, err msg = %s", err->code, err->message);
+       }
+       return pid;
+}
+
+static void _method_call_return_value(GDBusMethodInvocation *invocation, GVariant *params)
+{
+       const char *method_name;
+       method_name = g_dbus_method_invocation_get_method_name(invocation);
+       debug_error("Method Call '%s' success", method_name);
+       g_dbus_method_invocation_return_value(invocation, params);
+}
+static void _method_call_return_error(GDBusMethodInvocation *invocation, int ret)
+{
+       const char *err_name, *method_name;
+       err_name = _convert_error_code(ret);
+       method_name = g_dbus_method_invocation_get_method_name(invocation);
+       debug_error("Method Call '%s' failed, err '%s(%X)'", method_name, err_name, ret);
+       g_dbus_method_invocation_return_dbus_error(invocation, err_name, "failed");
+}
+
+static void handle_method_test(GDBusMethodInvocation* invocation)
+{
+       int ret = MM_ERROR_NONE;
+       int val = 0, val2 = 0;
+       GVariant* params = NULL;
+
+       debug_fenter();
+
+       if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
+               debug_error("Parameter for Method is NULL");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto send_reply;
+       }
+
+       g_variant_get(params, "(ii)", &val, &val2);
+       debug_log("Got value : %d , %d", val, val2);
+
+       if ((ret = mm_sound_mgr_ipc_dbus_send_signal(SIGNAL_TEST, g_variant_new("(i)", val+val2))) != MM_ERROR_NONE) {
+               debug_error("signal send error : %X", ret);
+       } else {
+               debug_error("signal send success");
+       }
+
+send_reply:
+       if (ret == MM_ERROR_NONE) {
+               _method_call_return_value(invocation, g_variant_new("(i)", val * val2));
+       } else {
+               ret = MM_ERROR_INVALID_ARGUMENT;
+               _method_call_return_error(invocation,  ret);
+       }
+
+       debug_fleave();
+}
+
+static void handle_method_play_file_start(GDBusMethodInvocation* invocation)
+{
+       gchar* filename = NULL;
+       char *stream_type = NULL;
+       gint32 ret = MM_ERROR_NONE, slotid = 0;
+       gint32 tone = 0, repeat = 0, volume = 0, vol_config = 0, priority = 0;
+       gint32 session_type = 0, session_option = 0, pid = 0, keytone = 0, handle_route =0, stream_index = 0;
+       gboolean enable_session = 0;
+       GVariant *params = NULL;
+
+       debug_fenter();
+
+       if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
+               debug_error("Parameter for Method is NULL");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto send_reply;
+       }
+
+       g_variant_get(params, "(siiiiiiiiiibsi)", &filename, &tone, &repeat, &volume,
+                     &vol_config, &priority, &session_type, &session_option, &pid, &keytone, &handle_route, &enable_session, &stream_type, &stream_index);
+       if (!filename) {
+           debug_error("filename null");
+           ret = MM_ERROR_SOUND_INTERNAL;
+           goto send_reply;
+       }
+       ret = _MMSoundMgrIpcPlayFile(filename, tone, repeat, volume, vol_config, priority,
+                               session_type, session_option, _get_sender_pid(invocation), keytone, handle_route, enable_session, &slotid, stream_type, stream_index);
+
+send_reply:
+       if (ret == MM_ERROR_NONE) {
+               _method_call_return_value(invocation, g_variant_new("(i)", slotid));
+       } else {
+               _method_call_return_error(invocation, ret);
+       }
+
+       debug_fleave();
+}
+
+static void handle_method_play_file_start_with_stream_info(GDBusMethodInvocation* invocation)
+{
+       gchar* filename = NULL;
+       char *stream_type = NULL;
+       gint32 ret = MM_ERROR_NONE, slotid = 0;
+       gint32 repeat = 0, volume = 0, priority = 0, pid = 0, handle_route =0, stream_index = 0;
+       GVariant *params = NULL;
+
+       debug_fenter();
+
+       if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
+               debug_error("Parameter for Method is NULL");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto send_reply;
+       }
+
+       g_variant_get(params, "(siiiiisi)", &filename, &repeat, &volume,
+                     &priority, &pid, &handle_route, &stream_type, &stream_index);
+       if (!filename) {
+           debug_error("filename null");
+           ret = MM_ERROR_SOUND_INTERNAL;
+           goto send_reply;
+       }
+       ret = _MMSoundMgrIpcPlayFileWithStreamInfo(filename, repeat, volume, priority,
+                               _get_sender_pid(invocation), handle_route, &slotid, stream_type, stream_index);
+
+send_reply:
+       if (ret == MM_ERROR_NONE) {
+               _method_call_return_value(invocation, g_variant_new("(i)", slotid));
+       } else {
+               _method_call_return_error(invocation, ret);
+       }
+
+       debug_fleave();
+}
+
+static void handle_method_play_dtmf(GDBusMethodInvocation* invocation)
+{
+       int ret = MM_ERROR_NONE, slotid = 0;
+       int tone = 0, repeat = 0, volume = 0, vol_config = 0, session_type = 0, session_option = 0, pid = 0, stream_index = 0;
+       char* stream_type = NULL;
+       gboolean enable_session = 0;
+       GVariant *params = NULL;
+
+       debug_fenter();
+
+       if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
+               debug_error("Parameter for Method is NULL");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto send_reply;
+       }
+
+       g_variant_get(params, "(iiiiiiibsi)", &tone, &repeat, &volume,
+                     &vol_config, &session_type, &session_option, &pid, &enable_session, &stream_type, &stream_index);
+       debug_error("volume - %d", volume);
+       ret = _MMSoundMgrIpcPlayDTMF(tone, repeat, volume, vol_config,
+                                    session_type, session_option, _get_sender_pid(invocation), enable_session, &slotid, stream_type, stream_index);
+
+send_reply:
+       if (ret == MM_ERROR_NONE) {
+               _method_call_return_value(invocation, g_variant_new("(i)", slotid));
+       } else {
+               _method_call_return_error(invocation, ret);
+       }
+
+
+       debug_fleave();
+}
+
+static void handle_method_play_dtmf_with_stream_info(GDBusMethodInvocation* invocation)
+{
+       int ret = MM_ERROR_NONE, slotid = 0;
+       int tone = 0, repeat = 0, volume = 0, pid = 0, stream_index = 0;
+       char* stream_type = NULL;
+       GVariant *params = NULL;
+
+       debug_fenter();
+
+       if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
+               debug_error("Parameter for Method is NULL");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto send_reply;
+       }
+
+       g_variant_get(params, "(iiiisi)", &tone, &repeat, &volume, &pid, &stream_type, &stream_index);
+       ret = _MMSoundMgrIpcPlayDTMFWithStreamInfo(tone, repeat, volume, _get_sender_pid(invocation), &slotid, stream_type, stream_index);
+
+send_reply:
+       if (ret == MM_ERROR_NONE) {
+               _method_call_return_value(invocation, g_variant_new("(i)", slotid));
+       } else {
+               _method_call_return_error(invocation, ret);
+       }
+
+       debug_fleave();
+}
+
+static void handle_method_play_file_stop(GDBusMethodInvocation* invocation)
+{
+       int ret = MM_ERROR_NONE;
+       int handle = 0;
+       GVariant *params = NULL;
+
+       debug_fenter();
+
+       if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
+               debug_error("Parameter for Method is NULL");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto send_reply;
+       }
+
+       g_variant_get(params, "(i)", &handle);
+       ret = _MMSoundMgrIpcStop(handle);
+
+send_reply:
+       if (ret == MM_ERROR_NONE) {
+               _method_call_return_value(invocation, g_variant_new("()"));
+       } else {
+               _method_call_return_error(invocation, ret);
+       }
+
+       debug_fleave();
+}
+static void handle_method_get_bt_a2dp_status(GDBusMethodInvocation* invocation)
+{
+       int ret = MM_ERROR_NONE;
+       gboolean is_bt_on = FALSE;
+       gchar* bt_name = NULL;
+
+       debug_fenter();
+
+//     ret = MMSoundMgrPulseHandleIsBtA2DPOnReq(&is_bt_on, &bt_name);
+
+send_reply:
+       if (ret == MM_ERROR_NONE) {
+               _method_call_return_value(invocation, g_variant_new("(bs)", is_bt_on, bt_name));
+       } else {
+               _method_call_return_error(invocation, ret);
+       }
+
+       if (bt_name)
+               g_free(bt_name);
+
+       debug_fleave();
+}
+
+static void handle_method_set_sound_path_for_active_device( GDBusMethodInvocation* invocation)
+{
+       int ret = MM_ERROR_NONE;
+       int device_in = 0, device_out = 0;
+       GVariant *params = NULL;
+
+       debug_fenter();
+
+       if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
+               debug_error("Parameter for Method is NULL");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto send_reply;
+       }
+
+       g_variant_get(params, "(ii)", &device_in, &device_out);
+       ret = __mm_sound_mgr_ipc_set_sound_path_for_active_device(device_in, device_out);
+
+send_reply:
+       if (ret == MM_ERROR_NONE) {
+               _method_call_return_value(invocation, g_variant_new("()"));
+       } else {
+               _method_call_return_error(invocation, ret);
+       }
+
+       debug_fleave();
+}
+
+static void handle_method_get_audio_path(GDBusMethodInvocation* invocation)
+{
+       int ret = MM_ERROR_NONE;
+       int device_in = 0, device_out = 0;
+
+       debug_fenter();
+
+       ret = __mm_sound_mgr_ipc_get_audio_path(&device_in, &device_out);
+
+send_reply:
+       if (ret == MM_ERROR_NONE) {
+               _method_call_return_value(invocation, g_variant_new("(ii)", device_in, device_out));
+       } else {
+               _method_call_return_error(invocation, ret);
+       }
+
+       debug_fleave();
+}
+
+static void handle_method_get_connected_device_list(GDBusMethodInvocation* invocation)
+{
+       int ret = MM_ERROR_NONE;
+       GVariant *params = NULL, *reply_v = NULL;
+       GVariantBuilder reply_builder;
+       int mask_flags = 0;
+       int devices_num = 0, device_idx = 0;
+       mm_sound_device_t *device_list = NULL, *device_entry = NULL;
+
+       if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
+               debug_error("Parameter for Method is NULL");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto send_reply;
+       }
+
+       g_variant_get(params, "(i)", &mask_flags);
+       debug_log("Get device list with device_flag %X", mask_flags);
+       if ((ret = __mm_sound_mgr_ipc_get_current_connected_device_list(mask_flags, &device_list, &devices_num))==MM_ERROR_NONE) {
+               g_variant_builder_init(&reply_builder, G_VARIANT_TYPE("(a(iiiis))"));
+               g_variant_builder_open(&reply_builder, G_VARIANT_TYPE("a(iiiis)"));
+               for (device_idx = 0; device_idx < devices_num; device_idx++) {
+                       device_entry = &device_list[device_idx];
+//                     debug_log("device(%d): id(%d), type(%d), io(%d), state(%d), name(%s) ", device_idx, device_entry->id, device_entry->type, device_entry->io_direction, device_entry->state, device_entry->name);
+                       g_variant_builder_add(&reply_builder, "(iiiis)", device_entry->id, device_entry->type, device_entry->io_direction, device_entry->state, device_entry->name);
+               }
+               g_variant_builder_close(&reply_builder);
+       }
+
+send_reply:
+       if (ret == MM_ERROR_NONE) {
+               _method_call_return_value(invocation, g_variant_builder_end(&reply_builder));
+               debug_log("Reply Sent");
+       } else {
+               _method_call_return_error(invocation, ret);
+       }
+}
+
+static void handle_method_register_focus(GDBusMethodInvocation* invocation)
+{
+       int ret = MM_ERROR_NONE;
+       int pid = 0, handle_id = 0;
+       const char* stream_type = NULL;
+       GVariant *params = NULL;
+#ifdef SUPPORT_CONTAINER
+       int container_pid = -1;
+       char* container = NULL;
+#ifdef USE_SECURITY
+       GVariant* cookie_data;
+#endif /* USE_SECURITY */
+#endif /* SUPPORT_CONTAINER */
+
+
+       debug_fenter();
+
+       if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
+               debug_error("Parameter for Method is NULL");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto send_reply;
+       }
+
+#ifdef SUPPORT_CONTAINER
+#ifdef USE_SECURITY
+       g_variant_get(params, "(@ayiis)", &cookie_data, &container_pid, &handle_id, &stream_type);
+       container = _get_container_from_cookie(cookie_data);
+       ret = __mm_sound_mgr_ipc_register_focus(_get_sender_pid(invocation), handle_id, stream_type, container, container_pid);
+
+       if (container)
+               free(container);
+#else /* USE_SECURITY */
+       g_variant_get(params, "(siis)", &container, &container_pid, &handle_id, &stream_type);
+       ret = __mm_sound_mgr_ipc_register_focus(_get_sender_pid(invocation), handle_id, stream_type, container, container_pid);
+
+#endif /* USE_SECURITY */
+#else /* SUPPORT_CONTAINER */
+       g_variant_get(params, "(iis)", &pid, &handle_id, &stream_type);
+       ret = __mm_sound_mgr_ipc_register_focus(_get_sender_pid(invocation), handle_id, stream_type);
+
+#endif /* SUPPORT_CONTAINER */
+
+send_reply:
+       if (ret == MM_ERROR_NONE) {
+               _method_call_return_value(invocation, g_variant_new("()"));
+       } else {
+               _method_call_return_error(invocation, ret);
+       }
+
+       debug_fleave();
+}
+
+static void handle_method_unregister_focus(GDBusMethodInvocation* invocation)
+{
+
+       int ret = MM_ERROR_NONE;
+       int pid = 0, handle_id = 0;
+       GVariant *params = NULL;
+
+       debug_fenter();
+
+       if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
+               debug_error("Parameter for Method is NULL");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto send_reply;
+       }
+
+       g_variant_get(params, "(ii)", &pid, &handle_id);
+       ret = __mm_sound_mgr_ipc_unregister_focus(_get_sender_pid(invocation), handle_id);
+
+send_reply:
+       if (ret == MM_ERROR_NONE) {
+               _method_call_return_value(invocation, g_variant_new("()"));
+       } else {
+               _method_call_return_error(invocation, ret);
+       }
+
+       debug_fleave();
+}
+
+static void handle_method_acquire_focus(GDBusMethodInvocation* invocation)
+{
+       int ret = MM_ERROR_NONE;
+       int pid = 0, handle_id = 0, focus_type = 0;
+       const char* name = NULL;
+       GVariant *params = NULL;
+
+       debug_fenter();
+
+       if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
+               debug_error("Parameter for Method is NULL");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto send_reply;
+       }
+
+       g_variant_get(params, "(iiis)", &pid, &handle_id, &focus_type, &name);
+       ret = __mm_sound_mgr_ipc_acquire_focus(_get_sender_pid(invocation), handle_id, focus_type, name);
+
+send_reply:
+       if (ret == MM_ERROR_NONE) {
+               _method_call_return_value(invocation, g_variant_new("()"));
+       } else {
+               _method_call_return_error(invocation, ret);
+       }
+
+       debug_fleave();
+}
+
+static void handle_method_release_focus(GDBusMethodInvocation* invocation)
+{
+       int ret = MM_ERROR_NONE;
+       int pid = 0, handle_id = 0, focus_type = 0;
+       const char* name = NULL;
+       GVariant *params = NULL;
+
+       debug_fenter();
+
+       if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
+               debug_error("Parameter for Method is NULL");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto send_reply;
+       }
+
+       g_variant_get(params, "(iiis)", &pid, &handle_id, &focus_type, &name);
+       ret = __mm_sound_mgr_ipc_release_focus(_get_sender_pid(invocation), handle_id, focus_type, name);
+
+send_reply:
+       if (ret == MM_ERROR_NONE) {
+               _method_call_return_value(invocation, g_variant_new("()"));
+       } else {
+               _method_call_return_error(invocation, ret);
+       }
+
+       debug_fleave();
+}
+
+static void handle_method_watch_focus(GDBusMethodInvocation* invocation)
+{
+       int ret = MM_ERROR_NONE;
+       int pid = 0, handle_id = 0, focus_type = 0;
+       GVariant *params = NULL;
+#ifdef SUPPORT_CONTAINER
+       int container_pid = -1;
+       char* container = NULL;
+#ifdef USE_SECURITY
+       GVariant* cookie_data;
+#endif /* USE_SECURITY */
+#endif /* SUPPORT_CONTAINER */
+
+       debug_fenter();
+
+       if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
+               debug_error("Parameter for Method is NULL");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto send_reply;
+       }
+
+#ifdef SUPPORT_CONTAINER
+#ifdef USE_SECURITY
+       g_variant_get(params, "(@ayiii)", &cookie_data, &container_pid, &handle_id, &focus_type);
+       container = _get_container_from_cookie(cookie_data);
+       ret = __mm_sound_mgr_ipc_watch_focus(_get_sender_pid(invocation), handle_id, focus_type, container, container_pid);
+
+       if (container)
+               free(container);
+#else /* USE_SECURITY */
+       g_variant_get(params, "(siii)", &container, &container_pid, &handle_id, &focus_type);
+       ret = __mm_sound_mgr_ipc_watch_focus(_get_sender_pid(invocation), handle_id, focus_type, container, container_pid);
+
+#endif /* USE_SECURITY */
+#else /* SUPPORT_CONTAINER */
+       g_variant_get(params, "(iii)", &pid, &handle_id, &focus_type);
+       ret = __mm_sound_mgr_ipc_watch_focus(_get_sender_pid(invocation), handle_id, focus_type);
+
+#endif /* SUPPORT_CONTAINER */
+
+send_reply:
+       if (ret == MM_ERROR_NONE) {
+               _method_call_return_value(invocation, g_variant_new("()"));
+       } else {
+               _method_call_return_error(invocation, ret);
+       }
+
+       debug_fleave();
+}
+
+static void handle_method_unwatch_focus (GDBusMethodInvocation* invocation)
+{
+       int ret = MM_ERROR_NONE;
+       int pid = 0;
+       int handle_id = 0;
+       GVariant *params = NULL;
+
+       debug_fenter();
+
+       if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
+               debug_error("Parameter for Method is NULL");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto send_reply;
+       }
+
+       g_variant_get(params, "(ii)", &pid, &handle_id);
+       ret = __mm_sound_mgr_ipc_unwatch_focus(_get_sender_pid(invocation), handle_id);
+
+send_reply:
+       if (ret == MM_ERROR_NONE) {
+               _method_call_return_value(invocation, g_variant_new("()"));
+       } else {
+               _method_call_return_error(invocation, ret);
+       }
+
+       debug_fleave();
+}
+
+/*********************** ASM METHODS ****************************/
+
+#ifdef SUPPORT_CONTAINER
+#ifdef USE_SECURITY
+static char* _get_container_from_cookie(GVariant* cookie_data)
+{
+       char* container = NULL;
+       int cookie_len = 0;
+       char* cookie = NULL;
+       int ret = 0;
+
+       cookie_len = g_variant_get_size(cookie_data);
+       if (cookie_len != COOKIE_SIZE) {
+               debug_error ("cookie_len = [%d]", cookie_len);
+               return NULL;
+       }
+
+       ret = security_server_get_zone_by_cookie(g_variant_get_data(cookie_data), &container);
+       if (ret == SECURITY_SERVER_API_SUCCESS) {
+               debug_error ("success!!!! zone = [%s]", container);
+       } else {
+               debug_error ("failed!!!! ret = [%d]", ret);
+       }
+
+       return container;
+}
+#endif /* USE_SECURITY */
+#endif /* SUPPORT_CONTAINER */
+
+// TODO : Too many arguments..
+static void handle_method_asm_register_sound(GDBusMethodInvocation* invocation)
+{
+       int ret = MM_ERROR_NONE;
+       int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0, resource = 0;
+       int pid_r = 0, alloc_handle_r = 0, cmd_handle_r = 0, request_id_r = 0, sound_command_r = 0, sound_state_r = 0;
+       GVariant *params = NULL;
+#ifdef SUPPORT_CONTAINER
+       int container_pid = -1;
+       char* container = NULL;
+#ifdef USE_SECURITY
+       GVariant* cookie_data;
+#endif /* USE_SECURITY */
+#endif /* SUPPORT_CONTAINER */
+
+       debug_fenter();
+
+       if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
+               debug_error("Parameter for Method is NULL");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto send_reply;
+       }
+
+#ifdef SUPPORT_CONTAINER
+#ifdef USE_SECURITY
+       g_variant_get(params, "(@ayiiiiii)", &cookie_data, &container_pid, &handle, &sound_event, &request_id, &sound_state, &resource);
+       container = _get_container_from_cookie(cookie_data);
+       ret = __mm_sound_mgr_ipc_asm_register_sound(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource,
+                                       container, container_pid, &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r, &sound_command_r, &sound_state_r);
+       if (container)
+               free(container);
+#else /* USE_SECURITY */
+       g_variant_get(params, "(siiiiii)", &container, &container_pid, &handle, &sound_event, &request_id, &sound_state, &resource);
+       ret = __mm_sound_mgr_ipc_asm_register_sound(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource,
+                                       container, container_pid, &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r, &sound_command_r, &sound_state_r);
+#endif /* USE_SECURITY */
+#else /* SUPPORT_CONTAINER */
+       g_variant_get(params, "(iiiiii)", &pid, &handle, &sound_event, &request_id, &sound_state, &resource);
+       ret = __mm_sound_mgr_ipc_asm_register_sound(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource,
+                                       &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r, &sound_command_r, &sound_state_r);
+#endif /* SUPPORT_CONTAINER */
+
+send_reply:
+       if (ret == MM_ERROR_NONE) {
+               _method_call_return_value(invocation, g_variant_new("(iiiiii)", pid_r, alloc_handle_r, cmd_handle_r,
+                                                                   request_id_r, sound_command_r, sound_state_r));
+       } else {
+               _method_call_return_error(invocation, ret);
+       }
+
+       debug_fleave();
+}
+
+static void handle_method_asm_unregister_sound(GDBusMethodInvocation* invocation)
+{
+       int ret = MM_ERROR_NONE;
+       int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0, resource = 0;
+       GVariant *params = NULL;
+
+       debug_fenter();
+
+       if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
+               debug_error("Parameter for Method is NULL");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto send_reply;
+       }
+
+       g_variant_get(params, "(iiiiii)", &pid, &handle, &sound_event, &request_id, &sound_state, &resource);
+       ret = __mm_sound_mgr_ipc_asm_unregister_sound(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource);
+
+send_reply:
+       if (ret == MM_ERROR_NONE) {
+               _method_call_return_value(invocation, g_variant_new("()"));
+       } else {
+               _method_call_return_error(invocation, ret);
+       }
+
+       debug_fleave();
+}
+
+static void handle_method_asm_register_watcher(GDBusMethodInvocation* invocation)
+{
+       int ret = MM_ERROR_NONE;
+       int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0, resource = 0;
+       int pid_r = 0, alloc_handle_r = 0, cmd_handle_r = 0, request_id_r = 0, sound_command_r = 0, sound_state_r = 0;
+       GVariant *params = NULL;
+#ifdef SUPPORT_CONTAINER
+       int container_pid = -1;
+       char* container = NULL;
+#ifdef USE_SECURITY
+       GVariant* cookie_data;
+#endif /* USE_SECURITY */
+#endif /* SUPPORT_CONTAINER */
+
+       debug_fenter();
+
+       if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
+               debug_error("Parameter for Method is NULL");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto send_reply;
+       }
+
+#ifdef SUPPORT_CONTAINER
+#ifdef USE_SECURITY
+       g_variant_get(params, "(@ayiiiiii)", &cookie_data, &container_pid, &handle, &sound_event, &request_id, &sound_state, &resource);
+       container = _get_container_from_cookie(cookie_data);
+       ret = __mm_sound_mgr_ipc_asm_register_watcher(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource,
+                                               container, container_pid, &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r, &sound_command_r, &sound_state_r);
+       if (container)
+               free(container);
+#else /* USE_SECURITY */
+       g_variant_get(params, "(siiiiii)", &container, &container_pid, &handle, &sound_event, &request_id, &sound_state, &resource);
+       ret = __mm_sound_mgr_ipc_asm_register_watcher(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource,
+                                       container, container_pid, &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r, &sound_command_r, &sound_state_r);
+#endif /* USE_SECURITY */
+#else /* SUPPORT_CONTAINER */
+       g_variant_get(params, "(iiiiii)", &pid, &handle, &sound_event, &request_id, &sound_state, &resource);
+       ret = __mm_sound_mgr_ipc_asm_register_watcher(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource,
+                       &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r, &sound_command_r, &sound_state_r);
+#endif /* SUPPORT_CONTAINER */
+
+send_reply:
+       if (ret == MM_ERROR_NONE) {
+               _method_call_return_value(invocation, g_variant_new("(iiiiii)", pid_r, alloc_handle_r, cmd_handle_r,
+                                                                   request_id_r, sound_command_r, sound_state_r));
+       } else {
+               _method_call_return_error(invocation, ret);
+       }
+
+       debug_fleave();
+}
+
+static void handle_method_asm_unregister_watcher(GDBusMethodInvocation* invocation)
+{
+       int ret = MM_ERROR_NONE;
+       int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0, resource = 0;
+       GVariant *params = NULL;
+
+       debug_fenter();
+
+       if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
+               debug_error("Parameter for Method is NULL");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto send_reply;
+       }
+
+       g_variant_get(params, "(iiiiii)", &pid, &handle, &sound_event, &request_id, &sound_state, &resource);
+       ret = __mm_sound_mgr_ipc_asm_unregister_watcher(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource);
+
+send_reply:
+       if (ret == MM_ERROR_NONE) {
+               _method_call_return_value(invocation, g_variant_new("()"));
+       } else {
+               _method_call_return_error(invocation, ret);
+       }
+
+       debug_fleave();
+}
+
+static void handle_method_asm_get_mystate(GDBusMethodInvocation* invocation)
+{
+       int ret = MM_ERROR_NONE;
+       int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0, resource = 0;
+       int pid_r = 0, alloc_handle_r = 0, cmd_handle_r = 0, request_id_r = 0, sound_command_r = 0, sound_state_r = 0;
+       GVariant *params = NULL;
+
+       debug_fenter();
+
+       if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
+               debug_error("Parameter for Method is NULL");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto send_reply;
+       }
+
+       g_variant_get(params, "(iiiiii)", &pid, &handle, &sound_event, &request_id, &sound_state, &resource);
+       ret = __mm_sound_mgr_ipc_asm_get_mystate(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource,
+                                                     &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r, &sound_state_r);
+
+send_reply:
+       if (ret == MM_ERROR_NONE) {
+               _method_call_return_value(invocation, g_variant_new("(iiiii)", pid_r, alloc_handle_r, cmd_handle_r,
+                                                                   request_id_r, sound_state_r));
+       } else {
+               _method_call_return_error(invocation, ret);
+       }
+
+       debug_fleave();
+}
+
+static void handle_method_asm_set_state(GDBusMethodInvocation* invocation)
+{
+       int ret = MM_ERROR_NONE;
+       int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0, resource = 0;
+       int pid_r = 0, alloc_handle_r = 0, cmd_handle_r = 0, request_id_r = 0, sound_command_r = 0, sound_state_r = 0, error_code_r = 0;
+       GVariant *params = NULL;
+
+       debug_fenter();
+
+       if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
+               debug_error("Parameter for Method is NULL");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto send_reply;
+       }
+
+       g_variant_get(params, "(iiiiii)", &pid, &handle, &sound_event, &request_id, &sound_state, &resource);
+       ret = __mm_sound_mgr_ipc_asm_set_state(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource,
+                                                     &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r, &sound_command_r, &sound_state_r, &error_code_r);
+
+send_reply:
+       if (ret == MM_ERROR_NONE) {
+               _method_call_return_value(invocation, g_variant_new("(iiiiiii)", pid_r, alloc_handle_r, cmd_handle_r,
+                                                                   request_id_r, sound_command_r, sound_state_r, error_code_r));
+       } else {
+               _method_call_return_error(invocation, ret);
+       }
+
+       debug_fleave();
+}
+
+static void handle_method_asm_get_state(GDBusMethodInvocation* invocation)
+{
+       int ret = MM_ERROR_NONE;
+       int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0, resource = 0;
+       int pid_r = 0, alloc_handle_r = 0, cmd_handle_r = 0, request_id_r = 0, sound_command_r = 0, sound_state_r = 0;
+       GVariant *params = NULL;
+
+       debug_fenter();
+
+       if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
+               debug_error("Parameter for Method is NULL");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto send_reply;
+       }
+
+       g_variant_get(params, "(iiiiii)", &pid, &handle, &sound_event, &request_id, &sound_state, &resource);
+       ret = __mm_sound_mgr_ipc_asm_get_state(pid, handle, sound_event, request_id, sound_state, resource,
+                                                     &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r, &sound_state_r);
+
+send_reply:
+       if (ret == MM_ERROR_NONE) {
+               _method_call_return_value(invocation, g_variant_new("(iiiii)", pid_r, alloc_handle_r, cmd_handle_r,
+                                                                   request_id_r, sound_state_r));
+       } else {
+               _method_call_return_error(invocation, ret);
+       }
+
+       debug_fleave();
+}
+
+static void handle_method_asm_set_subsession(GDBusMethodInvocation* invocation)
+{
+       int ret = MM_ERROR_NONE;
+       int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0, resource = 0;
+       int pid_r = 0, alloc_handle_r = 0, cmd_handle_r = 0, request_id_r = 0;
+       GVariant *params = NULL;
+
+       debug_fenter();
+
+       if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
+               debug_error("Parameter for Method is NULL");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto send_reply;
+       }
+
+       g_variant_get(params, "(iiiiii)", &pid, &handle, &sound_event, &request_id, &sound_state, &resource);
+       ret = __mm_sound_mgr_ipc_asm_set_subsession(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource,
+                                                     &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r);
+
+send_reply:
+       if (ret == MM_ERROR_NONE) {
+               _method_call_return_value(invocation, g_variant_new("(iiii)", pid_r, alloc_handle_r, cmd_handle_r,
+                                                                   request_id_r));
+       } else {
+               _method_call_return_error(invocation, ret);
+       }
+
+       debug_fleave();
+}
+
+static void handle_method_asm_get_subsession(GDBusMethodInvocation* invocation)
+{
+       int ret = MM_ERROR_NONE;
+       int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0, resource = 0;
+       int pid_r = 0, alloc_handle_r = 0, cmd_handle_r = 0, request_id_r = 0, sound_command_r = 0;
+       GVariant *params = NULL;
+
+       debug_fenter();
+
+       if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
+               debug_error("Parameter for Method is NULL");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto send_reply;
+       }
+
+       g_variant_get(params, "(iiiiii)", &pid, &handle, &sound_event, &request_id, &sound_state, &resource);
+       ret = __mm_sound_mgr_ipc_asm_get_subsession(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource,
+                                                     &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r, &sound_command_r);
+
+send_reply:
+       if (ret == MM_ERROR_NONE) {
+               _method_call_return_value(invocation, g_variant_new("(iiiii)", pid_r, alloc_handle_r, cmd_handle_r,
+                                                                   request_id_r, sound_command_r));
+       } else {
+               _method_call_return_error(invocation, ret);
+       }
+
+       debug_fleave();
+}
+
+static void handle_method_asm_set_subevent(GDBusMethodInvocation* invocation)
+{
+       int ret = MM_ERROR_NONE;
+       int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0, resource = 0;
+       int pid_r = 0, alloc_handle_r = 0, cmd_handle_r = 0, request_id_r = 0, sound_command_r = 0, sound_state_r = 0;
+       GVariant *params = NULL;
+
+       debug_fenter();
+
+       if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
+               debug_error("Parameter for Method is NULL");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto send_reply;
+       }
+
+       g_variant_get(params, "(iiiiii)", &pid, &handle, &sound_event, &request_id, &sound_state, &resource);
+       ret = __mm_sound_mgr_ipc_asm_set_subevent(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource,
+                                                  &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r, &sound_command_r, &sound_state_r);
+
+send_reply:
+       if (ret == MM_ERROR_NONE) {
+               _method_call_return_value(invocation, g_variant_new("(iiiiii)", pid_r, alloc_handle_r, cmd_handle_r,
+                                                                request_id_r, sound_command_r, sound_state_r));
+       } else {
+               _method_call_return_error(invocation, ret);
+       }
+
+       debug_fleave();
+}
+
+static void handle_method_asm_get_subevent(GDBusMethodInvocation* invocation)
+{
+       int ret = MM_ERROR_NONE;
+       int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0, resource = 0;
+       int pid_r = 0, alloc_handle_r = 0, cmd_handle_r = 0, request_id_r = 0, sound_command_r = 0;
+       GVariant *params = NULL;
+
+       debug_fenter();
+
+       if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
+               debug_error("Parameter for Method is NULL");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto send_reply;
+       }
+
+       g_variant_get(params, "(iiiiii)", &pid, &handle, &sound_event, &request_id, &sound_state, &resource);
+       ret = __mm_sound_mgr_ipc_asm_get_subevent(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource,
+                                                  &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r, &sound_command_r);
+
+send_reply:
+       if (ret == MM_ERROR_NONE) {
+               _method_call_return_value(invocation, g_variant_new("(iiiii)", pid_r, alloc_handle_r, cmd_handle_r,
+                                                                request_id_r, sound_command_r ));
+       } else {
+               _method_call_return_error(invocation, ret);
+       }
+
+       debug_fleave();
+}
+
+static void handle_method_asm_set_session_option(GDBusMethodInvocation* invocation)
+{
+       int ret = MM_ERROR_NONE;
+       int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0, resource = 0;
+       int pid_r = 0, alloc_handle_r = 0, cmd_handle_r = 0, request_id_r = 0, sound_command_r = 0, error_code_r = 0;
+       GVariant *params = NULL;
+
+       debug_fenter();
+
+       if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
+               debug_error("Parameter for Method is NULL");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto send_reply;
+       }
+
+       g_variant_get(params, "(iiiiii)", &pid, &handle, &sound_event, &request_id, &sound_state, &resource);
+       ret = __mm_sound_mgr_ipc_asm_set_session_option(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource,
+                                               &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r, &sound_command_r, &error_code_r);
+
+send_reply:
+       if (ret == MM_ERROR_NONE) {
+               _method_call_return_value(invocation, g_variant_new("(iiiiii)", pid_r, alloc_handle_r, cmd_handle_r,
+                                                             request_id_r, sound_command_r, error_code_r ));
+       } else {
+               _method_call_return_error(invocation, ret);
+       }
+
+       debug_fleave();
+}
+
+static void handle_method_asm_get_session_option(GDBusMethodInvocation* invocation)
+{
+       int ret = MM_ERROR_NONE;
+       int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0, resource = 0;
+       int pid_r = 0, alloc_handle_r = 0, cmd_handle_r = 0, request_id_r = 0, sound_command_r = 0, option_flag_r = 0;
+       GVariant *params = NULL;
+
+       debug_fenter();
+
+       if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
+               debug_error("Parameter for Method is NULL");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto send_reply;
+       }
+
+       g_variant_get(params, "(iiiiii)", &pid, &handle, &sound_event, &request_id, &sound_state, &resource);
+       ret = __mm_sound_mgr_ipc_asm_get_session_option(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource,
+                                            &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r, &sound_command_r, &option_flag_r);
+
+send_reply:
+       if (ret == MM_ERROR_NONE) {
+               _method_call_return_value(invocation, g_variant_new("(iiiiii)", pid_r, alloc_handle_r, cmd_handle_r,
+                                                          request_id_r, sound_command_r, option_flag_r ));
+       } else {
+               _method_call_return_error(invocation, ret);
+       }
+
+       debug_fleave();
+}
+
+static void handle_method_asm_reset_resume_tag(GDBusMethodInvocation* invocation)
+{
+       int ret = MM_ERROR_NONE;
+       int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0, resource = 0;
+       int pid_r = 0, alloc_handle_r = 0, cmd_handle_r = 0, request_id_r = 0, sound_command_r = 0, sound_state_r = 0;
+       GVariant *params = NULL;
+
+       debug_fenter();
+
+       if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
+               debug_error("Parameter for Method is NULL");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto send_reply;
+       }
+
+       g_variant_get(params, "(iiiiii)", &pid, &handle, &sound_event, &request_id, &sound_state, &resource);
+       ret = __mm_sound_mgr_ipc_asm_reset_resume_tag(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource,
+                                         &pid_r, &alloc_handle_r, &cmd_handle_r, &request_id_r, &sound_command_r, &sound_state_r);
+
+send_reply:
+       if (ret == MM_ERROR_NONE) {
+               _method_call_return_value(invocation, g_variant_new("(iiiiii)", pid_r, alloc_handle_r, cmd_handle_r,
+                                                       request_id_r, sound_command_r, sound_state_r ));
+       } else {
+               _method_call_return_error(invocation, ret);
+       }
+
+       debug_fleave();
+}
+
+static void handle_method_asm_dump(GDBusMethodInvocation* invocation)
+{
+
+       int ret = MM_ERROR_NONE;
+       int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0, resource = 0;
+       GVariant *params = NULL;
+
+       debug_fenter();
+
+       if (!(params = g_dbus_method_invocation_get_parameters(invocation))) {
+               debug_error("Parameter for Method is NULL");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto send_reply;
+       }
+
+       g_variant_get(params, "(iiiiii)", &pid, &handle, &sound_event, &request_id, &sound_state, &resource);
+       ret = __mm_sound_mgr_ipc_asm_dump(_get_sender_pid(invocation), handle, sound_event, request_id, sound_state, resource);
+
+send_reply:
+       if (ret == MM_ERROR_NONE) {
+               _method_call_return_value(invocation, g_variant_new("()"));
+       } else {
+               _method_call_return_error(invocation, ret);
+       }
+
+       debug_fleave();
+}
+
+/****************************************************************/
+
+
+static void handle_method_call(GDBusConnection *connection,
+                                                       const gchar *sender,
+                                                       const gchar *object_path,
+                                                       const gchar *interface_name,
+                                                       const gchar *method_name,
+                                                       GVariant *parameters,
+                                                       GDBusMethodInvocation *invocation,
+                                                       gpointer userdata)
+{
+       int method_idx = 0;
+
+       if (!parameters) {
+               debug_error("Parameter Null");
+               return;
+       }
+       debug_log("Method Call, obj : %s, intf : %s, method : %s", object_path, interface_name, method_name);
+
+       for (method_idx = 0; method_idx < METHOD_CALL_MAX; method_idx++) {
+               if (!g_strcmp0(method_name, methods[method_idx].info.name)) {
+                       methods[method_idx].handler(invocation);
+               }
+       }
+}
+
+
+static GVariant* handle_get_property(GDBusConnection *connection,
+                                                                       const gchar *sender,
+                                                                       const gchar *object_path,
+                                                                       const gchar *interface_name,
+                                                                       const gchar *property_name,
+                                                                       GError **error,
+                                                                       gpointer userdata)
+{
+       debug_log("Get Property, obj : %s, intf : %s, prop : %s", object_path, interface_name, property_name);
+       return NULL;
+}
+
+static gboolean handle_set_property(GDBusConnection *connection,
+                                                                       const gchar *sender,
+                                                                       const gchar *object_path,
+                                                                       const gchar *interface_name,
+                                                                       const gchar *property_name,
+                                                                       GVariant *value,
+                                                                       GError **error,
+                                                                       gpointer userdata)
+{
+       debug_log("Set Property, obj : %s, intf : %s, prop : %s", object_path, interface_name, property_name);
+       return TRUE;
+}
+
+static const GDBusInterfaceVTable interface_vtable =
+{
+       handle_method_call,
+       handle_get_property,
+       handle_set_property
+};
+
+static void handle_signal_asm_emergent_exit(GVariant* params, gpointer user_data)
+{
+       int ret = MM_ERROR_NONE;
+       int pid = 0, handle = 0, sound_event = 0, request_id = 0, sound_state = 0;
+
+       debug_fenter();
+
+       if (!params) {
+               debug_error("Invalid Parameters");
+               return;
+       }
+
+       g_variant_get(params, "(iiiii)", &pid, &handle, &sound_event, &request_id, &sound_state);
+       ret = __mm_sound_mgr_ipc_asm_emergent_exit(pid, handle, sound_event, request_id, sound_state);
+
+       if (ret == MM_ERROR_NONE)
+               debug_error("ASM emergent exit, successfully handled");
+       else
+               debug_error("ASM emergent exit, handle failed, ret : 0x%X", ret);
+
+       debug_fleave();
+}
+
+static void handle_signal(GDBusConnection  *connection,
+                                     const gchar      *sender_name,
+                                     const gchar      *object_path,
+                                     const gchar      *interface_name,
+                                     const gchar      *signal_name,
+                                     GVariant         *params,
+                                     gpointer          user_data)
+{
+       if (!object_path || !interface_name || !signal_name) {
+               debug_error("Invalid Parameters");
+               return;
+       }
+
+       debug_log("Got Signal : Object '%s, Interface '%s', Signal '%s'", object_path, interface_name, signal_name);
+
+       if (!g_strcmp0(object_path, OBJECT_ASM)) {
+               if (!g_strcmp0(interface_name, INTERFACE_ASM) && !g_strcmp0(signal_name, "EmergentExit")) {
+                       debug_log("handle signal '%s.%s'", interface_name, signal_name);
+                       handle_signal_asm_emergent_exit(params, user_data);
+               } else {
+                       debug_log("Unknown Signal '%s.%s'", interface_name, signal_name);
+               }
+       } else {
+               debug_log("Unknown Object '%s'", object_path);
+       }
+}
+
+
+static void on_bus_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data)
+{
+       guint reg_id;
+       guint subs_id;
+       debug_log("Bus Acquired (%s)", name);
+
+       conn_g = connection;
+       reg_id = g_dbus_connection_register_object(connection,
+                                         OBJECT_SOUND_SERVER,
+                                         introspection_data->interfaces[0],
+                                         &interface_vtable,
+                                         NULL,
+                                         NULL,
+                                         NULL);
+       if (!reg_id) {
+               debug_error("Register object(%s) failed", OBJECT_SOUND_SERVER);
+               return ;
+       }
+
+       subs_id = g_dbus_connection_signal_subscribe(connection, NULL, INTERFACE_ASM, "EmergentExit", OBJECT_ASM, \
+                        NULL, G_DBUS_SIGNAL_FLAGS_NONE, handle_signal, NULL, NULL );
+
+       if (!subs_id) {
+               debug_error ("g_dbus_connection_signal_subscribe() failed ");
+               return;
+       }
+}
+
+static void on_name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data)
+{
+       debug_log("Name Acquired (%s)", name);
+}
+
+static void on_name_lost(GDBusConnection *connection, const gchar *name, gpointer user_data)
+{
+       debug_log("Name Lost (%s)", name);
+}
+
+static int _mm_sound_mgr_dbus_own_name(GBusType bus_type, const char* wellknown_name, guint* owner_id)
+{
+       guint oid;
+
+       debug_log("Own name (%s) for sound-server", wellknown_name);
+
+       oid = g_bus_own_name(bus_type, wellknown_name , G_BUS_NAME_OWNER_FLAGS_NONE,
+                       on_bus_acquired, on_name_acquired, on_name_lost, NULL, NULL);
+       if (oid <= 0) {
+               debug_error("Dbus own name failed");
+               return MM_ERROR_SOUND_INTERNAL;
+       } else {
+               *owner_id = oid;
+       }
+
+       return MM_ERROR_NONE;
+}
+
+static void _mm_sound_mgr_dbus_unown_name(guint oid)
+{
+       debug_log("Unown name for Sound-Server");
+       if (oid > 0) {
+               g_bus_unown_name(oid);
+       }
+}
+
+/* not for mm-sound client */
+int mm_sound_mgr_ipc_dbus_send_signal_freeze (char* command, int pid)
+{
+       GError *err = NULL;
+       GDBusConnection *conn = NULL;
+       gboolean ret;
+
+       if (command == NULL || pid <= 0) {
+               debug_error ("invalid arguments [%s][%d]", command, pid);
+               return -1;
+       }
+
+       conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+       if (!conn && err) {
+               debug_error ("g_bus_get_sync() error (%s) ", err->message);
+               g_error_free (err);
+               return -1;
+       }
+
+       ret = g_dbus_connection_emit_signal (conn,
+                               NULL, PROC_DBUS_OBJECT, PROC_DBUS_INTERFACE, PROC_DBUS_METHOD,
+                               g_variant_new ("(si)", command, pid),
+                               &err);
+       if (!ret && err) {
+               debug_error ("g_dbus_connection_emit_signal() error (%s) ", err->message);
+               goto error;
+       }
+
+       ret = g_dbus_connection_flush_sync(conn, NULL, &err);
+       if (!ret && err) {
+               debug_error ("g_dbus_connection_flush_sync() error (%s) ", err->message);
+               goto error;
+       }
+
+       g_object_unref(conn);
+       debug_msg ("sending [%s] for pid (%d) success", command, pid);
+
+       return 0;
+
+error:
+       g_error_free (err);
+       g_object_unref(conn);
+       return -1;
+}
+
+int __mm_sound_mgr_ipc_dbus_notify_device_connected (mm_sound_device_t *device, gboolean is_connected)
+{
+       int ret = MM_ERROR_NONE;
+       GVariantBuilder builder;
+       GVariant* param = NULL;
+
+       debug_log("Send Signal '%s'", signals[SIGNAL_DEVICE_CONNECTED]);
+
+       g_variant_builder_init(&builder, G_VARIANT_TYPE("((iiiis)b)"));
+       g_variant_builder_open(&builder, G_VARIANT_TYPE_TUPLE);
+       g_variant_builder_add(&builder, "(iiiis)", device->id, device->type, device->io_direction, device->state, device->name);
+       g_variant_builder_close(&builder);
+       g_variant_builder_add(&builder, "b", is_connected);
+       param = g_variant_builder_end(&builder);
+       if (param) {
+               if ((ret = mm_sound_mgr_ipc_dbus_send_signal(SIGNAL_DEVICE_CONNECTED, param))!= MM_ERROR_NONE) {
+                       debug_error("Send device connected signal failed");
+               }
+       } else {
+               debug_error("Build variant for dbus param failed");
+       }
+
+       return ret;
+}
+
+int __mm_sound_mgr_ipc_dbus_notify_device_info_changed (mm_sound_device_t *device, int changed_device_info_type)
+{
+       int ret = MM_ERROR_NONE;
+       GVariantBuilder builder;
+       GVariant* param = NULL;
+
+       debug_log("Send Signal '%s'", signals[SIGNAL_DEVICE_INFO_CHANGED]);
+
+       g_variant_builder_init(&builder, G_VARIANT_TYPE("((iiiis)i)"));
+       g_variant_builder_open(&builder, G_VARIANT_TYPE_TUPLE);
+       g_variant_builder_add(&builder, "(iiiis)", device->id, device->type, device->io_direction, device->state, device->name);
+       g_variant_builder_close(&builder);
+       g_variant_builder_add(&builder, "i", changed_device_info_type);
+       param = g_variant_builder_end(&builder);
+       if (param) {
+               if ((ret = mm_sound_mgr_ipc_dbus_send_signal(SIGNAL_DEVICE_INFO_CHANGED, param)) != MM_ERROR_NONE) {
+                       debug_error("Send device info changed signal failed");
+               }
+       } else {
+               debug_error("Build variant for dbus param failed");
+       }
+
+       return ret;
+}
+
+int __mm_sound_mgr_ipc_dbus_notify_volume_changed(unsigned int vol_type, unsigned int value)
+{
+       int ret = MM_ERROR_NONE;
+       GVariant* param = NULL;
+
+       debug_log("Send Signal '%s'", signals[SIGNAL_VOLUME_CHANGED]);
+
+       param = g_variant_new("(uu)", vol_type, value);
+       if (param) {
+               if ((ret = mm_sound_mgr_ipc_dbus_send_signal(SIGNAL_VOLUME_CHANGED, param)) != MM_ERROR_NONE) {
+                       debug_error("Send device connected signal failed");
+               }
+       } else {
+               debug_error("Build variant for dbus param failed");
+       }
+
+       return ret;
+}
+
+int __mm_sound_mgr_ipc_dbus_notify_play_file_end(int handle)
+{
+       int ret = MM_ERROR_NONE;
+       GVariant* param = NULL;
+
+       debug_log("Send Signal '%s'", signals[SIGNAL_PLAY_FILE_END]);
+
+       param = g_variant_new("(i)", handle);
+       if (param) {
+               if ((ret = mm_sound_mgr_ipc_dbus_send_signal(SIGNAL_PLAY_FILE_END, param)) != MM_ERROR_NONE) {
+                       debug_error("Send play file end for '%d' failed", handle);
+               }
+       } else {
+               debug_error("Build variant for dbus param failed");
+       }
+
+       return ret;
+}
+
+int __mm_sound_mgr_ipc_dbus_notify_active_device_changed(int device_in, int device_out)
+{
+       return MM_ERROR_SOUND_INTERNAL;
+}
+
+int __mm_sound_mgr_ipc_dbus_notify_available_device_changed(int device_in, int device_out, int available)
+{
+       return MM_ERROR_SOUND_INTERNAL;
+}
+
+#define PA_BUS_NAME                                    "org.pulseaudio.Server"
+#define PA_STREAM_MANAGER_OBJECT_PATH                  "/org/pulseaudio/Ext/StreamManager"
+#define PA_STREAM_MANAGER_INTERFACE                    "org.pulseaudio.Ext.StreamManager"
+#define PA_STREAM_MANAGER_METHOD_NAME_GET_STREAM_LIST  "GetStreamList"
+int __mm_sound_mgr_ipc_dbus_get_stream_list(stream_list_t* stream_list)
+{
+       int ret = MM_ERROR_NONE;
+       GVariant *result = NULL;
+       GVariant *child = NULL;
+       GDBusConnection *conn = NULL;
+       GError *err = NULL;
+       int i = 0;
+
+       g_type_init();
+
+       conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+       if (!conn && err) {
+               LOGE("g_bus_get_sync() error (%s)", err->message);
+               g_error_free (err);
+               ret = MM_ERROR_SOUND_INTERNAL;
+               return ret;
+       }
+       result = g_dbus_connection_call_sync (conn,
+                                                       PA_BUS_NAME,
+                                                       PA_STREAM_MANAGER_OBJECT_PATH,
+                                                       PA_STREAM_MANAGER_INTERFACE,
+                                                       PA_STREAM_MANAGER_METHOD_NAME_GET_STREAM_LIST,
+                                                       NULL,
+                                                       G_VARIANT_TYPE("(vv)"),
+                                                       G_DBUS_CALL_FLAGS_NONE,
+                                                       2000,
+                                                       NULL,
+                                                       &err);
+       if (!result && err) {
+               debug_error("g_dbus_connection_call_sync() error (%s)", err->message);
+               ret = MM_ERROR_SOUND_INTERNAL;
+       } else {
+               GVariantIter iter;
+               GVariant *item = NULL;
+               child = g_variant_get_child_value(result, 0);
+               item = g_variant_get_variant(child);
+               gchar *name;
+               i = 0;
+               g_variant_iter_init(&iter, item);
+               while ((i < AVAIL_STREAMS_MAX) && g_variant_iter_loop(&iter, "&s", &name)) {
+                       debug_log ("name : %s", name);
+                       stream_list->stream_types[i++] = strdup(name);
+               }
+               g_variant_iter_free (&iter);
+               g_variant_unref (item);
+               g_variant_unref (child);
+
+               child = g_variant_get_child_value(result, 1);
+               item = g_variant_get_variant(child);
+               gint32 priority;
+               i = 0;
+               g_variant_iter_init(&iter, item);
+               while ((i < AVAIL_STREAMS_MAX) && g_variant_iter_loop(&iter, "i", &priority)) {
+                       debug_log ("priority : %d", priority);
+                       stream_list->priorities[i++] = priority;
+               }
+               g_variant_iter_free (&iter);
+               g_variant_unref (item);
+               g_variant_unref (child);
+
+               g_variant_unref(result);
+       }
+       g_object_unref(conn);
+
+       return ret;
+}
+
+int MMSoundMgrDbusInit(void)
+{
+       debug_enter();
+
+       introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
+       if (!introspection_data)
+               return MM_ERROR_SOUND_INTERNAL;
+
+       if (_mm_sound_mgr_dbus_own_name(G_BUS_TYPE_SYSTEM, BUS_NAME_SOUND_SERVER, &sound_server_owner_id) != MM_ERROR_NONE) {
+               debug_error ("dbus own name for sound-server error\n");
+               return MM_ERROR_SOUND_INTERNAL;
+       }
+
+       debug_leave();
+
+       return MM_ERROR_NONE;
+}
+
+void MMSoundMgrDbusFini(void)
+{
+       debug_enter("\n");
+
+       _mm_sound_mgr_dbus_unown_name(sound_server_owner_id);
+       g_dbus_node_info_unref (introspection_data);
+
+       debug_leave("\n");
+}
+
+
+
index 850e88e..c79828a 100644 (file)
@@ -19,6 +19,7 @@
  *
  */
 
+#if 0
 #include <stdlib.h>
 #include <string.h>
 
 #include <pulse/ext-policy.h>
 #include <pulse/ext-echo-cancel.h>
 
-#define SUPPORT_MONO_AUDIO
-#define SUPPORT_AUDIO_BALANCE
 #ifdef SUPPORT_BT_SCO
 #define SUPPORT_BT_SCO_DETECT
 #endif
-#define SUPPORT_AUDIO_MUTEALL
 
 #include "include/mm_sound_mgr_pulse.h"
 #include "include/mm_sound_mgr_session.h"
@@ -122,6 +120,9 @@ typedef struct _pulse_info
 #endif
        pthread_t thread;
        GAsyncQueue *queue;
+
+       pa_disconnect_cb disconnect_cb;
+       void* user_data;
 }pulse_info_t;
 
 typedef enum {
@@ -368,9 +369,13 @@ static void context_subscribe_cb (pa_context * c, pa_subscription_event_type_t t
        }
 }
 
+#define PA_READY_CHECK_MAX_RETRY 20
+#define PA_READY_CHECK_INTERVAL_US 200000
+
 static void context_state_cb (pa_context *c, void *userdata)
 {
        pulse_info_t *pinfo = (pulse_info_t *)userdata;
+       int left_retry = PA_READY_CHECK_MAX_RETRY;
 
        if (pinfo == NULL) {
                debug_error ("pinfo is null");
@@ -385,19 +390,19 @@ static void context_state_cb (pa_context *c, void *userdata)
                        break;
                case PA_CONTEXT_FAILED:
                        {
-                           // wait for pa_ready file creation.
-                           int fd = -1;
-
-                           do {
-                               fd = open(PA_READY, O_RDONLY);
-                                       if(fd < 0) {
-                                   usleep(20000);
-                                       }
-                           } while(fd < 0);
-                           close(fd);
-
-                           debug_error("pulseaudio crash!! sound_server will be restart!!");
-                           kill(getpid(), SIGKILL);
+                               // wait for pa_ready file creation.
+                               debug_error("pulseaudio disconnected!! wait for pa_ready file creation");
+
+                               do {
+                                       if (access(PA_READY, F_OK) == 0)
+                                               break;
+                                       usleep(PA_READY_CHECK_INTERVAL_US);
+                                       debug_error ("waiting....[%d]", left_retry);
+                               } while(left_retry--);
+
+                               debug_error("call disconnect handler [%p] to quit sound-server", pinfo->disconnect_cb);
+                               if (pinfo->disconnect_cb)
+                                       pinfo->disconnect_cb(pinfo->user_data);
                        }
                        break;
                case PA_CONTEXT_TERMINATED:
@@ -416,6 +421,7 @@ void *pulse_client_thread_run (void *args)
        pa_operation *o = NULL;
        pa_client_command_t cmd = PA_CLIENT_NOT_USED;
 
+#if 0
        while(1)
        {
                cmd = (pa_client_command_t)g_async_queue_pop(pinfo->queue);
@@ -506,6 +512,7 @@ unlock_and_fail:
 
 destroy:
        pa_threaded_mainloop_unlock(pinfo->m);
+#endif
 
        return 0;
 }
@@ -672,292 +679,6 @@ static void unload_hdmi_cb(pa_context *c, int success, void *userdata)
        pa_threaded_mainloop_signal(pinfo->m, 0);
 }
 
-/* -------------------------------- MONO AUDIO --------------------------------------------*/
-#ifdef SUPPORT_MONO_AUDIO
-#define TOUCH_SOUND_PLAY_COMLETE_TIME 50000
-
-static void set_mono_cb (pa_context *c, int success, void *userdata)
-{
-       pulse_info_t *pinfo = (pulse_info_t *)userdata;
-       if (pinfo == NULL) {
-               debug_error ("pinfo is null");
-               return;
-       }
-
-       if (success) {
-               debug_msg ("[PA_CB] m[%p] c[%p] set mono success", pinfo->m, c);
-       } else {
-               debug_error("[PA_CB] m[%p] c[%p] set mono fail:%s", pinfo->m, c, pa_strerror(pa_context_errno(c)));
-       }
-       pa_threaded_mainloop_signal(pinfo->m, 0);
-}
-
-static void mono_changed_cb(keynode_t* node, void* data)
-{
-       int key_value;
-       pa_operation *o = NULL;
-       pulse_info_t* pinfo = (pulse_info_t*)data;
-
-       if (pinfo == NULL) {
-               debug_error ("pinfo is null");
-               return;
-       }
-
-       vconf_get_bool(VCONF_KEY_MONO_AUDIO, &key_value);
-       debug_msg ("%s changed callback called, key value = %d\n",vconf_keynode_get_name(node), key_value);
-       /*for make sure touch sound play complete*/
-       usleep(TOUCH_SOUND_PLAY_COMLETE_TIME);
-
-       pa_threaded_mainloop_lock(pinfo->m);
-       CHECK_CONTEXT_DEAD_GOTO(pinfo->context, unlock_and_fail);
-
-       debug_msg("[PA] pa_ext_policy_set_mono m[%p] c[%p] mono:%d", pinfo->m, pinfo->context, key_value);
-       o = pa_ext_policy_set_mono (pinfo->context, key_value, set_mono_cb, pinfo);
-       CHECK_CONTEXT_SUCCESS_GOTO(pinfo->context, o, unlock_and_fail);
-       while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) {
-               pa_threaded_mainloop_wait(pinfo->m);
-               CHECK_CONTEXT_DEAD_GOTO(pinfo->context, unlock_and_fail);
-       }
-       pa_operation_unref(o);
-
-       pa_threaded_mainloop_unlock(pinfo->m);
-       return;
-
-unlock_and_fail:
-       if (o) {
-               pa_operation_cancel(o);
-               pa_operation_unref(o);
-       }
-       pa_threaded_mainloop_unlock(pinfo->m);
-}
-
-int MMSoundMgrPulseHandleRegisterMonoAudio (void* pinfo)
-{
-       int ret = vconf_notify_key_changed(VCONF_KEY_MONO_AUDIO, mono_changed_cb, pinfo);
-       debug_msg ("vconf [%s] set ret = %d\n", VCONF_KEY_MONO_AUDIO, ret);
-       return ret;
-}
-#endif /* SUPPORT_MONO_AUDIO */
-
-/* -------------------------------- Audio Balance --------------------------------------------*/
-#ifdef SUPPORT_AUDIO_BALANCE
-static void set_balance_cb (pa_context *c, int success, void *userdata)
-{
-       pulse_info_t *pinfo = (pulse_info_t *)userdata;
-       if (pinfo == NULL) {
-               debug_error ("pinfo is null");
-               return;
-       }
-
-       if (success) {
-               debug_msg ("[PA_CB] m[%p] c[%p] set balance success", pinfo->m, c);
-       } else {
-               debug_error("[PA_CB] m[%p] c[%p] set balance fail:%s", pinfo->m, c, pa_strerror(pa_context_errno(c)));
-       }
-       pa_threaded_mainloop_signal(pinfo->m, 0);
-}
-
-static void _balance_changed_cb(keynode_t* node, void* data)
-{
-       double balance_value;
-       pulse_info_t* pinfo = (pulse_info_t*)data;
-       pa_operation *o = NULL;
-
-       if (pinfo == NULL) {
-               debug_error ("pinfo is null");
-               return;
-       }
-
-       vconf_get_dbl(VCONF_KEY_VOLUME_BALANCE, &balance_value);
-       debug_msg ("%s changed callback called, balance value = %f\n",vconf_keynode_get_name(node), balance_value);
-
-       pa_threaded_mainloop_lock(pinfo->m);
-       CHECK_CONTEXT_DEAD_GOTO(pinfo->context, unlock_and_fail);
-
-       debug_msg("[PA] pa_ext_policy_set_balance m[%p] c[%p] balance:%.2f", pinfo->m, pinfo->context, balance_value);
-       o = pa_ext_policy_set_balance (pinfo->context, &balance_value, set_balance_cb, pinfo);
-       CHECK_CONTEXT_SUCCESS_GOTO(pinfo->context, o, unlock_and_fail);
-       while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) {
-               pa_threaded_mainloop_wait(pinfo->m);
-               CHECK_CONTEXT_DEAD_GOTO(pinfo->context, unlock_and_fail);
-       }
-       pa_operation_unref(o);
-
-       pa_threaded_mainloop_unlock(pinfo->m);
-       return;
-
-unlock_and_fail:
-       if (o) {
-               pa_operation_cancel(o);
-               pa_operation_unref(o);
-       }
-       pa_threaded_mainloop_unlock(pinfo->m);
-}
-
-int MMSoundMgrPulseHandleRegisterAudioBalance (void* pinfo)
-{
-       int ret = vconf_notify_key_changed(VCONF_KEY_VOLUME_BALANCE, _balance_changed_cb, pinfo);
-       debug_msg ("vconf [%s] set ret = %d\n", VCONF_KEY_VOLUME_BALANCE, ret);
-       return ret;
-}
-
-void MMSoundMgrPulseHandleResetAudioBalanceOnBoot(void* data)
-{
-       double balance_value;
-       pulse_info_t* pinfo = (pulse_info_t*)data;
-       pa_operation *o = NULL;
-
-       if (pinfo == NULL) {
-               debug_error ("pinfo is null");
-               return;
-       }
-
-       if (vconf_get_dbl(VCONF_KEY_VOLUME_BALANCE, &balance_value)) {
-               debug_error ("vconf_get_dbl(VCONF_KEY_VOLUME_BALANCE) failed..\n");
-               balance_value = 0;
-               vconf_set_dbl(VCONF_KEY_VOLUME_BALANCE, balance_value);
-       } else {
-               pa_threaded_mainloop_lock(pinfo->m);
-               CHECK_CONTEXT_DEAD_GOTO(pinfo->context, unlock_and_fail);
-
-               debug_msg("[PA] pa_ext_policy_set_balance m[%p] c[%p] balance:%.2f", pinfo->m, pinfo->context, balance_value);
-               o = pa_ext_policy_set_balance (pinfo->context, &balance_value, set_balance_cb, pinfo);
-               CHECK_CONTEXT_SUCCESS_GOTO(pinfo->context, o, unlock_and_fail);
-               while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) {
-                       pa_threaded_mainloop_wait(pinfo->m);
-                       CHECK_CONTEXT_DEAD_GOTO(pinfo->context, unlock_and_fail);
-               }
-               pa_operation_unref(o);
-
-               pa_threaded_mainloop_unlock(pinfo->m);
-       }
-       return;
-
-unlock_and_fail:
-       if (o) {
-               pa_operation_cancel(o);
-               pa_operation_unref(o);
-       }
-       pa_threaded_mainloop_unlock(pinfo->m);
-}
-#endif /* SUPPORT_AUDIO_BALANCE */
-
-
-#ifdef SUPPORT_AUDIO_MUTEALL
-static void set_muteall_cb (pa_context *c, int success, void *userdata)
-{
-       pulse_info_t *pinfo = (pulse_info_t *)userdata;
-       if (pinfo == NULL) {
-               debug_error ("pinfo is null");
-               return;
-       }
-
-       if (success) {
-               debug_msg ("[PA_CB] m[%p] c[%p] set muteall success", pinfo->m, c);
-       } else {
-               debug_error("[PA_CB] m[%p] c[%p] set muteall fail:%s", pinfo->m, c, pa_strerror(pa_context_errno(c)));
-       }
-       pa_threaded_mainloop_signal(pinfo->m, 0);
-}
-
-static void _muteall_changed_cb(keynode_t* node, void* data)
-{
-       int key_value;
-       int i;
-       pulse_info_t* pinfo = (pulse_info_t*)data;
-       pa_operation *o = NULL;
-
-       if (pinfo == NULL) {
-               debug_error ("pinfo is null\n");
-               return;
-       }
-
-       vconf_get_int(VCONF_KEY_MUTE_ALL, &key_value);
-       debug_msg ("%s changed callback called, muteall value = %d\n", vconf_keynode_get_name(node), key_value);
-
-       mm_sound_mute_all(key_value);
-
-       pa_threaded_mainloop_lock(pinfo->m);
-       CHECK_CONTEXT_DEAD_GOTO(pinfo->context, unlock_and_fail);
-
-       debug_msg("[PA] pa_ext_policy_set_muteall m[%p] c[%p] muteall:%d", pinfo->m, pinfo->context, key_value);
-       o = pa_ext_policy_set_muteall (pinfo->context, key_value, set_muteall_cb, pinfo);
-       CHECK_CONTEXT_SUCCESS_GOTO(pinfo->context, o, unlock_and_fail);
-       while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) {
-               pa_threaded_mainloop_wait(pinfo->m);
-               CHECK_CONTEXT_DEAD_GOTO(pinfo->context, unlock_and_fail);
-       }
-       pa_operation_unref(o);
-
-       pa_threaded_mainloop_unlock(pinfo->m);
-
-       if (!key_value) {
-               for (i =0;i<VOLUME_TYPE_MAX;i++) {
-                       unsigned int vconf_value;
-                       mm_sound_volume_get_value(i,&vconf_value);
-                       mm_sound_volume_set_value(i,vconf_value);
-               }
-       }
-       return;
-
-unlock_and_fail:
-       if (o) {
-               pa_operation_cancel(o);
-               pa_operation_unref(o);
-       }
-       pa_threaded_mainloop_unlock(pinfo->m);
-}
-
-int MMSoundMgrPulseHandleRegisterAudioMuteall (void* pinfo)
-{
-       int ret = vconf_notify_key_changed(VCONF_KEY_MUTE_ALL, _muteall_changed_cb, pinfo);
-       debug_msg ("vconf [%s] set ret = %d\n", VCONF_KEY_MUTE_ALL, ret);
-       return ret;
-}
-
-void MMSoundMgrPulseHandleResetAudioMuteallOnBoot(void* data)
-{
-       int key_value;
-       pulse_info_t* pinfo = (pulse_info_t*)data;
-       pa_operation *o = NULL;
-
-       if (pinfo == NULL) {
-               debug_error ("pinfo is null\n");
-               return;
-       }
-
-       if (vconf_get_int(VCONF_KEY_MUTE_ALL, &key_value)) {
-               debug_error ("vconf_get_int(VCONF_KEY_MUTE_ALL) failed..\n");
-               key_value = 0;
-               vconf_set_int(VCONF_KEY_MUTE_ALL, key_value);
-       } else {
-               mm_sound_mute_all(key_value);
-
-               pa_threaded_mainloop_lock(pinfo->m);
-               CHECK_CONTEXT_DEAD_GOTO(pinfo->context, unlock_and_fail);
-
-               debug_msg("[PA] pa_ext_policy_set_muteall m[%p] c[%p] muteall:%d", pinfo->m, pinfo->context, key_value);
-               o = pa_ext_policy_set_muteall (pinfo->context, key_value, set_muteall_cb, pinfo);
-               CHECK_CONTEXT_SUCCESS_GOTO(pinfo->context, o, unlock_and_fail);
-               while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) {
-                       pa_threaded_mainloop_wait(pinfo->m);
-                       CHECK_CONTEXT_DEAD_GOTO(pinfo->context, unlock_and_fail);
-               }
-               pa_operation_unref(o);
-
-               pa_threaded_mainloop_unlock(pinfo->m);
-       }
-       return;
-
-unlock_and_fail:
-       if (o) {
-               pa_operation_cancel(o);
-               pa_operation_unref(o);
-       }
-       pa_threaded_mainloop_unlock(pinfo->m);
-}
-#endif /* SUPPORT_AUDIO_MUTEALL */
-
 /* -------------------------------- BT SCO --------------------------------------------*/
 #ifdef SUPPORT_BT_SCO_DETECT
 
@@ -1046,6 +767,7 @@ static void __bt_audio_connection_state_changed_cb(int result,
                2 : BT_AUDIO_PROFILE_TYPE_A2DP
                3 : BT_AUDIO_PROFILE_TYPE_AG    */
 
+#if 0
        const static char * type_str[4] = { "ALL", "HSP/HFP", "A2DP", "AG" };
        int length = sizeof(type_str) / sizeof(char*);
        pulse_info_t* pinfo = (pulse_info_t*)user_data;
@@ -1083,6 +805,7 @@ static void __bt_audio_connection_state_changed_cb(int result,
                debug_msg("connection state changed end\n");
        } else
                debug_msg("bt ag-sco is not ready. ag_init(%d)\n", pinfo->ag_init);
+#endif
 
 }
 
@@ -1094,9 +817,16 @@ static void __bt_ag_sco_state_changed_cb(int result, bool opened, void *user_dat
        debug_msg("bt ag-sco state changed. opend(%d), ag_init(%d)\n", opened, pinfo->ag_init);
 
        if(pinfo->ag_init == true) {
+               if (opened) {
+                       MMSoundMgrDeviceUpdateStatus (DEVICE_UPDATE_STATUS_CHANGED_INFO_IO_DIRECTION, DEVICE_TYPE_BLUETOOTH, DEVICE_IO_DIRECTION_BOTH, DEVICE_ID_AUTO, NULL, DEVICE_STATE_DEACTIVATED, NULL);
+               } else {
+                       MMSoundMgrDeviceUpdateStatus (DEVICE_UPDATE_STATUS_CHANGED_INFO_IO_DIRECTION, DEVICE_TYPE_BLUETOOTH, DEVICE_IO_DIRECTION_OUT, DEVICE_ID_AUTO, NULL, DEVICE_STATE_DEACTIVATED, NULL);
+               }
                MMSoundMgrSessionGetSession(&session);
-               if (session == SESSION_VOICECALL) {
-                       debug_warning("SESSION(SESSION_VOICECALL), we don't handle sco stat in call session. sound-path should be routed in active device function by call app\n");
+               if (session == SESSION_VOICECALL ||
+                       session == SESSION_VIDEOCALL ||
+                       session == SESSION_VOIP) {
+                       debug_warning("SESSION(%d), we don't handle sco stat in call session. sound-path should be routed in active device function by call app\n", session);
                        return;
                }
 
@@ -1209,12 +939,14 @@ void _speaker_volume_changed_cb()
                debug_warning("Fail to get volume value %x", ret);
                return;
        }
-
+#if 0
+       /* TODO : need to clarify BT volume requirement */
+       /* mm_sound_volume_get_step is deprecated now.(rather use dbus interface in pulseaudio directly, see sound-manager) */
        if(MM_ERROR_NONE != mm_sound_volume_get_step(voltype, &max_vol)) {
                debug_warning("get volume max failed. voltype(%d)\n", voltype);
                return;
        }
-
+#endif
        native_vol = vconf_value;
 
        /* limitation : should be matched between client volume 9 to native volume and
@@ -1283,9 +1015,14 @@ static int _bt_hf_set_volume_by_client(const unsigned int vol)
                        voltype = VOLUME_TYPE_VOIP;
        }
 
+#if 0
+       /* TODO : need to clarify BT volume requirement */
+       /* mm_sound_volume_get_step is deprecated now.(rather use dbus interface in pulseaudio directly, see sound-manager) */
        if(MM_ERROR_NONE != mm_sound_volume_get_step(voltype, &max_vol)) {
                debug_warning("get volume max failed. voltype(%d)\n", voltype);
+               return;
        }
+#endif
 
        /* limitation : should be matched between client volume 9 to native volume 3 and
        native volume 3 to client volume 9 for BLUETOOTH certification.*/
@@ -1632,34 +1369,22 @@ int MMSoundMgrPulseGetBluetoothInfo(bool* is_nrec, int* bandwidth)
 #endif /* SUPPORT_BT_SCO_DETECT */
 
 /* -------------------------------- MGR MAIN --------------------------------------------*/
-
-int MMSoundMgrPulseHandleIsBtA2DPOnReq (mm_ipc_msg_t *msg, int (*sendfunc)(mm_ipc_msg_t*))
+int MMSoundMgrPulseHandleIsBtA2DPOnReq (bool* is_bt_on, char** bt_name)
 {
        int ret = 0;
-       mm_ipc_msg_t respmsg = {0,};
-       char* bt_name;
-       bool is_bt_on = false;
-       pthread_mutex_lock(&g_mutex);
-
-       debug_enter("msg = %p, sendfunc = %p\n", msg, sendfunc);
+       char* _bt_name;
+       bool _is_bt_on = false;
 
-       bt_name = MMSoundMgrSessionGetBtA2DPName();
-       if (bt_name && strlen(bt_name) > 0) {
-               is_bt_on = true;
+       pthread_mutex_lock(&g_mutex);
+       _bt_name = MMSoundMgrSessionGetBtA2DPName();
+       if (_bt_name && strlen(_bt_name) > 0) {
+               _is_bt_on = true;
        }
 
-       debug_log ("is_bt_on = [%d], name = [%s]\n", is_bt_on, bt_name);
-
-       SOUND_MSG_SET(respmsg.sound_msg,
-                               MM_SOUND_MSG_RES_IS_BT_A2DP_ON, msg->sound_msg.handle, is_bt_on, msg->sound_msg.msgid);
-       MMSOUND_STRNCPY(respmsg.sound_msg.filename, bt_name, FILE_PATH);
+       debug_log ("is_bt_on = [%d], name = [%s]\n", _is_bt_on, _bt_name);
 
-       /* Send Response */
-       ret = sendfunc (&respmsg);
-       if (ret != MM_ERROR_NONE) {
-               /* TODO : Error Handling */
-               debug_error ("sendfunc failed....ret = [%x]\n", ret);
-       }
+       *is_bt_on = _is_bt_on;
+       *bt_name = strdup(_bt_name);
 
        pthread_mutex_unlock(&g_mutex);
 
@@ -1925,40 +1650,6 @@ unlock_and_fail:
        debug_leave("\n");
 }
 
-void MMSoundMgrPulseSetMuteall(int mute)
-{
-       pa_operation *o = NULL;
-
-       debug_msg("all streams are %s. pulse_info(0x%x)", mute ? "muted" : "unmuted", pulse_info);
-
-       if (pa_threaded_mainloop_in_thread(pulse_info->m)) {
-        o = pa_ext_policy_set_muteall (pulse_info->context, mute, set_muteall_cb, pulse_info);
-               pa_operation_unref(o);
-       } else {
-               pa_threaded_mainloop_lock(pulse_info->m);
-               CHECK_CONTEXT_DEAD_GOTO(pulse_info->context, muteall_and_fail);
-        o = pa_ext_policy_set_muteall (pulse_info->context, mute, set_muteall_cb, pulse_info);
-               CHECK_CONTEXT_SUCCESS_GOTO(pulse_info->context, o, muteall_and_fail);
-               while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) {
-                       pa_threaded_mainloop_wait(pulse_info->m);
-                       CHECK_CONTEXT_DEAD_GOTO(pulse_info->context, muteall_and_fail);
-               }
-               pa_operation_unref(o);
-
-               pa_threaded_mainloop_unlock(pulse_info->m);
-       }
-       debug_leave("\n");
-       return;
-
-muteall_and_fail:
-       if (o) {
-               pa_operation_cancel(o);
-               pa_operation_unref(o);
-       }
-       pa_threaded_mainloop_unlock(pulse_info->m);
-       debug_leave("\n");
-}
-
 void MMSoundMgrPulseSetVoicecontrolState (bool state)
 {
        pa_operation *o = NULL;
@@ -1995,28 +1686,34 @@ unlock_and_fail:
        debug_leave("\n");
 }
 
-static void _poweroff_changed_cb(keynode_t* node, void* data)
+static void _recorder_changed_cb(keynode_t* node, void* data)
 {
        int key_value;
        pulse_info_t* pinfo = (pulse_info_t*)data;
+       session_t session = 0;
 
        if (pinfo == NULL) {
                debug_error ("pinfo is null\n");
                return;
        }
 
-       vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &key_value);
-       debug_msg ("%s changed callback called, poweroff value = %d\n", vconf_keynode_get_name(node), key_value);
+       vconf_get_int(VCONFKEY_RECORDER_STATE, &key_value);
+       debug_msg ("%s changed callback called, recorder state value = %d\n", vconf_keynode_get_name(node), key_value);
+
+       MMSoundMgrSessionGetSession(&session);
 
-       if (key_value >= VCONFKEY_SYSMAN_POWER_OFF_DIRECT) {
-               MMSoundMgrPulseSetMuteall(1);
+       if ((key_value == VCONFKEY_RECORDER_STATE_RECORDING || key_value == VCONFKEY_RECORDER_STATE_RECORDING_PAUSE) && session == SESSION_FMRADIO) {
+               vconf_set_int(VCONF_KEY_FMRADIO_RECORDING, 1);
+       } else {
+               vconf_set_int(VCONF_KEY_FMRADIO_RECORDING, 0);
        }
 }
 
-int MMSoundMgrPulseHandleRegisterPowerOffMuteall(void* pinfo)
+int MMSoundMgrPulseHandleRegisterFMRadioRecording(void* pinfo)
 {
-       int ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, _poweroff_changed_cb, pinfo);
-       debug_msg ("vconf [%s] set ret = %d\n", VCONFKEY_SYSMAN_POWER_OFF_STATUS, ret);
+       int ret = vconf_notify_key_changed(VCONFKEY_RECORDER_STATE, _recorder_changed_cb, pinfo);
+       debug_msg ("vconf [%s] set ret = %d\n", VCONFKEY_RECORDER_STATE, ret);
+
        return ret;
 }
 
@@ -2324,14 +2021,6 @@ static void set_active_device_cb(pa_context *c, int success, int need_update, vo
        }
 
        pa_threaded_mainloop_signal(pinfo->m, 0);
-
-       if (need_update) {
-               debug_msg("[PA] pa_ext_policy_set_active_device need to update volume.");
-               if(MM_ERROR_NONE != _mm_sound_mgr_device_update_volume()) {
-                       debug_error ("_mm_sound_mgr_device_update_volume failed.");
-               }
-       }
-
 }
 
 static void set_active_device_nosignal_cb(pa_context *c, int success, int need_update, void *userdata)
@@ -2347,13 +2036,6 @@ static void set_active_device_nosignal_cb(pa_context *c, int success, int need_u
        } else {
                debug_error("[PA_CB] c[%p] set active device fail:%s", c, pa_strerror(pa_context_errno(c)));
        }
-
-       if (need_update) {
-               debug_msg("[PA] pa_ext_policy_set_active_device need to update volume.");
-               if(MM_ERROR_NONE != _mm_sound_mgr_device_update_volume()) {
-                       debug_error ("_mm_sound_mgr_device_update_volume failed.");
-               }
-       }
 }
 
 void MMSoundMgrPulseGetPathInfo(mm_sound_device_out *device_out, mm_sound_device_in *device_in)
@@ -2531,107 +2213,7 @@ static void set_update_volume_nosignal_cb(pa_context *c, int success, void *user
        }
 }
 
-void MMSoundMgrPulseUpdateVolume(void)
-{
-       pa_operation *o = NULL;
-
-       if (pa_threaded_mainloop_in_thread(pulse_info->m)) {
-               o = pa_ext_policy_update_volume(pulse_info->context, set_update_volume_nosignal_cb, pulse_info);
-               pa_operation_unref(o);
-       } else {
-               pa_threaded_mainloop_lock(pulse_info->m);
-               CHECK_CONTEXT_DEAD_GOTO(pulse_info->context, unlock_and_fail);
-
-               debug_msg("[PA] pa_ext_update_volume m[%p] c[%p]", pulse_info->m, pulse_info->context);
-               o = pa_ext_policy_update_volume(pulse_info->context, set_update_volume_cb, pulse_info);
-               CHECK_CONTEXT_SUCCESS_GOTO(pulse_info->context, o, unlock_and_fail);
-               while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) {
-                       pa_threaded_mainloop_wait(pulse_info->m);
-                       CHECK_CONTEXT_DEAD_GOTO(pulse_info->context, unlock_and_fail);
-               }
-               pa_operation_unref(o);
-               pa_threaded_mainloop_unlock(pulse_info->m);
-       }
-       return;
-
-unlock_and_fail:
-       if (o) {
-               pa_operation_cancel(o);
-               pa_operation_unref(o);
-       }
-       pa_threaded_mainloop_unlock(pulse_info->m);
-}
-
-/* -------------------------------- booting sound  --------------------------------------------*/
-
-#define VCONF_BOOTING "memory/private/sound/booting"
-
-static void __pa_context_success_cb (pa_context *c, int success, void *userdata)
-{
-       pulse_info_t *pinfo = (pulse_info_t *)userdata;
-       if (pinfo == NULL) {
-               debug_error ("pinfo is null");
-               return;
-       }
-
-       if (success) {
-               debug_msg ("[PA_CB] m[%p] c[%p] set booting success", pinfo->m, c);
-       } else {
-               debug_error("[PA_CB] m[%p] c[%p] set booting fail:%s", pinfo->m, c, pa_strerror(pa_context_errno(c)));
-       }
-       pa_threaded_mainloop_signal(pinfo->m, 0);
-}
-
-static void _booting_changed_cb(keynode_t* node, void* data)
-{
-       char* booting = NULL;
-       pulse_info_t* pinfo = (pulse_info_t*)data;
-       pa_operation *o = NULL;
-       unsigned int value;
-
-       if (pinfo == NULL) {
-               debug_error ("pinfo is null");
-               return;
-       }
-
-       booting = vconf_get_str(VCONF_BOOTING);
-       debug_msg ("%s changed callback called, booting value = %s\n",vconf_keynode_get_name(node), booting);
-       if (booting) {
-               free(booting);
-       }
-
-       pa_threaded_mainloop_lock(pinfo->m);
-       CHECK_CONTEXT_DEAD_GOTO(pinfo->context, unlock_and_fail);
-
-       mm_sound_volume_get_value(VOLUME_TYPE_SYSTEM, &value);
-       o = pa_ext_policy_play_sample(pinfo->context, "booting", VOLUME_TYPE_SYSTEM, VOLUME_GAIN_BOOTING, value, ( void (*)(pa_context *, uint32_t , void *))__pa_context_success_cb, pinfo);
-
-       CHECK_CONTEXT_SUCCESS_GOTO(pinfo->context, o, unlock_and_fail);
-       while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) {
-               pa_threaded_mainloop_wait(pinfo->m);
-               CHECK_CONTEXT_DEAD_GOTO(pinfo->context, unlock_and_fail);
-       }
-       pa_operation_unref(o);
-
-       pa_threaded_mainloop_unlock(pinfo->m);
-       return;
-
-unlock_and_fail:
-       if (o) {
-               pa_operation_cancel(o);
-               pa_operation_unref(o);
-       }
-       pa_threaded_mainloop_unlock(pinfo->m);
-}
-
-int MMSoundMgrPulseHandleRegisterBooting (void* pinfo)
-{
-       int ret = vconf_notify_key_changed(VCONF_BOOTING, _booting_changed_cb, pinfo);
-       debug_msg ("vconf [%s] set ret = %d\n", VCONF_BOOTING, ret);
-       return ret;
-}
-
-void* MMSoundMgrPulseInit(void)
+void* MMSoundMgrPulseInit(pa_disconnect_cb cb, void* user_data)
 {
        pulse_info = (pulse_info_t*) malloc (sizeof(pulse_info_t));
        memset (pulse_info, 0, sizeof(pulse_info_t));
@@ -2647,22 +2229,13 @@ void* MMSoundMgrPulseInit(void)
        pulse_info->usb_idx = PA_INVALID_INDEX;
        pulse_info->dock_idx = PA_INVALID_INDEX;
        pulse_info->device_type = PA_INVALID_INDEX;
-#ifdef SUPPORT_MONO_AUDIO
-       MMSoundMgrPulseHandleRegisterMonoAudio(pulse_info);
-#endif
-#ifdef SUPPORT_AUDIO_BALANCE
-       MMSoundMgrPulseHandleRegisterAudioBalance(pulse_info);
-       MMSoundMgrPulseHandleResetAudioBalanceOnBoot(pulse_info);
-#endif
 
-#ifdef SUPPORT_AUDIO_MUTEALL
-       MMSoundMgrPulseHandleRegisterAudioMuteall(pulse_info);
-       MMSoundMgrPulseHandleResetAudioMuteallOnBoot(pulse_info);
-#endif
+       pulse_info->disconnect_cb = cb;
+       pulse_info->user_data = user_data;
+
 #ifdef SUPPORT_BT_SCO
        MMSoundMgrPulseHandleRegisterBluetoothStatus(pulse_info);
 #endif
-       MMSoundMgrPulseHandleRegisterBooting(pulse_info);
 
        debug_leave("\n");
        return pulse_info;
@@ -2674,6 +2247,11 @@ int MMSoundMgrPulseFini(void* handle)
 
        debug_enter("\n");
 
+       if (handle == NULL) {
+               debug_warning ("handle is NULL....");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
        pulse_deinit(pinfo);
 #ifdef SUPPORT_BT_SCO
        bt_deinitialize();
@@ -2687,4 +2265,5 @@ int MMSoundMgrPulseFini(void* handle)
        debug_leave("\n");
        return MM_ERROR_NONE;
 }
+#endif
 
index 317c897..de783fb 100644 (file)
@@ -19,6 +19,7 @@
  *
  */
 
+#if 0
 #include <stdlib.h>
 #include <string.h>
 #include <pthread.h>
@@ -53,8 +54,6 @@
 
 #define MAX_STRING_LEN 256
 
-#define VCONF_SOUND_BURSTSHOT "memory/private/sound/burstshot"
-
 #define DEVICE_API_BLUETOOTH   "bluez"
 #define DEVICE_API_ALSA        "alsa"
 #define DEVICE_BUS_BLUETOOTH "bluetooth"
@@ -550,7 +549,7 @@ static int __set_playback_route_notification (session_state_t state)
 
        if (state == SESSION_START) {
                /* FIXME : Need to check using vconf key with check status and policy */
-               if (_mm_sound_is_recording() || _mm_sound_is_mute_policy()) {
+               if (mm_sound_util_is_recording() || mm_sound_util_is_mute_policy()) {
                        /* Force earphone path for mute case */
                        if ((ret = __set_sound_path_to_earphone_only ()) != MM_ERROR_NONE) {
                                debug_error ("__set_sound_path_to_earphone_only() failed [%x]\n", ret);
@@ -699,25 +698,6 @@ static bool __is_recording_subsession ()
        return is_recording;
 }
 
-static void _wait_if_burstshot_exists(void)
-{
-       int retry = 0;
-       int is_burstshot = 0;
-
-       do {
-               if (retry > 0)
-                       usleep (BURST_CHECK_INTERVAL);
-               if (vconf_get_int(VCONF_SOUND_BURSTSHOT, &is_burstshot) != 0) {
-                       debug_warning ("Faided to get [%s], assume no burstshot....", VCONF_SOUND_BURSTSHOT);
-                       is_burstshot = 0;
-               } else {
-                       debug_warning ("Is Burstshot [%d], retry...[%d/%d], interval usec = %d",
-                                               is_burstshot, retry, MAX_BURST_CHECK_RETRY, BURST_CHECK_INTERVAL);
-               }
-       } while (is_burstshot && retry++ < MAX_BURST_CHECK_RETRY);
-}
-
-
 static int __set_sound_path_for_current_active (bool need_broadcast, bool need_cork)
 {
        int ret = MM_ERROR_NONE;
@@ -733,9 +713,6 @@ static int __set_sound_path_for_current_active (bool need_broadcast, bool need_c
                return MM_ERROR_SOUND_INVALID_STATE;
        }
 
-       /* Wait if BurstShot is ongoing */
-       _wait_if_burstshot_exists();
-
        if (need_cork)
                MMSoundMgrPulseSetCorkAll (true);
 
@@ -747,8 +724,8 @@ static int __set_sound_path_for_current_active (bool need_broadcast, bool need_c
        if (in == MM_SOUND_DEVICE_IN_BT_SCO && out == MM_SOUND_DEVICE_OUT_BT_SCO) {
                bool nrec = 0;
                int bandwidth = MM_SOUND_BANDWIDTH_UNKNOWN;
-
-               ret = MMSoundMgrPulseGetBluetoothInfo(&nrec, &bandwidth);
+               /* Remove BT dependency */
+               /* ret = MMSoundMgrPulseGetBluetoothInfo(&nrec, &bandwidth); */
                if(ret == MM_ERROR_NONE) {
                        g_info.bt_info.is_nrec = nrec;
                        g_info.bt_info.ag_wb = bandwidth;
@@ -791,7 +768,7 @@ static int __set_sound_path_for_current_active (bool need_broadcast, bool need_c
                        if (out == MM_SOUND_DEVICE_OUT_MIRRORING) {
                                /* mirroring option */
                        }
-                       if (_mm_sound_is_mute_policy ()) {
+                       if (mm_sound_util_is_mute_policy ()) {
                                /* Mute Ringtone */
                                out = MM_SOUND_DEVICE_OUT_BT_A2DP;
                        } else {
@@ -810,40 +787,12 @@ static int __set_sound_path_for_current_active (bool need_broadcast, bool need_c
        case SESSION_VOICECALL:
        case SESSION_VIDEOCALL:
                if (g_info.subsession == SUBSESSION_RINGTONE) {
-#ifndef _TIZEN_PUBLIC_
-#ifndef TIZEN_MICRO
-                       int vr_enabled = 0;
-#endif
-                       int vr_ringtone_enabled = 0;
-#endif
                        in = MM_SOUND_DEVICE_IN_NONE;
                        /* If active device was WFD(mirroring), set option */
                        if (out == MM_SOUND_DEVICE_OUT_MIRRORING) {
                                /* mirroring option */
                        }
 
-#ifndef _TIZEN_PUBLIC_
-#ifdef TIZEN_MICRO
-                       if (vconf_get_bool(VCONF_KEY_VR_RINGTONE_ENABLED, &vr_ringtone_enabled)) {
-                               debug_warning("vconf_get_bool for %s failed\n", VCONF_KEY_VR_RINGTONE_ENABLED);
-                       }
-
-                       if (vr_ringtone_enabled) {
-                               /* bargin option */
-                       }
-#else
-                       /* If voice control for incoming call is enabled, set capture path here for avoiding ringtone breaks */
-                       if (vconf_get_bool(VCONF_KEY_VR_ENABLED, &vr_enabled)) {
-                               debug_warning("vconf_get_bool for %s failed\n", VCONF_KEY_VR_ENABLED);
-                       } else if (vconf_get_bool(VCONF_KEY_VR_RINGTONE_ENABLED, &vr_ringtone_enabled)) {
-                               debug_warning("vconf_get_bool for %s failed\n", VCONF_KEY_VR_RINGTONE_ENABLED);
-                       }
-
-                       if (vr_enabled && vr_ringtone_enabled) {
-                               /* bargin option */
-                       }
-#endif /* TIZEN_MICRO */
-#endif /* #ifndef _TIZEN_PUBLIC_ */
                        if (_mm_sound_is_mute_policy ()) {
                                /* Mute Ringtone */
 #ifdef TIZEN_MICRO
@@ -950,7 +899,6 @@ static int __set_sound_path_for_current_active (bool need_broadcast, bool need_c
                }               
                MMSoundMgrPulseSetCorkAll (false);
        }
-       MMSoundMgrPulseUpdateVolume();
 
        /* clean up */
        debug_fleave();
@@ -1096,6 +1044,18 @@ int  MMSoundMgrSessionSetSoundPathForActiveDevice (mm_sound_device_out playback,
                SET_CAPTURE_ONLY_ACTIVE(capture);
        }
        MMSoundMgrPulseSetActiveDevice(GET_ACTIVE_CAPTURE(), GET_ACTIVE_PLAYBACK());
+
+       if (IS_ACTIVE(MM_SOUND_DEVICE_OUT_BT_A2DP)) {
+               MMSoundMgrPulseSetDefaultSink (DEVICE_API_BLUETOOTH, DEVICE_BUS_BLUETOOTH);
+       } else if (IS_ACTIVE(MM_SOUND_DEVICE_OUT_USB_AUDIO)) {
+               MMSoundMgrPulseSetUSBDefaultSink (MM_SOUND_DEVICE_OUT_USB_AUDIO);
+       } else if (IS_ACTIVE(MM_SOUND_DEVICE_OUT_MULTIMEDIA_DOCK)) {
+               MMSoundMgrPulseSetUSBDefaultSink (MM_SOUND_DEVICE_OUT_MULTIMEDIA_DOCK);
+       } else if (IS_ACTIVE(MM_SOUND_DEVICE_OUT_HDMI)) {
+               MMSoundMgrPulseSetDefaultSinkByName (ALSA_SINK_HDMI);
+       } else {
+               MMSoundMgrPulseSetDefaultSink (DEVICE_API_ALSA, DEVICE_BUS_BUILTIN);
+       }
        UNLOCK_PATH();
 
 END_SET_DEVICE:
@@ -1127,6 +1087,18 @@ static int __set_sound_path_for_active_device_nolock (mm_sound_device_out playba
        }
        MMSoundMgrPulseSetActiveDevice(GET_ACTIVE_CAPTURE(), GET_ACTIVE_PLAYBACK());
 
+       if (IS_ACTIVE(MM_SOUND_DEVICE_OUT_BT_A2DP)) {
+               MMSoundMgrPulseSetDefaultSink (DEVICE_API_BLUETOOTH, DEVICE_BUS_BLUETOOTH);
+       } else if (IS_ACTIVE(MM_SOUND_DEVICE_OUT_USB_AUDIO)) {
+               MMSoundMgrPulseSetUSBDefaultSink (MM_SOUND_DEVICE_OUT_USB_AUDIO);
+       } else if (IS_ACTIVE(MM_SOUND_DEVICE_OUT_MULTIMEDIA_DOCK)) {
+               MMSoundMgrPulseSetUSBDefaultSink (MM_SOUND_DEVICE_OUT_MULTIMEDIA_DOCK);
+       } else if (IS_ACTIVE(MM_SOUND_DEVICE_OUT_HDMI)) {
+               MMSoundMgrPulseSetDefaultSinkByName (ALSA_SINK_HDMI);
+       } else {
+               MMSoundMgrPulseSetDefaultSink (DEVICE_API_ALSA, DEVICE_BUS_BUILTIN);
+       }
+
 END_SET_DEVICE:
        debug_fleave();
        return ret;
@@ -1307,7 +1279,7 @@ static void __set_initial_active_device (void)
        SET_AVAILABLE(MM_SOUND_DEVICE_IN_MIC);
 
        /* Get wired status and set available status */
-       _mm_sound_get_earjack_type (&g_info.headset_type);
+       mm_sound_util_get_earjack_type (&g_info.headset_type);
        if (g_info.headset_type > EARJACK_UNPLUGGED) {
                SET_AVAILABLE(MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY);
                if (g_info.headset_type == DEVICE_EARJACK_TYPE_SPK_WITH_MIC) {
@@ -1321,7 +1293,7 @@ static void __set_initial_active_device (void)
        }
 
        /* Get Dock status and set available status */
-       _mm_sound_get_dock_type (&dock_type);
+       mm_sound_util_get_dock_type (&dock_type);
        if (dock_type == DOCK_DESKDOCK) {
                SET_AVAILABLE(MM_SOUND_DEVICE_OUT_DOCK);
        }
@@ -2586,20 +2558,13 @@ int MMSoundMgrSessionSetSubSession(subsession_t subsession, int subsession_opt)
                                need_update = true;
                        }
                        break;
-       }       if (g_info.subsession == SUBSESSION_VOICE) {
-#ifdef SUPPORT_BT_SCO
-               if (IS_ACTIVE(MM_SOUND_DEVICE_OUT_BT_SCO) && IS_ACTIVE(MM_SOUND_DEVICE_IN_BT_SCO)) {
-                       /* Update BT info */
-                       MMSoundMgrPulseUpdateBluetoothAGCodec();
-               }
-#endif
        }
-
        if (g_info.subsession == SUBSESSION_VOICE) {
 #ifdef SUPPORT_BT_SCO
                if (IS_ACTIVE(MM_SOUND_DEVICE_OUT_BT_SCO) && IS_ACTIVE(MM_SOUND_DEVICE_IN_BT_SCO)) {
                        /* Update BT info */
-                       MMSoundMgrPulseUpdateBluetoothAGCodec();
+                       /* Remove BT dependency */
+                       /* MMSoundMgrPulseUpdateBluetoothAGCodec(); */
                }
 #endif
        }
@@ -2674,11 +2639,7 @@ bool MMSoundMgrSessionGetVoiceControlState ()
 /* -------------------------------- NOISE REDUCTION --------------------------------------------*/
 static bool __is_noise_reduction_on (void)
 {
-       int noise_reduction_on = 1;
-
-       if (vconf_get_bool(VCONF_KEY_NOISE_REDUCTION, &noise_reduction_on)) {
-               debug_warning("vconf_get_bool for VCONF_KEY_NOISE_REDUCTION failed\n");
-       }
+       int noise_reduction_on = 0;
 
        return (noise_reduction_on == 1) ? true : false;
 }
@@ -2686,11 +2647,7 @@ static bool __is_noise_reduction_on (void)
 /* -------------------------------- EXTRA VOLUME --------------------------------------------*/
 static bool __is_extra_volume_on (void)
 {
-       int extra_volume_on = 1;
-
-       if (vconf_get_bool(VCONF_KEY_EXTRA_VOLUME, &extra_volume_on )) {
-               debug_warning("vconf_get_bool for VCONF_KEY_EXTRA_VOLUME failed\n");
-       }
+       int extra_volume_on = 0;
 
        return (extra_volume_on  == 1) ? true : false;
 }
@@ -2699,11 +2656,7 @@ static bool __is_extra_volume_on (void)
 /* -------------------------------- UPSCALING --------------------------------------------*/
 static bool __is_upscaling_needed (void)
 {
-       int is_wbamr = 1;
-
-       if (vconf_get_bool(VCONF_KEY_WBAMR, &is_wbamr)) {
-               debug_warning("vconf_get_bool for VCONF_KEY_WBAMR failed\n");
-       }
+       int is_wbamr = 0;
 
        return (is_wbamr == 0) ? true : false;
 }
@@ -2906,4 +2859,5 @@ int MMSoundMgrSessionFini(void)
 
        return MM_ERROR_NONE;
 }
+#endif
 
index d330b94..fe44b7c 100644 (file)
@@ -242,7 +242,7 @@ static int _MMSoundPluginGetList(const char *plugdir ,char ***list)
                        goto free_entry;
                }
 
-               debug_msg("item %d is %s\n", item_idx, entry[item_idx]->d_name);
+               debug_log("item %d is %s\n", item_idx, entry[item_idx]->d_name);
 
                if (S_ISREG(finfo.st_mode)) {
                        temp[tn++] = __strcatdup(plugdir, entry[item_idx]->d_name);
index b5bd15c..2c88eea 100644 (file)
 #include "include/mm_sound_mgr_run.h"
 #include "include/mm_sound_mgr_codec.h"
 #include "include/mm_sound_mgr_ipc.h"
-#include "include/mm_sound_mgr_pulse.h"
+#include "include/mm_sound_mgr_ipc_dbus.h"
+//#include "include/mm_sound_mgr_pulse.h"
 #include "include/mm_sound_mgr_asm.h"
-#include "include/mm_sound_mgr_session.h"
-#include "include/mm_sound_mgr_device.h"
-#include "include/mm_sound_mgr_device_headset.h"
-#include "include/mm_sound_mgr_device_dock.h"
-#include "include/mm_sound_mgr_device_hdmi.h"
-#include "include/mm_sound_mgr_device_wfd.h"
+//#include "include/mm_sound_mgr_session.h"
+//#include "include/mm_sound_mgr_device.h"
+//#include "include/mm_sound_mgr_device_headset.h"
+//#include "include/mm_sound_mgr_device_dock.h"
+//#include "include/mm_sound_mgr_device_hdmi.h"
+//#include "include/mm_sound_mgr_device_wfd.h"
 #include <audio-session-manager.h>
 
 #include <glib.h>
@@ -66,7 +67,7 @@
 #define HIBERNATION_SOUND_CHECK_PATH   "/tmp/hibernation/sound_ready"
 #define USE_SYSTEM_SERVER_PROCESS_MONITORING
 
-#define        ASM_CHECK_INTERVAL      10000
+#define VCONFKEY_CHECK_INTERVAL        10000
 
 #define MAX_PLUGIN_DIR_PATH_LEN        256
 
@@ -106,57 +107,55 @@ GMainLoop *g_mainloop;
 
 void* pulse_handle;
 
-gpointer event_loop_thread(gpointer data)
+void mainloop_run()
 {
        g_mainloop = g_main_loop_new(NULL, TRUE);
        if(g_mainloop == NULL) {
                debug_error("g_main_loop_new() failed\n");
        }
        g_main_loop_run(g_mainloop);
-       return NULL;
 }
 
-static void __wait_for_asm_ready ()
+static void __wait_for_vconfkey_ready (const char *keyname)
 {
        int retry_count = 0;
-       int asm_ready = 0;
-       while (!asm_ready) {
-               debug_msg("Checking ASM ready....[%d]\n", retry_count++);
-               if (vconf_get_int(ASM_READY_KEY, &asm_ready)) {
-                       debug_warning("vconf_get_int for ASM_READY_KEY (%s) failed\n", ASM_READY_KEY);
+       int vconf_ready = 0;
+       while (!vconf_ready) {
+               debug_msg("Checking the vconf key[%s] ready....[%d]\n", keyname, retry_count++);
+               if (vconf_get_int(keyname, &vconf_ready)) {
+                       debug_warning("vconf_get_int for vconf key[%s] failed\n", keyname);
                }
-               usleep (ASM_CHECK_INTERVAL);
+               usleep (VCONFKEY_CHECK_INTERVAL);
        }
-       debug_msg("ASM is now ready...clear the key!!!\n");
-       vconf_set_int(ASM_READY_KEY, 0);
+       debug_msg("vconf key[%s] is now ready...clear the key!!!\n", keyname);
+       vconf_set_int(keyname, 0);
 }
 
 static int _handle_power_off ()
 {
-       int handle = 0;
-       int asm_error = 0;
-
-       if (ASM_register_sound (-1, &handle, ASM_EVENT_EMERGENCY, ASM_STATE_PLAYING, NULL, NULL, ASM_RESOURCE_NONE, &asm_error)) {
-               if (ASM_unregister_sound (handle, ASM_EVENT_EMERGENCY, &asm_error)) {
-                       debug_log ("asm register/unregister success!!!\n");
-                       return 0;
-               } else {
-                       debug_error ("asm unregister failed...0x%x\n", asm_error);
-               }
-       } else {
-               debug_error ("asm register failed...0x%x\n", asm_error);
-       }
-
-       return -1;
+       debug_warning ("not supported\n");
+       return 0;
 }
 
 static int _handle_sound_reset ()
 {
-       int ret = 0;
        debug_warning ("not supported\n");
        return 0;
 }
 
+static void _pa_disconnect_cb (void *user_data)
+{
+       debug_warning ("g_mainloop = %p, user_data = %p", g_mainloop, user_data);
+
+       if (pulse_handle) {
+               free(pulse_handle);
+               pulse_handle = NULL;
+       }
+
+       if (g_mainloop)
+               g_main_loop_quit(g_mainloop);
+}
+
 static sem_t* sem_create_n_wait()
 {
        sem_t* sem = NULL;
@@ -249,33 +248,28 @@ int main(int argc, char **argv)
        sigaction(SIGTERM, &action, &sigterm_action);
        sigaction(SIGSYS, &action, &sigsys_action);
 
-       if (!g_thread_supported ())
-               g_thread_init (NULL);
-
-       if(NULL == g_thread_create(event_loop_thread, NULL, FALSE, NULL)) {
-               fprintf(stderr,"event loop thread create failed\n");
-               return 3;
-       }
-
        if (serveropt.startserver || serveropt.printlist) {
                MMSoundThreadPoolInit();
                MMSoundMgrRunInit(serveropt.plugdir);
                MMSoundMgrCodecInit(serveropt.plugdir);
-               if (!serveropt.testmode)
-                       MMSoundMgrIpcInit();
 
-               pulse_handle = MMSoundMgrPulseInit();
+               MMSoundMgrDbusInit();
+
+//             pulse_handle = MMSoundMgrPulseInit(_pa_disconnect_cb, g_mainloop);
                MMSoundMgrASMInit();
                /* Wait for ASM Ready */
-               __wait_for_asm_ready();
+               __wait_for_vconfkey_ready(ASM_READY_KEY);
                debug_warning("sound_server [%d] asm ready...now, initialize devices!!!\n", getpid());
+#ifdef USE_FOCUS
+               MMSoundMgrFocusInit();
+#endif
 
-               _mm_sound_mgr_device_init();
-               MMSoundMgrHeadsetInit();
-               MMSoundMgrDockInit();
-               MMSoundMgrHdmiInit();
-               MMSoundMgrWfdInit();
-               MMSoundMgrSessionInit();
+//             _mm_sound_mgr_device_init();
+//             MMSoundMgrHeadsetInit();
+//             MMSoundMgrDockInit();
+//             MMSoundMgrHdmiInit();
+//             MMSoundMgrWfdInit();
+//             MMSoundMgrSessionInit();
        }
 
        debug_warning("sound_server [%d] initialization complete...now, start running!!\n", getpid());
@@ -284,40 +278,40 @@ int main(int argc, char **argv)
                /* Start Run types */
                MMSoundMgrRunRunAll();
 
-#ifdef USE_HIBERNATION
-               /* set hibernation check */
-               _mm_sound_check_hibernation (HIBERNATION_SOUND_CHECK_PATH);
-#endif
                unlink(PA_READY); // remove pa_ready file after sound-server init.
 
-               if (sem_post(sem) == -1) {
-                       debug_error ("error sem post : %d", errno);
-               } else {
-                       debug_msg ("Ready to play booting sound!!!!");
+               if (sem) {
+                       if (sem_post(sem) == -1) {
+                               debug_error ("error sem post : %d", errno);
+                       } else {
+                               debug_msg ("Ready to play booting sound!!!!");
+                       }
                }
                /* Start Ipc mgr */
-               MMSoundMgrIpcReady();
+
+               mainloop_run();
        }
 
        debug_warning("sound_server [%d] terminating \n", getpid());
 
        if (serveropt.startserver || serveropt.printlist) {
                MMSoundMgrRunStopAll();
-               if (!serveropt.testmode)
-                       MMSoundMgrIpcFini();
-
+               MMSoundMgrDbusFini();
                MMSoundMgrCodecFini();
                MMSoundMgrRunFini();
                MMSoundThreadPoolFini();
 
-               MMSoundMgrWfdFini();
-               MMSoundMgrHdmiFini();
-               MMSoundMgrDockFini();
-               MMSoundMgrHeadsetFini();
-               MMSoundMgrSessionFini();
-               _mm_sound_mgr_device_fini();
+//             MMSoundMgrWfdFini();
+//             MMSoundMgrHdmiFini();
+//             MMSoundMgrDockFini();
+//             MMSoundMgrHeadsetFini();
+//             MMSoundMgrSessionFini();
+//             _mm_sound_mgr_device_fini();
+#ifdef USE_FOCUS
+               MMSoundMgrFocusFini();
+#endif
                MMSoundMgrASMFini();
-               MMSoundMgrPulseFini(pulse_handle);
+//             MMSoundMgrPulseFini(pulse_handle);
 #ifdef USE_HIBERNATION
                if(heynoti_unsubscribe(heynotifd, "HIBERNATION_LEAVE", NULL)) {
                        debug_error("heynoti_unsubscribe failed..\n");
@@ -326,7 +320,7 @@ int main(int argc, char **argv)
 #endif
        }
 
-       debug_warning("sound_server [%d] exit \n", getpid());
+       debug_warning("sound_server [%d] exit ----------------- END \n", getpid());
 
        return 0;
 }
index 6a3ff0d..a98b5cc 100644 (file)
@@ -8,12 +8,15 @@ libsoundpluginkeytone_la_CFLAGS  = \
                                $(GIO_CFLAGS) \
                                -I$(srcdir)/../../../include \
                                -I$(srcdir)/../../include \
+                               $(PA_CFLAGS) \
                                $(MMLOGSVR_CFLAGS) -DMMF_LOG_OWNER=0x002 -DMMF_DEBUG_PREFIX=\"MMF-SOUND\"
 
 libsoundpluginkeytone_la_LIBADD  = $(MMCOMMON_LIBS) \
                                $(MMLOGSVR_LIBS) \
                                $(VCONF_LIBS) \
                                $(GIO_LIBS) \
+                               $(PA_LIBS) \
+                               $(srcdir)/../../../libmmfsound.la \
                                $(srcdir)/../../../common/libmmfsoundcommon.la
 
 if OGG_SUPPORT
index 70b0672..acf092a 100644 (file)
 #include "../../include/mm_sound_plugin_codec.h"
 #include "../../../include/mm_sound_utils.h"
 #include "../../../include/mm_sound_common.h"
-#include "../../include/mm_sound_pa_client.h"
+#include "../../../include/mm_sound_pa_client.h"
 
-#ifdef OGG_SUPPORT
-#include <tremolo_vorbisdec_api.h>
-#define OGG_DEC_BUF_SIZE 4096
-#endif
-
-#define OGG_FILE_SAMPLE_PLAY_DURATION (290)
 #define DEFAULT_TIMEOUT_MSEC_IN_USEC (600*1000)
 #define ENV_KEYTONE_TIMEOUT "KEYTONE_TIMEOUT"
 
@@ -61,6 +55,8 @@
 #define KEYTONE_PATH_TMP "/tmp/keytone"                /* Keytone pipe path (it will be deprecated)*/
 #define KEYTONE_GROUP  6526                    /* Keytone group : assigned by security */
 #define FILE_FULL_PATH 1024                            /* File path lenth */
+#define ROLE_NAME_LEN 64                               /* Role name length */
+#define VOLUME_GAIN_TYPE_LEN 64                /* Volume gain type length */
 #define AUDIO_CHANNEL 1
 #define AUDIO_SAMPLERATE 44100
 #define DURATION_CRITERIA 11000          /* write once or not       */
 
 #endif /* SUPPORT_DBUS_KEYTONE */
 
-enum {
-       WAVE_CODE_UNKNOWN               = 0,
-       WAVE_CODE_PCM                   = 1,
-       WAVE_CODE_ADPCM                 = 2,
-       WAVE_CODE_G711                  = 3,
-       WAVE_CODE_IMA_ADPCM             = 17,
-       WAVE_CODE_G723_ADPCM            = 20,
-       WAVE_CODE_GSM                   = 49,
-       WAVE_CODE_G721_ADPCM            = 64,
-       WAVE_CODE_MPEG                  = 80,
-};
-
-#define MAKE_FOURCC(a, b, c, d)                ((a) | (b) << 8) | ((c) << 16 | ((d) << 24))
-#define RIFF_CHUNK_ID                          ((unsigned long) MAKE_FOURCC('R', 'I', 'F', 'F'))
-#define RIFF_CHUNK_TYPE                                ((unsigned long) MAKE_FOURCC('W', 'A', 'V', 'E'))
-#define FMT_CHUNK_ID                           ((unsigned long) MAKE_FOURCC('f', 'm', 't', ' '))
-#define DATA_CHUNK_ID                          ((unsigned long) MAKE_FOURCC('d', 'a', 't', 'a'))
-
-enum {
-       RENDER_READY,
-       RENDER_START,
-       RENDER_STARTED,
-       RENDER_STOP,
-       RENDER_STOPED,
-       RENDER_STOPED_N_WAIT,
-       RENDER_COND_TIMED_WAIT,
-};
-
 typedef struct
 {
        pthread_mutex_t sw_lock;
@@ -118,11 +86,6 @@ typedef struct
        int volume_config;
        int state;
        void *src;
-#ifdef OGG_SUPPORT
-       void *ogg_dec;
-       unsigned char *ogg_dec_buf;
-       int ogg_offset;
-#endif
 } keytone_info_t;
 
 typedef struct
@@ -139,48 +102,85 @@ typedef struct
 
 static int (*g_thread_pool_func)(void*, void (*)(void*)) = NULL;
 
-int CreateAudioHandle();
-static int g_CreatedFlag = 0;
-static int __MMSoundKeytoneParse(MMSourceType *source, mmsound_codec_info_t *info);
 static int _MMSoundKeytoneInit(void);
 static int _MMSoundKeytoneFini(void);
-static int _MMSoundKeytoneRender(void *param_not_used);
 static keytone_info_t g_keytone;
 static int stop_flag = 0;
 
-//#define USE_SILENT_SND
-#ifdef USE_SILENT_SND
-/* Per Sample X 1000 msec /Samplerate = Duration per Sample msec */
-/* 1024 Samples X 1000 / 44.1K = 23.22 msec [Duration of Zerovalue feeding time */
-/* Mono channel & 16bit format = 2byte per sample */
-#define SILENT_SND 4096
-static unsigned char g_silent_sound[SILENT_SND];
-#endif
-
-#define CONTROL_LATENCY
-#ifdef CONTROL_LATENCY
-#define LATENCY_BUF (8192*2)
-#define LATENCY_CONTROL (5292*2)
-static unsigned char g_latency_buf[LATENCY_BUF];
-#endif
-
-
-
 #ifdef SUPPORT_DBUS_KEYTONE
-typedef struct {
+#define AUDIO_VOLUME_CONFIG_TYPE(vol) (vol & 0x00FF)
+#define AUDIO_VOLUME_CONFIG_GAIN(vol) (vol & 0xFF00)
+typedef struct ipc_data {
        char filename[FILE_FULL_PATH];
-       int volume_config;
-} ipc_t;
+       char role[ROLE_NAME_LEN];
+       char volume_gain_type[VOLUME_GAIN_TYPE_LEN];
+}ipc_t;
 
 GDBusConnection *conn;
 guint sig_id;
 
+static const char* _convert_volume_type_to_role(int volume_type)
+{
+       debug_warning ("volume_type(%d)", volume_type);
+       switch(volume_type) {
+       case VOLUME_TYPE_SYSTEM:
+               return "system";
+       case VOLUME_TYPE_NOTIFICATION:
+               return "notification";
+       case VOLUME_TYPE_ALARM:
+               return "alarm";
+       case VOLUME_TYPE_RINGTONE:
+               return "ringtone";
+       case VOLUME_TYPE_CALL:
+               return "call";
+       case VOLUME_TYPE_VOIP:
+               return "voip";
+       case VOLUME_TYPE_VOICE:
+               return "voice";
+       default:
+               return NULL;
+       }
+}
+
+static const char* _convert_volume_gain_type_to_string(int volume_gain_type)
+{
+       debug_warning ("volume_gain_type(0x%x)", volume_gain_type);
+       switch(volume_gain_type) {
+       case VOLUME_GAIN_DEFAULT:
+               return NULL;
+       case VOLUME_GAIN_DIALER:
+               return "dialer";
+       case VOLUME_GAIN_TOUCH:
+               return "touch";
+       case VOLUME_GAIN_AF:
+               return "af";
+       case VOLUME_GAIN_SHUTTER1:
+               return "shutter1";
+       case VOLUME_GAIN_SHUTTER2:
+               return "shutter2";
+       case VOLUME_GAIN_CAMCORDING:
+               return "camcording";
+       case VOLUME_GAIN_MIDI:
+               return "midi";
+       case VOLUME_GAIN_BOOTING:
+               return "booting";
+       case VOLUME_GAIN_VIDEO:
+               return "video";
+       case VOLUME_GAIN_TTS:
+               return "tts";
+       default:
+               return NULL;
+       }
+}
+
 static int _play_keytone(const char *filename, int volume_config)
 {
        int err = -1;
        int fd = -1;
-       ipc_t data = {{0,},};
+       ipc_t data = {{0,},{0,},{0,}};
        int ret = MM_ERROR_NONE;
+       char *role = NULL;
+       char *vol_gain_type = NULL;
 
        debug_msg("filepath=[%s], volume_config=[0x%x]\n", filename, volume_config);
 
@@ -189,9 +189,16 @@ static int _play_keytone(const char *filename, int volume_config)
 
        /* Open PIPE */
        if ((fd = open(KEYTONE_PATH, O_WRONLY | O_NONBLOCK)) != -1) {
-               /* Set send info. */
-               data.volume_config = volume_config;
+               /* convert volume type to role */
+               role = _convert_volume_type_to_role(AUDIO_VOLUME_CONFIG_TYPE(volume_config));
+               if (role) {
+                       MMSOUND_STRNCPY(data.role, role, ROLE_NAME_LEN);
+                       vol_gain_type = _convert_volume_gain_type_to_string(AUDIO_VOLUME_CONFIG_GAIN(volume_config));
+                       if (vol_gain_type)
+                               MMSOUND_STRNCPY(data.volume_gain_type, vol_gain_type, VOLUME_GAIN_TYPE_LEN);
+               }
                MMSOUND_STRNCPY(data.filename, filename, FILE_FULL_PATH);
+
                /* Write to PIPE */
                if ((err = write(fd, &data, sizeof(ipc_t))) < 0) {
                        debug_error("Fail to write data: %s\n", strerror(errno));
@@ -209,13 +216,13 @@ static int _play_keytone(const char *filename, int volume_config)
        return ret;
 }
 
-static bool __is_mute_sound ()
+static bool _is_mute_sound ()
 {
        int setting_sound_status = true;
        int setting_touch_sound = true;
 
        /* 1. Check if recording is in progress */
-       if (_mm_sound_is_recording()) {
+       if (mm_sound_util_is_recording()) {
                debug_log ("During Recording....MUTE!!!");
                return true;
        }
@@ -227,7 +234,7 @@ static bool __is_mute_sound ()
        return !(setting_sound_status & setting_touch_sound);
 }
 
-static void on_changed_receive(GDBusConnection *conn,
+static void _on_changed_receive(GDBusConnection *conn,
                                                           const gchar *sender_name,
                                                           const gchar *object_path,
                                                           const gchar *interface_name,
@@ -238,7 +245,7 @@ static void on_changed_receive(GDBusConnection *conn,
        debug_msg ("sender : %s, object : %s, interface : %s, signal : %s",
                        sender_name, object_path, interface_name, signal_name);
 
-       if (__is_mute_sound ()) {
+       if (_is_mute_sound ()) {
                debug_log ("Skip playing keytone due to mute sound mode");
        } else {
                _play_keytone (DBUS_HW_KEYTONE, VOLUME_TYPE_SYSTEM | VOLUME_GAIN_TOUCH);
@@ -262,7 +269,7 @@ static int _init_dbus_keytone ()
 
        sig_id = g_dbus_connection_signal_subscribe(conn,
                        NULL, INTERFACE_NAME, SIGNAL_NAME, OBJECT_PATH, NULL, 0,
-                       on_changed_receive, NULL, NULL);
+                       _on_changed_receive, NULL, NULL);
        if (sig_id == 0) {
                debug_error ("g_dbus_connection_signal_subscribe() error (%d)", sig_id);
                goto sig_error;
@@ -288,22 +295,6 @@ static void _deinit_dbus_keytone ()
 }
 #endif /* SUPPORT_DBUS_KEYTONE */
 
-
-static MMSourceType * _mm_source_dup(MMSourceType *source)
-{
-       MMSourceType *dup = (MMSourceType *)malloc (sizeof (MMSourceType));
-       memcpy (dup, source, sizeof (MMSourceType));
-
-       dup->ptr = (char*)malloc (source->tot_size);
-       memcpy (dup->ptr, source->ptr, source->tot_size);
-       dup->type = MM_SOURCE_MEMORY;
-       dup->fd = -1;
-
-       return dup;
-}
-
-
-
 static
 int MMSoundPlugRunKeytoneControlRun(void)
 {
@@ -315,17 +306,8 @@ int MMSoundPlugRunKeytoneControlRun(void)
        mmsound_codec_info_t info = {0,};
        MMSourceType source = {0,};
 
-       mmsound_codec_info_t info_cached = {0,};
-       MMSourceType* source_cached = NULL;
-       int is_new_keytone = 0;
-       char previous_keytone[FILE_FULL_PATH] = { 0, };
        buf_param_t buf_param = {NULL, NULL};
 
-#ifdef OGG_SUPPORT
-       int skipsize;
-       OGG_DEC_INFO ogg_info;
-#endif
-
        debug_enter("\n");
 
        /* INIT IPC */
@@ -363,7 +345,6 @@ int MMSoundPlugRunKeytoneControlRun(void)
 
        debug_msg("Start IPC with pipe\n");
        size = sizeof(ipc_type);
-       int once= MMSOUND_TRUE;
 
 #ifdef SUPPORT_DBUS_KEYTONE
        _init_dbus_keytone();
@@ -382,153 +363,11 @@ int MMSoundPlugRunKeytoneControlRun(void)
 #if defined(_DEBUG_VERBOS_)
                debug_log("Read returns\n");
 #endif
-
-               pthread_mutex_lock(&g_keytone.sw_lock);
-
-               if (g_keytone.state == RENDER_STARTED) {
-                       g_keytone.state = RENDER_STOP;
-                       pthread_cond_wait(&g_keytone.sw_cond, &g_keytone.sw_lock);
-               }
-
-               /* Close audio handle if volume_config is changed */
-               if ((g_CreatedFlag == MMSOUND_TRUE) && (g_keytone.volume_config != data.volume_config)) {
-                       debug_msg("Close audio handle if volume config is changed previous:%x new:%x",
-                               g_keytone.volume_config, data.volume_config);
-
-                       if(mm_sound_pa_close(g_keytone.handle) < 0)
-                               debug_critical("mm_sound_pa_close() failed !!!!!!!!\n");
-
-                       g_CreatedFlag = MMSOUND_FALSE;
-               }
-               g_keytone.volume_config = data.volume_config;
-#if defined(_DEBUG_VERBOS_)
-               debug_log("The volume config is [%x]\n", g_keytone.volume_config);
-#endif
-
-               is_new_keytone = strcmp (data.filename, previous_keytone);
-               if (is_new_keytone) {
-                       ret = mm_source_open_file(data.filename, &source, MM_SOURCE_NOT_DRM_CONTENTS);
-                       if (ret != MM_ERROR_NONE) {
-                               debug_critical("Cannot open files\n");
-                               pthread_mutex_unlock(&g_keytone.sw_lock);
-                               continue;
-                       }
-                       ret = __MMSoundKeytoneParse(&source, &info);
-                       if (ret != MM_ERROR_NONE) {
-                               debug_critical("Fail to parse file\n");
-                               mm_source_close(&source);
-                               source.ptr = NULL;
-                               pthread_mutex_unlock(&g_keytone.sw_lock);
-                               continue;
-                       }
-
-                       /* Close audio handle if audio spec is changed */
-                       if ((g_CreatedFlag == MMSOUND_TRUE)
-                               && ((info.channels != info_cached.channels)
-                                       || (info.samplerate!= info_cached.samplerate)
-                                       || (info.format != info_cached.format))) {
-                               debug_msg("Close audio handle if audio channel is changed with previous:%d new:%d", info_cached.channels, info.channels);
-
-                               if(mm_sound_pa_close(g_keytone.handle) < 0)
-                                       debug_critical("mm_sound_pa_close() failed !!!!!!!!\n");
-
-                               g_CreatedFlag = MMSOUND_FALSE;
-                       }
-
-                       /* Cache this */
-                       strcpy (previous_keytone, data.filename);
-                       memcpy (&info_cached, &info, sizeof(mmsound_codec_info_t));
-                       /* Free previous buffer */
-                       if (source_cached) {
-                               mm_source_close(source_cached);
-                               free (source_cached);
-                               source_cached = NULL;
-                       }
-                       /* Cache again in case of new keytone path */
-                       source_cached = _mm_source_dup(&source);
-
-                       /* Close opened file after copy sound */
-                       ret = mm_source_close(&source);
-                       if (ret != MM_ERROR_NONE)
-                       {
-                               debug_critical("Fail to close file\n");
-                               source.ptr = NULL;
-                               pthread_mutex_unlock(&g_keytone.sw_lock);
-                               continue;
-                       }
-               } else {
-#if defined(_DEBUG_VERBOS_)
-                       debug_msg ("CONTROL :: Use Cached data : skip source open & parse!!!!!\n");
-#endif
-               }
-
-               if (g_CreatedFlag== MMSOUND_FALSE) {
-                       if(MM_ERROR_NONE != CreateAudioHandle(info)) {
-                               debug_critical("Audio handle creation failed. cannot play keytone\n");
-                               mm_source_close(&source);
-                               source.ptr = NULL;
-                               pthread_mutex_unlock(&g_keytone.sw_lock);
-                               continue;
-                       }
-                       g_CreatedFlag = MMSOUND_TRUE;
-               }
-               /* Use cached value always */
-               buf_param.info = &info_cached;
-               buf_param.source = source_cached;
-
-#ifdef OGG_SUPPORT
-               if(!is_new_keytone) {
-                       if (buf_param.info->codec == MM_SOUND_SUPPORTED_CODEC_OGG) {
-                               debug_msg("In case OGG codec type = %d :: SrcPtr = %x :: SrcSize =%d \n ", buf_param.info->codec,buf_param.source->ptr, buf_param.source->cur_size);
-                               ret = OGGDEC_ResetDecode(g_keytone.ogg_dec);
-                               if(ret != OGGDEC_SUCCESS) {
-                                       debug_warning("Fail to reset, if in case of first time, ignore it");
-                               }
-                               ret = OGGDEC_InitDecode(g_keytone.ogg_dec, (unsigned char*)buf_param.source->ptr, buf_param.source->cur_size, &skipsize);
-                               if(ret != OGGDEC_SUCCESS) {
-                                       debug_error("Fail to init ogg decoder\n");
-                                       pthread_mutex_unlock(&g_keytone.sw_lock);
-                                       if (fd > -1) close(fd);
-                                       return MM_ERROR_SOUND_UNSUPPORTED_MEDIA_TYPE;
-                               }
-                               ret = OGGDEC_InfoDecode(g_keytone.ogg_dec, (unsigned char*)buf_param.source->ptr, &skipsize, &ogg_info);
-                               if(ret != OGGDEC_SUCCESS) {
-                                       debug_error("Fail to get ogg info\n");
-                                       pthread_mutex_unlock(&g_keytone.sw_lock);
-                                       if (fd > -1) close(fd);
-                                       return MM_ERROR_SOUND_UNSUPPORTED_MEDIA_TYPE;
-                               }
-                       }
-               }
-#endif
-               g_keytone.src = &buf_param;
-               if (once== MMSOUND_TRUE) {
-                       g_thread_pool_func(NULL,  (void*)_MMSoundKeytoneRender);
-                       once= MMSOUND_FALSE;
-               }
-
-               if (g_keytone.state == RENDER_STOPED_N_WAIT ||
-                                g_keytone.state == RENDER_COND_TIMED_WAIT) {
-                       pthread_cond_signal(&g_keytone.sw_cond);
-               }
-
-#if defined(_DEBUG_VERBOS_)
-               debug_log ("set state to START, unlock \n");
-#endif
-               g_keytone.state = RENDER_START;
-               pthread_mutex_unlock(&g_keytone.sw_lock);
-
        }
 
        if (fd > -1)
                close(fd);
 
-       if (source_cached) {
-               mm_source_close(source_cached);
-               free(source_cached);
-               source_cached = NULL;
-       }
-
        _MMSoundKeytoneFini();
        debug_leave("\n");
 
@@ -590,27 +429,7 @@ static int _MMSoundKeytoneInit(void)
                debug_error("pthread_cond_init() failed\n");
                return MM_ERROR_SOUND_INTERNAL;
        }
-#ifdef OGG_SUPPORT
-       /* Ogg decoder create */
-       g_keytone.ogg_dec_buf = (unsigned char*) malloc(sizeof(unsigned char)*OGG_DEC_BUF_SIZE);
-       if (g_keytone.ogg_dec_buf == NULL) {
-               debug_error("Fail to malloc\n");
-               return MM_ERROR_SOUND_NO_FREE_SPACE;
-       }
-       memset(g_keytone.ogg_dec_buf, 0, sizeof(unsigned char)*OGG_DEC_BUF_SIZE);
-       if(!OGGDEC_CreateDecode(&g_keytone.ogg_dec)) {
-               free(g_keytone.ogg_dec_buf);
-               debug_error("Fail to create OGG decoder\n");
-               return MM_ERROR_SOUND_INTERNAL;
-       }
-#endif
-#ifdef USE_SILENT_SND
-       memset(g_silent_sound, 0, SILENT_SND);
-#endif
 
-#ifdef CONTROL_LATENCY
-       memset(g_latency_buf, 0, LATENCY_BUF);
-#endif
        return MM_ERROR_NONE;
 }
 
@@ -628,416 +447,5 @@ static int _MMSoundKeytoneFini(void)
                debug_error("Fail to destroy cond\n");
                return MM_ERROR_SOUND_INTERNAL;
        }
-#ifdef OGG_SUPPORT
-       if(!OGGDEC_ResetDecode(g_keytone.ogg_dec)) {
-               debug_error("Fail to Reset decode\n");
-               return MM_ERROR_SOUND_INTERNAL;
-       }
-
-       if(!OGGDEC_DeleteDecode(g_keytone.ogg_dec)) {
-               debug_error("Fail to delete decoder\n");
-               return MM_ERROR_SOUND_INTERNAL;
-       }
-       if (g_keytone.ogg_dec_buf)
-               free(g_keytone.ogg_dec_buf);
-#endif
-       return MM_ERROR_NONE;
-}
-
-int CreateAudioHandle(mmsound_codec_info_t info)
-{
-       int err = MM_ERROR_NONE;
-       int size;
-       int mode;
-       pa_sample_spec ss;
-
-       if(info.duration < OGG_FILE_SAMPLE_PLAY_DURATION) {
-               mode = HANDLE_MODE_OUTPUT_LOW_LATENCY;
-       } else {
-               mode = HANDLE_MODE_OUTPUT;
-       }
-
-       ss.rate = info.samplerate;
-       ss.channels = info.channels;
-       ss.format = PA_SAMPLE_S16LE;
-
-       mm_sound_handle_route_info route_info;
-       route_info.policy = HANDLE_ROUTE_POLICY_OUT_AUTO;
-
-       g_keytone.handle = mm_sound_pa_open(mode, &route_info, HANDLE_PRIORITY_NORMAL, g_keytone.volume_config, &ss, NULL, &size);
-       if(!g_keytone.handle) {
-               debug_error("Fail to audio open \n");
-               return MM_ERROR_SOUND_INTERNAL;
-       }
-
-#if defined(_DEBUG_VERBOS_)
-       debug_log("Period size is %d bytes\n", g_keytone.period);
-#endif
-
-       //FIXME :: remove dasf buffer size
-       if (g_keytone.period > MAX_BUFFER_SIZE) {
-               g_keytone.period = MAX_BUFFER_SIZE;
-       }
-
-       return err;
-
-}
-
-static void _init_timeout_val (struct timeval* ptv)
-{
-       int timeout_us = DEFAULT_TIMEOUT_MSEC_IN_USEC;
-       char* str_timeout = NULL;
-
-       if (ptv == NULL)
-               return;
-
-       str_timeout = getenv (ENV_KEYTONE_TIMEOUT);
-       if (str_timeout) {
-               debug_log ("[%s] detected = [%s]\n", ENV_KEYTONE_TIMEOUT, str_timeout);
-               timeout_us = atoi (str_timeout);
-       }
-       debug_log ("Set keytone timeout as [%d] us\n", timeout_us);
-
-       ptv->tv_sec = 0;
-       ptv->tv_usec = timeout_us;
-}
-
-static int _MMSoundKeytoneRender(void *param_not_used)
-{
-       //static int IsAmpON = MMSOUND_FALSE; //FIXME :: this should be removed
-       MMSourceType source = {0,};
-       mmsound_codec_info_t info = {0,};
-       unsigned char *buf = NULL;
-       unsigned int size=0;
-       buf_param_t *param=NULL;
-//     unsigned int period_buffer, period_time = 0;
-
-#ifdef LATENCY_CONTROL
-       static int lt_cnt = 0;
-#endif
-
-       struct timespec timeout;
-       struct timeval tv;
-       struct timeval tv_to_add;
-       struct timeval tv_result;
-       int stat;
-#ifdef OGG_SUPPORT
-       int err, decoded_len, used_size;
-#endif
-       /* Initialize timeout value */
-       _init_timeout_val (&tv_to_add);
-
-       /* Loop */
-       while(stop_flag) {
-               pthread_mutex_lock(&g_keytone.sw_lock);
-               if(g_keytone.state == RENDER_STOPED) {
-#if defined(_DEBUG_VERBOS_)
-                       debug_log ("set state to STOPPED_N_WAIT and do cond wait\n");
-#endif
-                       g_keytone.state = RENDER_STOPED_N_WAIT;
-                       pthread_cond_wait(&g_keytone.sw_cond, &g_keytone.sw_lock);
-               }
-
-               if(g_keytone.state == RENDER_START) {
-                       param = (buf_param_t *)g_keytone.src;
-                       source = *param->source; /* Copy source */
-                       info = *param->info;
-                       buf = source.ptr+info.doffset;
-                       size = info.size;
-                       if(buf[0]=='\0') {
-                               size=0;
-                               debug_critical("Ooops.... Not Expected!!!!!!!!\n");
-                       }
-                       g_keytone.state = RENDER_STARTED;
-               }
-               pthread_mutex_unlock(&g_keytone.sw_lock);
-
-#ifdef USE_SILENT_SND
-{
-               static int use_silent_snd = 0;
-               use_silent_snd = 1;
-               if(use_silent_snd) {
-                       /* Silent SND playback */
-                       mm_sound_pa_write(g_keytone.handle, g_silent_sound, SILENT_SND);
-                       debug_msg("[Keysound] Silence sound played %d\n",SILENT_SND);
-                       use_silent_snd = 0;
-               }
-}
-#endif
-
-               while(size && stop_flag) {
-                       pthread_mutex_lock(&g_keytone.sw_lock);
-                       if (g_keytone.state == RENDER_STOP) {
-#ifdef CONTROL_LATENCY
-#if defined(_DEBUG_VERBOS_)
-                               debug_log ("[CONTROL_LATENCY] state is STOP %d", lt_cnt);
-#endif
-                               if(lt_cnt > 0) {
-                                       mm_sound_pa_write(g_keytone.handle, g_latency_buf, lt_cnt);
-                                       mm_sound_pa_drain(g_keytone.handle);
-                                       lt_cnt = 0;
-                               }
-#endif /* CONTROL_LATENCY */
-
-                               pthread_mutex_unlock(&g_keytone.sw_lock);
-                               break;
-                       }
-                       pthread_mutex_unlock(&g_keytone.sw_lock);
-                       if(info.codec == MM_SOUND_SUPPORTED_CODEC_OGG) {
-#ifdef OGG_SUPPORT
-                               err = OGGDEC_FrameDecode(g_keytone.ogg_dec, (unsigned char*)buf, &used_size, (char*)g_keytone.ogg_dec_buf, &decoded_len);
-                               if (decoded_len == 0) {
-                                       /* EOF */
-                                       /* Rare case */
-                                       break;
-                               }
-                               if (decoded_len > 0) {
-#ifdef CONTROL_LATENCY
-                                       memcpy(g_latency_buf+lt_cnt, g_keytone.ogg_dec_buf, decoded_len);
-                                       lt_cnt += decoded_len;
-                                       buf += used_size;
-#if defined(_DEBUG_VERBOS_)
-                                       debug_log("[CONTROL_LATENCY] DATA Ring count %d", lt_cnt);
-#endif
-                                       if(lt_cnt > LATENCY_CONTROL) {
-                                               mm_sound_pa_write(g_keytone.handle, g_latency_buf, lt_cnt);
-#if defined(_DEBUG_VERBOS_)
-                                               debug_log("[CONTROL_LATENCY] Write count %d", lt_cnt);
-#endif
-                                               lt_cnt = 0;
-                                       }
-#else
-                                       mm_sound_pa_write(g_keytone.handle, g_keytone.ogg_dec_buf, decoded_len);
-                                       buf += used_size;
-#endif /* CONTROL_LATENCY */
-                               } else {
-                                       size = 0;
-                                       break;
-                               }
-                               if (err != OGGDEC_SUCCESS) {
-                                       size = 0;
-                                       debug_log("Decoding End %d", err);
-#ifdef CONTROL_LATENCY
-                                       if(lt_cnt > 0) {
-                                               mm_sound_pa_write(g_keytone.handle, g_latency_buf, lt_cnt);
-#if defined(_DEBUG_VERBOS_)
-                                               debug_log("[CONTROL_LATENCY] Last frame is out %d", lt_cnt);
-#endif
-                                               mm_sound_pa_drain(g_keytone.handle);
-                                               lt_cnt = 0;
-                                       }
-#endif /* CONTROL_LATENCY */
-                                       break;
-                               }
-#endif /* OGG_SUPPORT */
-                       } else if (size < DURATION_CRITERIA) {
-#if defined(_DEBUG_VERBOS_)
-                               debug_msg("[Keysound] Last Buffer :: size=%d, period=%d\n", size, DURATION_CRITERIA);
-#endif
-                               mm_sound_pa_write(g_keytone.handle,  buf, size);
-                               size = 0;
-                       } else {
-#if defined(_DEBUG_VERBOS_)
-                               debug_msg("[Keysound] size=%d, period=%d\n", size, DURATION_CRITERIA);
-#endif
-                               mm_sound_pa_write(g_keytone.handle, (void *)buf, DURATION_CRITERIA);
-                               size -= DURATION_CRITERIA;
-                               buf += DURATION_CRITERIA;
-                       }
-               }
-               pthread_mutex_lock(&g_keytone.sw_lock);
-               if(g_keytone.state == RENDER_STOP ) {
-#if defined(_DEBUG_VERBOS_)
-                       debug_log("state is STOP, do cond signal \n");
-#endif
-                       g_keytone.state = RENDER_STOPED;
-                       pthread_cond_signal(&g_keytone.sw_cond);
-               } else {
-#if defined(_DEBUG_VERBOS_)
-                       debug_log("state is not STOP\n");
-#endif
-                       g_keytone.state = RENDER_COND_TIMED_WAIT;
-
-                       /* Set timeout : GetCurrent + Timeout => convert to timespec */
-                       gettimeofday(&tv, NULL);
-                       timeradd(&tv, &tv_to_add, &tv_result);
-                       timeout.tv_sec = tv_result.tv_sec;
-                       timeout.tv_nsec = tv_result.tv_usec * 1000;
-
-                       stat = pthread_cond_timedwait(&g_keytone.sw_cond, &g_keytone.sw_lock, &timeout);
-                       if(stat == ETIMEDOUT && g_keytone.state != RENDER_START) {
-                               debug_log("TIMEOUT in Not START state, close Audio, set state to STOPPED\n");
-
-                               if(mm_sound_pa_close(g_keytone.handle) < 0)
-                                       debug_critical("mm_sound_pa_close() failed !!!!!!!!\n");
-
-                               g_CreatedFlag = MMSOUND_FALSE;
-                               g_keytone.state = RENDER_STOPED;
-                       }
-               } /* while(stop_flag) */
-
-               pthread_mutex_unlock(&g_keytone.sw_lock);
-       }
-       return MMSOUND_FALSE;
-}
-
-static int __MMSoundKeytoneParse(MMSourceType *source, mmsound_codec_info_t *info)
-{
-       struct __riff_chunk
-       {
-               long chunkid;
-               long chunksize;
-               long rifftype;
-       };
-
-       struct __wave_chunk
-       {
-               long chunkid;
-               long chunksize;
-               unsigned short compression;
-               unsigned short channels;
-               unsigned long samplerate;
-               unsigned long avgbytepersec;
-               unsigned short blockkalign;
-               unsigned short bitspersample;
-       };
-
-       struct __data_chunk
-       {
-               long chunkid;
-               long chunkSize;
-       };
-
-       struct __riff_chunk *priff = NULL;
-       struct __wave_chunk *pwav = NULL;
-       struct __data_chunk *pdata = NULL;
-//     struct __fmt_chunk *pfmt  = NULL;
-
-       int datalen = -1;
-       char *data = NULL;
-       unsigned int tSize;
-       int ret;
-#ifdef OGG_SUPPORT
-       OGG_DEC_INFO ogg_info;
-       int skipsize;
-#endif
-
-       data = MMSourceGetPtr(source);
-       datalen = MMSourceGetCurSize(source);
-
-#if defined(_DEBUG_VERBOS_)
-       debug_msg("source ptr :[%p]\n", data);
-       debug_msg("source size :[%d]\n", datalen);
-#endif
-       priff = (struct __riff_chunk *) data;
-
-       /* Must be checked, Just for wav or not */
-       if (priff->chunkid != RIFF_CHUNK_ID ||priff->rifftype != RIFF_CHUNK_TYPE) {
-#ifdef OGG_SUPPORT
-               ret = OGGDEC_ResetDecode(g_keytone.ogg_dec);
-               if(ret != OGGDEC_SUCCESS) {
-                       debug_warning("Fail to reset, if in case of first time, ignore it");
-               }
-               /* Ogg media type case */
-               ret = OGGDEC_InitDecode(g_keytone.ogg_dec, (unsigned char*)data, datalen, &skipsize);
-               if(ret != OGGDEC_SUCCESS ) {
-                       debug_error("Fail to init ogg decoder\n");
-                       return MM_ERROR_SOUND_UNSUPPORTED_MEDIA_TYPE;
-               }
-               info->doffset = skipsize;
-
-               ret = OGGDEC_InfoDecode(g_keytone.ogg_dec, (unsigned char*)data, &skipsize, &ogg_info);
-               if(ret != OGGDEC_SUCCESS ) {
-                       debug_error("Fail to get ogg info\n");
-                       return MM_ERROR_SOUND_UNSUPPORTED_MEDIA_TYPE;
-               }
-               ret = OGGDEC_PreparseDecode((unsigned char*)data, datalen, &ogg_info);
-               if (ret != OGGDEC_SUCCESS) {
-                       debug_error("Not valid Ogg data format");
-                       return MM_ERROR_SOUND_UNSUPPORTED_MEDIA_TYPE;
-               }
-
-               info->codec = MM_SOUND_SUPPORTED_CODEC_OGG;
-               info->channels = ogg_info.channels;
-               info->format = 16;
-               info->samplerate = ogg_info.samplerate;
-               info->doffset += skipsize;
-               info->size = datalen;
-               info->duration = ogg_info.duration;
-               debug_msg("Duration %d :: Channels %d :: Samplerate %d :: File size %d :: offset %d \n", ogg_info.duration, ogg_info.channels, ogg_info.samplerate, info->size, info->doffset);
-               //debug_leave("\n");
-               return MM_ERROR_NONE;
-#else
-               debug_error("Not WAVE File\n");
-               return MM_ERROR_SOUND_UNSUPPORTED_MEDIA_TYPE;
-#endif
-       }
-
-       if(priff->chunksize != datalen -8)
-               priff->chunksize = (datalen-8);
-
-       if (priff->chunkid != RIFF_CHUNK_ID ||priff->chunksize != datalen -8 ||priff->rifftype != RIFF_CHUNK_TYPE) {
-               debug_msg("This contents is not RIFF file\n");
-#if defined(_DEBUG_VERBOS_)
-               debug_msg("cunkid : %ld, chunksize : %ld, rifftype : 0x%lx\n", priff->chunkid, priff->chunksize, priff->rifftype);
-               debug_msg("cunkid : %ld, chunksize : %d, rifftype : 0x%lx\n", RIFF_CHUNK_ID, datalen-8, RIFF_CHUNK_TYPE);
-#endif
-               return MM_ERROR_SOUND_UNSUPPORTED_MEDIA_TYPE;
-       }
-#if defined(_DEBUG_VERBOS_)
-       debug_msg("cunkid : %ld, chunksize : %ld, rifftype : %lx\n", priff->chunkid, priff->chunksize, priff->rifftype);
-       debug_msg("cunkid : %ld, chunksize : %d, rifftype : %lx\n", RIFF_CHUNK_ID, datalen-8, RIFF_CHUNK_TYPE);
-#endif
-       tSize = sizeof(struct __riff_chunk);
-       pdata = (struct __data_chunk*)(data+tSize);
-
-       while (pdata->chunkid != FMT_CHUNK_ID && tSize < datalen) {
-               tSize += (pdata->chunkSize+8);
-
-               if (tSize >= datalen) {
-                       debug_warning("Wave Parsing is Finished : unable to find the Wave Format chunk\n");
-                       return MM_ERROR_SOUND_UNSUPPORTED_MEDIA_TYPE;
-               } else {
-                       pdata = (struct __data_chunk*)(data+tSize);
-               }
-       }
-       pwav = (struct __wave_chunk*)(data+tSize);
-
-       if (pwav->chunkid != FMT_CHUNK_ID ||
-                  pwav->compression != WAVE_CODE_PCM ||        /* Only supported PCM */
-                  pwav->avgbytepersec != pwav->samplerate * pwav->blockkalign ||
-                  pwav->blockkalign != (pwav->bitspersample >> 3)*pwav->channels) {
-               debug_msg("This contents is not supported wave file\n");
-#if defined(_DEBUG_VERBOS_)
-               debug_msg("chunkid : 0x%lx, comp : 0x%x, av byte/sec : %lu, blockalign : %d\n", pwav->chunkid, pwav->compression, pwav->avgbytepersec, pwav->blockkalign);
-#endif
-               return MM_ERROR_SOUND_UNSUPPORTED_MEDIA_TYPE;
-       }
-
-       /* Only One data chunk support */
-
-       tSize += (pwav->chunksize+8);
-       pdata = (struct __data_chunk *)(data+tSize);
-
-       while (pdata->chunkid != DATA_CHUNK_ID && tSize < datalen) {
-               tSize += (pdata->chunkSize+8);
-               if (tSize >= datalen) {
-                       debug_warning("Wave Parsing is Finished : unable to find the data chunk\n");
-                       return MM_ERROR_SOUND_UNSUPPORTED_MEDIA_TYPE;
-               } else {
-                       pdata = (struct __data_chunk*)(data+tSize);
-               }
-       }
-
-       info->codec = MM_SOUND_SUPPORTED_CODEC_WAVE;
-       info->channels = pwav->channels;
-       info->format = pwav->bitspersample;
-       info->samplerate = pwav->samplerate;
-       info->doffset = (tSize+8);
-       info->size = pdata->chunkSize;
-#if defined(_DEBUG_VERBOS_)
-       debug_msg("info->size:%d\n", info->size);
-#endif
-
        return MM_ERROR_NONE;
 }
index ea1c76b..d3a1f14 100644 (file)
@@ -9,11 +9,14 @@ libsoundplugintremoloogg_la_CFLAGS  = \
                                -I$(srcdir)/ \
                                -I$(srcdir)/../../include \
                                -I$(srcdir)/../../../include \
+                               $(PA_CFLAGS) \
                                $(MMLOGSVR_CFLAGS) -DMMF_LOG_OWNER=0x002 -DMMF_DEBUG_PREFIX=\"MMF-SOUND\"
 
 libsoundplugintremoloogg_la_LIBADD = $(MMCOMMON_LIBS) \
                                $(MMLOGSVR_LIBS) \
                                $(TREMOLO_LIBS) \
+                               $(PA_LIBS) \
+                               $(srcdir)/../../../libmmfsound.la \
                                $(srcdir)/../../../common/libmmfsoundcommon.la
 
 install-exec-hook:
index 78abc8f..de590fe 100644 (file)
@@ -372,7 +372,7 @@ int MMSoundPlugCodecOggCreate(mmsound_codec_param_t *param, mmsound_codec_info_t
                default:
                        break;
        }
-       p->handle = mm_sound_pa_open(HANDLE_MODE_OUTPUT_LOW_LATENCY, &route_info, 0, param->volume_config, &ss, NULL, &size);
+       p->handle = mm_sound_pa_open(HANDLE_MODE_OUTPUT_LOW_LATENCY, &route_info, 0, param->volume_config, &ss, NULL, &size, param->stream_type, param->stream_index);
        if(!p->handle) {
                debug_error("[CODEC OGG] Can not open audio handle\n");
                if (p->handle_route == MM_SOUND_HANDLE_ROUTE_SPEAKER || p->handle_route == MM_SOUND_HANDLE_ROUTE_SPEAKER_NO_RESTORE) {
index 022bc49..6e7d138 100644 (file)
@@ -6,10 +6,14 @@ libsoundplugintone_la_CFLAGS  = \
                                $(MMCOMMON_CFLAGS) \
                                -I$(srcdir)/../../../../common/include \
                                -I$(srcdir)/../../../include \
+                               $(PA_CFLAGS) \
                                $(MMLOGSVR_CFLAGS) -DMMF_LOG_OWNER=0x002 -DMMF_DEBUG_PREFIX=\"MMF-SOUND\"
 
 libsoundplugintone_la_LIBADD  = \
                                $(MMCOMMON_LIBS) \
+                               $(PA_LIBS) \
+                               $(srcdir)/../../../libmmfsound.la \
+                               $(srcdir)/../../../common/libmmfsoundcommon.la \
                                $(MMLOGSVR_LIBS)
 
 install-exec-hook:
index 468bd74..85fbbf6 100644 (file)
@@ -786,7 +786,7 @@ int MMSoundPlugCodecToneCreate(mmsound_codec_param_t *param, mmsound_codec_info_
        ss.format = PA_SAMPLE_S16LE;
        route_info.policy = HANDLE_ROUTE_POLICY_OUT_AUTO;
 
-       toneInfo->handle = mm_sound_pa_open(HANDLE_MODE_OUTPUT, &route_info, HANDLE_PRIORITY_NORMAL, param->volume_config, &ss, NULL, &size);
+       toneInfo->handle = mm_sound_pa_open(HANDLE_MODE_OUTPUT, &route_info, HANDLE_PRIORITY_NORMAL, param->volume_config, &ss, NULL, &size, param->stream_type, param->stream_index);
        if (!toneInfo->handle) {
                debug_error("Device Open Error 0x%x\n", result);
                goto Error;
index b2a7110..0bb8989 100644 (file)
@@ -6,10 +6,13 @@ libsoundpluginwave_la_CFLAGS  = \
                                $(MMCOMMON_CFLAGS) \
                               -I$(srcdir)/../../../include \
                               -I$(srcdir)/../../include \
+                               $(PA_CFLAGS) \
                                $(MMLOGSVR_CFLAGS) -DMMF_LOG_OWNER=0x002 -DMMF_DEBUG_PREFIX=\"MMF-SOUND\"
 
 libsoundpluginwave_la_LIBADD  = $(MMCOMMON_LIBS) \
                                $(MMLOGSVR_LIBS) \
+                               $(PA_LIBS) \
+                               $(srcdir)/../../../libmmfsound.la \
                                $(srcdir)/../../../common/libmmfsoundcommon.la 
 
 install-exec-hook:
index 93175d8..6e15091 100644 (file)
@@ -80,7 +80,7 @@ typedef struct
        int keytone;
        int repeat_count;
        int (*stop_cb)(int);
-       int cb_param;
+       int cb_param; // slotid
        int state;
        pthread_mutex_t mutex;
        pthread_mutex_t *codec_wave_mutex;
@@ -94,6 +94,8 @@ typedef struct
        MMSourceType *source;
        char buffer[48000 / 1000 * SAMPLE_COUNT * 2 *2];//segmentation fault when above 22.05KHz stereo
        int gain, out, in, option;
+       char stream_type[MM_SOUND_STREAM_TYPE_LEN];
+       int stream_index;
 } wave_info_t;
 
 static void _runing(void *param);
@@ -242,11 +244,11 @@ int MMSoundPlugCodecWaveCreate(mmsound_codec_param_t *param, mmsound_codec_info_
 #ifdef DEBUG_DETAIL
        debug_enter("\n");
 #endif
-       debug_msg("period[%d] type[%s] ch[%d] format[%d] rate[%d] doffset[%d] priority[%d] repeat[%d] volume[%d] callback[%p] keytone[%08x] route[%d]\n",
+
+       debug_msg("period[%d] type[%s] ch[%d] format[%d] rate[%d] doffset[%d] priority[%d] repeat[%d] volume[%f] callback[%p] keytone[%08x] route[%d]\n",
                        keytone_period, (info->codec == MM_SOUND_SUPPORTED_CODEC_WAVE) ? "Wave" : "Unknown",
                        info->channels, info->format, info->samplerate, info->doffset, param->priority, param->repeat_count,
                        param->volume, param->stop_cb, param->keytone, param->handle_route);
-
        source = param->source;
 
        if (g_thread_pool_func == NULL) {
@@ -275,6 +277,8 @@ int MMSoundPlugCodecWaveCreate(mmsound_codec_param_t *param, mmsound_codec_info_
        p->cb_param = param->param;
        p->source = source;
        p->codec_wave_mutex = param->codec_wave_mutex;
+       p->stream_index = param->stream_index;
+       strncpy(p->stream_type, param->stream_type, MM_SOUND_STREAM_TYPE_LEN);
        //      pthread_mutex_init(&p->mutex, NULL);
 
        debug_msg("[CODEC WAV] transper_size : %d\n", p->transper_size);
@@ -291,10 +295,7 @@ int MMSoundPlugCodecWaveCreate(mmsound_codec_param_t *param, mmsound_codec_info_
        p->channels = info->channels;
        p->samplerate = info->samplerate;
 
-       if(param->handle_route == MM_SOUND_HANDLE_ROUTE_USING_CURRENT) /* normal, solo */
-               p->handle_route = HANDLE_ROUTE_POLICY_OUT_AUTO;
-       else /* loud solo */
-               p->handle_route = HANDLE_ROUTE_POLICY_OUT_HANDSET;
+       p->handle_route = param->handle_route;
 
        switch(info->format)
        {
@@ -401,6 +402,8 @@ static void _runing(void *param)
                        /* MMSoundMgrPulseSetActiveDevice(route_info_device_in, route_info.device_out); */
                        break;
                case MM_SOUND_HANDLE_ROUTE_USING_CURRENT:
+                       route_info.policy = HANDLE_ROUTE_POLICY_OUT_AUTO;
+                       break;
                default:
                        break;
        }
@@ -409,7 +412,7 @@ static void _runing(void *param)
        ss.channels = p->channels;
        ss.format = p->format;
        p->period = pa_sample_size(&ss) * ((ss.rate * 25) / 1000);
-       p->handle = mm_sound_pa_open(p->mode, &route_info, p->priority, p->volume_config, &ss, NULL, &size);
+       p->handle = mm_sound_pa_open(p->mode, &route_info, p->priority, p->volume_config, &ss, NULL, &size, p->stream_type, p->stream_index);
        if(!p->handle) {
                debug_critical("[CODEC WAV] Can not open audio handle\n");
                CODEC_WAVE_UNLOCK(p->codec_wave_mutex);
old mode 100644 (file)
new mode 100755 (executable)
index 3cd81ec..6af657c
@@ -29,6 +29,9 @@
 #define MAX_PATH_LEN           1024
 #define MIN_TONE_PLAY_TIME 300
 #include "../include/mm_sound.h"
+#ifdef USE_FOCUS
+#include "../include/mm_sound_focus.h"
+#endif
 #include "../include/mm_sound_common.h"
 #include "../include/mm_sound_private.h"
 #include "../include/mm_sound_pa_client.h"
@@ -66,7 +69,7 @@ GIOChannel *stdin_channel;
 char g_file_name[MAX_STRING_LEN];
 char g_dir_name[MAX_PATH_LEN];
 
-
+int g_focus_watch_index = -1;
 GMainLoop* g_loop;
 
 // Function
@@ -96,16 +99,21 @@ void test_callback(void *data, int id)
        debug_log("test_callback is called\n");
        test_callback_done = 1;
 }
+void mm_sound_test_cb1(int a, void *user_data)
+{
+       debug_log("dbus test user callback called: param(%d), userdata(%d)\n", a, (int)user_data);
+       g_print("my callback pid : %u  tid : %u\n", getpid(), pthread_self());
+}
 void device_connected_cb (MMSoundDevice_t device_h, bool is_connected, void *user_data)
 {
        int ret = 0;
-       int type = 0;
+       int device_type = 0;
        int io_direction = 0;
        int state = 0;
        int id = 0;
        char *name = NULL;
        debug_log("*** device_connected_cb is called, device_h[0x%x], is_connected[%d], user_date[0x%x]\n", device_h, is_connected, user_data);
-       ret = mm_sound_get_device_type(device_h, &type);
+       ret = mm_sound_get_device_type(device_h, &device_type);
        if (ret) {
                debug_error("failed to mm_sound_get_device_type()\n");
        }
@@ -125,18 +133,18 @@ void device_connected_cb (MMSoundDevice_t device_h, bool is_connected, void *use
        if (ret) {
                debug_error("failed to mm_sound_get_device_name()\n");
        }
-       debug_log("*** --- type[%d], id[%d], io_direction[%d], state[%d], name[%s]\n", type, id, io_direction, state, name);
+       debug_log("*** --- type[%d], id[%d], io_direction[%d], state[%d], name[%s]\n", device_type, id, io_direction, state, name);
 }
 void device_info_changed_cb (MMSoundDevice_t device_h, int changed_info_type, void *user_data)
 {
        int ret = 0;
-       int type = 0;
+       int device_type = 0;
        int io_direction = 0;
        int state = 0;
        int id = 0;
        char *name = NULL;
        debug_log("*** device_info_changed_cb is called, device_h[0x%x], changed_info_type[%d], user_date[0x%x]\n", device_h, changed_info_type, user_data);
-       ret = mm_sound_get_device_type(device_h, &type);
+       ret = mm_sound_get_device_type(device_h, &device_type);
        if (ret) {
                debug_error("failed to mm_sound_get_device_type()\n");
        }
@@ -156,8 +164,40 @@ void device_info_changed_cb (MMSoundDevice_t device_h, int changed_info_type, vo
        if (ret) {
                debug_error("failed to mm_sound_get_device_name()\n");
        }
-       debug_log("*** --- type[%d], id[%d], io_direction[%d], state[%d], name[%s]\n", type, id, io_direction, state, name);
+       debug_log("*** --- type[%d], id[%d], io_direction[%d], state[%d], name[%s]\n", device_type, id, io_direction, state, name);
 }
+#ifdef USE_FOCUS
+void focus_cb0 (int index, mm_sound_focus_type_e type, mm_sound_focus_state_e state, const char *reason_for_change, const char *additional_info, void *user_data)
+{
+       char *_state = NULL;
+       if (state == FOCUS_IS_RELEASED)
+               _state = "RELEASED";
+       else
+               _state = "ACQUIRED";
+       debug_log("*** focus_cb0 is called, index[%d], focus_type[%d], state[%s], reason_for_change[%s], additional_info[%s], user_data[%s]\n",
+                       index, type, _state, reason_for_change, additional_info, user_data);
+}
+void focus_cb1 (int index, mm_sound_focus_type_e type, mm_sound_focus_state_e state, const char *reason_for_change, const char *additional_info, void *user_data)
+{
+       char *_state = NULL;
+       if (state == FOCUS_IS_RELEASED)
+               _state = "RELEASED";
+       else
+               _state = "ACQUIRED";
+       debug_log("*** focus_cb1 is called, index[%d], focus_type[%d], state[%s], reason_for_change[%s], additional_info[%s], user_data[%s]\n",
+                       index, type, _state, reason_for_change, additional_info, user_data);
+}
+void focus_watch_cb (int index, mm_sound_focus_type_e type, mm_sound_focus_state_e state, const char *reason_for_change, const char *additional_info, void *user_data)
+{
+       char *_state = NULL;
+       if (state == FOCUS_IS_RELEASED)
+               _state = "RELEASED";
+       else
+               _state = "ACQUIRED";
+       debug_log("*** focus_watch_cb is called, index[%d], focus_type[%d], state[%s], reason_for_change[%s], additional_info[%s], user_data[%s]\n",
+                       index, type, _state, reason_for_change, additional_info, user_data);
+}
+#endif
 void quit_program()
 {
        g_main_loop_quit(g_loop);
@@ -182,12 +222,15 @@ static void displaymenu()
                g_print("       Sound Play APIs\n");
                g_print("==================================================================\n");
                g_print("k : Key Sound     \t");
-               g_print("a : play sound    \t");
+               g_print("an : play sound    \t");
+               g_print("as : play sound with stream type\t");
                g_print("A : play loud solo\n");
                g_print("c : play sound ex \t");
-               g_print("F : Play DTMF     \t");
+               g_print("FN : Play DTMF     \t");
+               g_print("FS : Play DTMF with stream type\t");
                g_print("b : Play directory\n");
-               g_print("s : Stop play     \n");
+               g_print("s : Stop play     \t");
+               g_print("m : stereo to mono\n");
                g_print("==================================================================\n");
                g_print("       Volume APIs\n");
                g_print("==================================================================\n");
@@ -200,8 +243,6 @@ static void displaymenu()
                g_print("g : Get voice   \t");
                g_print("h : Inc. voice  \t");
                g_print("j : Dec. voice  \n");
-               g_print("B : Set audio balance\n");
-               g_print("M : Set mute all\n");
                g_print("==================================================================\n");
                g_print("       Audio route APIs\n");
                g_print("==================================================================\n");
@@ -231,6 +272,21 @@ static void displaymenu()
                g_print("Q : Add device info. changed callback \t");
                g_print("W : Remove device info. changed callback \n");
                g_print("==================================================================\n");
+#ifdef USE_FOCUS
+               g_print("       Focus APIs\n");
+               g_print("==================================================================\n");
+               g_print("DS : signal subscribe for stream info\t");
+               g_print("DU : signal unsubscribe for stream info\n");
+               g_print("SS : Send signal for stream info\n");
+               g_print("GU : Get Focus id\n");
+               g_print("SF : Set Focus Callback\t");
+               g_print("UF : Unset Focus Callback\n");
+               g_print("AF : Acquire Focus\t");
+               g_print("RF : Release Focus\n");
+               g_print("WS : Set Focus Watch Callback\t");
+               g_print("WU : Unset Focus Watch Callback\n");
+               g_print("==================================================================\n");
+#endif
                g_print("d : Input Directory \t");
                g_print("f : Input File name \t");
                g_print("x : Exit Program \n");
@@ -354,21 +410,313 @@ static void __mm_sound_active_device_changed_cb (mm_sound_device_in device_in, m
                        device_in, __get_capture_device_str(device_in), device_out, __get_playback_device_str(device_out));
 }
 
+static void __mm_sound_signal_cb1 (mm_sound_signal_name_t signal, int value, void *user_data)
+{
+       int _value = 0;
+       g_print ("[%s] signal[%d], value[%d], user_data[0x%x]]\n", __func__, signal, value, user_data);
+       mm_sound_get_signal_value (signal, &_value);
+       g_print (" -- get value : %d\n", _value);
+}
+
+static void __mm_sound_signal_cb2 (mm_sound_signal_name_t signal, int value, void *user_data)
+{
+       int _value = 0;
+       g_print ("[%s] signal[%d], value[%d], user_data[0x%x]]\n", __func__, signal, value, user_data);
+       mm_sound_get_signal_value (signal, &_value);
+       g_print (" -- get value : %d\n", _value);
+}
+unsigned int g_subscribe_id1 = 0;
+unsigned int g_subscribe_id2 = 0;
+
 static void interpret (char *cmd)
 {
        int ret=0;
+       int value = 0;
        static int handle = -1;
        MMSoundPlayParam soundparam = {0,};
 
        switch (g_menu_state)
        {
                case CURRENT_STATUS_MAINMENU:
+#ifdef USE_FOCUS
+                       if(strncmp(cmd, "DS", 2) ==0) {
+                               ret = mm_sound_subscribe_signal(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, &g_subscribe_id1, __mm_sound_signal_cb1, NULL);
+                               if(ret < 0)
+                                       debug_log("mm_sound_subscribe_signal() failed with 0x%x\n", ret);
+                               else
+                                       debug_log("id: %u, callback:0x%x\n", g_subscribe_id1, __mm_sound_signal_cb1);
+                               ret = mm_sound_subscribe_signal(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, &g_subscribe_id2, __mm_sound_signal_cb2, NULL);
+                               if(ret < 0)
+                                       debug_log("mm_sound_subscribe_signal() failed with 0x%x\n", ret);
+                               else
+                                       debug_log("id: %u, callback:0x%x\n", g_subscribe_id2, __mm_sound_signal_cb2);
+                       }
+
+                       else if(strncmp(cmd, "DU", 2) ==0) {
+                               mm_sound_unsubscribe_signal(g_subscribe_id1);
+                               debug_log("unsubscribe_signal for id[%d]\n", g_subscribe_id1);
+                               mm_sound_unsubscribe_signal(g_subscribe_id2);
+                               debug_log("unsubscribe_signal for id[%d]\n", g_subscribe_id2);
+                       }
+
+                       else if(strncmp(cmd, "SS", 2) ==0) {
+                               ret = mm_sound_send_signal(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, 1);
+                               if(ret < 0)
+                                       debug_log("mm_sound_send_signal() failed with 0x%x\n", ret);
+                               else
+                                       debug_log("mm_sound_send_signal for signal[%s], value[%d] is success\n", MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, 1);
+                               mm_sound_get_signal_value (MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, &value);
+                               g_print (" -- get value of RELEASE_INTERNAL_FOCUS : %d\n", value);
+                               ret = mm_sound_send_signal(MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, 0);
+                               if(ret < 0)
+                                       debug_log("mm_sound_send_signal() failed with 0x%x\n", ret);
+                               else
+                                       debug_log("mm_sound_send_signal for signal[%s], value[%d] is success\n", MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, 0);
+                               mm_sound_get_signal_value (MM_SOUND_SIGNAL_RELEASE_INTERNAL_FOCUS, &value);
+                               g_print (" -- get value of RELEASE_INTERNAL_FOCUS : %d\n", value);
+                       }
+
+                       else if(strncmp(cmd, "GU", 2) ==0) {
+                               int id = 0;
+                               ret = mm_sound_focus_get_id(&id);
+                               if(ret < 0)
+                                       debug_log("mm_sound_focus_get_id() failed with 0x%x\n", ret);
+                               else
+                                       debug_log("id : %d\n", id);
+                       }
+
+                       else if(strncmp(cmd, "SF", 2) ==0) {
+                               int ret = 0;
+                               char input_string[128];
+                               char flag_1, flag_2;
+                               int id = 0;
+                               char *stream_type = NULL;
+                               const char *user_data = "this is user data";
+
+                               fflush(stdin);
+                               g_print ("1. Media\n");
+                               g_print ("2. Alarm\n");
+                               g_print ("3. Notification\n");
+                               g_print ("4. Emergency\n");
+                               g_print ("5. TTS\n");
+                               g_print ("6. Ringtone\n");
+                               g_print ("7. Call\n");
+                               g_print ("8. VOIP\n");
+                               g_print ("0. Voice Recognition\n");
+                               g_print("> select id and stream type: (eg. 0 3)");
+
+                               if (fgets(input_string, sizeof(input_string)-1, stdin)) {
+                                       g_print ("### fgets return  NULL\n");
+                               }
+                               flag_1 = input_string[0];
+                               flag_2 = input_string[2];
+
+                               if(flag_1 == '0') { id = 0; }
+                               else if(flag_1 == '1') { id = 1; }
+                               else if(flag_1 == '2') { id = 2; }
+                               else { id = 2; }
+                               if(flag_2 == '1') { stream_type = "media"; }
+                               else if(flag_2 == '2') { stream_type = "alarm"; }
+                               else if(flag_2 == '3') { stream_type = "notification"; }
+                               else if(flag_2 == '4') { stream_type = "emergency"; }
+                               else if(flag_2 == '5') { stream_type = "tts"; }
+                               else if(flag_2 == '6') { stream_type = "ringtone"; }
+                               else if(flag_2 == '7') { stream_type = "call"; }
+                               else if(flag_2 == '8') { stream_type = "voip"; }
+                               else if(flag_2 == '0') { stream_type = "voice_recognition"; }
+                               else { stream_type = "media"; }
+
+                               ret = mm_sound_register_focus(id, stream_type, (id == 0)? focus_cb0 : focus_cb1, user_data);
+                               if (ret) {
+                                       g_print("failed to mm_sound_register_focus(), ret[0x%x]\n", ret);
+                               } else {
+                                       g_print("id[%d], stream_type[%s], callback fun[0x%x]\n", id, stream_type, (id == 0)? focus_cb0 : focus_cb1);
+                               }
+                       }
+
+                       else if(strncmp(cmd, "UF", 2) ==0) {
+                               int ret = 0;
+                               char input_string[128];
+                               char flag_1;
+                               int id = 0;
+                               fflush(stdin);
+                               g_print("> select id:");
+                               if (fgets(input_string, sizeof(input_string)-1, stdin)) {
+                                       g_print ("### fgets return  NULL\n");
+                               }
+                               flag_1 = input_string[0];
+                               if(flag_1 == '0') { id = 0; }
+                               else if(flag_1 == '1') { id = 1; }
+                               else if(flag_1 == '2') { id = 2; }
+                               else { id = 2; }
+                               ret = mm_sound_unregister_focus(id);
+                               if (ret) {
+                                       g_print("failed to mm_sound_unregister_focus(), ret[0x%x]\n", ret);
+                               }
+                       }
+
+                       else if(strncmp(cmd, "AF", 2) ==0) {
+                               int ret = 0;
+                               char input_string[128];
+                               char flag_1, flag_2;
+                               int id = 0;
+                               mm_sound_focus_type_e type = FOCUS_FOR_PLAYBACK;
+                               fflush(stdin);
+                               g_print ("1. focus for playback\n");
+                               g_print ("2. focus for recording\n");
+                               g_print ("3. focus for both\n");
+                               g_print("> select id and focus_type: (eg. 0 1)");
+                               if (fgets(input_string, sizeof(input_string)-1, stdin)) {
+                                       g_print ("### fgets return  NULL\n");
+                               }
+                               flag_1 = input_string[0];
+                               flag_2 = input_string[2];
+
+                               if(flag_1 == '0') { id = 0; }
+                               else if(flag_1 == '1') { id = 1; }
+                               else if(flag_1 == '2') { id = 2; }
+                               else { id = 2; }
+
+                               if(flag_2 == '1') { type = FOCUS_FOR_PLAYBACK; }
+                               else if(flag_2 == '2') { type = FOCUS_FOR_CAPTURE; }
+                               else { type = FOCUS_FOR_BOTH; }
+                               ret = mm_sound_acquire_focus(id, type, "additional_info. for acquire");
+                               if (ret) {
+                                       g_print("failed to mm_sound_acquire_focus(), ret[0x%x]\n", ret);
+                               }
+                       }
+
+                       else if(strncmp(cmd, "RF", 2) ==0) {
+                               int ret = 0;
+                               char input_string[128];
+                               char flag_1, flag_2;
+                               int id = 0;
+                               mm_sound_focus_type_e type = FOCUS_FOR_PLAYBACK;
+                               fflush(stdin);
+                               g_print ("1. focus for playback\n");
+                               g_print ("2. focus for recording\n");
+                               g_print ("3. focus for all\n");
+                               g_print("> select id and focus_type: (eg. 0 1)");
+                               if (fgets(input_string, sizeof(input_string)-1, stdin)) {
+                                       g_print ("### fgets return  NULL\n");
+                               }
+                               flag_1 = input_string[0];
+                               flag_2 = input_string[2];
+
+                               if(flag_1 == '0') { id = 0; }
+                               else if(flag_1 == '1') { id = 1; }
+                               else if(flag_1 == '2') { id = 2; }
+                               else { id = 2; }
+
+                               if(flag_2 == '1') { type = FOCUS_FOR_PLAYBACK; }
+                               else if(flag_2 == '2') { type = FOCUS_FOR_CAPTURE; }
+                               else { type = FOCUS_FOR_BOTH; }
+                               ret = mm_sound_release_focus(id, type, "additional_info. for release");
+                               if (ret) {
+                                       g_print("failed to mm_sound_release_focus(), ret[0x%x]\n", ret);
+                               }
+                       }
+
+                       else if(strncmp(cmd, "WS", 2) ==0) {
+                               int ret = 0;
+                               char input_string[128];
+                               char flag_1;
+                               int type = 0;
+                               char *stream_type = NULL;
+                               const char *user_data = "this is user data for watch";
+
+                               fflush(stdin);
+                               g_print ("1. playback\n");
+                               g_print ("2. recording\n");
+                               g_print ("3. both\n");
+                               g_print("> select interest focus type:");
+
+                               if (fgets(input_string, sizeof(input_string)-1, stdin)) {
+                                       g_print ("### fgets return  NULL\n");
+                               }
+                               flag_1 = input_string[0];
+
+                               if(flag_1 == '1') { type = 1; }
+                               else if(flag_1 == '2') { type = 2; }
+                               else if(flag_1 == '3') { type = 3; }
+                               else { type = 1; }
+                               ret = mm_sound_set_focus_watch_callback(type, focus_watch_cb, user_data, &g_focus_watch_index);
+                               if (ret) {
+                                       g_print("failed to mm_sound_set_focus_watch_callback(), ret[0x%x]\n", ret);
+                               } else {
+                                       g_print("index[%d], type[%d], callback fun[0x%x]\n", g_focus_watch_index, type, focus_watch_cb);
+                               }
+                       }
+
+                       else if(strncmp(cmd, "WU", 2) ==0) {
+                               int ret = 0;
+                               ret = mm_sound_unset_focus_watch_callback(g_focus_watch_index);
+                               if (ret) {
+                                       g_print("failed to mm_sound_unset_focus_watch_callback(), ret[0x%x]\n", ret);
+                               }
+                       }
+                       else if(strncmp(cmd, "k", 1) == 0)
+#else
                        if(strncmp(cmd, "k", 1) == 0)
+#endif
                        {
-                               ret = mm_sound_play_keysound(KEYTONE_FILE, 8);
+                               ret = mm_sound_play_keysound(KEYTONE_FILE, 0);
                                if(ret < 0)
                                        debug_log("keysound play failed with 0x%x\n", ret);
                        }
+                       else if (strcmp(cmd, "dbus-m") == 0) {
+                           int ret = 0;
+                           int a = 3;
+                           int b = 4;
+                           int result_val = 0;
+                           g_print("dbus method test call\n");
+                           ret = mm_sound_test(a, b, &result_val);
+                           if (ret) {
+                               g_print("failed to mm_sound_test(), ret[0x%x]\n", ret);
+                           } else {
+                               g_print("Got answer : %d\n", result_val);
+                           }
+                       } else if (strcmp(cmd, "dbus-a") == 0) {
+                           int ret = 0;
+                           int user_data = 3;
+                           g_print("dbus method test add callback\n");
+                           g_print("my testsuite pid : %u  tid : %u\n", getpid(), pthread_self());
+                           ret = mm_sound_add_test_callback(mm_sound_test_cb1, (void *)user_data);
+                           if (ret) {
+                               g_print("failed to mm_sound_add_test_callback(), ret[0x%x]\n", ret);
+                           } else {
+                               g_print("add test callback success\n");
+                           }
+                       } else if (strcmp(cmd, "dbus-r") == 0) {
+                           int ret = 0;
+                           g_print("dbus method test remove callback\n");
+                           ret = mm_sound_remove_test_callback();
+                           if (ret) {
+                               g_print("failed to mm_sound_remove_test_callback(), ret[0x%x]\n", ret);
+                           } else {
+                               g_print("remove test callback success\n");
+                           }
+                       }
+                       else if (strncmp(cmd, "gap", 3) == 0) {
+                               int ret = 0;
+                               int device_in=0, device_out=0;
+                               ret = mm_sound_get_audio_path(&device_in, &device_out);
+                               if (ret == MM_ERROR_NONE) {
+                                   g_print ("### mm_sound_get_audio_path() Success (%X,%X)\n\n", device_in, device_out);
+                               } else {
+                                   g_print ("### mm_sound_get_audio_path() Error : errno [%x]\n\n", ret);
+                               }
+                       }
+                       else if (strncmp(cmd, "spa", 3) == 0) {
+                               int ret = 0;
+                               int device_in=1, device_out=200;
+                               ret = mm_sound_set_sound_path_for_active_device(device_out, device_in);
+                               if (ret == MM_ERROR_NONE) {
+                                   g_print ("### mm_sound_set_sound_path_for_active_device() Success (%X,%X)\n\n", device_in, device_out);
+                               } else {
+                                   g_print ("### mm_sound_sspfad() Error : errno [%x]\n\n", ret);
+                               }
+                       }
                        else if(strncmp(cmd, "q", 1) == 0)
                        {//get media volume
                                unsigned int value = 100;
@@ -530,68 +878,20 @@ static void interpret (char *cmd)
                                        }
                                }
                        }
-
-                       else if(strncmp(cmd, "B", 1) == 0)
-                       {
-                               int ret = 0;
-                               char input_string[128];
-                               float balance;
-
-                               fflush(stdin);
-                               ret = mm_sound_volume_get_balance(&balance);
-                               if (ret == MM_ERROR_NONE) {
-                                       g_print ("### mm_sound_volume_get_balance Success, balance=%f\n", balance);
-                               } else {
-                                       g_print ("### mm_sound_volume_get_balance Error = %x\n", ret);
-                               }
-                               g_print("> Enter new audio balance (current is %f) : ", balance);
-                               if (fgets(input_string, sizeof(input_string)-1, stdin) == NULL) {
-                                       g_print ("### fgets return  NULL\n");
-                               }
-
-                               balance = atof (input_string);
-                               ret = mm_sound_volume_set_balance(balance);
-                               if (ret == MM_ERROR_NONE) {
-                                       g_print ("### mm_sound_volume_set_balance(%f) Success\n", balance);
-                               } else {
-                                       g_print ("### mm_sound_volume_set_balance(%f) Error = %x\n", balance, ret);
-                               }
-                       }
-
-                       else if(strncmp(cmd, "M", 1) == 0)
-                       {
-                               int ret = 0;
-                               char input_string[128];
-                               int muteall;
-
-                               fflush(stdin);
-                               ret = mm_sound_get_muteall(&muteall);
-                               if (ret == MM_ERROR_NONE) {
-                                       g_print ("### mm_sound_get_muteall Success, muteall=%d\n", muteall);
-                               } else {
-                                       g_print ("### mm_sound_get_muteall Error = %x\n", ret);
-                               }
-                               g_print("> Enter new muteall state (current is %d) : ", muteall);
-                               if (fgets(input_string, sizeof(input_string)-1, stdin) == NULL) {
-                                       g_print ("### fgets return  NULL\n");
-                               }
-
-                               muteall = atoi (input_string);
-                               ret = mm_sound_set_muteall(muteall);
-                               if (ret == MM_ERROR_NONE) {
-                                       g_print ("### mm_sound_set_muteall(%d) Success\n", muteall);
-                               } else {
-                                       g_print ("### mm_sound_set_muteall(%d) Error = %x\n", muteall, ret);
-                               }
-                       }
-
-                       else if(strncmp(cmd, "a", 1) == 0)
+                       else if(strncmp(cmd, "an", 2) == 0)
                        {
                                debug_log("volume is %d type, %d\n", g_volume_type, g_volume_value);
                                ret = mm_sound_play_sound(g_file_name, g_volume_type, mycallback ,"USERDATA", &handle);
                                if(ret < 0)
                                        debug_log("mm_sound_play_sound() failed with 0x%x\n", ret);
                        }
+                       else if(strncmp(cmd, "as", 2) == 0)
+                       {
+                               debug_log("stream %s type, %d\n", "media", g_volume_value);
+                               ret = mm_sound_play_sound_with_stream_info(g_file_name, "media", -1, mycallback ,"USERDATA", &handle);
+                               if(ret < 0)
+                                       debug_log("mm_sound_play_sound() failed with 0x%x\n", ret);
+                       }
                        else if(strncmp(cmd, "A", 1) == 0)
                        {
                                debug_log("volume is %d type, %d\n", g_volume_type, g_volume_value);
@@ -599,7 +899,7 @@ static void interpret (char *cmd)
                                if(ret < 0)
                                        debug_log("mm_sound_play_sound_loud_solo() failed with 0x%x\n", ret);
                        }
-                       else if(strncmp(cmd, "F", 1) == 0)
+                       else if(strncmp(cmd, "FN", 2) == 0)
                        {
                                char num = 0;
                                char input_string[128] = "";
@@ -721,6 +1021,124 @@ static void interpret (char *cmd)
                                                debug_log ("[magpie] Play DTMF sound cannot be played ! %d\n", handle);
                                }
                        }
+                       else if(strncmp(cmd, "FS", 2) == 0)
+                       {
+                               char num = 0;
+                               char input_string[128] = "";
+                               char *tok = NULL;
+                               char *stream_type = NULL;
+                               int tonetime=0;
+                               double volume=1.0;
+                               MMSoundTone_t tone = MM_SOUND_TONE_DTMF_0;
+
+                               while(num != 'q') {
+                                       fflush(stdin);
+                                       g_print("enter number(0~H exit:q), stream type(media, system, ...),  volume(0.0~1.0),  time(ms):\t ");
+                                       if (fgets(input_string, sizeof(input_string)-1, stdin) == NULL) {
+                                               g_print ("### fgets return  NULL\n");
+                                       }
+                                       tok = strtok(input_string, " ");
+                                       if(!tok) continue;
+                                       if(tok[0] == 'q') {
+                                               break;
+                                       }
+                                       else if(tok[0] < '0' || tok[0] > '~') {
+                                               if(tok[0] == '*' || tok[0] == '#')
+                                                       ;
+                                               else
+                                                       continue;
+                                       }
+                                       num = tok[0];
+                                       if(num >= '0' && num <= '9') {
+                                               tone = (MMSoundTone_t)(num - '0');
+                                       }
+                                       else if(num == '*') {
+                                               tone = MM_SOUND_TONE_DTMF_S;
+                                       }
+                                       else if(num == '#') {
+                                               tone =MM_SOUND_TONE_DTMF_P;
+                                       }
+                                       else if(num == 'A') {   tone = MM_SOUND_TONE_DTMF_A;    }
+                                       else if(num == 'B') {   tone = MM_SOUND_TONE_DTMF_B;    }
+                                       else if(num == 'C') {   tone = MM_SOUND_TONE_DTMF_C;    }
+                                       else if(num == 'D') {   tone = MM_SOUND_TONE_DTMF_D;    }
+                                       else if(num == 'E') {   tone = MM_SOUND_TONE_SUP_DIAL;  }
+                                       else if(num == 'F') {   tone = MM_SOUND_TONE_ANSI_DIAL; }
+                                       else if(num == 'G') {   tone = MM_SOUND_TONE_JAPAN_DIAL;        }
+                                       else if(num == 'H') {   tone = MM_SOUND_TONE_SUP_BUSY;          }
+                                       else if(num == 'I') {           tone = MM_SOUND_TONE_ANSI_BUSY;         }
+                                       else if(num == 'J') {           tone = MM_SOUND_TONE_JAPAN_BUSY;                }
+                                       else if(num == 'K') {   tone = MM_SOUND_TONE_SUP_CONGESTION;            }
+                                       else if(num == 'L') {           tone = MM_SOUND_TONE_ANSI_CONGESTION;           }
+                                       else if(num == 'M') {   tone = MM_SOUND_TONE_SUP_RADIO_ACK;             }
+                                       else if(num == 'N') {   tone = MM_SOUND_TONE_JAPAN_RADIO_ACK;           }
+                                       else if(num == 'O') {   tone = MM_SOUND_TONE_SUP_RADIO_NOTAVAIL;        }
+                                       else if(num == 'P') {   tone = MM_SOUND_TONE_SUP_ERROR;         }
+                                       else if(num == 'Q') {   tone = MM_SOUND_TONE_SUP_CALL_WAITING;  }
+                                       else if(num == 'R') {   tone = MM_SOUND_TONE_ANSI_CALL_WAITING; }
+                                       else if(num == 'S') {   tone = MM_SOUND_TONE_SUP_RINGTONE;              }
+                                       else if(num == 'T') {   tone = MM_SOUND_TONE_ANSI_RINGTONE;     }
+                                       else if(num == 'U') {   tone = MM_SOUND_TONE_PROP_BEEP;         }
+                                       else if(num == 'V') {   tone = MM_SOUND_TONE_PROP_ACK;          }
+                                       else if(num == 'W') {   tone = MM_SOUND_TONE_PROP_NACK; }
+                                       else if(num == 'X') {   tone = MM_SOUND_TONE_PROP_PROMPT;       }
+                                       else if(num == 'Y') {   tone = MM_SOUND_TONE_PROP_BEEP2;        }
+                                       else if(num == 'Z')  {  tone =MM_SOUND_TONE_CDMA_HIGH_SLS;      }
+                                       else if(num == '[')  {  tone = MM_SOUND_TONE_CDMA_MED_SLS;      }
+                                       else if(num == ']')  {  tone = MM_SOUND_TONE_CDMA_LOW_SLS;      }
+                                       else if(num == '^')  {  tone =MM_SOUND_TONE_CDMA_HIGH_S_X4;     }
+                                       else if(num == '_')  {  tone =MM_SOUND_TONE_CDMA_MED_S_X4;      }
+                                       else if(num == 'a')  {  tone =MM_SOUND_TONE_CDMA_LOW_S_X4;      }
+                                       else if(num == 'b')  {  tone =MM_SOUND_TONE_CDMA_HIGH_PBX_L;    }
+                                       else if(num == 'c')  {  tone =MM_SOUND_TONE_CDMA_MED_PBX_L;     }
+                                       else if(num == 'd')  {  tone =MM_SOUND_TONE_CDMA_LOW_PBX_L;     }
+                                       else if(num == 'e')  {  tone =MM_SOUND_TONE_CDMA_HIGH_PBX_SS;   }
+                                       else if(num == 'f')  {  tone =MM_SOUND_TONE_CDMA_MED_PBX_SS;    }
+                                       else if(num == 'g')  {  tone =MM_SOUND_TONE_CDMA_LOW_PBX_SS;    }
+                                       else if(num == 'h')  {  tone =MM_SOUND_TONE_CDMA_HIGH_PBX_SSL;  }
+                                       else if(num == 'i')  {          tone =MM_SOUND_TONE_CDMA_MED_PBX_SSL;   }
+                                       else if(num == 'j')  {  tone =MM_SOUND_TONE_CDMA_LOW_PBX_SSL;           }
+                                       else if(num == 'k')  {  tone =MM_SOUND_TONE_CDMA_HIGH_PBX_SLS;  }
+                                       else if(num == 'l')  {          tone =MM_SOUND_TONE_CDMA_MED_PBX_SLS;   }
+                                       else if(num == 'm')  {  tone =MM_SOUND_TONE_CDMA_LOW_PBX_SLS;           }
+                                       else if(num == 'n')  {  tone =MM_SOUND_TONE_CDMA_HIGH_PBX_S_X4; }
+                                       else if(num == 'o')  {  tone =MM_SOUND_TONE_CDMA_MED_PBX_S_X4;  }
+                                       else if(num == 'p')  {  tone =MM_SOUND_TONE_CDMA_LOW_PBX_S_X4;  }
+                                       else if(num == 'q')  {  tone =MM_SOUND_TONE_CDMA_ALERT_NETWORK_LITE;    }
+                                       else if(num == 'r')  {  tone =MM_SOUND_TONE_CDMA_ALERT_AUTOREDIAL_LITE; }
+                                       else if(num == 's')  {  tone =MM_SOUND_TONE_CDMA_ONE_MIN_BEEP;  }
+                                       else if(num == 't')  {  tone =MM_SOUND_TONE_CDMA_KEYPAD_VOLUME_KEY_LITE;                }
+                                       else if(num == 'u')  {  tone =MM_SOUND_TONE_CDMA_PRESSHOLDKEY_LITE;     }
+                                       else if(num == 'v')  {  tone =MM_SOUND_TONE_CDMA_ALERT_INCALL_LITE;     }
+                                       else if(num == 'w')  {  tone =MM_SOUND_TONE_CDMA_EMERGENCY_RINGBACK;    }
+                                       else if(num == 'x')  {  tone =MM_SOUND_TONE_CDMA_ALERT_CALL_GUARD;      }
+                                       else if(num == 'y')  {  tone =MM_SOUND_TONE_CDMA_SOFT_ERROR_LITE;       }
+                                       else if(num == 'z')  {  tone =MM_SOUND_TONE_CDMA_CALLDROP_LITE; }
+                                       else if(num == '{')  {  tone =MM_SOUND_TONE_LOW_FRE;    }
+                                       else if(num == '}')  {  tone =MM_SOUND_TONE_MED_FRE;    }
+                                       else if(num == '~')  {  tone =MM_SOUND_TONE_HIGH_FRE; }
+
+                                       stream_type = strtok(NULL, " ");
+
+                                       tok = strtok(NULL, " ");
+                                       if(tok)  volume = (double)atof(tok);
+
+                                       tok = strtok(NULL, " ");
+                                       if(tok)
+                                       {
+                                               tonetime = atoi(tok);
+                                       }
+                                       else
+                                       {
+                                               tonetime = MIN_TONE_PLAY_TIME;
+                                       }
+
+                                       debug_log("stream type: %s\t volume is %f\t tonetime: %d\n", stream_type, volume, tonetime);
+                                       ret = mm_sound_play_tone_with_stream_info(tone, stream_type, -1, volume, tonetime, &handle);
+                                       if(ret<0)
+                                               debug_log ("[magpie] Play DTMF sound with stream type cannot be played ! %d\n", handle);
+                               }
+                       }
                        else if (strncmp (cmd, "b",1) == 0)
                        {
                                DIR     *basedir;
@@ -926,8 +1344,7 @@ static void interpret (char *cmd)
                        } else {
                                g_print ("### mm_sound_remove_active_device_changed_callback() Error : errno [%x]\n\n", ret);
                        }
-               }
-               else if (strncmp(cmd, "{", 1) == 0) {
+               } else if (strncmp(cmd, "{", 1) == 0) {
                        int ret = 0;
                        bool connected = 0;
                        char* bt_name = NULL;
@@ -1083,7 +1500,7 @@ static void interpret (char *cmd)
                        int ret = 0;
                        mm_sound_device_flags_e flags = MM_SOUND_DEVICE_ALL_FLAG;
                        MMSoundDeviceList_t device_list;
-                       int type = 0;
+                       int device_type = 0;
                        int io_direction = 0;
                        int state = 0;
                        int id = 0;
@@ -1101,7 +1518,7 @@ static void interpret (char *cmd)
                                        if (dret) {
                                                debug_error("failed to mm_sound_get_next_device(), dret[0x%x]\n", dret);
                                        } else {
-                                               ret = mm_sound_get_device_type(device_h, &type);
+                                               ret = mm_sound_get_device_type(device_h, &device_type);
                                                if (ret) {
                                                        debug_error("failed to mm_sound_get_device_type()\n");
                                                }
@@ -1121,7 +1538,7 @@ static void interpret (char *cmd)
                                                if (ret) {
                                                        debug_error("failed to mm_sound_get_device_name()\n");
                                                }
-                                               debug_log("*** --- [NEXT DEVICE] type[%d], id[%d], io_direction[%d], state[%d], name[%s]\n", type, id, io_direction, state, name);
+                                               debug_log("*** --- [NEXT DEVICE] type[%d], id[%d], io_direction[%d], state[%d], name[%s]\n", device_type, id, io_direction, state, name);
                                        }
                                } while (dret == MM_ERROR_NONE);
                                do {
@@ -1130,7 +1547,7 @@ static void interpret (char *cmd)
                                        if (dret) {
                                                debug_error("failed to mm_sound_get_prev_device(), dret[0x%x]\n", dret);
                                        } else {
-                                               ret = mm_sound_get_device_type(device_h, &type);
+                                               ret = mm_sound_get_device_type(device_h, &device_type);
                                                if (ret) {
                                                        debug_error("failed to mm_sound_get_device_type()\n");
                                                }
@@ -1150,7 +1567,7 @@ static void interpret (char *cmd)
                                                if (ret) {
                                                        debug_error("failed to mm_sound_get_device_name()\n");
                                                }
-                                               debug_log("*** --- [PREV DEVICE] type[%d], id[%d], io_direction[%d], state[%d], name[%s]\n", type, id, io_direction, state, name);
+                                               debug_log("*** --- [PREV DEVICE] type[%d], id[%d], io_direction[%d], state[%d], name[%s]\n", device_type, id, io_direction, state, name);
                                        }
                                } while (dret == MM_ERROR_NONE);
                        }
@@ -1223,7 +1640,6 @@ static void interpret (char *cmd)
                                g_print("failed to mm_sound_remove_device_connected_callback(), ret[0x%x]\n", ret);
                        }
                }
-
                else if(strncmp(cmd, "Q", 1) ==0) {
                        int ret = 0;
                        char input_string[128];
@@ -1291,6 +1707,7 @@ static void interpret (char *cmd)
                                g_print("failed to mm_sound_remove_device_information_changed_callback(), ret[0x%x]\n", ret);
                        }
                }
+
                else if (strncmp(cmd, "x", 1) == 0) {
                        quit_program();
                }
@@ -1317,50 +1734,26 @@ void volume_change_callback(volume_type_t type, unsigned int volume, void *user_
                g_print("Volume Callback Runs :::: MEDIA VALUME %d\n", volume);
 }
 
-void muteall_change_callback(void* data)
-{
-       int  muteall;
-
-       mm_sound_get_muteall(&muteall);
-       g_print("Muteall Callback Runs :::: muteall value = %d\n", muteall);
-}
-
-void audio_route_policy_changed_callback(void* data, system_audio_route_t policy)
-{
-       int dummy = (int) data;
-       system_audio_route_t lv_policy;
-       char *str_route[SYSTEM_AUDIO_ROUTE_POLICY_MAX] = {
-                       "DEFAULT","IGN_A2DP","HANDSET"
-               };
-       g_print("Audio Route Policy has changed to [%s]\n", str_route[policy]);
-       g_print("...read....current....policy...to cross check..%d\n", dummy);
-       if(0 > mm_sound_route_get_system_policy(&lv_policy)) {
-               g_print("Can not get policy...in callback function\n");
-       }
-       else {
-               g_print("...readed policy [%s]\n", str_route[lv_policy]);
-       }
-}
-
 int main(int argc, char *argv[])
 {
        int ret = 0;
+
        stdin_channel = g_io_channel_unix_new(0);
        g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)input, NULL);
        g_loop = g_main_loop_new (NULL, 1);
 
+       MMSOUND_STRNCPY(g_file_name, POWERON_FILE, MAX_STRING_LEN);
+       g_print("\nThe input filename is '%s' \n\n",g_file_name);
+
+       /* test volume changed callback */
        g_print("callback function addr :: %p\n", volume_change_callback);
        g_volume_type = VOLUME_TYPE_MEDIA;
        ret = mm_sound_volume_get_value(g_volume_type, &g_volume_value);
        if(ret < 0) {
                g_print("mm_sound_volume_get_value 0x%x\n", ret);
        }
-
-       MMSOUND_STRNCPY(g_file_name, POWERON_FILE, MAX_STRING_LEN);
-       g_print("\nThe input filename is '%s' \n\n",g_file_name);
-
        mm_sound_add_volume_changed_callback(volume_change_callback, (void*) &g_volume_type);
-       mm_sound_muteall_add_callback(muteall_change_callback);
+
        displaymenu();
        g_main_loop_run (g_loop);