X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fmm_camcorder_videorec.c;h=69565ab7bc829b31d66f46a6ef30d78e772b5e55;hb=3e3fcb7eedc07a5c517bc85a74cbd94e961091a7;hp=de054ed559406f8716244bec16eeaf3e0d2624c3;hpb=35b5a6c84ff9425fc4bc02e20fc47edb5dcc6a1d;p=platform%2Fcore%2Fmultimedia%2Flibmm-camcorder.git diff --git a/src/mm_camcorder_videorec.c b/src/mm_camcorder_videorec.c index de054ed..69565ab 100644 --- a/src/mm_camcorder_videorec.c +++ b/src/mm_camcorder_videorec.c @@ -463,6 +463,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,8 +505,8 @@ 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); @@ -525,6 +526,7 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) 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); @@ -554,18 +556,9 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) 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_free_space = _mmcamcorder_get_freespace(dir_name, hcamcorder->root_directory, &free_space); - _mmcam_dbg_warn("current space - %s [%" G_GUINT64_FORMAT "], system [%" G_GUINT64_FORMAT "]", - dir_name, free_space, hcamcorder->system_memory); + _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 */ @@ -634,6 +627,9 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) info->restart_preview = TRUE; } + /* set recording hint */ + MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "recording-hint", TRUE); + if (info->restart_preview) { /* stop preview and set new size */ _mmcam_dbg_log("restart preview"); @@ -710,10 +706,10 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) CameraControl = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst); if (CameraControl) { MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "stop-video", TRUE); -#ifdef LATEST_CAMERA_CONTROL + _mmcam_dbg_log("GST_CAMERA_CONTROL_RECORD_COMMAND_START"); gst_camera_control_set_record_command(CameraControl, GST_CAMERA_CONTROL_RECORD_COMMAND_START); -#endif /* LATEST_CAMERA_CONTROL */ + MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "stop-video", FALSE); } else { _mmcam_dbg_err("could not get camera control"); @@ -761,10 +757,10 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) CameraControl = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst); if (CameraControl) { MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "stop-video", TRUE); -#ifdef LATEST_CAMERA_CONTROL + _mmcam_dbg_log("GST_CAMERA_CONTROL_RECORD_COMMAND_STOP"); gst_camera_control_set_record_command(CameraControl, GST_CAMERA_CONTROL_RECORD_COMMAND_STOP); -#endif /* LATEST_CAMERA_CONTROL */ + MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "stop-video", FALSE); } else { _mmcam_dbg_err("failed to get camera control"); @@ -835,8 +831,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; @@ -848,11 +842,11 @@ 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 "", + _mmcam_dbg_err("Pause fail, frame count %llu", 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 "", + _mmcam_dbg_warn("Waiting for enough video frame, retrial[%d], frame %llu", count, info->video_frame_count); } @@ -862,11 +856,11 @@ 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 "]", + _mmcam_dbg_err("Pause fail, frame count VIDEO[%llu], AUDIO [%llu]", 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 "]", + _mmcam_dbg_warn("Waiting for enough frames, retrial [%d], VIDEO[%llu], AUDIO [%llu]", count, info->video_frame_count, info->audio_frame_count); } @@ -885,6 +879,21 @@ 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; @@ -893,15 +902,18 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) goto _ERR_CAMCORDER_VIDEO_COMMAND; } + /* set recording hint */ + MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst, "recording-hint", FALSE); + /* stop video stream */ if (info->record_dual_stream) { CameraControl = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst); if (CameraControl) { MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "stop-video", TRUE); -#ifdef LATEST_CAMERA_CONTROL + _mmcam_dbg_log("GST_CAMERA_CONTROL_RECORD_COMMAND_STOP"); gst_camera_control_set_record_command(CameraControl, GST_CAMERA_CONTROL_RECORD_COMMAND_STOP); -#endif /* LATEST_CAMERA_CONTROL */ + MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "stop-video", FALSE); } else { _mmcam_dbg_err("failed to get camera control"); @@ -949,12 +961,11 @@ 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; - if (info->b_commiting) { _mmcam_dbg_err("now on commiting previous file!!(command : %d)", command); return MM_ERROR_CAMCORDER_CMD_IS_RUNNING; @@ -967,36 +978,48 @@ 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 %llu, 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 %llu, 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[%llu], AUDIO [%llu], 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[%llu], AUDIO [%llu], capturing %d", + count, info->video_frame_count, info->audio_frame_count, hcamcorder->capture_in_recording); } - - usleep(_MMCAMCORDER_FRAME_WAIT_TIME); } + + usleep(_MMCAMCORDER_FRAME_WAIT_TIME); } /* block push buffer */ @@ -1004,22 +1027,38 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) _mmcam_dbg_log("block push buffer to appsrc"); 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); @@ -1027,6 +1066,9 @@ int _mmcamcorder_video_command(MMHandleType handle, int command) info->b_commiting = FALSE; goto _ERR_CAMCORDER_VIDEO_COMMAND; } + + /* reset flag */ + hcamcorder->capture_in_recording = FALSE; } break; default: @@ -1073,11 +1115,7 @@ int _mmcamcorder_video_handle_eos(MMHandleType handle) } 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); @@ -1096,15 +1134,18 @@ int _mmcamcorder_video_handle_eos(MMHandleType handle) _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); + /* stop video stream */ if (info->record_dual_stream) { GstCameraControl *control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst); if (control) { MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "stop-video", TRUE); -#ifdef LATEST_CAMERA_CONTROL + _mmcam_dbg_log("GST_CAMERA_CONTROL_RECORD_COMMAND_STOP"); gst_camera_control_set_record_command(control, GST_CAMERA_CONTROL_RECORD_COMMAND_STOP); -#endif /* LATEST_CAMERA_CONTROL */ + MMCAMCORDER_G_OBJECT_SET(sc->element[_MMCAMCORDER_VIDEOSINK_SINK].gst, "stop-video", FALSE); } else { _mmcam_dbg_err("failed to get camera control"); @@ -1346,7 +1387,7 @@ static GstPadProbeReturn __mmcamcorder_video_dataprobe_record(GstPad *pad, GstPa guint64 buffer_size = 0; guint64 trailer_size = 0; guint64 queued_buffer = 0; - char *filename = NULL; + char *dir_name = NULL; GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info); GstMapInfo mapinfo; @@ -1389,11 +1430,14 @@ static GstPadProbeReturn __mmcamcorder_video_dataprobe_record(GstPad *pad, GstPa 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; + dir_name = g_path_get_dirname(videoinfo->filename); + if (dir_name) { + ret = _mmcamcorder_get_freespace(dir_name, hcamcorder->root_directory, &free_space); + g_free(dir_name); + dir_name = NULL; + } else { + _mmcam_dbg_err("failed to get dir name from [%s]", videoinfo->filename); + ret = -1; } /*_mmcam_dbg_log("check free space for recording");*/ @@ -1797,7 +1841,7 @@ static gboolean __mmcamcorder_add_metadata_mp4(MMHandleType handle) info = sc->info_video; - f = fopen(info->filename, "rb+"); + f = fopen64(info->filename, "rb+"); if (f == NULL) { strerror_r(errno, err_msg, MAX_ERROR_MESSAGE_LEN); _mmcam_dbg_err("file open failed [%s]", err_msg); @@ -1835,7 +1879,7 @@ static gboolean __mmcamcorder_add_metadata_mp4(MMHandleType handle) goto fail; } - udta_pos = ftell(f); + udta_pos = ftello(f); if (udta_pos < 0) { goto ftell_fail; } @@ -1863,7 +1907,7 @@ static gboolean __mmcamcorder_add_metadata_mp4(MMHandleType handle) } } - current_pos = ftell(f); + current_pos = ftello(f); if (current_pos < 0) { goto ftell_fail; } @@ -1885,18 +1929,18 @@ static gboolean __mmcamcorder_add_metadata_mp4(MMHandleType handle) /* find moov container. update moov container size. */ - if((current_pos = ftell(f))<0) + if((current_pos = ftello(f))<0) goto ftell_fail; if (_mmcamcorder_find_tag(f, MMCAM_FOURCC('m','o','o','v'), TRUE)) { - gint64 internal_pos = ftell(f); + gint64 internal_pos = ftello(f); _mmcam_dbg_log("found moov container"); if (fseek(f, -8L, SEEK_CUR) !=0) { goto fail; } - moov_pos = ftell(f); + moov_pos = ftello(f); if (moov_pos < 0) { goto ftell_fail; } @@ -1906,7 +1950,7 @@ static gboolean __mmcamcorder_add_metadata_mp4(MMHandleType handle) } /* add orientation info */ - if (fseek(f, internal_pos, SEEK_SET) < 0) { + if (fseeko(f, internal_pos, SEEK_SET) < 0) { _mmcam_dbg_err("fseek failed : errno %d", errno); goto fail; } @@ -2015,7 +2059,7 @@ int _mmcamcorder_video_prepare_record(MMHandleType handle) _mmcam_dbg_log("Record file name [%s]", info->filename); - MMCAMCORDER_G_OBJECT_SET(sc->encode_element[_MMCAMCORDER_ENCSINK_SINK].gst, "location", info->filename); + MMCAMCORDER_G_OBJECT_SET_POINTER(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 */