| 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);
/*---------------------------------------------------------------------------------------
| 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",
buffer = NULL;
}
- return;
+ return TRUE;
}
{
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;
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);
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);
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 */
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);
}
/* 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);
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);
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;
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);
}
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);
}
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;
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;
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 */
_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);
info->b_commiting = FALSE;
goto _ERR_CAMCORDER_VIDEO_COMMAND;
}
+
+ /* reset flag */
+ hcamcorder->capture_in_recording = FALSE;
}
break;
default:
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);
+ _mmcamcorder_sound_solo_play(handle, _MMCAMCORDER_SAMPLE_SOUND_NAME_REC_STOP, 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);
/* 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);
+ report->recording_filename = g_strdup(info->filename);
msg.param.data= report;
msg.param.code = 1;
_mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
/*_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;
}
_mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
}
- pthread_mutex_unlock(&(videoinfo->size_check_lock));
+ g_mutex_unlock(&videoinfo->size_check_lock);
return FALSE;
}
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;
}
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;
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));
+ 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;
}
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");*/
break;
}
- pthread_mutex_lock(&(videoinfo->size_check_lock));
+ g_mutex_lock(&videoinfo->size_check_lock);
/* check max size of recorded file */
if (videoinfo->max_size > 0 &&
_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;
}
_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;
}
MMCAM_TARGET_FILENAME, &temp_filename, &size,
NULL);
if (temp_filename) {
- info->filename = strdup(temp_filename);
+ info->filename = g_strdup(temp_filename);
}
if (!info->filename) {
_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 */