/* alloc main buffer */
vid_buf = gst_camerasrc_buffer_new(camerasrc);
+ if (!vid_buf) {
+ GST_ERROR("failed to alloc camerasrc buffer");
+ return GST_FLOW_ERROR;
+ }
/* check restart preview command */
if (!g_queue_is_empty(camerasrc->restart_cmd_list)) {
}
}
- GST_LOG_OBJECT(camerasrc, "start SELECT call");
-
- for (i = 0 ; i < _MAX_TRIAL_WAIT_FRAME ; i++) {
- /* Wait frame */
- //ret = camerasrc_wait_frame_available(camerasrc->v4l2_handle, _DEFAULT_DEQUE_WAITINGTIME);
- ret = CAMERASRC_SUCCESS;
- if (ret != CAMERASRC_SUCCESS) {
- if (ret == CAMERASRC_ERR_DEVICE_WAIT_TIMEOUT && i < (_MAX_TRIAL_WAIT_FRAME - 1)) {
- /* wait until any live buffer is finalized if all buffers are LIVE */
- g_mutex_lock(&camerasrc->buffer_lock);
-
- GST_WARNING_OBJECT(camerasrc, "SELECT TIMEOUT!!! Retry..(live %d)", camerasrc->num_live_buffers);
-
- if (camerasrc->buffer_count <= camerasrc->num_live_buffers) {
- gint64 end_time;
-
- GST_INFO("All buffers are LIVE. wait buffer finalize...");
-
- end_time = g_get_monotonic_time () + _PREVIEW_BUFFER_WAIT_TIMEOUT;
-
- if (!g_cond_wait_until(&camerasrc->buffer_cond, &camerasrc->buffer_lock, end_time)) {
- GST_ERROR_OBJECT(camerasrc, "Buffer wait timeout[%d usec]. Return ERROR", _PREVIEW_BUFFER_WAIT_TIMEOUT);
- return GST_FLOW_ERROR;
- } else {
- GST_INFO("Signal received. Retry...");
- }
- }
-
- GST_INFO_OBJECT(camerasrc, "buffer wait done. current live %d", camerasrc->num_live_buffers);
-
- g_mutex_unlock(&camerasrc->buffer_lock);
-
- /* retry waiting */
- continue;
- }
-
- if (ret == CAMERASRC_ERR_DEVICE_UNAVAILABLE) {
- GST_ERROR_OBJECT(camerasrc, "register trouble error!! [%x]", ret);
- /*g_signal_emit (G_OBJECT (camerasrc), gst_camerasrc_signals[SIGNAL_REGISTER_TROUBLE], (GQuark)NULL);*/
- gst_camerasrc_error_handler(camerasrc, ret);
-
- return GST_FLOW_ERROR;
- } else if (ret == CAMERASRC_ERR_INVALID_STATE && (i < _MAX_TRIAL_WAIT_FRAME - 1)) {
- GST_WARNING_OBJECT(camerasrc, "try again...");
- } else {
- GST_ERROR_OBJECT(camerasrc, "Frame waiting error[%x]", ret);
- gst_camerasrc_error_handler(camerasrc, ret);
-
- return GST_FLOW_ERROR;
- }
- } else {
- GST_LOG_OBJECT(camerasrc, "select success, do DQBUF");
- break;
- }
- }
-
/* Buffer DQ */
GST_DEBUG_OBJECT(camerasrc, "camerasrc_dequeue_buffer");
ret = camerasrc_dequeue_buffer(camerasrc->v4l2_handle, &v4l2_buffer_index, &main_buf, NULL);
if (ret != CAMERASRC_SUCCESS) {
GST_ERROR_OBJECT(camerasrc, "Dequeue frame error[%x]", ret);
gst_camerasrc_error_handler(camerasrc, ret);
-
+ gst_buffer_unref(vid_buf->buffer);
+ free(vid_buf);
return GST_FLOW_ERROR;
}
PREVIEW_ERROR:
if (vid_buf) {
+ gst_buffer_unref(vid_buf->buffer);
gst_camerasrc_buffer_finalize(vid_buf);
- gst_buffer_unref((GstBuffer *)vid_buf);
vid_buf = NULL;
}
"height", G_TYPE_INT, camerasrc->cap_height,
NULL);
- buf_sample1 = gst_sample_new(buf->buffer, sample_caps, NULL, NULL);
+ buf_sample1 = gst_sample_new(gst_buffer, sample_caps, NULL, NULL);
gst_buffer_unref(gst_buffer);
gst_buffer = NULL;
"height", G_TYPE_INT, _THUMBNAIL_HEIGHT,
NULL);
- buf_sample2 = gst_sample_new(buf->buffer, sample_caps, NULL, NULL);
+ buf_sample2 = gst_sample_new(gst_buffer, sample_caps, NULL, NULL);
gst_buffer_unref(gst_buffer);
gst_buffer = NULL;
"height", G_TYPE_INT, camerasrc->height,
NULL);
- buf_sample3 = gst_sample_new(buf->buffer, sample_caps, NULL, NULL);
+ buf_sample3 = gst_sample_new(gst_buffer, sample_caps, NULL, NULL);
gst_buffer_unref(gst_buffer);
gst_buffer = NULL;
ret = _gst_camerasrc_get_normal_buffer(camerasrc, &main_buf, camerasrc->cap_width, camerasrc->cap_height,
&buf_memory, camerasrc->cap_fourcc);
if (ret == FALSE) {
+ gst_buffer_unref(buf->buffer);
+ free(buf);
return GST_FLOW_ERROR;
}
gst_buffer_append_memory(buf->buffer, buf_memory);
GST_INFO (" refcount = %d",GST_MINI_OBJECT_REFCOUNT_VALUE(GST_MINI_OBJECT_CAST (buf)));
gst_buffer_unref(buf->buffer);
GST_INFO (" refcount = %d",GST_MINI_OBJECT_REFCOUNT_VALUE(GST_MINI_OBJECT_CAST (buf)));
+ free(buf);
buf = NULL;
*buffer = NULL;
}
} else {
/* check again */
if (camerasrc->cap_next_time < cur_time + _CONTINUOUS_SHOT_MARGIN) {
+ unsigned long diff_time = 0;
+
GST_DEBUG_OBJECT(camerasrc, "check again time");
- usleep((camerasrc->cap_next_time - cur_time) * 1000);
+
+ diff_time = camerasrc->cap_next_time - cur_time;
+
+ if (diff_time >= 10)
+ usleep(diff_time * 1000);
+ else
+ usleep(10000);
+
goto CHECK_CAPTURE_INTERVAL;
}
int command = GST_CAMERA_CONTROL_CAPTURE_COMMAND_NONE;
GstFlowReturn ret = GST_FLOW_OK;
+ if (!buffer) {
+ GST_ERROR_OBJECT(camerasrc, "NULL buffer");
+ return GST_FLOW_ERROR;
+ }
+
g_mutex_lock(&camerasrc->mutex);
if (!g_queue_is_empty(camerasrc->capture_cmd_list)) {
break;
}
- if (!buffer || !(*buffer) || !GST_IS_BUFFER(*buffer)) {
+ if (!(*buffer) || !GST_IS_BUFFER(*buffer)) {
/* To avoid seg fault, make dummy buffer. */
GST_WARNING_OBJECT (camerasrc, "Make a dummy buffer");
*buffer = gst_buffer_new();
{
GstCameraBuffer *ret = NULL;
+ if (!camerasrc) {
+ GST_ERROR("NULL camerasrc");
+ return NULL;
+ }
+
ret = (GstCameraBuffer *)malloc(sizeof(*ret));
+ if (!ret) {
+ GST_ERROR("alloc failed for GstCameraBuffer");
+ return NULL;
+ }
+
ret->buffer = gst_buffer_new();
+ if (!ret->buffer) {
+ GST_ERROR("gst_buffer new failed");
+ free(ret);
+ return NULL;
+ }
GST_LOG_OBJECT(camerasrc, "creating buffer : %p", ret);
camerasrc->fps_auto = _DEFAULT_FPS_AUTO;
camerasrc->pix_format = _DEFAULT_PIX_FORMAT;
camerasrc->colorspace = _DEFAULT_COLORSPACE;
- strcpy(camerasrc->format_name, _DEFAULT_PIX_FORMAT_NAME);
+ strncpy(camerasrc->format_name, _DEFAULT_PIX_FORMAT_NAME, FORMAT_NAME_LENGTH - 1);
camerasrc->num_live_buffers = 0;
camerasrc->buffer_count = _DEFAULT_BUFFER_COUNT;
camerasrc->buffer_running = FALSE;
gst_camerasrc_debug("set capture mode");
- int error = CAMERASRC_ERROR;
+ int error = CAMERASRC_SUCCESS;
g_return_val_if_fail(camerasrc, FALSE);
break;
default:
gst_camerasrc_debug("Not supported type.");
- return FALSE;
+ error = CAMERASRC_ERROR;
+ break;
}
if (error != CAMERASRC_SUCCESS) {
gst_camerasrc_debug("get capture mode");
- int error = CAMERASRC_ERROR;
+ int error = CAMERASRC_SUCCESS;
g_return_val_if_fail(camerasrc, FALSE);
break;
default:
gst_camerasrc_debug("Not supported type.");
- return FALSE;
+ error = CAMERASRC_ERROR;
+ break;
}
if (error != CAMERASRC_SUCCESS) {
{
gst_camerasrc_debug("set detect");
- int error = CAMERASRC_ERROR;
+ int error = CAMERASRC_SUCCESS;
g_return_val_if_fail(camerasrc, FALSE);
break;
default:
gst_camerasrc_debug("Not supported type.");
- return FALSE;
+ error = CAMERASRC_ERROR;
+ break;
}
if (error != CAMERASRC_SUCCESS) {
{
gst_camerasrc_debug("get detect");
- int error = CAMERASRC_ERROR;
+ int error = CAMERASRC_SUCCESS;
g_return_val_if_fail(camerasrc, FALSE);
break;
default:
gst_camerasrc_debug("Not supported type.");
- return FALSE;
+ error = CAMERASRC_ERROR;
+ break;
}
if (error != CAMERASRC_SUCCESS) {