X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fmm_camcorder_videorec.c;h=1acd72fae397693843d571ee0d4db3e516936748;hb=9bd836bdb35afe5b1a9a57687609f96182c7b2f4;hp=73ccfa8a534daec668e102488da09fb0f0462f0a;hpb=536202c8c1ee7d885bcdc0f3d04555e46823089c;p=platform%2Fcore%2Fmultimedia%2Flibmm-camcorder.git diff --git a/src/mm_camcorder_videorec.c b/src/mm_camcorder_videorec.c index 73ccfa8..1acd72f 100644 --- a/src/mm_camcorder_videorec.c +++ b/src/mm_camcorder_videorec.c @@ -20,7 +20,7 @@ */ /*======================================================================================= -| INCLUDE FILES | +| INCLUDE FILES | =======================================================================================*/ #include #include @@ -28,25 +28,26 @@ #include "mm_camcorder_videorec.h" /*--------------------------------------------------------------------------------------- -| GLOBAL VARIABLE DEFINITIONS for internal | +| GLOBAL VARIABLE DEFINITIONS for internal | ---------------------------------------------------------------------------------------*/ -#define _MMCAMCORDER_LOCATION_INFO // for add gps information -#define MAX_ERROR_MESSAGE_LEN 128 +#define _MMCAMCORDER_LOCATION_INFO /* for add gps information */ +#define MAX_ERROR_MESSAGE_LEN 128 /*--------------------------------------------------------------------------------------- -| LOCAL VARIABLE DEFINITIONS for internal | +| LOCAL VARIABLE DEFINITIONS for internal | ---------------------------------------------------------------------------------------*/ -#define _MMCAMCORDER_MINIMUM_FRAME 5 -#define _MMCAMCORDER_RETRIAL_COUNT 10 -#define _MMCAMCORDER_FRAME_WAIT_TIME 200000 /* ms */ -#define _OFFSET_COMPOSITION_MATRIX 40L -#define _GOP_GEN_INTERVAL 1000000000 /*nano seconds*/ +#define _MMCAMCORDER_MINIMUM_FRAME 5 +#define _MMCAMCORDER_RETRIAL_COUNT 10 +#define _MMCAMCORDER_FRAME_WAIT_TIME 200000 /* ms */ +#define _OFFSET_COMPOSITION_MATRIX 40L +#define _GOP_GEN_INTERVAL 1000000000 /*nano seconds*/ +#define _MMCAMCORDER_VIDEO_MINIMUM_SPACE (_MMCAMCORDER_MINIMUM_SPACE << 1) /* byte */ /*--------------------------------------------------------------------------------------- -| LOCAL FUNCTION PROTOTYPES: | +| LOCAL FUNCTION PROTOTYPES: | ---------------------------------------------------------------------------------------*/ /* STATIC INTERNAL FUNCTION */ -static void __mmcamcorder_video_stream_cb(GstElement *element, GstSample *sample, gpointer u_data); +static gboolean __mmcamcorder_video_stream_cb(GstElement *element, GstSample *sample, gpointer u_data); static GstPadProbeReturn __mmcamcorder_audio_dataprobe_check(GstPad *pad, GstPadProbeInfo *info, gpointer u_data); static GstPadProbeReturn __mmcamcorder_video_dataprobe_record(GstPad *pad, GstPadProbeInfo *info, gpointer u_data); static GstPadProbeReturn __mmcamcorder_audioque_dataprobe(GstPad *pad, GstPadProbeInfo *info, gpointer u_data); @@ -54,7 +55,6 @@ static GstPadProbeReturn __mmcamcorder_video_dataprobe_audio_disable(GstPad *pad static GstPadProbeReturn __mmcamcorder_audio_dataprobe_audio_mute(GstPad *pad, GstPadProbeInfo *info, gpointer u_data); static gboolean __mmcamcorder_add_metadata(MMHandleType handle, int fileformat); static gboolean __mmcamcorder_add_metadata_mp4(MMHandleType handle); -static GstPadProbeReturn __mmcamcorder_eventprobe_monitor(GstPad *pad, GstPadProbeInfo *info, gpointer u_data); /*======================================================================================= | FUNCTION DEFINITIONS | @@ -62,22 +62,22 @@ static GstPadProbeReturn __mmcamcorder_eventprobe_monitor(GstPad *pad, GstPadPro /*--------------------------------------------------------------------------------------- | GLOBAL FUNCTION DEFINITIONS: | ---------------------------------------------------------------------------------------*/ -static void __mmcamcorder_video_stream_cb(GstElement *element, GstSample *sample, gpointer u_data) +static gboolean __mmcamcorder_video_stream_cb(GstElement *element, GstSample *sample, gpointer u_data) { mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data); _MMCamcorderSubContext *sc = NULL; GstBuffer *buffer = gst_sample_get_buffer(sample); - mmf_return_if_fail(buffer); - mmf_return_if_fail(gst_buffer_n_memory(buffer)); - mmf_return_if_fail(hcamcorder); + mmf_return_val_if_fail(buffer, FALSE); + mmf_return_val_if_fail(gst_buffer_n_memory(buffer), FALSE); + mmf_return_val_if_fail(hcamcorder, FALSE); sc = MMF_CAMCORDER_SUBCONTEXT(hcamcorder); - mmf_return_if_fail(sc); + mmf_return_val_if_fail(sc, FALSE); /* _mmcam_dbg_log("ENTER - push_encoding_buffer %d, buffer %p, MALLOCDATA %p, size %d", - sc->info_video->push_encoding_buffer, buffer, GST_BUFFER_MALLOCDATA(buffer), GST_BUFFER_SIZE(buffer)); + sc->info_video->push_encoding_buffer, buffer, GST_BUFFER_MALLOCDATA(buffer), GST_BUFFER_SIZE(buffer)); */ /* push buffer in appsrc to encode */ @@ -87,8 +87,8 @@ static void __mmcamcorder_video_stream_cb(GstElement *element, GstSample *sample GstFlowReturn ret = 0; GstClock *pipe_clock = NULL; - if(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst) { - if(sc->info_video->is_firstframe) { + if (sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst) { + if (sc->info_video->is_firstframe) { sc->info_video->is_firstframe = FALSE; pipe_clock = GST_ELEMENT_CLOCK(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst); if (pipe_clock) { @@ -98,17 +98,17 @@ static void __mmcamcorder_video_stream_cb(GstElement *element, GstSample *sample } } } else { - if(sc->info_video->is_firstframe) { + if (sc->info_video->is_firstframe) { 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_PTS(buffer) = GST_BUFFER_PTS(buffer) - sc->info_video->base_video_ts; + GST_BUFFER_DTS(buffer) = GST_BUFFER_PTS(buffer); ret = gst_app_src_push_buffer((GstAppSrc *)sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, buffer); - if (ret != GST_FLOW_OK && - ret != GST_FLOW_FLUSHING) { + if (ret != GST_FLOW_OK && ret != GST_FLOW_FLUSHING) { _mmcam_dbg_err("gst_app_src_push_buffer failed [0x%x]", ret); gst_buffer_unref(buffer); buffer = NULL; @@ -117,13 +117,13 @@ static void __mmcamcorder_video_stream_cb(GstElement *element, GstSample *sample /*_mmcam_dbg_log("push buffer result : 0x%x", ret);*/ } else { _mmcam_dbg_warn("unref video buffer immediately - push encoding buffer %d", - sc->info_video->push_encoding_buffer); + sc->info_video->push_encoding_buffer); gst_buffer_unref(buffer); buffer = NULL; } - return; + return TRUE; } @@ -131,7 +131,6 @@ int _mmcamcorder_create_recorder_pipeline(MMHandleType handle) { int i = 0; int err = MM_ERROR_NONE; - int audio_disable = FALSE; const char* gst_element_rsink_name = NULL; GstBus *bus = NULL; @@ -152,14 +151,13 @@ int _mmcamcorder_create_recorder_pipeline(MMHandleType handle) _mmcam_dbg_warn("start"); err = _mmcamcorder_check_videocodec_fileformat_compatibility(handle); - if (err != MM_ERROR_NONE) { + if (err != MM_ERROR_NONE) return err; - } /* Main pipeline */ - if(sc->encode_element[_MMCAMCORDER_ENCODE_MAIN_PIPE].gst) { + if (sc->encode_element[_MMCAMCORDER_ENCODE_MAIN_PIPE].gst) { _mmcam_dbg_log("pipeline is exist so need to remove pipeline _MMCAMCORDER_ENCODE_MAIN_PIPE = %p", - sc->encode_element[_MMCAMCORDER_ENCODE_MAIN_PIPE].gst); + sc->encode_element[_MMCAMCORDER_ENCODE_MAIN_PIPE].gst); _mmcamcorder_remove_recorder_pipeline((MMHandleType)hcamcorder); } @@ -167,41 +165,36 @@ int _mmcamcorder_create_recorder_pipeline(MMHandleType handle) /* get audio disable */ mm_camcorder_get_attributes(handle, NULL, - MMCAM_AUDIO_DISABLE, &audio_disable, - NULL); + MMCAM_AUDIO_DISABLE, &sc->audio_disable, + NULL); - if (sc->is_modified_rate || audio_disable) { - sc->audio_disable = TRUE; - } else { - sc->audio_disable = FALSE; - } - _mmcam_dbg_log("AUDIO DISABLE : %d (is_modified_rate %d, audio_disable %d)", - sc->audio_disable, sc->is_modified_rate, audio_disable); + _mmcam_dbg_log("MMCAM_AUDIO_DISABLE %d, is_modified_rate %d", + sc->audio_disable, sc->is_modified_rate); + + sc->audio_disable |= sc->is_modified_rate; if (sc->audio_disable == FALSE) { /* create audiosrc bin */ err = _mmcamcorder_create_audiosrc_bin((MMHandleType)hcamcorder); - if (err != MM_ERROR_NONE) { + if (err != MM_ERROR_NONE) return err; - } } err = _mmcamcorder_create_encodesink_bin((MMHandleType)hcamcorder, MM_CAMCORDER_ENCBIN_PROFILE_VIDEO); - if (err != MM_ERROR_NONE) { + if (err != MM_ERROR_NONE) return err; - } if (sc->audio_disable == FALSE) { gst_bin_add(GST_BIN(sc->encode_element[_MMCAMCORDER_ENCODE_MAIN_PIPE].gst), - sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst); + sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst); } /* add element and encodesink bin to encode main pipeline */ gst_bin_add_many(GST_BIN(sc->encode_element[_MMCAMCORDER_ENCODE_MAIN_PIPE].gst), - sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, - sc->encode_element[_MMCAMCORDER_ENCSINK_FILT].gst, - sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, - NULL); + sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, + sc->encode_element[_MMCAMCORDER_ENCSINK_FILT].gst, + sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, + NULL); /* Link each element : appsrc - capsfilter - encodesink bin */ srcpad = gst_element_get_static_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, "src"); @@ -213,41 +206,46 @@ int _mmcamcorder_create_recorder_pipeline(MMHandleType handle) _MM_GST_PAD_LINK_UNREF(srcpad, sinkpad, err, pipeline_creation_error); if (sc->audio_disable == FALSE) { - srcpad = gst_element_get_static_pad (sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst, "src"); - sinkpad = gst_element_get_static_pad (sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, "audio_sink0"); + srcpad = gst_element_get_static_pad(sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst, "src"); + sinkpad = gst_element_get_static_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_BIN].gst, "audio_sink0"); _MM_GST_PAD_LINK_UNREF(srcpad, sinkpad, err, pipeline_creation_error); } _mmcamcorder_conf_get_element(handle, hcamcorder->conf_main, - CONFIGURE_CATEGORY_MAIN_RECORD, - "RecordsinkElement", - &RecordsinkElement); + CONFIGURE_CATEGORY_MAIN_RECORD, + "RecordsinkElement", + &RecordsinkElement); _mmcamcorder_conf_get_value_element_name(RecordsinkElement, &gst_element_rsink_name); + if (!gst_element_rsink_name) { + _mmcam_dbg_err("failed to get recordsink name"); + err = MM_ERROR_CAMCORDER_INTERNAL; + goto pipeline_creation_error; + } + /* set data probe function */ /* register message cb */ - /* set data probe function for audio */ - + /* set data probe functions */ if (sc->audio_disable == FALSE) { sinkpad = gst_element_get_static_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC].gst, "sink"); MMCAMCORDER_ADD_BUFFER_PROBE(sinkpad, _MMCAMCORDER_HANDLER_VIDEOREC, - __mmcamcorder_audioque_dataprobe, hcamcorder); + __mmcamcorder_audioque_dataprobe, hcamcorder); gst_object_unref(sinkpad); sinkpad = NULL; /* for voice mute */ srcpad = gst_element_get_static_pad(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, "src"); MMCAMCORDER_ADD_BUFFER_PROBE(srcpad, _MMCAMCORDER_HANDLER_VIDEOREC, - __mmcamcorder_audio_dataprobe_audio_mute, hcamcorder); + __mmcamcorder_audio_dataprobe_audio_mute, hcamcorder); gst_object_unref(srcpad); srcpad = NULL; if (sc->encode_element[_MMCAMCORDER_ENCSINK_AENC_QUE].gst) { srcpad = gst_element_get_static_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC_QUE].gst, "src"); MMCAMCORDER_ADD_EVENT_PROBE(srcpad, _MMCAMCORDER_HANDLER_VIDEOREC, - __mmcamcorder_eventprobe_monitor, hcamcorder); + __mmcamcorder_eventprobe_monitor, hcamcorder); gst_object_unref(srcpad); srcpad = NULL; } @@ -256,7 +254,7 @@ int _mmcamcorder_create_recorder_pipeline(MMHandleType handle) if (sc->encode_element[_MMCAMCORDER_ENCSINK_VENC_QUE].gst) { srcpad = gst_element_get_static_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC_QUE].gst, "src"); MMCAMCORDER_ADD_EVENT_PROBE(srcpad, _MMCAMCORDER_HANDLER_VIDEOREC, - __mmcamcorder_eventprobe_monitor, hcamcorder); + __mmcamcorder_eventprobe_monitor, hcamcorder); gst_object_unref(srcpad); srcpad = NULL; } @@ -264,7 +262,7 @@ int _mmcamcorder_create_recorder_pipeline(MMHandleType handle) if (sc->audio_disable) { sinkpad = gst_element_get_static_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst, "sink"); MMCAMCORDER_ADD_BUFFER_PROBE(sinkpad, _MMCAMCORDER_HANDLER_VIDEOREC, - __mmcamcorder_video_dataprobe_audio_disable, hcamcorder); + __mmcamcorder_video_dataprobe_audio_disable, hcamcorder); gst_object_unref(sinkpad); sinkpad = NULL; } @@ -272,31 +270,42 @@ int _mmcamcorder_create_recorder_pipeline(MMHandleType handle) if (!strcmp(gst_element_rsink_name, "filesink")) { srcpad = gst_element_get_static_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC].gst, "src"); MMCAMCORDER_ADD_BUFFER_PROBE(srcpad, _MMCAMCORDER_HANDLER_VIDEOREC, - __mmcamcorder_video_dataprobe_record, hcamcorder); + __mmcamcorder_video_dataprobe_record, hcamcorder); gst_object_unref(srcpad); srcpad = NULL; srcpad = gst_element_get_static_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC].gst, "src"); MMCAMCORDER_ADD_BUFFER_PROBE(srcpad, _MMCAMCORDER_HANDLER_VIDEOREC, - __mmcamcorder_audio_dataprobe_check, hcamcorder); + __mmcamcorder_audio_dataprobe_check, hcamcorder); gst_object_unref(srcpad); srcpad = NULL; } + sinkpad = gst_element_get_static_pad(sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst, "sink"); + MMCAMCORDER_ADD_BUFFER_PROBE(sinkpad, _MMCAMCORDER_HANDLER_VIDEOREC, + __mmcamcorder_muxed_dataprobe, hcamcorder); + MMCAMCORDER_ADD_EVENT_PROBE(sinkpad, _MMCAMCORDER_HANDLER_VIDEOREC, + __mmcamcorder_eventprobe_monitor, hcamcorder); + gst_object_unref(sinkpad); + sinkpad = NULL; + bus = gst_pipeline_get_bus(GST_PIPELINE(sc->encode_element[_MMCAMCORDER_ENCODE_MAIN_PIPE].gst)); /* register pipeline message callback */ hcamcorder->encode_pipeline_cb_event_id = gst_bus_add_watch(bus, (GstBusFunc)_mmcamcorder_pipeline_cb_message, hcamcorder); + /* set sync handler */ + gst_bus_set_sync_handler(bus, _mmcamcorder_encode_pipeline_bus_sync_callback, (gpointer)hcamcorder, NULL); + gst_object_unref(bus); bus = NULL; return MM_ERROR_NONE; pipeline_creation_error: - for (i = _MMCAMCORDER_AUDIOSRC_BIN ; i <= _MMCAMCORDER_ENCSINK_SINK ; i++) { + for (i = _MMCAMCORDER_AUDIOSRC_BIN ; i <= _MMCAMCORDER_ENCSINK_SINK ; i++) _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, i); - } + _MMCAMCORDER_ELEMENT_REMOVE(sc->encode_element, _MMCAMCORDER_ENCODE_MAIN_PIPE); return err; } @@ -324,7 +333,7 @@ int _mmcamcorder_remove_audio_pipeline(MMHandleType handle) /* release audiosrc bin */ gst_bin_remove(GST_BIN(sc->encode_element[_MMCAMCORDER_ENCODE_MAIN_PIPE].gst), - sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst); + sc->encode_element[_MMCAMCORDER_AUDIOSRC_BIN].gst); /* To avoid conflicting between old elements and newly created elements, @@ -348,6 +357,9 @@ int _mmcamcorder_remove_encode_pipeline(MMHandleType handle) GstPad *reqpad = NULL; mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle); _MMCamcorderSubContext *sc = NULL; +#ifdef _MMCAMCORDER_MM_RM_SUPPORT + int ret = MM_ERROR_NONE; +#endif /* _MMCAMCORDER_MM_RM_SUPPORT */ mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED); @@ -384,9 +396,34 @@ int _mmcamcorder_remove_encode_pipeline(MMHandleType handle) It's because the pipeline of audio recording destroys at the same time, and '_mmcamcorder_element_release_noti' will perfom removing handle. */ - //_mmcamcorder_remove_element_handle(handle, (void *)sc->encode_element, _MMCAMCORDER_ENCODE_MAIN_PIPE, _MMCAMCORDER_ENCSINK_SINK); + /* _mmcamcorder_remove_element_handle(handle, (void *)sc->encode_element, + _MMCAMCORDER_ENCODE_MAIN_PIPE, _MMCAMCORDER_ENCSINK_SINK); */ + + _mmcam_dbg_warn("Encoder pipeline removed"); + +#ifdef _MMCAMCORDER_MM_RM_SUPPORT + _MMCAMCORDER_LOCK_RESOURCE(hcamcorder); + + _mmcam_dbg_warn("lock resource - cb calling %d", hcamcorder->is_release_cb_calling); + + if (hcamcorder->is_release_cb_calling == FALSE) { + /* release resource */ + ret = mm_resource_manager_mark_for_release(hcamcorder->resource_manager, + hcamcorder->video_encoder_resource); + if (ret == MM_RESOURCE_MANAGER_ERROR_NONE) + hcamcorder->video_encoder_resource = NULL; + + _mmcam_dbg_warn("mark resource for release 0x%x", ret); + + ret = mm_resource_manager_commit(hcamcorder->resource_manager); - _mmcam_dbg_log("Encoder pipeline removed"); + _mmcam_dbg_warn("commit resource release 0x%x", ret); + } + + _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder); + + _mmcam_dbg_warn("unlock resource"); +#endif /* _MMCAMCORDER_MM_RM_SUPPORT */ } return MM_ERROR_NONE; @@ -463,6 +500,7 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) { int size = 0; int fileformat = 0; + int count = 0; int ret = MM_ERROR_NONE; double motion_rate = _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE; char *err_name = NULL; @@ -504,79 +542,108 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) int ret_free_space = 0; char *dir_name = NULL; guint64 free_space = 0; - guint64 free_space_exceptsystem = 0; int file_system_type = 0; + int root_directory_length = 0; /* Recording */ _mmcam_dbg_log("Record Start - dual stream %d", info->support_dual_stream); +#ifdef _MMCAMCORDER_MM_RM_SUPPORT + _MMCAMCORDER_LOCK_RESOURCE(hcamcorder); + + /* prepare resource manager for H/W encoder */ + if (hcamcorder->video_encoder_resource == NULL) { + ret = mm_resource_manager_mark_for_acquire(hcamcorder->resource_manager, + MM_RESOURCE_MANAGER_RES_TYPE_VIDEO_ENCODER, + MM_RESOURCE_MANAGER_RES_VOLUME_FULL, + &hcamcorder->video_encoder_resource); + if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) { + _mmcam_dbg_err("could not prepare for encoder resource"); + ret = MM_ERROR_RESOURCE_INTERNAL; + _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder); + goto _ERR_CAMCORDER_VIDEO_COMMAND; + } + } else { + _mmcam_dbg_log("encoder already acquired"); + } + + /* acquire resources */ + ret = mm_resource_manager_commit(hcamcorder->resource_manager); + if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) { + _mmcam_dbg_err("could not acquire resources"); + ret = MM_ERROR_RESOURCE_INTERNAL; + _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder); + goto _ERR_CAMCORDER_VIDEO_COMMAND; + } + + _MMCAMCORDER_UNLOCK_RESOURCE(hcamcorder); +#endif /* _MMCAMCORDER_MM_RM_SUPPORT */ + /* init record_dual_stream */ info->record_dual_stream = FALSE; ret = mm_camcorder_get_attributes(handle, &err_name, - MMCAM_CAMERA_FPS, &fps, - MMCAM_CAMERA_WIDTH, &(info->preview_width), - MMCAM_CAMERA_HEIGHT, &(info->preview_height), - MMCAM_VIDEO_WIDTH, &(info->video_width), - MMCAM_VIDEO_HEIGHT, &(info->video_height), - MMCAM_FILE_FORMAT, &fileformat, - MMCAM_TARGET_FILENAME, &temp_filename, &size, - MMCAM_TARGET_MAX_SIZE, &imax_size, - MMCAM_TARGET_TIME_LIMIT, &imax_time, - MMCAM_FILE_FORMAT, &(info->fileformat), - MMCAM_CAMERA_RECORDING_MOTION_RATE, &motion_rate, - NULL); + MMCAM_CAMERA_FPS, &fps, + MMCAM_CAMERA_WIDTH, &(info->preview_width), + MMCAM_CAMERA_HEIGHT, &(info->preview_height), + MMCAM_VIDEO_WIDTH, &(info->video_width), + MMCAM_VIDEO_HEIGHT, &(info->video_height), + MMCAM_FILE_FORMAT, &fileformat, + MMCAM_TARGET_FILENAME, &temp_filename, &size, + MMCAM_TARGET_MAX_SIZE, &imax_size, + MMCAM_TARGET_TIME_LIMIT, &imax_time, + MMCAM_FILE_FORMAT, &(info->fileformat), + MMCAM_CAMERA_RECORDING_MOTION_RATE, &motion_rate, + MMCAM_ROOT_DIRECTORY, &hcamcorder->root_directory, &root_directory_length, + NULL); if (ret != MM_ERROR_NONE) { _mmcam_dbg_warn("Get attrs fail. (%s:%x)", err_name, ret); - SAFE_FREE (err_name); + SAFE_FREE(err_name); goto _ERR_CAMCORDER_VIDEO_COMMAND; } - if (temp_filename == NULL) { - _mmcam_dbg_err("filename is not set"); + if (!temp_filename && !hcamcorder->mstream_cb) { + _mmcam_dbg_err("filename is not set and muxed stream cb is NULL"); ret = MM_ERROR_CAMCORDER_INVALID_ARGUMENT; goto _ERR_CAMCORDER_VIDEO_COMMAND; } /* set max size */ - if (imax_size <= 0) { + if (imax_size <= 0) info->max_size = 0; /* do not check */ - } else { + else info->max_size = ((guint64)imax_size) << 10; /* to byte */ - } /* set max time */ - if (imax_time <= 0) { + if (imax_time <= 0) info->max_time = 0; /* do not check */ - } else { - info->max_time = ((guint64)imax_time) * 1000; /* to millisecond */ - } + else + info->max_time = (guint64)((double)imax_time * (double)1000 * motion_rate); /* to millisecond */ dir_name = g_path_get_dirname(temp_filename); if (dir_name) { - ret_free_space = _mmcamcorder_get_freespace(dir_name, &free_space); - if(_mmcamcorder_check_file_path(dir_name)) { - if (_mmcamcorder_get_freespace_except_system(&free_space_exceptsystem) == MM_ERROR_NONE) { - hcamcorder->system_memory = free_space - free_space_exceptsystem; - free_space = free_space - hcamcorder->system_memory; - } else { - hcamcorder->system_memory = 0; - } + ret = _mmcamcorder_get_storage_info(dir_name, hcamcorder->root_directory, &hcamcorder->storage_info); + if (ret != 0) { + _mmcam_dbg_err("get storage info failed"); + g_free(dir_name); + dir_name = NULL; + return MM_ERROR_OUT_OF_STORAGE; } - _mmcam_dbg_warn("current space - %s [%" G_GUINT64_FORMAT "], system [%" G_GUINT64_FORMAT "]", - dir_name, free_space, hcamcorder->system_memory); + ret_free_space = _mmcamcorder_get_freespace(hcamcorder->storage_info.type, &free_space); + + _mmcam_dbg_warn("current space - %s [%" G_GUINT64_FORMAT "]", dir_name, free_space); if (_mmcamcorder_get_file_system_type(dir_name, &file_system_type) == 0) { /* MSDOS_SUPER_MAGIC : 0x4d44 */ if (file_system_type == MSDOS_SUPER_MAGIC && (info->max_size == 0 || info->max_size > FAT32_FILE_SYSTEM_MAX_SIZE)) { - _mmcam_dbg_warn("FAT32 and too large max[%"G_GUINT64_FORMAT"], set max as %"G_GUINT64_FORMAT, - info->max_size, FAT32_FILE_SYSTEM_MAX_SIZE); + _mmcam_dbg_warn("FAT32 and too large max[%"G_GUINT64_FORMAT"], set max as %lu", + info->max_size, FAT32_FILE_SYSTEM_MAX_SIZE); info->max_size = FAT32_FILE_SYSTEM_MAX_SIZE; } else { _mmcam_dbg_warn("file system 0x%x, max size %"G_GUINT64_FORMAT, - file_system_type, info->max_size); + file_system_type, info->max_size); } } else { _mmcam_dbg_warn("_mmcamcorder_get_file_system_type failed"); @@ -589,25 +656,26 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) ret_free_space = -1; } - if ((ret_free_space == -1) || free_space <= (_MMCAMCORDER_MINIMUM_SPACE<<1)) { + if (temp_filename && + (ret_free_space == -1 || free_space <= _MMCAMCORDER_VIDEO_MINIMUM_SPACE)) { _mmcam_dbg_err("OUT of STORAGE [ret_free_space:%d or free space [%" G_GUINT64_FORMAT "] is smaller than [%d]", - ret_free_space, free_space, (_MMCAMCORDER_MINIMUM_SPACE<<1)); + ret_free_space, free_space, _MMCAMCORDER_VIDEO_MINIMUM_SPACE); return MM_ERROR_OUT_OF_STORAGE; } - pthread_mutex_lock(&(hcamcorder->task_thread_lock)); + g_mutex_lock(&hcamcorder->task_thread_lock); if (sc->encode_element[_MMCAMCORDER_ENCODE_MAIN_PIPE].gst == NULL && hcamcorder->task_thread_state == _MMCAMCORDER_TASK_THREAD_STATE_NONE) { /* Play record start sound */ - _mmcamcorder_sound_solo_play(handle, _MMCAMCORDER_FILEPATH_REC_START_SND, FALSE); + _mmcamcorder_sound_solo_play(handle, _MMCAMCORDER_SAMPLE_SOUND_NAME_REC_START, FALSE); } - pthread_mutex_unlock(&(hcamcorder->task_thread_lock)); + g_mutex_unlock(&hcamcorder->task_thread_lock); _mmcam_dbg_warn("video size [%dx%d]", info->video_width, info->video_height); if (info->video_width == 0 || info->video_height == 0) { _mmcam_dbg_warn("video size is invalid [%dx%d] use preview size [%dx%d]", - info->video_width, info->video_height, info->preview_width, info->preview_height); + info->video_width, info->video_height, info->preview_width, info->preview_height); info->video_width = info->preview_width; info->video_height = info->preview_height; } @@ -623,8 +691,8 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "video-width", info->video_width); MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "video-height", info->video_height); } else if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264 && - info->preview_width == info->video_width && - info->preview_height == info->video_height) { + info->preview_width == info->video_width && + info->preview_height == info->video_height) { _mmcam_dbg_log("H264 preview mode and same resolution"); /* No need to restart preview */ @@ -643,15 +711,23 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "empty-buffers", TRUE); MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst, "empty-buffers", TRUE); + MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "keep-camera-preview", TRUE); ret = _mmcamcorder_gst_set_state(handle, pipeline, GST_STATE_READY); + /* check decoder recreation */ + if (!_mmcamcorder_recreate_decoder_for_encoded_preview(handle)) { + _mmcam_dbg_err("_mmcamcorder_recreate_decoder_for_encoded_preview failed"); + ret = MM_ERROR_CAMCORDER_INTERNAL; + goto _ERR_CAMCORDER_VIDEO_COMMAND; + } + MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "empty-buffers", FALSE); MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst, "empty-buffers", FALSE); + MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "keep-camera-preview", FALSE); - if (ret != MM_ERROR_NONE) { + if (ret != MM_ERROR_NONE) goto _ERR_CAMCORDER_VIDEO_COMMAND; - } if (!_mmcamcorder_set_camera_resolution(handle, info->video_width, info->video_height)) { ret = MM_ERROR_CAMCORDER_INTERNAL; @@ -660,9 +736,8 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) /* Start preview again with new setting */ ret = _mmcamcorder_gst_set_state(handle, pipeline, GST_STATE_PLAYING); - if (ret != MM_ERROR_NONE) { + if (ret != MM_ERROR_NONE) goto _ERR_CAMCORDER_VIDEO_COMMAND; - } if (motion_rate < 1.0) { _mmcam_dbg_warn("wait for stabilization of frame"); @@ -673,28 +748,27 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) } _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, - CONFIGURE_CATEGORY_MAIN_RECORD, - "DropVideoFrame", - &(sc->drop_vframe)); + CONFIGURE_CATEGORY_MAIN_RECORD, + "DropVideoFrame", + &(sc->drop_vframe)); _mmcamcorder_conf_get_value_int(handle, hcamcorder->conf_main, - CONFIGURE_CATEGORY_MAIN_RECORD, - "PassFirstVideoFrame", - &(sc->pass_first_vframe)); + CONFIGURE_CATEGORY_MAIN_RECORD, + "PassFirstVideoFrame", + &(sc->pass_first_vframe)); _mmcam_dbg_log("Drop video frame count[%d], Pass fisrt video frame count[%d]", - sc->drop_vframe, sc->pass_first_vframe); + sc->drop_vframe, sc->pass_first_vframe); info->record_drop_count = (guint)motion_rate; info->record_motion_rate = motion_rate; - if (sc->is_modified_rate) { + if (sc->is_modified_rate) info->record_timestamp_ratio = (_MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE/motion_rate); - } else { + else info->record_timestamp_ratio = _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE; - } _mmcam_dbg_warn("recording fps %d, motion rate %f, timestamp_ratio %f", - fps, info->record_motion_rate, info->record_timestamp_ratio); + fps, info->record_motion_rate, info->record_timestamp_ratio); /* set push buffer flag */ info->push_encoding_buffer = PUSH_ENCODING_BUFFER_INIT; @@ -703,9 +777,8 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) /* connect video stream cb signal */ /*130826 Connect video stream cb for handling fast record frame cb*/ if (info->record_dual_stream) { - if (_mmcamcorder_connect_video_stream_cb_signal((MMHandleType)hcamcorder) != MM_ERROR_NONE) { + if (_mmcamcorder_connect_video_stream_cb_signal((MMHandleType)hcamcorder) != MM_ERROR_NONE) goto _ERR_CAMCORDER_VIDEO_COMMAND; - } } /* start video stream */ @@ -724,17 +797,17 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) } /* check pre-created encode pipeline */ - pthread_mutex_lock(&(hcamcorder->task_thread_lock)); + g_mutex_lock(&hcamcorder->task_thread_lock); if (sc->encode_element[_MMCAMCORDER_ENCODE_MAIN_PIPE].gst == NULL && hcamcorder->task_thread_state == _MMCAMCORDER_TASK_THREAD_STATE_NONE) { /* create encoding pipeline */ - ret =_mmcamcorder_video_prepare_record((MMHandleType)hcamcorder); + ret = _mmcamcorder_video_prepare_record((MMHandleType)hcamcorder); if (ret != MM_ERROR_NONE) { - pthread_mutex_unlock(&(hcamcorder->task_thread_lock)); + g_mutex_unlock(&hcamcorder->task_thread_lock); goto _ERR_CAMCORDER_VIDEO_COMMAND; } } - pthread_mutex_unlock(&(hcamcorder->task_thread_lock)); + g_mutex_unlock(&hcamcorder->task_thread_lock); /* check recording start sound */ _mmcamcorder_sound_solo_play_wait(handle); @@ -745,8 +818,10 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) basetime wouldn't change if you set (GstClockTime)0. 3. Move set start time position below PAUSED of pipeline. */ - //gst_element_set_start_time(GST_ELEMENT(sc->element[_MMCAMCORDER_MAIN_PIPE].gst), (GstClockTime)1); - //gst_element_set_start_time(GST_ELEMENT(sc->encode_element[_MMCAMCORDER_ENCODE_MAIN_PIPE].gst), (GstClockTime)1); + /* + gst_element_set_start_time(GST_ELEMENT(sc->element[_MMCAMCORDER_MAIN_PIPE].gst), (GstClockTime)1); + gst_element_set_start_time(GST_ELEMENT(sc->encode_element[_MMCAMCORDER_ENCODE_MAIN_PIPE].gst), (GstClockTime)1); + */ info->video_frame_count = 0; info->is_firstframe = TRUE; @@ -756,6 +831,7 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) sc->ferror_count = 0; hcamcorder->error_occurs = FALSE; sc->bget_eos = FALSE; + sc->muxed_stream_offset = 0; ret = _mmcamcorder_gst_set_state(handle, sc->encode_element[_MMCAMCORDER_ENCODE_MAIN_PIPE].gst, GST_STATE_PLAYING); if (ret != MM_ERROR_NONE) { @@ -793,18 +869,17 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) CameraControlChannel = item->data; _mmcam_dbg_log("CameraControlChannel->label %s", CameraControlChannel->label); if (!strcmp(CameraControlChannel->label, "new-gop")) { - //gst_camera_control_set_value(CameraControl, CameraControlChannel, 1); + /* gst_camera_control_set_value(CameraControl, CameraControlChannel, 1); */ break; } } - if (item == NULL) { + if (item == NULL) _mmcam_dbg_warn("failed to find new-gop control channel"); - } } } else { _mmcam_dbg_warn("Can't cast Video source into camera control or not H264 prevew format[%d]", - sc->info_image->preview_format); + sc->info_image->preview_format); } } else { /* Resume case */ @@ -819,14 +894,13 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) CameraControlChannel = item->data; _mmcam_dbg_log("CameraControlChannel->label %s", CameraControlChannel->label); if (!strcmp(CameraControlChannel->label, "new-gop")) { - //gst_camera_control_set_value(CameraControl, CameraControlChannel, 1); + /* gst_camera_control_set_value(CameraControl, CameraControlChannel, 1); */ break; } } - if (item == NULL) { + if (item == NULL) _mmcam_dbg_warn("failed to find new-gop control channel"); - } } } @@ -838,8 +912,6 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) break; case _MMCamcorder_CMD_PAUSE: { - int count = 0; - if (info->b_commiting) { _mmcam_dbg_warn("now on commiting previous file!!(command : %d)", command); return MM_ERROR_CAMCORDER_CMD_IS_RUNNING; @@ -851,12 +923,10 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) if (info->video_frame_count >= _MMCAMCORDER_MINIMUM_FRAME) { break; } else if (count == _MMCAMCORDER_RETRIAL_COUNT) { - _mmcam_dbg_err("Pause fail, frame count %" G_GUINT64_FORMAT "", - info->video_frame_count); + _mmcam_dbg_err("Pause fail, frame count %"G_GUINT64_FORMAT, info->video_frame_count); return MM_ERROR_CAMCORDER_INVALID_CONDITION; } else { - _mmcam_dbg_warn("Waiting for enough video frame, retrial[%d], frame %" G_GUINT64_FORMAT "", - count, info->video_frame_count); + _mmcam_dbg_warn("Waiting for enough video frame, retrial[%d], frame %"G_GUINT64_FORMAT, count, info->video_frame_count); } usleep(_MMCAMCORDER_FRAME_WAIT_TIME); @@ -865,12 +935,12 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) if (info->video_frame_count >= _MMCAMCORDER_MINIMUM_FRAME && info->audio_frame_count) { break; } else if (count == _MMCAMCORDER_RETRIAL_COUNT) { - _mmcam_dbg_err("Pause fail, frame count VIDEO[%" G_GUINT64_FORMAT "], AUDIO [%" G_GUINT64_FORMAT "]", - info->video_frame_count, info->audio_frame_count); + _mmcam_dbg_err("Pause fail, frame count VIDEO[%"G_GUINT64_FORMAT"], AUDIO [%"G_GUINT64_FORMAT"]", + info->video_frame_count, info->audio_frame_count); return MM_ERROR_CAMCORDER_INVALID_CONDITION; } else { - _mmcam_dbg_warn("Waiting for enough frames, retrial [%d], VIDEO[%" G_GUINT64_FORMAT "], AUDIO [%" G_GUINT64_FORMAT "]", - count, info->video_frame_count, info->audio_frame_count); + _mmcam_dbg_warn("Waiting for enough frames, retrial [%d], VIDEO[%"G_GUINT64_FORMAT"], AUDIO [%"G_GUINT64_FORMAT"]", + count, info->video_frame_count, info->audio_frame_count); } usleep(_MMCAMCORDER_FRAME_WAIT_TIME); @@ -888,13 +958,27 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) return MM_ERROR_CAMCORDER_CMD_IS_RUNNING; } + for (count = 0 ; count <= _MMCAMCORDER_RETRIAL_COUNT ; count++) { + /* capturing */ + if (hcamcorder->capture_in_recording == FALSE) { + break; + } else if (count == _MMCAMCORDER_RETRIAL_COUNT) { + _mmcam_dbg_err("Failed to Wait capture data"); + hcamcorder->capture_in_recording = FALSE; + break; + } else { + _mmcam_dbg_warn("Waiting for capture data - retrial [%d]", count); + } + + usleep(_MMCAMCORDER_FRAME_WAIT_TIME); + } + /* block push buffer */ info->push_encoding_buffer = PUSH_ENCODING_BUFFER_STOP; ret = _mmcamcorder_remove_recorder_pipeline((MMHandleType)hcamcorder); - if (ret != MM_ERROR_NONE) { + if (ret != MM_ERROR_NONE) goto _ERR_CAMCORDER_VIDEO_COMMAND; - } /* set recording hint */ MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "recording-hint", FALSE); @@ -918,14 +1002,22 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) /* restart preview */ MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "empty-buffers", TRUE); MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst, "empty-buffers", TRUE); + MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "keep-camera-preview", TRUE); - ret =_mmcamcorder_gst_set_state(handle, pipeline, GST_STATE_READY); + ret = _mmcamcorder_gst_set_state(handle, pipeline, GST_STATE_READY); + + /* check decoder recreation */ + if (!_mmcamcorder_recreate_decoder_for_encoded_preview(handle)) { + _mmcam_dbg_err("_mmcamcorder_recreate_decoder_for_encoded_preview failed"); + ret = MM_ERROR_CAMCORDER_INTERNAL; + } MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst, "empty-buffers", FALSE); MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "empty-buffers", FALSE); - if (ret != MM_ERROR_NONE) { + MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "keep-camera-preview", FALSE); + + if (ret != MM_ERROR_NONE) goto _ERR_CAMCORDER_VIDEO_COMMAND; - } /* reset restart_preview for inset window layout */ info->restart_preview = FALSE; @@ -935,10 +1027,9 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) goto _ERR_CAMCORDER_VIDEO_COMMAND; } - ret =_mmcamcorder_gst_set_state(handle, pipeline, GST_STATE_PLAYING); - if (ret != MM_ERROR_NONE) { + ret = _mmcamcorder_gst_set_state(handle, pipeline, GST_STATE_PLAYING); + if (ret != MM_ERROR_NONE) goto _ERR_CAMCORDER_VIDEO_COMMAND; - } } /* remove target file */ @@ -955,11 +1046,12 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) info->video_frame_count = 0; info->audio_frame_count = 0; info->filesize = 0; + hcamcorder->capture_in_recording = FALSE; break; } case _MMCamcorder_CMD_COMMIT: { - int count = 0; + guint64 free_space; if (info->b_commiting) { _mmcam_dbg_err("now on commiting previous file!!(command : %d)", command); @@ -973,34 +1065,52 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) for (count = 0 ; count <= _MMCAMCORDER_RETRIAL_COUNT ; count++) { if (sc->audio_disable) { /* check only video frame */ - if (info->video_frame_count >= _MMCAMCORDER_MINIMUM_FRAME) { + if (info->video_frame_count >= _MMCAMCORDER_MINIMUM_FRAME && + hcamcorder->capture_in_recording == FALSE) { break; } else if (count == _MMCAMCORDER_RETRIAL_COUNT) { - _mmcam_dbg_err("Commit fail, frame count is %" G_GUINT64_FORMAT "", - info->video_frame_count); - info->b_commiting = FALSE; - return MM_ERROR_CAMCORDER_INVALID_CONDITION; + _mmcam_dbg_err("Commit fail, frame count is %"G_GUINT64_FORMAT", capturing %d", + info->video_frame_count, hcamcorder->capture_in_recording); + + if (info->video_frame_count >= _MMCAMCORDER_MINIMUM_FRAME) { + _mmcam_dbg_warn("video frames are enough. keep going..."); + } else { + info->b_commiting = FALSE; + return MM_ERROR_CAMCORDER_INVALID_CONDITION; + } } else { - _mmcam_dbg_warn("Waiting for enough video frame, retrial [%d], frame %" G_GUINT64_FORMAT "", - count, info->video_frame_count); + _mmcam_dbg_warn("Waiting for enough video frame, retrial [%d], frame %"G_GUINT64_FORMAT", capturing %d", + count, info->video_frame_count, hcamcorder->capture_in_recording); } - - usleep(_MMCAMCORDER_FRAME_WAIT_TIME); } else { /* check both of video and audio frame */ - if (info->video_frame_count >= _MMCAMCORDER_MINIMUM_FRAME && info->audio_frame_count) { + if (info->video_frame_count >= _MMCAMCORDER_MINIMUM_FRAME && + info->audio_frame_count && + hcamcorder->capture_in_recording == FALSE) { break; } else if (count == _MMCAMCORDER_RETRIAL_COUNT) { - _mmcam_dbg_err("Commit fail, VIDEO[%" G_GUINT64_FORMAT "], AUDIO [%" G_GUINT64_FORMAT "]", - info->video_frame_count, info->audio_frame_count); + _mmcam_dbg_err("Commit fail, VIDEO[%"G_GUINT64_FORMAT"], AUDIO [%"G_GUINT64_FORMAT"], capturing %d", + info->video_frame_count, info->audio_frame_count, hcamcorder->capture_in_recording); + + if (info->video_frame_count >= _MMCAMCORDER_MINIMUM_FRAME && info->audio_frame_count) { + _mmcam_dbg_warn("video/audio frames are enough. keep going..."); + } else { + info->b_commiting = FALSE; + return MM_ERROR_CAMCORDER_INVALID_CONDITION; + } - info->b_commiting = FALSE; return MM_ERROR_CAMCORDER_INVALID_CONDITION; } else { - _mmcam_dbg_warn("Waiting for enough frames, retrial [%d], VIDEO[%" G_GUINT64_FORMAT "], AUDIO [%" G_GUINT64_FORMAT "]", - count, info->video_frame_count, info->audio_frame_count); + _mmcam_dbg_warn("Waiting for enough frames, retrial [%d], VIDEO[%"G_GUINT64_FORMAT"], AUDIO [%"G_GUINT64_FORMAT"], capturing %d", + count, info->video_frame_count, info->audio_frame_count, hcamcorder->capture_in_recording); } + } + if (hcamcorder->capture_in_recording) { + gint64 end_time = g_get_monotonic_time() + (200 * G_TIME_SPAN_MILLISECOND); + if (!_MMCAMCORDER_CMD_WAIT_UNTIL(handle, end_time)) + _mmcam_dbg_warn("timeout"); + } else { usleep(_MMCAMCORDER_FRAME_WAIT_TIME); } } @@ -1009,30 +1119,56 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) info->push_encoding_buffer = PUSH_ENCODING_BUFFER_STOP; _mmcam_dbg_log("block push buffer to appsrc"); + _mmcamcorder_get_freespace(hcamcorder->storage_info.type, &free_space); + if (free_space < _MMCAMCORDER_MINIMUM_SPACE) { + _mmcam_dbg_warn("_MMCamcorder_CMD_COMMIT out of storage [%" G_GUINT64_FORMAT "]", free_space); + ret = MM_ERROR_OUT_OF_STORAGE; + goto _ERR_CAMCORDER_VIDEO_COMMAND; + } + if (sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst != NULL) { - ret = gst_element_send_event(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, gst_event_new_eos()); - _mmcam_dbg_warn("send eos to appsrc result : %d", ret); + if (gst_element_send_event(sc->encode_element[_MMCAMCORDER_ENCSINK_SRC].gst, gst_event_new_eos())) { + _mmcam_dbg_warn("VIDEO: send eos to appsrc done"); + } else { + _mmcam_dbg_err("VIDEO: send EOS failed"); + info->b_commiting = FALSE; + ret = MM_ERROR_CAMCORDER_INTERNAL; + goto _ERR_CAMCORDER_VIDEO_COMMAND; + } + } else { + _mmcam_dbg_err("No video stream source"); + info->b_commiting = FALSE; + ret = MM_ERROR_CAMCORDER_INTERNAL; + goto _ERR_CAMCORDER_VIDEO_COMMAND; } if (sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst != NULL) { - ret = gst_element_send_event(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, gst_event_new_eos()); - _mmcam_dbg_warn("send eos to audiosrc result : %d", ret); + if (gst_element_send_event(sc->encode_element[_MMCAMCORDER_AUDIOSRC_SRC].gst, gst_event_new_eos())) { + _mmcam_dbg_warn("AUDIO: send eos to audiosrc done"); + } else { + _mmcam_dbg_err("AUDIO: send EOS failed"); + info->b_commiting = FALSE; + ret = MM_ERROR_CAMCORDER_INTERNAL; + goto _ERR_CAMCORDER_VIDEO_COMMAND; + } + } else { + _mmcam_dbg_log("No audio stream"); } /* sc */ sc->display_interval = 0; sc->previous_slot_time = 0; - /* init system memory size */ - hcamcorder->system_memory = 0; - /* Wait EOS */ _mmcam_dbg_log("Start to wait EOS"); - ret =_mmcamcorder_get_eos_message(handle); + ret = _mmcamcorder_get_eos_message(handle); if (ret != MM_ERROR_NONE) { info->b_commiting = FALSE; goto _ERR_CAMCORDER_VIDEO_COMMAND; } + + /* reset flag */ + hcamcorder->capture_in_recording = FALSE; } break; default: @@ -1043,9 +1179,8 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) return MM_ERROR_NONE; _ERR_CAMCORDER_VIDEO_COMMAND: - if (command == _MMCamcorder_CMD_RECORD) { + if (command == _MMCamcorder_CMD_RECORD) _mmcamcorder_remove_recorder_pipeline((MMHandleType)hcamcorder); - } return ret; } @@ -1073,34 +1208,19 @@ int _mmcamcorder_video_handle_eos(MMHandleType handle) _mmcam_dbg_err(""); - if (hcamcorder->state_change_by_system != _MMCAMCORDER_STATE_CHANGE_BY_ASM) { - /* Play record stop sound */ - _mmcamcorder_sound_solo_play(handle, _MMCAMCORDER_FILEPATH_REC_STOP_SND, FALSE); - } else { - _mmcam_dbg_warn("Play stop sound through pulseaudio"); - -#ifdef _MMCAMCORDER_UPLOAD_SAMPLE - _mmcamcorder_sound_init(handle, _MMCAMCORDER_FILEPATH_REC_STOP_SND); -#else /* _MMCAMCORDER_UPLOAD_SAMPLE */ - _mmcamcorder_sound_init(handle); -#endif /* _MMCAMCORDER_UPLOAD_SAMPLE */ - - _mmcamcorder_sound_play((MMHandleType)hcamcorder, _MMCAMCORDER_SAMPLE_SOUND_NAME_REC_STOP, TRUE); - - _mmcamcorder_sound_finalize(handle); - } + /* Play record stop sound */ + _mmcamcorder_sound_solo_play(handle, _MMCAMCORDER_SAMPLE_SOUND_NAME_REC_STOP, FALSE); /* remove blocking part */ MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "block", FALSE); mm_camcorder_get_attributes(handle, NULL, - MMCAM_RECORDER_TAG_ENABLE, &enabletag, - NULL); + MMCAM_RECORDER_TAG_ENABLE, &enabletag, + NULL); ret = _mmcamcorder_remove_recorder_pipeline((MMHandleType)hcamcorder); - if (ret != MM_ERROR_NONE) { + if (ret != MM_ERROR_NONE) _mmcam_dbg_warn("_MMCamcorder_CMD_COMMIT:__mmcamcorder_remove_recorder_pipeline failed. error[%x]", ret); - } /* set recording hint */ MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "recording-hint", FALSE); @@ -1122,18 +1242,14 @@ int _mmcamcorder_video_handle_eos(MMHandleType handle) if (enabletag && !(sc->ferror_send)) { ret = __mmcamcorder_add_metadata((MMHandleType)hcamcorder, info->fileformat); - if (ret) { - _mmcam_dbg_log("Writing location information SUCCEEDED !!"); - } else { - _mmcam_dbg_err("Writing location information FAILED !!"); - } + _mmcam_dbg_log("Writing location information [%s] !!", ret ? "SUCCEEDED" : "FAILED"); } /* Check file size */ if (info->max_size > 0) { _mmcamcorder_get_file_size(info->filename, &file_size); - _mmcam_dbg_log("MAX size %lld byte - created filesize %lld byte", - info->max_size, file_size); + _mmcam_dbg_log("MAX size %"G_GUINT64_FORMAT" byte - created filesize %"G_GUINT64_FORMAT" byte", + info->max_size, file_size); if (file_size > info->max_size) { _MMCamcorderMsgItem message; @@ -1148,13 +1264,22 @@ int _mmcamcorder_video_handle_eos(MMHandleType handle) /* block queue */ MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst, "empty-buffers", TRUE); MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "empty-buffers", TRUE); + MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "keep-camera-preview", TRUE); _mmcam_dbg_log("Set state of pipeline as READY"); ret = _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_MAIN_PIPE].gst, GST_STATE_READY); + /* check decoder recreation */ + if (!_mmcamcorder_recreate_decoder_for_encoded_preview(handle)) { + _mmcam_dbg_err("_mmcamcorder_recreate_decoder_for_encoded_preview failed"); + ret = MM_ERROR_CAMCORDER_INTERNAL; + } + /* unblock queue */ MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_QUE].gst, "empty-buffers", FALSE); MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_QUE].gst, "empty-buffers", FALSE); + MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "keep-camera-preview", FALSE); + if (ret != MM_ERROR_NONE) { msg.id = MM_MESSAGE_CAMCORDER_ERROR; msg.param.code = ret; @@ -1166,9 +1291,15 @@ int _mmcamcorder_video_handle_eos(MMHandleType handle) info->restart_preview = FALSE; /* recover preview size */ - _mmcamcorder_set_camera_resolution(handle, info->preview_width, info->preview_height); + if (!_mmcamcorder_set_camera_resolution(handle, info->preview_width, info->preview_height)) { + msg.id = MM_MESSAGE_CAMCORDER_ERROR; + msg.param.code = MM_ERROR_CAMCORDER_INTERNAL; + _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg); + _mmcam_dbg_err("Failed to set camera resolution %dx%d", + info->preview_width, info->preview_height); + } - ret =_mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_MAIN_PIPE].gst, GST_STATE_PLAYING); + ret = _mmcamcorder_gst_set_state(handle, sc->element[_MMCAMCORDER_MAIN_PIPE].gst, GST_STATE_PLAYING); /* Do not return when error is occurred. Recording file was created successfully, but starting pipeline failed */ if (ret != MM_ERROR_NONE) { @@ -1183,12 +1314,12 @@ int _mmcamcorder_video_handle_eos(MMHandleType handle) /* Send recording report to application */ msg.id = MM_MESSAGE_CAMCORDER_VIDEO_CAPTURED; - report = (MMCamRecordingReport *)malloc(sizeof(MMCamRecordingReport)); + report = (MMCamRecordingReport *)g_malloc(sizeof(MMCamRecordingReport)); if (!report) { _mmcam_dbg_err("Recording report fail(%s). Out of memory.", info->filename); } else { - report->recording_filename = strdup(info->filename); - msg.param.data= report; + report->recording_filename = g_strdup(info->filename); + msg.param.data = report; msg.param.code = 1; _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg); } @@ -1205,10 +1336,8 @@ int _mmcamcorder_video_handle_eos(MMHandleType handle) info->filesize = 0; info->b_commiting = FALSE; - if (hcamcorder->state_change_by_system != _MMCAMCORDER_STATE_CHANGE_BY_ASM) { - /* check recording stop sound */ - _mmcamcorder_sound_solo_play_wait(handle); - } + /* check recording stop sound */ + _mmcamcorder_sound_solo_play_wait(handle); _mmcam_dbg_err("_MMCamcorder_CMD_COMMIT : end"); @@ -1216,50 +1345,6 @@ int _mmcamcorder_video_handle_eos(MMHandleType handle) } -/** - * This function is record 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. - * - * @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 - * @remarks - * @see - */ -static GstPadProbeReturn __mmcamcorder_eventprobe_monitor(GstPad *pad, GstPadProbeInfo *info, gpointer u_data){ - GstEvent *event = GST_PAD_PROBE_INFO_EVENT(info); - switch (GST_EVENT_TYPE(event)) { - case GST_EVENT_UNKNOWN: - /* upstream events */ - case GST_EVENT_QOS: - case GST_EVENT_SEEK: - case GST_EVENT_NAVIGATION: - case GST_EVENT_LATENCY: - /* downstream serialized events */ - case GST_EVENT_SEGMENT : - 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)); - break; - case GST_EVENT_EOS: - _mmcam_dbg_warn("[%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)); - break; - default: - _mmcam_dbg_log("[%s:%s] gots %s", GST_DEBUG_PAD_NAME(pad), GST_EVENT_TYPE_NAME(event)); - break; - } - - return GST_PAD_PROBE_OK; -} - - static GstPadProbeReturn __mmcamcorder_audio_dataprobe_check(GstPad *pad, GstPadProbeInfo *info, gpointer u_data) { mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data); @@ -1270,6 +1355,7 @@ static GstPadProbeReturn __mmcamcorder_audio_dataprobe_check(GstPad *pad, GstPad _MMCamcorderMsgItem msg; guint64 buffer_size = 0; guint64 trailer_size = 0; + guint64 max_size = 0; mmf_return_val_if_fail(hcamcorder, GST_PAD_PROBE_OK); mmf_return_val_if_fail(buffer, GST_PAD_PROBE_DROP); @@ -1289,50 +1375,48 @@ static GstPadProbeReturn __mmcamcorder_audio_dataprobe_check(GstPad *pad, GstPad /*_mmcam_dbg_err("[%" GST_TIME_FORMAT "]", GST_TIME_ARGS(GST_BUFFER_PTS(buffer)));*/ - pthread_mutex_lock(&(videoinfo->size_check_lock)); + g_mutex_lock(&videoinfo->size_check_lock); if (videoinfo->audio_frame_count == 0) { videoinfo->filesize += buffer_size; videoinfo->audio_frame_count++; - pthread_mutex_unlock(&(videoinfo->size_check_lock)); + g_mutex_unlock(&videoinfo->size_check_lock); return GST_PAD_PROBE_OK; } if (sc->ferror_send || sc->isMaxsizePausing) { _mmcam_dbg_warn("Recording is paused, drop frames"); - pthread_mutex_unlock(&(videoinfo->size_check_lock)); + g_mutex_unlock(&videoinfo->size_check_lock); return GST_PAD_PROBE_DROP; } /* get trailer size */ - if (videoinfo->fileformat == MM_FILE_FORMAT_3GP || videoinfo->fileformat == MM_FILE_FORMAT_MP4) { + if (videoinfo->fileformat == MM_FILE_FORMAT_3GP || videoinfo->fileformat == MM_FILE_FORMAT_MP4) MMCAMCORDER_G_OBJECT_GET(sc->encode_element[_MMCAMCORDER_ENCSINK_MUX].gst, "expected-trailer-size", &trailer_size); - } else { + else trailer_size = 0; - } /* check max size of recorded file */ - if (videoinfo->max_size > 0 && - videoinfo->max_size < videoinfo->filesize + buffer_size + trailer_size + _MMCAMCORDER_MMS_MARGIN_SPACE) { + max_size = videoinfo->filesize + buffer_size + trailer_size + _MMCAMCORDER_MMS_MARGIN_SPACE; + if (videoinfo->max_size > 0 && videoinfo->max_size < max_size) { GstState pipeline_state = GST_STATE_VOID_PENDING; GstElement *pipeline = sc->element[_MMCAMCORDER_MAIN_PIPE].gst; _mmcam_dbg_warn("Max size!!! Recording is paused."); _mmcam_dbg_warn("Max size : [%" G_GUINT64_FORMAT "], current file size : [%" G_GUINT64_FORMAT "]," \ - " buffer size : [%" G_GUINT64_FORMAT "], trailer size : [%" G_GUINT64_FORMAT "]", - videoinfo->max_size, videoinfo->filesize, buffer_size, trailer_size); + " buffer size : [%" G_GUINT64_FORMAT "], trailer size : [%" G_GUINT64_FORMAT "]", + videoinfo->max_size, videoinfo->filesize, buffer_size, trailer_size); if (!sc->isMaxsizePausing) { sc->isMaxsizePausing = TRUE; gst_element_get_state(pipeline, &pipeline_state, NULL, -1) ; - if (pipeline_state == GST_STATE_PLAYING) { + if (pipeline_state == GST_STATE_PLAYING) MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "block", TRUE); - } msg.id = MM_MESSAGE_CAMCORDER_MAX_SIZE; _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg); } - pthread_mutex_unlock(&(videoinfo->size_check_lock)); + g_mutex_unlock(&videoinfo->size_check_lock); return FALSE; } @@ -1340,7 +1424,7 @@ static GstPadProbeReturn __mmcamcorder_audio_dataprobe_check(GstPad *pad, GstPad videoinfo->filesize += buffer_size; videoinfo->audio_frame_count++; - pthread_mutex_unlock(&(videoinfo->size_check_lock)); + g_mutex_unlock(&videoinfo->size_check_lock); return GST_PAD_PROBE_OK; } @@ -1355,9 +1439,10 @@ static GstPadProbeReturn __mmcamcorder_video_dataprobe_record(GstPad *pad, GstPa guint64 buffer_size = 0; guint64 trailer_size = 0; guint64 queued_buffer = 0; - char *filename = NULL; + guint64 max_size = 0; GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info); GstMapInfo mapinfo; + storage_state_e storage_state = STORAGE_STATE_UNMOUNTABLE; mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data); _MMCamcorderMsgItem msg; @@ -1384,104 +1469,118 @@ static GstPadProbeReturn __mmcamcorder_video_dataprobe_record(GstPad *pad, GstPa videoinfo->video_frame_count++; if (videoinfo->video_frame_count <= (guint64)_MMCAMCORDER_MINIMUM_FRAME) { /* _mmcam_dbg_log("Pass minimum frame: info->video_frame_count: %" G_GUINT64_FORMAT " ", - info->video_frame_count); */ - pthread_mutex_lock(&(videoinfo->size_check_lock)); + info->video_frame_count); */ + g_mutex_lock(&videoinfo->size_check_lock); videoinfo->filesize += buffer_size; - pthread_mutex_unlock(&(videoinfo->size_check_lock)); + g_mutex_unlock(&videoinfo->size_check_lock); return GST_PAD_PROBE_OK; } /* get trailer size */ - if (videoinfo->fileformat == MM_FILE_FORMAT_3GP || videoinfo->fileformat == MM_FILE_FORMAT_MP4) { + if (videoinfo->fileformat == MM_FILE_FORMAT_3GP || videoinfo->fileformat == MM_FILE_FORMAT_MP4) MMCAMCORDER_G_OBJECT_GET(sc->encode_element[_MMCAMCORDER_ENCSINK_MUX].gst, "expected-trailer-size", &trailer_size); - } else { + else trailer_size = 0; - } - - filename = videoinfo->filename; - ret = _mmcamcorder_get_freespace(filename, &free_space); - - if(_mmcamcorder_check_file_path(filename) && hcamcorder->system_memory) { - free_space = free_space - hcamcorder->system_memory; - } - - /*_mmcam_dbg_log("check free space for recording");*/ - switch (ret) { - case -2: /* file not exist */ - case -1: /* failed to get free space */ + /* check free space */ + ret = _mmcamcorder_get_freespace(hcamcorder->storage_info.type, &free_space); + if (ret != 0) { _mmcam_dbg_err("Error occured. [%d]", ret); if (sc->ferror_count == 2 && sc->ferror_send == FALSE) { sc->ferror_send = TRUE; + msg.id = MM_MESSAGE_CAMCORDER_ERROR; - if (ret == -2) { - msg.param.code = MM_ERROR_FILE_NOT_FOUND; - } else { - msg.param.code = MM_ERROR_FILE_READ; - } + msg.param.code = MM_ERROR_FILE_READ; + _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg); } else { sc->ferror_count++; } return GST_PAD_PROBE_DROP; /* skip this buffer */ - break; - default: /* succeeded to get free space */ - /* check free space for recording */ - /* get queued buffer size */ - if (sc->encode_element[_MMCAMCORDER_ENCSINK_AENC_QUE].gst) { - MMCAMCORDER_G_OBJECT_GET(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC_QUE].gst, "current-level-bytes", &aq_size); - } - if (sc->encode_element[_MMCAMCORDER_ENCSINK_VENC_QUE].gst) { - MMCAMCORDER_G_OBJECT_GET(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC_QUE].gst, "current-level-bytes", &vq_size); - } + } - queued_buffer = aq_size + vq_size; + if (free_space == 0) { + /* check storage state */ + storage_get_state(hcamcorder->storage_info.id, &storage_state); - /* check free space */ - if (free_space < (_MMCAMCORDER_MINIMUM_SPACE + buffer_size + trailer_size + queued_buffer)) { - _mmcam_dbg_warn("No more space for recording!!! Recording is paused."); - _mmcam_dbg_warn("Free Space : [%" G_GUINT64_FORMAT "], trailer size : [%" G_GUINT64_FORMAT "]," \ - " buffer size : [%" G_GUINT64_FORMAT "], queued buffer size : [%" G_GUINT64_FORMAT "]", \ - free_space, trailer_size, buffer_size, queued_buffer); + _mmcam_dbg_warn("storage state %d", storage_state); - if (!sc->isMaxsizePausing) { - MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "block", TRUE); - sc->isMaxsizePausing = TRUE; + if (storage_state == STORAGE_STATE_REMOVED || + storage_state == STORAGE_STATE_UNMOUNTABLE) { + _mmcam_dbg_err("storage was removed!"); + + _MMCAMCORDER_LOCK(hcamcorder); + + if (sc->ferror_send == FALSE) { + _mmcam_dbg_err("OUT_OF_STORAGE error"); + + sc->ferror_send = TRUE; + + _MMCAMCORDER_UNLOCK(hcamcorder); + + msg.id = MM_MESSAGE_CAMCORDER_ERROR; + msg.param.code = MM_ERROR_OUT_OF_STORAGE; - msg.id = MM_MESSAGE_CAMCORDER_NO_FREE_SPACE; _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg); + } else { + _MMCAMCORDER_UNLOCK(hcamcorder); + _mmcam_dbg_warn("error was already sent"); } return GST_PAD_PROBE_DROP; } - break; } - pthread_mutex_lock(&(videoinfo->size_check_lock)); + /* get queued buffer size */ + if (sc->encode_element[_MMCAMCORDER_ENCSINK_AENC_QUE].gst) + MMCAMCORDER_G_OBJECT_GET(sc->encode_element[_MMCAMCORDER_ENCSINK_AENC_QUE].gst, "current-level-bytes", &aq_size); + + if (sc->encode_element[_MMCAMCORDER_ENCSINK_VENC_QUE].gst) + MMCAMCORDER_G_OBJECT_GET(sc->encode_element[_MMCAMCORDER_ENCSINK_VENC_QUE].gst, "current-level-bytes", &vq_size); + + queued_buffer = aq_size + vq_size; + + if (free_space < (_MMCAMCORDER_MINIMUM_SPACE + buffer_size + trailer_size + queued_buffer)) { + _mmcam_dbg_warn("No more space for recording!!! Recording is paused."); + _mmcam_dbg_warn("Free Space : [%" G_GUINT64_FORMAT "], trailer size : [%" G_GUINT64_FORMAT "]," \ + " buffer size : [%" G_GUINT64_FORMAT "], queued buffer size : [%" G_GUINT64_FORMAT "]", \ + free_space, trailer_size, buffer_size, queued_buffer); + + if (!sc->isMaxsizePausing) { + MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "block", TRUE); + sc->isMaxsizePausing = TRUE; + + msg.id = MM_MESSAGE_CAMCORDER_NO_FREE_SPACE; + _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg); + } + + return GST_PAD_PROBE_DROP; + } + + g_mutex_lock(&videoinfo->size_check_lock); /* check max size of recorded file */ - if (videoinfo->max_size > 0 && - videoinfo->max_size < videoinfo->filesize + buffer_size + trailer_size + _MMCAMCORDER_MMS_MARGIN_SPACE) { + max_size = videoinfo->filesize + buffer_size + trailer_size + _MMCAMCORDER_MMS_MARGIN_SPACE; + if (videoinfo->max_size > 0 && videoinfo->max_size < max_size) { GstState pipeline_state = GST_STATE_VOID_PENDING; GstElement *pipeline = sc->element[_MMCAMCORDER_MAIN_PIPE].gst; _mmcam_dbg_warn("Max size!!! Recording is paused."); _mmcam_dbg_warn("Max size : [%" G_GUINT64_FORMAT "], current file size : [%" G_GUINT64_FORMAT "]," \ - " buffer size : [%" G_GUINT64_FORMAT "], trailer size : [%" G_GUINT64_FORMAT "]", - videoinfo->max_size, videoinfo->filesize, buffer_size, trailer_size); + " buffer size : [%" G_GUINT64_FORMAT "], trailer size : [%" G_GUINT64_FORMAT "]", + videoinfo->max_size, videoinfo->filesize, buffer_size, trailer_size); if (!sc->isMaxsizePausing) { sc->isMaxsizePausing = TRUE; gst_element_get_state(pipeline, &pipeline_state, NULL, -1) ; - if (pipeline_state == GST_STATE_PLAYING) { + if (pipeline_state == GST_STATE_PLAYING) MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "block", TRUE); - } msg.id = MM_MESSAGE_CAMCORDER_MAX_SIZE; _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg); } - pthread_mutex_unlock(&(videoinfo->size_check_lock)); + g_mutex_unlock(&videoinfo->size_check_lock); return GST_PAD_PROBE_DROP; } @@ -1492,7 +1591,7 @@ static GstPadProbeReturn __mmcamcorder_video_dataprobe_record(GstPad *pad, GstPa _mmcam_dbg_log("filesize %lld Byte, ", videoinfo->filesize); */ - pthread_mutex_unlock(&(videoinfo->size_check_lock)); + g_mutex_unlock(&videoinfo->size_check_lock); return GST_PAD_PROBE_OK; } @@ -1526,16 +1625,15 @@ static GstPadProbeReturn __mmcamcorder_video_dataprobe_audio_disable(GstPad *pad rec_pipe_time = GST_TIME_AS_MSECONDS(b_time); - if (videoinfo->fileformat == MM_FILE_FORMAT_3GP || videoinfo->fileformat == MM_FILE_FORMAT_MP4) { + if (videoinfo->fileformat == MM_FILE_FORMAT_3GP || videoinfo->fileformat == MM_FILE_FORMAT_MP4) MMCAMCORDER_G_OBJECT_GET(sc->encode_element[_MMCAMCORDER_ENCSINK_MUX].gst, "expected-trailer-size", &trailer_size); - } else { + else trailer_size = 0; - } /* check max time */ if (videoinfo->max_time > 0 && rec_pipe_time > videoinfo->max_time) { - _mmcam_dbg_warn("Current time : [%" G_GUINT64_FORMAT "], Maximum time : [%" G_GUINT64_FORMAT "]", \ - rec_pipe_time, videoinfo->max_time); + _mmcam_dbg_warn("Time current [%" G_GUINT64_FORMAT "], Max [%" G_GUINT64_FORMAT "], motion rate [%lf]", \ + rec_pipe_time, videoinfo->max_time, videoinfo->record_motion_rate); if (!sc->isMaxtimePausing) { MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "block", TRUE); @@ -1573,7 +1671,7 @@ static GstPadProbeReturn __mmcamcorder_video_dataprobe_audio_disable(GstPad *pad /* _mmcam_dbg_log("time [%" GST_TIME_FORMAT "], size [%d]", - GST_TIME_ARGS(rec_pipe_time), msg.param.recording_status.filesize); + GST_TIME_ARGS(rec_pipe_time), msg.param.recording_status.filesize); */ if (videoinfo->record_timestamp_ratio != _MMCAMCORDER_DEFAULT_RECORDING_MOTION_RATE) { @@ -1581,7 +1679,7 @@ static GstPadProbeReturn __mmcamcorder_video_dataprobe_audio_disable(GstPad *pad /* _mmcam_dbg_log("record_motion_rate %d, videoinfo->record_drop_count %d", - record_motion_rate, videoinfo->record_drop_count); + record_motion_rate, videoinfo->record_drop_count); */ /* drop some frame if fast motion */ @@ -1600,6 +1698,7 @@ static GstPadProbeReturn __mmcamcorder_video_dataprobe_audio_disable(GstPad *pad } GST_BUFFER_PTS(buffer) = b_time * (videoinfo->record_timestamp_ratio); + GST_BUFFER_DTS(buffer) = GST_BUFFER_PTS(buffer); } return GST_PAD_PROBE_OK; @@ -1628,17 +1727,16 @@ static GstPadProbeReturn __mmcamcorder_audioque_dataprobe(GstPad *pad, GstPadPro videoinfo = sc->info_video; if (!GST_CLOCK_TIME_IS_VALID(GST_BUFFER_PTS(buffer))) { - _mmcam_dbg_err( "Buffer timestamp is invalid, check it"); + _mmcam_dbg_err("Buffer timestamp is invalid, check it"); return GST_PAD_PROBE_OK; } rec_pipe_time = GST_TIME_AS_MSECONDS(GST_BUFFER_PTS(buffer)); - if (videoinfo->fileformat == MM_FILE_FORMAT_3GP || videoinfo->fileformat == MM_FILE_FORMAT_MP4) { + if (videoinfo->fileformat == MM_FILE_FORMAT_3GP || videoinfo->fileformat == MM_FILE_FORMAT_MP4) MMCAMCORDER_G_OBJECT_GET(sc->encode_element[_MMCAMCORDER_ENCSINK_MUX].gst, "expected-trailer-size", &trailer_size); - } else { + else trailer_size = 0; - } /* calculate remained time can be recorded */ if (videoinfo->max_time > 0 && videoinfo->max_time < (remained_time + rec_pipe_time)) { @@ -1651,8 +1749,8 @@ static GstPadProbeReturn __mmcamcorder_audioque_dataprobe(GstPad *pad, GstPadPro } if (videoinfo->max_time > 0 && rec_pipe_time > videoinfo->max_time) { - _mmcam_dbg_warn("Current time : [%" G_GUINT64_FORMAT "], Maximum time : [%" G_GUINT64_FORMAT "]", \ - rec_pipe_time, videoinfo->max_time); + _mmcam_dbg_warn("Time current [%" G_GUINT64_FORMAT "], Max [%" G_GUINT64_FORMAT "], motion rate [%lf]", \ + rec_pipe_time, videoinfo->max_time, videoinfo->record_motion_rate); if (!sc->isMaxtimePausing) { MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "block", TRUE); @@ -1680,7 +1778,7 @@ static GstPadProbeReturn __mmcamcorder_audioque_dataprobe(GstPad *pad, GstPadPro /* _mmcam_dbg_log("audio data probe :: time [%" GST_TIME_FORMAT "], size [%lld KB]", - GST_TIME_ARGS(rec_pipe_time), msg.param.recording_status.filesize); + GST_TIME_ARGS(rec_pipe_time), msg.param.recording_status.filesize); */ return GST_PAD_PROBE_OK; @@ -1703,10 +1801,10 @@ static GstPadProbeReturn __mmcamcorder_audio_dataprobe_audio_mute(GstPad *pad, G /*_mmcam_dbg_log("AUDIO SRC time stamp : [%" GST_TIME_FORMAT "] \n", GST_TIME_ARGS(GST_BUFFER_PTS(buffer)));*/ err = mm_camcorder_get_attributes((MMHandleType)hcamcorder, &err_name, - MMCAM_AUDIO_VOLUME, &volume, - MMCAM_AUDIO_FORMAT, &format, - MMCAM_AUDIO_CHANNEL, &channel, - NULL); + MMCAM_AUDIO_VOLUME, &volume, + MMCAM_AUDIO_FORMAT, &format, + MMCAM_AUDIO_CHANNEL, &channel, + NULL); if (err != MM_ERROR_NONE) { _mmcam_dbg_warn("Get attrs fail. (%s:%x)", err_name, err); SAFE_FREE(err_name); @@ -1718,9 +1816,8 @@ static GstPadProbeReturn __mmcamcorder_audio_dataprobe_audio_mute(GstPad *pad, G gst_buffer_map(buffer, &mapinfo, GST_MAP_READWRITE); /* Set audio stream NULL */ - if (volume == 0.0) { + if (volume == 0.0) memset(mapinfo.data, 0, mapinfo.size); - } /* CALL audio stream callback */ if (hcamcorder->astream_cb && buffer && mapinfo.data && mapinfo.size > 0) { @@ -1733,7 +1830,7 @@ static GstPadProbeReturn __mmcamcorder_audio_dataprobe_audio_mute(GstPad *pad, G } /*_mmcam_dbg_log("Call video steramCb, data[%p], Width[%d],Height[%d], Format[%d]", - GST_BUFFER_DATA(buffer), width, height, format);*/ + GST_BUFFER_DATA(buffer), width, height, format);*/ stream.data = (void *)mapinfo.data; stream.format = format; @@ -1743,9 +1840,8 @@ static GstPadProbeReturn __mmcamcorder_audio_dataprobe_audio_mute(GstPad *pad, G _MMCAMCORDER_LOCK_ASTREAM_CALLBACK(hcamcorder); - if (hcamcorder->astream_cb) { + if (hcamcorder->astream_cb) hcamcorder->astream_cb(&stream, hcamcorder->astream_cb_param); - } _MMCAMCORDER_UNLOCK_ASTREAM_CALLBACK(hcamcorder); } @@ -1789,8 +1885,8 @@ static gboolean __mmcamcorder_add_metadata_mp4(MMHandleType handle) int gps_enable = 0; char *err_name = NULL; char err_msg[MAX_ERROR_MESSAGE_LEN] = {'\0',}; - _MMCamcorderLocationInfo location_info = {0,0,0}; - _MMCamcorderLocationInfo geo_info = {0,0,0}; + _MMCamcorderLocationInfo location_info = {0, 0, 0}; + _MMCamcorderLocationInfo geo_info = {0, 0, 0}; _MMCamcorderVideoInfo *info = NULL; mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle); @@ -1814,15 +1910,15 @@ static gboolean __mmcamcorder_add_metadata_mp4(MMHandleType handle) } mm_camcorder_get_attributes(handle, &err_name, - MMCAM_TAG_LATITUDE, &latitude, - MMCAM_TAG_LONGITUDE, &longitude, - MMCAM_TAG_ALTITUDE, &altitude, - MMCAM_TAG_VIDEO_ORIENTATION, &orientation, - MMCAM_TAG_GPS_ENABLE, &gps_enable, - NULL); + MMCAM_TAG_LATITUDE, &latitude, + MMCAM_TAG_LONGITUDE, &longitude, + MMCAM_TAG_ALTITUDE, &altitude, + MMCAM_TAG_VIDEO_ORIENTATION, &orientation, + MMCAM_TAG_GPS_ENABLE, &gps_enable, + NULL); if (err_name) { _mmcam_dbg_warn("Get tag attrs fail. (%s:%x)", err_name, err); - SAFE_FREE (err_name); + SAFE_FREE(err_name); } location_info.longitude = _mmcamcorder_double_to_fix(longitude); @@ -1834,31 +1930,28 @@ static gboolean __mmcamcorder_add_metadata_mp4(MMHandleType handle) /* find udta container. if, there are udta container, write loci box after that else, make udta container and write loci box. */ - if (_mmcamcorder_find_fourcc(f, MMCAM_FOURCC('u','d','t','a'), TRUE)) { + if (_mmcamcorder_find_fourcc(f, MMCAM_FOURCC('u', 'd', 't', 'a'), TRUE)) { size_t nread = 0; _mmcam_dbg_log("find udta container"); /* read size */ - if (fseek(f, -8L, SEEK_CUR) != 0) { + if (fseek(f, -8L, SEEK_CUR) != 0) goto fail; - } udta_pos = ftello(f); - if (udta_pos < 0) { + if (udta_pos < 0) goto ftell_fail; - } nread = fread(&buf, sizeof(char), sizeof(buf), f); - _mmcam_dbg_log("recorded file fread %d", nread); + _mmcam_dbg_log("recorded file fread %zu", nread); udta_size = _mmcamcorder_get_container_size(buf); /* goto end of udta and write 'loci' box */ - if (fseek(f, (udta_size-4L), SEEK_CUR) != 0) { + if (fseek(f, (udta_size-4L), SEEK_CUR) != 0) goto fail; - } if (gps_enable) { if (!_mmcamcorder_write_loci(f, location_info)) { @@ -1873,18 +1966,15 @@ static gboolean __mmcamcorder_add_metadata_mp4(MMHandleType handle) } current_pos = ftello(f); - if (current_pos < 0) { + if (current_pos < 0) goto ftell_fail; - } - if (!_mmcamcorder_update_size(f, udta_pos, current_pos)) { + if (!_mmcamcorder_update_size(f, udta_pos, current_pos)) goto fail; - } } else { _mmcam_dbg_log("No udta container"); - if (fseek(f, 0, SEEK_END) != 0) { + if (fseek(f, 0, SEEK_END) != 0) goto fail; - } if (!_mmcamcorder_write_udta(f, gps_enable, location_info, geo_info)) { _mmcam_dbg_err("failed to write udta"); @@ -1894,38 +1984,35 @@ static gboolean __mmcamcorder_add_metadata_mp4(MMHandleType handle) /* find moov container. update moov container size. */ - if((current_pos = ftello(f))<0) + if ((current_pos = ftello(f)) < 0) goto ftell_fail; - if (_mmcamcorder_find_tag(f, MMCAM_FOURCC('m','o','o','v'), TRUE)) { + if (_mmcamcorder_find_tag(f, MMCAM_FOURCC('m', 'o', 'o', 'v'), TRUE)) { gint64 internal_pos = ftello(f); _mmcam_dbg_log("found moov container"); - if (fseek(f, -8L, SEEK_CUR) !=0) { + if (fseek(f, -8L, SEEK_CUR) != 0) goto fail; - } moov_pos = ftello(f); - if (moov_pos < 0) { + if (moov_pos < 0) goto ftell_fail; - } - if (!_mmcamcorder_update_size(f, moov_pos, current_pos)) { + if (!_mmcamcorder_update_size(f, moov_pos, current_pos)) goto fail; - } /* add orientation info */ if (fseeko(f, internal_pos, SEEK_SET) < 0) { - _mmcam_dbg_err("fseek failed : errno %d", errno); + _mmcam_dbg_err("fseeko failed : errno %d", errno); goto fail; } - if (!_mmcamcorder_find_tag(f, MMCAM_FOURCC('t','r','a','k'), FALSE)) { + if (!_mmcamcorder_find_tag(f, MMCAM_FOURCC('t', 'r', 'a', 'k'), FALSE)) { _mmcam_dbg_err("failed to find [trak] tag"); goto fail; } - if (!_mmcamcorder_find_tag(f, MMCAM_FOURCC('t','k','h','d'), FALSE)) { + if (!_mmcamcorder_find_tag(f, MMCAM_FOURCC('t', 'k', 'h', 'd'), FALSE)) { _mmcam_dbg_err("failed to find [tkhd] tag"); goto fail; } @@ -1933,10 +2020,13 @@ static gboolean __mmcamcorder_add_metadata_mp4(MMHandleType handle) _mmcam_dbg_log("found [tkhd] tag"); /* seek to start position of composition matrix */ - fseek(f, _OFFSET_COMPOSITION_MATRIX, SEEK_CUR); - - /* update composition matrix for orientation */ - _mmcamcorder_update_composition_matrix(f, orientation); + if (fseek(f, _OFFSET_COMPOSITION_MATRIX, SEEK_CUR) == 0) { + /* update composition matrix for orientation */ + _mmcamcorder_update_composition_matrix(f, orientation); + } else { + _mmcam_dbg_err("fseek failed : errno %d", errno); + goto fail; + } } else { _mmcam_dbg_err("No 'moov' container"); goto fail; @@ -1970,9 +2060,9 @@ int _mmcamcorder_connect_video_stream_cb_signal(MMHandleType handle) if (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst) { _mmcam_dbg_warn("connect video stream cb signal to _MMCAMCORDER_VIDEOSRC_SRC"); MMCAMCORDER_SIGNAL_CONNECT(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, - _MMCAMCORDER_HANDLER_VIDEOREC, "video-stream-cb", - G_CALLBACK(__mmcamcorder_video_stream_cb), - hcamcorder); + _MMCAMCORDER_HANDLER_VIDEOREC, "video-stream-cb", + G_CALLBACK(__mmcamcorder_video_stream_cb), + hcamcorder); return MM_ERROR_NONE; } else { _mmcam_dbg_err("videosrc element is not created yet"); @@ -1984,6 +2074,8 @@ int _mmcamcorder_connect_video_stream_cb_signal(MMHandleType handle) int _mmcamcorder_video_prepare_record(MMHandleType handle) { int ret = MM_ERROR_NONE; + int size = 0; + char *temp_filename = NULL; _MMCamcorderVideoInfo *info = NULL; _MMCamcorderSubContext *sc = NULL; @@ -2000,31 +2092,29 @@ int _mmcamcorder_video_prepare_record(MMHandleType handle) _mmcam_dbg_warn("start"); /* create encoding pipeline */ - ret =_mmcamcorder_create_recorder_pipeline((MMHandleType)hcamcorder); - if (ret != MM_ERROR_NONE) { + ret = _mmcamcorder_create_recorder_pipeline((MMHandleType)hcamcorder); + if (ret != MM_ERROR_NONE) goto _ERR_PREPARE_RECORD; - } - - if (info->filename == NULL) { - char *temp_filename = NULL; - int size = 0; - mm_camcorder_get_attributes(handle, NULL, - MMCAM_TARGET_FILENAME, &temp_filename, &size, - NULL); - if (temp_filename) { - info->filename = strdup(temp_filename); - } + SAFE_G_FREE(info->filename); + mm_camcorder_get_attributes(handle, NULL, + MMCAM_TARGET_FILENAME, &temp_filename, &size, + NULL); + if (temp_filename) { + info->filename = g_strdup(temp_filename); if (!info->filename) { _mmcam_dbg_err("strdup[src:%p] was failed", temp_filename); goto _ERR_PREPARE_RECORD; } - } - _mmcam_dbg_log("Record file name [%s]", info->filename); + _mmcam_dbg_log("Record file name [%s]", info->filename); + MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst, "location", info->filename); + } else { + _mmcam_dbg_log("Recorded data will be written in [%s]", _MMCamcorder_FILENAME_NULL); + MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst, "location", _MMCamcorder_FILENAME_NULL); + } - MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst, "location", info->filename); MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_ENCBIN].gst, "block", 0); /* Adjust display FPS */ @@ -2032,9 +2122,8 @@ int _mmcamcorder_video_prepare_record(MMHandleType handle) sc->previous_slot_time = 0; ret = _mmcamcorder_gst_set_state(handle, sc->encode_element[_MMCAMCORDER_ENCODE_MAIN_PIPE].gst, GST_STATE_PAUSED); - if (ret != MM_ERROR_NONE) { + if (ret != MM_ERROR_NONE) goto _ERR_PREPARE_RECORD; - } _mmcam_dbg_warn("done");