Fix Svace issues 16/126016/2 accepted/tizen/unified/20170420.155405 submit/tizen/20170420.061013 tizen_4.0.m1_release
authorJeongmo Yang <jm80.yang@samsung.com>
Thu, 20 Apr 2017 01:22:32 +0000 (10:22 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Thu, 20 Apr 2017 05:00:50 +0000 (14:00 +0900)
[Version] 0.0.1-2
[Profile] Common
[Issue Type] Bug fix

Change-Id: Iba31ce0ce32aa5eac95beaa29b4986fe1189fb37
Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
camerasrc/src/gstcamerasrc.c
camerasrc/src/gstcamerasrccontrol.c
packaging/gst-plugins-camera-n4.spec

index ede5df6f76bae0a4a518c8297128c8be4d0a2485..745b4de386bcb828b87d1ef52872371e574d863c 100644 (file)
@@ -1087,6 +1087,10 @@ static GstFlowReturn gst_camerasrc_read_preview(GstCameraSrc *camerasrc, GstBuff
 
        /* 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)) {
@@ -1110,69 +1114,14 @@ static GstFlowReturn gst_camerasrc_read_preview(GstCameraSrc *camerasrc, GstBuff
                }
        }
 
-       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;
        }
 
@@ -1277,8 +1226,8 @@ static GstFlowReturn gst_camerasrc_read_preview(GstCameraSrc *camerasrc, GstBuff
 
 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;
        }
 
@@ -1439,7 +1388,7 @@ CHECK_CAPTURE_INTERVAL:
                                                                  "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;
@@ -1459,7 +1408,7 @@ CHECK_CAPTURE_INTERVAL:
                                                                          "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;
@@ -1485,7 +1434,7 @@ CHECK_CAPTURE_INTERVAL:
                                                                          "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;
@@ -1559,6 +1508,8 @@ CHECK_CAPTURE_INTERVAL:
                                                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);
@@ -1650,6 +1601,7 @@ CHECK_CAPTURE_INTERVAL:
                                        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;
                                }
@@ -1669,8 +1621,17 @@ CHECK_CAPTURE_INTERVAL:
                } 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;
                        }
 
@@ -1714,6 +1675,11 @@ static GstFlowReturn gst_camerasrc_read(GstCameraSrc *camerasrc, GstBuffer **buf
        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)) {
@@ -1746,7 +1712,7 @@ static GstFlowReturn gst_camerasrc_read(GstCameraSrc *camerasrc, GstBuffer **buf
                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();
@@ -1875,8 +1841,23 @@ static GstCameraBuffer *gst_camerasrc_buffer_new(GstCameraSrc *camerasrc)
 {
        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);
 
@@ -3420,7 +3401,7 @@ static void gst_camerasrc_init(GstCameraSrc *camerasrc)
        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;
index deac43ad41ea0f103730f85ea7614f68a7d95878..2571a1ded701e23a4ad08a36c875f95c27d6b068 100644 (file)
@@ -230,7 +230,7 @@ gboolean gst_camerasrc_control_set_capture_mode(GstCameraSrc *camerasrc, gint ty
 
        gst_camerasrc_debug("set capture mode");
 
-       int error = CAMERASRC_ERROR;
+       int error = CAMERASRC_SUCCESS;
 
        g_return_val_if_fail(camerasrc, FALSE);
 
@@ -245,7 +245,8 @@ gboolean gst_camerasrc_control_set_capture_mode(GstCameraSrc *camerasrc, gint ty
                break;
        default:
                gst_camerasrc_debug("Not supported type.");
-               return FALSE;
+               error = CAMERASRC_ERROR;
+               break;
        }
 
        if (error != CAMERASRC_SUCCESS) {
@@ -262,7 +263,7 @@ gboolean gst_camerasrc_control_get_capture_mode(GstCameraSrc *camerasrc, gint ty
 
        gst_camerasrc_debug("get capture mode");
 
-       int error = CAMERASRC_ERROR;
+       int error = CAMERASRC_SUCCESS;
 
        g_return_val_if_fail(camerasrc, FALSE);
 
@@ -277,7 +278,8 @@ gboolean gst_camerasrc_control_get_capture_mode(GstCameraSrc *camerasrc, gint ty
                break;
        default:
                gst_camerasrc_debug("Not supported type.");
-               return FALSE;
+               error = CAMERASRC_ERROR;
+               break;
        }
 
        if (error != CAMERASRC_SUCCESS) {
@@ -354,7 +356,7 @@ gboolean gst_camerasrc_control_set_detect(GstCameraSrc *camerasrc, gint type, gi
 {
        gst_camerasrc_debug("set detect");
        
-       int error = CAMERASRC_ERROR;
+       int error = CAMERASRC_SUCCESS;
 
        g_return_val_if_fail(camerasrc, FALSE);
 
@@ -372,7 +374,8 @@ gboolean gst_camerasrc_control_set_detect(GstCameraSrc *camerasrc, gint type, gi
                break;
        default:
                gst_camerasrc_debug("Not supported type.");
-               return FALSE;
+               error = CAMERASRC_ERROR;
+               break;
        }
 
        if (error != CAMERASRC_SUCCESS) {
@@ -387,7 +390,7 @@ gboolean gst_camerasrc_control_get_detect(GstCameraSrc *camerasrc, gint type, gi
 {
        gst_camerasrc_debug("get detect");
 
-       int error = CAMERASRC_ERROR;
+       int error = CAMERASRC_SUCCESS;
 
        g_return_val_if_fail(camerasrc, FALSE);
        
@@ -405,7 +408,8 @@ gboolean gst_camerasrc_control_get_detect(GstCameraSrc *camerasrc, gint type, gi
                break;
        default:
                gst_camerasrc_debug("Not supported type.");
-               return FALSE;
+               error = CAMERASRC_ERROR;
+               break;
        }
 
        if (error != CAMERASRC_SUCCESS) {
index 8b826bb06a4482b606820a05737d0775a671b8c3..dc575bce3e68febbecea64625f77415c5e3442b3 100644 (file)
@@ -1,7 +1,7 @@
 Name:       gst-plugins-camera-n4
 Summary:    GStreamer codec plugins package for N4
 Version:    0.0.1
-Release:    1
+Release:    2
 Group:      Multimedia/Framework
 License:    LGPL-2.1+ and Apache-2.0
 Source0:    %{name}-%{version}.tar.gz