Support zero-copy with encoded format
[platform/core/multimedia/libmm-camcorder.git] / src / mm_camcorder_internal.c
index 24f4eb4..27a683d 100644 (file)
@@ -36,7 +36,6 @@
 #include <mm_types.h>
 
 #include <gst/video/colorbalance.h>
-#include <gst/video/cameracontrol.h>
 #include <asm/types.h>
 
 #include <system_info.h>
 #include "mm_camcorder_rm.h"
 #endif /* _MMCAMCORDER_RM_SUPPORT */
 
-/* log level */
-int mmcam_log_level = MM_CAMCORDER_LOG_LEVEL_INFO;
-
 /*---------------------------------------------------------------------------------------
 |    LOCAL VARIABLE DEFINITIONS for internal                                           |
 ---------------------------------------------------------------------------------------*/
 #define __MMCAMCORDER_CMD_ITERATE_MAX           3
-#define __MMCAMCORDER_SET_GST_STATE_TIMEOUT     5
+#define __MMCAMCORDER_SET_GST_STATE_TIMEOUT     10
 #define __MMCAMCORDER_FORCE_STOP_TRY_COUNT      30
 #define __MMCAMCORDER_FORCE_STOP_WAIT_TIME      100000  /* us */
 #define __MMCAMCORDER_SOUND_WAIT_TIMEOUT        3
@@ -75,13 +71,14 @@ static gint     __mmcamcorder_init_handle(mmf_camcorder_t **hcamcorder, int devi
 static void     __mmcamcorder_deinit_handle(mmf_camcorder_t *hcamcorder);
 static gint     __mmcamcorder_init_configure_video_capture(mmf_camcorder_t *hcamcorder);
 static gint     __mmcamcorder_init_configure_audio(mmf_camcorder_t *hcamcorder);
+static gint     __mmcamcorder_init_configure_common(mmf_camcorder_t *hcamcorder);
 static void     __mmcamcorder_deinit_configure(mmf_camcorder_t *hcamcorder);
 static gboolean __mmcamcorder_init_gstreamer(camera_conf *conf);
 static void     __mmcamcorder_get_system_info(mmf_camcorder_t *hcamcorder);
 
-static GstBusSyncReply __mmcamcorder_handle_gst_sync_error(mmf_camcorder_t *hcamcorder, GstMessage *message);
-static GstBusSyncReply __mmcamcorder_gst_handle_sync_audio_error(mmf_camcorder_t *hcamcorder, gint err_code);
-static GstBusSyncReply __mmcamcorder_gst_handle_sync_others_error(mmf_camcorder_t *hcamcorder, gint err_code);
+static void     __mmcamcorder_handle_gst_sync_error(mmf_camcorder_t *hcamcorder, GstMessage *message);
+static void     __mmcamcorder_gst_handle_sync_audio_error(mmf_camcorder_t *hcamcorder, gint err_code);
+static void     __mmcamcorder_gst_handle_sync_others_error(mmf_camcorder_t *hcamcorder, gint err_code);
 static gboolean __mmcamcorder_handle_gst_error(MMHandleType handle, GstMessage *message, GError *error);
 static gint     __mmcamcorder_gst_handle_stream_error(MMHandleType handle, int code, GstMessage *message);
 static gint     __mmcamcorder_gst_handle_resource_error(MMHandleType handle, int code, GstMessage *message);
@@ -93,9 +90,6 @@ static gboolean __mmcamcorder_handle_gst_warning(MMHandleType handle, GstMessage
 static int      __mmcamcorder_resource_release_cb(mm_resource_manager_h rm,
        mm_resource_manager_res_h res, void *user_data);
 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
-#ifdef _MMCAMCORDER_USE_SET_ATTR_CB
-static gboolean __mmcamcorder_set_attr_to_camsensor_cb(gpointer data);
-#endif /* _MMCAMCORDER_USE_SET_ATTR_CB */
 
 /*=======================================================================================
 |  FUNCTION DEFINITIONS                                                                        |
@@ -103,6 +97,7 @@ static gboolean __mmcamcorder_set_attr_to_camsensor_cb(gpointer data);
 static gint __mmcamcorder_init_handle(mmf_camcorder_t **hcamcorder, int device_type)
 {
        int ret = MM_ERROR_NONE;
+       int log_level = MM_CAMCORDER_LOG_LEVEL_INFO;
        mmf_camcorder_t *new_handle = NULL;
 
        if (!hcamcorder) {
@@ -189,7 +184,9 @@ static gint __mmcamcorder_init_handle(mmf_camcorder_t **hcamcorder, int device_t
        _mmcamcorder_conf_get_value_int((MMHandleType)new_handle, new_handle->conf_main,
                CONFIGURE_CATEGORY_MAIN_GENERAL,
                "LogLevel",
-               &mmcam_log_level);
+               &log_level);
+
+       _mmcamcorder_set_log_level(log_level);
 
        /* allocate attribute */
        new_handle->attributes = _mmcamcorder_alloc_attribute((MMHandleType)new_handle);
@@ -198,13 +195,6 @@ static gint __mmcamcorder_init_handle(mmf_camcorder_t **hcamcorder, int device_t
                goto _INIT_HANDLE_FAILED;
        }
 
-       /* Set log level to attribute */
-       ret = mm_camcorder_set_attributes((MMHandleType)new_handle, NULL,
-               MMCAM_LOG_LEVEL, mmcam_log_level,
-               NULL);
-
-       MMCAM_LOG_INFO("set log level[%d], ret[0x%x]", mmcam_log_level, ret);
-
        *hcamcorder = new_handle;
 
        MMCAM_LOG_INFO("new handle %p", new_handle);
@@ -336,7 +326,6 @@ static gint __mmcamcorder_init_configure_video_capture(mmf_camcorder_t *hcamcord
        int rcmd_fmt_recording = MM_PIXEL_FORMAT_NV12;
        int rcmd_dpy_rotation = MM_DISPLAY_ROTATION_270;
        int play_capture_sound = TRUE;
-       int camera_device_count = MM_VIDEO_DEVICE_NUM;
        int camera_default_flip = MM_FLIP_NONE;
        int camera_facing_direction = MM_CAMCORDER_CAMERA_FACING_DIRECTION_REAR;
        char *err_attr_name = NULL;
@@ -353,27 +342,34 @@ static gint __mmcamcorder_init_configure_video_capture(mmf_camcorder_t *hcamcord
                return MM_ERROR_CAMCORDER_NOT_INITIALIZED;
        }
 
+       if (hcamcorder->is_network) {
+               snprintf(conf_file_name, sizeof(conf_file_name), "%s_network.ini",
+                       CONFIGURE_CTRL_FILE_PREFIX);
+       } else {
 #ifdef _MMCAMCORDER_CAMERA_CONF_MGR_SUPPORT
-       snprintf(devicetype, sizeof(devicetype), "%d", hcamcorder->device_type);
-       memset(&hcamcorder->conf_device_info, 0x00, sizeof(camera_conf_device_info_s));
-       ret_conf = camera_conf_mgr_get_ids(devicetype, __MMCAMCORDER_DEVICE_TYPE_STRING_LEN,
-               &hcamcorder->conf_device_info);
-       if (ret_conf !=  CAMERA_CONF_MGR_ERROR_NONE) {
-               MMCAM_LOG_ERROR("Device [%s] is not found", devicetype);
-               return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
-       }
+               snprintf(devicetype, sizeof(devicetype), "%d", hcamcorder->device_type);
+               memset(&hcamcorder->conf_device_info, 0x00, sizeof(camera_conf_device_info_s));
+               ret_conf = camera_conf_mgr_get_ids(devicetype, __MMCAMCORDER_DEVICE_TYPE_STRING_LEN,
+                       &hcamcorder->conf_device_info);
+               if (ret_conf !=  CAMERA_CONF_MGR_ERROR_NONE) {
+                       MMCAM_LOG_ERROR("Device [%s] is not found", devicetype);
+                       return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
+               }
 
-       snprintf(conf_file_name, sizeof(conf_file_name), "%s_%s_%s.ini",
-               CONFIGURE_CTRL_FILE_PREFIX, hcamcorder->conf_device_info.vendor_id,
-               hcamcorder->conf_device_info.product_id);
+               snprintf(conf_file_name, sizeof(conf_file_name), "%s_%s_%s.ini",
+                       CONFIGURE_CTRL_FILE_PREFIX, hcamcorder->conf_device_info.vendor_id,
+                       hcamcorder->conf_device_info.product_id);
 
-       MMCAM_LOG_INFO("Load control configure file [%d][%s][%s]", hcamcorder->device_type,
-               conf_file_name, hcamcorder->conf_device_info.node);
+               MMCAM_LOG_INFO("device info : node[%s]",
+                       hcamcorder->conf_device_info.node);
 #else
-       snprintf(conf_file_name, sizeof(conf_file_name), "%s%d.ini",
-               CONFIGURE_CTRL_FILE_PREFIX, hcamcorder->device_type);
-       MMCAM_LOG_INFO("Load control configure file [%d][%s]", hcamcorder->device_type, conf_file_name);
+               snprintf(conf_file_name, sizeof(conf_file_name), "%s%d.ini",
+                       CONFIGURE_CTRL_FILE_PREFIX, hcamcorder->device_type);
 #endif
+       }
+
+       MMCAM_LOG_INFO("Load control configure file [%d][%s]",
+               hcamcorder->device_type, conf_file_name);
 
        ret = _mmcamcorder_conf_get_info((MMHandleType)hcamcorder,
                CONFIGURE_TYPE_CTRL, (const char *)conf_file_name, &hcamcorder->conf_ctrl);
@@ -429,11 +425,6 @@ static gint __mmcamcorder_init_configure_video_capture(mmf_camcorder_t *hcamcord
                "PlayCaptureSound",
                &play_capture_sound);
 
-       _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
-               CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
-               "DeviceCount",
-               &camera_device_count);
-
        _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_ctrl,
                CONFIGURE_CATEGORY_CTRL_CAMERA,
                "FacingDirection",
@@ -449,9 +440,9 @@ static gint __mmcamcorder_init_configure_video_capture(mmf_camcorder_t *hcamcord
                "SupportZSL",
                &hcamcorder->support_zsl_capture);
 
-       MMCAM_LOG_INFO("Recommend fmt[cap:%d,rec:%d], dpy rot %d, cap snd %d, dev cnt %d, cam facing dir %d, step denom %d, support zsl %d",
+       MMCAM_LOG_INFO("Recommend fmt[cap:%d,rec:%d], dpy rot %d, cap snd %d, cam facing dir %d, step denom %d, support zsl %d",
                rcmd_fmt_capture, rcmd_fmt_recording, rcmd_dpy_rotation,
-               play_capture_sound, camera_device_count, camera_facing_direction,
+               play_capture_sound, camera_facing_direction,
                hcamcorder->brightness_step_denominator, hcamcorder->support_zsl_capture);
 
        _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
@@ -470,10 +461,25 @@ static gint __mmcamcorder_init_configure_video_capture(mmf_camcorder_t *hcamcord
                &hcamcorder->support_media_packet_preview_cb);
 
        _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
+               CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
+               "SupportExtraPreview",
+               &hcamcorder->support_extra_preview);
+
+       _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
                CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
                "UseVideoconvert",
                &hcamcorder->use_videoconvert);
 
+       _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
+               CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
+               "MeasurePreviewFPS",
+               &hcamcorder->measure_preview_fps);
+
+       _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
+               CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
+               "DefaultEncodedPreviewBitrate",
+               &hcamcorder->default_encoded_preview_bitrate);
+
        ret = mm_camcorder_get_attributes((MMHandleType)hcamcorder, NULL,
                MMCAM_CAMERA_WIDTH, &resolution_width,
                MMCAM_CAMERA_HEIGHT, &resolution_height,
@@ -489,9 +495,11 @@ static gint __mmcamcorder_init_configure_video_capture(mmf_camcorder_t *hcamcord
                return MM_ERROR_CAMCORDER_INTERNAL;
        }
 
-       MMCAM_LOG_INFO("ZeroCopy %d, UserBuffer %d, Videoconvert %d, MPPreviewCb %d",
+       MMCAM_LOG_INFO("ZC %d, UB %d, VC %d, MPPC %d, EP %d, MPFPS %d, DEPB %d",
                hcamcorder->use_zero_copy_format, hcamcorder->support_user_buffer,
-               hcamcorder->use_videoconvert, hcamcorder->support_media_packet_preview_cb);
+               hcamcorder->use_videoconvert, hcamcorder->support_media_packet_preview_cb,
+               hcamcorder->support_extra_preview, hcamcorder->measure_preview_fps,
+               hcamcorder->default_encoded_preview_bitrate);
 
        MMCAM_LOG_INFO("res : %d X %d, Default FPS by resolution : %d",
                resolution_width, resolution_height, fps_info.int_array.def);
@@ -510,8 +518,16 @@ static gint __mmcamcorder_init_configure_video_capture(mmf_camcorder_t *hcamcord
                "PlatformPrivilegeCamera",
                &platform_privilege_camera);
 
+       if (hcamcorder->is_network) {
+               _mmcamcorder_conf_get_value_string((MMHandleType)hcamcorder, hcamcorder->conf_main,
+                       CONFIGURE_CATEGORY_MAIN_GENERAL,
+                       "NetworkCameraHALName",
+                       &hcamcorder->network_hal_name);
+
+               MMCAM_LOG_INFO("network HAL name[%s]", hcamcorder->network_hal_name);
+       }
+
        ret = mm_camcorder_set_attributes((MMHandleType)hcamcorder, &err_attr_name,
-               MMCAM_CAMERA_DEVICE_COUNT, camera_device_count,
                MMCAM_CAMERA_FACING_DIRECTION, camera_facing_direction,
                MMCAM_RECOMMEND_PREVIEW_FORMAT_FOR_CAPTURE, rcmd_fmt_capture,
                MMCAM_RECOMMEND_PREVIEW_FORMAT_FOR_RECORDING, rcmd_fmt_recording,
@@ -520,11 +536,13 @@ static gint __mmcamcorder_init_configure_video_capture(mmf_camcorder_t *hcamcord
                MMCAM_SUPPORT_ZERO_COPY_FORMAT, hcamcorder->use_zero_copy_format,
                MMCAM_SUPPORT_MEDIA_PACKET_PREVIEW_CB, hcamcorder->support_media_packet_preview_cb,
                MMCAM_SUPPORT_USER_BUFFER, hcamcorder->support_user_buffer,
+               MMCAM_SUPPORT_EXTRA_PREVIEW, hcamcorder->support_extra_preview,
                MMCAM_CAMERA_FPS, fps_info.int_array.def,
                MMCAM_DISPLAY_FLIP, camera_default_flip,
                MMCAM_CAPTURE_SOUND_ENABLE, play_capture_sound,
                MMCAM_PLATFORM_PRIVILEGE_CAMERA, platform_privilege_camera,
                        platform_privilege_camera ? strlen(platform_privilege_camera) : 0,
+               MMCAM_ENCODED_PREVIEW_BITRATE, hcamcorder->default_encoded_preview_bitrate,
                NULL);
        if (ret != MM_ERROR_NONE) {
                MMCAM_LOG_ERROR("[0x%x] Set %s FAILED.", ret, err_attr_name ? err_attr_name : "[UNKNOWN]");
@@ -550,31 +568,65 @@ static gint __mmcamcorder_init_configure_video_capture(mmf_camcorder_t *hcamcord
 static gint __mmcamcorder_init_configure_audio(mmf_camcorder_t *hcamcorder)
 {
        int ret = MM_ERROR_NONE;
-       int camera_device_count = 0;
 
        if (!hcamcorder) {
                MMCAM_LOG_ERROR("NULL handle");
                return MM_ERROR_CAMCORDER_NOT_INITIALIZED;
        }
 
+       ret = _mmcamcorder_init_attr_from_configure((MMHandleType)hcamcorder, MM_CAMCONVERT_CATEGORY_AUDIO);
+       if (ret != MM_ERROR_NONE) {
+               MMCAM_LOG_ERROR("there is no audio device");
+               return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
+       }
+
+       return ret;
+}
+
+
+static gint __mmcamcorder_init_configure_common(mmf_camcorder_t *hcamcorder)
+{
+       int ret = MM_ERROR_NONE;
+       int device_count = 0;
+       const char *videosrc_name = NULL;
+       const char *audiosrc_name = NULL;
+       type_element *SrcElement = NULL;
+
+       if (!hcamcorder) {
+               MMCAM_LOG_ERROR("NULL handle");
+               return MM_ERROR_CAMCORDER_NOT_INITIALIZED;
+       }
+
+       /* Device count */
        _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
                CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
                "DeviceCount",
-               &camera_device_count);
+               &device_count);
+
+       /* Videosrc element name */
+       _mmcamcorder_conf_get_element((MMHandleType)hcamcorder, hcamcorder->conf_main,
+               CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
+               "VideosrcElement",
+               &SrcElement);
+       _mmcamcorder_conf_get_value_element_name(SrcElement, &videosrc_name);
+
+       /* Audiosrc element name */
+       _mmcamcorder_conf_get_element((MMHandleType)hcamcorder, hcamcorder->conf_main,
+               CONFIGURE_CATEGORY_MAIN_AUDIO_INPUT,
+               "AudiosrcElement",
+               &SrcElement);
+       _mmcamcorder_conf_get_value_element_name(SrcElement, &audiosrc_name);
+
+       MMCAM_LOG_INFO("Device count[%d], Videosrc[%s], Audiosrc[%s]",
+               device_count, videosrc_name, audiosrc_name);
 
        ret = mm_camcorder_set_attributes((MMHandleType)hcamcorder, NULL,
-               MMCAM_CAMERA_DEVICE_COUNT, camera_device_count,
+               MMCAM_CAMERA_DEVICE_COUNT, device_count,
+               MMCAM_VIDEOSRC_ELEMENT_NAME, videosrc_name, videosrc_name ? strlen(videosrc_name) : 0,
+               MMCAM_AUDIOSRC_ELEMENT_NAME, audiosrc_name, audiosrc_name ? strlen(audiosrc_name) : 0,
                NULL);
-       if (ret != MM_ERROR_NONE) {
-               MMCAM_LOG_ERROR("Set device count FAILED");
-               return MM_ERROR_CAMCORDER_INTERNAL;
-       }
-
-       ret = _mmcamcorder_init_attr_from_configure((MMHandleType)hcamcorder, MM_CAMCONVERT_CATEGORY_AUDIO);
-       if (ret != MM_ERROR_NONE) {
-               MMCAM_LOG_ERROR("there is no audio device");
-               return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
-       }
+       if (ret != MM_ERROR_NONE)
+               MMCAM_LOG_ERROR("Set FAILED[0x%x]", ret);
 
        return ret;
 }
@@ -622,16 +674,22 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
        if (ret != MM_ERROR_NONE)
                return ret;
 
+       /* set network camera flag */
+       hcamcorder->is_network = (gboolean)info->reserved[0];
+
        /* get DPM handle for camera/microphone restriction */
        hcamcorder->dpm_handle = dpm_manager_create();
 
        MMCAM_LOG_WARNING("DPM handle %p", hcamcorder->dpm_handle);
 
+       ret = __mmcamcorder_init_configure_common(hcamcorder);
+       if (ret != MM_ERROR_NONE)
+               goto _ERR_DEFAULT_VALUE_INIT;
+
        if (hcamcorder->device_type != MM_VIDEO_DEVICE_NONE) {
                ret = __mmcamcorder_init_configure_video_capture(hcamcorder);
-               if (ret != MM_ERROR_NONE) {
+               if (ret != MM_ERROR_NONE)
                        goto _ERR_DEFAULT_VALUE_INIT;
-               }
 
                /* add DPM camera policy changed callback */
                if (hcamcorder->dpm_handle) {
@@ -658,9 +716,8 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
        } else {
                ret = __mmcamcorder_init_configure_audio(hcamcorder);
-               if (ret != MM_ERROR_NONE) {
+               if (ret != MM_ERROR_NONE)
                        goto _ERR_DEFAULT_VALUE_INIT;
-               }
        }
 
        traceBegin(TTRACE_TAG_CAMERA, "MMCAMCORDER:CREATE:INIT_GSTREAMER");
@@ -795,13 +852,6 @@ int _mmcamcorder_destroy(MMHandleType handle)
        _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder);
 #endif /* _MMCAMCORDER_MM_RM_SUPPORT */
 
-       /* Remove idle function which is not called yet */
-       if (hcamcorder->setting_event_id) {
-               MMCAM_LOG_INFO("Remove remaining idle function");
-               g_source_remove(hcamcorder->setting_event_id);
-               hcamcorder->setting_event_id = 0;
-       }
-
        /* Remove messages which are not called yet */
        _mmcamcorder_remove_message_all(handle);
 
@@ -2247,6 +2297,39 @@ int _mmcamcorder_stop_focusing(MMHandleType handle)
        }
 }
 
+int _mmcamcorder_get_focus_level(MMHandleType handle, int *level)
+{
+       GstCameraControl *control = NULL;
+       _MMCamcorderSubContext *sc = NULL;
+       mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
+
+       mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
+       mmf_return_val_if_fail(level, MM_ERROR_CAMCORDER_INVALID_ARGUMENT);
+
+       sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
+       mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
+
+       if (!GST_IS_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
+               MMCAM_LOG_ERROR("Can't cast Video source into camera control.");
+               return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
+       }
+
+       control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
+       if (!control) {
+               MMCAM_LOG_ERROR("cast CAMERA_CONTROL failed");
+               return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
+       }
+
+       if (!gst_camera_control_get_focus_level(control, level)) {
+               MMCAM_LOG_ERROR("get focus level failed");
+               return MM_ERROR_CAMCORDER_NOT_SUPPORTED;
+       }
+
+       MMCAM_LOG_INFO("focus level[%d]", *level);
+
+       return MM_ERROR_NONE;
+}
+
 
 /*-----------------------------------------------
 |        CAMCORDER INTERNAL LOCAL              |
@@ -2549,15 +2632,13 @@ gboolean _mmcamcorder_pipeline_cb_message(GstBus *bus, GstMessage *message, gpoi
 
        mmf_return_val_if_fail(hcamcorder, FALSE);
        mmf_return_val_if_fail(message, FALSE);
-       /* MMCAM_LOG_INFO("message type=(%d)", GST_MESSAGE_TYPE(message)); */
+
+       MMCAM_LOG_DEBUG("message type[0x%x]", GST_MESSAGE_TYPE(message));
 
        switch (GST_MESSAGE_TYPE(message)) {
-       case GST_MESSAGE_UNKNOWN:
-               MMCAM_LOG_INFO("GST_MESSAGE_UNKNOWN");
-               break;
        case GST_MESSAGE_EOS:
        {
-               MMCAM_LOG_ERROR("Got EOS from element \"%s\"... but should not be reached here!",
+               MMCAM_LOG_ERROR("Got EOS from element[%s]... but should not be reached here!",
                        GST_STR_NULL(GST_ELEMENT_NAME(GST_MESSAGE_SRC(message))));
                break;
        }
@@ -2597,15 +2678,6 @@ gboolean _mmcamcorder_pipeline_cb_message(GstBus *bus, GstMessage *message, gpoi
                g_free(debug);
                break;
        }
-       case GST_MESSAGE_INFO:
-               MMCAM_LOG_INFO("GST_MESSAGE_INFO");
-               break;
-       case GST_MESSAGE_TAG:
-               MMCAM_LOG_INFO("GST_MESSAGE_TAG");
-               break;
-       case GST_MESSAGE_BUFFERING:
-               MMCAM_LOG_INFO("GST_MESSAGE_BUFFERING");
-               break;
        case GST_MESSAGE_STATE_CHANGED:
        {
                const GValue *vnewstate;
@@ -2629,63 +2701,15 @@ gboolean _mmcamcorder_pipeline_cb_message(GstBus *bus, GstMessage *message, gpoi
                }
                break;
        }
-       case GST_MESSAGE_STATE_DIRTY:
-               MMCAM_LOG_INFO("GST_MESSAGE_STATE_DIRTY");
-               break;
-       case GST_MESSAGE_STEP_DONE:
-               MMCAM_LOG_INFO("GST_MESSAGE_STEP_DONE");
-               break;
-       case GST_MESSAGE_CLOCK_PROVIDE:
-               MMCAM_LOG_INFO("GST_MESSAGE_CLOCK_PROVIDE");
-               break;
-       case GST_MESSAGE_CLOCK_LOST:
-               MMCAM_LOG_INFO("GST_MESSAGE_CLOCK_LOST");
-               break;
        case GST_MESSAGE_NEW_CLOCK:
        {
                GstClock *pipe_clock = NULL;
                gst_message_parse_new_clock(message, &pipe_clock);
-               /*MMCAM_LOG_INFO("GST_MESSAGE_NEW_CLOCK : %s", (clock ? GST_OBJECT_NAME (clock) : "NULL"));*/
+               MMCAM_LOG_INFO("GST_MESSAGE_NEW_CLOCK[%s]", (pipe_clock ? GST_OBJECT_NAME(pipe_clock) : "NULL"));
                break;
        }
-       case GST_MESSAGE_STRUCTURE_CHANGE:
-               MMCAM_LOG_INFO("GST_MESSAGE_STRUCTURE_CHANGE");
-               break;
-       case GST_MESSAGE_STREAM_STATUS:
-               /*MMCAM_LOG_INFO("GST_MESSAGE_STREAM_STATUS");*/
-               break;
-       case GST_MESSAGE_APPLICATION:
-               MMCAM_LOG_INFO("GST_MESSAGE_APPLICATION");
-               break;
-       case GST_MESSAGE_ELEMENT:
-               /*MMCAM_LOG_INFO("GST_MESSAGE_ELEMENT");*/
-               break;
-       case GST_MESSAGE_SEGMENT_START:
-               MMCAM_LOG_INFO("GST_MESSAGE_SEGMENT_START");
-               break;
-       case GST_MESSAGE_SEGMENT_DONE:
-               MMCAM_LOG_INFO("GST_MESSAGE_SEGMENT_DONE");
-               break;
-       case GST_MESSAGE_DURATION_CHANGED:
-               MMCAM_LOG_INFO("GST_MESSAGE_DURATION_CHANGED");
-               break;
-       case GST_MESSAGE_LATENCY:
-               MMCAM_LOG_INFO("GST_MESSAGE_LATENCY");
-               break;
-       case GST_MESSAGE_ASYNC_START:
-               MMCAM_LOG_INFO("GST_MESSAGE_ASYNC_START");
-               break;
-       case GST_MESSAGE_ASYNC_DONE:
-               /*MMCAM_LOG_INFO("GST_MESSAGE_ASYNC_DONE");*/
-               break;
-       case GST_MESSAGE_ANY:
-               MMCAM_LOG_INFO("GST_MESSAGE_ANY");
-               break;
-       case GST_MESSAGE_QOS:
-               /* MMCAM_LOG_INFO("GST_MESSAGE_QOS"); */
-               break;
        default:
-               MMCAM_LOG_INFO("not handled message type=(%d)", GST_MESSAGE_TYPE(message));
+               MMCAM_LOG_DEBUG("unhandled message type[0x%x]", GST_MESSAGE_TYPE(message));
                break;
        }
 
@@ -2695,18 +2719,17 @@ gboolean _mmcamcorder_pipeline_cb_message(GstBus *bus, GstMessage *message, gpoi
 
 GstBusSyncReply _mmcamcorder_pipeline_bus_sync_callback(GstBus *bus, GstMessage *message, gpointer data)
 {
-       GstElement *element = NULL;
        GError *err = NULL;
        gchar *debug_info = NULL;
 
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(data);
        _MMCamcorderSubContext *sc = NULL;
 
-       mmf_return_val_if_fail(hcamcorder, GST_BUS_PASS);
-       mmf_return_val_if_fail(message, GST_BUS_PASS);
+       mmf_return_val_if_fail(hcamcorder, GST_BUS_DROP);
+       mmf_return_val_if_fail(message, GST_BUS_DROP);
 
        sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
-       mmf_return_val_if_fail(sc, GST_BUS_PASS);
+       mmf_return_val_if_fail(sc, GST_BUS_DROP);
 
        if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_ERROR) {
                /* parse error message */
@@ -2723,11 +2746,9 @@ GstBusSyncReply _mmcamcorder_pipeline_bus_sync_callback(GstBus *bus, GstMessage
                        return GST_BUS_PASS;
                }
 
-               /* set videosrc element to compare */
-               element = GST_ELEMENT_CAST(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
-
                /* check domain[RESOURCE] and element[VIDEOSRC] */
-               if (err->domain == GST_RESOURCE_ERROR && GST_ELEMENT_CAST(message->src) == element) {
+               if (err->domain == GST_RESOURCE_ERROR &&
+                       GST_ELEMENT_CAST(message->src) == GST_ELEMENT_CAST(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst)) {
                        switch (err->code) {
                        case GST_RESOURCE_ERROR_BUSY:
                                MMCAM_LOG_ERROR("Camera device [busy]");
@@ -2736,7 +2757,6 @@ GstBusSyncReply _mmcamcorder_pipeline_bus_sync_callback(GstBus *bus, GstMessage
                        case GST_RESOURCE_ERROR_OPEN_WRITE:
                                MMCAM_LOG_ERROR("Camera device [open failed]");
                                hcamcorder->error_code = MM_ERROR_COMMON_INVALID_PERMISSION;
-                               /* sc->error_code = MM_ERROR_CAMCORDER_DEVICE_OPEN; // SECURITY PART REQUEST PRIVILEGE */
                                break;
                        case GST_RESOURCE_ERROR_OPEN_READ_WRITE:
                                MMCAM_LOG_ERROR("Camera device [open failed]");
@@ -2782,8 +2802,6 @@ GstBusSyncReply _mmcamcorder_pipeline_bus_sync_callback(GstBus *bus, GstMessage
                        msg.id = MM_MESSAGE_CAMCORDER_ERROR;
                        msg.param.code = hcamcorder->error_code;
                        _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
-
-                       goto DROP_MESSAGE;
                }
        } else if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_ELEMENT) {
                _MMCamcorderMsgItem msg;
@@ -2798,8 +2816,6 @@ GstBusSyncReply _mmcamcorder_pipeline_bus_sync_callback(GstBus *bus, GstMessage
                        msg.id = MM_MESSAGE_CAMCORDER_FOCUS_CHANGED;
                        msg.param.code = focus_state;
                        _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
-
-                       goto DROP_MESSAGE;
                } else if (gst_structure_has_name(gst_message_get_structure(message), "camerasrc-HDR")) {
                        int progress = 0;
                        int status = 0;
@@ -2812,8 +2828,6 @@ GstBusSyncReply _mmcamcorder_pipeline_bus_sync_callback(GstBus *bus, GstMessage
                                msg.param.code = progress;
                                _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
                        }
-
-                       goto DROP_MESSAGE;
                } else if (gst_structure_has_name(gst_message_get_structure(message), "camerasrc-FD")) {
                        int i = 0;
                        const GValue *g_value = gst_structure_get_value(gst_message_get_structure(message), "face-info");;
@@ -2825,7 +2839,8 @@ GstBusSyncReply _mmcamcorder_pipeline_bus_sync_callback(GstBus *bus, GstMessage
 
                        if (fd_info == NULL) {
                                MMCAM_LOG_WARNING("fd_info is NULL");
-                               goto DROP_MESSAGE;
+                               gst_message_unref(message);
+                               return GST_BUS_DROP;
                        }
 
                        cam_fd_info = (MMCamFaceDetectInfo *)g_malloc(sizeof(MMCamFaceDetectInfo));
@@ -2868,8 +2883,6 @@ GstBusSyncReply _mmcamcorder_pipeline_bus_sync_callback(GstBus *bus, GstMessage
                        /* free fd_info allocated by plugin */
                        free(fd_info);
                        fd_info = NULL;
-
-                       goto DROP_MESSAGE;
                } else if (gst_structure_has_name(gst_message_get_structure(message), "camerasrc-Capture")) {
                        int capture_done = FALSE;
 
@@ -2879,28 +2892,24 @@ GstBusSyncReply _mmcamcorder_pipeline_bus_sync_callback(GstBus *bus, GstMessage
                                        _mmcamcorder_sound_solo_play((MMHandleType)hcamcorder, _MMCAMCORDER_SAMPLE_SOUND_NAME_CAPTURE01, FALSE);
                                }
                        }
-
-                       goto DROP_MESSAGE;
+               } else {
+                       _mmcamcorder_pipeline_cb_message(bus, message, data);
                }
+       } else {
+               _mmcamcorder_pipeline_cb_message(bus, message, data);
        }
 
-       return GST_BUS_PASS;
-
-DROP_MESSAGE:
        gst_message_unref(message);
 
        return GST_BUS_DROP;
 }
 
 
-static GstBusSyncReply __mmcamcorder_gst_handle_sync_audio_error(mmf_camcorder_t *hcamcorder, gint err_code)
+static void __mmcamcorder_gst_handle_sync_audio_error(mmf_camcorder_t *hcamcorder, gint err_code)
 {
        _MMCamcorderMsgItem msg;
 
-       if (!hcamcorder) {
-               MMCAM_LOG_ERROR("NULL handle");
-               return GST_BUS_PASS;
-       }
+       mmf_return_if_fail(hcamcorder);
 
        switch (err_code) {
        case GST_RESOURCE_ERROR_OPEN_READ_WRITE:
@@ -2915,38 +2924,31 @@ static GstBusSyncReply __mmcamcorder_gst_handle_sync_audio_error(mmf_camcorder_t
                msg.param.code = hcamcorder->error_code;
 
                _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
-
-               MMCAM_LOG_ERROR("error : sc->error_occurs %d", hcamcorder->error_occurs);
-
-               return GST_BUS_DROP;
+               break;
        default:
+               MMCAM_LOG_ERROR("unhandled error code[%d]", err_code);
                break;
        }
-
-       return GST_BUS_PASS;
 }
 
 
-static GstBusSyncReply __mmcamcorder_gst_handle_sync_others_error(mmf_camcorder_t *hcamcorder, gint err_code)
+static void __mmcamcorder_gst_handle_sync_others_error(mmf_camcorder_t *hcamcorder, gint err_code)
 {
        gboolean b_committing = FALSE;
        storage_state_e storage_state = STORAGE_STATE_UNMOUNTABLE;
        _MMCamcorderMsgItem msg;
        _MMCamcorderSubContext *sc = NULL;
 
-       if (!hcamcorder) {
-               MMCAM_LOG_ERROR("NULL handle");
-               return GST_BUS_PASS;
-       }
+       mmf_return_if_fail(hcamcorder);
 
        sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
-       mmf_return_val_if_fail(sc, GST_BUS_PASS);
+       mmf_return_if_fail(sc);
 
        if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
-               mmf_return_val_if_fail(sc->info_video, GST_BUS_PASS);
+               mmf_return_if_fail(sc->info_video);
                b_committing = sc->info_video->b_committing;
        } else {
-               mmf_return_val_if_fail(sc->info_audio, GST_BUS_PASS);
+               mmf_return_if_fail(sc->info_audio);
                b_committing = sc->info_audio->b_committing;
        }
 
@@ -2969,7 +2971,7 @@ static GstBusSyncReply __mmcamcorder_gst_handle_sync_others_error(mmf_camcorder_
                } else {
                        MMCAM_LOG_ERROR("error was already sent");
                        _MMCAMCORDER_UNLOCK(hcamcorder);
-                       return GST_BUS_DROP;
+                       return;
                }
                break;
        case GST_RESOURCE_ERROR_NO_SPACE_LEFT:
@@ -3001,25 +3003,20 @@ static GstBusSyncReply __mmcamcorder_gst_handle_sync_others_error(mmf_camcorder_
 
                _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
        }
-
-       return GST_BUS_DROP;
 }
 
 
-static GstBusSyncReply __mmcamcorder_handle_gst_sync_error(mmf_camcorder_t *hcamcorder, GstMessage *message)
+static void __mmcamcorder_handle_gst_sync_error(mmf_camcorder_t *hcamcorder, GstMessage *message)
 {
        GError *err = NULL;
        gchar *debug_info = NULL;
-       GstBusSyncReply ret = GST_BUS_PASS;
        _MMCamcorderSubContext *sc = NULL;
 
-       if (!message || !hcamcorder) {
-               MMCAM_LOG_ERROR("NULL message(%p) or handle(%p)", message, hcamcorder);
-               return GST_BUS_PASS;
-       }
+       mmf_return_if_fail(hcamcorder);
+       mmf_return_if_fail(message);
 
        sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
-       mmf_return_val_if_fail(sc, GST_BUS_PASS);
+       mmf_return_if_fail(sc);
 
        /* parse error message */
        gst_message_parse_error(message, &err, &debug_info);
@@ -3031,35 +3028,31 @@ static GstBusSyncReply __mmcamcorder_handle_gst_sync_error(mmf_camcorder_t *hcam
        }
 
        if (!err) {
-               MMCAM_LOG_WARNING("failed to parse error message");
-               return GST_BUS_PASS;
+               MMCAM_LOG_ERROR("failed to parse error message");
+               return;
        }
 
        /* check domain[RESOURCE] and element[AUDIOSRC] */
        if (err->domain == GST_RESOURCE_ERROR &&
                GST_ELEMENT_CAST(message->src) == GST_ELEMENT_CAST(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst))
-               ret = __mmcamcorder_gst_handle_sync_audio_error(hcamcorder, err->code);
+               __mmcamcorder_gst_handle_sync_audio_error(hcamcorder, err->code);
        else
-               ret = __mmcamcorder_gst_handle_sync_others_error(hcamcorder, err->code);
+               __mmcamcorder_gst_handle_sync_others_error(hcamcorder, err->code);
 
        g_error_free(err);
-
-       return ret;
 }
 
 
 GstBusSyncReply _mmcamcorder_encode_pipeline_bus_sync_callback(GstBus *bus, GstMessage *message, gpointer data)
 {
-       GstBusSyncReply ret = GST_BUS_PASS;
-
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(data);
        _MMCamcorderSubContext *sc = NULL;
 
-       mmf_return_val_if_fail(hcamcorder, GST_BUS_PASS);
-       mmf_return_val_if_fail(message, GST_BUS_PASS);
+       mmf_return_val_if_fail(hcamcorder, GST_BUS_DROP);
+       mmf_return_val_if_fail(message, GST_BUS_DROP);
 
        sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
-       mmf_return_val_if_fail(sc, GST_BUS_PASS);
+       mmf_return_val_if_fail(sc, GST_BUS_DROP);
 
        if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_EOS) {
                MMCAM_LOG_INFO("got EOS from pipeline");
@@ -3070,16 +3063,15 @@ GstBusSyncReply _mmcamcorder_encode_pipeline_bus_sync_callback(GstBus *bus, GstM
                _MMCAMCORDER_SIGNAL(hcamcorder);
 
                _MMCAMCORDER_UNLOCK(hcamcorder);
-
-               ret = GST_BUS_DROP;
        } else if (GST_MESSAGE_TYPE(message) == GST_MESSAGE_ERROR) {
-               ret = __mmcamcorder_handle_gst_sync_error(hcamcorder, message);
+               __mmcamcorder_handle_gst_sync_error(hcamcorder, message);
+       } else {
+               _mmcamcorder_pipeline_cb_message(bus, message, data);
        }
 
-       if (ret == GST_BUS_DROP)
-               gst_message_unref(message);
+       gst_message_unref(message);
 
-       return ret;
+       return GST_BUS_DROP;
 }
 
 
@@ -3137,17 +3129,21 @@ int _mmcamcorder_create_pipeline(MMHandleType handle, int type)
 
                break;
        case MM_CAMCORDER_MODE_VIDEO_CAPTURE:
+               /* fall through */
        default:
                ret = _mmcamcorder_create_preview_pipeline(handle);
                if (ret != MM_ERROR_NONE)
                        return ret;
 
-               /* connect capture signal */
                if (!sc->bencbin_capture) {
                        ret = _mmcamcorder_connect_capture_signal(handle);
                        if (ret != MM_ERROR_NONE)
                                return ret;
                }
+
+               if (hcamcorder->support_extra_preview &&
+                       _mmcamcorder_initialize_extra_preview_stream(handle) != MM_ERROR_NONE)
+                       MMCAM_LOG_WARNING("connect extra preview stream signal failed");
                break;
        }
 
@@ -3181,7 +3177,6 @@ void _mmcamcorder_destroy_pipeline(MMHandleType handle, int type)
        gint i = 0;
        int element_num = 0;
        _MMCamcorderGstElement *element = NULL;
-       GstBus *bus = NULL;
 
        mmf_return_if_fail(hcamcorder);
 
@@ -3195,13 +3190,11 @@ void _mmcamcorder_destroy_pipeline(MMHandleType handle, int type)
        case MM_CAMCORDER_MODE_VIDEO_CAPTURE:
                element = sc->element;
                element_num = sc->element_num;
-               bus = gst_pipeline_get_bus(GST_PIPELINE(sc->element[_MMCAMCORDER_MAIN_PIPE].gst));
                _mmcamcorder_destroy_video_capture_pipeline(handle);
                break;
        case MM_CAMCORDER_MODE_AUDIO:
                element = sc->encode_element;
                element_num = sc->encode_element_num;
-               bus = gst_pipeline_get_bus(GST_PIPELINE(sc->encode_element[_MMCAMCORDER_ENCODE_MAIN_PIPE].gst));
                _mmcamcorder_destroy_audio_pipeline(handle);
                break;
        default:
@@ -3211,24 +3204,6 @@ void _mmcamcorder_destroy_pipeline(MMHandleType handle, int type)
 
        MMCAM_LOG_INFO("Pipeline clear!!");
 
-       /* Remove pipeline message callback */
-       if (hcamcorder->pipeline_cb_event_id > 0) {
-               g_source_remove(hcamcorder->pipeline_cb_event_id);
-               hcamcorder->pipeline_cb_event_id = 0;
-       }
-
-       /* Remove remained message in bus */
-       if (bus) {
-               GstMessage *gst_msg = NULL;
-               while ((gst_msg = gst_bus_pop(bus)) != NULL) {
-                       _mmcamcorder_pipeline_cb_message(bus, gst_msg, (gpointer)hcamcorder);
-                       gst_message_unref(gst_msg);
-                       gst_msg = NULL;
-               }
-               gst_object_unref(bus);
-               bus = NULL;
-       }
-
        /* checking unreleased element */
        for (i = 0 ; i < element_num ; i++) {
                if (element[i].gst) {
@@ -3252,28 +3227,6 @@ void _mmcamcorder_destroy_pipeline(MMHandleType handle, int type)
 }
 
 
-#ifdef _MMCAMCORDER_USE_SET_ATTR_CB
-static gboolean __mmcamcorder_set_attr_to_camsensor_cb(gpointer data)
-{
-       mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(data);
-
-       mmf_return_val_if_fail(hcamcorder, FALSE);
-
-       MMCAM_LOG_INFO("");
-
-       _mmcamcorder_set_attribute_to_camsensor((MMHandleType)hcamcorder);
-
-       /* initialize */
-       hcamcorder->setting_event_id = 0;
-
-       MMCAM_LOG_INFO("Done");
-
-       /* once */
-       return FALSE;
-}
-#endif /* _MMCAMCORDER_USE_SET_ATTR_CB */
-
-
 int _mmcamcorder_gst_set_state(MMHandleType handle, GstElement *pipeline, GstState target_state)
 {
        unsigned int k = 0;
@@ -3532,14 +3485,17 @@ static gboolean __mmcamcorder_handle_gst_error(MMHandleType handle, GstMessage *
 
        mmf_return_val_if_fail(hcamcorder, FALSE);
        mmf_return_val_if_fail(error, FALSE);
+
        sc = MMF_CAMCORDER_SUBCONTEXT(handle);
        mmf_return_val_if_fail(sc, FALSE);
 
-       MMCAM_LOG_INFO("");
+       MMCAM_LOG_INFO("error code %d", error->code);
+
+       mmf_return_val_if_fail(hcamcorder->state >= MM_CAMCORDER_STATE_READY, FALSE);
 
        /* filtering filesink related errors */
        if (hcamcorder->state == MM_CAMCORDER_STATE_RECORDING &&
-           (error->code ==  GST_RESOURCE_ERROR_WRITE || error->code ==  GST_RESOURCE_ERROR_SEEK)) {
+           (error->code == GST_RESOURCE_ERROR_WRITE || error->code == GST_RESOURCE_ERROR_SEEK)) {
                if (sc->ferror_count == 2 && sc->ferror_send == FALSE) {
                        sc->ferror_send = TRUE;
                        msg.param.code = __mmcamcorder_gst_handle_resource_error(handle, error->code, message);