Fix build error for product TV
[platform/core/multimedia/libmm-camcorder.git] / src / mm_camcorder_gstcommon.c
index 39c5285..362421c 100644 (file)
@@ -25,7 +25,6 @@
 #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>
@@ -40,7 +39,7 @@
 |    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},
@@ -130,6 +129,7 @@ gboolean    videocodec_fileformat_compatibility_table[MM_VIDEO_CODEC_NUM][MM_FILE_F
 #define _MMCAMCORDER_CONVERT_OUTPUT_BUFFER_NUM    6
 #define _MMCAMCORDER_NANOSEC_PER_1SEC             1000000000
 #define _MMCAMCORDER_NANOSEC_PER_1MILISEC         1000
+#define _MMCAMCORDER_SIGNAL_REQUEST_CODEC_CONFIG  "request-codec-config"
 
 
 /*-----------------------------------------------------------------------
@@ -152,22 +152,25 @@ static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstP
 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);
-#ifdef _MMCAMCORDER_PRODUCT_TV
-static bool __mmcamcorder_find_max_resolution(MMHandleType handle, gint *max_width, gint *max_height);
-#endif /* _MMCAMCORDER_PRODUCT_TV */
+static guint32 _mmcamcorder_get_structure_fourcc(const GstStructure *structure);
 
-static gboolean __mmcamcorder_set_stream_data_tbm(MMCamcorderVideoStreamDataType *stream, tbm_surface_info_s *ts_info);
-static gboolean __mmcamcorder_set_stream_data_normal(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMapInfo *map_info);
+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                                                                 |
 =======================================================================================*/
-static gboolean __mmcamcorder_set_stream_data_normal(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMapInfo *map_info)
+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(map_info, 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 */
@@ -225,8 +228,10 @@ static gboolean __mmcamcorder_set_stream_data_normal(MMCamcorderVideoStreamDataT
                stream->num_planes = 1;
                break;
 
-       case MM_PIXEL_FORMAT_ENCODED_H264: /* fall through */
-       case MM_PIXEL_FORMAT_ENCODED_MJPEG:
+       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;
@@ -255,38 +260,109 @@ static gboolean __mmcamcorder_set_stream_data_normal(MMCamcorderVideoStreamDataT
 
        default:
                MMCAM_LOG_ERROR("unsupported format[%d]", stream->format);
-               return FALSE;
+               ret = FALSE;
+               break;
        }
 
-       return TRUE;
+       return ret;
 }
 
 
-static gboolean __mmcamcorder_set_stream_data_tbm(MMCamcorderVideoStreamDataType *stream, tbm_surface_info_s *ts_info)
+static gboolean __mmcamcorder_set_stream_data_zero_copy(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMemory *memory)
 {
-       mmf_return_val_if_fail(ts_info, FALSE);
+       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;
+               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;
+               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:
@@ -298,116 +374,116 @@ static gboolean __mmcamcorder_set_stream_data_tbm(MMCamcorderVideoStreamDataType
 }
 
 
-gboolean _mmcamcorder_invoke_video_stream_cb(MMHandleType handle, GstBuffer *buffer, gboolean is_preview)
+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;
-       int num_bos = 0;
        gboolean ret_cb = TRUE;
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
        _MMCamcorderSubContext *sc = NULL;
        MMCamcorderVideoStreamDataType stream;
 
-       tbm_surface_h t_surface = NULL;
-       tbm_surface_info_s ts_info;
-
+       GstBuffer *buffer = NULL;
        GstMemory *memory = NULL;
        GstMapInfo map_info;
        GstCaps *caps = NULL;
-       GstPad *pad = 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);
 
-       /* clear data structure */
-       memset(&map_info, 0x0, sizeof(GstMapInfo));
        memset(&stream, 0x0, sizeof(MMCamcorderVideoStreamDataType));
 
-       stream.format = sc->info_image->preview_format;
-       if (is_preview) {
-               /* preview buffer - get resolution from caps */
-               pad = gst_element_get_static_pad(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "src");
-               mmf_return_val_if_fail(pad, FALSE);
+       caps = gst_sample_get_caps(sample);
+       mmf_return_val_if_fail(caps, FALSE);
 
-               caps = gst_pad_get_allowed_caps(pad);
-               if (!caps) {
-                       MMCAM_LOG_ERROR("failed to get caps from pad %p", pad);
-                       gst_object_unref(pad);
-                       return FALSE;
-               }
+       structure = gst_caps_get_structure(caps, 0);
+       mmf_return_val_if_fail(structure, FALSE);
 
-               structure = gst_caps_get_structure(caps, 0);
-               if (!structure) {
-                       MMCAM_LOG_ERROR("failed to get structure from caps %p", caps);
-                       gst_caps_unref(caps);
-                       gst_object_unref(pad);
-                       return FALSE;
-               }
-
-               gst_structure_get_int(structure, "width", &stream.width);
-               gst_structure_get_int(structure, "height", &stream.height);
-
-               gst_caps_unref(caps);
-               caps = NULL;
-               gst_object_unref(pad);
-               pad = NULL;
-       } else {
-               /* video recording buffer */
-               stream.width = sc->info_video->video_width;
-               stream.height = sc->info_video->video_height;
-       }
+       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);
 
-       /* set size and timestamp */
-       if (_mmcamcorder_is_encoded_preview_pixel_format(stream.format))
-               memory = gst_buffer_get_all_memory(buffer);
-       else
-               memory = gst_buffer_peek_memory(buffer, 0);
+       memory = gst_buffer_peek_memory(buffer, 0);
        if (!memory) {
                MMCAM_LOG_ERROR("GstMemory get failed from buffer %p", buffer);
                return FALSE;
        }
 
-       /* set zero-copy related information */
-       if (hcamcorder->use_zero_copy_format) {
-               t_surface = (tbm_surface_h)gst_tizen_memory_get_surface(memory);
-
-               if (tbm_surface_get_info(t_surface, &ts_info) != TBM_SURFACE_ERROR_NONE) {
-                       MMCAM_LOG_ERROR("failed to get tbm surface[%p] info", t_surface);
-                       goto _INVOKE_VIDEO_STREAM_CB_DONE;
-               }
-
-               /* 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 < 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]);
-               }
+       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);
 
-               stream.length_total = ts_info.size;
-               stream.internal_buffer = buffer;
+               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 (!__mmcamcorder_set_stream_data_tbm(&stream, &ts_info))
+       if (gst_is_tizen_memory(memory)) {
+               if (!__mmcamcorder_set_stream_data_zero_copy(&stream, buffer, memory))
                        goto _INVOKE_VIDEO_STREAM_CB_DONE;
        } else {
-               stream.length_total = gst_memory_get_sizes(memory, NULL, NULL);
+               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 (!gst_memory_map(memory, &map_info, GST_MAP_READWRITE) ||
-                       !__mmcamcorder_set_stream_data_normal(&stream, buffer, &map_info))
+               if (!__mmcamcorder_set_stream_data(&stream, buffer, &map_info))
                        goto _INVOKE_VIDEO_STREAM_CB_DONE;
        }
 
-       MMCAM_LOG_DEBUG("VideoStreamData : resolution[%dx%d], format[%d]",
-               stream.width, stream.height, stream.format);
+       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) {
@@ -423,17 +499,14 @@ gboolean _mmcamcorder_invoke_video_stream_cb(MMHandleType handle, GstBuffer *buf
        }
 
 _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]);
        }
 
-       if (map_info.data)
-               gst_memory_unmap(memory, &map_info);
-
-       if (_mmcamcorder_is_encoded_preview_pixel_format(stream.format))
-               gst_memory_unref(memory);
-
        return ret_cb;
 }
 
@@ -448,31 +521,33 @@ int _mmcamcorder_create_preview_elements(MMHandleType handle)
        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);
@@ -514,9 +589,9 @@ 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_LOG_WARNING("Get attrs fail. (%s:%x)", err_name, err);
@@ -542,12 +617,9 @@ int _mmcamcorder_create_preview_elements(MMHandleType handle)
        /* 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
@@ -556,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);
 
@@ -580,14 +659,18 @@ int _mmcamcorder_create_preview_elements(MMHandleType handle)
                MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "high-speed-fps", fps);
 
        /* Set basic information of videosrc element */
-       _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, VideosrcElement);
+       _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, videosrc_element);
 
        /* Set video device index */
+       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);
+               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);
+               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) {
@@ -606,83 +689,65 @@ int _mmcamcorder_create_preview_elements(MMHandleType handle)
                        &hcamcorder->recreate_decoder);
        }
 
-       if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
-               int preview_bitrate = 0;
-               int gop_interval = 0;
-               mm_camcorder_get_attributes(handle, NULL,
-                       MMCAM_ENCODED_PREVIEW_BITRATE, &preview_bitrate,
-                       MMCAM_ENCODED_PREVIEW_GOP_INTERVAL, &gop_interval,
-                       NULL);
+       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;
+               }
 
-               /* set encoded preview bitrate */
-               if (!_mmcamcorder_set_encoded_preview_bitrate(handle, preview_bitrate))
-                       MMCAM_LOG_WARNING("_mmcamcorder_set_encoded_preview_bitrate failed");
+               /* get video decoder element and name */
+               _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
+                       CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
+                       decoder_conf_name,
+                       &sc->VideodecoderElement);
 
-               /* set encoded preview iframe interval */
-               if (!_mmcamcorder_set_encoded_preview_gop_interval(handle, gop_interval))
-                       MMCAM_LOG_WARNING("_mmcamcorder_set_encoded_preview_gop_interval failed");
-       }
+               _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 (display_surface_type != MM_DISPLAY_SURFACE_NULL) {
-               const char *videodecoder_name = NULL;
-               /* case of decoder element */
-               if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
-                       /* get video decoder element and name for H.264 format */
-                       _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
-                               CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
-                               "VideodecoderElementH264",
-                               &sc->VideodecoderElementH264);
-                       _mmcamcorder_conf_get_value_element_name(sc->VideodecoderElementH264,
-                               &videodecoder_name);
-                       if (videodecoder_name) {
 #ifdef _MMCAMCORDER_RM_SUPPORT
-                               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_LOG_INFO("encoded preview decoder_name [%s], video decoder element [%s]",
-                                       decoder_name, videodecoder_name);
-                               /* create decoder element */
-                               _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_DECODE, decoder_name, "videosrc_decode", element_list, err);
-#else /* _MMCAMCORDER_RM_SUPPORT */
-                               MMCAM_LOG_INFO("video decoder element [%s]", videodecoder_name);
-                               /* 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);
-                       } else {
-                               MMCAM_LOG_ERROR("failed to get video decoder element name from %p", sc->VideodecoderElementH264);
-                               goto pipeline_creation_error;
-                       }
+               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(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) {
-#ifdef _MMCAMCORDER_RM_SUPPORT
-                       /* get video decoder element and name for MJPEG format */
-                       _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main,
-                               CONFIGURE_CATEGORY_MAIN_VIDEO_OUTPUT,
-                               "VideodecoderElementH264",
-                               &sc->VideodecoderElementH264);
-                       _mmcamcorder_conf_get_value_element_name(sc->VideodecoderElementH264,
-                               &videodecoder_name);
-                       if (videodecoder_name) {
-                               if (hcamcorder->request_resources.category_id[0] == RM_CATEGORY_VIDEO_DECODER)
-                                       snprintf(decoder_name, sizeof(decoder_name)-1, "%s", "omx_uhd_mjpegdec");
-                               else
-                                       snprintf(decoder_name, sizeof(decoder_name)-1, "%s", "omx_mjpegdec");
-                               MMCAM_LOG_INFO("encoded preview decoder_name [%s], video decoder element [%s]",
-                                       decoder_name, videodecoder_name);
-                               /* create decoder element */
-                               _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_DECODE, decoder_name, "videosrc_decode", element_list, err);
-                               _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, sc->VideodecoderElementH264);
-                       } else {
-                               MMCAM_LOG_ERROR("failed to get video decoder element name from %p", sc->VideodecoderElementH264);
-                               goto pipeline_creation_error;
-                       }
-#else /* _MMCAMCORDER_RM_SUPPORT */
-                       MMCAM_LOG_INFO("video decoder element [jpegdec]");
-                       /* create decoder element */
-                       _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_DECODE, "jpegdec", "videosrc_decode", element_list, err);
+                       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 */
+
+               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);
+
+               _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_DECODE, videodecoder_name_final, "videosrc_decode", element_list, err);
+
+               _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_DECODE].gst, sc->VideodecoderElement);
        }
 
        MMCAM_LOG_INFO("Current mode[%d]", hcamcorder->type);
@@ -699,67 +764,50 @@ int _mmcamcorder_create_preview_elements(MMHandleType handle)
 
        MMCAM_LOG_INFO("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);
-
-               err = mm_camcorder_get_attributes(handle, &err_name,
-                       MMCAM_DISPLAY_SOCKET_PATH, &socket_path, &socket_path_len,
-                       NULL);
-               if (err != MM_ERROR_NONE) {
-                       MMCAM_LOG_WARNING("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_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");
-               }
+               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_LOG_INFO("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_LOG_WARNING("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_LOG_ERROR("_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 */
@@ -789,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);
@@ -834,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);
 
@@ -891,11 +938,9 @@ int _mmcamcorder_create_audiosrc_bin(MMHandleType handle)
                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;
@@ -908,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,
@@ -1274,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) {
@@ -1351,8 +1397,10 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin
                }
 
                if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
-                       /* set dummy element */
-                       gst_element_venc_name = "identity";
+                       /* 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);
                }
@@ -1536,7 +1584,7 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin
        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;
@@ -1548,7 +1596,7 @@ 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;
@@ -1560,7 +1608,7 @@ 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;
@@ -1572,7 +1620,7 @@ 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;
@@ -1618,9 +1666,6 @@ pipeline_creation_error:
        if (element_list)
                g_list_free(element_list);
 
-       if (video_caps)
-               gst_caps_unref(video_caps);
-
        if (videoscale_caps)
                gst_caps_unref(videoscale_caps);
 
@@ -1690,15 +1735,26 @@ int _mmcamcorder_create_preview_pipeline(MMHandleType handle)
 
        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:
@@ -1721,7 +1777,8 @@ 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->push_encoding_buffer = PUSH_ENCODING_BUFFER_RUN;
-               MMCAM_LOG_WARNING("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");
        }
 }
 
@@ -1743,9 +1800,6 @@ 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 *dp_handle = NULL;
        MMCamWindowInfo *window_info = NULL;
        gulong xid;
@@ -1813,12 +1867,6 @@ int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* Videosi
                        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_LOG_INFO("videosink : %s, handle : %p", videosink_name, dp_handle);
 
@@ -1838,6 +1886,11 @@ int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* Videosi
                        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)",
@@ -1855,11 +1908,6 @@ int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* Videosi
                } else {
                        MMCAM_LOG_WARNING("dp_handle is null");
                }
-#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 {
                MMCAM_LOG_WARNING("Who are you?? (Videosink: %s)", videosink_name);
        }
@@ -1998,17 +2046,47 @@ gboolean _mmcamcorder_get_device_info(MMHandleType handle)
        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)
 {
+       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);
@@ -2032,50 +2110,29 @@ static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstP
                return GST_PAD_PROBE_DROP;
        }
 
-       if (hcamcorder->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_LOG_INFO("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_LOG_INFO("current fps(%d), average(%d)", kpi->current_fps, kpi->average_fps);
-                       */
-               }
-       }
+       if (hcamcorder->measure_preview_fps && hcamcorder->state >= MM_CAMCORDER_STATE_PREPARE)
+               _mmcamcorder_measure_fps(&sc->kpi);
 
        /* The first H.264 frame should not be skipped for vstream cb. */
        if (hcamcorder->state < MM_CAMCORDER_STATE_PREPARE &&
-               sc->info_image->preview_format != MM_PIXEL_FORMAT_ENCODED_H264) {
+               !_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) {
                MMCAM_LOG_WARNING("Not ready for stream callback");
                return GST_PAD_PROBE_OK;
        }
 
-       if (_mmcamcorder_invoke_video_stream_cb((MMHandleType)hcamcorder, buffer, TRUE))
+       /* make sample with buffer and caps */
+       caps = gst_pad_get_allowed_caps(pad);
+       mmf_return_val_if_fail(caps, GST_PAD_PROBE_OK);
+
+       sample = gst_sample_new(buffer, caps, NULL, NULL);
+       gst_caps_unref(caps);
+       mmf_return_val_if_fail(sample, GST_PAD_PROBE_OK);
+
+       ret = _mmcamcorder_invoke_video_stream_cb((MMHandleType)hcamcorder, sample, TRUE, -1);
+
+       gst_sample_unref(sample);
+
+       if (ret)
                return GST_PAD_PROBE_OK;
        else
                return GST_PAD_PROBE_DROP;
@@ -2084,10 +2141,22 @@ static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstP
 
 static GstPadProbeReturn __mmcamcorder_video_dataprobe_record(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
 {
-       if (_mmcamcorder_video_push_buffer(u_data, GST_PAD_PROBE_INFO_BUFFER(info)))
-               return GST_PAD_PROBE_OK;
+       gboolean ret = TRUE;
+       GstSample *sample = NULL;
+       GstCaps *caps = NULL;
+
+       caps = gst_pad_get_allowed_caps(pad);
+       mmf_return_val_if_fail(caps, GST_PAD_PROBE_OK);
+
+       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);
+
+       ret = _mmcamcorder_video_push_buffer(u_data, sample);
 
-       return GST_PAD_PROBE_DROP;
+       gst_sample_unref(sample);
+
+       return (ret ? GST_PAD_PROBE_OK : GST_PAD_PROBE_DROP);
 }
 
 
@@ -2553,7 +2622,6 @@ 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;
 
        mmf_camcorder_t *hcamcorder = NULL;
@@ -2647,42 +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 (_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) {
+                                       set_rotate == caps_rotate && fps == caps_fps_n) {
                                        MMCAM_LOG_INFO("No need to replace caps.");
                                } else {
-                                       MMCAM_LOG_INFO("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) {
+                                   fourcc == caps_fourcc && set_rotate == caps_rotate && fps == caps_fps_n) {
                                        MMCAM_LOG_INFO("No need to replace caps.");
                                } else {
-                                       MMCAM_LOG_INFO("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;
@@ -2690,12 +2758,12 @@ 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) {
+                           fourcc == caps_fourcc && set_rotate == caps_rotate && fps == caps_fps_n) {
                                MMCAM_LOG_INFO("No need to replace caps.");
                        } else {
-                               MMCAM_LOG_INFO("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;
@@ -2715,83 +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
-                       gint maxwidth = 0;
-                       gint maxheight = 0;
-                       int display_surface_type = MM_DISPLAY_SURFACE_NULL;
-                       mm_camcorder_get_attributes(handle, NULL,
-                                       MMCAM_DISPLAY_SURFACE, &display_surface_type,
-                                       NULL);
-
-                       if (display_surface_type != MM_DISPLAY_SURFACE_NULL &&
-                               __mmcamcorder_find_max_resolution(handle, &maxwidth, &maxheight) == false) {
-                               MMCAM_LOG_ERROR("can not find max resolution limitation");
-                               return false;
-                       } else if (display_surface_type == MM_DISPLAY_SURFACE_NULL) {
-                               maxwidth = set_width;
-                               maxheight = set_height;
-                       }
-#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);
-               } else if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_MJPEG){
-#ifdef _MMCAMCORDER_PRODUCT_TV
-                       caps = gst_caps_new_simple("video/x-jpeg",
-#else
-                       caps = gst_caps_new_simple("image/jpeg",
-#endif
-                               "width", G_TYPE_INT, set_width,
-                               "height", G_TYPE_INT, set_height,
-                               "framerate", GST_TYPE_FRACTION, fps, 1,
-                               NULL);
-               } else {
-                       char fourcc_string[sizeof(fourcc)+1];
-                       memcpy(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_LOG_INFO("vidoesrc new caps set [%s]", caps_str);
-                               g_free(caps_str);
-                               caps_str = NULL;
-                       } else {
-                               MMCAM_LOG_WARNING("caps string failed");
-                       }
-
-                       MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", caps);
-                       gst_caps_unref(caps);
-                       caps = NULL;
-               } else {
-                       MMCAM_LOG_ERROR("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;
 }
 
@@ -3055,9 +3064,9 @@ 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 */
 
@@ -3098,9 +3107,9 @@ bool _mmcamcorder_recreate_decoder_for_encoded_preview(MMHandleType handle)
 
        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_LOG_ERROR("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;
        }
 
@@ -3130,32 +3139,28 @@ bool _mmcamcorder_recreate_decoder_for_encoded_preview(MMHandleType handle)
                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_LOG_INFO("encoded preview decoder_name %s", decoder_name);
-       } else {
+               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(decoder_name, sizeof(decoder_name)-1, "%s", "omx_uhd_mjpegdec");
+                       snprintf(videodecoder_name_final, sizeof(videodecoder_name_final), "%s", "omx_uhd_mjpegdec");
                else
-                       snprintf(decoder_name, sizeof(decoder_name)-1, "%s", "omx_mjpegdec");
-               MMCAM_LOG_INFO("encoded preview decoder_name %s", decoder_name);
+                       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 */
 
        /* 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_LOG_ERROR("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_LOG_ERROR("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),
@@ -3199,7 +3204,7 @@ bool _mmcamcorder_recreate_decoder_for_encoded_preview(MMHandleType handle)
 }
 
 #ifdef _MMCAMCORDER_PRODUCT_TV
-static bool __mmcamcorder_find_max_resolution(MMHandleType handle, gint *max_width, gint *max_height)
+bool __mmcamcorder_find_max_resolution(MMHandleType handle, gint *max_width, gint *max_height)
 {
        _MMCamcorderSubContext *sc = NULL;
        mmf_camcorder_t *hcamcorder = NULL;