Add sub functions to remove duplicated code
[platform/core/api/camera.git] / src / camera.c
index 4ffe0ed..f061b94 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 #include <mm.h>
 #include <mm_types.h>
+#include <mm_camcorder.h>
 #include <muse_camera_msg.h>
 #include <camera_private.h>
 #include <muse_client.h>
-#include <dlog.h>
 #include <gio/gio.h>
+#include <dlfcn.h>
 
 #ifdef LOG_TAG
 #undef LOG_TAG
@@ -32,6 +34,7 @@
 #define LOG_TAG         "TIZEN_N_CAMERA"
 #define MODULE_NAME     "camera"
 
+
 /* for device changed callback */
 static GMutex g_cam_dev_state_changed_cb_lock;
 static GList *g_cam_dev_state_changed_cb_list;
@@ -41,27 +44,28 @@ static guint g_cam_dev_state_changed_cb_subscribe_id;
 static GMutex g_cam_idle_event_lock;
 
 /* log level */
-int g_mmcam_log_level;
-
-static void _camera_msg_send(int api, int *fds, 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 void _camera_msg_send_param2_int(int api, camera_cb_info_s *cb_info,
-       int *ret, camera_msg_param *param0, camera_msg_param *param1, int timeout);
-static void _camera_msg_return_buffer(int ret_fd, camera_cb_info_s *cb_info);
-static bool _camera_import_tbm_fd(tbm_bufmgr bufmgr, int fd, tbm_bo *bo, tbm_bo_handle *bo_handle);
-static void _camera_release_imported_bo(tbm_bo *bo);
-static int _camera_media_packet_create(camera_cb_info_s *cb_info, camera_stream_data_s *stream,
+static int g_camera_log_level = CAMERA_LOG_LEVEL_INFO;
+
+static bool __camera_import_tbm_fd(tbm_bufmgr bufmgr, int fd, tbm_bo *bo, tbm_bo_handle *bo_handle);
+static void __camera_release_imported_bo(tbm_bo *bo);
+
+static int __camera_create_media_packet(camera_cb_info_s *cb_info, MMCamcorderVideoStreamDataType *stream,
        camera_media_packet_data *mp_data, media_packet_h *packet);
-static int _camera_media_packet_data_create(int ret_fd, int *tfd, int num_buffer_fd, tbm_bo bo,
+static int __camera_create_media_packet_data(int ret_fd, int *tfd, int num_buffer_fd, 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 gboolean _camera_allocate_preview_buffer(camera_h camera);
-static void _camera_release_preview_buffer(camera_h camera);
+static void __camera_release_media_packet_data(camera_media_packet_data *mp_data, camera_cb_info_s *cb_info);
+
+static gboolean __camera_allocate_preview_buffer(camera_h camera);
+static void __camera_release_preview_buffer(camera_h camera);
+static void __camera_release_tfd(int tfd[MUSE_NUM_FD]);
+
+static bool __create_msg_handler_thread(camera_msg_handler_info_s *handler_info,
+       int type, const char *thread_name, camera_cb_info_s *cb_info);
+static void __destroy_msg_handler_thread(camera_msg_handler_info_s *handler_info);
 
 
-static gboolean _camera_allocate_preview_buffer(camera_h camera)
+//LCOV_EXCL_START
+static gboolean __camera_allocate_preview_buffer(camera_h camera)
 {
        int i = 0;
        int ret = CAMERA_ERROR_NONE;
@@ -72,10 +76,7 @@ static gboolean _camera_allocate_preview_buffer(camera_h camera)
        camera_cli_s *pc = (camera_cli_s *)camera;
        camera_cb_info_s *cb_info = NULL;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("invalid pointer %p %p", pc, pc ? pc->cb_info : NULL);
-               return FALSE;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, FALSE);
 
        cb_info = pc->cb_info;
 
@@ -136,21 +137,18 @@ static gboolean _camera_allocate_preview_buffer(camera_h camera)
        return TRUE;
 
 _ALLOCATE_PREVIEW_BUFFER_FAILED:
-       _camera_release_preview_buffer(camera);
+       __camera_release_preview_buffer(camera);
        return FALSE;
 }
 
 
-static void _camera_release_preview_buffer(camera_h camera)
+static void __camera_release_preview_buffer(camera_h camera)
 {
        int i = 0;
        camera_cli_s *pc = (camera_cli_s *)camera;
        camera_cb_info_s *cb_info = NULL;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("invalid pointer %p %p", pc, pc ? pc->cb_info : NULL);
-               return;
-       }
+       CAMERA_CHECK_HANDLE_RETURN(pc);
 
        CAM_LOG_INFO("Enter");
 
@@ -167,19 +165,36 @@ static void _camera_release_preview_buffer(camera_h camera)
                        break;
                }
 
-               if (cb_info->fds[i] >= 0) {
+               if (CAMERA_IS_FD_VALID(cb_info->fds[i])) {
                        close(cb_info->fds[i]);
-                       cb_info->fds[i] = -1;
+                       cb_info->fds[i] = CAMERA_FD_INIT;
                }
        }
 
        CAM_LOG_INFO("Done");
+}
+//LCOV_EXCL_STOP
+
+static void __camera_release_tfd(int tfd[MUSE_NUM_FD])
+{
+       int i;
+
+       if (!tfd) {
+               CAM_LOG_WARNING("NULL tfd");
+               return;
+       }
+
+       for (i = 0 ; i < MUSE_NUM_FD ; i++) {
+               if (!CAMERA_IS_FD_VALID(tfd[i]))
+                       break;
 
-       return;
+               close(tfd[i]);
+               tfd[i] = CAMERA_FD_INIT;
+       }
 }
 
 
-static void __camera_update_api_waiting(camera_cb_info_s *cb_info, int api, int value)
+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) {
@@ -193,8 +208,6 @@ static void __camera_update_api_waiting(camera_cb_info_s *cb_info, int api, int
 
        CAM_LOG_DEBUG("api[%d], value[%d], waiting[%d]",
                api, value, cb_info->api_waiting[api]);
-
-       return;
 }
 
 
@@ -243,8 +256,88 @@ static void __camera_device_state_changed_cb(GDBusConnection *connection,
 
 _DONE:
        g_mutex_unlock(&g_cam_dev_state_changed_cb_lock);
+}
+
+
+static void __camera_preview_cb_monitoring_info_sub_reset(monitoring_info_sub_s *info_sub)
+{
+       if (!info_sub) {
+               CAM_LOG_ERROR("NULL info_sub");
+               return;
+       }
+
+       info_sub->frame_count = 0;
+       info_sub->elapsed_sec_accum = 0.0;
+       info_sub->elapsed_sec_peak = 0.0;
+}
+
+
+static void __camera_preview_cb_monitoring_info_reset(camera_preview_cb_monitoring_info_s *info)
+{
+       if (!info) {
+               CAM_LOG_ERROR("NULL info");
+               return;
+       }
+
+       __camera_preview_cb_monitoring_info_sub_reset(info->total);
+       __camera_preview_cb_monitoring_info_sub_reset(info->interval);
+}
+
+
+static void __camera_preview_cb_monitoring_info_start(camera_preview_cb_monitoring_info_s *info)
+{
+       if (!info) {
+               CAM_LOG_ERROR("NULL info");
+               return;
+       }
+
+       g_timer_start(info->timer_calling);
+
+       if (info->interval->frame_count == 0)
+               g_timer_start(info->timer_interval);
+}
+
+
+static void __camera_preview_cb_monitoring_info_sub_update(monitoring_info_sub_s *info_sub, gdouble elapsed_sec)
+{
+       if (!info_sub) {
+               CAM_LOG_ERROR("NULL info_sub");
+               return;
+       }
+
+       info_sub->frame_count++;
+       info_sub->elapsed_sec_accum += elapsed_sec;
+
+       if (info_sub->elapsed_sec_peak < elapsed_sec)
+               info_sub->elapsed_sec_peak = elapsed_sec;
+}
+
+
+static void __camera_preview_cb_monitoring_info_end(camera_preview_cb_monitoring_info_s *info)
+{
+       gdouble elapsed_sec = 0.0;
+       gdouble elapsed_sec_interval = 0.0;
+
+       if (!info) {
+               CAM_LOG_ERROR("NULL info");
+               return;
+       }
+
+       elapsed_sec = g_timer_elapsed(info->timer_calling, NULL);
+       elapsed_sec_interval = g_timer_elapsed(info->timer_interval, NULL);
+
+       __camera_preview_cb_monitoring_info_sub_update(info->total, elapsed_sec);
+       __camera_preview_cb_monitoring_info_sub_update(info->interval, elapsed_sec);
 
-       return;
+       if (elapsed_sec_interval >= 1.0) {
+               CAM_LOG_INFO("id[%d], frame count[t:%llu,i:%llu], elapsed - avg[t:%dms,i:%dms], peak[t:%dms,i:%dms]",
+                       info->stream_id, info->total->frame_count, info->interval->frame_count,
+                       (int)((info->total->elapsed_sec_accum / (gdouble)info->total->frame_count) * 1000),
+                       (int)((info->interval->elapsed_sec_accum / (gdouble)info->interval->frame_count) * 1000),
+                       (int)(info->total->elapsed_sec_peak * 1000), (int)(info->interval->elapsed_sec_peak * 1000));
+
+               __camera_preview_cb_monitoring_info_sub_reset(info->interval);
+       }
 }
 
 
@@ -252,8 +345,8 @@ static void __camera_event_handler_preview(camera_cb_info_s *cb_info, char *recv
 {
        int i = 0;
        int ret = 0;
-       int ret_fd = -1;
-       int preview_fd = -1;
+       int ret_fd = CAMERA_FD_INIT;
+       int preview_fd = CAMERA_FD_INIT;
        int num_buffer_fd = 0;
        unsigned char *buf_pos = NULL;
 
@@ -266,10 +359,10 @@ static void __camera_event_handler_preview(camera_cb_info_s *cb_info, char *recv
 
        camera_msg_param param;
        camera_preview_data_s frame;
-       camera_stream_data_s *stream = NULL;
+       MMCamcorderVideoStreamDataType *stream = NULL;
        camera_media_packet_data *mp_data = NULL;
        media_packet_h pkt = NULL;
-       media_packet_h pkt_evas = NULL;
+       camera_preview_cb_monitoring_info_s *monitoring_info = NULL;
 
        /* tfd[0]: MMCamcorderVideoStreamDataType
           tfd[1]: data_bo or zero copy bo[0]
@@ -296,21 +389,18 @@ static void __camera_event_handler_preview(camera_cb_info_s *cb_info, char *recv
        ret_fd = preview_fd;
        CAMERA_MSG_PARAM_SET(param, INT, ret_fd);
 
-       if (num_buffer_fd < 0 || num_buffer_fd > BUFFER_MAX_PLANE_NUM) {
-               CAM_LOG_ERROR("invalid num buffer fd %d", num_buffer_fd);
+       if (cb_info->invoke_preview_cb == FALSE) {
+               CAM_LOG_WARNING("Skip preview callback for fd[%d] due to preview stop.", ret_fd);
                goto _PREVIEW_CB_HANDLER_DONE;
        }
 
-       if (num_buffer_fd == 0 && tfd[1] >= 0) {
-               /* import tbm data_bo and get virtual address */
-               if (!_camera_import_tbm_fd(cb_info->bufmgr, tfd[1], &data_bo, &data_bo_handle)) {
-                       CAM_LOG_ERROR("failed to import data fd %d", tfd[1]);
-                       goto _PREVIEW_CB_HANDLER_DONE;
-               }
+       if (num_buffer_fd < 0 || num_buffer_fd > BUFFER_MAX_PLANE_NUM) {
+               CAM_LOG_ERROR("invalid num buffer fd %d", num_buffer_fd);
+               goto _PREVIEW_CB_HANDLER_DONE;
        }
 
        /* import tbm bo and get virtual address */
-       if (!_camera_import_tbm_fd(cb_info->bufmgr, tfd[0], &bo, &bo_handle)) {
+       if (!__camera_import_tbm_fd(cb_info->bufmgr, tfd[0], &bo, &bo_handle)) {
                CAM_LOG_ERROR("failed to import fd %d", tfd[0]);
                goto _PREVIEW_CB_HANDLER_DONE;
        }
@@ -318,102 +408,167 @@ static void __camera_event_handler_preview(camera_cb_info_s *cb_info, char *recv
        buf_pos = (unsigned char *)bo_handle.ptr;
 
        /* get stream info */
-       stream = (camera_stream_data_s *)buf_pos;
+       stream = (MMCamcorderVideoStreamDataType *)buf_pos;
+
+       CAM_LOG_VERBOSE("meta [%llu] [%llu] [%llu] [%llu] [%llu] [%llu] [%llu] [%llu] [%llu] [%llu] [%llu] [%llu]",
+               stream->frame_meta.ts_soe, stream->frame_meta.ts_eoe,
+               stream->frame_meta.ts_sof, stream->frame_meta.ts_eof,
+               stream->frame_meta.ts_hal, stream->frame_meta.ts_qmf,
+               stream->frame_meta.ts_gst, stream->frame_meta.td_exp,
+               stream->frame_meta.ts_aux, stream->frame_meta.td_aux,
+               stream->frame_meta.seqnum, stream->frame_meta.flags);
 
-       for (i = 0 ; i < num_buffer_fd ; i++) {
-               /* import buffer bo and get virtual address */
-               if (!_camera_import_tbm_fd(cb_info->bufmgr, tfd[i + 1], &buffer_bo[i], &buffer_bo_handle[i])) {
-                       CAM_LOG_ERROR("failed to import buffer fd %d", tfd[i + 1]);
+       if (num_buffer_fd == 0 && CAMERA_IS_FD_VALID(tfd[1])) {
+               /* import tbm data_bo and get virtual address */
+               if (!__camera_import_tbm_fd(cb_info->bufmgr, tfd[1], &data_bo, &data_bo_handle)) {
+                       CAM_LOG_ERROR("failed to import data fd %d", tfd[1]);
                        goto _PREVIEW_CB_HANDLER_DONE;
                }
+
+               if (stream->data_type == MM_CAM_STREAM_DATA_ENCODED)
+                       stream->data.encoded.data = data_bo_handle.ptr;
+       } else {
+               for (i = 0 ; i < num_buffer_fd ; i++) {
+                       /* import buffer bo and get virtual address */
+                       if (!__camera_import_tbm_fd(cb_info->bufmgr, tfd[i + 1], &buffer_bo[i], &buffer_bo_handle[i])) {
+                               CAM_LOG_ERROR("failed to import buffer fd %d", tfd[i + 1]);
+                               goto _PREVIEW_CB_HANDLER_DONE;
+                       }
+               }
+
+               if (stream->data_type == MM_CAM_STREAM_DATA_ENCODED)
+                       stream->data.encoded.data = buffer_bo_handle[0].ptr;
        }
 
-       /* call preview callback */
-       if (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW]) {
+       /* preview callback */
+       if (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW] ||
+               cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW]) {
                camera_create_preview_frame(stream, num_buffer_fd, 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]);
+               /* set stream data for camera_get_preview_frame_rotation() */
+               cb_info->stream_data = stream;
+
+               if (stream->extra_stream_id < 0) {
+                       monitoring_info = cb_info->monitoring_info_preview;
+                       __camera_preview_cb_monitoring_info_start(monitoring_info);
+
+                       if (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW])
+                               ((camera_preview_cb)cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW])(&frame,
+                                       cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
+               } else {
+                       monitoring_info = cb_info->monitoring_info_preview_ex[stream->extra_stream_id];
+                       __camera_preview_cb_monitoring_info_start(monitoring_info);
+
+                       if (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW])
+                               ((camera_extra_preview_cb)cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW])(&frame,
+                                       stream->extra_stream_id, cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW]);
+               }
+
+               __camera_preview_cb_monitoring_info_end(monitoring_info);
+
+               cb_info->stream_data = NULL;
        }
 
-       if (CHECK_PREVIEW_CB(cb_info, PREVIEW_CB_TYPE_EVAS)) {
-               ret = _camera_media_packet_data_create(ret_fd, tfd, num_buffer_fd, bo, buffer_bo, data_bo, &mp_data);
+       if (stream->extra_stream_id >= 0)
+               goto _PREVIEW_CB_HANDLER_DONE;
 
-               if (ret == CAMERA_ERROR_NONE) {
-                       ret = _camera_media_packet_create(cb_info, stream, mp_data, &pkt_evas);
-                       if (ret != CAMERA_ERROR_NONE) {
-                               CAM_LOG_ERROR("create pkt for evas failed");
-                               _camera_media_packet_data_release(mp_data, cb_info);
-                               mp_data = NULL;
-                       }
+       /* make media packet with below cases.
+        * 1. media_packet_preview_cb is set
+        * 2. EVAS display rendering
+        * 3. media bridge is set
+        */
+       if (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW] ||
+               cb_info->is_evas_render ||
+               cb_info->bridge) {
+               ret = __camera_create_media_packet_data(ret_fd, tfd, num_buffer_fd, bo, buffer_bo, data_bo, &mp_data);
+               if (ret != CAMERA_ERROR_NONE) {
+                       CAM_LOG_ERROR("__camera_create_media_packet_data failed[0x%x]", ret);
+                       goto _PREVIEW_CB_HANDLER_DONE;
+               }
+
+               ret = __camera_create_media_packet(cb_info, stream, mp_data, &pkt);
+               if (ret != CAMERA_ERROR_NONE) {
+                       CAM_LOG_ERROR("__camera_create_media_packet failed[0x%x]", ret);
+                       __camera_release_media_packet_data(mp_data, cb_info);
+                       mp_data = NULL;
+                       goto _PREVIEW_CB_HANDLER_DONE;
                }
        }
 
-       /* call media packet callback */
+       /* 1. media packet preview callback */
        if (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]) {
-               ret = _camera_media_packet_data_create(ret_fd, tfd, num_buffer_fd, bo, buffer_bo, data_bo, &mp_data);
+               media_packet_ref(pkt);
 
-               if (ret == CAMERA_ERROR_NONE) {
-                       ret = _camera_media_packet_create(cb_info, stream, mp_data, &pkt);
+               monitoring_info = cb_info->monitoring_info_preview_mp;
+               __camera_preview_cb_monitoring_info_start(monitoring_info);
 
-                       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;
-                       }
-               }
+               ((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]);
+
+               __camera_preview_cb_monitoring_info_end(monitoring_info);
        }
 
-       /* call evas renderer */
-       if (pkt_evas) {
+       /* 2. call evas renderer */
+       if (cb_info->is_evas_render) {
                if (cb_info->run_evas_render) {
-                       mm_display_interface_evas_render(cb_info->dp_interface, pkt_evas);
+                       media_packet_ref(pkt);
+                       ret = mm_display_interface_evas_render(cb_info->dp_interface, pkt);
+                       if (ret != MM_ERROR_NONE) {
+                               CAM_LOG_ERROR("mm_display_interface_evas_render failed[0x%x]", ret);
+                               media_packet_unref(pkt);
+                       }
                } else {
                        CAM_LOG_WARNING("evas renderer is stopped, skip this buffer...");
-                       media_packet_destroy(pkt_evas);
                }
-               pkt_evas = NULL;
        }
 
-       /* 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, NULL, cb_info, NULL, 0);
-
-_PREVIEW_CB_HANDLER_DONE:
-       if (mp_data == NULL) {
-               /* release imported bo */
-               for (i = 0 ; i < num_buffer_fd && i < BUFFER_MAX_PLANE_NUM ; i++)
-                       _camera_release_imported_bo(&buffer_bo[i]);
-
-               /* unmap and unref tbm bo */
-               _camera_release_imported_bo(&data_bo);
-               _camera_release_imported_bo(&bo);
-
-               /* close imported fd */
-               for (i = 0 ; i < MUSE_NUM_FD ; i++) {
-                       if (tfd[i] >= 0) {
-                               close(tfd[i]);
-                               tfd[i] = -1;
-                       } else {
-                               break;
-                       }
+//LCOV_EXCL_START
+       /* 3. media bridge */
+       g_mutex_lock(&cb_info->bridge_lock);
+
+       if (cb_info->bridge) {
+               media_packet_ref(pkt);
+               ret = media_bridge_push_packet(cb_info->bridge, pkt);
+               if (ret != MEDIA_BRIDGE_ERROR_NONE) {
+                       CAM_LOG_ERROR("push packet to bridge failed[0x%x]", ret);
+                       media_packet_unref(pkt);
                }
+       }
+//LCOV_EXCL_STOP
 
-               /* return buffer */
-               _camera_msg_send_param1(MUSE_CAMERA_API_RETURN_BUFFER, cb_info, NULL, &param, 0);
+       g_mutex_unlock(&cb_info->bridge_lock);
+
+_PREVIEW_CB_HANDLER_DONE:
+       /* send PREVIEW_CB_RETURN message if zero copy buffer is used(num_buffer_fd is bigger than 0)
+          and preview callback(normal or media packet) is set. */
+       if (num_buffer_fd > 0 &&
+               (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW] ||
+                cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_MEDIA_PACKET_PREVIEW]))
+               _camera_msg_send(MUSE_CAMERA_API_PREVIEW_CB_RETURN, NULL, cb_info, NULL, 0);
 
-               CAM_LOG_DEBUG("return buffer Done[tfd:%d, ret fd:%d]", tfd[0], ret_fd);
+       if (pkt) {
+               media_packet_unref(pkt);
+               return;
        }
 
-       return;
+       /* return buffer */
+       _camera_msg_send_param1(MUSE_CAMERA_API_RETURN_BUFFER, cb_info, NULL, &param, 0);
+
+       CAM_LOG_DEBUG("return buffer Done[tfd:%d, ret fd:%d]", tfd[0], ret_fd);
+
+       /* release imported bo and fd */
+       __camera_release_imported_bo(&data_bo);
+       __camera_release_imported_bo(&bo);
+
+       for (i = 0 ; i < num_buffer_fd && i < BUFFER_MAX_PLANE_NUM ; i++)
+               __camera_release_imported_bo(&buffer_bo[i]);
+
+       __camera_release_tfd(tfd);
 }
 
 
 static void __camera_event_handler_capture(camera_cb_info_s *cb_info, char *recv_msg, int *tfd)
 {
-       int i = 0;
        int tfd_index = 0;
        int capture_fd_main = 0;
        int capture_fd_post = 0;
@@ -455,7 +610,7 @@ static void __camera_event_handler_capture(camera_cb_info_s *cb_info, char *recv
        }
 
        /* import tbm bo and get virtual address */
-       if (!_camera_import_tbm_fd(cb_info->bufmgr, tfd[tfd_index], &bo_main, &bo_main_handle)) {
+       if (!__camera_import_tbm_fd(cb_info->bufmgr, tfd[tfd_index], &bo_main, &bo_main_handle)) {
                CAM_LOG_ERROR("failed to import fd [%d] for main", tfd[tfd_index]);
                goto _CAPTURE_CB_HANDLER_DONE;
        }
@@ -473,10 +628,11 @@ static void __camera_event_handler_capture(camera_cb_info_s *cb_info, char *recv
        CAM_LOG_INFO("image info %dx%d, size %d, EXIF info %p, size %d",
                rImage->width, rImage->height, rImage->size, rImage->exif, rImage->exif_size);
 
-       if (capture_fd_post >= 0) {
+//LCOV_EXCL_START
+       if (CAMERA_IS_FD_VALID(capture_fd_post)) {
                /* import tbm bo and get virtual address */
                tfd_index++;
-               if (_camera_import_tbm_fd(cb_info->bufmgr, tfd[tfd_index], &bo_post, &bo_post_handle)) {
+               if (__camera_import_tbm_fd(cb_info->bufmgr, tfd[tfd_index], &bo_post, &bo_post_handle)) {
                        buf_pos = (unsigned char *)bo_post_handle.ptr;
                        rPostview = (camera_image_data_s *)buf_pos;
                        CAM_LOG_INFO("rPostview->size : %d", rPostview->size);
@@ -486,10 +642,10 @@ static void __camera_event_handler_capture(camera_cb_info_s *cb_info, char *recv
                }
        }
 
-       if (capture_fd_thumb >= 0) {
+       if (CAMERA_IS_FD_VALID(capture_fd_thumb)) {
                /* import tbm bo and get virtual address */
                tfd_index++;
-               if (_camera_import_tbm_fd(cb_info->bufmgr, tfd[tfd_index], &bo_thumb, &bo_thumb_handle)) {
+               if (__camera_import_tbm_fd(cb_info->bufmgr, tfd[tfd_index], &bo_thumb, &bo_thumb_handle)) {
                        buf_pos = (unsigned char *)bo_thumb_handle.ptr;
                        rThumbnail = (camera_image_data_s *)buf_pos;
                        CAM_LOG_INFO("rThumbnail->size : %d", rThumbnail->size);
@@ -498,47 +654,39 @@ static void __camera_event_handler_capture(camera_cb_info_s *cb_info, char *recv
                        CAM_LOG_ERROR("failed to import fd [%d] for thumbnail", tfd[tfd_index]);
                }
        }
+//LCOV_EXCL_STOP
 
        ((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 (capture_fd_main >= 0) {
-               _camera_release_imported_bo(&bo_main);
+       if (CAMERA_IS_FD_VALID(capture_fd_main)) {
+               __camera_release_imported_bo(&bo_main);
                _camera_msg_return_buffer(capture_fd_main, cb_info);
        }
 
-       if (capture_fd_post >= 0) {
-               _camera_release_imported_bo(&bo_post);
+       if (CAMERA_IS_FD_VALID(capture_fd_post)) {
+               __camera_release_imported_bo(&bo_post);
                _camera_msg_return_buffer(capture_fd_post, cb_info);
        }
 
-       if (capture_fd_thumb >= 0) {
-               _camera_release_imported_bo(&bo_thumb);
+       if (CAMERA_IS_FD_VALID(capture_fd_thumb)) {
+               __camera_release_imported_bo(&bo_thumb);
                _camera_msg_return_buffer(capture_fd_thumb, cb_info);
        }
 
-       for (i = 0 ; i < MUSE_NUM_FD ; i++) {
-               if (tfd[i] >= 0) {
-                       CAM_LOG_INFO("close %d", tfd[i]);
-                       close(tfd[i]);
-                       tfd[i] = -1;
-               } else {
-                       break;
-               }
-       }
+       __camera_release_tfd(tfd);
 
        CAM_LOG_INFO("return buffer done");
-
-       return;
 }
 
 
+//LCOV_EXCL_START
 static void __camera_event_handler_face_detection(camera_cb_info_s *cb_info, char *recv_msg, int *tfd)
 {
        int count = 0;
-       int face_fd = -1;
+       int face_fd = CAMERA_FD_INIT;
        camera_detected_face_s *faces = NULL;
 
        tbm_bo bo = NULL;
@@ -555,21 +703,21 @@ static void __camera_event_handler_face_detection(camera_cb_info_s *cb_info, cha
        if (count >= 0 && cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION]) {
                CAM_LOG_INFO("FACE_DETECTION - count %d, fd %d", count, tfd[0]);
 
-               if (tfd[0] >= 0) {
-                       if (_camera_import_tbm_fd(cb_info->bufmgr, tfd[0], &bo, &bo_handle)) {
+               if (CAMERA_IS_FD_VALID(tfd[0])) {
+                       if (__camera_import_tbm_fd(cb_info->bufmgr, tfd[0], &bo, &bo_handle)) {
                                /* set face info */
                                faces = bo_handle.ptr;
                        }
 
                        close(tfd[0]);
-                       tfd[0] = -1;
+                       tfd[0] = CAMERA_FD_INIT;
                }
 
                ((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);
+               __camera_release_imported_bo(&bo);
        } else {
                CAM_LOG_WARNING("skip face detection message [count %d, fd %d, cb %p]",
                        count, tfd[0], cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_FACE_DETECTION]);
@@ -577,12 +725,11 @@ static void __camera_event_handler_face_detection(camera_cb_info_s *cb_info, cha
 
        /* return buffer */
        _camera_msg_return_buffer(face_fd, cb_info);
-
-       return;
 }
+//LCOV_EXCL_STOP
 
 
-static bool _camera_import_tbm_fd(tbm_bufmgr bufmgr, int fd, tbm_bo *bo, tbm_bo_handle *bo_handle)
+static bool __camera_import_tbm_fd(tbm_bufmgr bufmgr, int fd, tbm_bo *bo, tbm_bo_handle *bo_handle)
 {
        tbm_bo tmp_bo = NULL;
        tbm_bo_handle tmp_bo_handle = {NULL, };
@@ -599,16 +746,14 @@ static bool _camera_import_tbm_fd(tbm_bufmgr bufmgr, int fd, tbm_bo *bo, tbm_bo_
                return false;
        }
 
-       tmp_bo_handle = tbm_bo_map(tmp_bo, TBM_DEVICE_CPU, TBM_OPTION_READ);
+       tmp_bo_handle = tbm_bo_get_handle(tmp_bo, TBM_DEVICE_CPU);
        if (tmp_bo_handle.ptr == NULL) {
-               CAM_LOG_ERROR("map failed %p", tmp_bo);
+               CAM_LOG_ERROR("tbm_bo_get_handle() failed %p", tmp_bo);
                tbm_bo_unref(tmp_bo);
                tmp_bo = NULL;
                return false;
        }
 
-       tbm_bo_unmap(tmp_bo);
-
        /* set bo and bo_handle */
        *bo = tmp_bo;
        *bo_handle = tmp_bo_handle;
@@ -618,7 +763,7 @@ static bool _camera_import_tbm_fd(tbm_bufmgr bufmgr, int fd, tbm_bo *bo, tbm_bo_
        return true;
 }
 
-static void _camera_release_imported_bo(tbm_bo *bo)
+static void __camera_release_imported_bo(tbm_bo *bo)
 {
        if (!bo || !(*bo)) {
                CAM_LOG_DEBUG("NULL bo");
@@ -627,11 +772,122 @@ static void _camera_release_imported_bo(tbm_bo *bo)
 
        tbm_bo_unref(*bo);
        *bo = NULL;
+}
+
+
+static bool __is_supported(camera_h camera, muse_camera_api_e api)
+{
+       int ret = CAMERA_ERROR_NONE;
+       camera_cli_s *pc = (camera_cli_s *)camera;
+
+       if (!pc || !pc->cb_info) {
+               CAM_LOG_ERROR("api[%d] NULL handle[%p]", api, pc);
+               set_last_result(CAMERA_ERROR_INVALID_PARAMETER);
+               return false;
+       }
+
+       CAM_LOG_INFO("Enter - api[%d]", api);
+
+       _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
+
+       CAM_LOG_INFO("Leave - api[%d], ret[%d]", api, ret);
+
+       return !!ret;
+}
+
+
+static int __set_mode(camera_h camera, muse_camera_api_e api, int set_mode)
+{
+       int ret = CAMERA_ERROR_NONE;
+       camera_cli_s *pc = (camera_cli_s *)camera;
+       camera_msg_param param;
+
+       if (!pc || !pc->cb_info) {
+               CAM_LOG_ERROR("api[%d] NULL handle[%p]", api, pc);
+               return CAMERA_ERROR_INVALID_PARAMETER;
+       }
+
+       CAM_LOG_INFO("Enter - api[%d], mode[%d]", api, set_mode);
+
+       CAMERA_MSG_PARAM_SET(param, INT, set_mode);
+
+       _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
+
+       CAM_LOG_INFO("Leave - api[%d], ret[0x%x]", api, ret);
+
+       return ret;
+}
+
+
+static int __set_enable(camera_h camera, muse_camera_api_e api, int set_enable)
+{
+       int ret = CAMERA_ERROR_NONE;
+       camera_cli_s *pc = (camera_cli_s *)camera;
+       camera_msg_param param;
+
+       if (!pc || !pc->cb_info) {
+               CAM_LOG_ERROR("api[%d] NULL handle[%p]", api, pc);
+               return CAMERA_ERROR_INVALID_PARAMETER;
+       }
+
+       CAM_LOG_INFO("Enter - api[%d], enable[%d]", api, set_enable);
+
+       CAMERA_MSG_PARAM_SET(param, INT, set_enable);
+
+       _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
 
-       return;
+       CAM_LOG_INFO("Leave - api[%d], ret[0x%x]", api, ret);
+
+       return ret;
+}
+
+
+void _camera_send_message_get_return(camera_cb_info_s *cb_info, muse_camera_api_e api, char *msg, int time_out, int *ret)
+{
+       int send_ret = 0;
+
+       if (!msg) {
+               CAM_LOG_ERROR("api[%d] message failed", api);
+               if (ret)
+                       *ret = CAMERA_ERROR_OUT_OF_MEMORY;
+
+               return;
+       }
+
+       if (api != MUSE_CAMERA_API_RETURN_BUFFER && api != MUSE_CAMERA_API_PREVIEW_CB_RETURN)
+               CAM_LOG_INFO("api[%d], message[%s]", api, msg);
+       else
+               CAM_LOG_DEBUG("api[%d], message[%s]", api, 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_msg_send(cb_info->fd, msg);
+               g_mutex_unlock(&cb_info->fd_lock);
+       }
+
+       if (send_ret < 0) {
+               CAM_LOG_ERROR("message send failed");
+               if (ret)
+                       *ret = CAMERA_ERROR_INVALID_OPERATION;
+       } else {
+               if (ret)
+                       *ret = _camera_client_wait_for_cb_return(api, cb_info, time_out);
+       }
+
+       _camera_update_api_waiting(cb_info, api, -1);
+
+       muse_core_msg_free(msg);
+
+       if (api != MUSE_CAMERA_API_RETURN_BUFFER && api != MUSE_CAMERA_API_PREVIEW_CB_RETURN)
+               CAM_LOG_INFO("api[%d] ret[0x%x]", api, ret ? *ret : 0x0);
+       else
+               CAM_LOG_DEBUG("api[%d] ret[0x%x]", api, ret ? *ret : 0x0);
 }
 
-static int _camera_client_wait_for_cb_return(muse_camera_api_e api, camera_cb_info_s *cb_info, int time_out)
+
+int _camera_client_wait_for_cb_return(muse_camera_api_e api, camera_cb_info_s *cb_info, int time_out)
 {
        int ret = CAMERA_ERROR_NONE;
        gint64 end_time;
@@ -657,6 +913,11 @@ static int _camera_client_wait_for_cb_return(muse_camera_api_e api, camera_cb_in
                        goto _CB_RETURN_END;
                }
 
+               if (!cb_info->is_server_connected) {
+                       ret = CAMERA_ERROR_SERVICE_DISCONNECTED;
+                       goto _CB_RETURN_END;
+               }
+
                if (!cb_info->api_activating[api])
                        CAM_LOG_WARNING("invalid signal received, wait again...");
        }
@@ -674,10 +935,9 @@ _CB_RETURN_END:
 }
 
 
-static void _camera_msg_send(int api, int *fds, camera_cb_info_s *cb_info,
+void _camera_msg_send(int api, int *fds, camera_cb_info_s *cb_info,
        int *ret, int timeout)
 {
-       int send_ret = 0;
        char *msg = NULL;
 
        if (!cb_info) {
@@ -690,54 +950,22 @@ static void _camera_msg_send(int api, int *fds, camera_cb_info_s *cb_info,
        }
 
        msg = muse_core_msg_new(api, NULL);
-       if (!msg) {
-               CAM_LOG_ERROR("msg failed: api %d", api);
-
-               if (ret)
-                       *ret = CAMERA_ERROR_OUT_OF_MEMORY;
 
-               return;
-       }
+       _camera_send_message_get_return(cb_info, api, msg, timeout, ret);
+}
 
-       CAM_LOG_DEBUG("send msg[%s]", msg);
 
-       if (cb_info->is_server_connected) {
-               __camera_update_api_waiting(cb_info, api, 1);
+void _camera_msg_send_param1(int api, camera_cb_info_s *cb_info,
+       int *ret, camera_msg_param *param, int timeout)
+{
+       int array_length;
+       char *msg = NULL;
 
-               g_mutex_lock(&cb_info->fd_lock);
-               send_ret = muse_core_msg_send_fd(cb_info->fd, fds, msg);
-               g_mutex_unlock(&cb_info->fd_lock);
-       }
+       if (!cb_info || !param) {
+               CAM_LOG_ERROR("invalid pointer : api %d - %p %p", api, cb_info, param);
 
-       if (send_ret < 0) {
-               CAM_LOG_ERROR("msg send failed");
-               if (ret)
-                       *ret = CAMERA_ERROR_INVALID_OPERATION;
-       } else {
                if (ret)
-                       *ret = _camera_client_wait_for_cb_return(api, cb_info, timeout);
-       }
-
-       __camera_update_api_waiting(cb_info, api, -1);
-
-       muse_core_msg_free(msg);
-
-       return;
-}
-
-
-static void _camera_msg_send_param1(int api, camera_cb_info_s *cb_info,
-       int *ret, camera_msg_param *param, int timeout)
-{
-       int send_ret = 0;
-       int array_length;
-       char *msg = NULL;
-
-       if (!cb_info || !param) {
-               CAM_LOG_ERROR("invalid pointer : api %d - %p %p", api, cb_info, param);
-
-               if (ret)
-                       *ret = CAMERA_ERROR_INVALID_PARAMETER;
+                       *ret = CAMERA_ERROR_INVALID_PARAMETER;
 
                return;
        }
@@ -768,55 +996,23 @@ static void _camera_msg_send_param1(int api, camera_cb_info_s *cb_info,
                break;
        }
 
-       if (!msg) {
-               CAM_LOG_ERROR("msg failed: api %d", api);
-
-               if (ret)
-                       *ret = CAMERA_ERROR_OUT_OF_MEMORY;
-
-               return;
-       }
-
-       CAM_LOG_DEBUG("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_msg_send(cb_info->fd, msg);
-               g_mutex_unlock(&cb_info->fd_lock);
-       }
-
-       if (send_ret < 0) {
-               CAM_LOG_ERROR("msg send failed");
-
-               if (ret)
-                       *ret = CAMERA_ERROR_INVALID_OPERATION;
-       } else {
-               if (ret)
-                       *ret = _camera_client_wait_for_cb_return(api, cb_info, timeout);
-       }
-
-       __camera_update_api_waiting(cb_info, api, -1);
-
-       muse_core_msg_free(msg);
-
-       return;
+       _camera_send_message_get_return(cb_info, api, msg, timeout, ret);
 }
 
 
-static void _camera_msg_send_param2_int(int api, camera_cb_info_s *cb_info,
+void _camera_msg_send_param2_int(int api, camera_cb_info_s *cb_info,
        int *ret, camera_msg_param *param0, camera_msg_param *param1, int timeout)
 {
-       int func_ret = CAMERA_ERROR_NONE;
-       int send_ret = 0;
        char *msg = NULL;
 
        if (!cb_info || !param0 || !param1) {
                CAM_LOG_ERROR("invalid ptr %p %p %p : api %d",
                        cb_info, param0, param1, api);
-               func_ret = CAMERA_ERROR_INVALID_PARAMETER;
-               goto _SEND_PARAM2_INT_DONE;
+
+               if (ret)
+                       *ret = CAMERA_ERROR_INVALID_PARAMETER;
+
+               return;
        }
 
        CAM_LOG_DEBUG("api[%d], param0[%s:%d], param1[%s:%d]",
@@ -828,43 +1024,12 @@ static void _camera_msg_send_param2_int(int api, camera_cb_info_s *cb_info,
                param0->type, param0->name, param0->value.value_INT,
                param1->type, param1->name, param1->value.value_INT,
                NULL);
-       if (!msg) {
-               CAM_LOG_ERROR("msg failed: api %d", api);
-               func_ret = CAMERA_ERROR_OUT_OF_MEMORY;
-               goto _SEND_PARAM2_INT_DONE;
-       }
-
-       CAM_LOG_DEBUG("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_msg_send(cb_info->fd, msg);
-               g_mutex_unlock(&cb_info->fd_lock);
-       }
-
-       if (send_ret < 0) {
-               CAM_LOG_ERROR("msg send failed");
-
-               func_ret = CAMERA_ERROR_INVALID_OPERATION;
-       } else {
-               func_ret = _camera_client_wait_for_cb_return(api, cb_info, timeout);
-       }
-
-       __camera_update_api_waiting(cb_info, api, -1);
-
-       muse_core_msg_free(msg);
-
-_SEND_PARAM2_INT_DONE:
-       if (ret)
-               *ret = func_ret;
 
-       return;
+       _camera_send_message_get_return(cb_info, api, msg, timeout, ret);
 }
 
 
-static void _camera_msg_return_buffer(int ret_fd, camera_cb_info_s *cb_info)
+void _camera_msg_return_buffer(int ret_fd, camera_cb_info_s *cb_info)
 {
        camera_msg_param param;
 
@@ -876,12 +1041,10 @@ static void _camera_msg_return_buffer(int ret_fd, camera_cb_info_s *cb_info)
        CAMERA_MSG_PARAM_SET(param, INT, ret_fd);
 
        _camera_msg_send_param1(MUSE_CAMERA_API_RETURN_BUFFER, cb_info, NULL, &param, 0);
-
-       return;
 }
 
 
-int _camera_get_tbm_surface_format(int in_format, uint32_t *out_format)
+int _camera_get_tbm_format(int in_format, uint32_t *out_format)
 {
        if (in_format <= MM_PIXEL_FORMAT_INVALID ||
            in_format >= MM_PIXEL_FORMAT_NUM ||
@@ -989,435 +1152,349 @@ int _camera_get_media_packet_mimetype(int in_format, media_format_mimetype_e *mi
        case MM_PIXEL_FORMAT_ARGB:
                *mimetype = MEDIA_FORMAT_ARGB;
                break;
+       case MM_PIXEL_FORMAT_ENCODED_H264:
+               /* TODO: How can we determine the profile for H.264 format? */
+               *mimetype = MEDIA_FORMAT_H264_SP;
+               break;
+       case MM_PIXEL_FORMAT_ENCODED_MJPEG:
+               *mimetype = MEDIA_FORMAT_MJPEG;
+               break;
+       case MM_PIXEL_FORMAT_ENCODED_VP8:
+               *mimetype = MEDIA_FORMAT_VP8;
+               break;
+       case MM_PIXEL_FORMAT_ENCODED_VP9:
+               *mimetype = MEDIA_FORMAT_VP9;
+               break;
        default:
-               CAM_LOG_ERROR("invalid in_format %d", in_format);
-               return CAMERA_ERROR_INVALID_PARAMETER;
+               CAM_LOG_ERROR("unsupported format[%d]", in_format);
+               return CAMERA_ERROR_NOT_SUPPORTED;
 //LCOV_EXCL_STOP
        }
 
        return CAMERA_ERROR_NONE;
 }
 
-void camera_create_preview_frame(camera_stream_data_s *stream, int num_buffer_fd,
-       tbm_bo_handle *buffer_bo_handle, tbm_bo_handle *data_bo_handle, camera_preview_data_s *frame)
+
+static int __camera_create_media_packet_data(int ret_fd, int *tfd, int num_buffer_fd, tbm_bo bo,
+       tbm_bo *buffer_bo, tbm_bo data_bo, camera_media_packet_data **mp_data)
 {
-       int total_size = 0;
-       unsigned char *buf_pos = NULL;
+       int i = 0;
+       int ret = CAMERA_ERROR_NONE;
+       camera_media_packet_data *new_mp_data = NULL;
 
-       if (stream == NULL || buffer_bo_handle == NULL || frame == NULL) {
-               CAM_LOG_ERROR("invalid parameter - stream:%p, buffer_bo_handle:%p", stream, buffer_bo_handle);
-               return;
+       if (!tfd || !mp_data) {
+               CAM_LOG_ERROR("NULL param[%p,%p]", tfd, mp_data);
+               return CAMERA_ERROR_INVALID_PARAMETER;
        }
 
-       /* set frame info */
-       if (stream->format == MM_PIXEL_FORMAT_ITLV_JPEG_UYVY)
-               frame->format  = MM_PIXEL_FORMAT_UYVY;
-       else
-               frame->format = stream->format;
+       new_mp_data = g_new0(camera_media_packet_data, 1);
 
-       frame->width = stream->width;
-       frame->height = stream->height;
-       frame->timestamp = stream->timestamp;
-       frame->num_of_planes = stream->num_planes;
+       new_mp_data->ret_fd = ret_fd;
+       new_mp_data->fd = tfd[0];
+       new_mp_data->num_buffer_fd = num_buffer_fd;
+       new_mp_data->bo = bo;
 
-       if (num_buffer_fd == 0) {
-//LCOV_EXCL_START
+       CAM_LOG_VERBOSE("tfd[%d], ret fd[%d]", new_mp_data->fd, new_mp_data->ret_fd);
+
+       if (data_bo) {
                /* non-zero copy */
-               if (!data_bo_handle || !data_bo_handle->ptr) {
-                       CAM_LOG_ERROR("NULL pointer");
-                       return;
-               }
+               new_mp_data->data_bo = data_bo;
+               new_mp_data->data_fd = tfd[1];
 
-               buf_pos = data_bo_handle->ptr;
-
-               if (stream->format == MM_PIXEL_FORMAT_ENCODED_H264) {
-                       frame->data.encoded_plane.data = buf_pos;
-                       frame->data.encoded_plane.size = stream->data.encoded.length_data;
-                       frame->data.encoded_plane.is_delta_frame = (bool)stream->data.encoded.is_delta_frame;
-                       total_size = stream->data.encoded.length_data;
-               } else if (stream->format == MM_PIXEL_FORMAT_ENCODED_MJPEG) {
-                       frame->data.encoded_plane.data = buf_pos;
-                       frame->data.encoded_plane.size = stream->data.encoded.length_data;
-                       total_size = stream->data.encoded.length_data;
-               } else if (stream->format == MM_PIXEL_FORMAT_INVZ) {
-                       frame->data.depth_plane.data = buf_pos;
-                       frame->data.depth_plane.size = stream->data.depth.length_data;
-                       total_size = stream->data.depth.length_data;
-               } else if (stream->format == MM_PIXEL_FORMAT_RGBA ||
-                       stream->format == MM_PIXEL_FORMAT_ARGB) {
-                       frame->data.rgb_plane.data = buf_pos;
-                       frame->data.rgb_plane.size = stream->data.rgb.length_data;
-                       total_size = stream->data.rgb.length_data;
-               } else {
-                       switch (stream->num_planes) {
-                       case 1:
-                               frame->data.single_plane.yuv = buf_pos;
-                               frame->data.single_plane.size = stream->data.yuv420.length_yuv;
-                               total_size = stream->data.yuv420.length_yuv;
-                               break;
-                       case 2:
-                               frame->data.double_plane.y = buf_pos;
-                               frame->data.double_plane.y_size = stream->data.yuv420sp.length_y;
-                               buf_pos += stream->data.yuv420sp.length_y;
-                               frame->data.double_plane.uv = buf_pos;
-                               frame->data.double_plane.uv_size = stream->data.yuv420sp.length_uv;
-                               total_size = stream->data.yuv420sp.length_y + \
-                                       stream->data.yuv420sp.length_uv;
-                               break;
-                       case 3:
-                               frame->data.triple_plane.y = buf_pos;
-                               frame->data.triple_plane.y_size = stream->data.yuv420p.length_y;
-                               buf_pos += stream->data.yuv420p.length_y;
-                               frame->data.triple_plane.u = buf_pos;
-                               frame->data.triple_plane.u_size = stream->data.yuv420p.length_u;
-                               buf_pos += stream->data.yuv420p.length_u;
-                               frame->data.triple_plane.v = buf_pos;
-                               frame->data.triple_plane.v_size = stream->data.yuv420p.length_v;
-                               total_size = stream->data.yuv420p.length_y + \
-                                       stream->data.yuv420p.length_u + \
-                                       stream->data.yuv420p.length_v;
-                               break;
-                       default:
-                               break;
-                       }
-               }
-//LCOV_EXCL_STOP
+               CAM_LOG_VERBOSE("bo[%p], fd[%d]",
+                       new_mp_data->data_bo, new_mp_data->data_fd);
        } else {
                /* zero copy */
-               switch (stream->num_planes) {
-//LCOV_EXCL_START
-               case 1:
-                       frame->data.single_plane.yuv = buffer_bo_handle[0].ptr;
-                       frame->data.single_plane.size = stream->data.yuv420.length_yuv;
-                       total_size = stream->data.yuv420.length_yuv;
-                       break;
-//LCOV_EXCL_STOP
-               case 2:
-                       frame->data.double_plane.y = buffer_bo_handle[0].ptr;
-                       if (stream->num_planes == (unsigned int)num_buffer_fd)
-                               frame->data.double_plane.uv = buffer_bo_handle[1].ptr;
-                       else
-                               frame->data.double_plane.uv = buffer_bo_handle[0].ptr + stream->data.yuv420sp.length_y;
-                       frame->data.double_plane.y_size = stream->data.yuv420sp.length_y;
-                       frame->data.double_plane.uv_size = stream->data.yuv420sp.length_uv;
-                       total_size = stream->data.yuv420sp.length_y + \
-                               stream->data.yuv420sp.length_uv;
-                       break;
-               case 3:
-//LCOV_EXCL_START
-                       frame->data.triple_plane.y = buffer_bo_handle[0].ptr;
-                       if (stream->num_planes == (unsigned int)num_buffer_fd) {
-                               frame->data.triple_plane.u = buffer_bo_handle[1].ptr;
-                               frame->data.triple_plane.v = buffer_bo_handle[2].ptr;
-                       } else {
-                               frame->data.triple_plane.u = buffer_bo_handle[0].ptr + stream->data.yuv420p.length_y;
-                               frame->data.triple_plane.v = buffer_bo_handle[1].ptr + stream->data.yuv420p.length_u;
-                       }
-                       frame->data.triple_plane.y_size = stream->data.yuv420p.length_y;
-                       frame->data.triple_plane.u_size = stream->data.yuv420p.length_u;
-                       frame->data.triple_plane.v_size = stream->data.yuv420p.length_v;
-                       total_size = stream->data.yuv420p.length_y + \
-                               stream->data.yuv420p.length_u + \
-                               stream->data.yuv420p.length_v;
-                       break;
-//LCOV_EXCL_STOP
-               default:
-                       break;
+               for (i = 0 ; i < num_buffer_fd ; i++) {
+                       new_mp_data->buffer_bo[i] = buffer_bo[i];
+                       new_mp_data->buffer_fd[i] = (tbm_fd)tfd[i + 1];
+
+                       CAM_LOG_VERBOSE("    [%d] bo[%p], fd[%d]",
+                               i, new_mp_data->buffer_bo[i], new_mp_data->buffer_fd[i]);
                }
+
+               for (i = num_buffer_fd ; i < MUSE_NUM_FD ; i++)
+                       new_mp_data->buffer_fd[i] = CAMERA_FD_INIT;
+
+               new_mp_data->data_fd = CAMERA_FD_INIT;
        }
 
-       CAM_LOG_DEBUG("format[%d], res[%dx%d], size[%d], plane num[%d]",
-            frame->format, frame->width, frame->height, total_size, frame->num_of_planes);
+       *mp_data = new_mp_data;
+
+       CAM_LOG_DEBUG("mp_data %p", new_mp_data);
 
-       return;
+       return ret;
 }
 
-static int _camera_media_packet_data_create(int ret_fd, int *tfd, int num_buffer_fd, tbm_bo bo,
-       tbm_bo *buffer_bo, tbm_bo data_bo, camera_media_packet_data **mp_data)
+static void __camera_release_media_packet_data(camera_media_packet_data *mp_data, camera_cb_info_s *cb_info)
 {
        int i = 0;
-       int ret = CAMERA_ERROR_NONE;
-       camera_media_packet_data *tmp_mp_data = NULL;
 
-       if (!tfd) {
-               CAM_LOG_ERROR("NULL tfd");
-               return CAMERA_ERROR_INVALID_PARAMETER;
+       if (!mp_data || !cb_info) {
+               CAM_LOG_ERROR("NULL pointer %p %p", mp_data, cb_info);
+               return;
        }
 
-       if (*mp_data == NULL) {
-               tmp_mp_data = g_new0(camera_media_packet_data, 1);
-               if (tmp_mp_data) {
-                       tmp_mp_data->ret_fd = ret_fd;
-                       tmp_mp_data->fd = tfd[0];
-                       tmp_mp_data->num_buffer_fd = num_buffer_fd;
-                       tmp_mp_data->bo = bo;
+       CAM_LOG_VERBOSE("tfd[%d], ret fd[%d]", mp_data->fd, mp_data->ret_fd);
 
-                       CAM_LOG_VERBOSE("tfd[%d], ret fd[%d]", tmp_mp_data->fd, tmp_mp_data->ret_fd);
+       /* release imported bo and close fd */
+       for (i = 0 ; i < mp_data->num_buffer_fd ; i++) {
+               CAM_LOG_VERBOSE("    release buffer[%d] fd[%d],bo[%p]",
+                       i, mp_data->buffer_fd[i], mp_data->buffer_bo[i]);
 
-                       if (data_bo) {
-                               /* non-zero copy */
-                               tmp_mp_data->data_bo = data_bo;
-                               tmp_mp_data->data_fd = tfd[1];
-
-                               CAM_LOG_VERBOSE("bo[%p], fd[%d]",
-                                       tmp_mp_data->data_bo, tmp_mp_data->data_fd);
-                       } else {
-                               /* zero copy */
-                               for (i = 0 ; i < num_buffer_fd ; i++) {
-                                       tmp_mp_data->buffer_bo[i] = buffer_bo[i];
-                                       tmp_mp_data->buffer_fd[i] = (tbm_fd)tfd[i + 1];
+               tbm_bo_unref(mp_data->buffer_bo[i]);
 
-                                       CAM_LOG_VERBOSE("    [%d] bo[%p], fd[%d]",
-                                               i, tmp_mp_data->buffer_bo[i], tmp_mp_data->buffer_fd[i]);
-                               }
-                       }
+               if (CAMERA_IS_FD_VALID(mp_data->buffer_fd[i]))
+                       close(mp_data->buffer_fd[i]);
+               else
+                       CAM_LOG_WARNING("invalid fd[%d] for buffer[%d]", mp_data->buffer_fd[i], i);
+       }
 
-                       tmp_mp_data->ref_cnt++;
+       if (mp_data->data_bo) {
+               CAM_LOG_VERBOSE("release data_fd[%d],data_bo[%p]",
+                       mp_data->data_fd, mp_data->data_bo);
 
-                       *mp_data = tmp_mp_data;
+               tbm_bo_unref(mp_data->data_bo);
 
-                       CAM_LOG_DEBUG("mp_data %p", tmp_mp_data);
-               } else {
-                       ret = CAMERA_ERROR_OUT_OF_MEMORY;
-                       CAM_LOG_ERROR("failed to alloc media packet data");
-               }
-       } else {
-               ((camera_media_packet_data *)*mp_data)->ref_cnt++;
+               if (CAMERA_IS_FD_VALID(mp_data->data_fd))
+                       close(mp_data->data_fd);
+               else
+                       CAM_LOG_WARNING("invalid data_fd[%d]", mp_data->data_fd);
        }
 
-       return ret;
+       CAM_LOG_VERBOSE("release fd[%d],bo[%p]", mp_data->fd, mp_data->bo);
+
+       tbm_bo_unref(mp_data->bo);
+
+       if (CAMERA_IS_FD_VALID(mp_data->fd))
+               close(mp_data->fd);
+       else
+               CAM_LOG_WARNING("invalid fd[%d]", mp_data->fd);
+
+       /* return buffer */
+       _camera_msg_return_buffer(mp_data->ret_fd, cb_info);
+
+       g_free(mp_data);
 }
 
-static void _camera_media_packet_data_release(camera_media_packet_data *mp_data, camera_cb_info_s *cb_info)
+
+static tbm_surface_h __camera_get_tbm_surface(MMCamcorderVideoStreamDataType *stream, camera_media_packet_data *mp_data)
 {
        int i = 0;
+       int ret = CAMERA_ERROR_NONE;
+       uint32_t tbm_format = 0;
+       tbm_bo bos[BUFFER_MAX_PLANE_NUM] = {NULL, };
+       tbm_surface_info_s tsurf_info;
 
-       if (!mp_data || !cb_info) {
-               CAM_LOG_ERROR("NULL pointer %p %p", mp_data, cb_info);
-               return;
+       if (!stream || !mp_data) {
+               CAM_LOG_ERROR("NULL param [%p,%p]", stream, mp_data);
+               return NULL;
        }
 
-       if (mp_data->ref_cnt > 1) {
-               mp_data->ref_cnt--;
-               CAM_LOG_INFO("ref count %d", mp_data->ref_cnt);
-       } else {
-               CAM_LOG_VERBOSE("tfd[%d], ret fd[%d]", mp_data->fd, mp_data->ret_fd);
-
-               /* release imported bo and close imported fd */
-               for (i = 0 ; i < mp_data->num_buffer_fd ; i++) {
-                       tbm_bo_unref(mp_data->buffer_bo[i]);
-                       mp_data->buffer_bo[i] = NULL;
-
-                       close(mp_data->buffer_fd[i]);
-                       mp_data->buffer_fd[i] = -1;
-               }
+       if (mp_data->num_buffer_fd < 1 && !mp_data->data_bo) {
+               CAM_LOG_ERROR("No valid data");
+               return NULL;
+       }
 
-               /* unref tbm bo and close imported fd */
-               close(mp_data->fd);
-               mp_data->fd = -1;
+       ret = _camera_get_tbm_format(stream->format, &tbm_format);
+       if (ret != CAMERA_ERROR_NONE)
+               return NULL;
 
-               _camera_release_imported_bo(&mp_data->bo);
+       memset(&tsurf_info, 0x0, sizeof(tbm_surface_info_s));
 
-               if (mp_data->data_bo && mp_data->data_fd >= 0) {
-                       close(mp_data->data_fd);
-                       mp_data->data_fd = -1;
+       if (mp_data->num_buffer_fd > 0) {
+               for (i = 0 ; i < mp_data->num_buffer_fd ; i++)
+                       bos[i] = mp_data->buffer_bo[i];
+       } else {
+               bos[0] = mp_data->data_bo;
+       }
+
+       tsurf_info.width = stream->width;
+       tsurf_info.height = stream->height;
+       tsurf_info.format = tbm_format;
+       tsurf_info.bpp = tbm_surface_internal_get_bpp(tbm_format);
+       tsurf_info.num_planes = tbm_surface_internal_get_num_planes(tbm_format);
+
+       switch (tbm_format) {
+       case TBM_FORMAT_NV12:   /* fall through */
+       case TBM_FORMAT_NV21:   /* fall through */
+       case TBM_FORMAT_YUV420: /* fall through */
+       case TBM_FORMAT_YVU420: /* fall through */
+       case TBM_FORMAT_UYVY:   /* fall through */
+       case TBM_FORMAT_YUYV:
+               for (i = 0 ; i < (int)tsurf_info.num_planes ; i++) {
+                       tsurf_info.planes[i].stride = stream->stride[i];
+                       tsurf_info.planes[i].size = stream->stride[i] * stream->elevation[i];
+                       if (i != 0 && mp_data->num_buffer_fd <= 1)
+                               tsurf_info.planes[i].offset = tsurf_info.planes[i - 1].offset + tsurf_info.planes[i - 1].size;
+                       tsurf_info.size += tsurf_info.planes[i].size;
+
+                       CAM_LOG_VERBOSE("[plane:%d] st[%d], el[%d], size[%d]",
+                               i, stream->stride[i], stream->elevation[i], tsurf_info.planes[i].size);
                }
-               _camera_release_imported_bo(&mp_data->data_bo);
-
-               /* return buffer */
-               _camera_msg_return_buffer(mp_data->ret_fd, cb_info);
-
-               g_free(mp_data);
+               break;
+//LCOV_EXCL_START
+       case TBM_FORMAT_RGB565:     /* fall through */
+       case TBM_FORMAT_RGB888:     /* fall through */
+       case TBM_FORMAT_RGBA8888:   /* fall through */
+       case TBM_FORMAT_ARGB8888:
+               tsurf_info.planes[0].size = stream->data.rgb.length_data;
+               tsurf_info.planes[0].offset = 0;
+               tsurf_info.size = stream->data.rgb.length_data;
+               break;
+       default:
+               CAM_LOG_ERROR("Not supported format[%d]", stream->format);
+               return NULL;
+//LCOV_EXCL_STOP
        }
 
-       return;
+       return tbm_surface_internal_create_with_bos(&tsurf_info, bos,
+               mp_data->num_buffer_fd > 0 ? mp_data->num_buffer_fd : 1);
 }
 
-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_update_media_packet_format(camera_cb_info_s *cb_info, MMCamcorderVideoStreamDataType *stream)
 {
-       media_packet_h pkt = NULL;
+       int ret = CAMERA_ERROR_NONE;
+       int pkt_fmt_width = 0;
+       int pkt_fmt_height = 0;
        bool make_pkt_fmt = false;
-       tbm_surface_h tsurf = NULL;
-       tbm_surface_info_s tsurf_info;
        media_format_mimetype_e mimetype = MEDIA_FORMAT_NV12;
-       uint32_t bo_format = 0;
-       int ret = 0;
-       int i = 0;
-       int num_buffer_fd = 0;
-       tbm_bo *buffer_bo = NULL;
+       media_format_mimetype_e pkt_fmt_mimetype = MEDIA_FORMAT_NV12;
 
-       if (cb_info == NULL || stream == NULL || mp_data == NULL || packet == NULL) {
-               CAM_LOG_ERROR("invalid parameter - cb_info:%p, stream:%p, mp_data:%p, packet:%p",
-                       cb_info, stream, mp_data, packet);
+       if (!cb_info || !stream) {
+               CAM_LOG_ERROR("invalid parameter - %p, %p", cb_info, stream);
                return CAMERA_ERROR_INVALID_PARAMETER;
        }
 
-       memset(&tsurf_info, 0x0, sizeof(tbm_surface_info_s));
-       buffer_bo = mp_data->buffer_bo;
-       num_buffer_fd = mp_data->num_buffer_fd;
+       ret = _camera_get_media_packet_mimetype(stream->format, &mimetype);
+       if (ret != CAMERA_ERROR_NONE)
+               return ret;
 
-       /* create tbm surface */
-       for (i = 0 ; i < BUFFER_MAX_PLANE_NUM ; i++)
-               tsurf_info.planes[i].stride = stream->stride[i];
+       /* check media packet format */
+       if (cb_info->pkt_fmt) {
+               media_format_get_video_info(cb_info->pkt_fmt,
+                       &pkt_fmt_mimetype, &pkt_fmt_width, &pkt_fmt_height, NULL, NULL);
 
-       /* get tbm surface format */
-       ret = _camera_get_tbm_surface_format(stream->format, &bo_format);
-       ret |= _camera_get_media_packet_mimetype(stream->format, &mimetype);
+               CAM_LOG_DEBUG("pkt_fmt %dx%d - stream %dx%d",
+                       pkt_fmt_width, pkt_fmt_height, stream->width, stream->height);
 
-       if (ret == CAMERA_ERROR_NONE) {
-               tsurf_info.width = stream->width;
-               tsurf_info.height = stream->height;
-               tsurf_info.format = bo_format;
-               tsurf_info.bpp = tbm_surface_internal_get_bpp(bo_format);
-               tsurf_info.num_planes = tbm_surface_internal_get_num_planes(bo_format);
-
-               if (num_buffer_fd > 0) {
-                       switch (bo_format) {
-                       case TBM_FORMAT_NV12:
-                       case TBM_FORMAT_NV21:
-                               tsurf_info.planes[0].size = stream->stride[0] * stream->elevation[0];
-                               tsurf_info.planes[1].size = stream->stride[1] * stream->elevation[1];
-                               tsurf_info.planes[0].offset = 0;
-                               if (num_buffer_fd == 1)
-                                       tsurf_info.planes[1].offset = tsurf_info.planes[0].size;
-                               tsurf_info.size = tsurf_info.planes[0].size + tsurf_info.planes[1].size;
-                               break;
-//LCOV_EXCL_START
-                       case TBM_FORMAT_YUV420:
-                       case TBM_FORMAT_YVU420:
-                               tsurf_info.planes[0].size = stream->stride[0] * stream->elevation[0];
-                               tsurf_info.planes[1].size = stream->stride[1] * stream->elevation[1];
-                               tsurf_info.planes[2].size = stream->stride[2] * stream->elevation[2];
-                               tsurf_info.planes[0].offset = 0;
-                               if (num_buffer_fd == 1) {
-                                       tsurf_info.planes[1].offset = tsurf_info.planes[0].size;
-                                       tsurf_info.planes[2].offset = tsurf_info.planes[0].size + tsurf_info.planes[1].size;
-                               }
-                               tsurf_info.size = tsurf_info.planes[0].size + tsurf_info.planes[1].size + tsurf_info.planes[2].size;
-                               break;
-                       case TBM_FORMAT_UYVY:
-                       case TBM_FORMAT_YUYV:
-                               tsurf_info.planes[0].size = (stream->stride[0] * stream->elevation[0]) << 1;
-                               tsurf_info.planes[0].offset = 0;
-                               tsurf_info.size = tsurf_info.planes[0].size;
-                               break;
-                       default:
-                               break;
-//LCOV_EXCL_STOP
-                       }
+               if (pkt_fmt_mimetype != mimetype ||
+                       pkt_fmt_width != stream->width ||
+                       pkt_fmt_height != stream->height) {
+                       CAM_LOG_WARNING("change fmt[previous:0x%x,%dx%d]",
+                                       pkt_fmt_mimetype, pkt_fmt_width, pkt_fmt_height);
 
-                       tsurf = tbm_surface_internal_create_with_bos(&tsurf_info, buffer_bo, num_buffer_fd);
-               } else if (mp_data->data_bo) {
-//LCOV_EXCL_START
-                       switch (bo_format) {
-                       case TBM_FORMAT_NV12:
-                       case TBM_FORMAT_NV21:
-                               tsurf_info.planes[0].size = stream->width * stream->height;
-                               tsurf_info.planes[1].size = (tsurf_info.planes[0].size) >> 1;
-                               tsurf_info.planes[0].offset = 0;
-                               tsurf_info.planes[1].offset = tsurf_info.planes[0].size;
-                               tsurf_info.size = tsurf_info.planes[0].size + tsurf_info.planes[1].size;
-                               break;
-                       case TBM_FORMAT_YUV420:
-                       case TBM_FORMAT_YVU420:
-                               tsurf_info.planes[0].size = stream->width * stream->height;
-                               tsurf_info.planes[1].size = (stream->width >> 1) * (stream->height >> 1);
-                               tsurf_info.planes[2].size = tsurf_info.planes[1].size;
-                               tsurf_info.planes[0].offset = 0;
-                               tsurf_info.planes[1].offset = tsurf_info.planes[0].size;
-                               tsurf_info.planes[2].offset = tsurf_info.planes[0].size + tsurf_info.planes[1].size;
-                               tsurf_info.size = tsurf_info.planes[0].size + tsurf_info.planes[1].size + tsurf_info.planes[2].size;
-                               break;
-                       case TBM_FORMAT_UYVY:
-                       case TBM_FORMAT_YUYV:
-                               tsurf_info.planes[0].size = (stream->width * stream->height) << 1;
-                               tsurf_info.planes[0].offset = 0;
-                               tsurf_info.size = tsurf_info.planes[0].size;
-                               break;
-                       default:
-                               break;
-                       }
+                       media_format_unref(cb_info->pkt_fmt);
+                       cb_info->pkt_fmt = NULL;
+                       make_pkt_fmt = true;
+               }
+       } else {
+               make_pkt_fmt = true;
+       }
 
-                       tsurf = tbm_surface_internal_create_with_bos(&tsurf_info, &mp_data->data_bo, 1);
-//LCOV_EXCL_STOP
+       /* create packet format */
+       if (make_pkt_fmt) {
+               CAM_LOG_WARNING("make new fmt - 0x%x, %dx%d",
+                       mimetype, stream->width, stream->height);
+
+               ret = media_format_create(&cb_info->pkt_fmt);
+               if (ret != MEDIA_FORMAT_ERROR_NONE) {
+                       CAM_LOG_ERROR("media_format_create failed 0x%x", ret);
+                       return CAMERA_ERROR_INVALID_OPERATION;
+               }
+
+               ret = media_format_set_video_mime(cb_info->pkt_fmt, mimetype);
+               ret |= media_format_set_video_width(cb_info->pkt_fmt, stream->width);
+               ret |= media_format_set_video_height(cb_info->pkt_fmt, stream->height);
+               if (ret != MEDIA_FORMAT_ERROR_NONE) {
+                       CAM_LOG_ERROR("media format set failed 0x%x", ret);
+                       return CAMERA_ERROR_INVALID_OPERATION;
                }
        }
 
-       if (tsurf) {
-               /* check media packet format */
-               if (cb_info->pkt_fmt) {
-                       int pkt_fmt_width = 0;
-                       int pkt_fmt_height = 0;
-                       media_format_mimetype_e pkt_fmt_mimetype = MEDIA_FORMAT_NV12;
+       return CAMERA_ERROR_NONE;
+}
 
-                       media_format_get_video_info(cb_info->pkt_fmt, &pkt_fmt_mimetype, &pkt_fmt_width, &pkt_fmt_height, NULL, NULL);
 
-                       CAM_LOG_INFO("pkt_fmt %dx%d - stream %dx%d", pkt_fmt_width, pkt_fmt_height, stream->width, stream->height);
+static int __camera_create_media_packet(camera_cb_info_s *cb_info, MMCamcorderVideoStreamDataType *stream,
+       camera_media_packet_data *mp_data, media_packet_h *packet)
+{
+       media_packet_h pkt = NULL;
+       tbm_surface_h tsurf = NULL;
+       int ret = CAMERA_ERROR_NONE;
 
-                       if (pkt_fmt_mimetype != mimetype ||
-                           pkt_fmt_width != stream->width ||
-                           pkt_fmt_height != stream->height) {
-                               CAM_LOG_WARNING("change fmt: current 0x%x, %dx%d",
-                                    pkt_fmt_mimetype, pkt_fmt_width, pkt_fmt_height);
-                               media_format_unref(cb_info->pkt_fmt);
-                               cb_info->pkt_fmt = NULL;
-                               make_pkt_fmt = true;
-                       }
-               } else {
-                       make_pkt_fmt = true;
-               }
+       if (!cb_info || !stream || !mp_data || !packet) {
+               CAM_LOG_ERROR("invalid parameter - %p, %p, %p, %p",
+                       cb_info, stream, mp_data, packet);
+               return CAMERA_ERROR_INVALID_PARAMETER;
+       }
 
-               /* create packet format */
-               if (make_pkt_fmt) {
-                       CAM_LOG_WARNING("make new pkt_fmt - 0x%x, %dx%d", mimetype, stream->width, stream->height);
-                       ret = media_format_create(&cb_info->pkt_fmt);
-                       if (ret == MEDIA_FORMAT_ERROR_NONE) {
-                               ret = media_format_set_video_mime(cb_info->pkt_fmt, mimetype);
-                               ret |= media_format_set_video_width(cb_info->pkt_fmt, stream->width);
-                               ret |= media_format_set_video_height(cb_info->pkt_fmt, stream->height);
-                               CAM_LOG_WARNING("media_format_set : 0x%x", ret);
-                       } else {
-                               CAM_LOG_WARNING("media_format_create failed 0x%x", ret);
+       ret = __camera_update_media_packet_format(cb_info, stream);
+       if (ret != CAMERA_ERROR_NONE)
+               return ret;
+
+       if (stream->data_type == MM_CAM_STREAM_DATA_ENCODED) {
+               ret = media_packet_new_from_external_memory(cb_info->pkt_fmt,
+                       stream->data.encoded.data, stream->data.encoded.length_data,
+                       (media_packet_dispose_cb)_camera_media_packet_dispose, (void *)cb_info,
+                       &pkt);
+
+               if (pkt) {
+                       if (!stream->data.encoded.is_delta_frame)
+                               media_packet_set_flags(pkt, MEDIA_PACKET_SYNC_FRAME);
+
+                       if (stream->data.encoded.is_header_included) {
+                               media_packet_set_flags(pkt, MEDIA_PACKET_CODEC_CONFIG);
+                               CAM_LOG_INFO("Codec config in buffer");
                        }
                }
+       } else {
+               tsurf = __camera_get_tbm_surface(stream, mp_data);
+               if (!tsurf) {
+                       CAM_LOG_ERROR("get tbm surface failed");
+                       ret = CAMERA_ERROR_INVALID_OPERATION;
+                       goto _PACKET_CREATE_FAILED;
+               }
 
-               /* create media packet */
-               ret = media_packet_create_from_tbm_surface(cb_info->pkt_fmt,
-                       tsurf, (media_packet_finalize_cb)_camera_media_packet_finalize,
+               ret = media_packet_new_from_tbm_surface(cb_info->pkt_fmt,
+                       tsurf, (media_packet_dispose_cb)_camera_media_packet_dispose,
                        (void *)cb_info, &pkt);
-               if (ret != MEDIA_PACKET_ERROR_NONE) {
-                       CAM_LOG_ERROR("media_packet_create failed 0x%x", ret);
-                       tbm_surface_destroy(tsurf);
-                       tsurf = NULL;
-               }
-       } else {
-               CAM_LOG_ERROR("tbm surface failed. %dx%d, format %d, num_buffer_fd %d, data_bo %p",
-                       stream->width, stream->height, stream->format, num_buffer_fd, mp_data->data_bo);
        }
 
-       if (pkt) {
-               /* set media packet data */
-               ret = media_packet_set_extra(pkt, (void *)mp_data);
-               if (ret != MEDIA_PACKET_ERROR_NONE) {
-                       CAM_LOG_ERROR("media_packet_set_extra failed");
+       if (ret != MEDIA_PACKET_ERROR_NONE) {
+               CAM_LOG_ERROR("media_packet_new[t:%d] failed 0x%x", stream->data_type, ret);
+               goto _PACKET_CREATE_FAILED;
+       }
 
-                       _camera_media_packet_data_release(mp_data, cb_info);
+       ret = media_packet_set_extra(pkt, (void *)mp_data);
+       if (ret != MEDIA_PACKET_ERROR_NONE) {
+               CAM_LOG_ERROR("media_packet_set_extra failed");
+               goto _PACKET_CREATE_FAILED;
+       }
 
-                       media_packet_destroy(pkt);
-               } else {
-                       /* set timestamp : msec -> nsec */
-                       if (media_packet_set_pts(pkt, (uint64_t)(stream->timestamp) * 1000000) != MEDIA_PACKET_ERROR_NONE)
-                               CAM_LOG_WARNING("media_packet_set_pts failed");
+       if (media_packet_set_pts(pkt, stream->timestamp_nsec) != MEDIA_PACKET_ERROR_NONE)
+               CAM_LOG_WARNING("media_packet_set_pts failed");
 
-                       *packet = pkt;
-               }
-       }
+       if (media_packet_set_rotate_method(pkt, (media_packet_rotate_method_e)stream->rotation) != MEDIA_PACKET_ERROR_NONE)
+               CAM_LOG_WARNING("media_packet_set_rotate_method failed");
 
-       return ret;
+       CAM_LOG_VERBOSE("new media packet[%p], tbm surface[%p]", pkt, tsurf);
+
+       *packet = pkt;
+
+       return CAMERA_ERROR_NONE;
+
+_PACKET_CREATE_FAILED:
+       if (tsurf)
+               tbm_surface_destroy(tsurf);
+       if (pkt)
+               media_packet_unref(pkt);
+
+       return CAMERA_ERROR_INVALID_OPERATION;
 }
 
-int _camera_media_packet_finalize(media_packet_h pkt, int error_code, void *user_data)
+void _camera_media_packet_dispose(media_packet_h pkt, void *user_data)
 {
        int ret = 0;
        camera_cb_info_s *cb_info = (camera_cb_info_s *)user_data;
@@ -1426,37 +1503,29 @@ int _camera_media_packet_finalize(media_packet_h pkt, int error_code, void *user
 
        if (!pkt || !cb_info) {
                CAM_LOG_ERROR("NULL pointer %p %p", pkt, cb_info);
-               return MEDIA_PACKET_FINALIZE;
+               return;
        }
 
        ret = media_packet_get_extra(pkt, (void **)&mp_data);
-       if (ret != MEDIA_PACKET_ERROR_NONE) {
+       if (ret != MEDIA_PACKET_ERROR_NONE || !mp_data) {
                CAM_LOG_ERROR("media_packet_get_extra failed 0x%x", ret);
-               return MEDIA_PACKET_FINALIZE;
+               return;
        }
 
-       CAM_LOG_VERBOSE("mp_data[%p]", mp_data);
+       ret = media_packet_get_tbm_surface(pkt, &tsurf);
 
-       g_mutex_lock(&cb_info->mp_data_mutex);
+       CAM_LOG_VERBOSE("media packet[%p] - mp_data[%p],tsurf[%p]",
+               pkt, mp_data, tsurf);
 
-       _camera_media_packet_data_release(mp_data, cb_info);
-       mp_data = NULL;
+       if (tsurf)
+               tbm_surface_destroy(tsurf);
 
+       g_mutex_lock(&cb_info->mp_data_mutex);
+       __camera_release_media_packet_data(mp_data, cb_info);
        g_mutex_unlock(&cb_info->mp_data_mutex);
-
-       ret = media_packet_get_tbm_surface(pkt, &tsurf);
-       if (ret != MEDIA_PACKET_ERROR_NONE)
-               CAM_LOG_ERROR("get tbm_surface failed 0x%x", ret);
-
-       if (tsurf) {
-               tbm_surface_destroy(tsurf);
-               tsurf = NULL;
-       }
-
-       return MEDIA_PACKET_FINALIZE;
 }
 
-static void _camera_client_user_callback(camera_cb_info_s *cb_info, char *recv_msg, muse_camera_event_e event, int *tfd)
+static void __camera_client_user_callback(camera_cb_info_s *cb_info, char *recv_msg, muse_camera_event_e event, int *tfd)
 {
        int param1 = 0;
        int param2 = 0;
@@ -1649,11 +1718,9 @@ static void _camera_client_user_callback(camera_cb_info_s *cb_info, char *recv_m
        }
 
        g_mutex_unlock(&cb_info->user_cb_mutex[event]);
-
-       return;
 }
 
-static gboolean _camera_idle_event_callback(gpointer data)
+static gboolean __camera_idle_event_callback(gpointer data)
 {
        camera_cb_info_s *cb_info = NULL;
        camera_idle_event_s *cam_idle_event = (camera_idle_event_s *)data;
@@ -1680,7 +1747,7 @@ static gboolean _camera_idle_event_callback(gpointer data)
        g_mutex_unlock(&g_cam_idle_event_lock);
 
        /* user callback */
-       _camera_client_user_callback(cb_info, cam_idle_event->recv_msg, cam_idle_event->event, cam_idle_event->tfd);
+       __camera_client_user_callback(cb_info, cam_idle_event->recv_msg, cam_idle_event->event, cam_idle_event->tfd);
 
 IDLE_EVENT_CALLBACK_DONE:
        /* release event */
@@ -1690,7 +1757,7 @@ IDLE_EVENT_CALLBACK_DONE:
        return FALSE;
 }
 
-static gpointer _camera_msg_handler_func(gpointer data)
+static gpointer __camera_msg_handler_func(gpointer data)
 {
        int api = 0;
        int type = 0;
@@ -1698,6 +1765,7 @@ static gpointer _camera_msg_handler_func(gpointer data)
        camera_idle_event_s *cam_idle_event = NULL;
        camera_msg_handler_info_s *handler_info = (camera_msg_handler_info_s *)data;
        camera_cb_info_s *cb_info = NULL;
+       GThread *thread = NULL;
 
        if (!handler_info || !handler_info->cb_info) {
                CAM_LOG_ERROR("NULL handler %p", handler_info);
@@ -1706,8 +1774,9 @@ static gpointer _camera_msg_handler_func(gpointer data)
 
        cb_info = (camera_cb_info_s *)handler_info->cb_info;
        type = handler_info->type;
+       thread = handler_info->thread;
 
-       CAM_LOG_INFO("t:%d start", type);
+       CAM_LOG_INFO("t:%d start[thread:%p]", type, thread);
 
        g_mutex_lock(&handler_info->mutex);
 
@@ -1747,7 +1816,7 @@ static gpointer _camera_msg_handler_func(gpointer data)
 
                                        CAM_LOG_DEBUG("t[%d] camera api[%d] - return[0x%x]", type, api, ret);
 
-                                       g_cond_signal(&cb_info->api_cond[api]);
+                                       g_cond_broadcast(&cb_info->api_cond[api]);
                                } else {
                                        CAM_LOG_WARNING("no waiting for this api [%d]", api);
                                }
@@ -1757,9 +1826,14 @@ static gpointer _camera_msg_handler_func(gpointer data)
 
                        g_mutex_unlock(&cb_info->api_mutex[api]);
                } else if (api == MUSE_CAMERA_CB_EVENT) {
+                       if (cam_msg->event == MUSE_CAMERA_EVENT_TYPE_INTERRUPTED) {
+                               CAM_LOG_WARNING("INTERRUPTED, release thread for preview cb");
+                               __destroy_msg_handler_thread(&cb_info->preview_cb_info);
+                       }
+
                        switch (cam_msg->event_class) {
                        case MUSE_CAMERA_EVENT_CLASS_THREAD_SUB:
-                               _camera_client_user_callback(cb_info, cam_msg->recv_msg, cam_msg->event, cam_msg->tfd);
+                               __camera_client_user_callback(cb_info, cam_msg->recv_msg, cam_msg->event, cam_msg->tfd);
                                break;
                        case MUSE_CAMERA_EVENT_CLASS_THREAD_MAIN:
                                cam_idle_event = g_new0(camera_idle_event_s, 1);
@@ -1782,7 +1856,7 @@ static gpointer _camera_msg_handler_func(gpointer data)
                                g_mutex_unlock(&g_cam_idle_event_lock);
 
                                g_idle_add_full(G_PRIORITY_DEFAULT,
-                                       (GSourceFunc)_camera_idle_event_callback,
+                                       (GSourceFunc)__camera_idle_event_callback,
                                        (gpointer)cam_idle_event,
                                        NULL);
                                break;
@@ -1795,7 +1869,6 @@ static gpointer _camera_msg_handler_func(gpointer data)
                }
 
                g_free(cam_msg);
-               cam_msg = NULL;
 
                g_mutex_lock(&handler_info->mutex);
        }
@@ -1804,23 +1877,23 @@ static gpointer _camera_msg_handler_func(gpointer data)
        while (!g_queue_is_empty(handler_info->queue)) {
                cam_msg = (camera_message_s *)g_queue_pop_head(handler_info->queue);
                if (cam_msg) {
-                       CAM_LOG_INFO("t:%d remove camera message %p", type, cam_msg);
-                       free(cam_msg);
-                       cam_msg = NULL;
+                       CAM_LOG_INFO("t:%d remove message %p", type, cam_msg);
+                       __camera_release_tfd(cam_msg->tfd);
+                       g_free(cam_msg);
                } else {
-                       CAM_LOG_WARNING("t:%d NULL camera message", type);
+                       CAM_LOG_WARNING("t:%d NULL message", type);
                }
        }
 
        g_mutex_unlock(&handler_info->mutex);
 
-       CAM_LOG_INFO("t:%d return", type);
+       CAM_LOG_INFO("t:%d return[thread:%p]", type, thread);
 
        return NULL;
 }
 
 
-static void _camera_deactivate_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;
        GList *list = NULL;
@@ -1855,7 +1928,6 @@ static void _camera_deactivate_idle_event_all(camera_cb_info_s *cb_info)
                        cb_info->idle_event_list = g_list_remove(cb_info->idle_event_list, (gpointer)cam_idle_event);
 
                        g_free(cam_idle_event);
-                       cam_idle_event = NULL;
 
                        continue;
                }
@@ -1872,8 +1944,6 @@ static void _camera_deactivate_idle_event_all(camera_cb_info_s *cb_info)
        cb_info->idle_event_list = NULL;
 
        g_mutex_unlock(&g_cam_idle_event_lock);
-
-       return;
 }
 
 
@@ -1896,7 +1966,7 @@ static void __camera_add_msg_to_queue(camera_cb_info_s *cb_info, int api, int ev
        cam_msg->event = event;
        cam_msg->event_class = event_class;
 
-       if (tfd && tfd[0] >= 0)
+       if (tfd)
                memcpy(cam_msg->tfd, tfd, sizeof(cam_msg->tfd));
 
        strncpy(cam_msg->recv_msg, msg, sizeof(cam_msg->recv_msg) - 1);
@@ -1905,6 +1975,16 @@ static void __camera_add_msg_to_queue(camera_cb_info_s *cb_info, int api, int ev
                api, event, event_class);
 
        if (event == MUSE_CAMERA_EVENT_TYPE_PREVIEW) {
+               if (!cb_info->preview_cb_info.thread) {
+                       LOGI("The thread for preview cb is not created yet, create it now");
+                       if (!__create_msg_handler_thread(&cb_info->preview_cb_info,
+                                       CAMERA_MESSAGE_HANDLER_TYPE_PREVIEW_CB, "cam:preview_cb", cb_info)) {
+                               CAM_LOG_ERROR("failed to create thread for preview cb");
+                               g_free(cam_msg);
+                               return;
+                       }
+               }
+
                g_mutex_lock(&cb_info->preview_cb_info.mutex);
                g_queue_push_tail(cb_info->preview_cb_info.queue, (gpointer)cam_msg);
                g_cond_signal(&cb_info->preview_cb_info.cond);
@@ -1922,8 +2002,6 @@ static void __camera_add_msg_to_queue(camera_cb_info_s *cb_info, int api, int ev
        }
 
        cam_msg = NULL;
-
-       return;
 }
 
 
@@ -2003,7 +2081,8 @@ static void __camera_process_msg(camera_cb_info_s *cb_info, char *msg, int *tfd)
                                        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) {
+                                       switch (api) {
+                                       case MUSE_CAMERA_API_GET_DISPLAY_ROI_AREA:
                                                muse_core_msg_deserialize("get_value",
                                                        msg, NULL, NULL, MUSE_TYPE_ARRAY, cb_info->get_display_roi_area);
                                                CAM_LOG_INFO("get display roi %d,%d,%dx%d",
@@ -2011,11 +2090,25 @@ static void __camera_process_msg(camera_cb_info_s *cb_info, char *msg, int *tfd)
                                                        cb_info->get_display_roi_area[1],
                                                        cb_info->get_display_roi_area[2],
                                                        cb_info->get_display_roi_area[3]);
-                                       } else {
+                                               break;
+                                       case MUSE_CAMERA_API_ATTR_GET_GEOTAG:
                                                muse_core_msg_deserialize("get_value",
                                                        msg, NULL, NULL, MUSE_TYPE_ARRAY, cb_info->get_geotag);
                                                CAM_LOG_INFO("get geotag %lf, %lf, %lf",
                                                        cb_info->get_geotag[0], cb_info->get_geotag[1], cb_info->get_geotag[2]);
+                                               break;
+                                       case MUSE_CAMERA_API_GET_EXTRA_PREVIEW_STREAM_FORMAT:
+                                               muse_core_msg_deserialize("get_value",
+                                                       msg, NULL, NULL, MUSE_TYPE_ARRAY, cb_info->get_extra_preview_stream_format);
+                                               CAM_LOG_INFO("get extra preview stream format %d,%dx%d,%d",
+                                                       cb_info->get_extra_preview_stream_format[0],
+                                                       cb_info->get_extra_preview_stream_format[1],
+                                                       cb_info->get_extra_preview_stream_format[2],
+                                                       cb_info->get_extra_preview_stream_format[3]);
+                                               break;
+                                       default:
+                                               CAM_LOG_WARNING("unknown api[%d]", api);
+                                               break;
                                        }
                                        break;
                                case MUSE_CAMERA_GET_TYPE_STRING:
@@ -2033,7 +2126,7 @@ static void __camera_process_msg(camera_cb_info_s *cb_info, char *msg, int *tfd)
                        cb_info->api_ret[api] = ret;
                        cb_info->api_activating[api] = TRUE;
 
-                       g_cond_signal(&cb_info->api_cond[api]);
+                       g_cond_broadcast(&cb_info->api_cond[api]);
                } else {
                        CAM_LOG_WARNING("no waiting for this api [%d]", api);
                }
@@ -2044,16 +2137,14 @@ static void __camera_process_msg(camera_cb_info_s *cb_info, char *msg, int *tfd)
        } else {
                CAM_LOG_WARNING("unknown camera api %d, class %d", api, api_class);
        }
-
-       return;
 }
 
 
-static gpointer _camera_msg_recv_func(gpointer data)
+static gpointer __camera_msg_recv_func(gpointer data)
 {
        int i = 0;
        int recv_length = 0;
-       int tfd[MUSE_NUM_FD] = {-1, -1, -1, -1};
+       int tfd[MUSE_NUM_FD] = {CAMERA_FD_INIT, CAMERA_FD_INIT, CAMERA_FD_INIT, CAMERA_FD_INIT};
        char *recv_msg = NULL;
        camera_cb_info_s *cb_info = (camera_cb_info_s *)data;
 
@@ -2068,7 +2159,7 @@ static gpointer _camera_msg_recv_func(gpointer data)
 
        while (g_atomic_int_get(&cb_info->msg_recv_running)) {
                for (i = 0 ; i < MUSE_NUM_FD ; i++)
-                       tfd[i] = -1;
+                       tfd[i] = CAMERA_FD_INIT;
 
                recv_length = muse_core_msg_recv_fd(cb_info->fd, recv_msg, MUSE_MSG_MAX_LENGTH, tfd);
                if (recv_length <= 0) {
@@ -2077,7 +2168,7 @@ static gpointer _camera_msg_recv_func(gpointer data)
                        break;
                }
 
-               if (tfd[0] >= 0)
+               if (CAMERA_IS_FD_VALID(tfd[0]))
                        CAM_LOG_DEBUG("tfd[%d/%d/%d/%d]", tfd[0], tfd[1], tfd[2], tfd[3]);
 
                recv_msg[recv_length] = '\0';
@@ -2089,6 +2180,7 @@ static gpointer _camera_msg_recv_func(gpointer data)
 
        CAM_LOG_INFO("client cb exit - server connected %d", cb_info->is_server_connected);
 
+//LCOV_EXCL_START
        if (!cb_info->is_server_connected) {
                char *error_msg = NULL;
 
@@ -2123,8 +2215,14 @@ static gpointer _camera_msg_recv_func(gpointer data)
                muse_core_msg_free(error_msg);
                error_msg = NULL;
 
+               for (i = 0 ; i < MUSE_CAMERA_API_MAX ; i++) {
+                       if (cb_info->api_waiting[i])
+                               g_cond_broadcast(&cb_info->api_cond[i]);
+               }
+
                CAM_LOG_ERROR("add error msg for service disconnection done");
        }
+//LCOV_EXCL_STOP
 
        return NULL;
 }
@@ -2139,7 +2237,14 @@ static bool __create_msg_handler_thread(camera_msg_handler_info_s *handler_info,
                return false;
        }
 
-       CAM_LOG_INFO("t:%d", type);
+       g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&handler_info->mutex);
+
+       if (handler_info->thread) {
+               CAM_LOG_WARNING("t:%d thread[%p] is already created", type, handler_info->thread);
+               return true;
+       }
+
+       CAM_LOG_INFO("t:%d [%s]", type, thread_name);
 
        handler_info->type = type;
        handler_info->queue = g_queue_new();
@@ -2148,26 +2253,21 @@ static bool __create_msg_handler_thread(camera_msg_handler_info_s *handler_info,
                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,
-               _camera_msg_handler_func, (gpointer)handler_info, NULL);
+               __camera_msg_handler_func, (gpointer)handler_info, NULL);
        if (handler_info->thread == NULL) {
                CAM_LOG_ERROR("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;
        }
 
-       CAM_LOG_INFO("t:%d done", type);
+       CAM_LOG_INFO("t:%d done[thread:%p]", type, handler_info->thread);
 
        return true;
 }
@@ -2175,95 +2275,172 @@ static bool __create_msg_handler_thread(camera_msg_handler_info_s *handler_info,
 
 static void __destroy_msg_handler_thread(camera_msg_handler_info_s *handler_info)
 {
-       int type = 0;
+       GThread *thread = NULL;
 
        if (!handler_info) {
                CAM_LOG_ERROR("NULL handler");
                return;
        }
 
+       g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&handler_info->mutex);
+
        if (!handler_info->thread) {
-               CAM_LOG_WARNING("thread is not created");
+               CAM_LOG_WARNING("thread[t:%d] is not created", handler_info->type);
                return;
        }
 
-       type = handler_info->type;
+       thread = handler_info->thread;
+       handler_info->thread = NULL;
 
-       CAM_LOG_INFO("t:%d thread %p", type, handler_info->thread);
+       CAM_LOG_INFO("t:%d thread[%p]", handler_info->type, 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);
-       handler_info->thread = NULL;
+       g_clear_pointer(&locker, g_mutex_locker_free);
+
+       g_thread_join(thread);
 
-       g_mutex_clear(&handler_info->mutex);
-       g_cond_clear(&handler_info->cond);
        g_queue_free(handler_info->queue);
        handler_info->queue = NULL;
 
-       CAM_LOG_INFO("t:%d done", type);
-
-       return;
+       CAM_LOG_INFO("t:%d done", handler_info->type);
 }
 
 
-static camera_cb_info_s *_camera_client_callback_new(gint sockfd)
+static void __camera_mutex_cond_init(camera_cb_info_s *cb_info)
 {
-       camera_cb_info_s *cb_info = NULL;
-       gint i = 0;
-
-       g_return_val_if_fail(sockfd > 0, NULL);
+       int i = 0;
 
-       cb_info = g_new0(camera_cb_info_s, 1);
-       if (cb_info == NULL) {
-               CAM_LOG_ERROR("cb_info failed");
-               goto ErrorExit;
+       if (!cb_info) {
+               CAM_LOG_ERROR("NULL cb_info");
+               return;
        }
 
-       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]);
        }
 
+       for (i = 0 ; i < MUSE_CAMERA_EVENT_TYPE_NUM ; i++)
+               g_mutex_init(&cb_info->user_cb_mutex[i]);
+
        g_mutex_init(&cb_info->fd_lock);
        g_mutex_init(&cb_info->mp_data_mutex);
+       g_mutex_init(&cb_info->bridge_lock);
+
+       g_mutex_init(&cb_info->msg_handler_info.mutex);
+       g_mutex_init(&cb_info->preview_cb_info.mutex);
+       g_mutex_init(&cb_info->capture_cb_info.mutex);
+       g_cond_init(&cb_info->msg_handler_info.cond);
+       g_cond_init(&cb_info->preview_cb_info.cond);
+       g_cond_init(&cb_info->capture_cb_info.cond);
+
+       CAM_LOG_INFO("done");
+}
+
+
+static void __camera_mutex_cond_clear(camera_cb_info_s *cb_info)
+{
+       int i = 0;
+
+       if (!cb_info) {
+               CAM_LOG_ERROR("NULL cb_info");
+               return;
+       }
+
+       g_mutex_clear(&cb_info->msg_handler_info.mutex);
+       g_mutex_clear(&cb_info->preview_cb_info.mutex);
+       g_mutex_clear(&cb_info->capture_cb_info.mutex);
+       g_cond_clear(&cb_info->msg_handler_info.cond);
+       g_cond_clear(&cb_info->preview_cb_info.cond);
+       g_cond_clear(&cb_info->capture_cb_info.cond);
+
+       g_mutex_clear(&cb_info->fd_lock);
+       g_mutex_clear(&cb_info->mp_data_mutex);
+       g_mutex_clear(&cb_info->bridge_lock);
 
        for (i = 0 ; i < MUSE_CAMERA_EVENT_TYPE_NUM ; i++)
-               g_mutex_init(&cb_info->user_cb_mutex[i]);
+               g_mutex_clear(&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)) {
-               CAM_LOG_ERROR("msg_handler_info failed");
+       for (i = 0 ; i < MUSE_CAMERA_API_MAX ; i++) {
+               g_mutex_clear(&cb_info->api_mutex[i]);
+               g_cond_clear(&cb_info->api_cond[i]);
+       }
+
+       CAM_LOG_INFO("done");
+}
+
+
+static camera_preview_cb_monitoring_info_s *__camera_preview_cb_monitoring_info_create(int stream_id)
+{
+       camera_preview_cb_monitoring_info_s *new_info = g_new0(camera_preview_cb_monitoring_info_s, 1);
+
+       new_info->stream_id = stream_id;
+       new_info->total = g_new0(monitoring_info_sub_s, 1);
+       new_info->interval = g_new0(monitoring_info_sub_s, 1);
+       new_info->timer_calling = g_timer_new();
+       new_info->timer_interval = g_timer_new();
+
+       CAM_LOG_INFO("create preview cb monitoring info[%p]", new_info);
+
+       return new_info;
+}
+
+
+static void __camera_preview_cb_monitoring_info_destroy(camera_preview_cb_monitoring_info_s *info)
+{
+       if (!info)
+               return;
+
+       g_timer_destroy(info->timer_calling);
+       g_timer_destroy(info->timer_interval);
+       g_free(info->total);
+       g_free(info->interval);
+
+       CAM_LOG_INFO("destroy preview cb monitoring info[%p]", info);
+
+       g_free(info);
+}
+
+
+static camera_cb_info_s *__camera_client_callback_new(gint sockfd)
+{
+       int i = 0;
+       camera_cb_info_s *cb_info = NULL;
+
+       g_return_val_if_fail(sockfd > 0, NULL);
+
+       cb_info = g_new0(camera_cb_info_s, 1);
+       if (!cb_info) {
+               CAM_LOG_ERROR("cb_info failed");
                goto ErrorExit;
        }
 
-       /* message handler thread for preview callback */
-       if (!__create_msg_handler_thread(&cb_info->preview_cb_info,
-               CAMERA_MESSAGE_HANDLER_TYPE_PREVIEW_CB, "camera_msg_handler:preview_cb", cb_info)) {
-               CAM_LOG_ERROR("preview_cb_info failed");
+       cb_info->api_waiting[MUSE_CAMERA_API_CREATE] = 1;
+
+       __camera_mutex_cond_init(cb_info);
+
+       /* message handler thread */
+       if (!__create_msg_handler_thread(&cb_info->msg_handler_info,
+                       CAMERA_MESSAGE_HANDLER_TYPE_GENERAL, "cam:msg_handler", cb_info)) {
+               CAM_LOG_ERROR("msg_handler_info failed");
                goto ErrorExit;
        }
 
        /* message handler thread for capture callback */
        if (!__create_msg_handler_thread(&cb_info->capture_cb_info,
-               CAMERA_MESSAGE_HANDLER_TYPE_CAPTURE_CB, "camera_msg_handler:capture_cb", cb_info)) {
+                       CAMERA_MESSAGE_HANDLER_TYPE_CAPTURE_CB, "cam:capture_cb", cb_info)) {
                CAM_LOG_ERROR("capture_cb_info failed");
                goto ErrorExit;
        }
 
        cb_info->fd = sockfd;
-       cb_info->preview_cb_flag = 0;
 
        /* message receive thread */
        g_atomic_int_set(&cb_info->msg_recv_running, 1);
-       cb_info->msg_recv_thread = g_thread_try_new("camera_msg_recv",
-               _camera_msg_recv_func, (gpointer)cb_info, NULL);
+       cb_info->msg_recv_thread = g_thread_try_new("cam:msg_recv",
+               __camera_msg_recv_func, (gpointer)cb_info, NULL);
        if (cb_info->msg_recv_thread == NULL) {
                CAM_LOG_ERROR("message receive thread creation failed");
                goto ErrorExit;
@@ -2271,28 +2448,23 @@ static camera_cb_info_s *_camera_client_callback_new(gint sockfd)
 
        /* initialize fd */
        for (i = 0 ; i < MUSE_NUM_FD ; i++)
-               cb_info->fds[i] = -1;
+               cb_info->fds[i] = CAMERA_FD_INIT;
 
        cb_info->is_server_connected = TRUE;
 
+       cb_info->monitoring_info_preview = __camera_preview_cb_monitoring_info_create(CAMERA_MONITORING_INFO_STREAM_ID_PREVIEW);
+       cb_info->monitoring_info_preview_mp = __camera_preview_cb_monitoring_info_create(CAMERA_MONITORING_INFO_STREAM_ID_PREVIEW_MP);
+       for (i = 0 ; i < MM_CAMCORDER_EXTRA_PREVIEW_STREAM_MAX ; i++)
+               cb_info->monitoring_info_preview_ex[i] = __camera_preview_cb_monitoring_info_create(i);
+
        return cb_info;
 //LCOV_EXCL_START
 ErrorExit:
        if (cb_info) {
                __destroy_msg_handler_thread(&cb_info->msg_handler_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->mp_data_mutex);
-
-               for (i = 0 ; i < MUSE_CAMERA_API_MAX ; i++) {
-                       g_mutex_clear(&cb_info->api_mutex[i]);
-                       g_cond_clear(&cb_info->api_cond[i]);
-               }
+               __camera_mutex_cond_clear(cb_info);
 
                g_free(cb_info);
                cb_info = NULL;
@@ -2302,11 +2474,15 @@ ErrorExit:
 //LCOV_EXCL_STOP
 }
 
-static void _camera_client_callback_destroy(camera_cb_info_s *cb_info)
+
+static void __camera_client_callback_destroy(camera_cb_info_s *cb_info)
 {
        int i = 0;
 
-       g_return_if_fail(cb_info != NULL);
+       if (!cb_info) {
+               CAM_LOG_ERROR("NULL cb_info");
+               return;
+       }
 
        CAM_LOG_INFO("msg_recv thread[%p] destroy", cb_info->msg_recv_thread);
 
@@ -2316,24 +2492,15 @@ static void _camera_client_callback_destroy(camera_cb_info_s *cb_info)
        CAM_LOG_INFO("msg_recv thread removed");
 
        /* destroy msg handler threads */
-       __destroy_msg_handler_thread(&cb_info->msg_handler_info);
        __destroy_msg_handler_thread(&cb_info->preview_cb_info);
+       __destroy_msg_handler_thread(&cb_info->msg_handler_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->mp_data_mutex);
-
-       for (i = 0 ; i < MUSE_CAMERA_API_MAX ; i++) {
-               g_mutex_clear(&cb_info->api_mutex[i]);
-               g_cond_clear(&cb_info->api_cond[i]);
-       }
+       __camera_mutex_cond_clear(cb_info);
 
-       if (cb_info->fd > -1) {
+       if (CAMERA_IS_FD_VALID(cb_info->fd)) {
                muse_client_close(cb_info->fd);
-               cb_info->fd = -1;
+               cb_info->fd = CAMERA_FD_INIT;
        }
 
        if (cb_info->bufmgr) {
@@ -2350,11 +2517,12 @@ static void _camera_client_callback_destroy(camera_cb_info_s *cb_info)
                cb_info->dp_interface = NULL;
        }
 
-       cb_info->preview_cb_flag = 0;
+       __camera_preview_cb_monitoring_info_destroy(cb_info->monitoring_info_preview);
+       __camera_preview_cb_monitoring_info_destroy(cb_info->monitoring_info_preview_mp);
+       for (i = 0 ; i < MM_CAMCORDER_EXTRA_PREVIEW_STREAM_MAX ; i++)
+               __camera_preview_cb_monitoring_info_destroy(cb_info->monitoring_info_preview_ex[i]);
 
        g_free(cb_info);
-
-       return;
 }
 
 //LCOV_EXCL_START
@@ -2362,14 +2530,11 @@ int _camera_start_evas_rendering(camera_h camera)
 {
        camera_cli_s *pc = (camera_cli_s *)camera;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("start");
 
-       if (!CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
+       if (!pc->cb_info->is_evas_render) {
                CAM_LOG_ERROR("EVAS surface is not set");
                return CAMERA_ERROR_NONE;
        }
@@ -2386,14 +2551,11 @@ int _camera_stop_evas_rendering(camera_h camera, bool keep_screen)
        int ret = CAMERA_ERROR_NONE;
        camera_cli_s *pc = (camera_cli_s *)camera;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("stop - keep screen %d", keep_screen);
 
-       if (!CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
+       if (!pc->cb_info->is_evas_render) {
                CAM_LOG_ERROR("EVAS surface is not set");
                return CAMERA_ERROR_NONE;
        }
@@ -2416,7 +2578,7 @@ int _camera_stop_evas_rendering(camera_h camera, bool keep_screen)
 int _camera_independent_request(int api, int device_type, const char *key, int *value)
 {
        int ret = CAMERA_ERROR_NONE;
-       int sock_fd = -1;
+       int sock_fd = CAMERA_FD_INIT;
        int module_index = -1;
        char *msg = NULL;
        char recv_msg[MUSE_CAMERA_MSG_MAX_LENGTH] = {'\0',};
@@ -2479,18 +2641,18 @@ int _camera_independent_request(int api, int device_type, const char *key, int *
        CAM_LOG_INFO("api %d - value %d", api, *value);
 
 _REQUEST_EXIT:
-       if (sock_fd > -1) {
+       if (CAMERA_IS_FD_VALID(sock_fd)) {
                muse_client_close(sock_fd);
-               sock_fd = -1;
+               sock_fd = CAMERA_FD_INIT;
        }
 
        return ret;
 }
 
 
-int camera_create(camera_device_e device, camera_h *camera)
+int _camera_create_private(camera_device_e device, bool is_network, camera_h *camera)
 {
-       int sock_fd = -1;
+       int sock_fd = CAMERA_FD_INIT;
        char *send_msg = NULL;
        int send_ret = 0;
        int ret = CAMERA_ERROR_NONE;
@@ -2501,10 +2663,7 @@ int camera_create(camera_device_e device, camera_h *camera)
        int module_index = -1;
        int device_type = (int)device;
 
-       if (!camera) {
-               CAM_LOG_ERROR("NULL pointer");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAM_LOG_INFO("device %d, is_network %d", device, is_network);
 
        sock_fd = muse_client_new();
        if (sock_fd < 0) {
@@ -2522,6 +2681,7 @@ int camera_create(camera_device_e device, camera_h *camera)
        send_msg = muse_core_msg_new(api,
                MUSE_TYPE_INT, "module", module_index,
                MUSE_TYPE_INT, PARAM_DEVICE_TYPE, device_type,
+               MUSE_TYPE_INT, "is_network", (int)is_network,
                0);
 
        if (!send_msg) {
@@ -2555,14 +2715,14 @@ int camera_create(camera_device_e device, camera_h *camera)
                goto ErrorExit;
        }
 
-       pc->cb_info = _camera_client_callback_new(sock_fd);
+       pc->cb_info = __camera_client_callback_new(sock_fd);
        if (pc->cb_info == NULL) {
                CAM_LOG_ERROR("cb_info alloc failed");
                ret = CAMERA_ERROR_OUT_OF_MEMORY;
                goto ErrorExit;
        }
 
-       sock_fd = -1;
+       sock_fd = CAMERA_FD_INIT;
 
        CAM_LOG_INFO("cb info : %d", pc->cb_info->fd);
 
@@ -2573,6 +2733,7 @@ int camera_create(camera_device_e device, camera_h *camera)
        if (ret == CAMERA_ERROR_NONE) {
                int preview_format = CAMERA_PIXEL_FORMAT_INVALID;
                int user_buffer_supported = 0;
+               int log_level = CAMERA_LOG_LEVEL_INFO;
                intptr_t handle = 0;
 
                muse_camera_msg_get_pointer(handle, pc->cb_info->recv_msg);
@@ -2584,19 +2745,24 @@ int camera_create(camera_device_e device, camera_h *camera)
 
                muse_camera_msg_get(preview_format, pc->cb_info->recv_msg);
                muse_camera_msg_get(user_buffer_supported, pc->cb_info->recv_msg);
-
-               g_mmcam_log_level = CAMERA_LOG_LEVEL_INFO;
-
-
+               muse_camera_msg_get(log_level, pc->cb_info->recv_msg);
 
                pc->remote_handle = handle;
                pc->cb_info->bufmgr = bufmgr;
                pc->cb_info->preview_format = preview_format;
                pc->cb_info->dp_info.type = CAMERA_DISPLAY_TYPE_NONE;
                pc->cb_info->user_buffer_supported = (gboolean)user_buffer_supported;
+               pc->cb_info->is_network = is_network;
+               g_camera_log_level = log_level;
 
                CAM_LOG_INFO("default preview format %d, user buffer %d, log level %d",
-                       preview_format, user_buffer_supported, g_mmcam_log_level);
+                       preview_format, user_buffer_supported, g_camera_log_level);
+
+               if (!camera) {
+                       CAM_LOG_ERROR("NULL out handle");
+                       ret= CAMERA_ERROR_INVALID_PARAMETER;
+                       goto ErrorExit;
+               }
 
                *camera = (camera_h)pc;
 
@@ -2615,9 +2781,9 @@ ErrorExit:
                bufmgr = NULL;
        }
 
-       if (sock_fd > -1) {
+       if (CAMERA_IS_FD_VALID(sock_fd)) {
                muse_client_close(sock_fd);
-               sock_fd = -1;
+               sock_fd = CAMERA_FD_INIT;
        }
 
        if (pc) {
@@ -2626,13 +2792,13 @@ ErrorExit:
 
                        /* pc->cb_info->fd should be closed,
                           because g_thread_join for msg_recv_thread is not returned
-                          in _camera_client_callback_destroy. */
-                       if (temp_fd > -1) {
-                               pc->cb_info->fd = -1;
+                          in __camera_client_callback_destroy. */
+                       if (CAMERA_IS_FD_VALID(temp_fd)) {
+                               pc->cb_info->fd = CAMERA_FD_INIT;
                                muse_client_close(temp_fd);
                        }
 
-                       _camera_client_callback_destroy(pc->cb_info);
+                       __camera_client_callback_destroy(pc->cb_info);
                        pc->cb_info = NULL;
                }
                g_free(pc);
@@ -2646,6 +2812,12 @@ ErrorExit:
 }
 
 
+int camera_create(camera_device_e device, camera_h *camera)
+{
+       return _camera_create_private(device, false, camera);
+}
+
+
 int camera_change_device(camera_h camera, camera_device_e device)
 {
        int i = 0;
@@ -2654,10 +2826,7 @@ int camera_change_device(camera_h camera, camera_device_e device)
        camera_cli_s *pc = (camera_cli_s *)camera;
        camera_msg_param param;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAMERA_MSG_PARAM_SET(param, INT, device);
 
@@ -2669,7 +2838,6 @@ int camera_change_device(camera_h camera, camera_device_e device)
                        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;
@@ -2682,10 +2850,7 @@ int camera_destroy(camera_h camera)
        muse_camera_api_e api = MUSE_CAMERA_API_DESTROY;
        camera_cli_s *pc = (camera_cli_s *)camera;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -2695,8 +2860,8 @@ int camera_destroy(camera_h camera)
                CAM_LOG_WARNING("server disconnected. release resource without send message.");
 
        if (ret == CAMERA_ERROR_NONE) {
-               _camera_deactivate_idle_event_all(pc->cb_info);
-               _camera_client_callback_destroy(pc->cb_info);
+               __camera_deactivate_idle_event_all(pc->cb_info);
+               __camera_client_callback_destroy(pc->cb_info);
                pc->cb_info = NULL;
 
                g_free(pc);
@@ -2710,25 +2875,18 @@ int camera_destroy(camera_h camera)
 
 int camera_start_preview(camera_h camera)
 {
+       int i = 0;
        int ret = CAMERA_ERROR_NONE;
+       int *fds = NULL;
        muse_camera_api_e api = MUSE_CAMERA_API_START_PREVIEW;
        camera_cli_s *pc = (camera_cli_s *)camera;
        camera_state_e current_state = CAMERA_STATE_NONE;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter : preview format %d, display type %d",
                pc->cb_info->preview_format, pc->cb_info->dp_info.type);
 
-       ret = camera_get_state(camera, &current_state);
-       if (ret != CAMERA_ERROR_NONE) {
-               CAM_LOG_ERROR("failed to get current state 0x%x", ret);
-               return ret;
-       }
-
        if (pc->cb_info->preview_format == CAMERA_PIXEL_FORMAT_INVZ &&
                pc->cb_info->dp_info.type != CAMERA_DISPLAY_TYPE_NONE) {
                CAM_LOG_ERROR("CAMERA_DISPLAY_TYPE_NONE[current %d] should be set with INVZ format",
@@ -2736,24 +2894,67 @@ int camera_start_preview(camera_h camera)
                return CAMERA_ERROR_INVALID_OPERATION;
        }
 
-       if (current_state == CAMERA_STATE_CREATED && pc->cb_info->user_buffer_supported) {
-               if (!_camera_allocate_preview_buffer(camera))
+       ret = camera_get_state(camera, &current_state);
+       if (ret != CAMERA_ERROR_NONE) {
+               CAM_LOG_ERROR("failed to get current state 0x%x", ret);
+               return ret;
+       }
+
+       if (current_state == CAMERA_STATE_CREATED) {
+               __camera_preview_cb_monitoring_info_reset(pc->cb_info->monitoring_info_preview);
+               __camera_preview_cb_monitoring_info_reset(pc->cb_info->monitoring_info_preview_mp);
+               for (i = 0 ; i < MM_CAMCORDER_EXTRA_PREVIEW_STREAM_MAX ; i++)
+                       __camera_preview_cb_monitoring_info_reset(pc->cb_info->monitoring_info_preview_ex[i]);
+
+               if (!__create_msg_handler_thread(&pc->cb_info->preview_cb_info,
+                               CAMERA_MESSAGE_HANDLER_TYPE_PREVIEW_CB, "cam:preview_cb", pc->cb_info)) {
+                       CAM_LOG_ERROR("preview_cb_info failed");
                        return CAMERA_ERROR_INVALID_OPERATION;
+               }
 
-               _camera_msg_send(api, pc->cb_info->fds, pc->cb_info, &ret, CAMERA_CB_NO_TIMEOUT);
-       } else {
-               _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_NO_TIMEOUT);
+               if (pc->cb_info->user_buffer_supported) {
+                       if (!__camera_allocate_preview_buffer(camera)) {
+                               ret = CAMERA_ERROR_INVALID_OPERATION;
+                               goto _START_FAILED;
+                       }
+
+                       fds = pc->cb_info->fds;
+               }
        }
 
-       if (ret == CAMERA_ERROR_NONE && CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
+       pc->cb_info->invoke_preview_cb = TRUE;
+
+       _camera_msg_send(api, fds, pc->cb_info, &ret,
+#ifdef TIZEN_FEATURE_NO_TIMEOUT_FOR_PREVIEW
+               CAMERA_CB_NO_TIMEOUT);
+#else
+               CAMERA_CB_TIMEOUT_FOR_PREVIEW);
+#endif
+       if (ret != CAMERA_ERROR_NONE)
+               goto _START_FAILED;
+
+       if (pc->cb_info->is_evas_render) {
                ret = _camera_start_evas_rendering(camera);
                if (ret != CAMERA_ERROR_NONE) {
                        CAM_LOG_ERROR("stop preview because of error");
                        _camera_msg_send(MUSE_CAMERA_API_STOP_PREVIEW, NULL, pc->cb_info, NULL, 0);
+                       goto _START_FAILED;
                }
        }
 
-       CAM_LOG_INFO("ret : 0x%x", ret);
+       CAM_LOG_INFO("done");
+
+       return CAMERA_ERROR_NONE;
+
+_START_FAILED:
+       if (current_state == CAMERA_STATE_CREATED) {
+               if (pc->cb_info->user_buffer_supported)
+                       __camera_release_preview_buffer(camera);
+
+               __destroy_msg_handler_thread(&pc->cb_info->preview_cb_info);
+       }
+
+       CAM_LOG_ERROR("failed : 0x%x", ret);
 
        return ret;
 }
@@ -2766,15 +2967,12 @@ int camera_stop_preview(camera_h camera)
        muse_camera_api_e api = MUSE_CAMERA_API_STOP_PREVIEW;
        camera_state_e current_state = CAMERA_STATE_NONE;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
 //LCOV_EXCL_START
-       if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
+       if (pc->cb_info->is_evas_render) {
                ret = camera_get_state(camera, &current_state);
                if (ret != CAMERA_ERROR_NONE) {
                        CAM_LOG_ERROR("failed to get current state 0x%x", ret);
@@ -2788,12 +2986,17 @@ int camera_stop_preview(camera_h camera)
                }
        }
 //LCOV_EXCL_STOP
-       /* send stop preview message */
+
+       pc->cb_info->invoke_preview_cb = FALSE;
+
        _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
 
        if (ret == CAMERA_ERROR_NONE) {
                if (pc->cb_info->user_buffer_supported)
-                       _camera_release_preview_buffer(camera);
+                       __camera_release_preview_buffer(camera);
+
+               /* release remained message for preview callback */
+               __destroy_msg_handler_thread(&pc->cb_info->preview_cb_info);
        } else if (current_state == CAMERA_STATE_PREVIEW) {
                CAM_LOG_WARNING("restart evas rendering");
                _camera_start_evas_rendering(camera);
@@ -2811,10 +3014,7 @@ int camera_start_capture(camera_h camera, camera_capturing_cb capturing_cb, came
        camera_cli_s *pc = (camera_cli_s *)camera;
        muse_camera_api_e api = MUSE_CAMERA_API_START_CAPTURE;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -2834,27 +3034,7 @@ int camera_start_capture(camera_h camera, camera_capturing_cb capturing_cb, came
 
 bool camera_is_supported_continuous_capture(camera_h camera)
 {
-       int ret = CAMERA_ERROR_NONE;
-       camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_SUPPORT_CONTINUOUS_CAPTURE;
-
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
-
-       CAM_LOG_INFO("Enter");
-
-       _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
-
-       if (ret < 0) {
-               CAM_LOG_ERROR("error is occurred 0x%x", ret);
-               ret = false;
-       }
-
-       CAM_LOG_INFO("ret : %d", ret);
-
-       return (bool)ret;
+       return __is_supported(camera, MUSE_CAMERA_API_SUPPORT_CONTINUOUS_CAPTURE);
 }
 
 
@@ -2866,10 +3046,7 @@ int camera_start_continuous_capture(camera_h camera, int count, int interval, ca
        camera_msg_param param;
        int value = 0;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -2896,10 +3073,7 @@ int camera_stop_continuous_capture(camera_h camera)
        camera_cli_s *pc = (camera_cli_s *)camera;
        muse_camera_api_e api = MUSE_CAMERA_API_STOP_CONTINUOUS_CAPTURE;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -2913,114 +3087,55 @@ int camera_stop_continuous_capture(camera_h camera)
 
 bool camera_is_supported_face_detection(camera_h camera)
 {
-       int ret = CAMERA_ERROR_NONE;
-       camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_SUPPORT_FACE_DETECTION;
+       return __is_supported(camera, MUSE_CAMERA_API_SUPPORT_FACE_DETECTION);
+}
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
 
-       CAM_LOG_INFO("Enter");
+bool camera_is_supported_zero_shutter_lag(camera_h camera)
+{
+       return __is_supported(camera, MUSE_CAMERA_API_SUPPORT_ZERO_SHUTTER_LAG);
+}
 
-       _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
 
-       if (ret < 0) {
-               CAM_LOG_ERROR("error is occurred 0x%x", ret);
-               ret = false;
-       }
+bool camera_is_supported_media_packet_preview_cb(camera_h camera)
+{
+       return __is_supported(camera, MUSE_CAMERA_API_SUPPORT_MEDIA_PACKET_PREVIEW_CB);
+}
 
-       CAM_LOG_INFO("ret : %d", ret);
 
-       return (bool)ret;
+bool camera_is_supported_extra_preview(camera_h camera)
+{
+       return __is_supported(camera, MUSE_CAMERA_API_SUPPORT_EXTRA_PREVIEW);
 }
 
 
-bool camera_is_supported_zero_shutter_lag(camera_h camera)
+int camera_get_device_count(camera_h camera, int *device_count)
 {
        int ret = CAMERA_ERROR_NONE;
        camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_SUPPORT_ZERO_SHUTTER_LAG;
+       muse_camera_api_e api = MUSE_CAMERA_API_GET_DEVICE_COUNT;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
        _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
 
-       if (ret < 0) {
-               CAM_LOG_ERROR("error is occurred 0x%x", ret);
-               ret = false;
-       }
+       if (ret == CAMERA_ERROR_NONE)
+               *device_count = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DEVICE_COUNT];
 
-       CAM_LOG_INFO("ret : %d", ret);
+       CAM_LOG_INFO("ret : 0x%x", ret);
 
-       return (bool)ret;
+       return ret;
 }
 
-
-bool camera_is_supported_media_packet_preview_cb(camera_h camera)
+int camera_start_face_detection(camera_h camera, camera_face_detected_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_SUPPORT_MEDIA_PACKET_PREVIEW_CB;
+       muse_camera_api_e api = MUSE_CAMERA_API_START_FACE_DETECTION;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
-
-       CAM_LOG_INFO("Enter");
-
-       _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
-
-       if (ret < 0) {
-               CAM_LOG_ERROR("error is occurred 0x%x", ret);
-               ret = false;
-       }
-
-       CAM_LOG_INFO("ret : %d", ret);
-
-       return (bool)ret;
-}
-
-int camera_get_device_count(camera_h camera, int *device_count)
-{
-       int ret = CAMERA_ERROR_NONE;
-       camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_GET_DEVICE_COUNT;
-
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
-
-       CAM_LOG_INFO("Enter");
-
-       _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
-
-       if (ret == CAMERA_ERROR_NONE)
-               *device_count = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_DEVICE_COUNT];
-
-       CAM_LOG_INFO("ret : 0x%x", ret);
-
-       return ret;
-}
-
-int camera_start_face_detection(camera_h camera, camera_face_detected_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_START_FACE_DETECTION;
-
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -3046,10 +3161,7 @@ int camera_stop_face_detection(camera_h camera)
        camera_cli_s *pc = (camera_cli_s *)camera;
        muse_camera_api_e api = MUSE_CAMERA_API_STOP_FACE_DETECTION;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -3100,10 +3212,7 @@ int camera_start_focusing(camera_h camera, bool continuous)
        camera_msg_param param;
        int is_continuous = (int)continuous;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -3122,10 +3231,7 @@ int camera_cancel_focusing(camera_h camera)
        camera_cli_s *pc = (camera_cli_s *)camera;
        muse_camera_api_e api = MUSE_CAMERA_API_CANCEL_FOCUSING;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter, remote_handle : %td", pc->remote_handle);
 
@@ -3148,10 +3254,7 @@ int _camera_set_display(camera_h camera, mm_display_type_e type, void *display)
        muse_camera_api_e api = MUSE_CAMERA_API_SET_DISPLAY;
        muse_camera_display_info_s *dp_info = NULL;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        if (type > MM_DISPLAY_TYPE_OVERLAY_EXT) {
                CAM_LOG_ERROR("invalid type %d", type);
@@ -3245,10 +3348,8 @@ int _camera_set_display(camera_h camera, mm_display_type_e type, void *display)
 
        _camera_msg_send_param1(api, cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
 
-       if (ret == CAMERA_ERROR_NONE) {
-               if (type == MM_DISPLAY_TYPE_EVAS)
-                       SET_PREVIEW_CB_TYPE(cb_info, PREVIEW_CB_TYPE_EVAS);
-       }
+       if (ret == CAMERA_ERROR_NONE)
+               cb_info->is_evas_render = (type == MM_DISPLAY_TYPE_EVAS) ? TRUE : FALSE;
 
        return ret;
 }
@@ -3270,12 +3371,9 @@ int camera_set_preview_resolution(camera_h camera, int width, int height)
        camera_msg_param param;
        int value = 0;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
-       if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
+       if (pc->cb_info->is_evas_render) {
                ret = camera_get_state(camera, &current_state);
                if (ret != CAMERA_ERROR_NONE) {
                        CAM_LOG_ERROR("failed to get current state 0x%x", ret);
@@ -3315,10 +3413,7 @@ int camera_set_capture_resolution(camera_h camera, int width, int height)
        camera_msg_param param;
        int value = 0;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -3341,10 +3436,7 @@ int camera_set_capture_format(camera_h camera, camera_pixel_format_e format)
        muse_camera_api_e api = MUSE_CAMERA_API_SET_CAPTURE_FORMAT;
        camera_msg_param param;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter - format %d", set_format);
 
@@ -3366,10 +3458,7 @@ int camera_set_preview_format(camera_h camera, camera_pixel_format_e format)
        camera_cli_s *pc = (camera_cli_s *)camera;
        muse_camera_api_e api = MUSE_CAMERA_API_SET_PREVIEW_FORMAT;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter - format %d", set_format);
 
@@ -3419,12 +3508,9 @@ int camera_set_display_rotation(camera_h camera, camera_rotation_e rotation)
        camera_cli_s *pc = (camera_cli_s *)camera;
        camera_msg_param param;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
-       if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
+       if (pc->cb_info->is_evas_render) {
                ret = mm_display_interface_evas_set_rotation(pc->cb_info->dp_interface, rotation);
                if (ret != MM_ERROR_NONE) {
                        CAM_LOG_ERROR("failed to set rotation for evas surface 0x%x", ret);
@@ -3466,12 +3552,9 @@ int camera_set_display_flip(camera_h camera, camera_flip_e flip)
        camera_cli_s *pc = (camera_cli_s *)camera;
        camera_msg_param param;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
-       if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
+       if (pc->cb_info->is_evas_render) {
                ret = mm_display_interface_evas_set_flip(pc->cb_info->dp_interface, flip);
                if (ret != MM_ERROR_NONE) {
                        CAM_LOG_ERROR("failed to set flip for evas surface 0x%x", ret);
@@ -3513,12 +3596,9 @@ int camera_set_display_visible(camera_h camera, bool visible)
        camera_cli_s *pc = (camera_cli_s *)camera;
        camera_msg_param param;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
-       if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
+       if (pc->cb_info->is_evas_render) {
                ret = mm_display_interface_evas_set_visible(pc->cb_info->dp_interface, visible);
                if (ret != MM_ERROR_NONE) {
                        CAM_LOG_ERROR("failed to set visible for evas surface 0x%x", ret);
@@ -3560,12 +3640,9 @@ int camera_set_display_mode(camera_h camera, camera_display_mode_e mode)
        camera_cli_s *pc = (camera_cli_s *)camera;
        camera_msg_param param;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
-       if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
+       if (pc->cb_info->is_evas_render) {
                ret = mm_display_interface_evas_set_mode(pc->cb_info->dp_interface, mode);
                if (ret != MM_ERROR_NONE) {
                        CAM_LOG_ERROR("failed to set geometry for evas surface 0x%x", ret);
@@ -3607,10 +3684,7 @@ int camera_set_display_reuse_hint(camera_h camera, bool hint)
        camera_cli_s *pc = (camera_cli_s *)camera;
        camera_msg_param param;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter - hint %d", set_hint);
 
@@ -3764,8 +3838,6 @@ int camera_set_preview_cb(camera_h camera, camera_preview_cb callback, void *use
                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);
        }
 
        CAM_LOG_INFO("ret : 0x%x", ret);
@@ -3780,10 +3852,7 @@ int camera_unset_preview_cb(camera_h camera)
        camera_cli_s *pc = (camera_cli_s *)camera;
        muse_camera_api_e api = MUSE_CAMERA_API_UNSET_PREVIEW_CB;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -3796,8 +3865,6 @@ int camera_unset_preview_cb(camera_h camera)
                pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_PREVIEW] = NULL;
 
                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);
        }
 
        CAM_LOG_INFO("ret : 0x%x", ret);
@@ -3812,10 +3879,7 @@ int camera_set_media_packet_preview_cb(camera_h camera, camera_media_packet_prev
        camera_cli_s *pc = (camera_cli_s *)camera;
        muse_camera_api_e api = MUSE_CAMERA_API_SET_MEDIA_PACKET_PREVIEW_CB;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        if (camera_is_supported_media_packet_preview_cb(camera) == false) {
                CAM_LOG_ERROR("NOT SUPPORTED");
@@ -3852,9 +3916,11 @@ int camera_unset_media_packet_preview_cb(camera_h camera)
        camera_cli_s *pc = (camera_cli_s *)camera;
        muse_camera_api_e api = MUSE_CAMERA_API_UNSET_MEDIA_PACKET_PREVIEW_CB;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
+
+       if (camera_is_supported_media_packet_preview_cb(camera) == false) {
+               CAM_LOG_ERROR("NOT SUPPORTED");
+               return CAMERA_ERROR_NOT_SUPPORTED;
        }
 
        CAM_LOG_INFO("Enter");
@@ -3912,10 +3978,7 @@ int camera_unset_state_changed_cb(camera_h camera)
        camera_cli_s *pc = (camera_cli_s *)camera;
        muse_camera_api_e api = MUSE_CAMERA_API_UNSET_STATE_CHANGED_CB;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -3972,10 +4035,7 @@ int camera_unset_interrupted_cb(camera_h camera)
        camera_cli_s *pc = (camera_cli_s *)camera;
        muse_camera_api_e api = MUSE_CAMERA_API_UNSET_INTERRUPTED_CB;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -4032,10 +4092,7 @@ int camera_unset_interrupt_started_cb(camera_h camera)
        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) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -4092,10 +4149,7 @@ int camera_unset_focus_changed_cb(camera_h camera)
        camera_cli_s *pc = (camera_cli_s *)camera;
        muse_camera_api_e api = MUSE_CAMERA_API_UNSET_FOCUS_CHANGED_CB;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -4152,10 +4206,7 @@ int camera_unset_error_cb(camera_h camera)
        camera_cli_s *pc = (camera_cli_s *)camera;
        muse_camera_api_e api = MUSE_CAMERA_API_UNSET_ERROR_CB;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -4323,26 +4374,7 @@ int camera_attr_get_lens_orientation(camera_h camera, int *angle)
 
 int camera_attr_set_theater_mode(camera_h camera, camera_attr_theater_mode_e mode)
 {
-       int ret = CAMERA_ERROR_NONE;
-       camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_THEATER_MODE;
-       camera_msg_param param;
-       int set_mode = (int)mode;
-
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
-
-       CAM_LOG_INFO("Enter");
-
-       CAMERA_MSG_PARAM_SET(param, INT, set_mode);
-
-       _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
-
-       CAM_LOG_INFO("ret : 0x%x", ret);
-
-       return ret;
+       return __set_mode(camera, MUSE_CAMERA_API_ATTR_SET_THEATER_MODE, (int)mode);
 }
 
 
@@ -4402,10 +4434,7 @@ int camera_attr_set_preview_fps(camera_h camera, camera_attr_fps_e fps)
        camera_msg_param param;
        int set_fps = (int)fps;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -4426,10 +4455,7 @@ int camera_attr_set_image_quality(camera_h camera, int quality)
        muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_IMAGE_QUALITY;
        camera_msg_param param;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -4523,10 +4549,7 @@ int camera_attr_set_encoded_preview_bitrate(camera_h camera, int bitrate)
        camera_msg_param param;
        int set_bitrate = bitrate;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -4572,10 +4595,7 @@ int camera_attr_set_encoded_preview_gop_interval(camera_h camera, int interval)
        camera_msg_param param;
        int set_gop_interval = interval;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -4596,10 +4616,7 @@ int camera_attr_set_zoom(camera_h camera, int zoom)
        muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_ZOOM;
        camera_msg_param param;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter, remote_handle : %td", pc->remote_handle);
 
@@ -4615,24 +4632,7 @@ int camera_attr_set_zoom(camera_h camera, int zoom)
 
 int camera_attr_set_af_mode(camera_h camera, camera_attr_af_mode_e mode)
 {
-       int ret = CAMERA_ERROR_NONE;
-       camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_AF_MODE;
-       camera_msg_param param;
-       int set_mode = (int)mode;
-
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
-
-       CAM_LOG_INFO("Enter, remote_handle : %td", pc->remote_handle);
-
-       CAMERA_MSG_PARAM_SET(param, INT, set_mode);
-
-       _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
-
-       return ret;
+       return __set_mode(camera, MUSE_CAMERA_API_ATTR_SET_AF_MODE, (int)mode);
 }
 
 
@@ -4644,10 +4644,7 @@ int camera_attr_set_af_area(camera_h camera, int x, int y)
        camera_msg_param param;
        int value = 0;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter - %d,%d", x, y);
 
@@ -4668,10 +4665,7 @@ int camera_attr_clear_af_area(camera_h camera)
        camera_cli_s *pc = (camera_cli_s *)camera;
        muse_camera_api_e api = MUSE_CAMERA_API_ATTR_CLEAR_AF_AREA;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -4685,26 +4679,7 @@ int camera_attr_clear_af_area(camera_h camera)
 
 int camera_attr_set_exposure_mode(camera_h camera, camera_attr_exposure_mode_e mode)
 {
-       int ret = CAMERA_ERROR_NONE;
-       camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_EXPOSURE_MODE;
-       camera_msg_param param;
-       int set_mode = (int)mode;
-
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
-
-       CAM_LOG_INFO("Enter");
-
-       CAMERA_MSG_PARAM_SET(param, INT, set_mode);
-
-       _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
-
-       CAM_LOG_INFO("ret : 0x%x", ret);
-
-       return ret;
+       return __set_mode(camera, MUSE_CAMERA_API_ATTR_SET_EXPOSURE_MODE, (int)mode);
 }
 
 
@@ -4715,10 +4690,7 @@ int camera_attr_set_exposure(camera_h camera, int value)
        muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_EXPOSURE;
        camera_msg_param param;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -4740,10 +4712,7 @@ int camera_attr_set_iso(camera_h camera, camera_attr_iso_e iso)
        camera_msg_param param;
        int set_iso = (int)iso;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -4757,69 +4726,55 @@ int camera_attr_set_iso(camera_h camera, camera_attr_iso_e iso)
 }
 
 
-int camera_attr_set_brightness(camera_h camera, int level)
+int camera_attr_set_gain(camera_h camera, int level)
 {
-       int ret = CAMERA_ERROR_NONE;
-       camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_BRIGHTNESS;
-       camera_msg_param param;
-
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
-
-       CAM_LOG_INFO("Enter");
-
-       CAMERA_MSG_PARAM_SET(param, INT, level);
-
-       _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
+       return _camera_attr_set_level(camera, MUSE_CAMERA_API_ATTR_SET_GAIN, level);
+}
 
-       CAM_LOG_INFO("ret : 0x%x", ret);
 
-       return ret;
+int camera_attr_set_brightness(camera_h camera, int level)
+{
+       return _camera_attr_set_level(camera, MUSE_CAMERA_API_ATTR_SET_BRIGHTNESS, level);
 }
 
 
 int camera_attr_set_contrast(camera_h camera, int level)
 {
-       int ret = CAMERA_ERROR_NONE;
-       camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_CONTRAST;
-       camera_msg_param param;
+       return _camera_attr_set_level(camera, MUSE_CAMERA_API_ATTR_SET_CONTRAST, level);
+}
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
 
-       CAM_LOG_INFO("Enter");
+int camera_attr_set_hue(camera_h camera, int level)
+{
+       return _camera_attr_set_level(camera, MUSE_CAMERA_API_ATTR_SET_HUE, level);
+}
 
-       CAMERA_MSG_PARAM_SET(param, INT, level);
 
-       _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
+int camera_attr_set_saturation(camera_h camera, int level)
+{
+       return _camera_attr_set_level(camera, MUSE_CAMERA_API_ATTR_SET_SATURATION, level);
+}
 
-       CAM_LOG_INFO("ret : 0x%x", ret);
 
-       return ret;
+int camera_attr_set_sharpness(camera_h camera, int level)
+{
+       return _camera_attr_set_level(camera, MUSE_CAMERA_API_ATTR_SET_SHARPNESS, level);
 }
 
 
-int camera_attr_set_hue(camera_h camera, int level)
+int camera_attr_set_whitebalance(camera_h camera, camera_attr_whitebalance_e wb)
 {
        int ret = CAMERA_ERROR_NONE;
        camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_HUE;
+       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_WHITEBALANCE;
        camera_msg_param param;
+       int set_whitebalance = (int)wb;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
-       CAMERA_MSG_PARAM_SET(param, INT, level);
+       CAMERA_MSG_PARAM_SET(param, INT, set_whitebalance);
 
        _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
 
@@ -4829,22 +4784,18 @@ int camera_attr_set_hue(camera_h camera, int level)
 }
 
 
-int camera_attr_set_whitebalance(camera_h camera, camera_attr_whitebalance_e wb)
+int camera_attr_set_whitebalance_temperature(camera_h camera, int temperature)
 {
        int ret = CAMERA_ERROR_NONE;
        camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_WHITEBALANCE;
+       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_WHITEBALANCE_TEMPERATURE;
        camera_msg_param param;
-       int set_whitebalance = (int)wb;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
-       CAMERA_MSG_PARAM_SET(param, INT, set_whitebalance);
+       CAMERA_MSG_PARAM_SET(param, INT, temperature);
 
        _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
 
@@ -4862,10 +4813,7 @@ int camera_attr_set_effect(camera_h camera, camera_attr_effect_mode_e effect)
        camera_msg_param param;
        int set_effect = (int)effect;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -4881,51 +4829,13 @@ int camera_attr_set_effect(camera_h camera, camera_attr_effect_mode_e effect)
 
 int camera_attr_set_scene_mode(camera_h camera, camera_attr_scene_mode_e mode)
 {
-       int ret = CAMERA_ERROR_NONE;
-       camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_SCENE_MODE;
-       camera_msg_param param;
-       int set_mode = (int)mode;
-
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
-
-       CAM_LOG_INFO("Enter");
-
-       CAMERA_MSG_PARAM_SET(param, INT, set_mode);
-
-       _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
-
-       CAM_LOG_INFO("ret : 0x%x", ret);
-
-       return ret;
-}
+       return __set_mode(camera, MUSE_CAMERA_API_ATTR_SET_SCENE_MODE, (int)mode);
+}
 
 
 int camera_attr_enable_tag(camera_h camera, bool enable)
 {
-       int ret = CAMERA_ERROR_NONE;
-       camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_ENABLE_TAG;
-       camera_msg_param param;
-       int set_enable = (int)enable;
-
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
-
-       CAM_LOG_INFO("Enter");
-
-       CAMERA_MSG_PARAM_SET(param, INT, set_enable);
-
-       _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
-
-       CAM_LOG_INFO("ret : 0x%x", ret);
-
-       return ret;
+       return __set_enable(camera, MUSE_CAMERA_API_ATTR_ENABLE_TAG, (int)enable);
 }
 
 
@@ -4961,10 +4871,7 @@ int camera_attr_set_tag_orientation(camera_h camera, camera_attr_tag_orientation
        camera_msg_param param;
        int set_orientation = (int)orientation;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -5010,12 +4917,8 @@ int camera_attr_set_geotag(camera_h camera, double latitude, double longitude, d
        double set_geotag[3] = {latitude, longitude, altitude};
        char *msg = NULL;
        int length = 0;
-       int send_ret = 0;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -5025,31 +4928,8 @@ int camera_attr_set_geotag(camera_h camera, double latitude, double longitude, d
        msg = muse_core_msg_new(api,
                MUSE_TYPE_ARRAY, "set_geotag", length, (int *)set_geotag,
                NULL);
-       if (!msg) {
-               CAM_LOG_ERROR("msg creation failed: api %d", api);
-               return CAMERA_ERROR_OUT_OF_MEMORY;
-       }
-
-       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_msg_send(pc->cb_info->fd, msg);
-               g_mutex_unlock(&pc->cb_info->fd_lock);
-       }
-
-       if (send_ret < 0) {
-               CAM_LOG_ERROR("message send failed");
-               ret = CAMERA_ERROR_INVALID_OPERATION;
-       } else {
-               ret = _camera_client_wait_for_cb_return(api, pc->cb_info, CAMERA_CB_TIMEOUT);
-       }
-
-       __camera_update_api_waiting(pc->cb_info, api, -1);
 
-       muse_core_msg_free(msg);
-
-       CAM_LOG_INFO("ret : 0x%x", ret);
+       _camera_send_message_get_return(pc->cb_info, api, msg, CAMERA_CB_TIMEOUT, &ret);
 
        return ret;
 }
@@ -5061,10 +4941,7 @@ int camera_attr_remove_geotag(camera_h camera)
        camera_cli_s *pc = (camera_cli_s *)camera;
        muse_camera_api_e api = MUSE_CAMERA_API_ATTR_REMOVE_GEOTAG;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -5078,26 +4955,7 @@ int camera_attr_remove_geotag(camera_h camera)
 
 int camera_attr_set_flash_mode(camera_h camera, camera_attr_flash_mode_e mode)
 {
-       int ret = CAMERA_ERROR_NONE;
-       camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_FLASH_MODE;
-       camera_msg_param param;
-       int set_mode = (int)mode;
-
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
-
-       CAM_LOG_INFO("Enter");
-
-       CAMERA_MSG_PARAM_SET(param, INT, set_mode);
-
-       _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
-
-       CAM_LOG_INFO("ret : 0x%x", ret);
-
-       return ret;
+       return __set_mode(camera, MUSE_CAMERA_API_ATTR_SET_FLASH_MODE, (int)mode);
 }
 
 
@@ -5127,27 +4985,10 @@ int camera_attr_get_zoom(camera_h camera, int *zoom)
 
 int camera_attr_get_zoom_range(camera_h camera, int *min, int *max)
 {
-       int ret = CAMERA_ERROR_NONE;
-       camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_ZOOM_RANGE;
-
-       if (!pc || !pc->cb_info || !min || !max) {
-               CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
-
-       CAM_LOG_INFO("Enter");
-
-       _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
-
-       if (ret == CAMERA_ERROR_NONE) {
-               *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_ZOOM_RANGE][0];
-               *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_ZOOM_RANGE][1];
-       }
-
-       CAM_LOG_INFO("ret : 0x%x", ret);
-
-       return ret;
+       return _camera_attr_get_range(camera,
+               MUSE_CAMERA_API_ATTR_GET_ZOOM_RANGE,
+               MUSE_CAMERA_GET_INT_PAIR_ZOOM_RANGE,
+               min, max);
 }
 
 
@@ -5225,27 +5066,10 @@ int camera_attr_get_exposure(camera_h camera, int *value)
 
 int camera_attr_get_exposure_range(camera_h camera, int *min, int *max)
 {
-       int ret = CAMERA_ERROR_NONE;
-       camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EXPOSURE_RANGE;
-
-       if (!pc || !pc->cb_info || !min || !max) {
-               CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
-
-       CAM_LOG_INFO("Enter");
-
-       _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
-
-       if (ret == CAMERA_ERROR_NONE) {
-               *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_EXPOSURE_RANGE][0];
-               *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_EXPOSURE_RANGE][1];
-       }
-
-       CAM_LOG_INFO("ret : 0x%x", ret);
-
-       return ret;
+       return _camera_attr_get_range(camera,
+               MUSE_CAMERA_API_ATTR_GET_EXPOSURE_RANGE,
+               MUSE_CAMERA_GET_INT_PAIR_EXPOSURE_RANGE,
+               min, max);
 }
 
 
@@ -5273,14 +5097,32 @@ int camera_attr_get_iso(camera_h camera, camera_attr_iso_e *iso)
 }
 
 
-int camera_attr_get_brightness(camera_h camera, int *level)
+int camera_attr_get_gain(camera_h camera, int *level)
+{
+       return _camera_attr_get_level(camera,
+               MUSE_CAMERA_API_ATTR_GET_GAIN,
+               MUSE_CAMERA_GET_INT_GAIN,
+               level);
+}
+
+
+int camera_attr_get_gain_range(camera_h camera, int *min, int *max)
+{
+       return _camera_attr_get_range(camera,
+               MUSE_CAMERA_API_ATTR_GET_GAIN_RANGE,
+               MUSE_CAMERA_GET_INT_PAIR_GAIN_RANGE,
+               min, max);
+}
+
+
+int camera_attr_get_gain_step(camera_h camera, int *step)
 {
        int ret = CAMERA_ERROR_NONE;
        camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_BRIGHTNESS;
+       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_GAIN_STEP;
 
-       if (!pc || !pc->cb_info || !level) {
-               CAM_LOG_ERROR("NULL pointer %p %p", pc, level);
+       if (!pc || !pc->cb_info || !step) {
+               CAM_LOG_ERROR("NULL pointer %p %p", pc, step);
                return CAMERA_ERROR_INVALID_PARAMETER;
        }
 
@@ -5289,7 +5131,7 @@ int camera_attr_get_brightness(camera_h camera, int *level)
        _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
 
        if (ret == CAMERA_ERROR_NONE)
-               *level = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_BRIGHTNESS];
+               *step = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_GAIN_STEP];
 
        CAM_LOG_INFO("ret : 0x%x", ret);
 
@@ -5297,91 +5139,104 @@ int camera_attr_get_brightness(camera_h camera, int *level)
 }
 
 
-int camera_attr_get_brightness_range(camera_h camera, int *min, int *max)
+int camera_attr_get_brightness(camera_h camera, int *level)
 {
-       int ret = CAMERA_ERROR_NONE;
-       camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_BRIGHTNESS_RANGE;
-
-       if (!pc || !pc->cb_info || !min || !max) {
-               CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
-
-       CAM_LOG_INFO("Enter");
-
-       _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
-
-       if (ret == CAMERA_ERROR_NONE) {
-               *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_BRIGHTNESS_RANGE][0];
-               *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_BRIGHTNESS_RANGE][1];
-       }
+       return _camera_attr_get_level(camera,
+               MUSE_CAMERA_API_ATTR_GET_BRIGHTNESS,
+               MUSE_CAMERA_GET_INT_BRIGHTNESS,
+               level);
+}
 
-       CAM_LOG_INFO("ret : 0x%x", ret);
 
-       return ret;
+int camera_attr_get_brightness_range(camera_h camera, int *min, int *max)
+{
+       return _camera_attr_get_range(camera,
+               MUSE_CAMERA_API_ATTR_GET_BRIGHTNESS_RANGE,
+               MUSE_CAMERA_GET_INT_PAIR_BRIGHTNESS_RANGE,
+               min, max);
 }
 
 
 int camera_attr_get_contrast(camera_h camera, int *level)
 {
-       int ret = CAMERA_ERROR_NONE;
-       camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_CONTRAST;
+       return _camera_attr_get_level(camera,
+               MUSE_CAMERA_API_ATTR_GET_CONTRAST,
+               MUSE_CAMERA_GET_INT_CONTRAST,
+               level);
+}
 
-       if (!pc || !pc->cb_info || !level) {
-               CAM_LOG_ERROR("NULL pointer %p %p", pc, level);
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
 
-       CAM_LOG_INFO("Enter");
+int camera_attr_get_contrast_range(camera_h camera, int *min, int *max)
+{
+       return _camera_attr_get_range(camera,
+               MUSE_CAMERA_API_ATTR_GET_CONTRAST_RANGE,
+               MUSE_CAMERA_GET_INT_PAIR_CONTRAST_RANGE,
+               min, max);
+}
 
-       _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
 
-       if (ret == CAMERA_ERROR_NONE)
-               *level = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_CONTRAST];
+int camera_attr_get_hue(camera_h camera, int *level)
+{
+       return _camera_attr_get_level(camera,
+               MUSE_CAMERA_API_ATTR_GET_HUE,
+               MUSE_CAMERA_GET_INT_HUE,
+               level);
+}
 
-       CAM_LOG_INFO("ret : 0x%x", ret);
 
-       return ret;
+int camera_attr_get_hue_range(camera_h camera, int *min, int *max)
+{
+       return _camera_attr_get_range(camera,
+               MUSE_CAMERA_API_ATTR_GET_HUE_RANGE,
+               MUSE_CAMERA_GET_INT_PAIR_HUE_RANGE,
+               min, max);
 }
 
 
-int camera_attr_get_contrast_range(camera_h camera, int *min, int *max)
+int camera_attr_get_saturation(camera_h camera, int *level)
 {
-       int ret = CAMERA_ERROR_NONE;
-       camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_CONTRAST_RANGE;
+       return _camera_attr_get_level(camera,
+               MUSE_CAMERA_API_ATTR_GET_SATURATION,
+               MUSE_CAMERA_GET_INT_SATURATION,
+               level);
+}
 
-       if (!pc || !pc->cb_info || !min || !max) {
-               CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
 
-       CAM_LOG_INFO("Enter");
+int camera_attr_get_saturation_range(camera_h camera, int *min, int *max)
+{
+       return _camera_attr_get_range(camera,
+               MUSE_CAMERA_API_ATTR_GET_SATURATION_RANGE,
+               MUSE_CAMERA_GET_INT_PAIR_SATURATION_RANGE,
+               min, max);
+}
 
-       _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
 
-       if (ret == CAMERA_ERROR_NONE) {
-               *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_CONTRAST_RANGE][0];
-               *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_CONTRAST_RANGE][1];
-               CAM_LOG_INFO("min %d, max %d", *min, *max);
-       }
+int camera_attr_get_sharpness(camera_h camera, int *level)
+{
+       return _camera_attr_get_level(camera,
+               MUSE_CAMERA_API_ATTR_GET_SHARPNESS,
+               MUSE_CAMERA_GET_INT_SHARPNESS,
+               level);
+}
 
-       CAM_LOG_INFO("ret : 0x%x", ret);
 
-       return ret;
+int camera_attr_get_sharpness_range(camera_h camera, int *min, int *max)
+{
+       return _camera_attr_get_range(camera,
+               MUSE_CAMERA_API_ATTR_GET_SHARPNESS_RANGE,
+               MUSE_CAMERA_GET_INT_PAIR_SHARPNESS_RANGE,
+               min, max);
 }
 
 
-int camera_attr_get_hue(camera_h camera, int *level)
+int camera_attr_get_whitebalance(camera_h camera, camera_attr_whitebalance_e *wb)
 {
        int ret = CAMERA_ERROR_NONE;
        camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_HUE;
+       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_WHITEBALANCE;
 
-       if (!pc || !pc->cb_info || !level) {
-               CAM_LOG_ERROR("NULL pointer %p %p", pc, level);
+       if (!pc || !pc->cb_info || !wb) {
+               CAM_LOG_ERROR("NULL pointer %p %p", pc, wb);
                return CAMERA_ERROR_INVALID_PARAMETER;
        }
 
@@ -5390,7 +5245,7 @@ int camera_attr_get_hue(camera_h camera, int *level)
        _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
 
        if (ret == CAMERA_ERROR_NONE)
-               *level = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_HUE];
+               *wb = (camera_attr_whitebalance_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_WHITE_BALANCE];
 
        CAM_LOG_INFO("ret : 0x%x", ret);
 
@@ -5398,14 +5253,14 @@ int camera_attr_get_hue(camera_h camera, int *level)
 }
 
 
-int camera_attr_get_hue_range(camera_h camera, int *min, int *max)
+int camera_attr_get_whitebalance_temperature(camera_h camera, int *temperature)
 {
        int ret = CAMERA_ERROR_NONE;
        camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_HUE_RANGE;
+       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_WHITEBALANCE_TEMPERATURE;
 
-       if (!pc || !pc->cb_info || !min || !max) {
-               CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
+       if (!pc || !pc->cb_info || !temperature) {
+               CAM_LOG_ERROR("NULL pointer %p %p", pc, temperature);
                return CAMERA_ERROR_INVALID_PARAMETER;
        }
 
@@ -5413,11 +5268,8 @@ int camera_attr_get_hue_range(camera_h camera, int *min, int *max)
 
        _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
 
-       if (ret == CAMERA_ERROR_NONE) {
-               *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_HUE_RANGE][0];
-               *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_HUE_RANGE][1];
-               CAM_LOG_INFO("min %d, max %d", *min, *max);
-       }
+       if (ret == CAMERA_ERROR_NONE)
+               *temperature = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_WHITE_BALANCE_TEMPERATURE];
 
        CAM_LOG_INFO("ret : 0x%x", ret);
 
@@ -5425,14 +5277,23 @@ int camera_attr_get_hue_range(camera_h camera, int *min, int *max)
 }
 
 
-int camera_attr_get_whitebalance(camera_h camera, camera_attr_whitebalance_e *wb)
+int camera_attr_get_whitebalance_temperature_range(camera_h camera, int *min, int *max)
+{
+       return _camera_attr_get_range(camera,
+               MUSE_CAMERA_API_ATTR_GET_WHITEBALANCE_TEMPERATURE_RANGE,
+               MUSE_CAMERA_GET_INT_PAIR_WHITE_BALANCE_TEMPERATURE_RANGE,
+               min, max);
+}
+
+
+int camera_attr_get_whitebalance_temperature_step(camera_h camera, int *step)
 {
        int ret = CAMERA_ERROR_NONE;
        camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_WHITEBALANCE;
+       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_WHITEBALANCE_TEMPERATURE_STEP;
 
-       if (!pc || !pc->cb_info || !wb) {
-               CAM_LOG_ERROR("NULL pointer %p %p", pc, wb);
+       if (!pc || !pc->cb_info || !step) {
+               CAM_LOG_ERROR("NULL pointer %p %p", pc, step);
                return CAMERA_ERROR_INVALID_PARAMETER;
        }
 
@@ -5441,7 +5302,7 @@ int camera_attr_get_whitebalance(camera_h camera, camera_attr_whitebalance_e *wb
        _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
 
        if (ret == CAMERA_ERROR_NONE)
-               *wb = (camera_attr_whitebalance_e)pc->cb_info->get_int[MUSE_CAMERA_GET_INT_WHITE_BALANCE];
+               *step = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_WHITE_BALANCE_TEMPERATURE_STEP];
 
        CAM_LOG_INFO("ret : 0x%x", ret);
 
@@ -5945,10 +5806,7 @@ int camera_attr_set_stream_rotation(camera_h camera, camera_rotation_e rotation)
        camera_msg_param param;
        int set_rotation = (int)rotation;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -5994,10 +5852,7 @@ int camera_attr_set_stream_flip(camera_h camera, camera_flip_e flip)
        camera_msg_param param;
        int set_flip = (int)flip;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -6036,26 +5891,7 @@ int camera_attr_get_stream_flip(camera_h camera, camera_flip_e *flip)
 
 int camera_attr_set_hdr_mode(camera_h camera, camera_attr_hdr_mode_e mode)
 {
-       int ret = CAMERA_ERROR_NONE;
-       camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_HDR_MODE;
-       camera_msg_param param;
-       int set_mode = (int)mode;
-
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
-
-       CAM_LOG_INFO("Enter");
-
-       CAMERA_MSG_PARAM_SET(param, INT, set_mode);
-
-       _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
-
-       CAM_LOG_INFO("ret : 0x%x", ret);
-
-       return ret;
+       return __set_mode(camera, MUSE_CAMERA_API_ATTR_SET_HDR_MODE, (int)mode);
 }
 
 
@@ -6085,27 +5921,7 @@ int camera_attr_get_hdr_mode(camera_h camera, camera_attr_hdr_mode_e *mode)
 
 bool camera_attr_is_supported_hdr_capture(camera_h camera)
 {
-       int ret = CAMERA_ERROR_NONE;
-       camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_SUPPORTED_HDR_CAPTURE;
-
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
-
-       CAM_LOG_INFO("Enter");
-
-       _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
-
-       if (ret < 0) {
-               CAM_LOG_ERROR("error is occurred 0x%x", ret);
-               ret = false;
-       }
-
-       CAM_LOG_INFO("ret : %d", ret);
-
-       return (bool)ret;
+       return __is_supported(camera, MUSE_CAMERA_API_ATTR_IS_SUPPORTED_HDR_CAPTURE);
 }
 
 
@@ -6115,10 +5931,7 @@ int camera_attr_set_hdr_capture_progress_cb(camera_h camera, camera_attr_hdr_pro
        camera_cli_s *pc = (camera_cli_s *)camera;
        muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_HDR_CAPTURE_PROGRESS_CB;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -6155,10 +5968,7 @@ int camera_attr_unset_hdr_capture_progress_cb(camera_h camera)
        camera_cli_s *pc = (camera_cli_s *)camera;
        muse_camera_api_e api = MUSE_CAMERA_API_ATTR_UNSET_HDR_CAPTURE_PROGRESS_CB;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -6181,26 +5991,7 @@ int camera_attr_unset_hdr_capture_progress_cb(camera_h camera)
 
 int camera_attr_enable_anti_shake(camera_h camera, bool enable)
 {
-       int ret = CAMERA_ERROR_NONE;
-       camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_ENABLE_ANTI_SHAKE;
-       camera_msg_param param;
-       int set_enable = (int)enable;
-
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
-
-       CAM_LOG_INFO("Enter");
-
-       CAMERA_MSG_PARAM_SET(param, INT, set_enable);
-
-       _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
-
-       CAM_LOG_INFO("ret : 0x%x", ret);
-
-       return ret;
+       return __set_enable(camera, MUSE_CAMERA_API_ATTR_ENABLE_ANTI_SHAKE, (int)enable);
 }
 
 
@@ -6230,52 +6021,13 @@ int camera_attr_is_enabled_anti_shake(camera_h camera, bool *enabled)
 
 bool camera_attr_is_supported_anti_shake(camera_h camera)
 {
-       int ret = CAMERA_ERROR_NONE;
-       camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_SUPPORTED_ANTI_SHAKE;
-
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
-
-       CAM_LOG_INFO("Enter");
-
-       _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
-
-       if (ret < 0) {
-               CAM_LOG_ERROR("error is occurred 0x%x", ret);
-               ret = false;
-       }
-
-       CAM_LOG_INFO("ret : %d", ret);
-
-       return (bool)ret;
+       return __is_supported(camera, MUSE_CAMERA_API_ATTR_IS_SUPPORTED_ANTI_SHAKE);
 }
 
 
 int camera_attr_enable_video_stabilization(camera_h camera, bool enable)
 {
-       int ret = CAMERA_ERROR_NONE;
-       camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_ENABLE_VIDEO_STABILIZATION;
-       camera_msg_param param;
-       int set_enable = (int)enable;
-
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
-
-       CAM_LOG_INFO("Enter");
-
-       CAMERA_MSG_PARAM_SET(param, INT, set_enable);
-
-       _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
-
-       CAM_LOG_INFO("ret : 0x%x", ret);
-
-       return ret;
+       return __set_enable(camera, MUSE_CAMERA_API_ATTR_ENABLE_VIDEO_STABILIZATION, (int)enable);
 }
 
 
@@ -6305,52 +6057,13 @@ int camera_attr_is_enabled_video_stabilization(camera_h camera, bool *enabled)
 
 bool camera_attr_is_supported_video_stabilization(camera_h camera)
 {
-       int ret = CAMERA_ERROR_NONE;
-       camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_SUPPORTED_VIDEO_STABILIZATION;
-
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
-
-       CAM_LOG_INFO("Enter");
-
-       _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
-
-       if (ret < 0) {
-               CAM_LOG_ERROR("error is occurred 0x%x", ret);
-               ret = false;
-       }
-
-       CAM_LOG_INFO("ret : %d", ret);
-
-       return (bool)ret;
+       return __is_supported(camera, MUSE_CAMERA_API_ATTR_IS_SUPPORTED_VIDEO_STABILIZATION);
 }
 
 
 int camera_attr_enable_auto_contrast(camera_h camera, bool enable)
 {
-       int ret = CAMERA_ERROR_NONE;
-       camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_ENABLE_AUTO_CONTRAST;
-       camera_msg_param param;
-       int set_enable = (int)enable;
-
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
-
-       CAM_LOG_INFO("Enter");
-
-       CAMERA_MSG_PARAM_SET(param, INT, set_enable);
-
-       _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
-
-       CAM_LOG_INFO("ret : 0x%x", ret);
-
-       return ret;
+       return __set_enable(camera, MUSE_CAMERA_API_ATTR_ENABLE_AUTO_CONTRAST, (int)enable);
 }
 
 
@@ -6380,27 +6093,7 @@ int camera_attr_is_enabled_auto_contrast(camera_h camera, bool *enabled)
 
 bool camera_attr_is_supported_auto_contrast(camera_h camera)
 {
-       int ret = CAMERA_ERROR_NONE;
-       camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_IS_SUPPORTED_AUTO_CONTRAST;
-
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
-
-       CAM_LOG_INFO("Enter");
-
-       _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
-
-       if (ret < 0) {
-               CAM_LOG_ERROR("error is occurred 0x%x", ret);
-               ret = false;
-       }
-
-       CAM_LOG_INFO("ret : %d", ret);
-
-       return (bool)ret;
+       return __is_supported(camera, MUSE_CAMERA_API_ATTR_IS_SUPPORTED_AUTO_CONTRAST);
 }
 
 
@@ -6412,10 +6105,7 @@ int camera_attr_disable_shutter_sound(camera_h camera, bool disable)
        camera_msg_param param;
        int set_disable = (int)disable;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -6437,10 +6127,7 @@ int camera_attr_set_pan(camera_h camera, camera_attr_ptz_move_type_e move_type,
        camera_msg_param param0;
        camera_msg_param param1;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -6482,27 +6169,10 @@ int camera_attr_get_pan(camera_h camera, int *pan_step)
 
 int camera_attr_get_pan_range(camera_h camera, int *min, int *max)
 {
-       int ret = CAMERA_ERROR_NONE;
-       camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_PAN_RANGE;
-
-       if (!pc || !pc->cb_info || !min || !max) {
-               CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
-
-       CAM_LOG_INFO("Enter");
-
-       _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
-
-       if (ret == CAMERA_ERROR_NONE) {
-               *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_PAN_RANGE][0];
-               *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_PAN_RANGE][1];
-       }
-
-       CAM_LOG_INFO("ret : 0x%x", ret);
-
-       return ret;
+       return _camera_attr_get_range(camera,
+               MUSE_CAMERA_API_ATTR_GET_PAN_RANGE,
+               MUSE_CAMERA_GET_INT_PAIR_PAN_RANGE,
+               min, max);
 }
 
 
@@ -6514,10 +6184,7 @@ int camera_attr_set_tilt(camera_h camera, camera_attr_ptz_move_type_e move_type,
        camera_msg_param param0;
        camera_msg_param param1;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -6559,27 +6226,10 @@ int camera_attr_get_tilt(camera_h camera, int *tilt_step)
 
 int camera_attr_get_tilt_range(camera_h camera, int *min, int *max)
 {
-       int ret = CAMERA_ERROR_NONE;
-       camera_cli_s *pc = (camera_cli_s *)camera;
-       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_TILT_RANGE;
-
-       if (!pc || !pc->cb_info || !min || !max) {
-               CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
-
-       CAM_LOG_INFO("Enter");
-
-       _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
-
-       if (ret == CAMERA_ERROR_NONE) {
-               *min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_TILT_RANGE][0];
-               *max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_TILT_RANGE][1];
-       }
-
-       CAM_LOG_INFO("ret : 0x%x", ret);
-
-       return ret;
+       return _camera_attr_get_range(camera,
+               MUSE_CAMERA_API_ATTR_GET_TILT_RANGE,
+               MUSE_CAMERA_GET_INT_PAIR_TILT_RANGE,
+               min, max);
 }
 
 
@@ -6591,10 +6241,7 @@ int camera_attr_set_ptz_type(camera_h camera, camera_attr_ptz_type_e ptz_type)
        camera_msg_param param;
        int set_ptz_type = (int)ptz_type;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
@@ -6640,16 +6287,12 @@ int camera_attr_set_display_roi_area(camera_h camera, int x, int y, int width, i
        int set_display_roi_area[4] = {x, y, width, height};
        char *msg = NULL;
        int length = 0;
-       int send_ret = 0;
 
-       if (!pc || !pc->cb_info) {
-               CAM_LOG_ERROR("NULL handle");
-               return CAMERA_ERROR_INVALID_PARAMETER;
-       }
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
 
        CAM_LOG_INFO("Enter");
 
-       if (CHECK_PREVIEW_CB(pc->cb_info, PREVIEW_CB_TYPE_EVAS)) {
+       if (pc->cb_info->is_evas_render) {
                ret = mm_display_interface_evas_set_roi_area(pc->cb_info->dp_interface, x, y, width, height);
                if (ret != MM_ERROR_NONE) {
                        CAM_LOG_ERROR("mm_evas_renderer_set_roi_area error 0x%x", ret);
@@ -6663,31 +6306,8 @@ int camera_attr_set_display_roi_area(camera_h camera, int x, int y, int width, i
        msg = muse_core_msg_new(api,
                MUSE_TYPE_ARRAY, "set_display_roi_area", length, (int *)set_display_roi_area,
                NULL);
-       if (!msg) {
-               CAM_LOG_ERROR("msg creation failed: api %d", api);
-               return CAMERA_ERROR_OUT_OF_MEMORY;
-       }
-
-       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_msg_send(pc->cb_info->fd, msg);
-               g_mutex_unlock(&pc->cb_info->fd_lock);
-       }
-
-       if (send_ret < 0) {
-               CAM_LOG_ERROR("message send failed");
-               ret = CAMERA_ERROR_INVALID_OPERATION;
-       } else {
-               ret = _camera_client_wait_for_cb_return(api, pc->cb_info, CAMERA_CB_TIMEOUT);
-       }
-
-       __camera_update_api_waiting(pc->cb_info, api, -1);
-
-       muse_core_msg_free(msg);
-
-       CAM_LOG_INFO("ret : 0x%x", ret);
+       _camera_send_message_get_return(pc->cb_info, api, msg, CAMERA_CB_TIMEOUT, &ret);
 
        return ret;
 }
@@ -6894,3 +6514,419 @@ _DONE:
 
        return ret;
 }
+
+
+//LCOV_EXCL_START
+int camera_media_bridge_set_bridge(camera_h camera, media_bridge_h bridge)
+{
+       int ret = CAMERA_ERROR_NONE;
+       camera_cli_s *pc = (camera_cli_s *)camera;
+       muse_camera_api_e api = MUSE_CAMERA_API_SET_MEDIA_BRIDGE;
+
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
+
+       g_mutex_lock(&pc->cb_info->bridge_lock);
+
+       if (pc->cb_info->bridge) {
+               CAM_LOG_ERROR("media bridge[%p] is already set", pc->cb_info->bridge);
+               ret = CAMERA_ERROR_INVALID_OPERATION;
+               goto _SET_MEDIA_BRIDGE_DONE;
+       }
+
+       _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
+       if (ret != CAMERA_ERROR_NONE) {
+               CAM_LOG_ERROR("set media bridge failed[0x%x]", ret);
+               goto _SET_MEDIA_BRIDGE_DONE;
+       }
+
+       pc->cb_info->bridge = bridge;
+
+       CAM_LOG_INFO("[%p] set media bridge[%p]", camera, bridge);
+
+_SET_MEDIA_BRIDGE_DONE:
+       g_mutex_unlock(&pc->cb_info->bridge_lock);
+
+       return ret;
+}
+
+
+int camera_media_bridge_unset_bridge(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_MEDIA_BRIDGE;
+
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
+
+       g_mutex_lock(&pc->cb_info->bridge_lock);
+
+       if (!pc->cb_info->bridge) {
+               CAM_LOG_ERROR("no media bridge");
+               ret = CAMERA_ERROR_INVALID_OPERATION;
+               goto _UNSET_MEDIA_BRIDGE_DONE;
+       }
+
+       _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
+       if (ret != CAMERA_ERROR_NONE) {
+               CAM_LOG_ERROR("unset media bridge failed[0x%x]", ret);
+               goto _UNSET_MEDIA_BRIDGE_DONE;
+       }
+
+       CAM_LOG_INFO("[%p] unset media bridge[%p]", camera, pc->cb_info->bridge);
+
+       pc->cb_info->bridge = NULL;
+
+_UNSET_MEDIA_BRIDGE_DONE:
+       g_mutex_unlock(&pc->cb_info->bridge_lock);
+
+       return ret;
+}
+//LCOV_EXCL_STOP
+
+
+int camera_create_network(camera_device_e device, camera_h *camera)
+{
+       return _camera_create_private(device, true, camera);
+}
+
+
+int camera_set_extra_preview_cb(camera_h camera, camera_extra_preview_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_EXTRA_PREVIEW_CB;
+
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
+
+       if (!camera_is_supported_extra_preview(camera)) {
+               CAM_LOG_ERROR("extra preview is not supported");
+               return CAMERA_ERROR_NOT_SUPPORTED;
+       }
+
+       if (!callback) {
+               CAM_LOG_ERROR("NULL callback");
+               return CAMERA_ERROR_INVALID_PARAMETER;
+       }
+
+       CAM_LOG_INFO("Enter");
+
+       _camera_msg_send(api, NULL, 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_EXTRA_PREVIEW]);
+
+               pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW] = callback;
+               pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW] = user_data;
+
+               g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW]);
+       }
+
+       CAM_LOG_INFO("ret : 0x%x", ret);
+
+       return ret;
+}
+
+
+int camera_unset_extra_preview_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_EXTRA_PREVIEW_CB;
+
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
+
+       if (!camera_is_supported_extra_preview(camera)) {
+               CAM_LOG_ERROR("extra preview is not supported");
+               return CAMERA_ERROR_NOT_SUPPORTED;
+       }
+
+       CAM_LOG_INFO("Enter");
+
+       _camera_msg_send(api, NULL, 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_EXTRA_PREVIEW]);
+
+               pc->cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW] = NULL;
+               pc->cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW] = NULL;
+
+               g_mutex_unlock(&pc->cb_info->user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW]);
+       }
+
+       CAM_LOG_INFO("ret : 0x%x", ret);
+
+       return ret;
+}
+
+
+int camera_set_extra_preview_stream_format(camera_h camera, int stream_id, camera_pixel_format_e pixel_format, int width, int height, int fps)
+{
+       int ret = CAMERA_ERROR_NONE;
+       int stream_format[4] = {pixel_format, width, height, fps};
+       char *msg = NULL;
+       camera_cli_s *pc = (camera_cli_s *)camera;
+       muse_camera_api_e api = MUSE_CAMERA_API_SET_EXTRA_PREVIEW_STREAM_FORMAT;
+
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
+
+       CAM_LOG_INFO("Enter - stream[%d],[%d,%dx%d,%d]",
+               stream_id, pixel_format, width, height, fps);
+
+       msg = muse_core_msg_new(api,
+               MUSE_TYPE_INT, "stream_id", stream_id,
+               MUSE_TYPE_ARRAY, "stream_format", 4, stream_format,
+               NULL);
+
+       _camera_send_message_get_return(pc->cb_info, api, msg, CAMERA_CB_TIMEOUT, &ret);
+
+       return ret;
+}
+
+
+int camera_get_extra_preview_stream_format(camera_h camera, int stream_id, camera_pixel_format_e *pixel_format, int *width, int *height, int *fps)
+{
+       int ret = CAMERA_ERROR_NONE;
+       camera_cli_s *pc = (camera_cli_s *)camera;
+       camera_msg_param param;
+       muse_camera_api_e api = MUSE_CAMERA_API_GET_EXTRA_PREVIEW_STREAM_FORMAT;
+
+       if (!pc || !pc->cb_info || !pixel_format || !width || !height || !fps) {
+               CAM_LOG_ERROR("NULL pointer %p %p %p %p %p", pc, pixel_format, width, height, fps);
+               return CAMERA_ERROR_INVALID_PARAMETER;
+       }
+
+       CAM_LOG_INFO("Enter - stream[%d]", stream_id);
+
+       CAMERA_MSG_PARAM_SET(param, INT, stream_id);
+
+       _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
+
+       if (ret == CAMERA_ERROR_NONE) {
+               *pixel_format = (camera_pixel_format_e)pc->cb_info->get_extra_preview_stream_format[0];
+               *width = pc->cb_info->get_extra_preview_stream_format[1];
+               *height = pc->cb_info->get_extra_preview_stream_format[2];
+               *fps = pc->cb_info->get_extra_preview_stream_format[3];
+       }
+
+       CAM_LOG_INFO("ret : 0x%x", ret);
+
+       return ret;
+}
+
+
+int camera_attr_set_extra_preview_bitrate(camera_h camera, int stream_id, int bitrate)
+{
+       int ret = CAMERA_ERROR_NONE;
+       camera_cli_s *pc = (camera_cli_s *)camera;
+       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_EXTRA_PREVIEW_BITRATE;
+       camera_msg_param param0;
+       camera_msg_param param1;
+
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
+
+       CAM_LOG_INFO("Enter - stream[%d], bitrate[%d]", stream_id, bitrate);
+
+       CAMERA_MSG_PARAM_SET(param0, INT, stream_id);
+       CAMERA_MSG_PARAM_SET(param1, INT, bitrate);
+
+       _camera_msg_send_param2_int(api, pc->cb_info, &ret,
+               &param0, &param1, CAMERA_CB_TIMEOUT);
+
+       CAM_LOG_INFO("ret : 0x%x", ret);
+
+       return ret;
+}
+
+
+int camera_attr_get_extra_preview_bitrate(camera_h camera, int stream_id, int *bitrate)
+{
+       int ret = CAMERA_ERROR_NONE;
+       camera_cli_s *pc = (camera_cli_s *)camera;
+       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EXTRA_PREVIEW_BITRATE;
+       camera_msg_param param;
+
+       if (!pc || !pc->cb_info || !bitrate) {
+               CAM_LOG_ERROR("NULL pointer %p %p", pc, bitrate);
+               return CAMERA_ERROR_INVALID_PARAMETER;
+       }
+
+       CAM_LOG_INFO("Enter - stream[%d]", stream_id);
+
+       CAMERA_MSG_PARAM_SET(param, INT, stream_id);
+
+       _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
+
+       if (ret == CAMERA_ERROR_NONE) {
+               *bitrate = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_EXTRA_PREVIEW_BITRATE];
+               CAM_LOG_INFO("get bitrate[%d] for stream[%d]", *bitrate, stream_id);
+       } else {
+               CAM_LOG_ERROR("get bitrate failed for stream[%d] : 0x%x", stream_id, ret);
+       }
+
+       return ret;
+}
+
+
+int camera_attr_set_extra_preview_gop_interval(camera_h camera, int stream_id, int interval)
+{
+       int ret = CAMERA_ERROR_NONE;
+       camera_cli_s *pc = (camera_cli_s *)camera;
+       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_SET_EXTRA_PREVIEW_GOP_INTERVAL;
+       camera_msg_param param0;
+       camera_msg_param param1;
+
+       CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);
+
+       CAM_LOG_INFO("Enter - stream[%d], GOP interval[%d]", stream_id, interval);
+
+       CAMERA_MSG_PARAM_SET(param0, INT, stream_id);
+       CAMERA_MSG_PARAM_SET(param1, INT, interval);
+
+       _camera_msg_send_param2_int(api, pc->cb_info, &ret,
+               &param0, &param1, CAMERA_CB_TIMEOUT);
+
+       CAM_LOG_INFO("ret : 0x%x", ret);
+
+       return ret;
+}
+
+
+int camera_attr_get_extra_preview_gop_interval(camera_h camera, int stream_id, int *interval)
+{
+       int ret = CAMERA_ERROR_NONE;
+       camera_cli_s *pc = (camera_cli_s *)camera;
+       muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_EXTRA_PREVIEW_GOP_INTERVAL;
+       camera_msg_param param;
+
+       if (!pc || !pc->cb_info || !interval) {
+               CAM_LOG_ERROR("NULL pointer %p %p", pc, interval);
+               return CAMERA_ERROR_INVALID_PARAMETER;
+       }
+
+       CAM_LOG_INFO("Enter - stream[%d]", stream_id);
+
+       CAMERA_MSG_PARAM_SET(param, INT, stream_id);
+
+       _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
+
+       if (ret == CAMERA_ERROR_NONE) {
+               *interval = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_EXTRA_PREVIEW_GOP_INTERVAL];
+               CAM_LOG_INFO("get GOP interval[%d] for stream[%d]", *interval, stream_id);
+       } else {
+               CAM_LOG_ERROR("get GOP interval failed for stream[%d] : 0x%x", stream_id, ret);
+       }
+
+       return ret;
+}
+
+
+int camera_attr_get_preview_frame_rotation(camera_h camera, camera_rotation_e *rotation)
+{
+       camera_cli_s *pc = (camera_cli_s *)camera;
+
+       if (!pc || !pc->cb_info || !rotation) {
+               CAM_LOG_ERROR("NULL pointer %p %p", pc, rotation);
+               return CAMERA_ERROR_INVALID_PARAMETER;
+       }
+
+       if (!pc->cb_info->stream_data) {
+               CAM_LOG_ERROR("no stream data, maybe it's not in preview callback");
+               return CAMERA_ERROR_INVALID_OPERATION;
+       }
+
+       *rotation = pc->cb_info->stream_data->rotation;
+
+       CAM_LOG_DEBUG("frame rotation[%d]", *rotation);
+
+       return CAMERA_ERROR_NONE;
+}
+
+
+int _camera_get_log_level(void)
+{
+       return g_camera_log_level;
+}
+
+
+int _camera_attr_set_level(camera_h camera, muse_camera_api_e api, int level)
+{
+       int ret = CAMERA_ERROR_NONE;
+       camera_cli_s *pc = (camera_cli_s *)camera;
+       camera_msg_param param;
+
+       if (!pc || !pc->cb_info) {
+               CAM_LOG_ERROR("api[%d] NULL handle", api);
+               return CAMERA_ERROR_INVALID_PARAMETER;
+       }
+
+       CAM_LOG_INFO("api[%d] Enter - level[%d]", api, level);
+
+       CAMERA_MSG_PARAM_SET(param, INT, level);
+
+       _camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);
+
+       CAM_LOG_INFO("api[%d] ret[0x%x]", api, ret);
+
+       return ret;
+}
+
+
+int _camera_attr_get_level(camera_h camera, muse_camera_api_e api, muse_camera_get_int_e get_index, int *level)
+{
+       int ret = CAMERA_ERROR_NONE;
+       camera_cli_s *pc = (camera_cli_s *)camera;
+
+       if (!pc || !pc->cb_info || !level) {
+               CAM_LOG_ERROR("api[%d] NULL param[%p,%p]", api, pc, level);
+               return CAMERA_ERROR_INVALID_PARAMETER;
+       }
+
+       if (get_index >= MUSE_CAMERA_GET_INT_NUM) {
+               CAM_LOG_ERROR("api[%d] INVALID index[%d]", api, get_index);
+               return CAMERA_ERROR_INVALID_OPERATION;
+       }
+
+       CAM_LOG_INFO("api[%d] Enter", api);
+
+       _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
+
+       if (ret == CAMERA_ERROR_NONE) {
+               *level = pc->cb_info->get_int[get_index];
+               CAM_LOG_INFO("api[%d] level[%d]", api, *level);
+       }
+
+       CAM_LOG_INFO("api[%d] ret[0x%x]", api, ret);
+
+       return ret;
+}
+
+
+int _camera_attr_get_range(camera_h camera, muse_camera_api_e api, muse_camera_get_int_pair_e get_index, int *min, int *max)
+{
+       int ret = CAMERA_ERROR_NONE;
+       camera_cli_s *pc = (camera_cli_s *)camera;
+
+       if (!pc || !pc->cb_info || !min || !max) {
+               CAM_LOG_ERROR("api[%d] NULL param[%p,%p,%p]", api, pc, min, max);
+               return CAMERA_ERROR_INVALID_PARAMETER;
+       }
+
+       if (get_index >= MUSE_CAMERA_GET_INT_PAIR_NUM) {
+               CAM_LOG_ERROR("api[%d] INVALID index[%d]", api, get_index);
+               return CAMERA_ERROR_INVALID_OPERATION;
+       }
+
+       CAM_LOG_INFO("api[%d] Enter", api);
+
+       _camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);
+
+       if (ret == CAMERA_ERROR_NONE) {
+               *min = pc->cb_info->get_int_pair[get_index][0];
+               *max = pc->cb_info->get_int_pair[get_index][1];
+               CAM_LOG_INFO("api[%d] min[%d], max[%d]", api, *min, *max);
+       }
+
+       CAM_LOG_INFO("api[%d] ret[0x%x]", api, ret);
+
+       return ret;
+}