Fix build error for product TV
[platform/core/multimedia/libmm-camcorder.git] / src / mm_camcorder_gstcommon.c
index cd1db49..362421c 100644 (file)
  */
 
 /*=======================================================================================
-|  INCLUDE FILES                                                                       |
+|  INCLUDE FILES                                                                        |
 =======================================================================================*/
 #include <gst/allocators/gsttizenmemory.h>
 #include <gst/audio/audio-format.h>
 #include <gst/video/videooverlay.h>
-#include <gst/video/cameracontrol.h>
 
 #include <sys/time.h>
 #include <unistd.h>
 #include "mm_camcorder_gstcommon.h"
 
 /*-----------------------------------------------------------------------
-|    GLOBAL VARIABLE DEFINITIONS for internal                          |
+|    GLOBAL VARIABLE DEFINITIONS for internal                           |
 -----------------------------------------------------------------------*/
 /* Table for compatibility between audio codec and file format */
-gboolean       audiocodec_fileformat_compatibility_table[MM_AUDIO_CODEC_NUM][MM_FILE_FORMAT_NUM] = {
+static gboolean audiocodec_fileformat_compatibility_table[MM_AUDIO_CODEC_NUM][MM_FILE_FORMAT_NUM] = {
                   /* 3GP ASF AVI MATROSKA MP4 OGG NUT QT REAL AMR AAC MP3 AIFF AU WAV MID MMF DIVX FLV VOB IMELODY WMA WMV JPG FLAC M2TS*/
 /*AMR*/       { 1,  0,  0,       0,  0,  0,  0, 0,   0,  1,  0,  0,   0, 0,  0,  0,  0,   0,  0,  0,      0,  0,  0,  0,   0,   0},
 /*G723.1*/    { 0,  0,  0,       0,  0,  0,  0, 0,   0,  0,  0,  0,   0, 0,  0,  0,  0,   0,  0,  0,      0,  0,  0,  0,   0,   0},
@@ -89,7 +88,7 @@ gboolean      audiocodec_fileformat_compatibility_table[MM_AUDIO_CODEC_NUM][MM_FILE_F
 };
 
 /* Table for compatibility between video codec and file format */
-gboolean       videocodec_fileformat_compatibility_table[MM_VIDEO_CODEC_NUM][MM_FILE_FORMAT_NUM] = {
+static gboolean videocodec_fileformat_compatibility_table[MM_VIDEO_CODEC_NUM][MM_FILE_FORMAT_NUM] = {
                          /* 3GP ASF AVI MATROSKA MP4 OGG NUT QT REAL AMR AAC MP3 AIFF AU WAV MID MMF DIVX FLV VOB IMELODY WMA WMV JPG FLAC M2TS*/
 /*NONE*/         { 0,  0,  0,       0,  0,  0,  0, 0,   0,  0,  0,  0,   0, 0,  0,  0,  0,   0,  0,  0,      0,  0,  0,  0,   0,   0},
 /*H263*/         { 1,  0,  1,       0,  0,  0,  0, 0,   0,  0,  0,  0,   0, 0,  0,  0,  0,   0,  0,  0,      0,  0,  0,  0,   0,   0},
@@ -104,7 +103,7 @@ gboolean    videocodec_fileformat_compatibility_table[MM_VIDEO_CODEC_NUM][MM_FILE_F
 /*H262*/         { 0,  0,  0,       0,  0,  0,  0, 0,   0,  0,  0,  0,   0, 0,  0,  0,  0,   0,  0,  0,      0,  0,  0,  0,   0,   0},
 /*H263V2*/       { 0,  0,  0,       0,  0,  0,  0, 0,   0,  0,  0,  0,   0, 0,  0,  0,  0,   0,  0,  0,      0,  0,  0,  0,   0,   0},
 /*H263V3*/       { 0,  0,  0,       0,  0,  0,  0, 0,   0,  0,  0,  0,   0, 0,  0,  0,  0,   0,  0,  0,      0,  0,  0,  0,   0,   0},
-/*MJPEG*/        { 0,  0,  0,       0,  0,  0,  0, 0,   0,  0,  0,  0,   0, 0,  0,  0,  0,   0,  0,  0,      0,  0,  0,  0,   0,   0},
+/*MJPEG*/        { 0,  0,  1,       1,  0,  0,  0, 0,   0,  0,  0,  0,   0, 0,  0,  0,  0,   0,  0,  0,      0,  0,  0,  0,   0,   0},
 /*MPEG2*/        { 0,  0,  0,       0,  0,  0,  0, 0,   0,  0,  0,  0,   0, 0,  0,  0,  0,   0,  0,  0,      0,  0,  0,  0,   0,   0},
 /*MPEG4_SIMPLE*/ { 0,  0,  0,       0,  0,  0,  0, 0,   0,  0,  0,  0,   0, 0,  0,  0,  0,   0,  0,  0,      0,  0,  0,  0,   0,   0},
 /*MPEG4_ADV*/    { 0,  0,  0,       0,  0,  0,  0, 0,   0,  0,  0,  0,   0, 0,  0,  0,  0,   0,  0,  0,      0,  0,  0,  0,   0,   0},
@@ -123,78 +122,432 @@ gboolean videocodec_fileformat_compatibility_table[MM_VIDEO_CODEC_NUM][MM_FILE_F
 
 
 /*-----------------------------------------------------------------------
-|    LOCAL VARIABLE DEFINITIONS for internal                           |
+|    LOCAL VARIABLE DEFINITIONS for internal                            |
 -----------------------------------------------------------------------*/
 #define USE_AUDIO_CLOCK_TUNE
 #define _MMCAMCORDER_WAIT_EOS_TIME                60.0     /* sec */
 #define _MMCAMCORDER_CONVERT_OUTPUT_BUFFER_NUM    6
-#define _MMCAMCORDER_MIN_TIME_TO_PASS_FRAME       30000000 /* ns */
-#define _MMCAMCORDER_FRAME_PASS_MIN_FPS           30
 #define _MMCAMCORDER_NANOSEC_PER_1SEC             1000000000
 #define _MMCAMCORDER_NANOSEC_PER_1MILISEC         1000
+#define _MMCAMCORDER_SIGNAL_REQUEST_CODEC_CONFIG  "request-codec-config"
 
 
 /*-----------------------------------------------------------------------
-|    LOCAL FUNCTION PROTOTYPES:                                                |
+|    LOCAL FUNCTION PROTOTYPES:                                         |
 -----------------------------------------------------------------------*/
 /* STATIC INTERNAL FUNCTION */
 /**
- * These functions are preview video data probing function.
- * If this function is linked with certain pad by gst_pad_add_buffer_probe(),
- * this function will be called when data stream pass through the pad.
+ * These are video data probing functions.
+ * If there are pads which set probe callback by gst_pad_add_probe(),
+ * the functions will be called when data stream pass through the pad.
  *
- * @param[in]  pad             probing pad which calls this function.
- * @param[in]  buffer          buffer which contains stream data.
- * @param[in]  u_data          user data.
- * @return     This function returns true on success, or false value with error
+ * @param[in]  pad             probing pad which calls this function.
+ * @param[in]  buffer          buffer which contains stream data.
+ * @param[in]  u_data          user data.
+ * @return     Refer #GstPadProbeReturn in gstpad.h
  * @remarks
- * @see                __mmcamcorder_create_preview_pipeline()
+ * @see        __mmcamcorder_create_preview_pipeline()
  */
 static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstPadProbeInfo *info, gpointer u_data);
-static GstPadProbeReturn __mmcamcorder_video_dataprobe_push_buffer_to_record(GstPad *pad, GstPadProbeInfo *info, gpointer u_data);
+static GstPadProbeReturn __mmcamcorder_video_dataprobe_record(GstPad *pad, GstPadProbeInfo *info, gpointer u_data);
+
 static int __mmcamcorder_get_amrnb_bitrate_mode(int bitrate);
-static guint32 _mmcamcorder_convert_fourcc_string_to_value(const gchar* format_name);
+static guint32 _mmcamcorder_get_structure_fourcc(const GstStructure *structure);
+
+static gboolean __mmcamcorder_set_stream_data(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMapInfo *map_info);
+static gboolean __mmcamcorder_set_stream_data_zero_copy(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMemory *memory);
+static const char *__mmcamcorder_get_parser_name(MMPixelFormatType format);
+static void __mmcamcorder_request_codec_config(GstElement *videosrc_element);
 
 /*=======================================================================================
-|  FUNCTION DEFINITIONS                                                                        |
+|  FUNCTION DEFINITIONS                                                                 |
 =======================================================================================*/
-/*-----------------------------------------------------------------------
-|    GLOBAL FUNCTION DEFINITIONS:                                      |
------------------------------------------------------------------------*/
+static gboolean __mmcamcorder_set_stream_data(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMapInfo *map_info)
+{
+       gboolean ret = TRUE;
+
+       mmf_return_val_if_fail(buffer, FALSE);
+       mmf_return_val_if_fail(stream, FALSE);
+       mmf_return_val_if_fail(map_info, FALSE);
+
+       stream->length_total = map_info->size;
+
+       switch (stream->format) {
+       case MM_PIXEL_FORMAT_NV12: /* fall through */
+       case MM_PIXEL_FORMAT_NV21:
+               stream->data_type = MM_CAM_STREAM_DATA_YUV420SP;
+               stream->data.yuv420sp.y = map_info->data;
+               stream->data.yuv420sp.length_y = stream->width * stream->height;
+               stream->data.yuv420sp.uv = stream->data.yuv420sp.y + stream->data.yuv420sp.length_y;
+               stream->data.yuv420sp.length_uv = stream->data.yuv420sp.length_y >> 1;
+               stream->stride[0] = stream->width;
+               stream->elevation[0] = stream->height;
+               stream->stride[1] = stream->width;
+               stream->elevation[1] = stream->height >> 1;
+               stream->num_planes = 2;
+               break;
+
+       case MM_PIXEL_FORMAT_I420:
+               stream->data_type = MM_CAM_STREAM_DATA_YUV420P;
+               stream->data.yuv420p.y = map_info->data;
+               stream->data.yuv420p.length_y = stream->width * stream->height;
+               stream->data.yuv420p.u = stream->data.yuv420p.y + stream->data.yuv420p.length_y;
+               stream->data.yuv420p.length_u = stream->data.yuv420p.length_y >> 2;
+               stream->data.yuv420p.v = stream->data.yuv420p.u + stream->data.yuv420p.length_u;
+               stream->data.yuv420p.length_v = stream->data.yuv420p.length_u;
+               stream->stride[0] = stream->width;
+               stream->elevation[0] = stream->height;
+               stream->stride[1] = stream->stride[2] = stream->width >> 1;
+               stream->elevation[1] = stream->elevation[2] = stream->height >> 1;
+               stream->num_planes = 3;
+               break;
+
+       case MM_PIXEL_FORMAT_422P:
+               stream->data_type = MM_CAM_STREAM_DATA_YUV422P;
+               stream->data.yuv422p.y = map_info->data;
+               stream->data.yuv422p.length_y = stream->width * stream->height;
+               stream->data.yuv422p.u = stream->data.yuv422p.y + stream->data.yuv422p.length_y;
+               stream->data.yuv422p.length_u = stream->data.yuv422p.length_y >> 1;
+               stream->data.yuv422p.v = stream->data.yuv422p.u + stream->data.yuv422p.length_u;
+               stream->data.yuv422p.length_v = stream->data.yuv422p.length_u;
+               stream->stride[0] = stream->width;
+               stream->elevation[0] = stream->height;
+               stream->stride[1] = stream->stride[2] = stream->width;
+               stream->elevation[1] = stream->elevation[2] = stream->height >> 1;
+               stream->num_planes = 3;
+               break;
+
+       case MM_PIXEL_FORMAT_YUYV: /* fall through */
+       case MM_PIXEL_FORMAT_UYVY: /* fall through */
+       case MM_PIXEL_FORMAT_ITLV_JPEG_UYVY:
+               stream->data_type = MM_CAM_STREAM_DATA_YUV422;
+               stream->data.yuv422.yuv = map_info->data;
+               stream->data.yuv422.length_yuv = stream->length_total;
+               stream->stride[0] = stream->width << 1;
+               stream->elevation[0] = stream->height;
+               stream->num_planes = 1;
+               break;
+
+       case MM_PIXEL_FORMAT_ENCODED_H264:  /* fall through */
+       case MM_PIXEL_FORMAT_ENCODED_MJPEG: /* fall through */
+       case MM_PIXEL_FORMAT_ENCODED_VP8:   /* fall through */
+       case MM_PIXEL_FORMAT_ENCODED_VP9:   /* fall through */
+               stream->data_type = MM_CAM_STREAM_DATA_ENCODED;
+               stream->data.encoded.data = map_info->data;
+               stream->data.encoded.length_data = stream->length_total;
+               stream->data.encoded.is_delta_frame = GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT);
+               stream->num_planes = 1;
+               break;
+
+       case MM_PIXEL_FORMAT_INVZ:
+               stream->data_type = MM_CAM_STREAM_DATA_DEPTH;
+               stream->data.depth.data = map_info->data;
+               stream->data.depth.length_data = stream->length_total;
+               stream->stride[0] = stream->width << 1;
+               stream->elevation[0] = stream->height;
+               stream->num_planes = 1;
+               break;
+
+       case MM_PIXEL_FORMAT_RGBA: /* fall through */
+       case MM_PIXEL_FORMAT_ARGB:
+               stream->data_type = MM_CAM_STREAM_DATA_RGB;
+               stream->data.rgb.data = map_info->data;
+               stream->data.rgb.length_data = stream->length_total;
+               stream->stride[0] = stream->width << 2;
+               stream->elevation[0] = stream->height;
+               stream->num_planes = 1;
+               break;
+
+       default:
+               MMCAM_LOG_ERROR("unsupported format[%d]", stream->format);
+               ret = FALSE;
+               break;
+       }
+
+       return ret;
+}
+
+
+static gboolean __mmcamcorder_set_stream_data_zero_copy(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMemory *memory)
+{
+       int i = 0;
+       int num_bos = 0;
+       int tbm_ret = TBM_SURFACE_ERROR_NONE;
+       tbm_bo_handle bo_handle = {NULL, };
+       tbm_surface_info_s ts_info;
+
+       mmf_return_val_if_fail(stream, FALSE);
+       mmf_return_val_if_fail(buffer, FALSE);
+       mmf_return_val_if_fail(memory, FALSE);
+
+       if (_mmcamcorder_is_encoded_preview_pixel_format(stream->format)) {
+               stream->bo[0] = gst_tizen_memory_get_bos(memory, 0);
+
+               bo_handle = tbm_bo_get_handle(stream->bo[0], TBM_DEVICE_CPU);
+               if (!bo_handle.ptr) {
+                       MMCAM_LOG_ERROR("tbm_bo_get_handle failed[bo:%p,memory:%p]", stream->bo[0], memory);
+                       return FALSE;
+               }
+
+               stream->data_type = MM_CAM_STREAM_DATA_ENCODED;
+               stream->num_planes = 1;
+               stream->stride[0] = stream->width;
+               stream->elevation[0] = stream->height;
+               stream->data.encoded.data = bo_handle.ptr;
+               stream->length_total = gst_memory_get_sizes(memory, NULL, NULL);
+               stream->data.encoded.length_data = stream->length_total;
+               stream->data.encoded.is_delta_frame = GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT);
+
+               MMCAM_LOG_VERBOSE("[ENCODED] length[%u], is_delta[%d]",
+                       stream->data.encoded.length_data, stream->data.encoded.is_delta_frame);
+
+               return TRUE;
+       }
+
+       memset(&ts_info, 0x0, sizeof(tbm_surface_info_s));
+
+       tbm_ret = tbm_surface_get_info((tbm_surface_h)gst_tizen_memory_get_surface(memory), &ts_info);
+       if (tbm_ret != TBM_SURFACE_ERROR_NONE) {
+               MMCAM_LOG_ERROR("get tbm surface info failed[0x%x]", tbm_ret);
+               return FALSE;
+       }
+
+       stream->length_total = ts_info.size;
+       for (i = 0 ; i < ts_info.num_planes ; i++) {
+               stream->stride[i] = ts_info.planes[i].stride;
+               stream->elevation[i] = ts_info.planes[i].size / ts_info.planes[i].stride;
+               MMCAM_LOG_VERBOSE("    plane[%d] %dx%d", i, stream->stride[i], stream->elevation[i]);
+       }
+
+       num_bos = gst_tizen_memory_get_num_bos(memory);
+       for (i = 0 ; i < num_bos ; i++)
+               stream->bo[i] = gst_tizen_memory_get_bos(memory, i);
+
+
+       switch (stream->format) {
+       case MM_PIXEL_FORMAT_NV12: /* fall through */
+       case MM_PIXEL_FORMAT_NV21:
+               stream->data_type = MM_CAM_STREAM_DATA_YUV420SP;
+               stream->num_planes = 2;
+               stream->data.yuv420sp.y = ts_info.planes[0].ptr;
+               stream->data.yuv420sp.length_y = ts_info.planes[0].size;
+               stream->data.yuv420sp.uv = ts_info.planes[1].ptr;
+               stream->data.yuv420sp.length_uv = ts_info.planes[1].size;
+
+               MMCAM_LOG_VERBOSE("[420SP] 0[%p,%u], 1[%p,%u]",
+                       stream->data.yuv420sp.y, stream->data.yuv420sp.length_y,
+                       stream->data.yuv420sp.uv, stream->data.yuv420sp.length_uv);
+               break;
+
+       case MM_PIXEL_FORMAT_I420:
+               stream->data_type = MM_CAM_STREAM_DATA_YUV420P;
+               stream->num_planes = 3;
+               stream->data.yuv420p.y = ts_info.planes[0].ptr;
+               stream->data.yuv420p.length_y = ts_info.planes[0].size;
+               stream->data.yuv420p.u = ts_info.planes[1].ptr;
+               stream->data.yuv420p.length_u = ts_info.planes[1].size;
+               stream->data.yuv420p.v = ts_info.planes[2].ptr;
+               stream->data.yuv420p.length_v = ts_info.planes[2].size;
+
+               MMCAM_LOG_VERBOSE("[I420] 0[%p,%u], 1[%p,%u], 2[%p,%u]",
+                       stream->data.yuv420p.y, stream->data.yuv420p.length_y,
+                       stream->data.yuv420p.u, stream->data.yuv420p.length_u,
+                       stream->data.yuv420p.v, stream->data.yuv420p.length_v);
+               break;
+
+       case MM_PIXEL_FORMAT_YUYV:
+               stream->data_type = MM_CAM_STREAM_DATA_YUV422;
+               stream->num_planes = 1;
+               stream->data.yuv422.yuv = ts_info.planes[0].ptr;
+               stream->data.yuv422.length_yuv = ts_info.planes[0].size;
+
+               MMCAM_LOG_VERBOSE("[YUYV] 0[%p,%u]",
+                       stream->data.yuv422.yuv, stream->data.yuv422.length_yuv);
+               break;
+
+       default:
+               MMCAM_LOG_ERROR("unsupported format[%d]", stream->format);
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
+
+static const char *__mmcamcorder_get_parser_name(MMPixelFormatType format)
+{
+       switch (format) {
+       case MM_PIXEL_FORMAT_ENCODED_H264:
+               return "h264parse";
+       case MM_PIXEL_FORMAT_ENCODED_VP9:
+               return "vp9parse";
+       default:
+               MMCAM_LOG_WARNING("unsupported format[%d]", format);
+               return NULL;
+       }
+}
+
+
+static void __mmcamcorder_request_codec_config(GstElement *videosrc_element)
+{
+       if (!videosrc_element || !G_TYPE_CHECK_INSTANCE(videosrc_element)) {
+               MMCAM_LOG_WARNING("invalid videosrc element[%p]", videosrc_element);
+               return;
+       }
+
+       if (!g_signal_parse_name(_MMCAMCORDER_SIGNAL_REQUEST_CODEC_CONFIG,
+                       G_TYPE_FROM_INSTANCE(videosrc_element), NULL, NULL, FALSE)) {
+               MMCAM_LOG_WARNING("no signal[%s]", _MMCAMCORDER_SIGNAL_REQUEST_CODEC_CONFIG);
+               return;
+       }
+
+       MMCAM_LOG_INFO("emit signal[%s]", _MMCAMCORDER_SIGNAL_REQUEST_CODEC_CONFIG);
+
+       g_signal_emit_by_name(videosrc_element, _MMCAMCORDER_SIGNAL_REQUEST_CODEC_CONFIG);
+}
+
+
+gboolean _mmcamcorder_invoke_video_stream_cb(MMHandleType handle, GstSample *sample, gboolean is_preview, int stream_id)
+{
+       int i = 0;
+       gboolean ret_cb = TRUE;
+       mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
+       _MMCamcorderSubContext *sc = NULL;
+       MMCamcorderVideoStreamDataType stream;
+
+       GstBuffer *buffer = NULL;
+       GstMemory *memory = NULL;
+       GstMapInfo map_info;
+       GstCaps *caps = NULL;
+       GstStructure *structure = NULL;
+
+       mmf_return_val_if_fail(hcamcorder, FALSE);
+
+       buffer = gst_sample_get_buffer(sample);
+       mmf_return_val_if_fail(buffer, FALSE);
+       mmf_return_val_if_fail(gst_buffer_n_memory(buffer), FALSE);
+
+       sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
+       mmf_return_val_if_fail(sc, FALSE);
+
+       memset(&stream, 0x0, sizeof(MMCamcorderVideoStreamDataType));
+
+       caps = gst_sample_get_caps(sample);
+       mmf_return_val_if_fail(caps, FALSE);
+
+       structure = gst_caps_get_structure(caps, 0);
+       mmf_return_val_if_fail(structure, FALSE);
+
+       stream.format = _mmcamcorder_get_pixel_format(caps, TRUE);
+       gst_structure_get(structure,
+               "width", G_TYPE_INT, &stream.width,
+               "height", G_TYPE_INT, &stream.height,
+               NULL);
+
+       memory = gst_buffer_peek_memory(buffer, 0);
+       if (!memory) {
+               MMCAM_LOG_ERROR("GstMemory get failed from buffer %p", buffer);
+               return FALSE;
+       }
+
+       structure = gst_mini_object_get_qdata(GST_MINI_OBJECT_CAST(buffer), hcamcorder->buffer_quark);
+       if (structure && gst_structure_has_field(structure, "focus-state")) {
+               gst_structure_get(structure,
+                       "focus-state", G_TYPE_INT, &stream.focus_state,
+                       "facing-direction", G_TYPE_INT, &stream.facing_direction,
+                       "flip", G_TYPE_INT, &stream.flip,
+                       "rotation", G_TYPE_INT, &stream.rotation,
+                       NULL);
+
+               MMCAM_LOG_VERBOSE("structure[%p], [fs:%d,fd:%d,f:%d,r:%d]", structure,
+                       stream.focus_state, stream.facing_direction, stream.flip, stream.rotation);
+       }
+
+       if (gst_is_tizen_memory(memory)) {
+               if (!__mmcamcorder_set_stream_data_zero_copy(&stream, buffer, memory))
+                       goto _INVOKE_VIDEO_STREAM_CB_DONE;
+       } else {
+               memset(&map_info, 0x0, sizeof(GstMapInfo));
+
+               if (!gst_memory_map(memory, &map_info, GST_MAP_READWRITE)) {
+                       MMCAM_LOG_ERROR("map failed for memory[%p]", memory);
+                       return FALSE;
+               }
+
+               if (!__mmcamcorder_set_stream_data(&stream, buffer, &map_info))
+                       goto _INVOKE_VIDEO_STREAM_CB_DONE;
+       }
+
+       MMCAM_LOG_DEBUG("VideoStreamData : format[%d], resolution[%dx%d], stream_id[%d]",
+               stream.format, stream.width, stream.height, stream_id);
+
+       stream.timestamp = (unsigned int)(GST_BUFFER_PTS(buffer) / 1000000); /* nano sec -> milli sec */
+       stream.extra_stream_id = stream_id;
+       stream.internal_buffer = buffer;
+
+       /* invoke application callback */
+       if (is_preview) {
+               _MMCAMCORDER_LOCK_VSTREAM_CALLBACK(hcamcorder);
+               if (hcamcorder->vstream_cb)
+                       hcamcorder->vstream_cb(&stream, hcamcorder->vstream_cb_param);
+               _MMCAMCORDER_UNLOCK_VSTREAM_CALLBACK(hcamcorder);
+       } else {
+               _MMCAMCORDER_LOCK_VEDECISION_CALLBACK(hcamcorder);
+               if (hcamcorder->vedecision_cb)
+                       ret_cb = hcamcorder->vedecision_cb(&stream, hcamcorder->vedecision_cb_param);
+               _MMCAMCORDER_UNLOCK_VEDECISION_CALLBACK(hcamcorder);
+       }
+
+_INVOKE_VIDEO_STREAM_CB_DONE:
+       if (!gst_is_tizen_memory(memory))
+               gst_memory_unmap(memory, &map_info);
+
+       for (i = 0 ; i < TBM_SURF_PLANE_MAX && stream.bo[i] ; i++) {
+               tbm_bo_map(stream.bo[i], TBM_DEVICE_CPU, TBM_OPTION_READ|TBM_OPTION_WRITE);
+               tbm_bo_unmap(stream.bo[i]);
+       }
+
+       return ret_cb;
+}
+
+
 int _mmcamcorder_create_preview_elements(MMHandleType handle)
 {
        int err = MM_ERROR_NONE;
        int i = 0;
-       int camera_width = 0;
-       int camera_height = 0;
        int camera_rotate = 0;
        int camera_flip = 0;
        int fps = 0;
        int codectype = 0;
        int capture_width = 0;
        int capture_height = 0;
-       int capture_jpg_quality = 100;
+       int capture_quality = 0;
        int video_stabilization = 0;
        int anti_shake = 0;
        int display_surface_type = MM_DISPLAY_SURFACE_NULL;
        const char *videosrc_name = NULL;
        const char *videosink_name = NULL;
        const char *videoconvert_name = NULL;
+       const char *videodecoder_name = NULL;
+       const char *videoparse_name = NULL;
+       const char *decoder_conf_name = NULL;
+       char videodecoder_name_final[32] = {'\0',};
        char *err_name = NULL;
-       char *socket_path = NULL;
-       int socket_path_len;
 #ifdef _MMCAMCORDER_RM_SUPPORT
        int decoder_index = 0;
-       char decoder_name[20] = {'\0',};
 #endif /* _MMCAMCORDER_RM_SUPPORT */
        GstElement *sink_element = NULL;
+       GstCameraControl *control = NULL;
        int sink_element_size = 0;
+       int *fds = NULL;
+       int fd_number = 0;
+       int extra_preview_enable = 0;
 
        GList *element_list = NULL;
 
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
        _MMCamcorderSubContext *sc = NULL;
-       type_element *VideosrcElement = NULL;
+       type_element *videosrc_element = NULL;
        type_int_array *input_index = NULL;
 
        mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
@@ -203,7 +556,7 @@ int _mmcamcorder_create_preview_elements(MMHandleType handle)
        mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
        mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
 
-       _mmcam_dbg_log("");
+       MMCAM_LOG_INFO("");
 
        /* Check existence */
        for (i = _MMCAMCORDER_VIDEOSRC_SRC ; i <= _MMCAMCORDER_VIDEOSINK_SINK ; i++) {
@@ -211,7 +564,7 @@ int _mmcamcorder_create_preview_elements(MMHandleType handle)
                        if (((GObject *)sc->element[i].gst)->ref_count > 0)
                                gst_object_unref(sc->element[i].gst);
 
-                       _mmcam_dbg_log("element[index:%d] is Already existed.", i);
+                       MMCAM_LOG_INFO("element[index:%d] is Already existed.", i);
                }
        }
 
@@ -221,13 +574,11 @@ int _mmcamcorder_create_preview_elements(MMHandleType handle)
                                                                                  "InputIndex",
                                                                                  &input_index);
        if (input_index == NULL) {
-               _mmcam_dbg_err("Failed to get input_index");
+               MMCAM_LOG_ERROR("Failed to get input_index");
                return MM_ERROR_CAMCORDER_CREATE_CONFIGURE;
        }
 
        err = mm_camcorder_get_attributes(handle, &err_name,
-               MMCAM_CAMERA_WIDTH, &camera_width,
-               MMCAM_CAMERA_HEIGHT, &camera_height,
                MMCAM_CAMERA_FORMAT, &sc->info_image->preview_format,
                MMCAM_CAMERA_FPS, &fps,
                MMCAM_CAMERA_ROTATION, &camera_rotate,
@@ -238,25 +589,37 @@ int _mmcamcorder_create_preview_elements(MMHandleType handle)
                MMCAM_CAPTURE_HEIGHT, &capture_height,
                MMCAM_CAMERA_HDR_CAPTURE, &sc->info_image->hdr_capture_mode,
                MMCAM_IMAGE_ENCODER, &codectype,
-               MMCAM_IMAGE_ENCODER_QUALITY, &capture_jpg_quality,
-               MMCAM_DISPLAY_SOCKET_PATH, &socket_path, &socket_path_len,
+               MMCAM_IMAGE_ENCODER_QUALITY, &capture_quality,
                MMCAM_DISPLAY_SURFACE, &display_surface_type,
+               MMCAM_EXTRA_PREVIEW_ENABLE, &extra_preview_enable,
                NULL);
        if (err != MM_ERROR_NONE) {
-               _mmcam_dbg_warn("Get attrs fail. (%s:%x)", err_name, err);
+               MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
                SAFE_FREE(err_name);
                return err;
        }
 
+       if (hcamcorder->support_user_buffer) {
+               err = mm_camcorder_get_attributes(handle, NULL,
+                       MMCAM_USER_BUFFER_FD, &fds, &fd_number,
+                       NULL);
+               if (err != MM_ERROR_NONE || fd_number < 1) {
+                       MMCAM_LOG_ERROR("get user buffer fd failed 0x%x, number %d", err, fd_number);
+                       return err;
+               }
+
+               /*
+               for (i = 0 ; i < fd_number ; i++)
+                       MMCAM_LOG_INFO("fds[%d] %d", i, fds[i]);
+               */
+       }
+
        /* Get fourcc from picture format */
        sc->fourcc = _mmcamcorder_get_fourcc(sc->info_image->preview_format, codectype, hcamcorder->use_zero_copy_format);
 
-       /* Get videosrc element and its name from configure */
-       _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
-               CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT,
-               "VideosrcElement",
-               &VideosrcElement);
-       _mmcamcorder_conf_get_value_element_name(VideosrcElement, &videosrc_name);
+       _mmcamcorder_conf_get_element_and_name((MMHandleType)hcamcorder,
+               CONFIGURE_CATEGORY_MAIN_VIDEO_INPUT, "VideosrcElement",
+               &videosrc_element, &videosrc_name);
 
        /**
         * Create child element
@@ -265,14 +628,21 @@ int _mmcamcorder_create_preview_elements(MMHandleType handle)
 
        _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_FILT, "capsfilter", "videosrc_filter", element_list, err);
 
-       /* init high-speed-fps */
-       MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "high-speed-fps", 0);
+       /**
+        * This is for "tizencamerasrc" element only.
+        * The camera HAL library will be loaded when "hal-name" property is set.
+        * The default HAL library (libtizen-camera.so) will be loaded if 'hal-name' property is set to NULL.
+        */
+       MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hal-name", hcamcorder->network_hal_name);
 
-       /* set capture size, quality and flip setting which were set before mm_camcorder_realize */
+       /* camera properties */
+       MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "high-speed-fps", 0);
        MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-width", capture_width);
        MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-height", capture_height);
-       MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-jpg-quality", capture_jpg_quality);
+       MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "capture-quality", capture_quality);
        MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hdr-capture", sc->info_image->hdr_capture_mode);
+       MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "extra-preview", extra_preview_enable);
+       MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "buffer-quark", &hcamcorder->buffer_quark);
 
        _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_QUE, "queue", "videosrc_queue", element_list, err);
 
@@ -288,141 +658,156 @@ int _mmcamcorder_create_preview_elements(MMHandleType handle)
        if (sc->is_modified_rate)
                MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "high-speed-fps", fps);
 
-       /* Set basic infomation of videosrc element */
-       _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, VideosrcElement);
+       /* Set basic information of videosrc element */
+       _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, videosrc_element);
 
        /* Set video device index */
-       MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "camera-id", input_index->default_value);
-
-       /* make demux and decoder for H264 stream from videosrc */
-       if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
-               int preview_bitrate = 0;
-               int gop_interval = 0;
-               const char *videodecoder_name = NULL;
+       if (hcamcorder->is_network) {
+               MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "camera-id", hcamcorder->device_type);
+       } else {
+#ifdef _MMCAMCORDER_CAMERA_CONF_MGR_SUPPORT
+               MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "device-name", hcamcorder->conf_device_info.node);
+#else
+               MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "camera-id", input_index->default_value);
+#endif
+       }
+
+       /* set user buffer fd to videosrc element */
+       if (hcamcorder->support_user_buffer) {
+               control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
+               if (!gst_camera_control_set_user_buffer_fd(control, fds, fd_number)) {
+                       MMCAM_LOG_ERROR("set user buffer fd failed");
+                       goto pipeline_creation_error;
+               }
+       }
 
+       if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
                /* get recreate_decoder flag */
                _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
                        CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
                        "RecreateDecoder",
                        &hcamcorder->recreate_decoder);
+       }
+
+       if (display_surface_type != MM_DISPLAY_SURFACE_NULL &&
+               _mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
+               switch (sc->info_image->preview_format) {
+               case MM_PIXEL_FORMAT_ENCODED_H264:
+                       decoder_conf_name = "VideodecoderElementH264";
+                       break;
+               case MM_PIXEL_FORMAT_ENCODED_MJPEG:
+                       decoder_conf_name = "VideodecoderElementMJPEG";
+                       break;
+               case MM_PIXEL_FORMAT_ENCODED_VP8:
+                       decoder_conf_name = "VideodecoderElementVP8";
+                       break;
+               case MM_PIXEL_FORMAT_ENCODED_VP9:
+                       decoder_conf_name = "VideodecoderElementVP9";
+                       break;
+               default:
+                       MMCAM_LOG_ERROR("invalid format[%d]", sc->info_image->preview_format);
+                       goto pipeline_creation_error;
+               }
 
-               /* get video decoder element and name for H.264 format */
+               /* get video decoder element and name */
                _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
                        CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
-                       "VideodecoderElementH264",
-                       &sc->VideodecoderElementH264);
+                       decoder_conf_name,
+                       &sc->VideodecoderElement);
 
-               _mmcamcorder_conf_get_value_element_name(sc->VideodecoderElementH264, &videodecoder_name);
+               _mmcamcorder_conf_get_value_element_name(sc->VideodecoderElement,
+                       &videodecoder_name);
+
+               if (!videodecoder_name) {
+                       MMCAM_LOG_ERROR("failed to get video decoder[%d,%s]", sc->info_image->preview_format, decoder_conf_name);
+                       goto pipeline_creation_error;
+               }
 
-               if (videodecoder_name) {
-                       _mmcam_dbg_log("video decoder element [%s], recreate decoder %d",
-                               videodecoder_name, hcamcorder->recreate_decoder);
 #ifdef _MMCAMCORDER_RM_SUPPORT
+               MMCAM_LOG_INFO("decoder name from config[%s]", videodecoder_name);
+               if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
                        if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER_SUB)
                                decoder_index = 1;
-
-                       snprintf(decoder_name, sizeof(decoder_name)-1, "%s%d", videodecoder_name, decoder_index);
-                       _mmcam_dbg_log("encoded preview decoder_name %s", decoder_name);
-                       /* create decoder element */
-                       _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_DECODE, decoder_name, "videosrc_decode", element_list, err);
-#else /* _MMCAMCORDER_RM_SUPPORT */
-                       /* create decoder element */
-                       _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_DECODE, videodecoder_name, "videosrc_decode", element_list, err);
-#endif /* _MMCAMCORDER_RM_SUPPORT */
-                       _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, sc->VideodecoderElementH264);
+                       snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s%d", videodecoder_name, decoder_index);
+               } else if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_MJPEG) {
+                       if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER)
+                               snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_uhd_mjpegdec");
+                       else
+                               snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_mjpegdec");
                } else {
-                       _mmcam_dbg_err("failed to get video decoder element name from %p", sc->VideodecoderElementH264);
-                       goto pipeline_creation_error;
+#endif /* _MMCAMCORDER_RM_SUPPORT */
+                       snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", videodecoder_name);
+#ifdef _MMCAMCORDER_RM_SUPPORT
                }
+#endif /* _MMCAMCORDER_RM_SUPPORT */
 
-               /* set encoded preview bitrate and iframe interval */
-               mm_camcorder_get_attributes(handle, NULL,
-                       MMCAM_ENCODED_PREVIEW_BITRATE, &preview_bitrate,
-                       MMCAM_ENCODED_PREVIEW_GOP_INTERVAL, &gop_interval,
-                       NULL);
+               videoparse_name = __mmcamcorder_get_parser_name(sc->info_image->preview_format);
+               if (videoparse_name)
+                       _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_PARSE, videoparse_name, "videosrc_parse", element_list, err);
 
-               if (!_mmcamcorder_set_encoded_preview_bitrate(handle, preview_bitrate))
-                       _mmcam_dbg_warn("_mmcamcorder_set_encoded_preview_bitrate failed");
+               _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_DECODE, videodecoder_name_final, "videosrc_decode", element_list, err);
 
-               if (!_mmcamcorder_set_encoded_preview_gop_interval(handle, gop_interval))
-                       _mmcam_dbg_warn("_mmcamcorder_set_encoded_preview_gop_interval failed");
+               _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, sc->VideodecoderElement);
        }
 
-       _mmcam_dbg_log("Current mode[%d]", hcamcorder->type);
+       MMCAM_LOG_INFO("Current mode[%d]", hcamcorder->type);
 
        /* Get videosink name */
        _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
 
        if (!videosink_name) {
-               _mmcam_dbg_err("failed to get videosink name");
+               MMCAM_LOG_ERROR("failed to get videosink name");
                goto pipeline_creation_error;
        }
 
        _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_QUE, "queue", "videosink_queue", element_list, err);
 
-       _mmcam_dbg_log("videosink_name: %s", videosink_name);
-
-       if (display_surface_type == MM_DISPLAY_SURFACE_REMOTE) {
-               _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, videosink_name, "ipc_sink", element_list, err);
-
-               _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, sc->VideosinkElement);
+       MMCAM_LOG_INFO("videosink_name: %s", videosink_name);
 
-               err = mm_camcorder_get_attributes(handle, &err_name,
-                       MMCAM_DISPLAY_SOCKET_PATH, &socket_path, &socket_path_len,
-                       NULL);
-               if (err != MM_ERROR_NONE) {
-                       _mmcam_dbg_warn("Get socket path failed 0x%x", err);
-                       SAFE_FREE(err_name);
-                       goto pipeline_creation_error;
-               }
+       if (hcamcorder->use_videoconvert && (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "directvideosink"))) {
+               /* get video convert name */
+               _mmcamcorder_conf_get_value_element_name(sc->VideoconvertElement, &videoconvert_name);
 
-               g_object_set(G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst), "socket-path", socket_path, NULL);
-       } else {
-               if (hcamcorder->use_videoconvert && (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "directvideosink"))) {
-                       /* get video convert name */
-                       _mmcamcorder_conf_get_value_element_name(sc->VideoconvertElement, &videoconvert_name);
-
-                       if (videoconvert_name) {
-                               _mmcam_dbg_log("videoconvert element name : %s", videoconvert_name);
-                               _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_CLS, videoconvert_name, "videosink_cls", element_list, err);
-                       } else
-                               _mmcam_dbg_err("failed to get videoconvert element name");
-               }
+               if (videoconvert_name) {
+                       MMCAM_LOG_INFO("videoconvert element name : %s", videoconvert_name);
+                       _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_CLS, videoconvert_name, "videosink_cls", element_list, err);
+               } else
+                       MMCAM_LOG_ERROR("failed to get videoconvert element name");
+       }
 
-               /* check sink element in attribute */
-               mm_camcorder_get_attributes(handle, NULL,
-                       MMCAM_DISPLAY_REUSE_ELEMENT, &sink_element, &sink_element_size,
-                       NULL);
+       /* check sink element in attribute */
+       mm_camcorder_get_attributes(handle, NULL,
+               MMCAM_DISPLAY_REUSE_ELEMENT, &sink_element, &sink_element_size,
+               NULL);
 
-               if (sink_element) {
-                       int attr_index = 0;
-                       MMHandleType attrs = MMF_CAMCORDER_ATTRS(handle);
+       if (sink_element) {
+               int attr_index = 0;
+               MMHandleType attrs = MMF_CAMCORDER_ATTRS(handle);
 
-                       _mmcam_dbg_log("reuse sink element %p in attribute", sink_element);
+               MMCAM_LOG_INFO("reuse sink element %p in attribute", sink_element);
 
-                       _MMCAMCORDER_ELEMENT_ADD(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, sink_element, element_list, err);
+               _MMCAMCORDER_ELEMENT_ADD(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, sink_element, element_list, err);
 
-                       /* reset attribute */
-                       if (attrs) {
-                               mm_attrs_get_index((MMHandleType)attrs, MMCAM_DISPLAY_REUSE_ELEMENT, &attr_index);
-                               mm_attrs_set_data(attrs, attr_index, NULL, 0);
-                               mm_attrs_commit(attrs, attr_index);
-                       } else {
-                               _mmcam_dbg_warn("attribute is NULL");
-                               err = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
-                               goto pipeline_creation_error;
-                       }
+               /* reset attribute */
+               if (attrs) {
+                       mm_attrs_get_index((MMHandleType)attrs, MMCAM_DISPLAY_REUSE_ELEMENT, &attr_index);
+                       mm_attrs_set_data(attrs, attr_index, NULL, 0);
+                       mm_attrs_commit(attrs, attr_index);
                } else {
-                       _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, videosink_name, "videosink_sink", element_list, err);
-
-                       _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, sc->VideosinkElement);
-               }
-
-               if (_mmcamcorder_videosink_window_set(handle, sc->VideosinkElement) != MM_ERROR_NONE) {
-                       _mmcam_dbg_err("_mmcamcorder_videosink_window_set error");
-                       err = MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
+                       MMCAM_LOG_WARNING("attribute is NULL");
+                       err = MM_ERROR_CAMCORDER_NOT_INITIALIZED;
                        goto pipeline_creation_error;
                }
+       } else {
+               _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSINK_SINK, videosink_name, "videosink_sink", element_list, err);
+
+               _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, sc->VideosinkElement);
+       }
+
+       if (_mmcamcorder_videosink_window_set(handle, sc->VideosinkElement) != MM_ERROR_NONE) {
+               MMCAM_LOG_ERROR("_mmcamcorder_videosink_window_set error");
+               err = MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
+               goto pipeline_creation_error;
        }
 
        /* Set caps by rotation */
@@ -430,14 +815,14 @@ int _mmcamcorder_create_preview_elements(MMHandleType handle)
 
        /* add elements to main pipeline */
        if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst), element_list)) {
-               _mmcam_dbg_err("element_list add error.");
+               MMCAM_LOG_ERROR("element_list add error.");
                err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
                goto pipeline_creation_error;
        }
 
        /* link elements */
        if (!_mmcamcorder_link_elements(element_list)) {
-               _mmcam_dbg_err("element link error.");
+               MMCAM_LOG_ERROR("element link error.");
                err = MM_ERROR_CAMCORDER_GST_LINK;
                goto pipeline_creation_error;
        }
@@ -452,10 +837,9 @@ int _mmcamcorder_create_preview_elements(MMHandleType handle)
 pipeline_creation_error:
        _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_SRC);
        _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_FILT);
-       _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CLS_QUE);
-       _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CLS);
-       _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CLS_FILT);
        _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_QUE);
+       _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CAP_FILT);
+       _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_CAP_SINK);
        _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSRC_DECODE);
        _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSINK_QUE);
        _MMCAMCORDER_ELEMENT_REMOVE(sc->element, _MMCAMCORDER_VIDEOSINK_SINK);
@@ -497,7 +881,7 @@ int _mmcamcorder_create_audiosrc_bin(MMHandleType handle)
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
        _MMCamcorderSubContext *sc = NULL;
        _MMCamcorderGstElement *last_element = NULL;
-       type_element *AudiosrcElement = NULL;
+       type_element *audiosrc_element = NULL;
 
        mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
 
@@ -505,7 +889,7 @@ int _mmcamcorder_create_audiosrc_bin(MMHandleType handle)
        mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
        mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
 
-       _mmcam_dbg_log("");
+       MMCAM_LOG_INFO("");
 
        err = _mmcamcorder_check_audiocodec_fileformat_compatibility(handle);
        if (err != MM_ERROR_NONE)
@@ -525,7 +909,7 @@ int _mmcamcorder_create_audiosrc_bin(MMHandleType handle)
                MMCAM_SOUND_STREAM_INDEX, &stream_index,
                NULL);
        if (err != MM_ERROR_NONE) {
-               _mmcam_dbg_warn("Get attrs fail. (%s:%x)", err_name, err);
+               MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
                SAFE_FREE(err_name);
                return err;
        }
@@ -535,7 +919,7 @@ int _mmcamcorder_create_audiosrc_bin(MMHandleType handle)
                if (((GObject *)sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst)->ref_count > 0)
                        gst_object_unref(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst);
 
-               _mmcam_dbg_log("_MMCAMCORDER_AUDIOSRC_BIN is Already existed. Unref once...");
+               MMCAM_LOG_INFO("_MMCAMCORDER_AUDIOSRC_BIN is Already existed. Unref once...");
        }
 
        /* Create bin element */
@@ -549,21 +933,19 @@ int _mmcamcorder_create_audiosrc_bin(MMHandleType handle)
        }
 
        if (cat_name == NULL) {
-               _mmcam_dbg_err("strdup failed.");
+               MMCAM_LOG_ERROR("strdup failed.");
                err = MM_ERROR_CAMCORDER_LOW_MEMORY;
                goto pipeline_creation_error;
        }
 
-       _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
-               CONFIGURE_CATEGORY_MAIN_AUDIO_INPUT,
-               cat_name,
-               &AudiosrcElement);
-       _mmcamcorder_conf_get_value_element_name(AudiosrcElement, &audiosrc_name);
+       _mmcamcorder_conf_get_element_and_name((MMHandleType)hcamcorder,
+               CONFIGURE_CATEGORY_MAIN_AUDIO_INPUT, cat_name,
+               &audiosrc_element, &audiosrc_name);
 
        free(cat_name);
        cat_name = NULL;
 
-       _mmcam_dbg_log("Audio src name : %s", audiosrc_name);
+       MMCAM_LOG_INFO("Audio src name : %s", audiosrc_name);
 
        _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_SRC, audiosrc_name, "audiosrc_src", element_list, err);
 
@@ -571,7 +953,7 @@ int _mmcamcorder_create_audiosrc_bin(MMHandleType handle)
        _mmcamcorder_set_sound_stream_info(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, stream_type, stream_index);
 
        /* set audiosrc properties in ini configuration */
-       _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, AudiosrcElement);
+       _mmcamcorder_conf_set_value_element_property(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, audiosrc_element);
 
        /* set block size */
        _mmcamcorder_conf_get_value_int((MMHandleType)hcamcorder, hcamcorder->conf_main,
@@ -580,7 +962,7 @@ int _mmcamcorder_create_audiosrc_bin(MMHandleType handle)
                &buffer_interval);
 
        if (_mmcamcorder_get_audiosrc_blocksize(rate, format, channel, buffer_interval, &blocksize)) {
-               _mmcam_dbg_log("set audiosrc block size %d", blocksize);
+               MMCAM_LOG_INFO("set audiosrc block size %d", blocksize);
                MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, "blocksize", blocksize);
        }
 
@@ -591,7 +973,7 @@ int _mmcamcorder_create_audiosrc_bin(MMHandleType handle)
        MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-bytes", 0);
        MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_QUE].gst, "max-size-time", 0);
 
-       /* Set basic infomation */
+       /* Set basic information */
        if (a_enc != MM_AUDIO_CODEC_VORBIS) {
                int depth = 0;
                const gchar* format_name = NULL;
@@ -619,7 +1001,7 @@ int _mmcamcorder_create_audiosrc_bin(MMHandleType handle)
                        "channels", G_TYPE_INT, channel,
                        "format", G_TYPE_STRING, format_name,
                        NULL);
-               _mmcam_dbg_log("caps [x-raw, rate:%d, channel:%d, depth:%d], volume %lf",
+               MMCAM_LOG_INFO("caps [x-raw, rate:%d, channel:%d, depth:%d], volume %lf",
                        rate, channel, depth, volume);
        } else {
                /* what are the audio encoder which should get audio/x-raw-float? */
@@ -628,12 +1010,12 @@ int _mmcamcorder_create_audiosrc_bin(MMHandleType handle)
                        "channels", G_TYPE_INT, channel,
                        "format", G_TYPE_STRING, GST_AUDIO_NE(F32),
                        NULL);
-               _mmcam_dbg_log("caps [x-raw (F32), rate:%d, channel:%d, endianness:%d, width:32]",
+               MMCAM_LOG_INFO("caps [x-raw (F32), rate:%d, channel:%d, endianness:%d, width:32]",
                        rate, channel, BYTE_ORDER);
        }
 
        /* Replay Gain */
-       _mmcam_dbg_log("Replay gain - enable : %d, reference level : %lf",
+       MMCAM_LOG_INFO("Replay gain - enable : %d, reference level : %lf",
                replay_gain_enable, replay_gain_ref_level);
 
        if (replay_gain_enable) {
@@ -648,19 +1030,19 @@ int _mmcamcorder_create_audiosrc_bin(MMHandleType handle)
                gst_caps_unref(caps);
                caps = NULL;
        } else {
-               _mmcam_dbg_err("create caps error");
+               MMCAM_LOG_ERROR("create caps error");
                err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
                goto pipeline_creation_error;
        }
 
        if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst), element_list)) {
-               _mmcam_dbg_err("element add error.");
+               MMCAM_LOG_ERROR("element add error.");
                err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
                goto pipeline_creation_error;
        }
 
        if (!_mmcamcorder_link_elements(element_list)) {
-               _mmcam_dbg_err("element link error.");
+               MMCAM_LOG_ERROR("element link error.");
                err = MM_ERROR_CAMCORDER_GST_LINK;
                goto pipeline_creation_error;
        }
@@ -670,7 +1052,7 @@ int _mmcamcorder_create_audiosrc_bin(MMHandleType handle)
        if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst, gst_ghost_pad_new("src", pad))) {
                gst_object_unref(pad);
                pad = NULL;
-               _mmcam_dbg_err("failed to create ghost pad on _MMCAMCORDER_AUDIOSRC_BIN.");
+               MMCAM_LOG_ERROR("failed to create ghost pad on _MMCAMCORDER_AUDIOSRC_BIN.");
                err = MM_ERROR_CAMCORDER_GST_LINK;
                goto pipeline_creation_error;
        }
@@ -706,12 +1088,12 @@ void _mmcamcorder_set_encoder_bitrate(MMCamcorderEncoderType type, int codec, in
        int set_value = 0;
 
        if (!element) {
-               _mmcam_dbg_warn("NULL element, will be applied later - type %d, bitrate %d", type, bitrate);
+               MMCAM_LOG_WARNING("NULL element, will be applied later - type %d, bitrate %d", type, bitrate);
                return;
        }
 
        if (bitrate <= 0) {
-               _mmcam_dbg_warn("[type %d, codec %d] too small bitrate[%d], use default",
+               MMCAM_LOG_WARNING("[type %d, codec %d] too small bitrate[%d], use default",
                        type, codec, bitrate);
                return;
        }
@@ -721,25 +1103,25 @@ void _mmcamcorder_set_encoder_bitrate(MMCamcorderEncoderType type, int codec, in
                switch (codec) {
                case MM_AUDIO_CODEC_AMR:
                        set_value = __mmcamcorder_get_amrnb_bitrate_mode(bitrate);
-                       _mmcam_dbg_log("Set AMR encoder mode [%d]", set_value);
+                       MMCAM_LOG_INFO("Set AMR encoder mode [%d]", set_value);
                        MMCAMCORDER_G_OBJECT_SET(element, "band-mode", set_value);
                        break;
                case MM_AUDIO_CODEC_MP3:
                        set_value = bitrate / 1000;
-                       _mmcam_dbg_log("Set MP3 encoder bitrate [%d] kbps", set_value);
+                       MMCAM_LOG_INFO("Set MP3 encoder bitrate [%d] kbps", set_value);
                        MMCAMCORDER_G_OBJECT_SET(element, "bitrate", set_value);
                        break;
                case MM_AUDIO_CODEC_AAC:
-                       _mmcam_dbg_log("Set AAC encoder bitrate [%d] bps", bitrate);
+                       MMCAM_LOG_INFO("Set AAC encoder bitrate [%d] bps", bitrate);
                        MMCAMCORDER_G_OBJECT_SET(element, "bitrate", bitrate);
                        break;
                default:
-                       _mmcam_dbg_warn("Not AMR, MP3 and AAC codec, need to add code for audio bitrate");
+                       MMCAM_LOG_WARNING("Not AMR, MP3 and AAC codec, need to add code for audio bitrate");
                        break;
                }
        } else {
                /* video encoder bitrate setting */
-               _mmcam_dbg_log("Set video encoder bitrate %d", bitrate);
+               MMCAM_LOG_INFO("Set video encoder bitrate %d", bitrate);
                MMCAMCORDER_G_OBJECT_SET(element, "bitrate", bitrate);
        }
 
@@ -764,6 +1146,7 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin
        const char *gst_element_ienc_name = NULL;
        const char *gst_element_mux_name = NULL;
        const char *gst_element_rsink_name = NULL;
+       const char *gst_element_vscale_name = NULL;
        const char *str_profile = NULL;
        const char *str_aac = NULL;
        const char *str_aar = NULL;
@@ -772,6 +1155,7 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin
        const char *videoconvert_name = NULL;
        GstCaps *audio_caps = NULL;
        GstCaps *video_caps = NULL;
+       GstCaps *videoscale_caps = NULL;
        GstPad *pad = NULL;
        GList *element_list = NULL;
 
@@ -782,6 +1166,7 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin
        type_element *ImageencElement = NULL;
        type_element *MuxElement = NULL;
        type_element *RecordsinkElement = NULL;
+       type_element *VideoscaleElement = NULL;
 
        mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
 
@@ -789,14 +1174,14 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin
        mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
        mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
 
-       _mmcam_dbg_log("start - profile : %d", profile);
+       MMCAM_LOG_INFO("start - profile : %d", profile);
 
        /* Check existence */
        if (sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst) {
                if (((GObject *)sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst)->ref_count > 0)
                        gst_object_unref(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst);
 
-               _mmcam_dbg_log("_MMCAMCORDER_ENCSINK_BIN is Already existed.");
+               MMCAM_LOG_INFO("_MMCAMCORDER_ENCSINK_BIN is Already existed.");
        }
 
        /* Create bin element */
@@ -805,18 +1190,13 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin
        /* Create child element */
        if (profile != MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
                GstCaps *caps_from_pad = NULL;
+               char *caps_str = NULL;
 
                /* create appsrc and capsfilter */
                _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_SRC, "appsrc", "encodesink_src", element_list, err);
 
                _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_FILT, "capsfilter", "encodesink_filter", element_list, err);
 
-               /* release element_list, they will be placed out of encodesink bin */
-               if (element_list) {
-                       g_list_free(element_list);
-                       element_list = NULL;
-               }
-
                /* set appsrc as live source */
                MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "is-live", TRUE);
                MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "format", 3); /* GST_FORMAT_TIME */
@@ -824,15 +1204,15 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin
 
                /* set capsfilter */
                if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
-                       if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
-                               _mmcam_dbg_log("get pad from videosrc_filter");
+                       if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
+                               MMCAM_LOG_INFO("get pad from videosrc_filter");
                                pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "src");
                        } else {
-                               _mmcam_dbg_log("get pad from videosrc_que");
+                               MMCAM_LOG_INFO("get pad from videosrc_que");
                                pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
                        }
                        if (!pad) {
-                               _mmcam_dbg_err("get videosrc_que src pad failed");
+                               MMCAM_LOG_ERROR("get videosrc_que src pad failed");
                                err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
                                goto pipeline_creation_error;
                        }
@@ -851,28 +1231,84 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin
                        MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", &video_caps);
                }
 
-               if (video_caps) {
-                       char *caps_str = NULL;
+               if (!video_caps) {
+                       MMCAM_LOG_ERROR("create recording pipeline caps failed");
+                       err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
+                       goto pipeline_creation_error;
+               }
 
-                       if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
+               if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
+                       if (sc->info_video->use_videoscale) {
+                               gst_caps_set_simple(video_caps,
+                                       "width", G_TYPE_INT, sc->info_video->preview_width,
+                                       "height", G_TYPE_INT, sc->info_video->preview_height,
+                                       NULL);
+                               videoscale_caps = gst_caps_copy(video_caps);
+                       } else {
                                gst_caps_set_simple(video_caps,
                                        "width", G_TYPE_INT, sc->info_video->video_width,
                                        "height", G_TYPE_INT, sc->info_video->video_height,
                                        NULL);
                        }
+               }
+
+               caps_str = gst_caps_to_string(video_caps);
+
+               MMCAM_LOG_INFO("encodebin caps [%s]", caps_str);
+
+               g_free(caps_str);
+               caps_str = NULL;
+
+               MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_FILT].gst, "caps", video_caps);
+
+               gst_caps_unref(video_caps);
+               video_caps = NULL;
+
+               /* video scale */
+               if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO &&
+                       sc->info_video->use_videoscale) {
+                       if (!videoscale_caps) {
+                               MMCAM_LOG_ERROR("no videoscale caps");
+                               err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
+                               goto pipeline_creation_error;
+                       }
+
+                       gst_caps_set_simple(videoscale_caps,
+                               "width", G_TYPE_INT, sc->info_video->video_width,
+                               "height", G_TYPE_INT, sc->info_video->video_height,
+                               NULL);
+
+                       _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
+                               CONFIGURE_CATEGORY_MAIN_RECORD,
+                               "VideoscaleElement",
+                               &VideoscaleElement);
+
+                       if (!_mmcamcorder_conf_get_value_element_name(VideoscaleElement, &gst_element_vscale_name)) {
+                               MMCAM_LOG_ERROR("failed to get videoscale element name");
+                               err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
+                               goto pipeline_creation_error;
+                       }
+
+                       caps_str = gst_caps_to_string(videoscale_caps);
+
+                       MMCAM_LOG_INFO("encodebin videocale [%s][%s]", gst_element_vscale_name, caps_str);
 
-                       caps_str = gst_caps_to_string(video_caps);
-                       _mmcam_dbg_log("encodebin caps [%s]", caps_str);
                        g_free(caps_str);
                        caps_str = NULL;
 
-                       MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_FILT].gst, "caps", video_caps);
-                       gst_caps_unref(video_caps);
-                       video_caps = NULL;
-               } else {
-                       _mmcam_dbg_err("create recording pipeline caps failed");
-                       err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
-                       goto pipeline_creation_error;
+                       _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE, gst_element_vscale_name, "encodesink_vscale", element_list, err);
+                       _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE_FILT, "capsfilter", "encodesink_vscale_filter", element_list, err);
+
+                       MMCAMCORDER_G_OBJECT_SET_POINTER((sc->encode_element[_MMCAMCORDER_ENCSINK_VSCALE_FILT].gst), "caps", videoscale_caps);
+
+                       gst_caps_unref(videoscale_caps);
+                       videoscale_caps = NULL;
+               }
+
+               /* release element_list, they will be placed out of encodesink bin */
+               if (element_list) {
+                       g_list_free(element_list);
+                       element_list = NULL;
                }
 
                /* connect signal for ready to push buffer */
@@ -883,7 +1319,8 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin
                        hcamcorder);
        }
 
-       _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_ENCBIN, "encodebin", "encodesink_encbin", element_list, err);
+       _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_ENCBIN,
+               "tizenencodebin", "encodesink_encbin", element_list, err);
 
        /* check element availability */
        if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
@@ -901,16 +1338,16 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin
 
        if (err != MM_ERROR_NONE) {
                if (err_name) {
-                       _mmcam_dbg_err("failed to get attributes [%s][0x%x]", err_name, err);
+                       MMCAM_LOG_ERROR("failed to get attributes [%s][0x%x]", err_name, err);
                        SAFE_FREE(err_name);
                } else {
-                       _mmcam_dbg_err("failed to get attributes [0x%x]", err);
+                       MMCAM_LOG_ERROR("failed to get attributes [0x%x]", err);
                }
 
                goto pipeline_creation_error;
        }
 
-       _mmcam_dbg_log("Profile[%d]", profile);
+       MMCAM_LOG_INFO("Profile[%d]", profile);
 
        /* Set information */
        if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
@@ -935,7 +1372,7 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin
        _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_aar, &auto_audio_resample);
        _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, CONFIGURE_CATEGORY_MAIN_RECORD, str_acs, &auto_color_space);
 
-       _mmcam_dbg_log("Profile:%d, AutoAudioConvert:%d, AutoAudioResample:%d, AutoColorSpace:%d",
+       MMCAM_LOG_INFO("Profile:%d, AutoAudioConvert:%d, AutoAudioResample:%d, AutoColorSpace:%d",
                encodebin_profile, auto_audio_convert, auto_audio_resample, auto_color_space);
 
        MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "profile", encodebin_profile);
@@ -954,32 +1391,34 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin
                VideoencElement = _mmcamcorder_get_type_element(handle, MM_CAM_VIDEO_ENCODER);
 
                if (!VideoencElement) {
-                       _mmcam_dbg_err("Fail to get type element");
+                       MMCAM_LOG_ERROR("Fail to get type element");
                        err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
                        goto pipeline_creation_error;
                }
 
-               if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
-                       /* set dummy element */
-                       gst_element_venc_name = "identity";
+               if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
+                       /* set parse element */
+                       gst_element_venc_name = __mmcamcorder_get_parser_name(sc->info_image->preview_format);
+                       if (!gst_element_venc_name)
+                               gst_element_venc_name = "identity";
                } else {
                        _mmcamcorder_conf_get_value_element_name(VideoencElement, &gst_element_venc_name);
                }
 
                if (gst_element_venc_name) {
-                       _mmcam_dbg_log("video encoder name [%s]", gst_element_venc_name);
+                       MMCAM_LOG_INFO("video encoder name [%s]", gst_element_venc_name);
 
                        MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "venc-name", gst_element_venc_name);
                        _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VENC, "video-encode", err);
                } else {
-                       _mmcam_dbg_err("Fail to get video encoder name");
+                       MMCAM_LOG_ERROR("Fail to get video encoder name");
                        err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
                        goto pipeline_creation_error;
                }
 
                /* set color space converting element */
                if (auto_color_space) {
-                       _mmcam_dbg_log("set video convert element [%s]", videoconvert_name);
+                       MMCAM_LOG_INFO("set video convert element [%s]", videoconvert_name);
 
                        MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "vconv-name", videoconvert_name);
                        _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_VCONV, "video-convert", err);
@@ -999,10 +1438,10 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin
                                                gst_caps_unref(video_caps);
                                                video_caps = NULL;
                                        } else {
-                                               _mmcam_dbg_warn("failed to create caps");
+                                               MMCAM_LOG_WARNING("failed to create caps");
                                        }
                                } else {
-                                       _mmcam_dbg_log("current video codec is not openmax but [%s]", gst_element_venc_name);
+                                       MMCAM_LOG_INFO("current video codec is not openmax but [%s]", gst_element_venc_name);
                                }
                        }
                }
@@ -1021,7 +1460,7 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin
 
                AudioencElement = _mmcamcorder_get_type_element(handle, MM_CAM_AUDIO_ENCODER);
                if (!AudioencElement) {
-                       _mmcam_dbg_err("Fail to get type element");
+                       MMCAM_LOG_ERROR("Fail to get type element");
                        err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
                        goto pipeline_creation_error;
                }
@@ -1047,7 +1486,7 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin
                        MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "acaps", audio_caps);
                        gst_caps_unref(audio_caps);
                        audio_caps = NULL;
-                       _mmcam_dbg_log("***** MM_AUDIO_CODEC_OGG : setting audio/x-raw-int ");
+                       MMCAM_LOG_INFO("***** MM_AUDIO_CODEC_OGG : setting audio/x-raw-int ");
                }
 
                _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main,
@@ -1065,7 +1504,7 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin
                if (cap_format == MM_PIXEL_FORMAT_ENCODED) {
                        ImageencElement = _mmcamcorder_get_type_element(handle, MM_CAM_IMAGE_ENCODER);
                        if (!ImageencElement) {
-                               _mmcam_dbg_err("Fail to get type element");
+                               MMCAM_LOG_ERROR("Fail to get type element");
                                err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
                                goto pipeline_creation_error;
                        }
@@ -1084,7 +1523,7 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin
        if (profile != MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) {
                MuxElement = _mmcamcorder_get_type_element(handle, MM_CAM_FILE_FORMAT);
                if (!MuxElement) {
-                       _mmcam_dbg_err("Fail to get type element");
+                       MMCAM_LOG_ERROR("Fail to get type element");
                        err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
                        goto pipeline_creation_error;
                }
@@ -1133,23 +1572,23 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin
                        a_bitrate, sc->encode_element[_MMCAMCORDER_ENCSINK_AENC].gst);
        }
 
-       _mmcam_dbg_log("Element creation complete");
+       MMCAM_LOG_INFO("Element creation complete");
 
        /* Add element to bin */
        if (!_mmcamcorder_add_elements_to_bin(GST_BIN(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst), element_list)) {
-               _mmcam_dbg_err("element add error.");
+               MMCAM_LOG_ERROR("element add error.");
                err = MM_ERROR_CAMCORDER_RESOURCE_CREATION;
                goto pipeline_creation_error;
        }
 
-       _mmcam_dbg_log("Element add complete");
+       MMCAM_LOG_INFO("Element add complete");
 
        if (profile == MM_CAMCORDER_ENCBIN_PROFILE_VIDEO) {
-               pad = gst_element_get_request_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "video");
+               pad = gst_element_request_pad_simple(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "video");
                if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("video_sink0", pad))) {
                        gst_object_unref(pad);
                        pad = NULL;
-                       _mmcam_dbg_err("failed to create ghost video_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
+                       MMCAM_LOG_ERROR("failed to create ghost video_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
                        err = MM_ERROR_CAMCORDER_GST_LINK;
                        goto pipeline_creation_error;
                }
@@ -1157,11 +1596,11 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin
                pad = NULL;
 
                if (sc->audio_disable == FALSE) {
-                       pad = gst_element_get_request_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "audio");
+                       pad = gst_element_request_pad_simple(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "audio");
                        if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("audio_sink0", pad))) {
                                gst_object_unref(pad);
                                pad = NULL;
-                               _mmcam_dbg_err("failed to create ghost audio_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
+                               MMCAM_LOG_ERROR("failed to create ghost audio_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
                                err = MM_ERROR_CAMCORDER_GST_LINK;
                                goto pipeline_creation_error;
                        }
@@ -1169,11 +1608,11 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin
                        pad = NULL;
                }
        } else if (profile == MM_CAMCORDER_ENCBIN_PROFILE_AUDIO) {
-               pad = gst_element_get_request_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "audio");
+               pad = gst_element_request_pad_simple(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "audio");
                if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("audio_sink0", pad))) {
                        gst_object_unref(pad);
                        pad = NULL;
-                       _mmcam_dbg_err("failed to create ghost audio_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
+                       MMCAM_LOG_ERROR("failed to create ghost audio_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
                        err = MM_ERROR_CAMCORDER_GST_LINK;
                        goto pipeline_creation_error;
                }
@@ -1181,11 +1620,11 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin
                pad = NULL;
        } else {
                /* for stillshot */
-               pad = gst_element_get_request_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "image");
+               pad = gst_element_request_pad_simple(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "image");
                if (!gst_element_add_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, gst_ghost_pad_new("image_sink0", pad))) {
                        gst_object_unref(pad);
                        pad = NULL;
-                       _mmcam_dbg_err("failed to create ghost image_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
+                       MMCAM_LOG_ERROR("failed to create ghost image_sink0 on _MMCAMCORDER_ENCSINK_BIN.");
                        err = MM_ERROR_CAMCORDER_GST_LINK;
                        goto pipeline_creation_error;
                }
@@ -1193,21 +1632,19 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin
                pad = NULL;
        }
 
-       _mmcam_dbg_log("Get pad complete");
+       MMCAM_LOG_INFO("Get pad complete");
 
        /* Link internal element */
        if (!_mmcamcorder_link_elements(element_list)) {
-               _mmcam_dbg_err("element link error.");
+               MMCAM_LOG_ERROR("element link error.");
                err = MM_ERROR_CAMCORDER_GST_LINK;
                goto pipeline_creation_error;
        }
 
-       if (element_list) {
+       if (element_list)
                g_list_free(element_list);
-               element_list = NULL;
-       }
 
-       _mmcam_dbg_log("done");
+       MMCAM_LOG_INFO("done");
 
        return MM_ERROR_NONE;
 
@@ -1217,6 +1654,8 @@ pipeline_creation_error:
        _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_ENCBIN);
        _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_SRC);
        _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_FILT);
+       _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE);
+       _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_VSCALE_FILT);
        _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_VENC);
        _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_AENC);
        _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_IENC);
@@ -1224,10 +1663,11 @@ pipeline_creation_error:
        _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_SINK);
        _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCSINK_BIN);
 
-       if (element_list) {
+       if (element_list)
                g_list_free(element_list);
-               element_list = NULL;
-       }
+
+       if (videoscale_caps)
+               gst_caps_unref(videoscale_caps);
 
        return err;
 }
@@ -1249,7 +1689,7 @@ int _mmcamcorder_create_preview_pipeline(MMHandleType handle)
        mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
        mmf_return_val_if_fail(sc->element, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
 
-       _mmcam_dbg_log("");
+       MMCAM_LOG_INFO("");
 
        /** Create gstreamer element **/
        /* Main pipeline */
@@ -1262,10 +1702,10 @@ int _mmcamcorder_create_preview_pipeline(MMHandleType handle)
 
        /* Set data probe function */
        if (sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst) {
-               _mmcam_dbg_log("add video dataprobe to videosrc queue");
+               MMCAM_LOG_INFO("add video dataprobe to videosrc queue");
                srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
        } else {
-               _mmcam_dbg_err("there is no queue plugin");
+               MMCAM_LOG_ERROR("there is no queue plugin");
                goto pipeline_creation_error;
        }
 
@@ -1276,32 +1716,45 @@ int _mmcamcorder_create_preview_pipeline(MMHandleType handle)
                gst_object_unref(srcpad);
                srcpad = NULL;
        } else {
-               _mmcam_dbg_err("failed to get srcpad");
+               MMCAM_LOG_ERROR("failed to get srcpad");
                goto pipeline_creation_error;
        }
 
-       /* set dataprobe for video recording */
-       if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264)
-               srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
-       else
-               srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst, "src");
+       /* set dataprobe for video recording if it does not support dual stream. */
+       if (sc->info_video->record_dual_stream == FALSE) {
+               if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format))
+                       srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "src");
+               else
+                       srcpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst, "src");
 
-       MMCAMCORDER_ADD_BUFFER_PROBE(srcpad, _MMCAMCORDER_HANDLER_PREVIEW,
-               __mmcamcorder_video_dataprobe_push_buffer_to_record, hcamcorder);
-       gst_object_unref(srcpad);
-       srcpad = NULL;
+               MMCAMCORDER_ADD_BUFFER_PROBE(srcpad, _MMCAMCORDER_HANDLER_PREVIEW,
+                       __mmcamcorder_video_dataprobe_record, hcamcorder);
+               gst_object_unref(srcpad);
+               srcpad = NULL;
+       }
 
        bus = gst_pipeline_get_bus(GST_PIPELINE(sc->element[_MMCAMCORDER_MAIN_PIPE].gst));
 
-       /* Register pipeline message callback */
-       hcamcorder->pipeline_cb_event_id = gst_bus_add_watch(bus, _mmcamcorder_pipeline_cb_message, (gpointer)hcamcorder);
-
        /* set sync handler */
        gst_bus_set_sync_handler(bus, _mmcamcorder_pipeline_bus_sync_callback, (gpointer)hcamcorder, NULL);
 
        gst_object_unref(bus);
        bus = NULL;
 
+       /* capture mode */
+       err = _mmcamcorder_initialize_capture_mode(handle);
+       if (err != MM_ERROR_NONE) {
+               MMCAM_LOG_ERROR("initialize capture mode[%d] failed", hcamcorder->capture_mode);
+               goto pipeline_creation_error;
+       }
+
+       /* extra preview mode */
+       err = _mmcamcorder_initialize_extra_preview_mode(handle);
+       if (err != MM_ERROR_NONE) {
+               MMCAM_LOG_ERROR("initialize extra preview mode[%d] failed", hcamcorder->extra_preview.mode);
+               goto pipeline_creation_error;
+       }
+
        return MM_ERROR_NONE;
 
 pipeline_creation_error:
@@ -1315,7 +1768,7 @@ void _mmcamcorder_ready_to_encode_callback(GstElement *element, guint size, gpoi
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
        _MMCamcorderSubContext *sc = NULL;
 
-       /*_mmcam_dbg_log("start");*/
+       /*MMCAM_LOG_INFO("start");*/
 
        mmf_return_if_fail(hcamcorder);
        mmf_return_if_fail(hcamcorder->sub_context);
@@ -1323,9 +1776,9 @@ void _mmcamcorder_ready_to_encode_callback(GstElement *element, guint size, gpoi
 
        /* set flag */
        if (sc->info_video->push_encoding_buffer == PUSH_ENCODING_BUFFER_INIT) {
-               sc->info_video->get_first_I_frame = FALSE;
                sc->info_video->push_encoding_buffer = PUSH_ENCODING_BUFFER_RUN;
-               _mmcam_dbg_warn("set push_encoding_buffer RUN");
+               __mmcamcorder_request_codec_config(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
+               MMCAM_LOG_WARNING("start to push buffer to encoding pipeline");
        }
 }
 
@@ -1347,10 +1800,8 @@ int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* Videosi
        int zoom_attr = 0;
        int zoom_level = 0;
        int do_scaling = FALSE;
-#ifdef _MMCAMCORDER_RM_SUPPORT
-       int display_scaler = 0;
-#endif /* _MMCAMCORDER_RM_SUPPORT */
-       int *overlay = NULL;
+       int *dp_handle = NULL;
+       MMCamWindowInfo *window_info = NULL;
        gulong xid;
        char *err_name = NULL;
        const char *videosink_name = NULL;
@@ -1360,7 +1811,7 @@ int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* Videosi
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
        _MMCamcorderSubContext *sc = NULL;
 
-       _mmcam_dbg_log("");
+       MMCAM_LOG_INFO("");
 
        mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
 
@@ -1380,7 +1831,7 @@ int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* Videosi
                MMCAM_DISPLAY_ROTATION, &rotation,
                MMCAM_DISPLAY_FLIP, &flip,
                MMCAM_DISPLAY_VISIBLE, &visible,
-               MMCAM_DISPLAY_HANDLE, (void**)&overlay, &size,
+               MMCAM_DISPLAY_HANDLE, (void **)&dp_handle, &size,
                MMCAM_DISPLAY_MODE, &display_mode,
                MMCAM_DISPLAY_GEOMETRY_METHOD, &display_geometry_method,
                MMCAM_DISPLAY_SCALE, &zoom_attr,
@@ -1388,10 +1839,10 @@ int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* Videosi
                NULL);
        if (err != MM_ERROR_NONE) {
                if (err_name) {
-                       _mmcam_dbg_err("failed to get attributes [%s][0x%x]", err_name, err);
+                       MMCAM_LOG_ERROR("failed to get attributes [%s][0x%x]", err_name, err);
                        SAFE_FREE(err_name);
                } else {
-                       _mmcam_dbg_err("failed to get attributes [0x%x]", err);
+                       MMCAM_LOG_ERROR("failed to get attributes [0x%x]", err);
                }
 
                return err;
@@ -1400,51 +1851,68 @@ int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* Videosi
        _mmcamcorder_conf_get_value_element_name(VideosinkElement, &videosink_name);
 
        if (!videosink_name) {
-               _mmcam_dbg_err("failed to get videosink name");
+               MMCAM_LOG_ERROR("failed to get videosink name");
                return MM_ERROR_CAMCORDER_INTERNAL;
        }
 
-       _mmcam_dbg_log("(overlay=%p, size=%d)", overlay, size);
+       MMCAM_LOG_INFO("(dp_handle=%p, size=%d)", dp_handle, size);
 
        /* Set display handle */
-       if (!strcmp(videosink_name, "xvimagesink") ||
-           !strcmp(videosink_name, "ximagesink")) {
-               if (overlay) {
-                       xid = *overlay;
-                       _mmcam_dbg_log("xid = %lu )", xid);
+       if (!strcmp(videosink_name, "xvimagesink") || !strcmp(videosink_name, "ximagesink")) {
+               if (dp_handle) {
+                       xid = *dp_handle;
+                       MMCAM_LOG_INFO("xid = %lu )", xid);
                        gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), xid);
                } else {
-                       _mmcam_dbg_warn("Handle is NULL. Set xid as 0.. but, it's not recommended.");
+                       MMCAM_LOG_WARNING("Handle is NULL. Set xid as 0.. but, it's not recommended.");
                        gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), 0);
                }
-#ifdef _MMCAMCORDER_RM_SUPPORT
-               if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER_SUB)
-                       display_scaler = 1;
-
-               MMCAMCORDER_G_OBJECT_SET(vsink, "device-scaler", display_scaler);
-#endif /* _MMCAMCORDER_RM_SUPPORT */
        } else if (!strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink")) {
-               _mmcam_dbg_log("videosink : %s, handle : %p", videosink_name, overlay);
+               MMCAM_LOG_INFO("videosink : %s, handle : %p", videosink_name, dp_handle);
 
-               if (overlay) {
-                       MMCAMCORDER_G_OBJECT_SET_POINTER(vsink, "evas-object", overlay);
+               if (dp_handle) {
+                       MMCAMCORDER_G_OBJECT_SET_POINTER(vsink, "evas-object", dp_handle);
                        MMCAMCORDER_G_OBJECT_SET(vsink, "origin-size", !do_scaling);
                } else {
-                       _mmcam_dbg_err("display handle(eavs object) is NULL");
+                       MMCAM_LOG_ERROR("display handle(eavs object) is NULL");
                        return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
                }
-       } else if (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "directvideosink")) {
-               if (overlay) {
-                       _mmcam_dbg_log("wayland global surface id : %d", *(int *)(overlay));
-                       gst_video_overlay_set_wl_window_wl_surface_id(GST_VIDEO_OVERLAY(vsink), (guintptr)*(int *)(overlay));
+       } else if (!strcmp(videosink_name, "tizenwlsink")) {
+               if (dp_handle) {
+                       window_info = (MMCamWindowInfo *)dp_handle;
+                       MMCAM_LOG_INFO("wayland global surface id : %d", window_info->surface_id);
+                       gst_video_overlay_set_wl_window_wl_surface_id(GST_VIDEO_OVERLAY(vsink), window_info->surface_id);
+               } else {
+                       MMCAM_LOG_WARNING("Handle is NULL. skip setting.");
+               }
+       } else if (!strcmp(videosink_name, "directvideosink")) {
+#ifdef _MMCAMCORDER_RM_SUPPORT
+               /* set the videosink using the virtual device id instead of the real id (main=0, sub=1) */
+               MMCAM_LOG_INFO("device-scaler : %d", hcamcorder->returned_devices.device_id[1]);
+               MMCAMCORDER_G_OBJECT_SET(vsink, "device-scaler", hcamcorder->returned_devices.device_id[1]);
+#endif /* _MMCAMCORDER_RM_SUPPORT */
+               if (dp_handle) {
+                       window_info = (MMCamWindowInfo *)dp_handle;
+                       MMCAM_LOG_INFO("wayland global surface id : %d, x,y,w,h (%d,%d,%d,%d)",
+                               window_info->surface_id,
+                               window_info->rect.x,
+                               window_info->rect.y,
+                               window_info->rect.width,
+                               window_info->rect.height);
+                       gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), (guintptr)window_info->surface_id);
+                       gst_video_overlay_set_render_rectangle(GST_VIDEO_OVERLAY(vsink),
+                               window_info->rect.x,
+                               window_info->rect.y,
+                               window_info->rect.width,
+                               window_info->rect.height);
                } else {
-                       _mmcam_dbg_warn("Handle is NULL. skip setting.");
+                       MMCAM_LOG_WARNING("dp_handle is null");
                }
        } else {
-               _mmcam_dbg_warn("Who are you?? (Videosink: %s)", videosink_name);
+               MMCAM_LOG_WARNING("Who are you?? (Videosink: %s)", videosink_name);
        }
 
-       _mmcam_dbg_log("%s set: display_geometry_method[%d],origin-size[%d],visible[%d],rotate[%d],flip[%d]",
+       MMCAM_LOG_INFO("%s set: display_geometry_method[%d],origin-size[%d],visible[%d],rotate[%d],flip[%d]",
                videosink_name, display_geometry_method, origin_size, visible, rotation, flip);
 
        /* Set attribute */
@@ -1467,7 +1935,7 @@ int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* Videosi
                        zoom_level = 3;
                        break;
                default:
-                       _mmcam_dbg_warn("Unsupported zoom value. set as default.");
+                       MMCAM_LOG_WARNING("Unsupported zoom value. set as default.");
                        zoom_level = 1;
                        break;
                }
@@ -1516,14 +1984,14 @@ int _mmcamcorder_video_frame_stabilize(MMHandleType handle, int cmd)
                category = CONFIGURE_CATEGORY_CTRL_CAPTURE;
                break;
        default:
-               _mmcam_dbg_warn("unknown command : %d", cmd);
+               MMCAM_LOG_WARNING("unknown command : %d", cmd);
                return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
        }
 
        _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_ctrl,
                category, "FrameStabilityCount", &sc->frame_stability_count);
 
-       _mmcam_dbg_log("[cmd %d] frame stability count : %d",
+       MMCAM_LOG_INFO("[cmd %d] frame stability count : %d",
                cmd, sc->frame_stability_count);
 
        return MM_ERROR_NONE;
@@ -1556,7 +2024,7 @@ gboolean _mmcamcorder_get_device_info(MMHandleType handle)
                                if (exif_info.focal_len_denominator != 0)
                                        focal_len = ((double)exif_info.focal_len_numerator) / ((double) exif_info.focal_len_denominator);
                        } else {
-                               _mmcam_dbg_err("Fail to get camera control interface!");
+                               MMCAM_LOG_ERROR("Fail to get camera control interface!");
                                focal_len = 0.0;
                        }
                }
@@ -1566,32 +2034,59 @@ gboolean _mmcamcorder_get_device_info(MMHandleType handle)
                        MMCAM_CAMERA_FOCAL_LENGTH, focal_len,
                        NULL);
                if (err != MM_ERROR_NONE) {
-                       _mmcam_dbg_err("Set attributes error(%s:%x)!", err_name, err);
+                       MMCAM_LOG_ERROR("Set attributes error(%s:%x)!", err_name, err);
                        SAFE_FREE(err_name);
                        return FALSE;
                }
        } else {
-               _mmcam_dbg_warn("Sub context isn't exist.");
+               MMCAM_LOG_WARNING("Sub context isn't exist.");
                return FALSE;
        }
 
        return TRUE;
 }
 
-static guint32 _mmcamcorder_convert_fourcc_string_to_value(const gchar* format_name)
+static guint32 _mmcamcorder_get_structure_fourcc(const GstStructure *structure)
 {
-       return format_name[0] | (format_name[1] << 8) | (format_name[2] << 16) | (format_name[3] << 24);
+       const gchar *format_string = NULL;
+
+       if (!structure) {
+               MMCAM_LOG_WARNING("NULL structure");
+               return GST_MAKE_FOURCC('N', 'U', 'L', 'L');
+       }
+
+       if (gst_structure_has_name(structure, "video/x-h264"))
+               return GST_MAKE_FOURCC('H', '2', '6', '4');
+
+       if (gst_structure_has_name(structure, "video/x-h265"))
+               return GST_MAKE_FOURCC('H', '2', '6', '5');
+
+       if (gst_structure_has_name(structure, "video/x-vp8"))
+               return GST_MAKE_FOURCC('V', 'P', '8', '0');
+
+       if (gst_structure_has_name(structure, "video/x-vp9"))
+               return GST_MAKE_FOURCC('V', 'P', '9', '0');
+
+       if (gst_structure_has_name(structure, "video/x-jpeg") ||
+               gst_structure_has_name(structure, "image/jpeg"))
+               return GST_MAKE_FOURCC('M', 'J', 'P', 'G');
+
+       format_string = gst_structure_get_string(structure, "format");
+
+       if (format_string)
+               return GST_STR_FOURCC(format_string);
+
+       return GST_MAKE_FOURCC('N', 'O', 'N', 'E');
 }
 
 static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
 {
-       int current_state = MM_CAMCORDER_STATE_NONE;
-       int i = 0;
-
+       gboolean ret = TRUE;
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data);
        _MMCamcorderSubContext *sc = NULL;
-       _MMCamcorderKPIMeasure *kpi = NULL;
        GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info);
+       GstSample *sample = NULL;
+       GstCaps *caps = NULL;
 
        mmf_return_val_if_fail(buffer, GST_PAD_PROBE_DROP);
        mmf_return_val_if_fail(gst_buffer_n_memory(buffer), GST_PAD_PROBE_DROP);
@@ -1600,432 +2095,68 @@ static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstP
        sc = MMF_CAMCORDER_SUBCONTEXT(u_data);
        mmf_return_val_if_fail(sc, GST_PAD_PROBE_DROP);
 
-       current_state = hcamcorder->state;
-
        if (sc->drop_vframe > 0) {
                if (sc->pass_first_vframe > 0) {
                        sc->pass_first_vframe--;
-                       _mmcam_dbg_log("Pass video frame by pass_first_vframe");
+                       MMCAM_LOG_INFO("Pass video frame by pass_first_vframe");
                } else {
                        sc->drop_vframe--;
-                       _mmcam_dbg_log("Drop video frame by drop_vframe");
+                       MMCAM_LOG_INFO("Drop video frame by drop_vframe");
                        return GST_PAD_PROBE_DROP;
                }
        } else if (sc->frame_stability_count > 0) {
                sc->frame_stability_count--;
-               _mmcam_dbg_log("Drop video frame by frame_stability_count");
+               MMCAM_LOG_INFO("Drop video frame by frame_stability_count");
                return GST_PAD_PROBE_DROP;
        }
 
-       if (current_state >= MM_CAMCORDER_STATE_PREPARE) {
-               int diff_sec;
-               int frame_count = 0;
-               struct timeval current_video_time;
-
-               kpi = &(sc->kpi);
-               if (kpi->init_video_time.tv_sec == kpi->last_video_time.tv_sec &&
-                   kpi->init_video_time.tv_usec == kpi->last_video_time.tv_usec &&
-                   kpi->init_video_time.tv_usec  == 0) {
-                       /*
-                       _mmcam_dbg_log("START to measure FPS");
-                       */
-                       gettimeofday(&(kpi->init_video_time), NULL);
-               }
-
-               frame_count = ++(kpi->video_framecount);
-
-               gettimeofday(&current_video_time, NULL);
-               diff_sec = current_video_time.tv_sec - kpi->last_video_time.tv_sec;
-               if (diff_sec != 0) {
-                       kpi->current_fps = (frame_count - kpi->last_framecount) / diff_sec;
-                       if ((current_video_time.tv_sec - kpi->init_video_time.tv_sec) != 0) {
-                               int framecount = kpi->video_framecount;
-                               int elased_sec = current_video_time.tv_sec - kpi->init_video_time.tv_sec;
-                               kpi->average_fps = framecount / elased_sec;
-                       }
-
-                       kpi->last_framecount = frame_count;
-                       kpi->last_video_time.tv_sec = current_video_time.tv_sec;
-                       kpi->last_video_time.tv_usec = current_video_time.tv_usec;
-                       /*
-                       _mmcam_dbg_log("current fps(%d), average(%d)", kpi->current_fps, kpi->average_fps);
-                       */
-               }
-       }
-
-       /* video stream callback */
-       if (hcamcorder->vstream_cb && buffer) {
-               int state = MM_CAMCORDER_STATE_NULL;
-               int num_bos = 0;
-               unsigned int fourcc = 0;
-               const gchar *string_format = NULL;
-
-               MMCamcorderVideoStreamDataType stream;
-               tbm_surface_h t_surface = NULL;
-               tbm_surface_info_s t_info;
-
-               GstCaps *caps = NULL;
-               GstStructure *structure = NULL;
-               GstMemory *memory = NULL;
-               GstMapInfo mapinfo;
-
-               state = _mmcamcorder_get_state((MMHandleType)hcamcorder);
-               if (state < MM_CAMCORDER_STATE_PREPARE) {
-                       _mmcam_dbg_warn("Not ready for stream callback");
-                       return GST_PAD_PROBE_OK;
-               }
-
-               caps = gst_pad_get_current_caps(pad);
-               if (caps == NULL) {
-                       _mmcam_dbg_warn("Caps is NULL.");
-                       return GST_PAD_PROBE_OK;
-               }
-
-               /* clear data structure */
-               memset(&mapinfo, 0x0, sizeof(GstMapInfo));
-               memset(&stream, 0x0, sizeof(MMCamcorderVideoStreamDataType));
-
-               structure = gst_caps_get_structure(caps, 0);
-               gst_structure_get_int(structure, "width", &(stream.width));
-               gst_structure_get_int(structure, "height", &(stream.height));
-
-               if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
-                       stream.format = MM_PIXEL_FORMAT_ENCODED_H264;
-               } else {
-                       string_format = gst_structure_get_string(structure, "format");
-                       if (string_format == NULL) {
-                               gst_caps_unref(caps);
-                               caps = NULL;
-                               _mmcam_dbg_warn("get string error!!");
-                               return GST_PAD_PROBE_OK;
-                       }
-
-                       fourcc = _mmcamcorder_convert_fourcc_string_to_value(string_format);
-                       stream.format = _mmcamcorder_get_pixtype(fourcc);
-               }
-
-               gst_caps_unref(caps);
-               caps = NULL;
-
-               /*
-               _mmcam_dbg_log("Call video steramCb, data[%p], Width[%d],Height[%d], Format[%d]",
-                       GST_BUFFER_DATA(buffer), stream.width, stream.height, stream.format);
-               */
-
-               if (stream.width == 0 || stream.height == 0) {
-                       _mmcam_dbg_warn("Wrong condition!!");
-                       return GST_PAD_PROBE_OK;
-               }
-
-               /* set size and timestamp */
-               memory = gst_buffer_peek_memory(buffer, 0);
-               if (!memory) {
-                       _mmcam_dbg_err("GstMemory get failed from buffer %p", buffer);
-                       return GST_PAD_PROBE_OK;
-               }
-
-               if (hcamcorder->use_zero_copy_format) {
-                       t_surface = (tbm_surface_h)gst_tizen_memory_get_surface(memory);
-
-                       if (tbm_surface_get_info(t_surface, &t_info) != TBM_SURFACE_ERROR_NONE) {
-                               _mmcam_dbg_err("failed to get tbm surface[%p] info", t_surface);
-                               return GST_PAD_PROBE_OK;
-                       }
-
-                       stream.length_total = t_info.size;
-
-                       /* set bo, stride and elevation */
-                       num_bos = gst_tizen_memory_get_num_bos(memory);
-                       for (i = 0 ; i < num_bos ; i++)
-                               stream.bo[i] = gst_tizen_memory_get_bos(memory, i);
-
-                       for (i = 0 ; i < t_info.num_planes ; i++) {
-                               stream.stride[i] = t_info.planes[i].stride;
-                               stream.elevation[i] = t_info.planes[i].size / t_info.planes[i].stride;
-                               /*_mmcam_dbg_log("[%d] %dx%d", i, stream.stride[i], stream.elevation[i]);*/
-                       }
-
-                       /* set gst buffer */
-                       stream.internal_buffer = buffer;
-               } else {
-                       stream.length_total = gst_memory_get_sizes(memory, NULL, NULL);
-               }
-
-               stream.timestamp = (unsigned int)(GST_BUFFER_PTS(buffer)/1000000); /* nano sec -> mili sec */
-
-               /* set data pointers */
-               if (stream.format == MM_PIXEL_FORMAT_NV12 ||
-                       stream.format == MM_PIXEL_FORMAT_NV21 ||
-                       stream.format == MM_PIXEL_FORMAT_I420) {
-                       if (hcamcorder->use_zero_copy_format) {
-                               if (stream.format == MM_PIXEL_FORMAT_NV12 ||
-                                   stream.format == MM_PIXEL_FORMAT_NV21) {
-                                       stream.data_type = MM_CAM_STREAM_DATA_YUV420SP;
-                                       stream.num_planes = 2;
-                                       stream.data.yuv420sp.y = t_info.planes[0].ptr;
-                                       stream.data.yuv420sp.length_y = t_info.planes[0].size;
-                                       stream.data.yuv420sp.uv = t_info.planes[1].ptr;
-                                       stream.data.yuv420sp.length_uv = t_info.planes[1].size;
-                                       /*
-                                       _mmcam_dbg_log("format[%d][num_planes:%d] [Y]p:%p,size:%d [UV]p:%p,size:%d",
-                                               stream.format, stream.num_planes,
-                                               stream.data.yuv420sp.y, stream.data.yuv420sp.length_y,
-                                               stream.data.yuv420sp.uv, stream.data.yuv420sp.length_uv);
-                                       */
-                               } else {
-                                       stream.data_type = MM_CAM_STREAM_DATA_YUV420P;
-                                       stream.num_planes = 3;
-                                       stream.data.yuv420p.y = t_info.planes[0].ptr;
-                                       stream.data.yuv420p.length_y = t_info.planes[0].size;
-                                       stream.data.yuv420p.u = t_info.planes[1].ptr;
-                                       stream.data.yuv420p.length_u = t_info.planes[1].size;
-                                       stream.data.yuv420p.v = t_info.planes[2].ptr;
-                                       stream.data.yuv420p.length_v = t_info.planes[2].size;
-                                       /*
-                                       _mmcam_dbg_log("S420[num_planes:%d] [Y]p:%p,size:%d [U]p:%p,size:%d [V]p:%p,size:%d",
-                                               stream.num_planes,
-                                               stream.data.yuv420p.y, stream.data.yuv420p.length_y,
-                                               stream.data.yuv420p.u, stream.data.yuv420p.length_u,
-                                               stream.data.yuv420p.v, stream.data.yuv420p.length_v);
-                                       */
-                               }
-                       } else {
-                               gst_memory_map(memory, &mapinfo, GST_MAP_READWRITE);
-                               if (stream.format == MM_PIXEL_FORMAT_NV12 ||
-                                       stream.format == MM_PIXEL_FORMAT_NV21) {
-                                       stream.data_type = MM_CAM_STREAM_DATA_YUV420SP;
-                                       stream.num_planes = 2;
-                                       stream.data.yuv420sp.y = mapinfo.data;
-                                       stream.data.yuv420sp.length_y = stream.width * stream.height;
-                                       stream.data.yuv420sp.uv = stream.data.yuv420sp.y + stream.data.yuv420sp.length_y;
-                                       stream.data.yuv420sp.length_uv = stream.data.yuv420sp.length_y >> 1;
-                                       stream.stride[0] = stream.width;
-                                       stream.elevation[0] = stream.height;
-                                       stream.stride[1] = stream.width;
-                                       stream.elevation[1] = stream.height >> 1;
-                                       /*
-                                       _mmcam_dbg_log("format[%d][num_planes:%d] [Y]p:%p,size:%d [UV]p:%p,size:%d",
-                                               stream.format, stream.num_planes,
-                                               stream.data.yuv420sp.y, stream.data.yuv420sp.length_y,
-                                               stream.data.yuv420sp.uv, stream.data.yuv420sp.length_uv);
-                                       */
-                               } else {
-                                       stream.data_type = MM_CAM_STREAM_DATA_YUV420P;
-                                       stream.num_planes = 3;
-                                       stream.data.yuv420p.y = mapinfo.data;
-                                       stream.data.yuv420p.length_y = stream.width * stream.height;
-                                       stream.data.yuv420p.u = stream.data.yuv420p.y + stream.data.yuv420p.length_y;
-                                       stream.data.yuv420p.length_u = stream.data.yuv420p.length_y >> 2;
-                                       stream.data.yuv420p.v = stream.data.yuv420p.u + stream.data.yuv420p.length_u;
-                                       stream.data.yuv420p.length_v = stream.data.yuv420p.length_u;
-                                       stream.stride[0] = stream.width;
-                                       stream.elevation[0] = stream.height;
-                                       stream.stride[1] = stream.width >> 1;
-                                       stream.elevation[1] = stream.height >> 1;
-                                       stream.stride[2] = stream.width >> 1;
-                                       stream.elevation[2] = stream.height >> 1;
-                                       /*
-                                       _mmcam_dbg_log("I420[num_planes:%d] [Y]p:%p,size:%d [U]p:%p,size:%d [V]p:%p,size:%d",
-                                               stream.num_planes,
-                                               stream.data.yuv420p.y, stream.data.yuv420p.length_y,
-                                               stream.data.yuv420p.u, stream.data.yuv420p.length_u,
-                                               stream.data.yuv420p.v, stream.data.yuv420p.length_v);
-                                       */
-                               }
-                       }
-               } else {
-                       gst_memory_map(memory, &mapinfo, GST_MAP_READWRITE);
-
-                       switch (stream.format) {
-                       case MM_PIXEL_FORMAT_YUYV:
-                       case MM_PIXEL_FORMAT_UYVY:
-                       case MM_PIXEL_FORMAT_422P:
-                       case MM_PIXEL_FORMAT_ITLV_JPEG_UYVY:
-                               stream.data_type = MM_CAM_STREAM_DATA_YUV422;
-                               stream.data.yuv422.yuv = mapinfo.data;
-                               stream.data.yuv422.length_yuv = stream.length_total;
-                               stream.stride[0] = stream.width << 1;
-                               stream.elevation[0] = stream.height;
-                               break;
-                       case MM_PIXEL_FORMAT_ENCODED_H264:
-                               stream.data_type = MM_CAM_STREAM_DATA_ENCODED;
-                               stream.data.encoded.data = mapinfo.data;
-                               stream.data.encoded.length_data = stream.length_total;
-                               /*
-                               _mmcam_dbg_log("H264[num_planes:%d] [0]p:%p,size:%d",
-                                       stream.num_planes, stream.data.encoded.data, stream.data.encoded.length_data);
-                               */
-                               break;
-                       case MM_PIXEL_FORMAT_INVZ:
-                               stream.data_type = MM_CAM_STREAM_DATA_DEPTH;
-                               stream.data.depth.data = mapinfo.data;
-                               stream.data.depth.length_data = stream.length_total;
-                               stream.stride[0] = stream.width << 1;
-                               stream.elevation[0] = stream.height;
-                               break;
-                       case MM_PIXEL_FORMAT_RGBA:
-                       case MM_PIXEL_FORMAT_ARGB:
-                               stream.data_type = MM_CAM_STREAM_DATA_RGB;
-                               stream.data.rgb.data = mapinfo.data;
-                               stream.data.rgb.length_data = stream.length_total;
-                               stream.stride[0] = stream.width << 2;
-                               stream.elevation[0] = stream.height;
-                               break;
-                       default:
-                               stream.data_type = MM_CAM_STREAM_DATA_YUV420;
-                               stream.data.yuv420.yuv = mapinfo.data;
-                               stream.data.yuv420.length_yuv = stream.length_total;
-                               stream.stride[0] = (stream.width * 3) >> 1;
-                               stream.elevation[0] = stream.height;
-                               break;
-                       }
-
-                       stream.num_planes = 1;
-                       /*
-                       _mmcam_dbg_log("%c%c%c%c[num_planes:%d] [0]p:%p,size:%d",
-                               fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
-                               stream.num_planes, stream.data.yuv420.yuv, stream.data.yuv420.length_yuv);
-                       */
-               }
-
-               /* call application callback */
-               _MMCAMCORDER_LOCK_VSTREAM_CALLBACK(hcamcorder);
-               if (hcamcorder->vstream_cb) {
-                       hcamcorder->vstream_cb(&stream, hcamcorder->vstream_cb_param);
+       if (hcamcorder->measure_preview_fps && hcamcorder->state >= MM_CAMCORDER_STATE_PREPARE)
+               _mmcamcorder_measure_fps(&sc->kpi);
 
-                       for (i = 0 ; i < TBM_SURF_PLANE_MAX && stream.bo[i] ; i++) {
-                               tbm_bo_map(stream.bo[i], TBM_DEVICE_CPU, TBM_OPTION_READ|TBM_OPTION_WRITE);
-                               tbm_bo_unmap(stream.bo[i]);
-                       }
-               }
-
-               _MMCAMCORDER_UNLOCK_VSTREAM_CALLBACK(hcamcorder);
-
-               /* unmap memory */
-               if (mapinfo.data)
-                       gst_memory_unmap(memory, &mapinfo);
+       /* The first H.264 frame should not be skipped for vstream cb. */
+       if (hcamcorder->state < MM_CAMCORDER_STATE_PREPARE &&
+               !_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
+               MMCAM_LOG_WARNING("Not ready for stream callback");
+               return GST_PAD_PROBE_OK;
        }
 
-       return GST_PAD_PROBE_OK;
-}
+       /* make sample with buffer and caps */
+       caps = gst_pad_get_allowed_caps(pad);
+       mmf_return_val_if_fail(caps, GST_PAD_PROBE_OK);
 
-static GstPadProbeReturn __mmcamcorder_video_dataprobe_push_buffer_to_record(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
-{
-       mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data);
-       _MMCamcorderSubContext *sc = NULL;
-       GstClockTime diff = 0;           /* nsec */
-       GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info);
+       sample = gst_sample_new(buffer, caps, NULL, NULL);
+       gst_caps_unref(caps);
+       mmf_return_val_if_fail(sample, GST_PAD_PROBE_OK);
 
-       mmf_return_val_if_fail(buffer, GST_PAD_PROBE_DROP);
-       mmf_return_val_if_fail(gst_buffer_n_memory(buffer), GST_PAD_PROBE_DROP);
-       mmf_return_val_if_fail(hcamcorder, GST_PAD_PROBE_DROP);
+       ret = _mmcamcorder_invoke_video_stream_cb((MMHandleType)hcamcorder, sample, TRUE, -1);
 
-       sc = MMF_CAMCORDER_SUBCONTEXT(u_data);
-       mmf_return_val_if_fail(sc, GST_PAD_PROBE_DROP);
+       gst_sample_unref(sample);
 
-       /* push buffer in appsrc to encode */
-       if (!sc->info_video) {
-               _mmcam_dbg_warn("sc->info_video is NULL!!");
+       if (ret)
+               return GST_PAD_PROBE_OK;
+       else
                return GST_PAD_PROBE_DROP;
-       }
-
-       if (sc->info_video->push_encoding_buffer == PUSH_ENCODING_BUFFER_RUN &&
-           sc->info_video->record_dual_stream == FALSE &&
-           sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst) {
-               int ret = 0;
-               GstClock *clock = NULL;
-
-               /*
-               _mmcam_dbg_log("GST_BUFFER_FLAG_DELTA_UNIT is set : %d",
-                       GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT));
-               */
-
-               /* check first I frame */
-               if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264 &&
-                   sc->info_video->get_first_I_frame == FALSE) {
-                       if (!GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT)) {
-                               _mmcam_dbg_warn("first I frame is come");
-                               sc->info_video->get_first_I_frame = TRUE;
-                       } else {
-                               _mmcam_dbg_warn("NOT I frame.. skip this buffer");
-                               return GST_PAD_PROBE_OK;
-                       }
-               }
-
-               if (sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst) {
-                       if (sc->info_video->is_firstframe) {
-                               clock = GST_ELEMENT_CLOCK(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst);
-                               if (clock) {
-                                       gst_object_ref(clock);
-                                       sc->info_video->base_video_ts = GST_BUFFER_PTS(buffer) - (gst_clock_get_time(clock) - GST_ELEMENT(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst)->base_time);
-                                       gst_object_unref(clock);
-                               }
-                       }
-               } else {
-                       if (sc->info_video->is_firstframe) {
-                               /* for image capture with encodebin(ex:emulator) */
-                               if (sc->bencbin_capture && sc->info_image->capturing) {
-                                       g_mutex_lock(&hcamcorder->task_thread_lock);
-                                       _mmcam_dbg_log("send signal for sound play");
-                                       hcamcorder->task_thread_state = _MMCAMCORDER_TASK_THREAD_STATE_SOUND_SOLO_PLAY_START;
-                                       g_cond_signal(&hcamcorder->task_thread_cond);
-                                       g_mutex_unlock(&hcamcorder->task_thread_lock);
-                               }
-                               sc->info_video->base_video_ts = GST_BUFFER_PTS(buffer);
-                       }
-               }
-               GST_BUFFER_PTS(buffer) = GST_BUFFER_PTS(buffer) - sc->info_video->base_video_ts;
-               GST_BUFFER_DTS(buffer) = GST_BUFFER_PTS(buffer);
-
-               /*_mmcam_dbg_log("buffer %p, timestamp %"GST_TIME_FORMAT, buffer, GST_TIME_ARGS(GST_BUFFER_PTS(buffer)));*/
-
-               if (0) {
-                       GstCaps *caps = gst_pad_get_current_caps(pad);
-                       if (caps) {
-                               char *caps_string = gst_caps_to_string(caps);
-                               if (caps_string) {
-                                       _mmcam_dbg_log("%s", caps_string);
-                                       g_free(caps_string);
-                                       caps_string = NULL;
-                               }
-                               gst_caps_unref(caps);
-                               caps = NULL;
-                       } else {
-                               _mmcam_dbg_warn("failed to get caps from pad");
-                       }
-               }
-
-               g_signal_emit_by_name(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "push-buffer", buffer, &ret);
+}
 
-               /*_mmcam_dbg_log("push buffer result : 0x%x", ret);*/
 
-               if (sc->info_video->is_firstframe) {
-                       sc->info_video->is_firstframe = FALSE;
+static GstPadProbeReturn __mmcamcorder_video_dataprobe_record(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
+{
+       gboolean ret = TRUE;
+       GstSample *sample = NULL;
+       GstCaps *caps = NULL;
 
-                       /* drop buffer if it's from tizen allocator */
-                       if (gst_is_tizen_memory(gst_buffer_peek_memory(buffer, 0))) {
-                               _mmcam_dbg_warn("drop first buffer from tizen allocator to avoid copy in basesrc");
-                               return GST_PAD_PROBE_DROP;
-                       }
-               }
-       }
+       caps = gst_pad_get_allowed_caps(pad);
+       mmf_return_val_if_fail(caps, GST_PAD_PROBE_OK);
 
-       /* skip display if too fast FPS */
-       if (sc->info_video && sc->info_video->fps > _MMCAMCORDER_FRAME_PASS_MIN_FPS) {
-               if (sc->info_video->prev_preview_ts != 0) {
-                       diff = GST_BUFFER_PTS(buffer) - sc->info_video->prev_preview_ts;
-                       if (diff < _MMCAMCORDER_MIN_TIME_TO_PASS_FRAME) {
-                               _mmcam_dbg_log("it's too fast. drop frame...");
-                               return GST_PAD_PROBE_DROP;
-                       }
-               }
+       sample = gst_sample_new(GST_PAD_PROBE_INFO_BUFFER(info), caps, NULL, NULL);
+       gst_caps_unref(caps);
+       mmf_return_val_if_fail(sample, GST_PAD_PROBE_OK);
 
-               /*_mmcam_dbg_log("diff %llu", diff);*/
+       ret = _mmcamcorder_video_push_buffer(u_data, sample);
 
-               sc->info_video->prev_preview_ts = GST_BUFFER_PTS(buffer);
-       }
+       gst_sample_unref(sample);
 
-       return GST_PAD_PROBE_OK;
+       return (ret ? GST_PAD_PROBE_OK : GST_PAD_PROBE_DROP);
 }
 
 
@@ -2045,7 +2176,7 @@ GstPadProbeReturn __mmcamcorder_muxed_dataprobe(GstPad *pad, GstPadProbeInfo *in
        mmf_return_val_if_fail(sc, GST_PAD_PROBE_OK);
 
        if (!gst_buffer_map(buffer, &mapinfo, GST_MAP_READ)) {
-               _mmcam_dbg_warn("map failed : buffer %p", buffer);
+               MMCAM_LOG_WARNING("map failed : buffer %p", buffer);
                return GST_PAD_PROBE_OK;
        }
 
@@ -2086,18 +2217,18 @@ GstPadProbeReturn __mmcamcorder_eventprobe_monitor(GstPad *pad, GstPadProbeInfo
        case GST_EVENT_LATENCY:
        /* downstream serialized events */
        case GST_EVENT_BUFFERSIZE:
-               _mmcam_dbg_log("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
+               MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
                break;
        case GST_EVENT_TAG:
                {
                        GstTagList *tag_list = NULL;
                        _MMCamcorderReplayGain *replay_gain = NULL;
 
-                       _mmcam_dbg_log("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
+                       MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
 
                        hcamcorder = MMF_CAMCORDER(u_data);
                        if (!hcamcorder || !hcamcorder->sub_context) {
-                               _mmcam_dbg_warn("NULL handle");
+                               MMCAM_LOG_WARNING("NULL handle");
                                break;
                        }
 
@@ -2105,58 +2236,58 @@ GstPadProbeReturn __mmcamcorder_eventprobe_monitor(GstPad *pad, GstPadProbeInfo
 
                        gst_event_parse_tag(event, &tag_list);
                        if (!tag_list) {
-                               _mmcam_dbg_warn("failed to get tag list");
+                               MMCAM_LOG_WARNING("failed to get tag list");
                                break;
                        }
 
                        if (!gst_tag_list_get_double(tag_list, GST_TAG_TRACK_PEAK, &replay_gain->track_peak)) {
-                               _mmcam_dbg_warn("failed to get GST_TAG_TRACK_PEAK");
+                               MMCAM_LOG_WARNING("failed to get GST_TAG_TRACK_PEAK");
                                break;
                        }
 
                        if (!gst_tag_list_get_double(tag_list, GST_TAG_TRACK_GAIN, &replay_gain->track_gain)) {
-                               _mmcam_dbg_warn("failed to get GST_TAG_TRACK_GAIN");
+                               MMCAM_LOG_WARNING("failed to get GST_TAG_TRACK_GAIN");
                                break;
                        }
 
                        if (!gst_tag_list_get_double(tag_list, GST_TAG_ALBUM_PEAK, &replay_gain->album_peak)) {
-                               _mmcam_dbg_warn("failed to get GST_TAG_ALBUM_PEAK");
+                               MMCAM_LOG_WARNING("failed to get GST_TAG_ALBUM_PEAK");
                                break;
                        }
 
                        if (!gst_tag_list_get_double(tag_list, GST_TAG_ALBUM_GAIN, &replay_gain->album_gain)) {
-                               _mmcam_dbg_warn("failed to get GST_TAG_ALBUM_PEAK");
+                               MMCAM_LOG_WARNING("failed to get GST_TAG_ALBUM_PEAK");
                                break;
                        }
 
-                       _mmcam_dbg_log("Track [peak %lf, gain %lf], Album [peak %lf, gain %lf]",
+                       MMCAM_LOG_INFO("Track [peak %lf, gain %lf], Album [peak %lf, gain %lf]",
                                replay_gain->track_peak, replay_gain->track_gain,
                                replay_gain->album_peak, replay_gain->album_gain);
                }
                break;
        case GST_EVENT_SEGMENT:
-               _mmcam_dbg_log("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
+               MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
 
                hcamcorder = MMF_CAMCORDER(u_data);
                if (!hcamcorder) {
-                       _mmcam_dbg_warn("NULL handle");
+                       MMCAM_LOG_WARNING("NULL handle");
                        break;
                }
 
                sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
                if (!sc) {
-                       _mmcam_dbg_warn("NULL sub context");
+                       MMCAM_LOG_WARNING("NULL sub context");
                        break;
                }
 
                if (!sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst) {
-                       _mmcam_dbg_warn("no encoder sink");
+                       MMCAM_LOG_WARNING("no encoder sink");
                        break;
                }
 
                parent = gst_pad_get_parent(pad);
                if (!parent) {
-                       _mmcam_dbg_warn("get parent failed");
+                       MMCAM_LOG_WARNING("get parent failed");
                        break;
                }
 
@@ -2164,7 +2295,7 @@ GstPadProbeReturn __mmcamcorder_eventprobe_monitor(GstPad *pad, GstPadProbeInfo
                        const GstSegment *segment;
                        gst_event_parse_segment(event, &segment);
                        if (segment->format == GST_FORMAT_BYTES) {
-                               _mmcam_dbg_log("change current offset %llu -> %llu",
+                               MMCAM_LOG_INFO("change current offset %llu -> %"G_GUINT64_FORMAT,
                                        sc->muxed_stream_offset, segment->start);
 
                                sc->muxed_stream_offset = (unsigned long long)segment->start;
@@ -2175,15 +2306,15 @@ GstPadProbeReturn __mmcamcorder_eventprobe_monitor(GstPad *pad, GstPadProbeInfo
                parent = NULL;
                break;
        case GST_EVENT_EOS:
-               _mmcam_dbg_warn("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
+               MMCAM_LOG_WARNING("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
                break;
        /* bidirectional events */
        case GST_EVENT_FLUSH_START:
        case GST_EVENT_FLUSH_STOP:
-               _mmcam_dbg_err("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
+               MMCAM_LOG_ERROR("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
                break;
        default:
-               _mmcam_dbg_log("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
+               MMCAM_LOG_INFO("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event));
                break;
        }
 
@@ -2228,22 +2359,22 @@ int _mmcamcorder_get_eos_message(MMHandleType handle)
        sc = MMF_CAMCORDER_SUBCONTEXT(handle);
        mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
 
-       _mmcam_dbg_log("START");
+       MMCAM_LOG_INFO("START");
 
        _MMCAMCORDER_LOCK(handle);
 
        if (sc->bget_eos == FALSE) {
                end_time = g_get_monotonic_time() + 3 * G_TIME_SPAN_SECOND;
                if (_MMCAMCORDER_WAIT_UNTIL(handle, end_time)) {
-                       _mmcam_dbg_log("EOS signal received");
+                       MMCAM_LOG_INFO("EOS signal received");
                } else {
-                       _mmcam_dbg_err("EOS wait time out");
+                       MMCAM_LOG_ERROR("EOS wait time out");
 
                        if (hcamcorder->error_code == MM_ERROR_NONE)
                                hcamcorder->error_code = MM_ERROR_CAMCORDER_RESPONSE_TIMEOUT;
                }
        } else {
-               _mmcam_dbg_log("already got EOS");
+               MMCAM_LOG_INFO("already got EOS");
        }
 
        _MMCAMCORDER_UNLOCK(handle);
@@ -2251,19 +2382,19 @@ int _mmcamcorder_get_eos_message(MMHandleType handle)
        if (hcamcorder->error_code == MM_ERROR_NONE) {
                if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
                        mmf_return_val_if_fail(sc->info_video, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
-                       if (sc->info_video->b_commiting)
+                       if (sc->info_video->b_committing)
                                _mmcamcorder_video_handle_eos((MMHandleType)hcamcorder);
                } else {
                        mmf_return_val_if_fail(sc->info_audio, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
-                       if (sc->info_audio->b_commiting)
+                       if (sc->info_audio->b_committing)
                                _mmcamcorder_audio_handle_eos((MMHandleType)hcamcorder);
                }
        } else {
                ret = hcamcorder->error_code;
-               _mmcam_dbg_err("error 0x%x", ret);
+               MMCAM_LOG_ERROR("error 0x%x", ret);
        }
 
-       _mmcam_dbg_log("END");
+       MMCAM_LOG_INFO("END");
 
        return ret;
 }
@@ -2277,7 +2408,7 @@ void _mmcamcorder_remove_element_handle(MMHandleType handle, void *element, int
        mmf_return_if_fail(handle && remove_element);
        mmf_return_if_fail((first_elem >= 0) && (last_elem > 0) && (last_elem > first_elem));
 
-       _mmcam_dbg_log("");
+       MMCAM_LOG_INFO("");
 
        for (i = first_elem ; i <= last_elem ; i++) {
                remove_element[i].gst = NULL;
@@ -2297,26 +2428,26 @@ int _mmcamcorder_check_codec_fileformat_compatibility(const char *codec_type, in
                if (codec > MM_AUDIO_CODEC_INVALID && codec < MM_AUDIO_CODEC_NUM &&
                        file_format > MM_FILE_FORMAT_INVALID && file_format < MM_FILE_FORMAT_NUM) {
                        if (audiocodec_fileformat_compatibility_table[codec][file_format] == 0) {
-                               _mmcam_dbg_err("Audio codec[%d] and file format[%d] compatibility FAILED.", codec, file_format);
+                               MMCAM_LOG_ERROR("Audio codec[%d] and file format[%d] compatibility FAILED.", codec, file_format);
                                return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
                        }
 
-                       _mmcam_dbg_log("Audio codec[%d] and file format[%d] compatibility SUCCESS.", codec, file_format);
+                       MMCAM_LOG_INFO("Audio codec[%d] and file format[%d] compatibility SUCCESS.", codec, file_format);
                } else {
-                       _mmcam_dbg_err("Audio codec[%d] or file format[%d] is INVALID.", codec, file_format);
+                       MMCAM_LOG_ERROR("Audio codec[%d] or file format[%d] is INVALID.", codec, file_format);
                        return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
                }
        } else if (!strcmp(codec_type, MMCAM_VIDEO_ENCODER)) {
                if (codec > MM_VIDEO_CODEC_INVALID && codec < MM_VIDEO_CODEC_NUM &&
                        file_format > MM_FILE_FORMAT_INVALID && file_format < MM_FILE_FORMAT_NUM) {
                        if (videocodec_fileformat_compatibility_table[codec][file_format] == 0) {
-                               _mmcam_dbg_err("Video codec[%d] and file format[%d] compatibility FAILED.", codec, file_format);
+                               MMCAM_LOG_ERROR("Video codec[%d] and file format[%d] compatibility FAILED.", codec, file_format);
                                return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
                        }
 
-                       _mmcam_dbg_log("Video codec[%d] and file format[%d] compatibility SUCCESS.", codec, file_format);
+                       MMCAM_LOG_INFO("Video codec[%d] and file format[%d] compatibility SUCCESS.", codec, file_format);
                } else {
-                       _mmcam_dbg_err("Video codec[%d] or file format[%d] is INVALID.", codec, file_format);
+                       MMCAM_LOG_ERROR("Video codec[%d] or file format[%d] is INVALID.", codec, file_format);
                        return MM_ERROR_CAMCORDER_ENCODER_WRONG_TYPE;
                }
        }
@@ -2338,7 +2469,7 @@ int _mmcamcorder_check_audiocodec_fileformat_compatibility(MMHandleType handle)
                MMCAM_FILE_FORMAT, &file_format,
                NULL);
        if (err != MM_ERROR_NONE) {
-               _mmcam_dbg_warn("Get attrs fail. (%s:%x)", err_name, err);
+               MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
                SAFE_FREE(err_name);
                return err;
        }
@@ -2363,7 +2494,7 @@ int _mmcamcorder_check_videocodec_fileformat_compatibility(MMHandleType handle)
                MMCAM_FILE_FORMAT, &file_format,
                NULL);
        if (err != MM_ERROR_NONE) {
-               _mmcam_dbg_warn("Get attrs fail. (%s:%x)", err_name, err);
+               MMCAM_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
                SAFE_FREE(err_name);
                return err;
        }
@@ -2393,7 +2524,7 @@ bool _mmcamcorder_set_display_rotation(MMHandleType handle, int display_rotate,
                /* Get videosink name */
                _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
                if (videosink_name == NULL) {
-                       _mmcam_dbg_err("Please check videosink element in configuration file");
+                       MMCAM_LOG_ERROR("Please check videosink element in configuration file");
                        return FALSE;
                }
 
@@ -2401,14 +2532,14 @@ bool _mmcamcorder_set_display_rotation(MMHandleType handle, int display_rotate,
                        !strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink") ||
                        !strcmp(videosink_name, "directvideosink")) {
                        MMCAMCORDER_G_OBJECT_SET(sc->element[videosink_index].gst, "rotate", display_rotate);
-                       _mmcam_dbg_log("Set display-rotate [%d] done.", display_rotate);
+                       MMCAM_LOG_INFO("Set display-rotate [%d] done.", display_rotate);
                } else {
-                       _mmcam_dbg_warn("[%s] does not support DISPLAY_ROTATION, but no error", videosink_name);
+                       MMCAM_LOG_WARNING("[%s] does not support DISPLAY_ROTATION, but no error", videosink_name);
                }
 
                return TRUE;
        } else {
-               _mmcam_dbg_err("Videosink element is null");
+               MMCAM_LOG_ERROR("Videosink element is null");
                return FALSE;
        }
 }
@@ -2432,7 +2563,7 @@ bool _mmcamcorder_set_display_flip(MMHandleType handle, int display_flip, int vi
                /* Get videosink name */
                _mmcamcorder_conf_get_value_element_name(sc->VideosinkElement, &videosink_name);
                if (videosink_name == NULL) {
-                       _mmcam_dbg_err("Please check videosink element in configuration file");
+                       MMCAM_LOG_ERROR("Please check videosink element in configuration file");
                        return FALSE;
                }
 
@@ -2440,14 +2571,14 @@ bool _mmcamcorder_set_display_flip(MMHandleType handle, int display_flip, int vi
                        !strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink") ||
                        !strcmp(videosink_name, "directvideosink")) {
                        MMCAMCORDER_G_OBJECT_SET(sc->element[videosink_index].gst, "flip", display_flip);
-                       _mmcam_dbg_log("Set display flip [%d] done.", display_flip);
+                       MMCAM_LOG_INFO("Set display flip [%d] done.", display_flip);
                } else {
-                       _mmcam_dbg_warn("[%s] does not support DISPLAY_FLIP, but no error", videosink_name);
+                       MMCAM_LOG_WARNING("[%s] does not support DISPLAY_FLIP, but no error", videosink_name);
                }
 
                return TRUE;
        } else {
-               _mmcam_dbg_err("Videosink element is null");
+               MMCAM_LOG_ERROR("Videosink element is null");
                return FALSE;
        }
 }
@@ -2455,8 +2586,6 @@ bool _mmcamcorder_set_display_flip(MMHandleType handle, int display_flip, int vi
 
 bool _mmcamcorder_set_videosrc_rotation(MMHandleType handle, int videosrc_rotate)
 {
-       int width = 0;
-       int height = 0;
        int fps = 0;
        _MMCamcorderSubContext *sc = NULL;
 
@@ -2467,19 +2596,21 @@ bool _mmcamcorder_set_videosrc_rotation(MMHandleType handle, int videosrc_rotate
 
        sc = MMF_CAMCORDER_SUBCONTEXT(handle);
        if (!sc) {
-               _mmcam_dbg_log("sub context is not initailized");
+               MMCAM_LOG_INFO("sub context is not initialized");
                return TRUE;
        }
 
        mm_camcorder_get_attributes(handle, NULL,
-               MMCAM_CAMERA_WIDTH, &width,
-               MMCAM_CAMERA_HEIGHT, &height,
+               MMCAM_CAMERA_WIDTH, &sc->info_video->preview_width,
+               MMCAM_CAMERA_HEIGHT, &sc->info_video->preview_height,
                MMCAM_CAMERA_FPS, &fps,
                NULL);
 
-       _mmcam_dbg_log("set rotate %d", videosrc_rotate);
+       MMCAM_LOG_INFO("set rotate %d", videosrc_rotate);
 
-       return _mmcamcorder_set_videosrc_caps(handle, sc->fourcc, width, height, fps, videosrc_rotate);
+       return _mmcamcorder_set_videosrc_caps(handle, sc->fourcc,
+               sc->info_video->preview_width, sc->info_video->preview_height,
+               fps, videosrc_rotate);
 }
 
 
@@ -2491,15 +2622,7 @@ bool _mmcamcorder_set_videosrc_caps(MMHandleType handle, unsigned int fourcc, in
        int fps_auto = 0;
        unsigned int caps_fourcc = 0;
        gboolean do_set_caps = FALSE;
-
        GstCaps *caps = NULL;
-#ifdef _MMCAMCORDER_PRODUCT_TV
-       GstPad *sinkpad;
-       GstCaps *decsink_caps = NULL;
-       GstStructure *decsink_struct = NULL;
-       int maxwidth = 0;
-       int maxheight = 0;
-#endif /*_MMCAMCORDER_PRODUCT_TV */
 
        mmf_camcorder_t *hcamcorder = NULL;
        _MMCamcorderSubContext *sc = NULL;
@@ -2510,17 +2633,17 @@ bool _mmcamcorder_set_videosrc_caps(MMHandleType handle, unsigned int fourcc, in
        sc = MMF_CAMCORDER_SUBCONTEXT(handle);
 
        if (!sc || !(sc->element)) {
-               _mmcam_dbg_log("sub context is not initialized");
+               MMCAM_LOG_INFO("sub context is not initialized");
                return TRUE;
        }
 
        if (!sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
-               _mmcam_dbg_err("Video src is NULL!");
+               MMCAM_LOG_ERROR("Video src is NULL!");
                return FALSE;
        }
 
        if (!sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst) {
-               _mmcam_dbg_err("Video filter is NULL!");
+               MMCAM_LOG_ERROR("Video filter is NULL!");
                return FALSE;
        }
 
@@ -2537,7 +2660,7 @@ bool _mmcamcorder_set_videosrc_caps(MMHandleType handle, unsigned int fourcc, in
                        MMCAM_VIDEO_WIDTH, &sc->info_video->video_width,
                        MMCAM_VIDEO_HEIGHT, &sc->info_video->video_height,
                        NULL);
-               _mmcam_dbg_log("motion rate %f, capture size %dx%d, fps auto %d, video size %dx%d",
+               MMCAM_LOG_INFO("motion rate %f, capture size %dx%d, fps auto %d, video size %dx%d",
                        motion_rate, capture_width, capture_height, fps_auto,
                        sc->info_video->video_width, sc->info_video->video_height);
 
@@ -2583,7 +2706,7 @@ bool _mmcamcorder_set_videosrc_caps(MMHandleType handle, unsigned int fourcc, in
                set_width = width;
                set_height = height;
 
-               _mmcam_dbg_warn("ITLV format doe snot support INPUT ROTATE. Ignore ROTATE[%d]", rotate);
+               MMCAM_LOG_WARNING("ITLV format doe snot support INPUT ROTATE. Ignore ROTATE[%d]", rotate);
        }
 
        MMCAMCORDER_G_OBJECT_GET(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", &caps);
@@ -2592,41 +2715,42 @@ bool _mmcamcorder_set_videosrc_caps(MMHandleType handle, unsigned int fourcc, in
 
                structure = gst_caps_get_structure(caps, 0);
                if (structure) {
-                       const gchar *format_string = NULL;
                        int caps_width = 0;
                        int caps_height = 0;
-                       int caps_fps = 0;
+                       int caps_fps_n = 0;
+                       int caps_fps_d = 0;
                        int caps_rotate = 0;
 
-                       format_string = gst_structure_get_string(structure, "format");
-                       if (format_string)
-                               caps_fourcc = _mmcamcorder_convert_fourcc_string_to_value(format_string);
+                       caps_fourcc = _mmcamcorder_get_structure_fourcc(structure);
 
-                       gst_structure_get_int(structure, "width", &caps_width);
-                       gst_structure_get_int(structure, "height", &caps_height);
-                       gst_structure_get_int(structure, "fps", &caps_fps);
-                       gst_structure_get_int(structure, "rotate", &caps_rotate);
+                       gst_structure_get(structure,
+                               "width", G_TYPE_INT, &caps_width,
+                               "height", G_TYPE_INT, &caps_height,
+                               "framerate", GST_TYPE_FRACTION, &caps_fps_n, &caps_fps_d,
+                               "rotate", G_TYPE_INT, &caps_rotate,
+                               NULL);
 
 #ifdef _MMCAMCORDER_PRODUCT_TV
-                       if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
-                               if (set_width == caps_width && set_height == caps_height && set_rotate == caps_rotate && fps == caps_fps) {
-                                       _mmcam_dbg_log("No need to replace caps.");
+                       if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
+                               if (set_width == caps_width && set_height == caps_height &&
+                                       set_rotate == caps_rotate && fps == caps_fps_n) {
+                                       MMCAM_LOG_INFO("No need to replace caps.");
                                } else {
-                                       _mmcam_dbg_log("current [%c%c%c%c %dx%d, fps %d, rot %d], new [%c%c%c%c %dx%d, fps %d, rot %d]",
+                                       MMCAM_LOG_INFO("current [%c%c%c%c %dx%d, fps %d/%d, rot %d], new [%c%c%c%c %dx%d, fps %d, rot %d]",
                                                caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
-                                               caps_width, caps_height, caps_fps, caps_rotate,
+                                               caps_width, caps_height, caps_fps_n, caps_fps_d, caps_rotate,
                                                fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
                                                set_width, set_height, fps, set_rotate);
                                        do_set_caps = TRUE;
                                }
                        } else {
                                if (set_width == caps_width && set_height == caps_height &&
-                                   fourcc == caps_fourcc && set_rotate == caps_rotate && fps == caps_fps) {
-                                       _mmcam_dbg_log("No need to replace caps.");
+                                   fourcc == caps_fourcc && set_rotate == caps_rotate && fps == caps_fps_n) {
+                                       MMCAM_LOG_INFO("No need to replace caps.");
                                } else {
-                                       _mmcam_dbg_log("current [%c%c%c%c %dx%d, fps %d, rot %d], new [%c%c%c%c %dx%d, fps %d, rot %d]",
+                                       MMCAM_LOG_INFO("current [%c%c%c%c %dx%d, fps %d/%d, rot %d], new [%c%c%c%c %dx%d, fps %d, rot %d]",
                                                caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
-                                               caps_width, caps_height, caps_fps, caps_rotate,
+                                               caps_width, caps_height, caps_fps_n, caps_fps_d, caps_rotate,
                                                fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
                                                set_width, set_height, fps, set_rotate);
                                        do_set_caps = TRUE;
@@ -2634,23 +2758,23 @@ bool _mmcamcorder_set_videosrc_caps(MMHandleType handle, unsigned int fourcc, in
                        }
 #else /*_MMCAMCORDER_PRODUCT_TV */
                        if (set_width == caps_width && set_height == caps_height &&
-                           fourcc == caps_fourcc && set_rotate == caps_rotate && fps == caps_fps) {
-                               _mmcam_dbg_log("No need to replace caps.");
+                           fourcc == caps_fourcc && set_rotate == caps_rotate && fps == caps_fps_n) {
+                               MMCAM_LOG_INFO("No need to replace caps.");
                        } else {
-                               _mmcam_dbg_log("current [%c%c%c%c %dx%d, fps %d, rot %d], new [%c%c%c%c %dx%d, fps %d, rot %d]",
+                               MMCAM_LOG_INFO("current [%c%c%c%c %dx%d, fps %d/%d, rot %d], new [%c%c%c%c %dx%d, fps %d, rot %d]",
                                        caps_fourcc, caps_fourcc>>8, caps_fourcc>>16, caps_fourcc>>24,
-                                       caps_width, caps_height, caps_fps, caps_rotate,
+                                       caps_width, caps_height, caps_fps_n, caps_fps_d, caps_rotate,
                                        fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
                                        set_width, set_height, fps, set_rotate);
                                do_set_caps = TRUE;
                        }
 #endif /*_MMCAMCORDER_PRODUCT_TV */
                } else {
-                       _mmcam_dbg_log("can not get structure of caps. set new one...");
+                       MMCAM_LOG_INFO("can not get structure of caps. set new one...");
                        do_set_caps = TRUE;
                }
        } else {
-               _mmcam_dbg_log("No caps. set new one...");
+               MMCAM_LOG_INFO("No caps. set new one...");
                do_set_caps = TRUE;
        }
 
@@ -2659,90 +2783,24 @@ bool _mmcamcorder_set_videosrc_caps(MMHandleType handle, unsigned int fourcc, in
                caps = NULL;
        }
 
-       if (do_set_caps) {
-               if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
-#ifdef _MMCAMCORDER_PRODUCT_TV
-                       sinkpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, "sink");
-                       if (!sinkpad) {
-                               _mmcam_dbg_err("There are no decoder caps");
-                               return FALSE;
-                       }
-
-                       decsink_caps = gst_pad_get_pad_template_caps(sinkpad);
-                       if (!decsink_caps) {
-                               gst_object_unref(sinkpad);
-                               _mmcam_dbg_err("There is no decoder sink caps");
-                               return FALSE;
-                       }
-
-                       decsink_struct = gst_caps_get_structure(decsink_caps, 0);
-                       if (!decsink_struct) {
-                               _mmcam_dbg_err("There are no structure from caps");
-                               gst_object_unref(decsink_caps);
-                               gst_object_unref(sinkpad);
-                               return FALSE;
-                       }
-
-                       if (gst_structure_has_field(decsink_struct, "maxwidth"))
-                               gst_structure_get_int(decsink_struct, "maxwidth", &maxwidth);
-
-                       if (gst_structure_has_field(decsink_struct, "maxheight"))
-                               gst_structure_get_int(decsink_struct, "maxheight", &maxheight);
-#endif /* _MMCAMCORDER_PRODUCT_TV */
-
-                       caps = gst_caps_new_simple("video/x-h264",
-                               "width", G_TYPE_INT, set_width,
-                               "height", G_TYPE_INT, set_height,
-                               "framerate", GST_TYPE_FRACTION, fps, 1,
-                               "stream-format", G_TYPE_STRING, "byte-stream",
-#ifdef _MMCAMCORDER_PRODUCT_TV
-                               "maxwidth", G_TYPE_INT, maxwidth,
-                               "maxheight", G_TYPE_INT, maxheight,
-                               "alignment", G_TYPE_STRING, "au",
-#endif /* _MMCAMCORDER_PRODUCT_TV */
-                               NULL);
-
-#ifdef _MMCAMCORDER_PRODUCT_TV
-                       gst_object_unref(decsink_caps);
-                       gst_object_unref(sinkpad);
-#endif /* _MMCAMCORDER_PRODUCT_TV */
-               } else {
-                       char fourcc_string[sizeof(fourcc)+1];
-                       strncpy(fourcc_string, (char*)&fourcc, sizeof(fourcc));
-                       fourcc_string[sizeof(fourcc)] = '\0';
-                       caps = gst_caps_new_simple("video/x-raw",
-                               "format", G_TYPE_STRING, fourcc_string,
-                               "width", G_TYPE_INT, set_width,
-                               "height", G_TYPE_INT, set_height,
-                               "framerate", GST_TYPE_FRACTION, fps, 1,
-                               "rotate", G_TYPE_INT, set_rotate,
-                               NULL);
-               }
-
-               if (caps) {
-                       gchar *caps_str = gst_caps_to_string(caps);
-
-                       if (caps_str) {
-                               _mmcam_dbg_log("vidoesrc new caps set [%s]", caps_str);
-                               g_free(caps_str);
-                               caps_str = NULL;
-                       } else {
-                               _mmcam_dbg_warn("caps string failed");
-                       }
-
-                       MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", caps);
-                       gst_caps_unref(caps);
-                       caps = NULL;
-               } else {
-                       _mmcam_dbg_err("There are no caps");
-               }
-       }
-
        if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
                /* assume that it's camera capture mode */
                MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "csc-range", 1);
        }
 
+       if (!do_set_caps)
+               return TRUE;
+
+       caps = _mmcamcorder_get_video_caps(handle,
+               sc->info_image->preview_format, set_width, set_height, fps, set_rotate);
+       if (!caps) {
+               MMCAM_LOG_ERROR("There are no caps");
+               return FALSE;
+       }
+
+       MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", caps);
+       gst_caps_unref(caps);
+
        return TRUE;
 }
 
@@ -2758,7 +2816,7 @@ bool _mmcamcorder_set_videosrc_flip(MMHandleType handle, int videosrc_flip)
        if (!sc)
                return TRUE;
 
-       _mmcam_dbg_log("Set FLIP %d", videosrc_flip);
+       MMCAM_LOG_INFO("Set FLIP %d", videosrc_flip);
 
        if (sc->element && sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) {
                int hflip = 0;
@@ -2769,16 +2827,16 @@ bool _mmcamcorder_set_videosrc_flip(MMHandleType handle, int videosrc_flip)
                        hflip = (videosrc_flip & MM_FLIP_HORIZONTAL) == MM_FLIP_HORIZONTAL;
                        vflip = (videosrc_flip & MM_FLIP_VERTICAL) == MM_FLIP_VERTICAL;
 
-                       _mmcam_dbg_log("videosrc flip H:%d, V:%d", hflip, vflip);
+                       MMCAM_LOG_INFO("videosrc flip H:%d, V:%d", hflip, vflip);
 
                        MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "hflip", hflip);
                        MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "vflip", vflip);
                } else {
-                       _mmcam_dbg_warn("ITLV format does not support FLIP. Ignore FLIP[%d]",
+                       MMCAM_LOG_WARNING("ITLV format does not support FLIP. Ignore FLIP[%d]",
                                videosrc_flip);
                }
        } else {
-               _mmcam_dbg_warn("element is NULL");
+               MMCAM_LOG_WARNING("element is NULL");
                return FALSE;
        }
 
@@ -2803,7 +2861,7 @@ bool _mmcamcorder_set_videosrc_anti_shake(MMHandleType handle, int anti_shake)
        v_src = sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst;
 
        if (!v_src) {
-               _mmcam_dbg_warn("videosrc element is NULL");
+               MMCAM_LOG_WARNING("videosrc element is NULL");
                return FALSE;
        }
 
@@ -2811,16 +2869,16 @@ bool _mmcamcorder_set_videosrc_anti_shake(MMHandleType handle, int anti_shake)
 
        /* set anti-shake with camera control */
        if (!GST_IS_CAMERA_CONTROL(v_src)) {
-               _mmcam_dbg_warn("Can't cast Video source into camera control.");
+               MMCAM_LOG_WARNING("Can't cast Video source into camera control.");
                return FALSE;
        }
 
        control = GST_CAMERA_CONTROL(v_src);
        if (gst_camera_control_set_ahs(control, set_value)) {
-               _mmcam_dbg_log("Succeed in operating anti-handshake. value[%d]", set_value);
+               MMCAM_LOG_INFO("Succeed in operating anti-handshake. value[%d]", set_value);
                return TRUE;
        } else {
-               _mmcam_dbg_warn("Failed to operate anti-handshake. value[%d]", set_value);
+               MMCAM_LOG_WARNING("Failed to operate anti-handshake. value[%d]", set_value);
        }
 
        return FALSE;
@@ -2840,7 +2898,7 @@ bool _mmcamcorder_set_videosrc_stabilization(MMHandleType handle, int stabilizat
 
        v_src = sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst;
        if (!v_src) {
-               _mmcam_dbg_warn("videosrc element is NULL");
+               MMCAM_LOG_WARNING("videosrc element is NULL");
                return FALSE;
        }
 
@@ -2850,7 +2908,7 @@ bool _mmcamcorder_set_videosrc_stabilization(MMHandleType handle, int stabilizat
                int video_height = 0;
 
                if (stabilization == MM_CAMCORDER_VIDEO_STABILIZATION_ON) {
-                       _mmcam_dbg_log("ENABLE video stabilization");
+                       MMCAM_LOG_INFO("ENABLE video stabilization");
 
                        /* VDIS mode only supports NV12 and [720p or 1080p or 1088 * 1088] */
                        mm_camcorder_get_attributes(handle, NULL,
@@ -2859,14 +2917,14 @@ bool _mmcamcorder_set_videosrc_stabilization(MMHandleType handle, int stabilizat
                                NULL);
 
                        if (sc->info_image->preview_format == MM_PIXEL_FORMAT_NV12 && video_width >= 1080 && video_height >= 720) {
-                               _mmcam_dbg_log("NV12, video size %dx%d, ENABLE video stabilization",
+                               MMCAM_LOG_INFO("NV12, video size %dx%d, ENABLE video stabilization",
                                        video_width, video_height);
                                /* set vdis mode */
                                g_object_set(G_OBJECT(v_src),
                                                         "enable-vdis-mode", TRUE,
                                                         NULL);
                        } else {
-                               _mmcam_dbg_warn("invalid preview format %c%c%c%c or video size %dx%d",
+                               MMCAM_LOG_WARNING("invalid preview format %c%c%c%c or video size %dx%d",
                                                                sc->fourcc, sc->fourcc>>8, sc->fourcc>>16, sc->fourcc>>24,
                                                                video_width, video_height);
                                return FALSE;
@@ -2877,13 +2935,13 @@ bool _mmcamcorder_set_videosrc_stabilization(MMHandleType handle, int stabilizat
                                                "enable-vdis-mode", FALSE,
                                                NULL);
 
-                       _mmcam_dbg_log("DISABLE video stabilization");
+                       MMCAM_LOG_INFO("DISABLE video stabilization");
                }
        } else if (stabilization == MM_CAMCORDER_VIDEO_STABILIZATION_ON) {
-               _mmcam_dbg_err("no property for video stabilization, so can not set ON");
+               MMCAM_LOG_ERROR("no property for video stabilization, so can not set ON");
                return FALSE;
        } else {
-               _mmcam_dbg_warn("no property for video stabilization");
+               MMCAM_LOG_WARNING("no property for video stabilization");
        }
 
        return TRUE;
@@ -2907,7 +2965,7 @@ bool _mmcamcorder_set_camera_resolution(MMHandleType handle, int width, int heig
                MMCAM_CAMERA_FPS, &fps,
                NULL);
 
-       _mmcam_dbg_log("set %dx%d", width, height);
+       MMCAM_LOG_INFO("set %dx%d", width, height);
 
        return _mmcamcorder_set_videosrc_caps(handle, sc->fourcc, width, height, fps, sc->videosrc_rotate);
 }
@@ -2916,72 +2974,54 @@ bool _mmcamcorder_set_camera_resolution(MMHandleType handle, int width, int heig
 bool _mmcamcorder_set_encoded_preview_bitrate(MMHandleType handle, int bitrate)
 {
        _MMCamcorderSubContext *sc = NULL;
-       GstCameraControl *CameraControl = NULL;
-       GstCameraControlChannel *CameraControlChannel = NULL;
-       const GList *controls = NULL;
-       const GList *item = NULL;
 
        if ((void *)handle == NULL) {
-               _mmcam_dbg_warn("handle is NULL");
+               MMCAM_LOG_WARNING("handle is NULL");
                return FALSE;
        }
 
        sc = MMF_CAMCORDER_SUBCONTEXT(handle);
        if (!sc) {
-               _mmcam_dbg_warn("subcontext is NULL");
+               MMCAM_LOG_WARNING("subcontext is NULL");
                return FALSE;
        }
 
        if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst == NULL) {
-               _mmcam_dbg_warn("videosrc plugin is NULL");
+               MMCAM_LOG_WARNING("videosrc plugin is NULL");
                return FALSE;
        }
 
-       _mmcam_dbg_log("set encoded preview bitrate : %d bps", bitrate);
+       MMCAM_LOG_INFO("set encoded preview bitrate : %d bps", bitrate);
 
-       CameraControl = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
-       controls = gst_camera_control_list_channels(CameraControl);
-       _mmcam_dbg_log("controls : %p", controls);
-       if (controls != NULL) {
-               for (item = controls ; item && item->data ; item = item->next) {
-                       CameraControlChannel = item->data;
-                       _mmcam_dbg_log("label : %s", CameraControlChannel->label);
-                       if (!strcmp(CameraControlChannel->label, "bitrate")) {
-                               _mmcam_dbg_log("set encoded preview bitrate %d", bitrate);
-                               return gst_camera_control_set_value(CameraControl, CameraControlChannel, bitrate);
-                       }
-               }
-
-               _mmcam_dbg_warn("failed to find \"bitrate\" control channel");
-       }
+       MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "bitrate", bitrate);
 
-       return FALSE;
+       return TRUE;
 }
 
 
-bool _mmcamcorder_set_encoded_preview_gop_interval(MMHandleType handle, int interval)
+bool _mmcamcorder_set_encoded_preview_gop_interval(MMHandleType handle, int gop_interval)
 {
        _MMCamcorderSubContext *sc = NULL;
 
        if ((void *)handle == NULL) {
-               _mmcam_dbg_warn("handle is NULL");
+               MMCAM_LOG_WARNING("handle is NULL");
                return FALSE;
        }
 
        sc = MMF_CAMCORDER_SUBCONTEXT(handle);
        if (!sc) {
-               _mmcam_dbg_warn("subcontext is NULL");
+               MMCAM_LOG_WARNING("subcontext is NULL");
                return FALSE;
        }
 
        if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst == NULL) {
-               _mmcam_dbg_warn("videosrc plugin is NULL");
+               MMCAM_LOG_WARNING("videosrc plugin is NULL");
                return FALSE;
        }
 
-       _mmcam_dbg_log("set encoded preview GOP interval : %d ms", interval);
+       MMCAM_LOG_INFO("set encoded preview GOP interval : %d ms", gop_interval);
 
-       MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "newgop-interval", interval);
+       MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "gop-interval", gop_interval);
 
        return TRUE;
 }
@@ -2993,7 +3033,7 @@ bool _mmcamcorder_set_sound_stream_info(GstElement *element, char *stream_type,
        char stream_props[64] = {'\0',};
 
        if (element == NULL || stream_type == NULL || stream_index < 0) {
-               _mmcam_dbg_err("invalid argument %p %p %d", element, stream_type, stream_index);
+               MMCAM_LOG_ERROR("invalid argument %p %p %d", element, stream_type, stream_index);
                return FALSE;
        }
 
@@ -3001,11 +3041,11 @@ bool _mmcamcorder_set_sound_stream_info(GstElement *element, char *stream_type,
                "props,media.role=%s, media.parent_id=%d",
                stream_type, stream_index);
 
-       _mmcam_dbg_warn("stream type %s, index %d -> [%s]", stream_type, stream_index, stream_props);
+       MMCAM_LOG_WARNING("stream type %s, index %d -> [%s]", stream_type, stream_index, stream_props);
 
        props = gst_structure_from_string(stream_props, NULL);
        if (!props) {
-               _mmcam_dbg_err("failed to create GstStructure");
+               MMCAM_LOG_ERROR("failed to create GstStructure");
                return FALSE;
        }
 
@@ -3024,13 +3064,14 @@ bool _mmcamcorder_recreate_decoder_for_encoded_preview(MMHandleType handle)
        _MMCamcorderSubContext *sc = NULL;
        mmf_camcorder_t *hcamcorder = NULL;
        const char *videodecoder_name = NULL;
+       char videodecoder_name_final[32] = {'\0',};
+       int display_surface_type = MM_DISPLAY_SURFACE_NULL;
 #ifdef _MMCAMCORDER_RM_SUPPORT
-       char decoder_name[20] = {'\0',};
        int decoder_index = 0;
 #endif /* _MMCAMCORDER_RM_SUPPORT */
 
        if ((void *)handle == NULL) {
-               _mmcam_dbg_warn("handle is NULL");
+               MMCAM_LOG_WARNING("handle is NULL");
                return FALSE;
        }
 
@@ -3038,73 +3079,88 @@ bool _mmcamcorder_recreate_decoder_for_encoded_preview(MMHandleType handle)
 
        sc = MMF_CAMCORDER_SUBCONTEXT(handle);
        if (!sc) {
-               _mmcam_dbg_warn("subcontext is NULL");
+               MMCAM_LOG_WARNING("subcontext is NULL");
                return FALSE;
        }
 
-       if (sc->info_image->preview_format != MM_PIXEL_FORMAT_ENCODED_H264 ||
+       if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format) == false ||
                hcamcorder->recreate_decoder == FALSE) {
-               _mmcam_dbg_log("skip this fuction - format %d, recreate decoder %d",
+               MMCAM_LOG_INFO("skip this fuction - format %d, recreate decoder %d",
                        sc->info_image->preview_format, hcamcorder->recreate_decoder);
                return TRUE;
        }
 
+       mm_camcorder_get_attributes(handle, NULL,
+               MMCAM_DISPLAY_SURFACE, &display_surface_type,
+               NULL);
+
+       if (display_surface_type == MM_DISPLAY_SURFACE_NULL) {
+               MMCAM_LOG_INFO("no need to control decoder element");
+               return TRUE;
+       }
+
        if (sc->element[_MMCAMCORDER_MAIN_PIPE].gst == NULL ||
            sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst == NULL) {
-               _mmcam_dbg_warn("main pipeline or decoder plugin is NULL");
+               MMCAM_LOG_WARNING("main pipeline or decoder plugin is NULL");
                return FALSE;
        }
 
-       _mmcam_dbg_log("start");
+       MMCAM_LOG_INFO("start");
 
-       _mmcamcorder_conf_get_value_element_name(sc->VideodecoderElementH264, &videodecoder_name);
+       _mmcamcorder_conf_get_value_element_name(sc->VideodecoderElement, &videodecoder_name);
        if (videodecoder_name == NULL) {
-               _mmcam_dbg_err("failed to get decoder element name from %p", sc->VideodecoderElementH264);
+               MMCAM_LOG_ERROR("failed to get decoder element name from %p", sc->VideodecoderElement);
                return FALSE;
        }
 
        /* set state as NULL */
        ret = _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, GST_STATE_NULL);
        if (ret != MM_ERROR_NONE) {
-               _mmcam_dbg_err("failed to set NULL to decoder");
+               MMCAM_LOG_ERROR("failed to set NULL to decoder");
                return FALSE;
        }
 
        /* remove decoder - pads will be unlinked automatically in remove function */
        if (!gst_bin_remove(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst),
                            sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)) {
-               _mmcam_dbg_err("failed to remove decoder from pipeline");
+               MMCAM_LOG_ERROR("failed to remove decoder from pipeline");
                return FALSE;
        }
 
        /* check decoder element */
        if (sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst) {
-               _mmcam_dbg_log("decoder[%p] is still alive - ref count %d",
+               MMCAM_LOG_INFO("decoder[%p] is still alive - ref count %d",
                        G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
                        ((GObject *)sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)->ref_count);
        }
 
 #ifdef _MMCAMCORDER_RM_SUPPORT
-       if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER_SUB)
-               decoder_index = 1;
+       if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
+               if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER_SUB)
+                       decoder_index = 1;
+
+               snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s%d", videodecoder_name, decoder_index);
+       } else if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_MJPEG) {
+               /* MJPEG */
+               if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER)
+                       snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_uhd_mjpegdec");
+               else
+                       snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_mjpegdec");
+       } else {
+#endif /* _MMCAMCORDER_RM_SUPPORT */
+               snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", videodecoder_name);
+#ifdef _MMCAMCORDER_RM_SUPPORT
+       }
+#endif /* _MMCAMCORDER_RM_SUPPORT */
 
-       snprintf(decoder_name, sizeof(decoder_name)-1, "%s%d", videodecoder_name, decoder_index);
-       _mmcam_dbg_log("encoded preview decoder_name %s", decoder_name);
        /* create decoder */
-       sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst = gst_element_factory_make(decoder_name, "videosrc_decode");
-       if (sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst == NULL) {
-               _mmcam_dbg_err("Decoder[%s] creation fail", decoder_name);
-               return FALSE;
-       }
-#else /* _MMCAMCORDER_RM_SUPPORT */
-       /* create new decoder */
-       sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst = gst_element_factory_make(videodecoder_name, "videosrc_decode");
+       sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst = gst_element_factory_make(videodecoder_name_final, "videosrc_decode");
        if (sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst == NULL) {
-               _mmcam_dbg_err("Decoder [%s] creation fail", videodecoder_name);
+               MMCAM_LOG_ERROR("Decoder[%s] creation fail", videodecoder_name_final);
                return FALSE;
        }
-#endif /* _MMCAMCORDER_RM_SUPPORT */
-       _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, sc->VideodecoderElementH264);
+
+       _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, sc->VideodecoderElement);
 
        sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].id = _MMCAMCORDER_VIDEOSRC_DECODE;
        g_object_weak_ref(G_OBJECT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
@@ -3113,7 +3169,7 @@ bool _mmcamcorder_recreate_decoder_for_encoded_preview(MMHandleType handle)
        /* add to pipeline */
        if (!gst_bin_add(GST_BIN(sc->element[_MMCAMCORDER_MAIN_PIPE].gst),
                sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst)) {
-               _mmcam_dbg_err("failed to add decoder to pipeline");
+               MMCAM_LOG_ERROR("failed to add decoder to pipeline");
                gst_object_unref(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst);
                return FALSE;
        }
@@ -3121,28 +3177,97 @@ bool _mmcamcorder_recreate_decoder_for_encoded_preview(MMHandleType handle)
        /* link */
        if (_MM_GST_ELEMENT_LINK(GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst),
                GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst))) {
-               _mmcam_dbg_log("Link videosrc_queue to decoder OK");
+               MMCAM_LOG_INFO("Link videosrc_queue to decoder OK");
        } else {
-               _mmcam_dbg_err("Link videosrc_queue to decoder FAILED");
+               MMCAM_LOG_ERROR("Link videosrc_queue to decoder FAILED");
                return FALSE;
        }
 
        if (_MM_GST_ELEMENT_LINK(GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst),
                GST_ELEMENT(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst))) {
-               _mmcam_dbg_log("Link decoder to videosink_queue OK");
+               MMCAM_LOG_INFO("Link decoder to videosink_queue OK");
        } else {
-               _mmcam_dbg_err("Link decoder to videosink_queue FAILED");
+               MMCAM_LOG_ERROR("Link decoder to videosink_queue FAILED");
                return FALSE;
        }
 
        /* set state READY */
        ret = _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, GST_STATE_READY);
        if (ret != MM_ERROR_NONE) {
-               _mmcam_dbg_err("failed to set READY to decoder");
+               MMCAM_LOG_ERROR("failed to set READY to decoder");
                return FALSE;
        }
 
-       _mmcam_dbg_log("done");
+       MMCAM_LOG_INFO("done");
 
        return TRUE;
 }
+
+#ifdef _MMCAMCORDER_PRODUCT_TV
+bool __mmcamcorder_find_max_resolution(MMHandleType handle, gint *max_width, gint *max_height)
+{
+       _MMCamcorderSubContext *sc = NULL;
+       mmf_camcorder_t *hcamcorder = NULL;
+       int index = 0;
+       const gchar *mime = NULL;
+       GstPad *sinkpad;
+       GstCaps *decsink_caps = NULL;
+       GstStructure *decsink_struct = NULL;
+
+       mmf_return_val_if_fail(handle, false);
+       mmf_return_val_if_fail(max_width, false);
+       mmf_return_val_if_fail(max_height, false);
+
+       hcamcorder = MMF_CAMCORDER(handle);
+       mmf_return_val_if_fail(hcamcorder, false);
+
+       sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder);
+
+       sinkpad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, "sink");
+       if (!sinkpad) {
+               MMCAM_LOG_ERROR("There are no decoder caps");
+               return false;
+       }
+
+       decsink_caps = gst_pad_get_pad_template_caps(sinkpad);
+       if (!decsink_caps) {
+               gst_object_unref(sinkpad);
+               MMCAM_LOG_ERROR("There is no decoder sink caps");
+               return false;
+       }
+
+       for (index = 0; index < gst_caps_get_size(decsink_caps); index++) {
+               decsink_struct = gst_caps_get_structure(decsink_caps, index);
+               if (!decsink_struct) {
+                       MMCAM_LOG_ERROR("There are no structure from caps");
+                       gst_object_unref(decsink_caps);
+                       gst_object_unref(sinkpad);
+                       return false;
+               }
+               mime = gst_structure_get_name(decsink_struct);
+               if (!strcmp(mime, "video/x-h264")) {
+                       MMCAM_LOG_INFO("h264 caps structure found");
+                       if (gst_structure_has_field(decsink_struct, "maxwidth"))
+                               *max_width = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxwidth"));
+                       if (gst_structure_has_field(decsink_struct, "maxheight"))
+                               *max_height = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxheight"));
+                       break;
+               } else if (!strcmp(mime, "video/x-jpeg")) {
+                       MMCAM_LOG_INFO("mjpeg caps structure found");
+                       if (gst_structure_has_field(decsink_struct, "maxwidth"))
+                               *max_width = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxwidth"));
+                       if (gst_structure_has_field(decsink_struct, "maxheight"))
+                               *max_height = gst_value_get_int_range_max(gst_structure_get_value(decsink_struct, "maxheight"));
+                       break;
+               }
+       }
+       MMCAM_LOG_INFO("maxwidth = %d , maxheight = %d", (int)*max_width, (int)*max_height);
+       gst_object_unref(decsink_caps);
+       gst_object_unref(sinkpad);
+
+       if (*max_width <= 0 || *max_height <= 0)
+               return false;
+
+       return true;
+}
+#endif /* _MMCAMCORDER_PRODUCT_TV */