Add sub thread for audio stream callback 62/88062/5
authorJeongmo Yang <jm80.yang@samsung.com>
Tue, 13 Sep 2016 06:39:55 +0000 (15:39 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Thu, 29 Sep 2016 08:32:20 +0000 (17:32 +0900)
[Version] 0.2.37
[Profile] Common
[Issue Type] Enhancement
[Dependency module] N/A
[Dependency commit] N/A
[Test] [M(T) - Boot=(OK), sdb=(OK), Home=(OK), Touch=(OK), Version=tizen-mobile_20160913.1]

Change-Id: I56243fbcfa660c410218a38220f436a597c2b390
Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
include/recorder.h
include/recorder_private.h
packaging/capi-media-recorder.spec
src/recorder.c

index 8fbd344..682a2ee 100644 (file)
@@ -804,8 +804,8 @@ int recorder_foreach_supported_audio_encoder(recorder_h recorder, recorder_suppo
  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @remarks This function should be called before recording (recorder_start()).
  * @param[in] recorder The handle to the media recorder
- * @param[in] width    The preview width
- * @param[in] height   The preview height
+ * @param[in] width    The video width
+ * @param[in] height   The video height
  * @return @c 0 on success, otherwise a negative error value
  * @retval #RECORDER_ERROR_NONE Successful
  * @retval #RECORDER_ERROR_INVALID_PARAMETER Invalid parameter
index b42b831..76608dc 100644 (file)
@@ -60,27 +60,51 @@ enum {
        _RECORDER_GET_DOUBLE_MAX
 };
 
+enum {
+       _RECORDER_MESSAGE_HANDLER_TYPE_GENERAL,
+       _RECORDER_MESSAGE_HANDLER_TYPE_AUDIO_STREAM_CB
+};
+
+typedef struct _recorder_msg_handler_info_s {
+       int type;
+       void *cb_info;
+       int running;
+       GCond cond;
+       GMutex mutex;
+       GQueue *queue;
+       GThread *thread;
+} recorder_msg_handler_info_s;
+
 typedef struct _recorder_cb_info_s {
+       /* server connection */
        gint fd;
        gboolean is_server_connected;
 
+       /* message receive thread */
        GThread *msg_recv_thread;
-       GThread *msg_handler_thread;
        gint msg_recv_running;
-       gint msg_handler_running;
-       GCond msg_handler_cond;
-       GMutex msg_handler_mutex;
-       GQueue *msg_queue;
+       gchar recv_msg[RECORDER_MSG_LENGTH_MAX];
+       GCond api_cond[MUSE_RECORDER_API_MAX];
+       GMutex api_mutex[MUSE_RECORDER_API_MAX];
+       gint api_activating[MUSE_RECORDER_API_MAX];
+       gint api_ret[MUSE_RECORDER_API_MAX];
+
+       /* general message handler info */
+       recorder_msg_handler_info_s msg_handler_info;
+
+       /* preview cb message handler info */
+       recorder_msg_handler_info_s audio_stream_cb_info;
+
+       /* idle event */
        GList *idle_event_list;
        GCond idle_event_cond;
        GMutex idle_event_mutex;
+
+       /* user callback */
        gpointer user_cb[MUSE_RECORDER_EVENT_TYPE_NUM];
        gpointer user_data[MUSE_RECORDER_EVENT_TYPE_NUM];
-       gchar recv_msg[RECORDER_MSG_LENGTH_MAX];
-       GCond api_cond[MUSE_RECORDER_API_MAX];
-       GMutex api_mutex[MUSE_RECORDER_API_MAX];
-       gint *api_activating;
-       gint *api_ret;
+
+       /* tbm */
        tbm_bufmgr bufmgr;
 
        /* get values */
@@ -92,6 +116,8 @@ typedef struct _recorder_cb_info_s {
 typedef struct _recorder_message_s {
        gchar recv_msg[MUSE_RECORDER_MSG_MAX_LENGTH];
        muse_recorder_api_e api;
+       muse_recorder_event_e event;
+       muse_recorder_event_class_e event_class;
 } recorder_message_s;
 
 typedef struct _recorder_idle_event_s {
index a87bc07..692bb3e 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-recorder
 Summary:    A Recorder API
-Version:    0.2.36
+Version:    0.2.37
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index b545e8e..a5e453a 100644 (file)
@@ -411,47 +411,95 @@ static void _recorder_remove_idle_event_all(recorder_cb_info_s *cb_info)
 }
 
 
+static void __recorder_add_msg_to_queue(recorder_cb_info_s *cb_info, int api, int event, int event_class, char *msg)
+{
+       recorder_message_s *rec_msg = NULL;
+
+       if (!cb_info || !msg) {
+               LOGE("NULL pointer %p %p", cb_info, msg);
+               return;
+       }
+
+       rec_msg = g_new0(recorder_message_s, 1);
+       if (!rec_msg) {
+               LOGE("failed to alloc rec_msg for [%s]", msg);
+               return;
+       }
+
+       rec_msg->api = api;
+       rec_msg->event = event;
+       rec_msg->event_class = event_class;
+
+       strncpy(rec_msg->recv_msg, msg, sizeof(rec_msg->recv_msg) - 1);
+
+       /*LOGD("add recorder message to queue : api %d, event %d, event_class %d", api, event, event_class);*/
+
+       if (event == MUSE_RECORDER_EVENT_TYPE_AUDIO_STREAM) {
+               g_mutex_lock(&cb_info->audio_stream_cb_info.mutex);
+               g_queue_push_tail(cb_info->audio_stream_cb_info.queue, (gpointer)rec_msg);
+               g_cond_signal(&cb_info->audio_stream_cb_info.cond);
+               g_mutex_unlock(&cb_info->audio_stream_cb_info.mutex);
+       } else {
+               g_mutex_lock(&cb_info->msg_handler_info.mutex);
+               g_queue_push_tail(cb_info->msg_handler_info.queue, (gpointer)rec_msg);
+               g_cond_signal(&cb_info->msg_handler_info.cond);
+               g_mutex_unlock(&cb_info->msg_handler_info.mutex);
+       }
+
+       rec_msg = NULL;
+
+       return;
+}
+
+
 static void *_recorder_msg_handler_func(gpointer data)
 {
-       int ret = 0;
        int api = 0;
-       int event = 0;
-       int event_class = 0;
+       int type = 0;
        recorder_message_s *rec_msg = NULL;
        recorder_idle_event_s *rec_idle_event = NULL;
-       recorder_cb_info_s *cb_info = (recorder_cb_info_s *)data;
+       recorder_msg_handler_info_s *handler_info = (recorder_msg_handler_info_s *)data;
+       recorder_cb_info_s *cb_info = NULL;
 
-       if (cb_info == NULL) {
-               LOGE("cb_info NULL");
+       if (!handler_info || !handler_info->cb_info) {
+               LOGE("NULL handler %p", handler_info);
                return NULL;
        }
 
-       LOGD("start");
+       cb_info = (recorder_cb_info_s *)handler_info->cb_info;
+       type = handler_info->type;
 
-       g_mutex_lock(&cb_info->msg_handler_mutex);
+       LOGD("t:%d start", type);
 
-       while (g_atomic_int_get(&cb_info->msg_handler_running)) {
-               if (g_queue_is_empty(cb_info->msg_queue)) {
+       g_mutex_lock(&handler_info->mutex);
+
+       while (g_atomic_int_get(&handler_info->running)) {
+               if (g_queue_is_empty(handler_info->queue)) {
                        /*LOGD("signal wait...");*/
-                       g_cond_wait(&cb_info->msg_handler_cond, &cb_info->msg_handler_mutex);
+                       g_cond_wait(&handler_info->cond, &handler_info->mutex);
                        /*LOGD("signal received");*/
 
-                       if (g_atomic_int_get(&cb_info->msg_handler_running) == 0) {
+                       if (g_atomic_int_get(&handler_info->running) == 0) {
                                LOGD("stop event thread");
                                break;
                        }
                }
 
-               rec_msg = (recorder_message_s *)g_queue_pop_head(cb_info->msg_queue);
-               g_mutex_unlock(&cb_info->msg_handler_mutex);
+               rec_msg = (recorder_message_s *)g_queue_pop_head(handler_info->queue);
+               g_mutex_unlock(&handler_info->mutex);
                if (rec_msg == NULL) {
                        LOGE("NULL message");
-                       g_mutex_lock(&cb_info->msg_handler_mutex);
+                       g_mutex_lock(&handler_info->mutex);
                        continue;
                }
+
                api = rec_msg->api;
+
                if (api < MUSE_RECORDER_API_MAX) {
+                       int ret = 0;
+
                        g_mutex_lock(&cb_info->api_mutex[api]);
+
                        if (muse_recorder_msg_get(ret, rec_msg->recv_msg)) {
                                cb_info->api_ret[api] = ret;
                                cb_info->api_activating[api] = 1;
@@ -460,28 +508,14 @@ static void *_recorder_msg_handler_func(gpointer data)
 
                                g_cond_signal(&cb_info->api_cond[api]);
                        } else {
-                               LOGE("failed to get ret for api %d, msg %s", rec_msg->api, rec_msg->recv_msg);
+                               LOGE("t:%d failed to get ret for api %d, msg %s", type, api, rec_msg->recv_msg);
                        }
 
                        g_mutex_unlock(&cb_info->api_mutex[api]);
                } else if (api == MUSE_RECORDER_CB_EVENT) {
-                       event = -1;
-                       event_class = -1;
-
-                       if (!muse_recorder_msg_get(event, rec_msg->recv_msg) ||
-                           !muse_recorder_msg_get(event_class, rec_msg->recv_msg)) {
-                               LOGE("get failed : event %d, class %d", event, event_class);
-
-                               g_free(rec_msg);
-                               rec_msg = NULL;
-
-                               g_mutex_lock(&cb_info->msg_handler_mutex);
-                               continue;
-                       }
-
-                       switch (event_class) {
+                       switch (rec_msg->event_class) {
                        case MUSE_RECORDER_EVENT_CLASS_THREAD_SUB:
-                               _recorder_client_user_callback(cb_info, rec_msg->recv_msg, event);
+                               _recorder_client_user_callback(cb_info, rec_msg->recv_msg, rec_msg->event);
                                break;
                        case MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN:
                                rec_idle_event = g_new0(recorder_idle_event_s, 1);
@@ -490,12 +524,12 @@ static void *_recorder_msg_handler_func(gpointer data)
                                        break;
                                }
 
-                               rec_idle_event->event = event;
+                               rec_idle_event->event = rec_msg->event;
                                rec_idle_event->cb_info = cb_info;
                                g_mutex_init(&rec_idle_event->event_mutex);
-                               memcpy(rec_idle_event->recv_msg, rec_msg->recv_msg, sizeof(rec_idle_event->recv_msg));
+                               strncpy(rec_idle_event->recv_msg, rec_msg->recv_msg, sizeof(rec_idle_event->recv_msg) - 1);
 
-                               /*LOGD("add recorder event[%d, %p] to IDLE", event, rec_idle_event);*/
+                               /*LOGD("add recorder event[%d, %p] to IDLE", rec_msg->event, rec_idle_event);*/
 
                                g_mutex_lock(&cb_info->idle_event_mutex);
                                cb_info->idle_event_list = g_list_append(cb_info->idle_event_list, (gpointer)rec_idle_event);
@@ -507,7 +541,7 @@ static void *_recorder_msg_handler_func(gpointer data)
                                        NULL);
                                break;
                        default:
-                               LOGE("unknown event class %d", event_class);
+                               LOGE("unknown event class %d", rec_msg->event_class);
                                break;
                        }
                } else {
@@ -517,12 +551,12 @@ static void *_recorder_msg_handler_func(gpointer data)
                g_free(rec_msg);
                rec_msg = NULL;
 
-               g_mutex_lock(&cb_info->msg_handler_mutex);
+               g_mutex_lock(&handler_info->mutex);
        }
 
        /* remove remained event */
-       while (!g_queue_is_empty(cb_info->msg_queue)) {
-               rec_msg = (recorder_message_s *)g_queue_pop_head(cb_info->msg_queue);
+       while (!g_queue_is_empty(handler_info->queue)) {
+               rec_msg = (recorder_message_s *)g_queue_pop_head(handler_info->queue);
                if (rec_msg) {
                        LOGD("remove message %p", rec_msg);
                        free(rec_msg);
@@ -532,7 +566,7 @@ static void *_recorder_msg_handler_func(gpointer data)
                }
        }
 
-       g_mutex_unlock(&cb_info->msg_handler_mutex);
+       g_mutex_unlock(&handler_info->mutex);
 
        LOGD("return");
 
@@ -681,6 +715,8 @@ static void *_recorder_msg_recv_func(gpointer data)
        int ret = 0;
        int api = 0;
        int api_class = 0;
+       int event = 0;
+       int event_class = 0;
        int num_token = 0;
        int str_pos = 0;
        int prev_pos = 0;
@@ -688,7 +724,6 @@ static void *_recorder_msg_recv_func(gpointer data)
        char *error_msg = NULL;
        char **parse_str = NULL;
        recorder_cb_info_s *cb_info = (recorder_cb_info_s *)data;
-       recorder_message_s *rec_msg = NULL;
 
        if (cb_info == NULL) {
                LOGE("cb_info NULL");
@@ -757,9 +792,15 @@ static void *_recorder_msg_recv_func(gpointer data)
                                continue;
                        }
 
-                       if (api != MUSE_RECORDER_CB_EVENT) {
+                       if (api == MUSE_RECORDER_CB_EVENT) {
+                               if (!muse_recorder_msg_get(event, parse_str[i]) ||
+                                       !muse_recorder_msg_get(event_class, parse_str[i])) {
+                                       LOGE("failed to get event or event_class [%s]", parse_str[i]);
+                                       continue;
+                               }
+                       } else {
                                if (!muse_recorder_msg_get(api_class, parse_str[i])) {
-                                       LOGE("failed to get recorder api_class");
+                                       LOGE("failed to get api_class [%s]", parse_str[i]);
                                        continue;
                                }
                        }
@@ -801,25 +842,8 @@ static void *_recorder_msg_recv_func(gpointer data)
 
                                g_cond_signal(&cb_info->api_cond[api]);
                                g_mutex_unlock(&cb_info->api_mutex[api]);
-                       } else if (api_class == MUSE_RECORDER_API_CLASS_THREAD_SUB ||
-                                       api == MUSE_RECORDER_CB_EVENT) {
-                               rec_msg = g_new0(recorder_message_s, 1);
-                               if (rec_msg == NULL) {
-                                       LOGE("failed to alloc rec_msg");
-                                       continue;
-                               }
-
-                               rec_msg->api = api;
-                               memcpy(rec_msg->recv_msg, parse_str[i], sizeof(rec_msg->recv_msg));
-
-                               /*LOGD("add recorder message to queue : api %d", api);*/
-
-                               g_mutex_lock(&cb_info->msg_handler_mutex);
-                               g_queue_push_tail(cb_info->msg_queue, (gpointer)rec_msg);
-                               g_cond_signal(&cb_info->msg_handler_cond);
-                               g_mutex_unlock(&cb_info->msg_handler_mutex);
-
-                               rec_msg = NULL;
+                       } else if (api_class == MUSE_RECORDER_API_CLASS_THREAD_SUB || api == MUSE_RECORDER_CB_EVENT) {
+                               __recorder_add_msg_to_queue(cb_info, api, event, event_class, parse_str[i]);
                        } else {
                                LOGW("unknown recorder api %d and api_class %d", api, api_class);
                        }
@@ -831,8 +855,6 @@ static void *_recorder_msg_recv_func(gpointer data)
        if (!cb_info->is_server_connected) {
                /* send error msg for server disconnection */
                error_msg = muse_core_msg_json_factory_new(MUSE_RECORDER_CB_EVENT,
-                       MUSE_TYPE_INT, PARAM_EVENT, MUSE_RECORDER_EVENT_TYPE_ERROR,
-                       MUSE_TYPE_INT, PARAM_EVENT_CLASS, MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN,
                        MUSE_TYPE_INT, "error", RECORDER_ERROR_SERVICE_DISCONNECTED,
                        MUSE_TYPE_INT, "current_state", RECORDER_STATE_NONE,
                        NULL);
@@ -841,33 +863,21 @@ static void *_recorder_msg_recv_func(gpointer data)
                        goto CB_HANDLER_EXIT;
                }
 
-               rec_msg = g_new0(recorder_message_s, 1);
-               if (rec_msg == NULL) {
-                       LOGE("failed to alloc rec_msg");
-                       goto CB_HANDLER_EXIT;
-               }
-
-               rec_msg->api = MUSE_RECORDER_CB_EVENT;
-               memcpy(rec_msg->recv_msg, error_msg, sizeof(rec_msg->recv_msg));
-
-               /*LOGD("add recorder message to queue : api %d", api);*/
+               LOGE("add error msg for service disconnection done");
 
-               g_mutex_lock(&cb_info->msg_handler_mutex);
-               g_queue_push_tail(cb_info->msg_queue, (gpointer)rec_msg);
-               g_cond_signal(&cb_info->msg_handler_cond);
-               g_mutex_unlock(&cb_info->msg_handler_mutex);
+               __recorder_add_msg_to_queue(cb_info,
+                       MUSE_RECORDER_CB_EVENT,
+                       MUSE_RECORDER_EVENT_TYPE_ERROR,
+                       MUSE_RECORDER_EVENT_CLASS_THREAD_MAIN,
+                       error_msg);
 
-               rec_msg = NULL;
+               muse_core_msg_json_factory_free(error_msg);
+               error_msg = NULL;
 
                LOGE("add error msg for service disconnection done");
        }
 
 CB_HANDLER_EXIT:
-       if (error_msg) {
-               muse_core_msg_json_factory_free(error_msg);
-               error_msg = NULL;
-       }
-
        if (parse_str) {
                for (i = 0 ; i < RECORDER_PARSE_STRING_SIZE ; i++) {
                        if (parse_str[i]) {
@@ -883,11 +893,91 @@ CB_HANDLER_EXIT:
        return NULL;
 }
 
-static recorder_cb_info_s *_recorder_client_callback_new(gint sockfd)
+
+static bool __create_msg_handler_thread(recorder_msg_handler_info_s *handler_info,
+       int type, const char *thread_name, recorder_cb_info_s *cb_info)
+{
+       if (!handler_info || !thread_name || !cb_info) {
+               LOGE("t:%d NULL %p %p %p",
+                       type, handler_info, thread_name, cb_info);
+               return false;
+       }
+
+       LOGD("t:%d", type);
+
+       handler_info->type = type;
+       handler_info->queue = g_queue_new();
+       if (handler_info->queue == NULL) {
+               LOGE("t:%d queue failed", type);
+               return false;
+       }
+
+       g_mutex_init(&handler_info->mutex);
+       g_cond_init(&handler_info->cond);
+
+       handler_info->cb_info = (void *)cb_info;
+       g_atomic_int_set(&handler_info->running, 1);
+
+       handler_info->thread = g_thread_try_new(thread_name,
+               _recorder_msg_handler_func, (gpointer)handler_info, NULL);
+       if (handler_info->thread == NULL) {
+               LOGE("t:%d thread failed", type);
+
+               g_mutex_clear(&handler_info->mutex);
+               g_cond_clear(&handler_info->cond);
+               g_queue_free(handler_info->queue);
+               handler_info->queue = NULL;
+
+               return false;
+       }
+
+       LOGD("t:%d done", type);
+
+       return true;
+}
+
+
+static void __destroy_msg_handler_thread(recorder_msg_handler_info_s *handler_info)
+{
+       int type = 0;
+
+       if (!handler_info) {
+               LOGE("NULL handler");
+               return;
+       }
+
+       if (!handler_info->thread) {
+               LOGW("thread is not created");
+               return;
+       }
+
+       type = handler_info->type;
+
+       LOGD("t:%d thread %p", type, handler_info->thread);
+
+       g_mutex_lock(&handler_info->mutex);
+       g_atomic_int_set(&handler_info->running, 0);
+       g_cond_signal(&handler_info->cond);
+       g_mutex_unlock(&handler_info->mutex);
+
+       g_thread_join(handler_info->thread);
+       g_thread_unref(handler_info->thread);
+       handler_info->thread = NULL;
+
+       g_mutex_clear(&handler_info->mutex);
+       g_cond_clear(&handler_info->cond);
+       g_queue_free(handler_info->queue);
+       handler_info->queue = NULL;
+
+       LOGD("t:%d done", type);
+
+       return;
+}
+
+
+static recorder_cb_info_s *_recorder_client_callback_new(gint sockfd, bool need_msg_handler_thread)
 {
        recorder_cb_info_s *cb_info = NULL;
-       gint *tmp_activating = NULL;
-       gint *tmp_ret = NULL;
        gint i = 0;
 
        g_return_val_if_fail(sockfd > 0, NULL);
@@ -898,46 +988,33 @@ static recorder_cb_info_s *_recorder_client_callback_new(gint sockfd)
                goto ErrorExit;
        }
 
-       g_mutex_init(&cb_info->msg_handler_mutex);
-       g_cond_init(&cb_info->msg_handler_cond);
-       g_mutex_init(&cb_info->idle_event_mutex);
-       g_cond_init(&cb_info->idle_event_cond);
-
        for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
                g_mutex_init(&cb_info->api_mutex[i]);
                g_cond_init(&cb_info->api_cond[i]);
        }
 
-       tmp_activating = g_new0(gint, MUSE_RECORDER_API_MAX);
-       if (tmp_activating == NULL) {
-               LOGE("tmp_activating failed");
-               goto ErrorExit;
-       }
-
-       tmp_ret = g_new0(gint, MUSE_RECORDER_API_MAX);
-       if (tmp_ret == NULL) {
-               LOGE("tmp_ret failed");
-               goto ErrorExit;
-       }
+       g_mutex_init(&cb_info->idle_event_mutex);
+       g_cond_init(&cb_info->idle_event_cond);
 
-       cb_info->msg_queue = g_queue_new();
-       if (cb_info->msg_queue == NULL) {
-               LOGE("msg_queue new failed");
-               goto ErrorExit;
-       }
+       if (need_msg_handler_thread) {
+               /* message handler thread */
+               if (!__create_msg_handler_thread(&cb_info->msg_handler_info,
+                       _RECORDER_MESSAGE_HANDLER_TYPE_GENERAL, "recorder_msg_handler", cb_info)) {
+                       LOGE("msg_handler_info failed");
+                       goto ErrorExit;
+               }
 
-       g_atomic_int_set(&cb_info->msg_handler_running, 1);
-       cb_info->msg_handler_thread = g_thread_try_new("recorder_msg_handler",
-               _recorder_msg_handler_func, (gpointer)cb_info, NULL);
-       if (cb_info->msg_handler_thread == NULL) {
-               LOGE("message handler thread creation failed");
-               goto ErrorExit;
+               /* message handler thread for audio stream callback */
+               if (!__create_msg_handler_thread(&cb_info->audio_stream_cb_info,
+                       _RECORDER_MESSAGE_HANDLER_TYPE_AUDIO_STREAM_CB, "recorder_msg_handler:audio_stream_cb", cb_info)) {
+                       LOGE("audio_stream_cb_info failed");
+                       goto ErrorExit;
+               }
        }
 
        cb_info->fd = sockfd;
-       cb_info->api_activating = tmp_activating;
-       cb_info->api_ret = tmp_ret;
 
+       /* message receive thread */
        g_atomic_int_set(&cb_info->msg_recv_running, 1);
        cb_info->msg_recv_thread = g_thread_try_new("recorder_msg_recv",
                _recorder_msg_recv_func, (gpointer)cb_info, NULL);
@@ -952,45 +1029,21 @@ static recorder_cb_info_s *_recorder_client_callback_new(gint sockfd)
 
 ErrorExit:
        if (cb_info) {
-               if (cb_info->msg_handler_thread) {
-                       g_mutex_lock(&cb_info->msg_handler_mutex);
-                       g_atomic_int_set(&cb_info->msg_handler_running, 0);
-                       g_cond_signal(&cb_info->msg_handler_cond);
-                       g_mutex_unlock(&cb_info->msg_handler_mutex);
-
-                       g_thread_join(cb_info->msg_handler_thread);
-                       g_thread_unref(cb_info->msg_handler_thread);
-                       cb_info->msg_handler_thread = NULL;
-               }
+               __destroy_msg_handler_thread(&cb_info->msg_handler_info);
+               __destroy_msg_handler_thread(&cb_info->audio_stream_cb_info);
 
-               for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
-                       g_mutex_clear(&cb_info->api_mutex[i]);
-                       g_cond_clear(&cb_info->api_cond[i]);
-               }
-
-               g_mutex_clear(&cb_info->msg_handler_mutex);
-               g_cond_clear(&cb_info->msg_handler_cond);
                g_mutex_clear(&cb_info->idle_event_mutex);
                g_cond_clear(&cb_info->idle_event_cond);
 
-               if (cb_info->msg_queue) {
-                       g_queue_free(cb_info->msg_queue);
-                       cb_info->msg_queue = NULL;
+               for (i = 0 ; i < MUSE_RECORDER_API_MAX ; i++) {
+                       g_mutex_clear(&cb_info->api_mutex[i]);
+                       g_cond_clear(&cb_info->api_cond[i]);
                }
 
                g_free(cb_info);
                cb_info = NULL;
        }
 
-       if (tmp_activating) {
-               g_free(tmp_activating);
-               tmp_activating = NULL;
-       }
-       if (tmp_ret) {
-               g_free(tmp_ret);
-               tmp_ret = NULL;
-       }
-
        return NULL;
 }
 
@@ -1141,21 +1194,11 @@ static void _recorder_client_callback_destroy(recorder_cb_info_s *cb_info)
        g_thread_unref(cb_info->msg_recv_thread);
        cb_info->msg_recv_thread = NULL;
 
-       LOGD("msg thread removed");
+       LOGD("msg_recv thread removed");
 
-       g_mutex_lock(&cb_info->msg_handler_mutex);
-       g_atomic_int_set(&cb_info->msg_handler_running, 0);
-       g_cond_signal(&cb_info->msg_handler_cond);
-       g_mutex_unlock(&cb_info->msg_handler_mutex);
+       __destroy_msg_handler_thread(&cb_info->msg_handler_info);
+       __destroy_msg_handler_thread(&cb_info->audio_stream_cb_info);
 
-       g_thread_join(cb_info->msg_handler_thread);
-       g_thread_unref(cb_info->msg_handler_thread);
-       cb_info->msg_handler_thread = NULL;
-
-       g_queue_free(cb_info->msg_queue);
-       cb_info->msg_queue = NULL;
-       g_mutex_clear(&cb_info->msg_handler_mutex);
-       g_cond_clear(&cb_info->msg_handler_cond);
        g_mutex_clear(&cb_info->idle_event_mutex);
        g_cond_clear(&cb_info->idle_event_cond);
 
@@ -1164,8 +1207,6 @@ static void _recorder_client_callback_destroy(recorder_cb_info_s *cb_info)
                g_cond_clear(&cb_info->api_cond[i]);
        }
 
-       LOGD("event thread removed");
-
        if (cb_info->fd > -1) {
                muse_core_connection_close(cb_info->fd);
                cb_info->fd = -1;
@@ -1175,14 +1216,6 @@ static void _recorder_client_callback_destroy(recorder_cb_info_s *cb_info)
                tbm_bufmgr_deinit(cb_info->bufmgr);
                cb_info->bufmgr = NULL;
        }
-       if (cb_info->api_activating) {
-               g_free(cb_info->api_activating);
-               cb_info->api_activating = NULL;
-       }
-       if (cb_info->api_ret) {
-               g_free(cb_info->api_ret);
-               cb_info->api_ret = NULL;
-       }
        if (cb_info->get_filename) {
                free(cb_info->get_filename);
                cb_info->get_filename = NULL;
@@ -1323,7 +1356,7 @@ static int _recorder_create_common(recorder_h *recorder, muse_recorder_type_e ty
                goto _ERR_RECORDER_EXIT;
        }
 
-       pc->cb_info = _recorder_client_callback_new(sock_fd);
+       pc->cb_info = _recorder_client_callback_new(sock_fd, true);
        if (pc->cb_info == NULL) {
                ret = RECORDER_ERROR_OUT_OF_MEMORY;
                goto _ERR_RECORDER_EXIT;