Remove unused variable
[platform/core/api/camera.git] / src / camera.c
index 696b5a5..e5c2403 100644 (file)
 #include <camera.h>
 #include <muse_camera.h>
 #include <muse_camera_msg.h>
-#include <muse_core_ipc.h>
-#include <muse_core_module.h>
 #include <camera_private.h>
 #include <muse_core.h>
+#include <muse_client.h>
 #include <dlog.h>
 #include <Elementary.h>
 #include <tbm_surface_internal.h>
@@ -51,6 +50,21 @@ static int g_cam_dev_state_changed_cb_id;
 static GDBusConnection *g_cam_dev_state_changed_cb_conn;
 static guint g_cam_dev_state_changed_cb_subscribe_id;
 
+static void _camera_msg_send(int api, camera_cb_info_s *cb_info,
+       int *ret, int timeout);
+static void _camera_msg_send_param1(int api, camera_cb_info_s *cb_info,
+       int *ret, camera_msg_param *param, int timeout);
+static int _camera_import_tbm_key(tbm_bufmgr bufmgr, unsigned int tbm_key, tbm_bo *bo, tbm_bo_handle *bo_handle);
+static void _camera_release_imported_bo(tbm_bo *bo);
+static void _camera_preview_frame_create(camera_stream_data_s *stream, int num_buffer_key,
+       tbm_bo_handle *buffer_bo_handle, tbm_bo_handle *data_bo_handle, camera_preview_data_s *frame);
+static int _camera_media_packet_create(camera_cb_info_s *cb_info, camera_stream_data_s *stream,
+       camera_media_packet_data *mp_data, media_packet_h *packet);
+static int _camera_media_packet_data_create(int tbm_key, int num_buffer_key, tbm_bo bo,
+       tbm_bo *buffer_bo, tbm_bo data_bo, camera_media_packet_data **mp_data);
+static void _camera_media_packet_data_release(camera_media_packet_data *mp_data, camera_cb_info_s *cb_info);
+
+
 static void __global(void *data, struct wl_registry *registry,
        uint32_t name, const char *interface, uint32_t version)
 {
@@ -136,6 +150,8 @@ int _camera_get_wl_info(Evas_Object *obj, camera_wl_info_s *wl_info)
                goto _DONE;
        }
 
+       ecore_wl_window_video_has(window, EINA_TRUE);
+
        surface = (struct wl_surface *)ecore_wl_window_surface_get(window);
        if (!surface) {
                LOGE("failed to get wayland surface");
@@ -203,8 +219,6 @@ int _camera_get_wl_info(Evas_Object *obj, camera_wl_info_s *wl_info)
                Ecore_Evas *ecore_evas = NULL;
                ret = CAMERA_ERROR_NONE;
 
-               wl_info->evas_obj = obj;
-
                evas_object_geometry_get(obj, &wl_info->window_x, &wl_info->window_y,
                        &wl_info->window_width, &wl_info->window_height);
 
@@ -224,7 +238,7 @@ int _camera_get_wl_info(Evas_Object *obj, camera_wl_info_s *wl_info)
                }
 
                LOGD("evas object : %p, rotation : %d, parent id : %u, window : %d,%d,%dx%d",
-                       wl_info->evas_obj, rotation, wl_info->parent_id,
+                       obj, rotation, wl_info->parent_id,
                        wl_info->window_x, wl_info->window_y,
                        wl_info->window_width, wl_info->window_height);
        } else {
@@ -262,6 +276,25 @@ _DONE:
 }
 
 
+static void __camera_update_api_waiting(camera_cb_info_s *cb_info, int api, int value)
+{
+       if (!cb_info ||
+               api < 0 || api >= MUSE_CAMERA_API_MAX) {
+               LOGE("invalid param %p %d", cb_info, api);
+               return;
+       }
+
+       g_mutex_lock(&(cb_info->api_mutex[api]));
+       cb_info->api_waiting[api] += value;
+       g_mutex_unlock(&(cb_info->api_mutex[api]));
+
+       /*LOGD("api %d, value %d, waiting %d",
+               api, value, cb_info->api_waiting[api]);*/
+
+       return;
+}
+
+
 static void __camera_device_state_changed_cb(GDBusConnection *connection,
        const gchar *sender_name, const gchar *object_path, const gchar *interface_name,
        const gchar *signal_name, GVariant *param, gpointer user_data)
@@ -312,6 +345,339 @@ _DONE:
 }
 
 
+static void __camera_event_handler_preview(camera_cb_info_s *cb_info, char *recv_msg)
+{
+       int i = 0;
+       int ret = 0;
+       int num_buffer_key = 0;
+       int buffer_key[BUFFER_MAX_PLANE_NUM] = {0, };
+       int tbm_key = 0;
+       int data_key = 0;
+       unsigned char *buf_pos = NULL;
+       camera_msg_param param;
+
+       tbm_bo bo = NULL;
+       tbm_bo buffer_bo[BUFFER_MAX_PLANE_NUM] = {NULL, };
+       tbm_bo_handle bo_handle = {.ptr = NULL};
+       tbm_bo_handle buffer_bo_handle[BUFFER_MAX_PLANE_NUM] = {{.ptr = NULL}, };
+       tbm_bo data_bo = NULL;
+       tbm_bo_handle data_bo_handle = {.ptr = NULL};
+
+       camera_preview_data_s frame;
+       camera_stream_data_s *stream = NULL;
+       camera_media_packet_data *mp_data = NULL;
+       media_packet_h pkt = NULL;
+#ifdef TIZEN_FEATURE_EVAS_RENDERER
+       media_packet_h pkt_evas = NULL;
+#endif /* TIZEN_FEATURE_EVAS_RENDERER */
+
+       if (!cb_info || !recv_msg) {
+               LOGE("invalid param %p %p", cb_info, recv_msg);
+               return;
+       }
+
+       muse_camera_msg_get(tbm_key, recv_msg);
+       muse_camera_msg_get(num_buffer_key, recv_msg);
+       muse_camera_msg_get_array(buffer_key, recv_msg);
+       muse_camera_msg_get(data_key, recv_msg);
+
+       memset(&frame, 0x0, sizeof(camera_preview_data_s));
+
+       if (tbm_key <= 0) {
+               LOGE("invalid key %d", tbm_key);
+               return;
+       }
+
+       CAMERA_MSG_PARAM_SET(param, INT, tbm_key);
+
+       if (num_buffer_key < 0 || num_buffer_key > BUFFER_MAX_PLANE_NUM) {
+               LOGE("invalid num buffer key %d", num_buffer_key);
+               goto _PREVIEW_CB_HANDLER_DONE;
+       }
+
+       if (data_key > 0) {
+               /* import tbm data_bo and get virtual address */
+               if (!_camera_import_tbm_key(cb_info->bufmgr, data_key, &data_bo, &data_bo_handle)) {
+                       LOGE("failed to import data key %d", data_key);
+                       goto _PREVIEW_CB_HANDLER_DONE;
+               }
+       }
+
+       /* import tbm bo and get virtual address */
+       if (!_camera_import_tbm_key(cb_info->bufmgr, tbm_key, &bo, &bo_handle)) {
+               LOGE("failed to import key %d", tbm_key);
+               goto _PREVIEW_CB_HANDLER_DONE;
+       }
+
+       buf_pos = (unsigned char *)bo_handle.ptr;
+
+       /* get stream info */
+       stream = (camera_stream_data_s *)buf_pos;
+
+       for (i = 0 ; i < num_buffer_key ; i++) {
+               /* import buffer bo and get virtual address */
+               if (!_camera_import_tbm_key(cb_info->bufmgr, buffer_key[i], &buffer_bo[i], &buffer_bo_handle[i])) {
+                       LOGE("failed to import buffer key %d", buffer_key[i]);
+                       goto _PREVIEW_CB_HANDLER_DONE;
+               }
+       }
+
+       /* call preview callback */
+       if (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW]) {
+               _camera_preview_frame_create(stream, num_buffer_key, buffer_bo_handle, &data_bo_handle, &frame);
+
+               ((camera_preview_cb)cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW])(&frame,
+                       cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
+       }
+
+       if (CHECK_PREVIEW_CB(cb_info, PREVIEW_CB_TYPE_EVAS)) {
+#ifdef TIZEN_FEATURE_EVAS_RENDERER
+               ret = _camera_media_packet_data_create(tbm_key, num_buffer_key, bo, buffer_bo, data_bo, &mp_data);
+
+               if (ret == CAMERA_ERROR_NONE) {
+                       ret = _camera_media_packet_create(cb_info, stream, mp_data, &pkt_evas);
+                       if (ret != CAMERA_ERROR_NONE) {
+                               LOGE("create pkt for evas failed");
+                               _camera_media_packet_data_release(mp_data, cb_info);
+                               mp_data = NULL;
+                       }
+               }
+#else /* TIZEN_FEATURE_EVAS_RENDERER */
+               LOGW("evas renderer is not supported");
+#endif /* TIZEN_FEATURE_EVAS_RENDERER */
+       }
+
+       /* call media packet callback */
+       if (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]) {
+               ret = _camera_media_packet_data_create(tbm_key, num_buffer_key, bo, buffer_bo, data_bo, &mp_data);
+
+               if (ret == CAMERA_ERROR_NONE) {
+                       ret = _camera_media_packet_create(cb_info, stream, mp_data, &pkt);
+
+                       if (ret == CAMERA_ERROR_NONE) {
+                               ((camera_media_packet_preview_cb)cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW])(pkt,
+                                       cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
+                       } else {
+                               _camera_media_packet_data_release(mp_data, cb_info);
+                               mp_data = NULL;
+                       }
+               }
+       }
+
+#ifdef TIZEN_FEATURE_EVAS_RENDERER
+       /* call evas renderer */
+       if (pkt_evas) {
+               g_mutex_lock(&cb_info->evas_mutex);
+               if (cb_info->run_evas_render) {
+                       mm_evas_renderer_write(pkt_evas, cb_info->evas_info);
+               } else {
+                       LOGW("evas renderer is stopped, skip this buffer...");
+                       media_packet_destroy(pkt_evas);
+               }
+               pkt_evas = NULL;
+               g_mutex_unlock(&cb_info->evas_mutex);
+       }
+#endif /* TIZEN_FEATURE_EVAS_RENDERER */
+
+       /* send message for preview callback return */
+       if (!CHECK_PREVIEW_CB(cb_info, PREVIEW_CB_TYPE_EVAS))
+               _camera_msg_send(MUSE_CAMERA_API_PREVIEW_CB_RETURN, cb_info, NULL, 0);
+
+_PREVIEW_CB_HANDLER_DONE:
+       if (mp_data == NULL) {
+               /* release imported bo */
+               for (i = 0 ; i < num_buffer_key ; i++)
+                       _camera_release_imported_bo(&buffer_bo[i]);
+
+               /* unmap and unref tbm bo */
+               _camera_release_imported_bo(&data_bo);
+               _camera_release_imported_bo(&bo);
+
+               /* return buffer */
+               _camera_msg_send_param1(MUSE_CAMERA_API_RETURN_BUFFER, cb_info, NULL, &param, 0);
+
+               /*LOGD("return buffer Done");*/
+       }
+
+       return;
+}
+
+
+static void __camera_event_handler_capture(camera_cb_info_s *cb_info, char *recv_msg)
+{
+       int tbm_key = 0;
+       int tbm_key_main = 0;
+       int tbm_key_post = 0;
+       int tbm_key_thumb = 0;
+       unsigned char *buf_pos = NULL;
+
+       camera_msg_param param;
+       camera_image_data_s *rImage = NULL;
+       camera_image_data_s *rPostview = NULL;
+       camera_image_data_s *rThumbnail = NULL;
+
+       tbm_bo bo_main = NULL;
+       tbm_bo bo_post = NULL;
+       tbm_bo bo_thumb = NULL;
+       tbm_bo_handle bo_main_handle = {.ptr = NULL};
+       tbm_bo_handle bo_post_handle = {.ptr = NULL};
+       tbm_bo_handle bo_thumb_handle = {.ptr = NULL};
+
+       if (!cb_info || !recv_msg) {
+               LOGE("invalid param %p %p", cb_info, recv_msg);
+               return;
+       }
+
+       muse_camera_msg_get(tbm_key_main, recv_msg);
+       muse_camera_msg_get(tbm_key_post, recv_msg);
+       muse_camera_msg_get(tbm_key_thumb, recv_msg);
+
+       /*
+       LOGD("camera capture callback came in. tbm_key_main %d, tbm_key_post %d, tbm_key_thumb %d",
+               tbm_key_main, tbm_key_post, tbm_key_thumb);
+       */
+
+       if (tbm_key_main <= 0) {
+               LOGE("invalid key %d", tbm_key_main);
+               goto _CAPTURE_CB_HANDLER_DONE;
+       }
+
+       if (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_CAPTURE] == NULL) {
+               LOGW("NULL callback");
+               goto _CAPTURE_CB_HANDLER_DONE;
+       }
+
+       /* import tbm bo and get virtual address */
+       if (!_camera_import_tbm_key(cb_info->bufmgr, tbm_key_main, &bo_main, &bo_main_handle)) {
+               LOGE("failed to import key [%d] for main", tbm_key_main);
+               goto _CAPTURE_CB_HANDLER_DONE;
+       }
+
+       buf_pos = (unsigned char *)bo_main_handle.ptr;
+       rImage = (camera_image_data_s *)buf_pos;
+       rImage->data = buf_pos + sizeof(camera_image_data_s);
+       if (rImage->exif && rImage->exif_size > 0) {
+               rImage->exif = rImage->data + rImage->size;
+       } else {
+               rImage->exif = NULL;
+               rImage->exif_size = 0;
+       }
+
+       LOGD("image info %dx%d, size %d, EXIF info %p, size %d",
+               rImage->width, rImage->height, rImage->size, rImage->exif, rImage->exif_size);
+
+       if (tbm_key_post > 0) {
+               /* import tbm bo and get virtual address */
+               if (_camera_import_tbm_key(cb_info->bufmgr, tbm_key_post, &bo_post, &bo_post_handle)) {
+                       buf_pos = (unsigned char *)bo_post_handle.ptr;
+                       rPostview = (camera_image_data_s *)buf_pos;
+                       LOGD("rPostview->size : %d", rPostview->size);
+                       rPostview->data = buf_pos + sizeof(camera_image_data_s);
+               } else {
+                       LOGE("failed to import key [%d] for postview", tbm_key_post);
+               }
+       }
+
+       if (tbm_key_thumb > 0) {
+               /* import tbm bo and get virtual address */
+               if (_camera_import_tbm_key(cb_info->bufmgr, tbm_key_thumb, &bo_thumb, &bo_thumb_handle)) {
+                       buf_pos = (unsigned char *)bo_thumb_handle.ptr;
+                       rThumbnail = (camera_image_data_s *)buf_pos;
+                       LOGD("rThumbnail->size : %d", rThumbnail->size);
+                       rThumbnail->data = buf_pos + sizeof(camera_image_data_s);
+               } else {
+                       LOGE("failed to import key [%d] for thumbnail", tbm_key_thumb);
+               }
+       }
+
+       ((camera_capturing_cb)cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_CAPTURE])(rImage,
+               rPostview, rThumbnail, cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_CAPTURE]);
+
+_CAPTURE_CB_HANDLER_DONE:
+       /* return buffer */
+       if (tbm_key_main > 0) {
+               _camera_release_imported_bo(&bo_main);
+
+               tbm_key = tbm_key_main;
+               CAMERA_MSG_PARAM_SET(param, INT, tbm_key);
+
+               _camera_msg_send_param1(MUSE_CAMERA_API_RETURN_BUFFER, cb_info, NULL, &param, 0);
+       }
+
+       if (tbm_key_post > 0) {
+               _camera_release_imported_bo(&bo_post);
+
+               tbm_key = tbm_key_post;
+               CAMERA_MSG_PARAM_SET(param, INT, tbm_key);
+
+               _camera_msg_send_param1(MUSE_CAMERA_API_RETURN_BUFFER, cb_info, NULL, &param, 0);
+       }
+
+       if (tbm_key_thumb > 0) {
+               _camera_release_imported_bo(&bo_thumb);
+
+               tbm_key = tbm_key_thumb;
+               CAMERA_MSG_PARAM_SET(param, INT, tbm_key);
+
+               _camera_msg_send_param1(MUSE_CAMERA_API_RETURN_BUFFER, cb_info, NULL, &param, 0);
+       }
+
+       LOGD("return buffer done");
+
+       return;
+}
+
+
+static void __camera_event_handler_face_detection(camera_cb_info_s *cb_info, char *recv_msg)
+{
+       int count = 0;
+       int tbm_key = 0;
+       camera_detected_face_s *faces = NULL;
+       camera_msg_param param;
+
+       tbm_bo bo = NULL;
+       tbm_bo_handle bo_handle = {.ptr = NULL};
+
+       if (!cb_info || !recv_msg) {
+               LOGE("invalid param %p %p", cb_info, recv_msg);
+               return;
+       }
+
+       muse_camera_msg_get(count, recv_msg);
+       muse_camera_msg_get(tbm_key, recv_msg);
+
+       if (count >= 0 && cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION]) {
+               LOGD("FACE_DETECTION - count %d, tbm_key %d", count, tbm_key);
+
+               if (tbm_key > 0) {
+
+                       if (_camera_import_tbm_key(cb_info->bufmgr, tbm_key, &bo, &bo_handle)) {
+                               /* set face info */
+                               faces = bo_handle.ptr;
+                       }
+               }
+
+               ((camera_face_detected_cb)cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION])(faces,
+                       count, cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION]);
+
+               /* release bo */
+               _camera_release_imported_bo(&bo);
+       } else {
+               LOGW("skip face detection message [count %d, key %d, cb %p",
+                       count, tbm_key, cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION]);
+       }
+
+       /* return buffer */
+       if (tbm_key > 0) {
+               CAMERA_MSG_PARAM_SET(param, INT, tbm_key);
+               _camera_msg_send_param1(MUSE_CAMERA_API_RETURN_BUFFER, cb_info, NULL, &param, 0);
+               /*LOGD("return buffer done");*/
+       }
+
+       return;
+}
+
+
 static int _camera_import_tbm_key(tbm_bufmgr bufmgr, unsigned int tbm_key, tbm_bo *bo, tbm_bo_handle *bo_handle)
 {
        tbm_bo tmp_bo = NULL;
@@ -349,7 +715,7 @@ static int _camera_import_tbm_key(tbm_bufmgr bufmgr, unsigned int tbm_key, tbm_b
 static void _camera_release_imported_bo(tbm_bo *bo)
 {
        if (!bo || !(*bo)) {
-               LOGW("NULL bo");
+               /*LOGW("NULL bo");*/
                return;
        }
 
@@ -374,15 +740,22 @@ static int _camera_client_wait_for_cb_return(muse_camera_api_e api, camera_cb_in
        g_mutex_lock(&(cb_info->api_mutex[api]));
 
        if (cb_info->api_activating[api] == 0) {
-               end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_SECOND;
-               if (g_cond_wait_until(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]), end_time)) {
+               if (time_out == CAMERA_CB_NO_TIMEOUT) {
+                       LOGW("wait for api %d", api);
+                       g_cond_wait(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]));
                        ret = cb_info->api_ret[api];
                        cb_info->api_activating[api] = 0;
-
-                       /*LOGD("return value : 0x%x", ret);*/
+                       LOGW("api %d returned 0x%x", api, ret);
                } else {
-                       ret = CAMERA_ERROR_INVALID_OPERATION;
-                       LOGE("api %d was TIMED OUT!", api);
+                       end_time = g_get_monotonic_time() + time_out * G_TIME_SPAN_SECOND;
+                       if (g_cond_wait_until(&(cb_info->api_cond[api]), &(cb_info->api_mutex[api]), end_time)) {
+                               ret = cb_info->api_ret[api];
+                               cb_info->api_activating[api] = 0;
+                               /*LOGD("return value : 0x%x", ret);*/
+                       } else {
+                               ret = CAMERA_ERROR_INVALID_OPERATION;
+                               LOGE("api %d was TIMED OUT!", api);
+                       }
                }
        } else {
                ret = cb_info->api_ret[api];
@@ -423,7 +796,7 @@ static void _camera_msg_send(int api, camera_cb_info_s *cb_info,
                return;
        }
 
-       msg = muse_core_msg_json_factory_new(api, NULL);
+       msg = muse_core_msg_new(api, NULL);
        if (!msg) {
                LOGE("msg failed: api %d", api);
 
@@ -436,8 +809,10 @@ static void _camera_msg_send(int api, camera_cb_info_s *cb_info,
        /*LOGD("send msg %s", msg);*/
 
        if (cb_info->is_server_connected) {
+               __camera_update_api_waiting(cb_info, api, 1);
+
                g_mutex_lock(&cb_info->fd_lock);
-               send_ret = muse_core_ipc_send_msg(cb_info->fd, msg);
+               send_ret = muse_core_msg_send(cb_info->fd, msg);
                g_mutex_unlock(&cb_info->fd_lock);
        }
 
@@ -450,7 +825,9 @@ static void _camera_msg_send(int api, camera_cb_info_s *cb_info,
                        *ret = _camera_client_wait_for_cb_return(api, cb_info, timeout);
        }
 
-       muse_core_msg_json_factory_free(msg);
+       __camera_update_api_waiting(cb_info, api, -1);
+
+       muse_core_msg_free(msg);
 
        return;
 }
@@ -475,12 +852,12 @@ static void _camera_msg_send_param1(int api, camera_cb_info_s *cb_info,
 
        switch (param->type) {
        case MUSE_TYPE_INT:
-               msg = muse_core_msg_json_factory_new(api,
+               msg = muse_core_msg_new(api,
                        param->type, param->name, param->value.value_INT,
                        NULL);
                break;
        case MUSE_TYPE_STRING:
-               msg = muse_core_msg_json_factory_new(api,
+               msg = muse_core_msg_new(api,
                        param->type, param->name, param->value.value_STRING,
                        NULL);
                break;
@@ -501,8 +878,10 @@ static void _camera_msg_send_param1(int api, camera_cb_info_s *cb_info,
        /*LOGD("send msg %s", msg);*/
 
        if (cb_info->is_server_connected) {
+               __camera_update_api_waiting(cb_info, api, 1);
+
                g_mutex_lock(&cb_info->fd_lock);
-               send_ret = muse_core_ipc_send_msg(cb_info->fd, msg);
+               send_ret = muse_core_msg_send(cb_info->fd, msg);
                g_mutex_unlock(&cb_info->fd_lock);
        }
 
@@ -516,7 +895,9 @@ static void _camera_msg_send_param1(int api, camera_cb_info_s *cb_info,
                        *ret = _camera_client_wait_for_cb_return(api, cb_info, timeout);
        }
 
-       muse_core_msg_json_factory_free(msg);
+       __camera_update_api_waiting(cb_info, api, -1);
+
+       muse_core_msg_free(msg);
 
        return;
 }
@@ -635,7 +1016,7 @@ int _camera_get_media_packet_mimetype(int in_format, media_format_mimetype_e *mi
        return CAMERA_ERROR_NONE;
 }
 
-void _camera_preview_frame_create(camera_stream_data_s *stream, int num_buffer_key,
+static void _camera_preview_frame_create(camera_stream_data_s *stream, int num_buffer_key,
        tbm_bo_handle *buffer_bo_handle, tbm_bo_handle *data_bo_handle, camera_preview_data_s *frame)
 {
        int total_size = 0;
@@ -751,7 +1132,7 @@ void _camera_preview_frame_create(camera_stream_data_s *stream, int num_buffer_k
        return;
 }
 
-int _camera_media_packet_data_create(int tbm_key, int num_buffer_key, tbm_bo bo,
+static int _camera_media_packet_data_create(int tbm_key, int num_buffer_key, tbm_bo bo,
        tbm_bo *buffer_bo, tbm_bo data_bo, camera_media_packet_data **mp_data)
 {
        int i = 0;
@@ -783,7 +1164,7 @@ int _camera_media_packet_data_create(int tbm_key, int num_buffer_key, tbm_bo bo,
        return ret;
 }
 
-void _camera_media_packet_data_release(camera_media_packet_data *mp_data, camera_cb_info_s *cb_info)
+static void _camera_media_packet_data_release(camera_media_packet_data *mp_data, camera_cb_info_s *cb_info)
 {
        int i = 0;
        int tbm_key = 0;
@@ -822,7 +1203,7 @@ void _camera_media_packet_data_release(camera_media_packet_data *mp_data, camera
        return;
 }
 
-int _camera_media_packet_create(camera_cb_info_s *cb_info, camera_stream_data_s *stream,
+static int _camera_media_packet_create(camera_cb_info_s *cb_info, camera_stream_data_s *stream,
        camera_media_packet_data *mp_data, media_packet_h *packet)
 {
        media_packet_h pkt = NULL;
@@ -1046,10 +1427,6 @@ static void _camera_client_user_callback(camera_cb_info_s *cb_info, char *recv_m
 {
        int param1 = 0;
        int param2 = 0;
-       int tbm_key = 0;
-       tbm_bo bo = NULL;
-       tbm_bo_handle bo_handle = {NULL, };
-       camera_msg_param param;
 
        if (!recv_msg || event >= MUSE_CAMERA_EVENT_TYPE_NUM) {
                LOGE("invalid parameter - camera msg %p, event %d", recv_msg, event);
@@ -1058,16 +1435,24 @@ static void _camera_client_user_callback(camera_cb_info_s *cb_info, char *recv_m
 
        /*LOGD("get camera msg %s, event %d", recv_msg, event);*/
 
-       if (event == MUSE_CAMERA_EVENT_TYPE_PREVIEW) {
-               if (!(CHECK_PREVIEW_CB(cb_info, PREVIEW_CB_TYPE_EVAS)) &&
-                       cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW] == NULL &&
-                       cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] == NULL) {
-                       LOGW("all preview callback from user are NULL");
+       g_mutex_lock(&cb_info->user_cb_mutex[event]);
+
+       if (cb_info->user_cb[event] == NULL) {
+               if (event != MUSE_CAMERA_EVENT_TYPE_PREVIEW &&
+                       event != MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW &&
+                       event != MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION &&
+                       event != MUSE_CAMERA_EVENT_TYPE_CAPTURE) {
+                       g_mutex_unlock(&cb_info->user_cb_mutex[event]);
+                       LOGW("NULL callback for event %d, return here", event);
                        return;
                }
-       } else if (cb_info->user_cb[event] == NULL) {
-               LOGW("user callback for event %d is not set", event);
-               return;
+
+               /* return buffer message should be sent for some events.
+                - MUSE_CAMERA_EVENT_TYPE_PREVIEW
+                - MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW
+                - MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION
+                - MUSE_CAMERA_EVENT_TYPE_CAPTURE
+               */
        }
 
        switch (event) {
@@ -1105,158 +1490,7 @@ static void _camera_client_user_callback(camera_cb_info_s *cb_info, char *recv_m
                break;
        case MUSE_CAMERA_EVENT_TYPE_PREVIEW:
        case MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW:
-               {
-                       int i = 0;
-                       int ret = 0;
-                       int num_buffer_key = 0;
-                       int buffer_key[BUFFER_MAX_PLANE_NUM] = {0, };
-                       int data_key = 0;
-                       unsigned char *buf_pos = NULL;
-
-                       tbm_bo buffer_bo[BUFFER_MAX_PLANE_NUM] = {NULL, };
-                       tbm_bo_handle buffer_bo_handle[BUFFER_MAX_PLANE_NUM] = {{.ptr = NULL}, };
-                       tbm_bo data_bo = NULL;
-                       tbm_bo_handle data_bo_handle = {.ptr = NULL};
-
-                       camera_preview_data_s frame;
-                       camera_stream_data_s *stream = NULL;
-                       camera_media_packet_data *mp_data = NULL;
-                       media_packet_h pkt = NULL;
-#ifdef TIZEN_FEATURE_EVAS_RENDERER
-                       media_packet_h pkt_evas = NULL;
-#endif /* TIZEN_FEATURE_EVAS_RENDERER */
-
-                       muse_camera_msg_get(tbm_key, recv_msg);
-                       muse_camera_msg_get(num_buffer_key, recv_msg);
-                       muse_camera_msg_get_array(buffer_key, recv_msg);
-                       muse_camera_msg_get(data_key, recv_msg);
-
-                       memset(&frame, 0x0, sizeof(camera_preview_data_s));
-
-                       if (tbm_key <= 0) {
-                               LOGE("invalid key %d", tbm_key);
-                               break;
-                       }
-
-                       CAMERA_MSG_PARAM_SET(param, INT, tbm_key);
-
-                       if (data_key > 0) {
-                               /* import tbm data_bo and get virtual address */
-                               if (!_camera_import_tbm_key(cb_info->bufmgr, data_key, &data_bo, &data_bo_handle)) {
-                                       LOGE("failed to import data key %d", data_key);
-                                       _camera_msg_send_param1(MUSE_CAMERA_API_RETURN_BUFFER, cb_info, NULL, &param, 0);
-                                       break;
-                               }
-                       }
-
-                       /* import tbm bo and get virtual address */
-                       if (!_camera_import_tbm_key(cb_info->bufmgr, tbm_key, &bo, &bo_handle)) {
-                               LOGE("failed to import key %d", tbm_key);
-                               _camera_release_imported_bo(&data_bo);
-                               _camera_msg_send_param1(MUSE_CAMERA_API_RETURN_BUFFER, cb_info, NULL, &param, 0);
-                               break;
-                       }
-
-                       buf_pos = (unsigned char *)bo_handle.ptr;
-
-                       /* get stream info */
-                       stream = (camera_stream_data_s *)buf_pos;
-
-                       for (i = 0 ; i < num_buffer_key ; i++) {
-                               /* import buffer bo and get virtual address */
-                               if (!_camera_import_tbm_key(cb_info->bufmgr, buffer_key[i], &buffer_bo[i], &buffer_bo_handle[i])) {
-                                       LOGE("failed to import buffer key %d", buffer_key[i]);
-
-                                       /* release imported bo */
-                                       _camera_release_imported_bo(&data_bo);
-                                       _camera_release_imported_bo(&bo);
-
-                                       for (i -= 1 ; i >= 0 ; i--)
-                                               _camera_release_imported_bo(&buffer_bo[i]);
-
-                                       /* send return buffer */
-                                       _camera_msg_send_param1(MUSE_CAMERA_API_RETURN_BUFFER, cb_info, NULL, &param, 0);
-
-                                       return;
-                               }
-                       }
-
-                       /* call preview callback */
-                       if (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW]) {
-                               _camera_preview_frame_create(stream, num_buffer_key, buffer_bo_handle, &data_bo_handle, &frame);
-
-                               ((camera_preview_cb)cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW])(&frame,
-                                       cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
-                       }
-
-                       if (CHECK_PREVIEW_CB(cb_info, PREVIEW_CB_TYPE_EVAS)) {
-#ifdef TIZEN_FEATURE_EVAS_RENDERER
-                               ret = _camera_media_packet_data_create(tbm_key, num_buffer_key, bo, buffer_bo, data_bo, &mp_data);
-
-                               if (ret == CAMERA_ERROR_NONE) {
-                                       ret = _camera_media_packet_create(cb_info, stream, mp_data, &pkt_evas);
-                                       if (ret != CAMERA_ERROR_NONE) {
-                                               LOGE("create pkt for evas failed");
-                                               _camera_media_packet_data_release(mp_data, cb_info);
-                                               mp_data = NULL;
-                                       }
-                               }
-#else /* TIZEN_FEATURE_EVAS_RENDERER */
-                               LOGW("evas renderer is not supported");
-#endif /* TIZEN_FEATURE_EVAS_RENDERER */
-                       }
-
-                       /* call media packet callback */
-                       if (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]) {
-                               ret = _camera_media_packet_data_create(tbm_key, num_buffer_key, bo, buffer_bo, data_bo, &mp_data);
-
-                               if (ret == CAMERA_ERROR_NONE) {
-                                       ret = _camera_media_packet_create(cb_info, stream, mp_data, &pkt);
-
-                                       if (ret == CAMERA_ERROR_NONE) {
-                                               ((camera_media_packet_preview_cb)cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW])(pkt,
-                                                       cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
-                                       } else {
-                                               _camera_media_packet_data_release(mp_data, cb_info);
-                                               mp_data = NULL;
-                                       }
-                               }
-                       }
-
-#ifdef TIZEN_FEATURE_EVAS_RENDERER
-                       /* call evas renderer */
-                       if (pkt_evas) {
-                               g_mutex_lock(&cb_info->evas_mutex);
-                               if (cb_info->run_evas_render) {
-                                       mm_evas_renderer_write(pkt_evas, cb_info->evas_info);
-                               } else {
-                                       LOGW("evas renderer is stopped, skip this buffer...");
-                                       media_packet_destroy(pkt_evas);
-                               }
-                               pkt_evas = NULL;
-                               g_mutex_unlock(&cb_info->evas_mutex);
-                       }
-#endif /* TIZEN_FEATURE_EVAS_RENDERER */
-
-                       /* send message for preview callback return */
-                       if (!CHECK_PREVIEW_CB(cb_info, PREVIEW_CB_TYPE_EVAS))
-                               _camera_msg_send(MUSE_CAMERA_API_PREVIEW_CB_RETURN, cb_info, NULL, 0);
-
-                       if (mp_data == NULL) {
-                               /* release imported bo */
-                               for (i = 0 ; i < num_buffer_key ; i++)
-                                       _camera_release_imported_bo(&buffer_bo[i]);
-
-                               /* unmap and unref tbm bo */
-                               _camera_release_imported_bo(&data_bo);
-                               _camera_release_imported_bo(&bo);
-
-                               /* return buffer */
-                               _camera_msg_send_param1(MUSE_CAMERA_API_RETURN_BUFFER, cb_info, NULL, &param, 0);
-
-                               /*LOGD("return buffer Done");*/
-                       }
-               }
+               __camera_event_handler_preview(cb_info, recv_msg);
                break;
        case MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS:
                {
@@ -1264,7 +1498,7 @@ static void _camera_client_user_callback(camera_cb_info_s *cb_info, char *recv_m
 
                        muse_camera_msg_get(percent, recv_msg);
 
-                       LOGD("HDR progress - %d \%", percent);
+                       LOGD("HDR progress - %d %%", percent);
 
                        ((camera_attr_hdr_progress_cb)cb_info->user_cb[event])(percent, cb_info->user_data[event]);
                }
@@ -1293,49 +1527,30 @@ static void _camera_client_user_callback(camera_cb_info_s *cb_info, char *recv_m
                                (camera_state_e)previous, (camera_state_e)current, cb_info->user_data[event]);
                }
                break;
-       case MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION:
+       case MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED:
                {
-                       int count = 0;
-                       camera_detected_face_s *faces = NULL;
-
-                       muse_camera_msg_get(count, recv_msg);
-                       muse_camera_msg_get(tbm_key, recv_msg);
-
-                       if (count > 0 && tbm_key > 0) {
-                               LOGD("FACE_DETECTION - count %d, tbm_key %d", count, tbm_key);
-
-                               if (!_camera_import_tbm_key(cb_info->bufmgr, tbm_key, &bo, &bo_handle))
-                                       break;
-
-                               /* set face info */
-                               faces = bo_handle.ptr;
-
-                               ((camera_face_detected_cb)cb_info->user_cb[event])(faces, count, cb_info->user_data[event]);
-
-#if 0
-                               {
-                                       int i = 0;
+                       int policy = 0;
+                       int state = 0;
 
-                                       for (i = 0 ; i < count ; i++) {
-                                               LOGD("id[%2d] - score %d, position (%d,%d,%dx%d)",
-                                                    i, faces[i].score, faces[i].x, faces[i].y, faces[i].width, faces[i].height);
-                                       }
-                               }
-#endif
+                       muse_camera_msg_get(policy, recv_msg);
+                       muse_camera_msg_get(state, recv_msg);
 
-                               /* release bo */
-                               _camera_release_imported_bo(&bo);
+                       LOGW("INTERRUPT_STARTED - policy %d, state %d", policy, state);
 
-                               /* return buffer */
-                               CAMERA_MSG_PARAM_SET(param, INT, tbm_key);
-                               _camera_msg_send_param1(MUSE_CAMERA_API_RETURN_BUFFER, cb_info, NULL, &param, 0);
+                       if (policy == CAMERA_POLICY_SOUND)
+                               LOGW("DEPRECATION WARNING: CAMERA_POLICY_SOUND is deprecated and will be removed from next release.");
+                       else if (policy == CAMERA_POLICY_SOUND_BY_CALL)
+                               LOGW("DEPRECATION WARNING: CAMERA_POLICY_SOUND_BY_CALL is deprecated and will be removed from next release.");
+                       else if (policy == CAMERA_POLICY_SOUND_BY_ALARM)
+                               LOGW("DEPRECATION WARNING: CAMERA_POLICY_SOUND_BY_ALARM is deprecated and will be removed from next release.");
 
-                               /*LOGD("return buffer done");*/
-                       } else {
-                               LOGE("invalid message - count %d, key %d", count, tbm_key);
-                       }
+                       ((camera_interrupt_started_cb)cb_info->user_cb[event])((camera_policy_e)policy,
+                               (camera_state_e)state, cb_info->user_data[event]);
                }
                break;
+       case MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION:
+               __camera_event_handler_face_detection(cb_info, recv_msg);
+               break;
        case MUSE_CAMERA_EVENT_TYPE_ERROR:
                {
                        int error = 0;
@@ -1411,115 +1626,15 @@ static void _camera_client_user_callback(camera_cb_info_s *cb_info, char *recv_m
                }
                break;
        case MUSE_CAMERA_EVENT_TYPE_CAPTURE:
-               {
-                       camera_image_data_s *rImage = NULL;
-                       camera_image_data_s *rPostview = NULL;
-                       camera_image_data_s *rThumbnail = NULL;
-                       unsigned char *buf_pos = NULL;
-                       int tbm_key_main = 0;
-                       int tbm_key_post = 0;
-                       int tbm_key_thumb = 0;
-                       tbm_bo bo_main = NULL;
-                       tbm_bo bo_post = NULL;
-                       tbm_bo bo_thumb = NULL;
-                       tbm_bo_handle bo_main_handle = {NULL, };
-                       tbm_bo_handle bo_post_handle = {NULL, };
-                       tbm_bo_handle bo_thumb_handle = {NULL, };
-
-                       muse_camera_msg_get(tbm_key_main, recv_msg);
-                       muse_camera_msg_get(tbm_key_post, recv_msg);
-                       muse_camera_msg_get(tbm_key_thumb, recv_msg);
-
-                       /*
-                       LOGD("camera capture callback came in. tbm_key_main %d, tbm_key_post %d, tbm_key_thumb %d",
-                               tbm_key_main, tbm_key_post, tbm_key_thumb);
-                       */
-
-                       if (tbm_key_main <= 0) {
-                               LOGE("invalid key %d", tbm_key_main);
-                               break;
-                       }
-
-                       /* import tbm bo and get virtual address */
-                       if (!_camera_import_tbm_key(cb_info->bufmgr, tbm_key_main, &bo_main, &bo_main_handle))
-                               break;
-
-                       buf_pos = (unsigned char *)bo_main_handle.ptr;
-                       rImage = (camera_image_data_s *)buf_pos;
-                       rImage->data = buf_pos + sizeof(camera_image_data_s);
-                       if (rImage->exif && rImage->exif_size > 0) {
-                               rImage->exif = rImage->data + rImage->size;
-                       } else {
-                               rImage->exif = NULL;
-                               rImage->exif_size = 0;
-                       }
-
-                       LOGD("image info %dx%d, size %d, EXIF info %p, size %d",
-                               rImage->width, rImage->height, rImage->size, rImage->exif, rImage->exif_size);
-
-                       if (tbm_key_post > 0) {
-                               /* import tbm bo and get virtual address */
-                               if (!_camera_import_tbm_key(cb_info->bufmgr, tbm_key_post, &bo_post, &bo_post_handle))
-                                       break;
-
-                               buf_pos = (unsigned char *)bo_post_handle.ptr;
-                               rPostview = (camera_image_data_s *)buf_pos;
-                               LOGD("rPostview->size : %d", rPostview->size);
-                               rPostview->data = buf_pos + sizeof(camera_image_data_s);
-                       }
-
-                       if (tbm_key_thumb > 0) {
-                               /* import tbm bo and get virtual address */
-                               if (!_camera_import_tbm_key(cb_info->bufmgr, tbm_key_thumb, &bo_thumb, &bo_thumb_handle))
-                                       break;
-
-                               buf_pos = (unsigned char *)bo_thumb_handle.ptr;
-
-                               rThumbnail = (camera_image_data_s *)buf_pos;
-                               LOGD("rThumbnail->size : %d", rThumbnail->size);
-                               rThumbnail->data = buf_pos + sizeof(camera_image_data_s);
-                       }
-
-                       ((camera_capturing_cb)cb_info->user_cb[event])(rImage, rPostview, rThumbnail, cb_info->user_data[event]);
-
-                       /* unmap and unref tbm bo */
-                       _camera_release_imported_bo(&bo_main);
-
-                       /* return buffer */
-                       tbm_key = tbm_key_main;
-
-                       CAMERA_MSG_PARAM_SET(param, INT, tbm_key);
-
-                       _camera_msg_send_param1(MUSE_CAMERA_API_RETURN_BUFFER, cb_info, NULL, &param, 0);
-
-                       if (tbm_key_post > 0) {
-                               /* unmap and unref tbm bo */
-                               _camera_release_imported_bo(&bo_post);
-
-                               /* return buffer */
-                               param.value.value_INT = tbm_key_post;
-                               _camera_msg_send_param1(MUSE_CAMERA_API_RETURN_BUFFER, cb_info, NULL, &param, 0);
-                       }
-
-                       if (tbm_key_thumb > 0) {
-                               /* unmap and unref tbm bo */
-                               _camera_release_imported_bo(&bo_thumb);
-
-                               /* return buffer */
-                               param.value.value_INT = tbm_key_thumb;
-                               _camera_msg_send_param1(MUSE_CAMERA_API_RETURN_BUFFER, cb_info, NULL, &param, 0);
-                       }
-
-                       LOGD("return buffer done");
-               }
-               break;
-       case MUSE_CAMERA_EVENT_TYPE_VIDEO_FRAME_RENDER_ERROR:
+               __camera_event_handler_capture(cb_info, recv_msg);
                break;
        default:
-               LOGW("Unknown event : %d", event);
+               LOGW("unhandled event %d", event);
                break;
        }
 
+       g_mutex_unlock(&cb_info->user_cb_mutex[event]);
+
        return;
 }
 
@@ -1538,7 +1653,7 @@ static bool _camera_idle_event_callback(void *data)
 
        cb_info = cam_idle_event->cb_info;
        if (cb_info == NULL) {
-               LOGW("camera cb_info is NULL. event %d", cam_idle_event->event);
+               LOGW("camera cb_info is NULL. event %p %d", cam_idle_event, cam_idle_event->event);
                goto IDLE_EVENT_CALLBACK_DONE;
        }
 
@@ -1552,7 +1667,7 @@ static bool _camera_idle_event_callback(void *data)
        g_mutex_unlock(&cb_info->idle_event_mutex);
 
        /* user callback */
-       _camera_client_user_callback(cam_idle_event->cb_info, cam_idle_event->recv_msg, cam_idle_event->event);
+       _camera_client_user_callback(cb_info, cam_idle_event->recv_msg, cam_idle_event->event);
 
        /* send signal for waiting thread */
        g_cond_signal(&cb_info->idle_event_cond);
@@ -1619,12 +1734,16 @@ static void *_camera_msg_handler_func(gpointer data)
                        g_mutex_lock(&cb_info->api_mutex[api]);
 
                        if (muse_camera_msg_get(ret, cam_msg->recv_msg)) {
-                               cb_info->api_ret[api] = ret;
-                               cb_info->api_activating[api] = 1;
+                               if (cb_info->api_waiting[api] > 0) {
+                                       cb_info->api_ret[api] = ret;
+                                       cb_info->api_activating[api] = 1;
 
-                               /*LOGD("t:%d camera api %d - return 0x%x", type, ret);*/
+                                       /*LOGD("t:%d camera api %d - return 0x%x", type, ret);*/
 
-                               g_cond_signal(&cb_info->api_cond[api]);
+                                       g_cond_signal(&cb_info->api_cond[api]);
+                               } else {
+                                       LOGW("no waiting for this api [%d]", api);
+                               }
                        } else {
                                LOGE("t:%d failed to get camera ret for api %d, msg %s", type, api, cam_msg->recv_msg);
                        }
@@ -1692,10 +1811,9 @@ static void *_camera_msg_handler_func(gpointer data)
 }
 
 
-static void _camera_remove_idle_event_all(camera_cb_info_s *cb_info)
+static void _camera_deactivate_idle_event_all(camera_cb_info_s *cb_info)
 {
        camera_idle_event_s *cam_idle_event = NULL;
-       gboolean ret = TRUE;
        GList *list = NULL;
        gint64 end_time = 0;
 
@@ -1723,40 +1841,27 @@ static void _camera_remove_idle_event_all(camera_cb_info_s *cb_info)
                        continue;
                }
 
-               if (g_mutex_trylock(&cam_idle_event->event_mutex)) {
-                       ret = g_idle_remove_by_data(cam_idle_event);
-
-                       LOGD("remove idle event [%p], ret[%d]", cam_idle_event, ret);
-
-                       if (!ret) {
-                               cam_idle_event->cb_info = NULL;
-                               LOGW("idle event %p will be called later", cam_idle_event);
-                       }
-
-                       cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)cam_idle_event);
-
-                       g_mutex_unlock(&cam_idle_event->event_mutex);
-
-                       if (ret) {
-                               g_mutex_clear(&cam_idle_event->event_mutex);
+               if (!g_mutex_trylock(&cam_idle_event->event_mutex)) {
+                       LOGW("lock failed, %p event is calling now", cam_idle_event);
 
-                               g_free(cam_idle_event);
-                               cam_idle_event = NULL;
+                       end_time = g_get_monotonic_time() + G_TIME_SPAN_MILLISECOND * 100;
 
-                               LOGD("remove idle event done");
-                       }
+                       if (g_cond_wait_until(&cb_info->idle_event_cond, &cb_info->idle_event_mutex, end_time))
+                               LOGW("signal received");
+                       else
+                               LOGW("timeout");
 
                        continue;
                }
 
-               LOGW("event lock failed. it's being called...");
+               LOGW("set NULL cb_info for event %p %d, it will be freed on idle callback",
+                       cam_idle_event, cam_idle_event->event);
 
-               end_time = g_get_monotonic_time() + G_TIME_SPAN_MILLISECOND * 100;
+               cam_idle_event->cb_info = NULL;
+
+               cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)cam_idle_event);
 
-               if (g_cond_wait_until(&cb_info->idle_event_cond, &cb_info->idle_event_mutex, end_time))
-                       LOGW("signal received");
-               else
-                       LOGW("timeout");
+               g_mutex_unlock(&cam_idle_event->event_mutex);
        }
 
        g_list_free(cb_info->idle_event_list);
@@ -1829,7 +1934,7 @@ static void __camera_process_msg(camera_cb_info_s *cb_info, char *msg)
                return;
        }
 
-       LOGD("msg [%s]", msg);
+       /*LOGD("msg [%s]", msg);*/
 
        if (!muse_camera_msg_get(api, msg)) {
                LOGE("failed to get camera api");
@@ -1855,16 +1960,12 @@ static void __camera_process_msg(camera_cb_info_s *cb_info, char *msg)
                        return;
                }
 
-               g_mutex_lock(&cb_info->api_mutex[api]);
-
                if (!muse_camera_msg_get(ret, msg)) {
                        LOGE("failed to get camera ret");
-                       g_mutex_unlock(&cb_info->api_mutex[api]);
                        return;
                }
 
-               cb_info->api_ret[api] = ret;
-               cb_info->api_activating[api] = 1;
+               g_mutex_lock(&cb_info->api_mutex[api]);
 
                switch (api) {
                case MUSE_CAMERA_API_CREATE:
@@ -1887,30 +1988,30 @@ static void __camera_process_msg(camera_cb_info_s *cb_info, char *msg)
 
                                switch (get_type) {
                                case MUSE_CAMERA_GET_TYPE_INT:
-                                       muse_core_msg_json_deserialize("get_value", msg, NULL, &cb_info->get_int[get_index], NULL, MUSE_TYPE_INT);
+                                       muse_core_msg_deserialize("get_value", msg, NULL, NULL, MUSE_TYPE_INT, &cb_info->get_int[get_index]);
                                        break;
                                case MUSE_CAMERA_GET_TYPE_INT_PAIR:
-                                       muse_core_msg_json_deserialize("get_value0", msg, NULL, &cb_info->get_int_pair[get_index][0], NULL, MUSE_TYPE_INT);
-                                       muse_core_msg_json_deserialize("get_value1", msg, NULL, &cb_info->get_int_pair[get_index][1], NULL, MUSE_TYPE_INT);
+                                       muse_core_msg_deserialize("get_value0", msg, NULL, NULL, MUSE_TYPE_INT, &cb_info->get_int_pair[get_index][0]);
+                                       muse_core_msg_deserialize("get_value1", msg, NULL, NULL, MUSE_TYPE_INT, &cb_info->get_int_pair[get_index][1]);
                                        break;
                                case MUSE_CAMERA_GET_TYPE_ARRAY:
                                        if (api == MUSE_CAMERA_API_GET_DISPLAY_ROI_AREA) {
-                                               muse_core_msg_json_deserialize("get_value",
-                                                       msg, NULL, cb_info->get_display_roi_area, NULL, MUSE_TYPE_ARRAY);
+                                               muse_core_msg_deserialize("get_value",
+                                                       msg, NULL, NULL, MUSE_TYPE_ARRAY, cb_info->get_display_roi_area);
                                                LOGD("get display roi %d,%d,%dx%d",
                                                        cb_info->get_display_roi_area[0],
                                                        cb_info->get_display_roi_area[1],
                                                        cb_info->get_display_roi_area[2],
                                                        cb_info->get_display_roi_area[3]);
                                        } else {
-                                               muse_core_msg_json_deserialize("get_value",
-                                                       msg, NULL, cb_info->get_geotag, NULL, MUSE_TYPE_ARRAY);
+                                               muse_core_msg_deserialize("get_value",
+                                                       msg, NULL, NULL, MUSE_TYPE_ARRAY, cb_info->get_geotag);
                                                LOGD("get geotag %lf, %lf, %lf",
                                                        cb_info->get_geotag[0], cb_info->get_geotag[1], cb_info->get_geotag[2]);
                                        }
                                        break;
                                case MUSE_CAMERA_GET_TYPE_STRING:
-                                       muse_core_msg_json_deserialize("get_value", msg, NULL, cb_info->get_string[get_index], NULL, MUSE_TYPE_STRING);
+                                       muse_core_msg_deserialize("get_value", msg, NULL, NULL, MUSE_TYPE_STRING, cb_info->get_string[get_index]);
                                        break;
                                default:
                                        LOGW("unknown type %d", get_type);
@@ -1920,7 +2021,15 @@ static void __camera_process_msg(camera_cb_info_s *cb_info, char *msg)
                        break;
                }
 
-               g_cond_signal(&cb_info->api_cond[api]);
+               if (cb_info->api_waiting[api] > 0) {
+                       cb_info->api_ret[api] = ret;
+                       cb_info->api_activating[api] = 1;
+
+                       g_cond_signal(&cb_info->api_cond[api]);
+               } else {
+                       LOGW("no waiting for this api [%d]", api);
+               }
+
                g_mutex_unlock(&cb_info->api_mutex[api]);
        } else if (api_class == MUSE_CAMERA_API_CLASS_THREAD_SUB || api == MUSE_CAMERA_CB_EVENT) {
                __camera_add_msg_to_queue(cb_info, api, event, event_class, msg);
@@ -1934,15 +2043,15 @@ static void __camera_process_msg(camera_cb_info_s *cb_info, char *msg)
 
 static void *_camera_msg_recv_func(gpointer data)
 {
-       int i = 0;
-       int ret = 0;
-       int num_token = 0;
-       int str_pos = 0;
-       int prev_pos = 0;
-       int msg_length = 0;
-       char *error_msg = NULL;
+       int recv_length = 0;
+       int single_length = 0;
+       int remained_length = 0;
        char *recv_msg = NULL;
-       char **parse_str = NULL;
+       char *single_msg = NULL;
+       char *remained_msg = NULL;
+       int num_msg = 0;
+       int cur_pos = 0;
+       int prev_pos = 0;
        camera_cb_info_s *cb_info = (camera_cb_info_s *)data;
 
        if (!cb_info) {
@@ -1952,77 +2061,103 @@ static void *_camera_msg_recv_func(gpointer data)
 
        LOGD("start");
 
-       parse_str = (char **)malloc(sizeof(char *) * CAMERA_PARSED_STRING_NUM_MAX);
-       if (parse_str == NULL) {
-               LOGE("parse_str malloc failed");
+       single_msg = (char *)malloc(sizeof(char) * MUSE_CAMERA_MSG_MAX_LENGTH);
+       if (!single_msg) {
+               LOGE("single_msg malloc failed");
                return NULL;
        }
 
-       for (i = 0 ; i < CAMERA_PARSED_STRING_NUM_MAX ; i++) {
-               parse_str[i] = (char *)malloc(sizeof(char) * MUSE_CAMERA_MSG_MAX_LENGTH);
-               if (parse_str[i] == NULL) {
-                       LOGE("parse_str[%d] malloc failed", i);
-                       goto CB_HANDLER_EXIT;
-               }
-       }
-
        recv_msg = cb_info->recv_msg;
 
        while (g_atomic_int_get(&cb_info->msg_recv_running)) {
-               ret = muse_core_ipc_recv_msg(cb_info->fd, recv_msg);
-               if (ret <= 0) {
+               recv_length = muse_core_msg_recv(cb_info->fd, recv_msg);
+               if (recv_length <= 0) {
                        cb_info->is_server_connected = FALSE;
                        LOGE("receive msg failed - server disconnected");
                        break;
                }
 
-               recv_msg[ret] = '\0';
-
-               str_pos = 0;
+               cur_pos = 0;
                prev_pos = 0;
-               num_token = 0;
-
-               /*LOGD("recvMSg : %s, length : %d", recv_msg, ret);*/
-
-               /* Need to split the combined entering msgs.
-                   This module supports up to 20 combined msgs. */
-               for (str_pos = 0; str_pos < ret; str_pos++) {
-                       if (recv_msg[str_pos] == '}') {
-                               msg_length = str_pos - prev_pos + 1;
+               num_msg = 0;
+
+               /*LOGD("recv msg : %s, length : %d", recv_msg, recv_length);*/
+
+               /* Need to split the combined entering msgs */
+               for (cur_pos = 0 ; cur_pos < recv_length ; cur_pos++) {
+                       if (recv_msg[cur_pos] == '}') {
+                               single_length = cur_pos - prev_pos + 1;
+
+                               if (single_length < MUSE_CAMERA_MSG_MAX_LENGTH) {
+                                       /* check remained msg */
+                                       if (remained_length > 0) {
+                                               if (remained_msg) {
+                                                       strncpy(single_msg, remained_msg, remained_length);
+                                                       strncpy(single_msg + remained_length, recv_msg + prev_pos, single_length);
+                                                       single_msg[remained_length + single_length] = '\0';
+
+                                                       free(remained_msg);
+                                                       remained_msg = NULL;
+                                               } else {
+                                                       strncpy(single_msg, recv_msg + prev_pos, single_length);
+                                                       single_msg[single_length] = '\0';
+                                                       LOGE("lost msg [%s], skip...", single_msg);
+                                               }
+
+                                               remained_length = 0;
+                                       } else {
+                                               strncpy(single_msg, recv_msg + prev_pos, single_length);
+                                               single_msg[single_length] = '\0';
+                                       }
 
-                               if (msg_length < MUSE_CAMERA_MSG_MAX_LENGTH) {
-                                       strncpy(parse_str[num_token], recv_msg + prev_pos, msg_length);
-                                       parse_str[num_token][msg_length] = '\0';
-                                       num_token++;
-                                       /*LOGD("splitted msg : [%s], Index : %d", parse_str[num_token], num_token);*/
+                                       if (single_msg[0] == '{') {
+                                               num_msg++;
+                                               /*LOGD("splitted msg : [%s], Index : %d", single_msg, num_msg);*/
+                                               /* process each message */
+                                               __camera_process_msg(cb_info, single_msg);
+                                       } else {
+                                               LOGE("invalid msg [%s]", single_msg);
+                                       }
                                } else {
-                                       LOGW("too long message : length %d [%s]", msg_length, recv_msg + prev_pos);
+                                       LOGE("too long message [len %d] skip...", single_length);
                                }
 
-                               prev_pos = str_pos + 1;
-
-                               if (num_token >= CAMERA_PARSED_STRING_NUM_MAX) {
-                                       LOGE("There's too many tokens. Remained msg : %s", recv_msg[++str_pos]);
-                                       break;
-                               }
+                               prev_pos = cur_pos + 1;
                        }
                }
 
-               /*LOGD("num_token : %d", num_token);*/
+               /* check incompleted message */
+               if (recv_msg[recv_length - 1] != '}') {
+                       remained_length = recv_length - prev_pos;
+
+                       LOGW("incompleted message [len %d]", remained_length);
+
+                       if (remained_msg) {
+                               free(remained_msg);
+                               remained_msg = NULL;
+                       }
 
-               /* process each message */
-               for (i = 0; i < num_token; i++)
-                       __camera_process_msg(cb_info, parse_str[i]);
+                       remained_msg = (char *)malloc(remained_length + 1);
+                       if (remained_msg) {
+                               strncpy(remained_msg, recv_msg + prev_pos, remained_length);
+                               remained_msg[remained_length] = '\0';
+                       } else {
+                               LOGE("failed to alloc for remained msg");
+                       }
+               } else {
+                       remained_length = 0;
+               }
        }
 
        LOGD("client cb exit - server connected %d", cb_info->is_server_connected);
 
        if (!cb_info->is_server_connected) {
                /* send error msg for server disconnection */
-               error_msg = muse_core_msg_json_factory_new(MUSE_CAMERA_CB_EVENT,
+               char *error_msg = muse_core_msg_new(MUSE_CAMERA_CB_EVENT,
                        MUSE_TYPE_INT, "error", CAMERA_ERROR_SERVICE_DISCONNECTED,
                        MUSE_TYPE_INT, "current_state", CAMERA_STATE_NONE,
                        NULL);
+
                if (!error_msg) {
                        LOGE("error_msg failed");
                        goto CB_HANDLER_EXIT;
@@ -2034,23 +2169,21 @@ static void *_camera_msg_recv_func(gpointer data)
                        MUSE_CAMERA_EVENT_CLASS_THREAD_MAIN,
                        error_msg);
 
-               muse_core_msg_json_factory_free(error_msg);
+               muse_core_msg_free(error_msg);
                error_msg = NULL;
 
                LOGE("add error msg for service disconnection done");
        }
 
 CB_HANDLER_EXIT:
-       if (parse_str) {
-               for (i = 0 ; i < CAMERA_PARSED_STRING_NUM_MAX ; i++) {
-                       if (parse_str[i]) {
-                               free(parse_str[i]);
-                               parse_str[i] = NULL;
-                       }
-               }
+       if (single_msg) {
+               free(single_msg);
+               single_msg = NULL;
+       }
 
-               free(parse_str);
-               parse_str = NULL;
+       if (remained_msg) {
+               free(remained_msg);
+               remained_msg = NULL;
        }
 
        return NULL;
@@ -2124,7 +2257,6 @@ static void __destroy_msg_handler_thread(camera_msg_handler_info_s *handler_info
        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);
@@ -2151,6 +2283,8 @@ static camera_cb_info_s *_camera_client_callback_new(gint sockfd)
                goto ErrorExit;
        }
 
+       cb_info->api_waiting[MUSE_CAMERA_API_CREATE] = 1;
+
        for (i = 0 ; i < MUSE_CAMERA_API_MAX ; i++) {
                g_mutex_init(&cb_info->api_mutex[i]);
                g_cond_init(&cb_info->api_cond[i]);
@@ -2164,6 +2298,9 @@ static camera_cb_info_s *_camera_client_callback_new(gint sockfd)
        g_mutex_init(&cb_info->evas_mutex);
 #endif /* TIZEN_FEATURE_EVAS_RENDERER */
 
+       for (i = 0 ; i < MUSE_CAMERA_EVENT_TYPE_NUM ; i++)
+               g_mutex_init(&cb_info->user_cb_mutex[i]);
+
        /* message handler thread */
        if (!__create_msg_handler_thread(&cb_info->msg_handler_info,
                CAMERA_MESSAGE_HANDLER_TYPE_GENERAL, "camera_msg_handler", cb_info)) {
@@ -2210,6 +2347,9 @@ ErrorExit:
                __destroy_msg_handler_thread(&cb_info->preview_cb_info);
                __destroy_msg_handler_thread(&cb_info->capture_cb_info);
 
+               for (i = 0 ; i < MUSE_CAMERA_EVENT_TYPE_NUM ; i++)
+                       g_mutex_clear(&cb_info->user_cb_mutex[i]);
+
                g_mutex_clear(&cb_info->fd_lock);
                g_mutex_clear(&cb_info->idle_event_mutex);
                g_cond_clear(&cb_info->idle_event_cond);
@@ -2239,7 +2379,6 @@ static void _camera_client_callback_destroy(camera_cb_info_s *cb_info)
        LOGD("msg_recv thread[%p] destroy", cb_info->msg_recv_thread);
 
        g_thread_join(cb_info->msg_recv_thread);
-       g_thread_unref(cb_info->msg_recv_thread);
        cb_info->msg_recv_thread = NULL;
 
        LOGD("msg_recv thread removed");
@@ -2249,6 +2388,9 @@ static void _camera_client_callback_destroy(camera_cb_info_s *cb_info)
        __destroy_msg_handler_thread(&cb_info->preview_cb_info);
        __destroy_msg_handler_thread(&cb_info->capture_cb_info);
 
+       for (i = 0 ; i < MUSE_CAMERA_EVENT_TYPE_NUM ; i++)
+               g_mutex_clear(&cb_info->user_cb_mutex[i]);
+
        g_mutex_clear(&cb_info->fd_lock);
        g_mutex_clear(&cb_info->idle_event_mutex);
        g_cond_clear(&cb_info->idle_event_cond);
@@ -2263,7 +2405,7 @@ static void _camera_client_callback_destroy(camera_cb_info_s *cb_info)
        }
 
        if (cb_info->fd > -1) {
-               muse_core_connection_close(cb_info->fd);
+               muse_client_close(cb_info->fd);
                cb_info->fd = -1;
        }
 
@@ -2376,13 +2518,13 @@ int _camera_independent_request(int api, int device_type, const char *key, int *
                return CAMERA_ERROR_INVALID_PARAMETER;
        }
 
-       sock_fd = muse_core_client_new();
+       sock_fd = muse_client_new();
        if (sock_fd < 0) {
-               LOGE("muse_core_client_new failed");
+               LOGE("muse_client_new failed");
                return CAMERA_ERROR_INVALID_OPERATION;
        }
 
-       msg = muse_core_msg_json_factory_new(api,
+       msg = muse_core_msg_new(api,
                MUSE_TYPE_INT, "module", MUSE_CAMERA,
                MUSE_TYPE_INT, PARAM_DEVICE_TYPE, device_type,
                0);
@@ -2392,9 +2534,9 @@ int _camera_independent_request(int api, int device_type, const char *key, int *
                goto _REQUEST_EXIT;
        }
 
-       ret = muse_core_ipc_send_msg(sock_fd, msg);
+       ret = muse_core_msg_send(sock_fd, msg);
 
-       muse_core_msg_json_factory_free(msg);
+       muse_core_msg_free(msg);
        msg = NULL;
 
        if (ret < 0) {
@@ -2403,7 +2545,7 @@ int _camera_independent_request(int api, int device_type, const char *key, int *
                goto _REQUEST_EXIT;
        }
 
-       ret = muse_core_ipc_recv_msg(sock_fd, recv_msg);
+       ret = muse_core_msg_recv(sock_fd, recv_msg);
        if (ret <= 0) {
                LOGE("recv msg failed %d", errno);
                ret = CAMERA_ERROR_INVALID_OPERATION;
@@ -2417,13 +2559,13 @@ int _camera_independent_request(int api, int device_type, const char *key, int *
        }
 
        if (ret == CAMERA_ERROR_NONE)
-               muse_core_msg_json_deserialize(key, recv_msg, NULL, value, NULL, MUSE_TYPE_ANY);
+               muse_core_msg_deserialize(key, recv_msg, NULL, NULL, MUSE_TYPE_ANY, value);
 
        LOGD("api %d - value %d", api, *value);
 
 _REQUEST_EXIT:
        if (sock_fd > -1) {
-               muse_core_connection_close(sock_fd);
+               muse_client_close(sock_fd);
                sock_fd = -1;
        }
 
@@ -2450,16 +2592,16 @@ int camera_create(camera_device_e device, camera_h *camera)
                return CAMERA_ERROR_INVALID_PARAMETER;
        }
 
-       sock_fd = muse_core_client_new();
+       sock_fd = muse_client_new();
        if (sock_fd < 0) {
-               LOGE("muse_core_client_new failed - returned fd %d", sock_fd);
+               LOGE("muse_client_new failed - returned fd %d", sock_fd);
                ret = CAMERA_ERROR_INVALID_OPERATION;
                goto ErrorExit;
        }
 
        pid = getpid();
 
-       send_msg = muse_core_msg_json_factory_new(api,
+       send_msg = muse_core_msg_new(api,
                MUSE_TYPE_INT, "module", muse_module,
                MUSE_TYPE_INT, PARAM_DEVICE_TYPE, device_type,
                MUSE_TYPE_INT, "pid", pid,
@@ -2471,9 +2613,9 @@ int camera_create(camera_device_e device, camera_h *camera)
                goto ErrorExit;
        }
 
-       send_ret = muse_core_ipc_send_msg(sock_fd, send_msg);
+       send_ret = muse_core_msg_send(sock_fd, send_msg);
 
-       muse_core_msg_json_factory_free(send_msg);
+       muse_core_msg_free(send_msg);
        send_msg = NULL;
 
        if (send_ret < 0) {
@@ -2508,6 +2650,9 @@ int camera_create(camera_device_e device, camera_h *camera)
        LOGD("cb info : %d", pc->cb_info->fd);
 
        ret = _camera_client_wait_for_cb_return(api, pc->cb_info, CAMERA_CB_TIMEOUT);
+
+       pc->cb_info->api_waiting[MUSE_CAMERA_API_CREATE] = 0;
+
        if (ret == CAMERA_ERROR_NONE) {
                intptr_t handle = 0;
                muse_camera_msg_get_pointer(handle, pc->cb_info->recv_msg);
@@ -2541,7 +2686,7 @@ ErrorExit:
        }
 
        if (sock_fd > -1) {
-               muse_core_connection_close(sock_fd);
+               muse_client_close(sock_fd);
                sock_fd = -1;
        }
 
@@ -2562,6 +2707,7 @@ ErrorExit:
 
 int camera_change_device(camera_h camera, camera_device_e device)
 {
+       int i = 0;
        int ret = CAMERA_ERROR_NONE;
        muse_camera_api_e api = MUSE_CAMERA_API_CHANGE_DEVICE;
        camera_cli_s *pc = (camera_cli_s *)camera;
@@ -2576,6 +2722,15 @@ int camera_change_device(camera_h camera, camera_device_e device)
 
        _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
 
+       if (ret == CAMERA_ERROR_NONE) {
+               /* reset callback and user data */
+               for (i = 0 ; i < MUSE_CAMERA_EVENT_TYPE_NUM ; i++) {
+                       pc->cb_info->user_cb[i] = NULL;
+                       pc->cb_info->user_data[i] = NULL;
+               }
+               UNSET_PREVIEW_CB_TYPE(pc->cb_info, PREVIEW_CB_TYPE_USER);
+       }
+
        return ret;
 }
 
@@ -2599,7 +2754,7 @@ int camera_destroy(camera_h camera)
                LOGW("server disconnected. release resource without send message.");
 
        if (ret == CAMERA_ERROR_NONE) {
-               _camera_remove_idle_event_all(pc->cb_info);
+               _camera_deactivate_idle_event_all(pc->cb_info);
                _camera_client_callback_destroy(pc->cb_info);
                pc->cb_info = NULL;
 
@@ -2623,7 +2778,7 @@ int camera_start_preview(camera_h camera)
 
        LOGD("Enter");
 
-       _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT_LONG);
+       _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_NO_TIMEOUT);
        if (ret == CAMERA_ERROR_NONE && CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
                ret = _camera_start_evas_rendering(camera);
                if (ret != CAMERA_ERROR_NONE) {
@@ -2900,11 +3055,17 @@ int camera_start_face_detection(camera_h camera, camera_face_detected_cb callbac
 
        LOGD("Enter");
 
-       pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION] = callback;
-       pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION] = user_data;
-
        _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
 
+       if (ret == CAMERA_ERROR_NONE) {
+               g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION]);
+
+               pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION] = callback;
+               pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION] = user_data;
+
+               g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION]);
+       }
+
        LOGD("ret : 0x%x", ret);
 
        return ret;
@@ -2925,6 +3086,15 @@ int camera_stop_face_detection(camera_h camera)
 
        _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
 
+       if (ret == CAMERA_ERROR_NONE) {
+               g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION]);
+
+               pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION] = NULL;
+               pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION] = NULL;
+
+               g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION]);
+       }
+
        LOGD("ret : 0x%x", ret);
 
        return ret;
@@ -3133,7 +3303,7 @@ int camera_set_display(camera_h camera, camera_display_type_e type, camera_displ
                length = sizeof(camera_wl_info_s) / sizeof(int) + \
                        (sizeof(camera_wl_info_s) % sizeof(int) ? 1 : 0);
 
-               msg = muse_core_msg_json_factory_new(api,
+               msg = muse_core_msg_new(api,
                        MUSE_TYPE_INT, "type", type,
                        MUSE_TYPE_ARRAY, "wl_info", length, (int *)&pc->wl_info,
                        NULL);
@@ -3143,8 +3313,10 @@ int camera_set_display(camera_h camera, camera_display_type_e type, camera_displ
                }
 
                if (pc->cb_info->is_server_connected) {
+                       __camera_update_api_waiting(pc->cb_info, api, 1);
+
                        g_mutex_lock(&pc->cb_info->fd_lock);
-                       send_ret = muse_core_ipc_send_msg(pc->cb_info->fd, msg);
+                       send_ret = muse_core_msg_send(pc->cb_info->fd, msg);
                        g_mutex_unlock(&pc->cb_info->fd_lock);
                }
 
@@ -3155,7 +3327,9 @@ int camera_set_display(camera_h camera, camera_display_type_e type, camera_displ
                        ret = _camera_client_wait_for_cb_return(api, pc->cb_info, CAMERA_CB_TIMEOUT);
                }
 
-               muse_core_msg_json_factory_free(msg);
+               __camera_update_api_waiting(pc->cb_info, api, -1);
+
+               muse_core_msg_free(msg);
 
                LOGD("wayland parent id : %d, window %d,%d,%dx%d",
                        pc->wl_info.parent_id, pc->wl_info.window_x, pc->wl_info.window_y,
@@ -3178,6 +3352,7 @@ int camera_set_display(camera_h camera, camera_display_type_e type, camera_displ
 int camera_set_preview_resolution(camera_h camera, int width, int height)
 {
        int ret = CAMERA_ERROR_NONE;
+       camera_state_e current_state = CAMERA_STATE_NONE;
        camera_cli_s *pc = (camera_cli_s *)camera;
        muse_camera_api_e api = MUSE_CAMERA_API_SET_PREVIEW_RESOLUTION;
        camera_msg_param param;
@@ -3188,6 +3363,20 @@ int camera_set_preview_resolution(camera_h camera, int width, int height)
                return CAMERA_ERROR_INVALID_PARAMETER;
        }
 
+       if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
+               ret = camera_get_state(camera, &current_state);
+               if (ret != CAMERA_ERROR_NONE) {
+                       LOGE("failed to get current state 0x%x", ret);
+                       return ret;
+               }
+
+               if (current_state == CAMERA_STATE_PREVIEW) {
+                       ret = _camera_stop_evas_rendering(camera, true);
+                       if (ret != CAMERA_ERROR_NONE)
+                               return ret;
+               }
+       }
+
        value = (width << 16) | height;
        CAMERA_MSG_PARAM_SET(param, INT, value);
 
@@ -3197,6 +3386,11 @@ int camera_set_preview_resolution(camera_h camera, int width, int height)
 
        LOGD("ret : 0x%x", ret);
 
+       if (current_state == CAMERA_STATE_PREVIEW) {
+               LOGW("restart evas rendering");
+               _camera_start_evas_rendering(camera);
+       }
+
        return ret;
 }
 
@@ -3677,8 +3871,13 @@ int camera_set_preview_cb(camera_h camera, camera_preview_cb callback, void *use
        _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
 
        if (ret == CAMERA_ERROR_NONE) {
+               g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
+
                pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW] = callback;
                pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_PREVIEW] = user_data;
+
+               g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
+
                SET_PREVIEW_CB_TYPE(pc->cb_info, PREVIEW_CB_TYPE_USER);
        }
 
@@ -3701,12 +3900,18 @@ int camera_unset_preview_cb(camera_h camera)
 
        LOGD("Enter");
 
-       pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW] = NULL;
-       pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_PREVIEW] = NULL;
+       _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
+
+       if (ret == CAMERA_ERROR_NONE) {
+               g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
 
-       UNSET_PREVIEW_CB_TYPE(pc->cb_info, PREVIEW_CB_TYPE_USER);
+               pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW] = NULL;
+               pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_PREVIEW] = NULL;
 
-       _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
+               g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
+
+               UNSET_PREVIEW_CB_TYPE(pc->cb_info, PREVIEW_CB_TYPE_USER);
+       }
 
        LOGD("ret : 0x%x", ret);
 
@@ -3740,8 +3945,12 @@ int camera_set_media_packet_preview_cb(camera_h camera, camera_media_packet_prev
        _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
 
        if (ret == CAMERA_ERROR_NONE) {
+               g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
+
                pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = callback;
                pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = user_data;
+
+               g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
        }
 
        LOGD("ret : 0x%x", ret);
@@ -3763,11 +3972,17 @@ int camera_unset_media_packet_preview_cb(camera_h camera)
 
        LOGD("Enter");
 
-       pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = NULL;
-       pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = NULL;
-
        _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
 
+       if (ret == CAMERA_ERROR_NONE) {
+               g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
+
+               pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = NULL;
+               pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] = NULL;
+
+               g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]);
+       }
+
        LOGD("ret : 0x%x", ret);
 
        return ret;
@@ -3790,8 +4005,12 @@ int camera_set_state_changed_cb(camera_h camera, camera_state_changed_cb callbac
        _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
 
        if (ret == CAMERA_ERROR_NONE) {
+               g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE]);
+
                pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE] = callback;
                pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE] = user_data;
+
+               g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE]);
        }
 
        LOGD("ret : 0x%x", ret);
@@ -3813,11 +4032,17 @@ int camera_unset_state_changed_cb(camera_h camera)
 
        LOGD("Enter");
 
-       pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE] = NULL;
-       pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE] = NULL;
-
        _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
 
+       if (ret == CAMERA_ERROR_NONE) {
+               g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE]);
+
+               pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE] = NULL;
+               pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE] = NULL;
+
+               g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_STATE_CHANGE]);
+       }
+
        LOGD("ret : 0x%x", ret);
 
        return ret;
@@ -3840,8 +4065,12 @@ int camera_set_interrupted_cb(camera_h camera, camera_interrupted_cb callback, v
        _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
 
        if (ret == CAMERA_ERROR_NONE) {
+               g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED]);
+
                pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED] = callback;
                pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED] = user_data;
+
+               g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED]);
        }
 
        LOGD("ret : 0x%x", ret);
@@ -3863,11 +4092,77 @@ int camera_unset_interrupted_cb(camera_h camera)
 
        LOGD("Enter");
 
-       pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED] = NULL;
-       pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED] = NULL;
+       _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
+
+       if (ret == CAMERA_ERROR_NONE) {
+               g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED]);
+
+               pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED] = NULL;
+               pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED] = NULL;
+
+               g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPTED]);
+       }
+
+       LOGD("ret : 0x%x", ret);
+
+       return ret;
+}
+
+
+int camera_set_interrupt_started_cb(camera_h camera, camera_interrupt_started_cb callback, void *user_data)
+{
+       int ret = CAMERA_ERROR_NONE;
+       camera_cli_s *pc = (camera_cli_s *)camera;
+       muse_camera_api_e api = MUSE_CAMERA_API_SET_INTERRUPT_STARTED_CB;
+
+       if (!pc || !pc->cb_info || !callback) {
+               LOGE("NULL pointer %p %p", pc, callback);
+               return CAMERA_ERROR_INVALID_PARAMETER;
+       }
+
+       LOGD("Enter");
+
+       _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
+
+       if (ret == CAMERA_ERROR_NONE) {
+               g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED]);
+
+               pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = callback;
+               pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = user_data;
+
+               g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED]);
+       }
+
+       LOGD("ret : 0x%x", ret);
+
+       return ret;
+}
+
+
+int camera_unset_interrupt_started_cb(camera_h camera)
+{
+       int ret = CAMERA_ERROR_NONE;
+       camera_cli_s *pc = (camera_cli_s *)camera;
+       muse_camera_api_e api = MUSE_CAMERA_API_UNSET_INTERRUPT_STARTED_CB;
+
+       if (!pc || !pc->cb_info) {
+               LOGE("NULL handle");
+               return CAMERA_ERROR_INVALID_PARAMETER;
+       }
+
+       LOGD("Enter");
 
        _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
 
+       if (ret == CAMERA_ERROR_NONE) {
+               g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED]);
+
+               pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = NULL;
+               pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED] = NULL;
+
+               g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_INTERRUPT_STARTED]);
+       }
+
        LOGD("ret : 0x%x", ret);
 
        return ret;
@@ -3890,8 +4185,12 @@ int camera_set_focus_changed_cb(camera_h camera, camera_focus_changed_cb callbac
        _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
 
        if (ret == CAMERA_ERROR_NONE) {
+               g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE]);
+
                pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = callback;
                pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = user_data;
+
+               g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE]);
        }
 
        LOGD("ret : 0x%x", ret);
@@ -3913,11 +4212,17 @@ int camera_unset_focus_changed_cb(camera_h camera)
 
        LOGD("Enter");
 
-       pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = NULL;
-       pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = NULL;
-
        _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
 
+       if (ret == CAMERA_ERROR_NONE) {
+               g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE]);
+
+               pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = NULL;
+               pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE] = NULL;
+
+               g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_FOCUS_CHANGE]);
+       }
+
        LOGD("ret : 0x%x", ret);
 
        return ret;
@@ -3940,8 +4245,12 @@ int camera_set_error_cb(camera_h camera, camera_error_cb callback, void *user_da
        _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
 
        if (ret == CAMERA_ERROR_NONE) {
+               g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_ERROR]);
+
                pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_ERROR] = callback;
                pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_ERROR] = user_data;
+
+               g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_ERROR]);
        }
 
        LOGD("ret : 0x%x", ret);
@@ -3963,11 +4272,17 @@ int camera_unset_error_cb(camera_h camera)
 
        LOGD("Enter");
 
-       pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_ERROR] = NULL;
-       pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_ERROR] = NULL;
-
        _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
 
+       if (ret == CAMERA_ERROR_NONE) {
+               g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_ERROR]);
+
+               pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_ERROR] = NULL;
+               pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_ERROR] = NULL;
+
+               g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_ERROR]);
+       }
+
        LOGD("ret : 0x%x", ret);
 
        return ret;
@@ -4796,7 +5111,7 @@ int camera_attr_set_geotag(camera_h camera, double latitude, double longitude, d
        length = sizeof(set_geotag) / sizeof(int) + \
                (sizeof(set_geotag) % sizeof(int) ? 1 : 0);
 
-       msg = muse_core_msg_json_factory_new(api,
+       msg = muse_core_msg_new(api,
                MUSE_TYPE_ARRAY, "set_geotag", length, (int *)set_geotag,
                NULL);
        if (!msg) {
@@ -4805,8 +5120,10 @@ int camera_attr_set_geotag(camera_h camera, double latitude, double longitude, d
        }
 
        if (pc->cb_info->is_server_connected) {
+               __camera_update_api_waiting(pc->cb_info, api, 1);
+
                g_mutex_lock(&pc->cb_info->fd_lock);
-               send_ret = muse_core_ipc_send_msg(pc->cb_info->fd, msg);
+               send_ret = muse_core_msg_send(pc->cb_info->fd, msg);
                g_mutex_unlock(&pc->cb_info->fd_lock);
        }
 
@@ -4817,7 +5134,9 @@ int camera_attr_set_geotag(camera_h camera, double latitude, double longitude, d
                ret = _camera_client_wait_for_cb_return(api, pc->cb_info, CAMERA_CB_TIMEOUT);
        }
 
-       muse_core_msg_json_factory_free(msg);
+       __camera_update_api_waiting(pc->cb_info, api, -1);
+
+       muse_core_msg_free(msg);
 
        LOGD("ret : 0x%x", ret);
 
@@ -5851,11 +6170,17 @@ int camera_attr_set_hdr_capture_progress_cb(camera_h camera, camera_attr_hdr_pro
                return CAMERA_ERROR_INVALID_PARAMETER;
        }
 
-       pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = callback;
-       pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = user_data;
-
        _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
 
+       if (ret == CAMERA_ERROR_NONE) {
+               g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS]);
+
+               pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = callback;
+               pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = user_data;
+
+               g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS]);
+       }
+
        LOGD("ret : 0x%x", ret);
 
        return ret;
@@ -5875,11 +6200,17 @@ int camera_attr_unset_hdr_capture_progress_cb(camera_h camera)
 
        LOGD("Enter");
 
-       pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = NULL;
-       pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = NULL;
-
        _camera_msg_send(api, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
 
+       if (ret == CAMERA_ERROR_NONE) {
+               g_mutex_lock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS]);
+
+               pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = NULL;
+               pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS] = NULL;
+
+               g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_HDR_PROGRESS]);
+       }
+
        LOGD("ret : 0x%x", ret);
 
        return ret;
@@ -6194,7 +6525,7 @@ int camera_attr_get_pan_range(camera_h camera, int *min, int *max)
        muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_PAN_RANGE;
 
        if (!pc || !pc->cb_info || !min || !max) {
-               LOGE("NULL pointer %p %p", pc, min, max);
+               LOGE("NULL pointer %p %p %p", pc, min, max);
                return CAMERA_ERROR_INVALID_PARAMETER;
        }
 
@@ -6374,7 +6705,7 @@ int camera_attr_set_display_roi_area(camera_h camera, int x, int y, int width, i
        length = sizeof(set_display_roi_area) / sizeof(int) + \
                (sizeof(set_display_roi_area) % sizeof(int) ? 1 : 0);
 
-       msg = muse_core_msg_json_factory_new(api,
+       msg = muse_core_msg_new(api,
                MUSE_TYPE_ARRAY, "set_display_roi_area", length, (int *)set_display_roi_area,
                NULL);
        if (!msg) {
@@ -6383,8 +6714,10 @@ int camera_attr_set_display_roi_area(camera_h camera, int x, int y, int width, i
        }
 
        if (pc->cb_info->is_server_connected) {
+               __camera_update_api_waiting(pc->cb_info, api, 1);
+
                g_mutex_lock(&pc->cb_info->fd_lock);
-               send_ret = muse_core_ipc_send_msg(pc->cb_info->fd, msg);
+               send_ret = muse_core_msg_send(pc->cb_info->fd, msg);
                g_mutex_unlock(&pc->cb_info->fd_lock);
        }
 
@@ -6395,7 +6728,9 @@ int camera_attr_set_display_roi_area(camera_h camera, int x, int y, int width, i
                ret = _camera_client_wait_for_cb_return(api, pc->cb_info, CAMERA_CB_TIMEOUT);
        }
 
-       muse_core_msg_json_factory_free(msg);
+       __camera_update_api_waiting(pc->cb_info, api, -1);
+
+       muse_core_msg_free(msg);
 
        LOGD("ret : 0x%x", ret);