X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fmm_camcorder_gstcommon.c;h=efacf541659a69b1ed522f22cd83fd90f170a5bc;hb=bc9dc9af02ba3602fd930d79a5456f92ee1f42f9;hp=27ce41ff854f5f0a52e5c8778aa9206d69e62965;hpb=e3a8aca93f8cecb956c98a88f68f1d7921dc1aa2;p=platform%2Fcore%2Fmultimedia%2Flibmm-camcorder.git diff --git a/src/mm_camcorder_gstcommon.c b/src/mm_camcorder_gstcommon.c old mode 100644 new mode 100755 index 27ce41f..efacf54 --- a/src/mm_camcorder_gstcommon.c +++ b/src/mm_camcorder_gstcommon.c @@ -20,8 +20,9 @@ */ /*======================================================================================= -| INCLUDE FILES | +| INCLUDE FILES | =======================================================================================*/ +#include #include #include #include @@ -29,12 +30,14 @@ #include #include #include +#include +#include #include "mm_camcorder_internal.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] = { @@ -101,7 +104,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}, @@ -120,50 +123,327 @@ 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 /*----------------------------------------------------------------------- -| 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); +#ifdef _MMCAMCORDER_PRODUCT_TV +static bool __mmcamcorder_find_max_resolution(MMHandleType handle, gint *max_width, gint *max_height); +#endif /* _MMCAMCORDER_PRODUCT_TV */ + +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); /*======================================================================================= -| FUNCTION DEFINITIONS | +| FUNCTION DEFINITIONS | =======================================================================================*/ -/*----------------------------------------------------------------------- -| GLOBAL FUNCTION DEFINITIONS: | ------------------------------------------------------------------------*/ +static gboolean __mmcamcorder_set_stream_data_normal(MMCamcorderVideoStreamDataType *stream, GstBuffer *buffer, GstMapInfo *map_info) +{ + mmf_return_val_if_fail(buffer, FALSE); + mmf_return_val_if_fail(map_info, FALSE); + mmf_return_val_if_fail(stream, FALSE); + + 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: + 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); + return FALSE; + } + + return TRUE; +} + + +static gboolean __mmcamcorder_set_stream_data_tbm(MMCamcorderVideoStreamDataType *stream, tbm_surface_info_s *ts_info) +{ + mmf_return_val_if_fail(ts_info, FALSE); + mmf_return_val_if_fail(stream, FALSE); + + 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; + 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; + break; + + default: + MMCAM_LOG_ERROR("unsupported format[%d]", stream->format); + return FALSE; + } + + return TRUE; +} + + +gboolean _mmcamcorder_invoke_video_stream_cb(MMHandleType handle, GstBuffer *buffer, gboolean is_preview) +{ + 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; + + GstMemory *memory = NULL; + GstMapInfo map_info; + GstCaps *caps = NULL; + GstPad *pad = NULL; + GstStructure *structure = NULL; + + mmf_return_val_if_fail(hcamcorder, FALSE); + 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_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); + 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; + } + + /* set size and timestamp */ + if (_mmcamcorder_is_encoded_preview_pixel_format(stream.format)) { + memory = gst_buffer_get_all_memory(buffer); + stream.internal_buffer = buffer; + } else { + 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]); + } + + stream.length_total = ts_info.size; + stream.internal_buffer = buffer; + + if (!__mmcamcorder_set_stream_data_tbm(&stream, &ts_info)) + goto _INVOKE_VIDEO_STREAM_CB_DONE; + } else { + stream.length_total = gst_memory_get_sizes(memory, NULL, NULL); + + if (!gst_memory_map(memory, &map_info, GST_MAP_READWRITE) || + !__mmcamcorder_set_stream_data_normal(&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); + + stream.timestamp = (unsigned int)(GST_BUFFER_PTS(buffer) / 1000000); /* nano sec -> milli sec */ + + /* 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: + 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; +} + + 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; @@ -185,7 +465,10 @@ int _mmcamcorder_create_preview_elements(MMHandleType handle) 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; GList *element_list = NULL; @@ -200,7 +483,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++) { @@ -208,7 +491,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); } } @@ -218,13 +501,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, @@ -240,11 +521,26 @@ int _mmcamcorder_create_preview_elements(MMHandleType handle) MMCAM_DISPLAY_SURFACE, &display_surface_type, 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); @@ -260,9 +556,6 @@ int _mmcamcorder_create_preview_elements(MMHandleType handle) */ _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_SRC, videosrc_name, "videosrc_src", element_list, err); - /* Set video device index */ - MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "camera-id", input_index->default_value); - _MMCAMCORDER_ELEMENT_MAKE(sc, sc->element, _MMCAMCORDER_VIDEOSRC_FILT, "capsfilter", "videosrc_filter", element_list, err); /* init high-speed-fps */ @@ -288,76 +581,125 @@ 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 */ + /* Set basic information of videosrc element */ _mmcamcorder_conf_set_value_element_property(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, VideosrcElement); - /* 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; + /* Set video device index */ +#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); + } - /* 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) { - _mmcam_dbg_log("video decoder element [%s], recreate decoder %d", - videodecoder_name, hcamcorder->recreate_decoder); -#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_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); - } else { - _mmcam_dbg_err("failed to get video decoder element name from %p", sc->VideodecoderElementH264); - goto pipeline_creation_error; - } - - /* set encoded preview bitrate and iframe interval */ + 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); + /* set encoded preview bitrate */ if (!_mmcamcorder_set_encoded_preview_bitrate(handle, preview_bitrate)) - _mmcam_dbg_warn("_mmcamcorder_set_encoded_preview_bitrate failed"); + MMCAM_LOG_WARNING("_mmcamcorder_set_encoded_preview_bitrate failed"); + /* set encoded preview iframe interval */ if (!_mmcamcorder_set_encoded_preview_gop_interval(handle, gop_interval)) - _mmcam_dbg_warn("_mmcamcorder_set_encoded_preview_gop_interval failed"); + MMCAM_LOG_WARNING("_mmcamcorder_set_encoded_preview_gop_interval failed"); } - _mmcam_dbg_log("Current mode[%d]", hcamcorder->type); + 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; + } + } 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); +#endif /* _MMCAMCORDER_RM_SUPPORT */ + } + } + + 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); + 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); @@ -368,7 +710,7 @@ int _mmcamcorder_create_preview_elements(MMHandleType handle) 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); + MMCAM_LOG_WARNING("Get socket path failed 0x%x", err); SAFE_FREE(err_name); goto pipeline_creation_error; } @@ -380,10 +722,10 @@ int _mmcamcorder_create_preview_elements(MMHandleType handle) _mmcamcorder_conf_get_value_element_name(sc->VideoconvertElement, &videoconvert_name); if (videoconvert_name) { - _mmcam_dbg_log("videoconvert element name : %s", 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_dbg_err("failed to get videoconvert element name"); + MMCAM_LOG_ERROR("failed to get videoconvert element name"); } /* check sink element in attribute */ @@ -393,21 +735,19 @@ int _mmcamcorder_create_preview_elements(MMHandleType handle) if (sink_element) { int attr_index = 0; - mmf_attrs_t *attrs = MMF_CAMCORDER_ATTRS(handle); - mmf_attribute_t *attr_item = NULL; + 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); /* reset attribute */ if (attrs) { mm_attrs_get_index((MMHandleType)attrs, MMCAM_DISPLAY_REUSE_ELEMENT, &attr_index); - attr_item = &attrs->items[attr_index]; - mmf_attribute_set_data(attr_item, NULL, 0); - mmf_attribute_commit(attr_item); + mm_attrs_set_data(attrs, attr_index, NULL, 0); + mm_attrs_commit(attrs, attr_index); } else { - _mmcam_dbg_warn("attribute is NULL"); + MMCAM_LOG_WARNING("attribute is NULL"); err = MM_ERROR_CAMCORDER_NOT_INITIALIZED; goto pipeline_creation_error; } @@ -418,7 +758,7 @@ int _mmcamcorder_create_preview_elements(MMHandleType handle) } if (_mmcamcorder_videosink_window_set(handle, sc->VideosinkElement) != MM_ERROR_NONE) { - _mmcam_dbg_err("_mmcamcorder_videosink_window_set error"); + MMCAM_LOG_ERROR("_mmcamcorder_videosink_window_set error"); err = MM_ERROR_CAMCORDER_INVALID_ARGUMENT; goto pipeline_creation_error; } @@ -429,14 +769,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; } @@ -486,6 +826,8 @@ int _mmcamcorder_create_audiosrc_bin(MMHandleType handle) int stream_index = 0; int buffer_interval = 0; int blocksize = 0; + int replay_gain_enable = FALSE; + double replay_gain_ref_level = 0.0; GstCaps *caps = NULL; GstPad *pad = NULL; @@ -502,7 +844,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) @@ -516,11 +858,13 @@ int _mmcamcorder_create_audiosrc_bin(MMHandleType handle) MMCAM_AUDIO_FORMAT, &format, MMCAM_AUDIO_CHANNEL, &channel, MMCAM_AUDIO_VOLUME, &volume, + MMCAM_AUDIO_REPLAY_GAIN_ENABLE, &replay_gain_enable, + MMCAM_AUDIO_REPLAY_GAIN_REFERENCE_LEVEL, &replay_gain_ref_level, MMCAM_SOUND_STREAM_TYPE, &stream_type, &stream_type_len, 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; } @@ -530,7 +874,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 */ @@ -544,7 +888,7 @@ 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; } @@ -558,7 +902,7 @@ int _mmcamcorder_create_audiosrc_bin(MMHandleType handle) 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); @@ -575,7 +919,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); } @@ -586,14 +930,13 @@ 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); - if (a_enc != MM_AUDIO_CODEC_VORBIS) - _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_VOL, "volume", "audiosrc_volume", element_list, err); - - /* Set basic infomation */ + /* Set basic information */ if (a_enc != MM_AUDIO_CODEC_VORBIS) { int depth = 0; const gchar* format_name = NULL; + _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_VOL, "volume", "audiosrc_volume", element_list, err); + if (volume == 0.0) { /* Because data probe of audio src do the same job, it doesn't need to set "mute" here. Already null raw data. */ MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_VOL].gst, "volume", 1.0); @@ -615,7 +958,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? */ @@ -624,28 +967,39 @@ 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_LOG_INFO("Replay gain - enable : %d, reference level : %lf", + replay_gain_enable, replay_gain_ref_level); + + if (replay_gain_enable) { + _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_AUDIOSRC_RGA, "rganalysis", "audiosrc_rga", element_list, err); + MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_RGA].gst, "reference-level", replay_gain_ref_level); + /* If num-tracks is not set, album gain and peak event is not come. */ + MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_AUDIOSRC_RGA].gst, "num-tracks", 1); + } + if (caps) { MMCAMCORDER_G_OBJECT_SET_POINTER((sc->encode_element[_MMCAMCORDER_AUDIOSRC_FILT].gst), "caps", caps); 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; } @@ -655,7 +1009,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; } @@ -691,12 +1045,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; } @@ -706,25 +1060,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); } @@ -743,11 +1097,13 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin int auto_audio_convert = 0; int auto_audio_resample = 0; int auto_color_space = 0; + int cap_format = MM_PIXEL_FORMAT_INVALID; const char *gst_element_venc_name = NULL; const char *gst_element_aenc_name = NULL; 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; @@ -756,6 +1112,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; @@ -766,6 +1123,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); @@ -773,14 +1131,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 */ @@ -789,18 +1147,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 */ @@ -808,15 +1161,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; } @@ -835,28 +1188,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 */ @@ -867,28 +1276,35 @@ 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 */ - err = mm_camcorder_get_attributes(handle, &err_name, - MMCAM_AUDIO_ENCODER, &audio_enc, - MMCAM_AUDIO_CHANNEL, &channel, - MMCAM_VIDEO_ENCODER_BITRATE, &v_bitrate, - MMCAM_AUDIO_ENCODER_BITRATE, &a_bitrate, - NULL); + if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) { + err = mm_camcorder_get_attributes(handle, &err_name, + MMCAM_CAPTURE_FORMAT, &cap_format, + NULL); + } else { + err = mm_camcorder_get_attributes(handle, &err_name, + MMCAM_AUDIO_ENCODER, &audio_enc, + MMCAM_AUDIO_CHANNEL, &channel, + MMCAM_VIDEO_ENCODER_BITRATE, &v_bitrate, + MMCAM_AUDIO_ENCODER_BITRATE, &a_bitrate, + 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; + 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) { @@ -913,7 +1329,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); @@ -932,30 +1348,32 @@ 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) - gst_element_venc_name = "capsfilter"; - else + if (_mmcamcorder_is_encoded_preview_pixel_format(sc->info_image->preview_format)) { + /* set dummy element */ + 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); @@ -975,10 +1393,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); } } } @@ -997,7 +1415,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; } @@ -1023,7 +1441,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, @@ -1038,14 +1456,19 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin } if (profile == MM_CAMCORDER_ENCBIN_PROFILE_IMAGE) { - ImageencElement = _mmcamcorder_get_type_element(handle, MM_CAM_IMAGE_ENCODER); - if (!ImageencElement) { - _mmcam_dbg_err("Fail to get type element"); - err = MM_ERROR_CAMCORDER_RESOURCE_CREATION; - goto pipeline_creation_error; - } + if (cap_format == MM_PIXEL_FORMAT_ENCODED) { + ImageencElement = _mmcamcorder_get_type_element(handle, MM_CAM_IMAGE_ENCODER); + if (!ImageencElement) { + MMCAM_LOG_ERROR("Fail to get type element"); + err = MM_ERROR_CAMCORDER_RESOURCE_CREATION; + goto pipeline_creation_error; + } - _mmcamcorder_conf_get_value_element_name(ImageencElement, &gst_element_ienc_name); + _mmcamcorder_conf_get_value_element_name(ImageencElement, &gst_element_ienc_name); + } else { + /* raw format - set dummy element */ + gst_element_ienc_name = "identity"; + } MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "ienc-name", gst_element_ienc_name); _MMCAMCORDER_ENCODEBIN_ELMGET(sc, _MMCAMCORDER_ENCSINK_IENC, "image-encode", err); @@ -1055,7 +1478,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; } @@ -1104,23 +1527,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"); 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; } @@ -1132,7 +1555,7 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin 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; } @@ -1144,7 +1567,7 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin 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; } @@ -1156,7 +1579,7 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin 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; } @@ -1164,21 +1587,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; @@ -1188,6 +1609,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); @@ -1195,10 +1618,14 @@ 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 (video_caps) + gst_caps_unref(video_caps); + + if (videoscale_caps) + gst_caps_unref(videoscale_caps); return err; } @@ -1220,7 +1647,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 */ @@ -1233,10 +1660,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; } @@ -1247,26 +1674,25 @@ 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); @@ -1286,7 +1712,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); @@ -1294,9 +1720,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->get_first_I_frame = FALSE; sc->info_video->push_encoding_buffer = PUSH_ENCODING_BUFFER_RUN; - _mmcam_dbg_warn("set push_encoding_buffer RUN"); + MMCAM_LOG_WARNING("set push_encoding_buffer RUN"); } } @@ -1318,10 +1743,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; @@ -1331,7 +1754,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); @@ -1351,7 +1774,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, @@ -1359,10 +1782,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; @@ -1371,51 +1794,72 @@ 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); + /* set the videosink using the virtual device id instead of the real id (main=0, sub=1) */ + MMCAMCORDER_G_OBJECT_SET(vsink, "device-scaler", hcamcorder->returned_devices.device_id[1]); #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")) { + 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"); } +#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 */ } 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 */ @@ -1438,7 +1882,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; } @@ -1450,7 +1894,7 @@ int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* Videosi if (display_geometry_method == MM_DISPLAY_METHOD_CUSTOM_ROI) { if (!strcmp(videosink_name, "tizenwlsink")) { - gst_video_overlay_set_render_rectangle(GST_VIDEO_OVERLAY(vsink), + gst_video_overlay_set_display_roi_area(GST_VIDEO_OVERLAY(vsink), rect_x, rect_y, rect_width, rect_height); } else { g_object_set(vsink, @@ -1467,21 +1911,35 @@ int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* Videosi } -int _mmcamcorder_vframe_stablize(MMHandleType handle) +int _mmcamcorder_video_frame_stabilize(MMHandleType handle, int cmd) { + int category = 0; mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle); _MMCamcorderSubContext *sc = NULL; - _mmcam_dbg_log("%d", _MMCAMCORDER_CAMSTABLE_COUNT); - mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED); sc = MMF_CAMCORDER_SUBCONTEXT(handle); mmf_return_val_if_fail(sc, MM_ERROR_CAMCORDER_NOT_INITIALIZED); - if (sc->cam_stability_count != _MMCAMCORDER_CAMSTABLE_COUNT) - sc->cam_stability_count = _MMCAMCORDER_CAMSTABLE_COUNT; + switch (cmd) { + case _MMCamcorder_CMD_PREVIEW_START: + category = CONFIGURE_CATEGORY_CTRL_CAMERA; + break; + case _MMCamcorder_CMD_CAPTURE: + category = CONFIGURE_CATEGORY_CTRL_CAPTURE; + break; + default: + 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_LOG_INFO("[cmd %d] frame stability count : %d", + cmd, sc->frame_stability_count); return MM_ERROR_NONE; } @@ -1513,7 +1971,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; } } @@ -1523,12 +1981,12 @@ 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; } @@ -1542,16 +2000,10 @@ static guint32 _mmcamcorder_convert_fourcc_string_to_value(const gchar* format_n static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstPadProbeInfo *info, gpointer u_data) { - int current_state = MM_CAMCORDER_STATE_NONE; - int i = 0; - mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data); _MMCamcorderSubContext *sc = NULL; _MMCamcorderKPIMeasure *kpi = NULL; GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info); - GstMemory *dataBlock = NULL; - GstMemory *metaBlock = NULL; - GstMapInfo mapinfo; mmf_return_val_if_fail(buffer, GST_PAD_PROBE_DROP); mmf_return_val_if_fail(gst_buffer_n_memory(buffer), GST_PAD_PROBE_DROP); @@ -1560,26 +2012,22 @@ 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); - memset(&mapinfo, 0x0, sizeof(GstMapInfo)); - - 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->cam_stability_count > 0) { - sc->cam_stability_count--; - _mmcam_dbg_log("Drop video frame by cam_stability_count"); + } else if (sc->frame_stability_count > 0) { + sc->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) { + if (hcamcorder->state >= MM_CAMCORDER_STATE_PREPARE) { int diff_sec; int frame_count = 0; struct timeval current_video_time; @@ -1589,7 +2037,7 @@ static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstP 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"); + MMCAM_LOG_INFO("START to measure FPS"); */ gettimeofday(&(kpi->init_video_time), NULL); } @@ -1610,342 +2058,31 @@ static GstPadProbeReturn __mmcamcorder_video_dataprobe_preview(GstPad *pad, GstP 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); + MMCAM_LOG_INFO("current fps(%d), average(%d)", kpi->current_fps, kpi->average_fps); */ } } - /* video stream callback */ - if (hcamcorder->vstream_cb && buffer) { - GstCaps *caps = NULL; - GstStructure *structure = NULL; - int state = MM_CAMCORDER_STATE_NULL; - unsigned int fourcc = 0; - MMCamcorderVideoStreamDataType stream; - MMVideoBuffer *mm_buf = NULL; - const gchar *string_format = NULL; - - 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 stream data structure */ - 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 */ - dataBlock = gst_buffer_peek_memory(buffer, 0); - stream.length_total = gst_memory_get_sizes(dataBlock, NULL, NULL); - stream.timestamp = (unsigned int)(GST_BUFFER_PTS(buffer)/1000000); /* nano sec -> mili sec */ - - if (hcamcorder->use_zero_copy_format && gst_buffer_n_memory(buffer) > 1) { - metaBlock = gst_buffer_peek_memory(buffer, 1); - gst_memory_map(metaBlock, &mapinfo, GST_MAP_READ); - mm_buf = (MMVideoBuffer *)mapinfo.data; - } - - /* set data pointers */ - if (stream.format == MM_PIXEL_FORMAT_NV12 || - stream.format == MM_PIXEL_FORMAT_NV21 || - stream.format == MM_PIXEL_FORMAT_I420) { - if (mm_buf) { - 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 = mm_buf->data[0]; - stream.data.yuv420sp.length_y = stream.width * stream.height; - stream.data.yuv420sp.uv = mm_buf->data[1]; - stream.data.yuv420sp.length_uv = stream.data.yuv420sp.length_y >> 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 = mm_buf->data[0]; - stream.data.yuv420p.length_y = stream.width * stream.height; - stream.data.yuv420p.u = mm_buf->data[1]; - stream.data.yuv420p.length_u = stream.data.yuv420p.length_y >> 2; - stream.data.yuv420p.v = mm_buf->data[2]; - stream.data.yuv420p.length_v = stream.data.yuv420p.length_u; - /* - _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(dataBlock, &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 { - if (mm_buf) { - gst_memory_unmap(metaBlock, &mapinfo); - metaBlock = NULL; - } - gst_memory_map(dataBlock, &mapinfo, GST_MAP_READWRITE); - if (stream.format == MM_PIXEL_FORMAT_YUYV || - stream.format == MM_PIXEL_FORMAT_UYVY || - stream.format == MM_PIXEL_FORMAT_422P || - stream.format == 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; - } else if (stream.format == 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); - */ - } else { - 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; - } - - 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); - */ - } - - /* set tbm bo */ - if (mm_buf && mm_buf->type == MM_VIDEO_BUFFER_TYPE_TBM_BO) { - /* set bo, stride and elevation */ - for (i = 0 ; i < MM_VIDEO_BUFFER_PLANE_MAX ; i++) { - stream.bo[i] = (void *)mm_buf->handle.bo[i]; - stream.stride[i] = mm_buf->stride_width[i]; - stream.elevation[i] = mm_buf->stride_height[i]; - } - - /* set gst buffer */ - stream.internal_buffer = buffer; - } - - /* call application callback */ - _MMCAMCORDER_LOCK_VSTREAM_CALLBACK(hcamcorder); - if (hcamcorder->vstream_cb) { - hcamcorder->vstream_cb(&stream, hcamcorder->vstream_cb_param); - - for (i = 0 ; i < MM_VIDEO_BUFFER_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); - /* Either metaBlock was mapped, or dataBlock, but not both. */ - if (metaBlock) - gst_memory_unmap(metaBlock, &mapinfo); - else - gst_memory_unmap(dataBlock, &mapinfo); + /* 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) { + MMCAM_LOG_WARNING("Not ready for stream callback"); + return GST_PAD_PROBE_OK; } - return 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); - - 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); - - sc = MMF_CAMCORDER_SUBCONTEXT(u_data); - mmf_return_val_if_fail(sc, GST_PAD_PROBE_DROP); - - /* push buffer in appsrc to encode */ - if (!sc->info_video) { - _mmcam_dbg_warn("sc->info_video is NULL!!"); + if (_mmcamcorder_invoke_video_stream_cb((MMHandleType)hcamcorder, buffer, TRUE)) + 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) { - sc->info_video->is_firstframe = FALSE; - 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->is_firstframe = FALSE; - 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);*/ - } - - /* 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; - } - } +} - /*_mmcam_dbg_log("diff %llu", diff);*/ - sc->info_video->prev_preview_ts = GST_BUFFER_PTS(buffer); - } +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; - return GST_PAD_PROBE_OK; + return GST_PAD_PROBE_DROP; } @@ -1965,7 +2102,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; } @@ -2005,33 +2142,78 @@ GstPadProbeReturn __mmcamcorder_eventprobe_monitor(GstPad *pad, GstPadProbeInfo case GST_EVENT_NAVIGATION: case GST_EVENT_LATENCY: /* downstream serialized events */ - case GST_EVENT_TAG: 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_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_LOG_WARNING("NULL handle"); + break; + } + + replay_gain = &hcamcorder->sub_context->replay_gain; + + gst_event_parse_tag(event, &tag_list); + if (!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_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_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_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_LOG_WARNING("failed to get GST_TAG_ALBUM_PEAK"); + break; + } + + 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; } @@ -2039,7 +2221,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; @@ -2050,15 +2232,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; } @@ -2103,22 +2285,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); @@ -2126,19 +2308,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; } @@ -2152,7 +2334,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; @@ -2172,26 +2354,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; } } @@ -2213,7 +2395,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; } @@ -2238,7 +2420,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; } @@ -2268,7 +2450,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; } @@ -2276,14 +2458,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; } } @@ -2307,7 +2489,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; } @@ -2315,14 +2497,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; } } @@ -2330,8 +2512,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; @@ -2342,19 +2522,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); } @@ -2368,13 +2550,6 @@ bool _mmcamcorder_set_videosrc_caps(MMHandleType handle, unsigned int fourcc, in 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; @@ -2385,17 +2560,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; } @@ -2412,7 +2587,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); @@ -2458,7 +2633,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); @@ -2483,11 +2658,12 @@ bool _mmcamcorder_set_videosrc_caps(MMHandleType handle, unsigned int fourcc, in gst_structure_get_int(structure, "rotate", &caps_rotate); #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) { + 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, 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, fourcc, fourcc>>8, fourcc>>16, fourcc>>24, @@ -2497,9 +2673,9 @@ bool _mmcamcorder_set_videosrc_caps(MMHandleType handle, unsigned int fourcc, in } 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."); + 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, 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, fourcc, fourcc>>8, fourcc>>16, fourcc>>24, @@ -2510,9 +2686,9 @@ 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."); + 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, 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, fourcc, fourcc>>8, fourcc>>16, fourcc>>24, @@ -2521,11 +2697,11 @@ bool _mmcamcorder_set_videosrc_caps(MMHandleType handle, unsigned int fourcc, in } #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; } @@ -2537,34 +2713,22 @@ bool _mmcamcorder_set_videosrc_caps(MMHandleType handle, unsigned int fourcc, in 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; - } + 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); - 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 (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; } - - 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, @@ -2576,14 +2740,19 @@ bool _mmcamcorder_set_videosrc_caps(MMHandleType handle, unsigned int fourcc, in "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 - gst_object_unref(decsink_caps); - gst_object_unref(sinkpad); -#endif /* _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]; - strncpy(fourcc_string, (char*)&fourcc, sizeof(fourcc)); + 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, @@ -2595,12 +2764,21 @@ bool _mmcamcorder_set_videosrc_caps(MMHandleType handle, unsigned int fourcc, in } if (caps) { - _mmcam_dbg_log("vidoesrc new caps set. %"GST_PTR_FORMAT, 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_dbg_err("There are no caps"); + MMCAM_LOG_ERROR("There are no caps"); } } @@ -2624,7 +2802,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; @@ -2635,16 +2813,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; } @@ -2669,7 +2847,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; } @@ -2677,16 +2855,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; @@ -2706,7 +2884,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; } @@ -2716,7 +2894,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, @@ -2725,14 +2903,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; @@ -2743,13 +2921,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; @@ -2773,7 +2951,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); } @@ -2782,72 +2960,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); - } - } + MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "bitrate", bitrate); - _mmcam_dbg_warn("failed to find \"bitrate\" control channel"); - } - - 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; } @@ -2859,7 +3019,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; } @@ -2867,11 +3027,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; } @@ -2890,13 +3050,14 @@ bool _mmcamcorder_recreate_decoder_for_encoded_preview(MMHandleType handle) _MMCamcorderSubContext *sc = NULL; mmf_camcorder_t *hcamcorder = NULL; const char *videodecoder_name = NULL; + 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; } @@ -2904,69 +3065,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); 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->VideodecoderElementH264); 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(decoder_name, sizeof(decoder_name)-1, "%s%d", videodecoder_name, decoder_index); + MMCAM_LOG_INFO("encoded preview decoder_name %s", decoder_name); + } else { + /* MJPEG */ + 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", decoder_name); + } - 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); + 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"); 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); return FALSE; } #endif /* _MMCAMCORDER_RM_SUPPORT */ @@ -2979,7 +3159,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; } @@ -2987,28 +3167,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 +static 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 */