Fix double unlock of slot mutex in user stops scneario
[platform/core/multimedia/libmm-sound.git] / server / mm_sound_mgr_codec.c
index 598de46..c2c968b 100644 (file)
@@ -1,3 +1,4 @@
+
 /*
  * libmm-sound
  *
 #include <stdio.h>
 #include <string.h>
 #include <pthread.h>
+#include <unistd.h>
 
-#include <mm_source.h>
 #include <mm_error.h>
 #include <mm_types.h>
 #include <mm_debug.h>
-#include <mm_ipc.h>
 
-#include "include/mm_sound_mgr_common.h"
+#include <glib.h>
+
 #include "include/mm_sound_mgr_codec.h"
+#include "include/mm_sound_mgr_ipc.h"
 #include "include/mm_sound_plugin_codec.h"
 #include "include/mm_sound_thread_pool.h"
-#include "include/mm_sound_pa_client.h"
-#include "include/mm_sound_mgr_asm.h"
-
 
+#include "../include/mm_sound_common.h"
+#include "../include/mm_sound.h"
 
-#define _ENABLE_KEYTONE        /* Temporal test code */
+#define SHUTDOWN_TIMEOUT_SEC 60
+#define STATUS_IDLE 0
+#define STATUS_SOUND 3
+#define SOUND_SLOT_START 0
+#define MANAGER_HANDLE_MAX 256
 
 typedef struct {
        int (*callback)(int, void *, void *, int);      /* msg_type(pid) client callback & client data info */
@@ -51,626 +56,359 @@ typedef struct {
 
        int pluginid;
        int status;
-       int session_type;
-       int session_options;
-       int session_handle;
-
-       bool enable_session;
- } __mmsound_mgr_codec_handle_t;
+} __mmsound_mgr_codec_handle_t;
 
 static MMSoundPluginType *g_codec_plugins = NULL;
 static __mmsound_mgr_codec_handle_t g_slots[MANAGER_HANDLE_MAX];
 static mmsound_codec_interface_t g_plugins[MM_SOUND_SUPPORTED_CODEC_NUM];
 static pthread_mutex_t g_slot_mutex;
-static pthread_mutex_t codec_wave_mutex;
-static int _MMSoundMgrCodecStopCallback(int param);
-static int _MMSoundMgrCodecFindKeytoneSlot(int *slotid);
-static int _MMSoundMgrCodecGetEmptySlot(int *slotid);
-static int _MMSoundMgrCodecFindLocaleSlot(int *slotid);
+static GSourceFunc g_shutdown_cb;
+static guint g_timer_id = 0;
+
+#ifdef DEBUG_DETAIL
+#define SLOT_LOCK() do { \
+       debug_msg("Before Slot_mutex LOCK"); \
+       pthread_mutex_lock(&g_slot_mutex); \
+       debug_msg("After Slot_mutex LOCK"); \
+} while (0)
+#define SLOT_UNLOCK() do { \
+       debug_msg("Before Slot_mutex UNLOCK"); \
+       pthread_mutex_unlock(&g_slot_mutex); \
+       debug_msg("After Slot_mutex UNLOCK"); \
+} while (0)
+#else
+#define SLOT_LOCK() do { pthread_mutex_lock(&g_slot_mutex); } while (0)
+#define SLOT_UNLOCK() do { pthread_mutex_unlock(&g_slot_mutex); } while (0)
+#endif
+
 static int _MMSoundMgrCodecRegisterInterface(MMSoundPluginType *plugin);
+static int _MMSoundMgrCodecStopCallback(int param, bool stop_by_user);
+static gboolean _mm_sound_mgr_codec_slot_is_empty();
 
-#define STATUS_IDLE 0
-#define STATUS_KEYTONE 1
-#define STATUS_LOCALE 2
-#define STATUS_SOUND 3
+static gboolean _idle_cb(gpointer user_data)
+{
+       if (_mm_sound_mgr_codec_slot_is_empty()) {
+               debug_msg("slot is empty, ready to shutdown! %p", g_shutdown_cb);
+               if (g_shutdown_cb)
+                       g_shutdown_cb(NULL);
+       } else {
+               debug_warning("slot is not empty!!! no shutdown...");
+       }
 
-#define SOUND_SLOT_START 0
+       return FALSE;
+}
+
+static gboolean _timeout_cb(gpointer user_data)
+{
+       debug_warning("TIMEOUT : add idle callback now...");
+
+       g_idle_add(_idle_cb, NULL);
+       g_timer_id = 0;
 
+       return FALSE;
+}
 
 
-ASM_cb_result_t
-sound_codec_asm_callback(int handle, ASM_event_sources_t event_src, ASM_sound_commands_t command, unsigned int sound_status, void* cb_data)
+/* FIXME : critical section for g_timer_id? */
+static void _mm_sound_mgr_codec_shutdown_timer_start()
 {
-       int slotid = (int)cb_data;
-       int result = MM_ERROR_NONE;
-       ASM_cb_result_t cb_res = ASM_CB_RES_NONE;
-
-       debug_log("Got audio session callback msg for session_handle %d\n", handle);
-
-       switch(command)
-       {
-       case ASM_COMMAND_STOP:
-       case ASM_COMMAND_PAUSE:
-               debug_log("Got msg from asm to Stop or Pause %d\n", command);
-               result = MMSoundMgrCodecStop(slotid);
-               if (result != MM_ERROR_NONE) {
-                       debug_log("result error %d\n", result);
-               }
-               cb_res = ASM_CB_RES_STOP;
-               break;
-       case ASM_COMMAND_RESUME:
-       case ASM_COMMAND_PLAY:
-               debug_log("Got msg from asm to Play or Resume %d\n", command);
-               cb_res = ASM_CB_RES_NONE;;
-       default:
-               break;
+       if (g_timer_id > 0) {
+               debug_error("Already active timer [%d] exists", g_timer_id);
+               return;
+       }
+       if (g_shutdown_cb) {
+               g_timer_id = g_timeout_add_seconds(SHUTDOWN_TIMEOUT_SEC, _timeout_cb, NULL);
+               debug_warning("TIMER : new timer [%d]", g_timer_id);
+       } else {
+               debug_warning("No Timer started due to invalid shutdown callback");
        }
-       return cb_res;
 }
 
+static void _mm_sound_mgr_codec_shutdown_timer_stop()
+{
+       if (g_timer_id > 0) {
+               debug_warning("TIMER : remove timer id [%d]", g_timer_id);
+               g_source_remove(g_timer_id);
+               g_timer_id = 0;
+       } else {
+               debug_log("No Timer to stop...");
+       }
+}
 
-int MMSoundMgrCodecInit(const char *targetdir)
+static int _mm_sound_mgr_codec_slot_get_empty(int *slot)
 {
-       int loop = 0;
-       int count = 0;
+       int slotid = 0;
+       int err = MM_ERROR_NONE;
 
-       debug_enter("\n");
+       SLOT_LOCK();
 
-       memset (g_slots, 0, sizeof(g_slots));
+       while (1) {
+               for (slotid = SOUND_SLOT_START; slotid < MANAGER_HANDLE_MAX ; slotid++) {
+                       if (g_slots[slotid].status == STATUS_IDLE) {
+                               g_slots[slotid].status = STATUS_SOUND;
+                               break;
+                       }
+               }
 
-       if(pthread_mutex_init(&g_slot_mutex, NULL)) {
-               debug_error("pthread_mutex_init failed\n");
-               return MM_ERROR_SOUND_INTERNAL;
-       }
+               if (slotid < MANAGER_HANDLE_MAX) {
+                       debug_msg("New handle allocated (codec slot ID : [%d])", slotid);
+                       *slot = slotid;
+                       break;
+               }
 
-       if(pthread_mutex_init(&codec_wave_mutex, NULL)) {
-               debug_error("pthread_mutex_init failed\n");
-               return MM_ERROR_SOUND_INTERNAL;
+               /* FIXME: avoiding infinite wait is required */
+               debug_warning("Handle is full..wait for a while and will retry...");
+               sleep(1);
        }
 
-       for (count = 0; count < MANAGER_HANDLE_MAX; count++) {
-               g_slots[count].status = STATUS_IDLE;
-               g_slots[count].plughandle = 0;
-       }
+       _mm_sound_mgr_codec_shutdown_timer_stop();
 
-       if (g_codec_plugins) {
-               debug_warning("Please Check Init twice\n");
-               MMSoundPluginRelease(g_codec_plugins);
-       }
+       SLOT_UNLOCK();
 
-       MMSoundPluginScan(targetdir, MM_SOUND_PLUGIN_TYPE_CODEC, &g_codec_plugins);
+       return err;
+}
 
-       while (g_codec_plugins[loop].type != MM_SOUND_PLUGIN_TYPE_NONE) {
-               _MMSoundMgrCodecRegisterInterface(&g_codec_plugins[loop++]);
+static gboolean _mm_sound_mgr_codec_slot_is_empty()
+{
+       int slotid = 0;
+
+       for (slotid = SOUND_SLOT_START; slotid < MANAGER_HANDLE_MAX ; slotid++) {
+               if (g_slots[slotid].status == STATUS_SOUND)
+                       break;
        }
 
-       debug_leave("\n");
-       return MM_ERROR_NONE;
+       return (slotid == MANAGER_HANDLE_MAX) ? TRUE : FALSE;
 }
 
-int MMSoundMgrCodecFini(void)
+static void _mm_sound_mgr_codec_slot_clear(int slotid, bool dump)
 {
-       debug_enter("\n");
+       memset(&g_slots[slotid], 0, sizeof(__mmsound_mgr_codec_handle_t));
+       g_slots[slotid].status = STATUS_IDLE;
 
-       memset(g_plugins, 0, sizeof(mmsound_codec_interface_t) * MM_SOUND_SUPPORTED_CODEC_NUM);
-       MMSoundPluginRelease(g_codec_plugins);
-       g_codec_plugins = NULL;
-       pthread_mutex_destroy(&g_slot_mutex);
-       pthread_mutex_destroy(&codec_wave_mutex);
-       debug_leave("\n");
-       return MM_ERROR_NONE;
+       if (dump)
+               debug_warning("SlotID [%d] cleared", slotid);
 }
 
-
-int MMSoundMgrCodecPlay(int *slotid, const mmsound_mgr_codec_param_t *param)
+int MMSoundMgrCodecInit(const char *targetdir, GSourceFunc _shutdown_cb)
 {
-       int count = 0;
-       mmsound_codec_info_t info;
-       mmsound_codec_param_t codec_param;
-       int err = MM_ERROR_NONE;
-       int errorcode = 0;
-       int need_asm_unregister = 0;
-
-#ifdef DEBUG_DETAIL
-       debug_enter("\n");
-#endif
+       int loop = 0;
+       int slotid = 0;
 
-       for (count = 0; g_plugins[count].GetSupportTypes; count++) {
-               /* Find codec */
-               if (g_plugins[count].Parse(param->source, &info) == MM_ERROR_NONE)
-                       break;
-       }
+       debug_enter();
 
-       /*The count num means codec type WAV, MP3 */
-       debug_msg("DTMF[%d] Repeat[%d] Volume[%f] plugin_codec[%d]\n", param->tone, param->repeat_count, param->volume, count);
+       memset(g_slots, 0, sizeof(g_slots));
 
-       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;
+       if (pthread_mutex_init(&g_slot_mutex, NULL)) {
+               debug_error("pthread_mutex_init failed");
+               return MM_ERROR_SOUND_INTERNAL;
        }
 
-       /* KeyTone */
-       if (param->keytone == 1) {
-               /* Find keytone slot */
-               err = _MMSoundMgrCodecFindKeytoneSlot(slotid);
-               /* Not First connect */
-               if (err == MM_ERROR_NONE) {
-                       if(g_slots[*slotid].status != STATUS_IDLE) {
-                               MMSoundMgrCodecStop(*slotid);
-                       }
-                       debug_msg("Key tone : Stop to Play !!!\n");
-               }
-               codec_param.keytone = param->keytone;
-       } else if (param->keytone == 2) {
-               /* Find keytone slot */
-               err = _MMSoundMgrCodecFindLocaleSlot(slotid);
-               /* Not First connect */
-               if (err == MM_ERROR_NONE) {
-                       if(g_slots[*slotid].status != STATUS_IDLE) {
-                               MMSoundMgrCodecStop(*slotid);
-                       }
-                       debug_msg("Key tone : Stop to Play !!!\n");
-               }
-               codec_param.keytone = param->keytone;
-       } else {
-#ifdef DEBUG_DETAIL
-               debug_msg("Get New handle\n");
-#endif
-               codec_param.keytone = 0;
-       }
+       for (slotid = 0; slotid < MANAGER_HANDLE_MAX; slotid++)
+               _mm_sound_mgr_codec_slot_clear(slotid, false);
 
-       err = _MMSoundMgrCodecGetEmptySlot(slotid);
-       if (err != MM_ERROR_NONE) {
-               debug_error("Empty g_slot is not found\n");
-               goto cleanup;
+       if (g_codec_plugins) {
+               debug_warning("Please Check Init twice");
+               MMSoundPluginRelease(g_codec_plugins);
        }
 
-       codec_param.tone = param->tone;
-       codec_param.volume_config = param->volume_config;
-       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
-
-       /* In case of KEYTONE */
-       if (param->keytone == 1)
-               g_slots[*slotid].status = STATUS_KEYTONE;
-
-       /* In case of LOCALE */
-       if (param->keytone == 2) /* KeyTone */
-               g_slots[*slotid].status = STATUS_LOCALE;
-
-       /*
-        * Register ASM here
-        */
-       if (param->session_type != ASM_EVENT_CALL &&
-               param->session_type != ASM_EVENT_VIDEOCALL &&
-               param->session_type != ASM_EVENT_VOIP &&
-               param->session_type != ASM_EVENT_VOICE_RECOGNITION &&
-               param->priority != HANDLE_PRIORITY_SOLO &&
-               param->enable_session) {
-               if(!ASM_register_sound_ex((int)param->param, (int *)(&param->session_handle), param->session_type, ASM_STATE_NONE,
-                                                               sound_codec_asm_callback, (void*)*slotid, ASM_RESOURCE_NONE, &errorcode, __asm_process_message)) {
-                       debug_critical("ASM_register_sound_ex() failed 0x%X\n", errorcode);
-                       pthread_mutex_unlock(&g_slot_mutex);
-                       return MM_ERROR_POLICY_INTERNAL;
-               }
-               if(param->session_options) {
-                       if(!ASM_set_session_option(param->session_handle, param->session_options, &errorcode)) {
-                               debug_error("ASM_set_session_option() failed 0x%x\n", errorcode);
-                       }
-               }
-               if(!ASM_set_sound_state_ex(param->session_handle, param->session_type, ASM_STATE_PLAYING, ASM_RESOURCE_NONE, &errorcode, __asm_process_message)) {
-                       debug_critical("ASM_set_sound_state_ex() failed 0x%X\n", errorcode);
-                       pthread_mutex_unlock(&g_slot_mutex);
-                       if(!ASM_unregister_sound_ex(param->session_handle, param->session_type, &errorcode,__asm_process_message)) {
-                               debug_error("ASM_unregister_sound_ex() failed 0x%X\n", errorcode);
-                       }
-                       return MM_ERROR_POLICY_INTERNAL;
-               }
+       MMSoundPluginScan(targetdir, MM_SOUND_PLUGIN_TYPE_CODEC, &g_codec_plugins);
+       if (g_codec_plugins) {
+               while (g_codec_plugins[loop].type != MM_SOUND_PLUGIN_TYPE_NONE)
+                       _MMSoundMgrCodecRegisterInterface(&g_codec_plugins[loop++]);
        }
-       //
 
-       /* Codec id WAV or MP3 */
-       g_slots[*slotid].pluginid = count;
-       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;
-       g_slots[*slotid].session_handle = param->session_handle;
-       g_slots[*slotid].enable_session = true;
+       if (_shutdown_cb)
+               g_shutdown_cb = _shutdown_cb;
+       else
+               debug_warning("shutdown callback is NULL");
 
-       debug_msg("Using Slotid : [%d] Slot Status : [%d]\n", *slotid, g_slots[*slotid].status);
+       debug_leave();
+       return MM_ERROR_NONE;
+}
 
-       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");
-               if (param->session_handle) {
-                       need_asm_unregister = 1;
-               }
-               goto cleanup;
-       }
+int MMSoundMgrCodecFini(void)
+{
+       debug_enter();
 
-       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);
-               if (param->session_handle) {
-                       need_asm_unregister = 1;
-               }
-       }
+       memset(g_plugins, 0, sizeof(mmsound_codec_interface_t) * MM_SOUND_SUPPORTED_CODEC_NUM);
+       MMSoundPluginRelease(g_codec_plugins);
+       g_codec_plugins = NULL;
+       pthread_mutex_destroy(&g_slot_mutex);
 
-       pthread_mutex_unlock(&g_slot_mutex);
-#ifdef DEBUG_DETAIL
-       debug_msg("After Slot_mutex UNLOCK\n");
-#endif
+       debug_leave();
+       return MM_ERROR_NONE;
+}
 
-cleanup:
-       if(param->session_type != ASM_EVENT_CALL &&
-               param->session_type != ASM_EVENT_VIDEOCALL &&
-               param->session_type != ASM_EVENT_VOIP &&
-               param->session_type != ASM_EVENT_VOICE_RECOGNITION &&
-               param->enable_session &&
-               need_asm_unregister == 1) {
-               if(!ASM_set_sound_state_ex(param->session_handle, param->session_type, ASM_STATE_STOP, ASM_RESOURCE_NONE, &errorcode, __asm_process_message)) {
-                       debug_critical("ASM_set_sound_state_ex() failed 0x%X\n", errorcode);
-               }
-               if(!ASM_unregister_sound_ex(param->session_handle, param->session_type, &errorcode,__asm_process_message)) {
-                       debug_error("ASM_unregister_sound_ex() failed 0x%X\n", errorcode);
-                       return MM_ERROR_POLICY_INTERNAL;
+static int _MMSoundMgrCodecFindCodecPluginID(enum MMSoundSupportedCodec codec_to_find)
+{
+       int plugin_id = 0;
+       int *codec_type;
+
+       for (plugin_id = 0; plugin_id < MM_SOUND_SUPPORTED_CODEC_NUM; plugin_id++) {
+               if (g_plugins[plugin_id].GetSupportTypes) {
+                       codec_type = g_plugins[plugin_id].GetSupportTypes();
+                       if (codec_type[0] == codec_to_find)
+                               return plugin_id;
                }
        }
 
-#ifdef DEBUG_DETAIL
-       debug_leave("\n");
-#endif
-
-       return err;
+       return -1;
 }
 
 int MMSoundMgrCodecPlayWithStreamInfo(int *slotid, const mmsound_mgr_codec_param_t *param)
 {
-       int count = 0;
+       int plugin_id = 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");
+       debug_enter();
 #endif
-
-       for (count = 0; g_plugins[count].GetSupportTypes; count++) {
-               /* Find codec */
-               if (g_plugins[count].Parse(param->source, &info) == MM_ERROR_NONE)
-                       break;
+       plugin_id = _MMSoundMgrCodecFindCodecPluginID(MM_SOUND_SUPPORTED_CODEC_WAVE);
+       if (plugin_id == -1) {
+               debug_error("Could not find proper codec plugin!!!");
+               err = MM_ERROR_SOUND_INTERNAL;
+               goto cleanup;
        }
 
-       /*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;
+       err = g_plugins[plugin_id].Parse(param->pfilename, &info);
+       if (err != MM_ERROR_NONE) {
+               debug_error("Could not parse file [%s] by plugin[%d]", param->pfilename, plugin_id);
                goto cleanup;
        }
 
-       err = _MMSoundMgrCodecGetEmptySlot(slotid);
-       if (err != MM_ERROR_NONE) {
-               debug_error("Empty g_slot is not found\n");
+       err = _mm_sound_mgr_codec_slot_get_empty(slotid);
+       if (err != MM_ERROR_NONE || *slotid < 0) {
+               debug_error("Empty g_slot is not found");
                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.pfilename = param->pfilename;
        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
+       MMSOUND_STRNCPY(codec_param.stream_type, param->stream_type, MAX_STREAM_TYPE_LEN);
+       SLOT_LOCK();
 
        /* Codec id WAV or MP3 */
-       g_slots[*slotid].pluginid = count;
+       g_slots[*slotid].pluginid = plugin_id;
        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);
+       debug_msg("Using Slotid : [%d] Slot Status : [%d]", *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);
+       debug_msg("Created audio handle : [%p]", g_slots[*slotid].plughandle);
        if (err != MM_ERROR_NONE) {
-               debug_error("Plugin create fail : 0x%08X\n", err);
+               debug_error("Plugin create fail : 0x%08X", err);
                g_slots[*slotid].status = STATUS_IDLE;
-               pthread_mutex_unlock(&g_slot_mutex);
-               debug_warning("After Slot_mutex UNLOCK\n");
+               SLOT_UNLOCK();
                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);
+               debug_error("Fail to play : 0x%08X", 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
+       SLOT_UNLOCK();
 
 cleanup:
+       if (_mm_sound_mgr_codec_slot_is_empty())
+               _mm_sound_mgr_codec_shutdown_timer_start();
 
 #ifdef DEBUG_DETAIL
-       debug_leave("\n");
+       debug_leave();
 #endif
 
        return err;
 
 }
 
-#define DTMF_PLUGIN_COUNT 2
-int MMSoundMgrCodecPlayDtmf(int *slotid, const mmsound_mgr_codec_param_t *param)
+int MMSoundMgrCodecPlayDtmfWithStreamInfo(int *slotid, const mmsound_mgr_codec_param_t *param)
 {
-       int count = 0;
-       int *codec_type;
+       int plugin_id = 0;
        mmsound_codec_info_t info;
        mmsound_codec_param_t codec_param;
        int err = MM_ERROR_NONE;
-       int errorcode = 0;
-       int need_asm_unregister = 0;
 
 #ifdef DEBUG_DETAIL
-       debug_enter("\n");
+       debug_enter();
 #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;
+       plugin_id = _MMSoundMgrCodecFindCodecPluginID(MM_SOUND_SUPPORTED_CODEC_DTMF);
+       if (plugin_id == -1) {
+               debug_error("Could not find proper codec plugin!!!");
+               err = MM_ERROR_SOUND_INTERNAL;
+               goto cleanup;
        }
 
        /*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);
+       debug_msg("DTMF[%d] Repeat[%d] Volume[%f] plugin_codec[%d]", param->tone, param->repeat_count, param->volume, plugin_id);
 
-       if (g_plugins[count].GetSupportTypes == NULL) { /* Codec not found */
-               debug_error("unsupported file type %d\n", count);
-               printf("unsupported file type %d\n", count);
+       if (g_plugins[plugin_id].GetSupportTypes == NULL) { /* Codec not found */
+               debug_error("unsupported file type %d", plugin_id);
+               printf("unsupported file type %d", plugin_id);
                err = MM_ERROR_SOUND_UNSUPPORTED_MEDIA_TYPE;
                goto cleanup;
        }
 
 #ifdef DEBUG_DETAIL
-       debug_msg("Get New handle\n");
+       debug_msg("Get New handle");
 #endif
-       codec_param.keytone = 0;
 
-       err = _MMSoundMgrCodecGetEmptySlot(slotid);
-       if(err != MM_ERROR_NONE)
-       {
-               debug_error("Empty g_slot is not found\n");
+       err = _mm_sound_mgr_codec_slot_get_empty(slotid);
+       if (err != MM_ERROR_NONE || *slotid < 0) {
+               debug_error("Empty g_slot is not found");
                goto cleanup;
        }
 
        codec_param.tone = param->tone;
-       codec_param.priority = 0;
-       codec_param.volume_config = param->volume_config;
        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
+       MMSOUND_STRNCPY(codec_param.stream_type, param->stream_type, MAX_STREAM_TYPE_LEN);
+       SLOT_LOCK();
 
-       //
-       /*
-        * Register ASM here
-        */
-
-       if (param->session_type != ASM_EVENT_CALL &&
-               param->session_type != ASM_EVENT_VIDEOCALL &&
-               param->session_type != ASM_EVENT_VOIP &&
-               param->session_type != ASM_EVENT_VOICE_RECOGNITION &&
-               param->enable_session)  {
-               if(!ASM_register_sound_ex((int)param->param, (int *)(&param->session_handle), param->session_type, ASM_STATE_NONE,
-                                                               sound_codec_asm_callback, (void*)*slotid, ASM_RESOURCE_NONE, &errorcode, __asm_process_message)) {
-                       debug_critical("ASM_register_sound_ex() failed 0x%X\n", errorcode);
-                       pthread_mutex_unlock(&g_slot_mutex);
-                       return MM_ERROR_POLICY_INTERNAL;
-               }
-               if(param->session_options) {
-                       if(!ASM_set_session_option(param->session_handle, param->session_options, &errorcode)) {
-                               debug_error("ASM_set_session_option() failed 0x%x\n", errorcode);
-                       }
-               }
-               if(!ASM_set_sound_state_ex(param->session_handle, param->session_type, ASM_STATE_PLAYING, ASM_RESOURCE_NONE, &errorcode, __asm_process_message)) {
-                       debug_critical("ASM_set_sound_state_ex() failed 0x%X\n", errorcode);
-                       pthread_mutex_unlock(&g_slot_mutex);
-                       if(!ASM_unregister_sound_ex(param->session_handle, param->session_type, &errorcode,__asm_process_message)) {
-                               debug_error("ASM_unregister_sound_ex() failed 0x%X\n", errorcode);
-                       }
-                       return MM_ERROR_POLICY_INTERNAL;
-               }
-       }
-
-       g_slots[*slotid].pluginid = count;
-       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;
-       g_slots[*slotid].session_handle = param->session_handle;
-       g_slots[*slotid].enable_session = param->enable_session;
+       g_slots[*slotid].pluginid = plugin_id;
+       g_slots[*slotid].param    = param->param;               /* This arg is used callback data */
 
 #ifdef DEBUG_DETAIL
-       debug_msg("Using Slotid : [%d] Slot Status : [%d]\n", *slotid, g_slots[*slotid].status);
+       debug_msg("Using Slotid : [%d] Slot Status : [%d]", *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);
+       debug_msg("Created audio handle : [%p]", g_slots[*slotid].plughandle);
        if (err != MM_ERROR_NONE) {
-               debug_error("Plugin create fail : 0x%08X\n", err);
+               debug_error("Plugin create fail : 0x%08X", err);
                g_slots[*slotid].status = STATUS_IDLE;
-               pthread_mutex_unlock(&g_slot_mutex);
-               debug_warning("After Slot_mutex UNLOCK\n");
-               need_asm_unregister = 1;
+               SLOT_UNLOCK();
                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);
+               debug_error("Fail to play : 0x%08X", err);
                g_plugins[g_slots[*slotid].pluginid].Destroy(g_slots[*slotid].plughandle);
-               need_asm_unregister = 1;
        }
 
-       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
+       SLOT_UNLOCK();
+       debug_msg("Using Slotid : [%d] Slot Status : [%d]", *slotid, g_slots[*slotid].status);
 
 cleanup:
-       if (param->session_type != ASM_EVENT_CALL &&
-               param->session_type != ASM_EVENT_VIDEOCALL &&
-               param->session_type != ASM_EVENT_VOIP &&
-               param->session_type != ASM_EVENT_VOICE_RECOGNITION &&
-               param->enable_session &&
-               need_asm_unregister == 1) {
-               if(!ASM_unregister_sound_ex(param->session_handle, param->session_type, &errorcode,__asm_process_message)) {
-                       debug_error("Unregister sound failed 0x%X\n", errorcode);
-                       return MM_ERROR_POLICY_INTERNAL;
-               }
-       }
-
 #ifdef DEBUG_DETAIL
-       debug_leave("\n");
+       debug_leave();
 #endif
 
        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;
 
 }
 
@@ -678,256 +416,110 @@ int MMSoundMgrCodecStop(const int slotid)
 {
        int err = MM_ERROR_NONE;
 
-       debug_enter("(Slotid : [%d])\n", slotid);
+       debug_enter("(Slotid : [%d])", slotid);
 
-       if (slotid < 0 || MANAGER_HANDLE_MAX <= slotid) {
+       if (slotid < 0 || MANAGER_HANDLE_MAX <= slotid)
                return MM_ERROR_INVALID_ARGUMENT;
-       }
 
-       pthread_mutex_lock (&g_slot_mutex);
-#ifdef DEBUG_DETAIL
-       debug_msg("After Slot_mutex LOCK\n");
-#endif
+       SLOT_LOCK();
        if (g_slots[slotid].status == STATUS_IDLE) {
                err = MM_ERROR_SOUND_INVALID_STATE;
-               debug_warning("The playing slots is not found, Slot ID : [%d]\n", slotid);
+               debug_warning("The playing slots is not found, Slot ID : [%d]", slotid);
                goto cleanup;
        }
 #ifdef DEBUG_DETAIL
-       debug_msg("Found slot, Slotid [%d] State [%d]\n", slotid, g_slots[slotid].status);
+       debug_msg("Found slot, Slotid [%d] State [%d]", slotid, g_slots[slotid].status);
 #endif
 
        err = g_plugins[g_slots[slotid].pluginid].Stop(g_slots[slotid].plughandle);
-       if (err != MM_ERROR_NONE) {
-               debug_error("Fail to STOP Code : 0x%08X\n", err);
-       }
-       debug_msg("Found slot, Slotid [%d] State [%d]\n", slotid, g_slots[slotid].status);
+       if (err != MM_ERROR_NONE)
+               debug_error("Fail to STOP Code : 0x%08X", err);
+
 cleanup:
-       pthread_mutex_unlock(&g_slot_mutex);
-#ifdef DEBUG_DETAIL
-       debug_msg("After Slot_mutex UNLOCK\n");
-#endif
-       debug_leave("(err : 0x%08X)\n", err);
+       SLOT_UNLOCK();
+       debug_leave("(err : 0x%08X)", err);
 
        return err;
 }
 
-static int _MMSoundMgrCodecStopCallback(int param)
+static int _MMSoundMgrCodecStopCallback(int param, bool stop_by_user)
 {
        int err = MM_ERROR_NONE;
 
-       debug_enter("(Slot : %d)\n", param);
-
-       pthread_mutex_lock(&g_slot_mutex);
-       debug_msg("[CODEC MGR] Slot_mutex lock done\n");
-
-
-       /*
-        * Unregister ASM here
-        */
-
-       int errorcode = 0;
-       debug_msg("[CODEC MGR] enable_session %d ",g_slots[param].enable_session);
-
-       if (g_slots[param].session_handle) {
-               if(g_slots[param].session_type != ASM_EVENT_CALL &&
-                       g_slots[param].session_type != ASM_EVENT_VIDEOCALL &&
-                       g_slots[param].session_type != ASM_EVENT_VOIP &&
-                       g_slots[param].session_type != ASM_EVENT_VOICE_RECOGNITION &&
-                       g_slots[param].enable_session ) {
-                       if(!ASM_set_sound_state_ex(g_slots[param].session_handle, g_slots[param].session_type, ASM_STATE_STOP, ASM_RESOURCE_NONE, &errorcode, __asm_process_message)) {
-                               debug_error("[CODEC MGR] ASM_set_sound_state_ex() failed 0x%X\n", errorcode);
-                       }
-                       debug_msg("[CODEC MGR] ASM unregister\n");
-                       if(!ASM_unregister_sound_ex(g_slots[param].session_handle, g_slots[param].session_type, &errorcode, __asm_process_message)) {
-                               debug_error("[CODEC MGR] ASM_unregister_sound_ex() failed 0x%X\n", errorcode);
-                       }
-               }
-       }
-
-       __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);
-       if (err < 0 ) {
-               debug_critical("[CODEC MGR] Fail to destroy slot number : [%d] err [0x%x]\n", param, err);
+       if (param < 0 || param >= MANAGER_HANDLE_MAX) {
+               debug_error("Slot(%d) is invalid", param);
+               return MM_ERROR_INVALID_ARGUMENT;
        }
-       memset(&g_slots[param], 0, sizeof(__mmsound_mgr_codec_handle_t));
-       g_slots[param].status = STATUS_IDLE;
-       pthread_mutex_unlock(&g_slot_mutex);
-       debug_msg("[CODEC MGR] Slot_mutex done\n");
-
-       return err;
-}
-
-static int _MMSoundMgrCodecFindKeytoneSlot(int *slotid)
-{
-       int count = 0;
-       int err = MM_ERROR_NONE;
-
-#ifdef DEBUG_DETAIL
-       debug_enter("\n");
-#endif
 
-       pthread_mutex_lock(&g_slot_mutex);
-#ifdef DEBUG_DETAIL
-       debug_warning("After Slot_mutex LOCK\n");
-#endif
+       debug_enter("Slot(%d) : stop-by-user(%d)", param, stop_by_user);
 
-       for (count = SOUND_SLOT_START; count < MANAGER_HANDLE_MAX ; count++) {
-               if (g_slots[count].status == STATUS_KEYTONE) {
-                       break;
-               }
-       }
-       pthread_mutex_unlock(&g_slot_mutex);
-#ifdef DEBUG_DETAIL
-       debug_warning("After Slot_mutex UNLOCK\n");
-#endif
-       if (count < MANAGER_HANDLE_MAX) {
-               debug_msg("Found keytone handle allocated (Slot : [%d])\n", count);
-               *slotid = count;
-               err =  MM_ERROR_NONE;
-       } else {
-               debug_warning("Handle is full handle [KEY TONE] : [%d]\n", count);
-               err =  MM_ERROR_SOUND_INTERNAL;
+       if (!stop_by_user) {
+               SLOT_LOCK();
+               __mm_sound_mgr_ipc_notify_play_file_end(param);
+               debug_msg("Client callback msg_type (instance) : [%d]", (int)g_slots[param].param);
        }
 
-#ifdef DEBUG_DETAIL
-       debug_leave("\n");
-#endif
-
-       return err;
-}
-
-static int _MMSoundMgrCodecFindLocaleSlot(int *slotid)
-{
-       int count = 0;
-       int err = MM_ERROR_NONE;
-
-#ifdef DEBUG_DETAIL
-       debug_enter("\n");
-#endif
+       debug_msg("Handle allocated handle : [%p]", g_slots[param].plughandle);
+       err = g_plugins[g_slots[param].pluginid].Destroy(g_slots[param].plughandle);
+       if (err < 0)
+               debug_critical("Slot(%d) : Fail to destroy slot, err [0x%x]", param, err);
 
-       pthread_mutex_lock(&g_slot_mutex);
-#ifdef DEBUG_DETAIL
-       debug_warning("After Slot_mutex LOCK\n");
-#endif
+       _mm_sound_mgr_codec_slot_clear(param, true);
+       if (_mm_sound_mgr_codec_slot_is_empty())
+               _mm_sound_mgr_codec_shutdown_timer_start();
 
-       for (count = SOUND_SLOT_START; count < MANAGER_HANDLE_MAX ; count++) {
-               if (g_slots[count].status == STATUS_LOCALE) {
-                       break;
-               }
-       }
-       pthread_mutex_unlock(&g_slot_mutex);
+       if (!stop_by_user)
+               SLOT_UNLOCK();
 
-#ifdef DEBUG_DETAIL
-       debug_warning("After Slot_mutex UNLOCK\n");
-#endif
-       if (count < MANAGER_HANDLE_MAX) {
-               debug_msg("Found locale handle allocated (Slot : [%d])\n", count);
-               *slotid = count;
-               err =  MM_ERROR_NONE;
-       } else {
-               debug_warning("Handle is full handle [KEY TONE] \n");
-               err =  MM_ERROR_SOUND_INTERNAL;
-       }
-
-#ifdef DEBUG_DETAIL
-       debug_leave("\n");
-#endif
+       debug_fleave();
 
        return err;
 }
 
-static int _MMSoundMgrCodecGetEmptySlot(int *slot)
-{
-       int count = 0;
-       int err = MM_ERROR_NONE;
 
-#ifdef DEBUG_DETAIL
-       debug_enter("\n");
-#endif
-       debug_msg("Codec slot ID : [%d]\n", *slot);
-       pthread_mutex_lock(&g_slot_mutex);
-#ifdef DEBUG_DETAIL
-       debug_msg("After Slot_mutex LOCK\n");
-#endif
-
-       for (count = SOUND_SLOT_START; count < MANAGER_HANDLE_MAX ; count++) {
-               if (g_slots[count].status == STATUS_IDLE) {
-                       g_slots[count].status = STATUS_SOUND;
-                       break;
-               }
-       }
-       pthread_mutex_unlock(&g_slot_mutex);
-#ifdef DEBUG_DETAIL
-       debug_msg("After Slot_mutex UNLOCK\n");
-#endif
-
-       if (count < MANAGER_HANDLE_MAX) {
-               debug_msg("New handle allocated (codec slot ID : [%d])\n", count);
-               *slot = count;
-               err =  MM_ERROR_NONE;
-       } else {
-               debug_warning("Handle is full handle : [%d]\n", count);
-               *slot = -1;
-               /* Temporal code for reset */
-               while(count--) {
-                       g_slots[count].status = STATUS_IDLE;
-               }
-               err =  MM_ERROR_SOUND_INTERNAL;
-       }
-
-#ifdef DEBUG_DETAIL
-       debug_leave("\n");
-#endif
-
-       return err;
-}
 
 static int _MMSoundMgrCodecRegisterInterface(MMSoundPluginType *plugin)
 {
        int err = MM_ERROR_NONE;
-       int count = 0;
+       int plugin_id = 0;
        void *getinterface = NULL;
 
 #ifdef DEBUG_DETAIL
-       debug_enter("\n");
+       debug_enter();
 #endif
 
        /* find emptry slot */
-       for (count = 0; count < MM_SOUND_SUPPORTED_CODEC_NUM; count++) {
-               if (g_plugins[count].GetSupportTypes == NULL)
+       for (plugin_id = 0; plugin_id < MM_SOUND_SUPPORTED_CODEC_NUM; plugin_id++) {
+               if (g_plugins[plugin_id].GetSupportTypes == NULL)
                        break;
        }
 
-       if (count == MM_SOUND_SUPPORTED_CODEC_NUM) {
-               debug_critical("The plugin support type is not valid\n");
+       if (plugin_id == MM_SOUND_SUPPORTED_CODEC_NUM) {
+               debug_critical("The plugin support type is not valid");
                return MM_ERROR_COMMON_OUT_OF_RANGE;
        }
 
        err = MMSoundPluginGetSymbol(plugin, CODEC_GET_INTERFACE_FUNC_NAME, &getinterface);
        if (err != MM_ERROR_NONE) {
-               debug_error("Get Symbol CODEC_GET_INTERFACE_FUNC_NAME is fail : %x\n", err);
+               debug_error("Get Symbol CODEC_GET_INTERFACE_FUNC_NAME is fail : %x", err);
                goto cleanup;
        }
-       debug_msg("interface[%p] empty_slot[%d]\n", getinterface, count);
+       debug_msg("interface[%p] empty_slot[%d]", getinterface, plugin_id);
 
-       err = MMSoundPlugCodecCastGetInterface(getinterface)(&g_plugins[count]);
+       err = MMSoundPlugCodecCastGetInterface(getinterface)(&g_plugins[plugin_id]);
        if (err != MM_ERROR_NONE) {
-               debug_error("Get interface fail : %x\n", err);
+               debug_error("Get interface fail : %x", err);
 
 cleanup:
                /* If error occur, clean interface */
-               memset(&g_plugins[count], 0, sizeof(mmsound_codec_interface_t));
+               memset(&g_plugins[plugin_id], 0, sizeof(mmsound_codec_interface_t));
        } else {
-               if (g_plugins[count].SetThreadPool)
-                       g_plugins[count].SetThreadPool(MMSoundThreadPoolRun);
+               if (g_plugins[plugin_id].SetThreadPool)
+                       g_plugins[plugin_id].SetThreadPool(MMSoundThreadPoolRun);
        }
 
 #ifdef DEBUG_DETAIL
-       debug_leave("\n");
+       debug_leave();
 #endif
 
        return err;