disable picture if we want to
authorPaul Kocialkowski <contact@paulk.fr>
Fri, 1 Feb 2013 17:32:22 +0000 (18:32 +0100)
committerPaul Kocialkowski <contact@paulk.fr>
Fri, 1 Feb 2013 17:32:22 +0000 (18:32 +0100)
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
exynos_camera.c
exynos_camera.h

index 3842d97..39282c5 100644 (file)
@@ -510,141 +510,6 @@ int SecCamera::setObjectPosition(int x, int y)
        return 0;
 }
 
-// Auto-focus
-
-void *exynos_camera_auto_focus_thread(void *data)
-{
-       struct exynos_camera *exynos_camera;
-       int auto_focus_status = -1;
-       int auto_focus_result = 0;
-       int rc;
-       int i;
-
-       if (data == NULL)
-               return NULL;
-
-       exynos_camera = (struct exynos_camera *) data;
-
-       LOGE("%s: Starting thread", __func__);
-       exynos_camera->auto_focus_thread_running = 1;
-
-       rc = exynos_v4l2_s_ctrl(exynos_camera, 0, V4L2_CID_CAMERA_SET_AUTO_FOCUS, AUTO_FOCUS_ON);
-       if (rc < 0) {
-               LOGE("%s: s ctrl failed!", __func__);
-               auto_focus_result = 0;
-               goto thread_exit;
-       }
-
-       while (exynos_camera->auto_focus_enabled == 1) {
-               pthread_mutex_lock(&exynos_camera->auto_focus_mutex);
-
-               rc = exynos_v4l2_g_ctrl(exynos_camera, 0, V4L2_CID_CAMERA_AUTO_FOCUS_RESULT, &auto_focus_status);
-               if (rc < 0) {
-                       LOGE("%s: g ctrl failed!", __func__);
-                       auto_focus_result = 0;
-                       pthread_mutex_unlock(&exynos_camera->auto_focus_mutex);
-                       goto thread_exit;
-               }
-
-               switch (auto_focus_status) {
-                       case CAMERA_AF_STATUS_IN_PROGRESS:
-                               usleep(500);
-                               break;
-                       case CAMERA_AF_STATUS_SUCCESS:
-                       case CAMERA_AF_STATUS_1ST_SUCCESS:
-                               auto_focus_result = 1;
-                               pthread_mutex_unlock(&exynos_camera->auto_focus_mutex);
-                               goto thread_exit;
-                       case CAMERA_AF_STATUS_FAIL:
-                       default:
-                               auto_focus_result = 0;
-                               pthread_mutex_unlock(&exynos_camera->auto_focus_mutex);
-                               goto thread_exit;                               
-               }
-
-               pthread_mutex_unlock(&exynos_camera->auto_focus_mutex);
-       }
-
-thread_exit:
-       rc = exynos_v4l2_s_ctrl(exynos_camera, 0, V4L2_CID_CAMERA_SET_AUTO_FOCUS, AUTO_FOCUS_OFF);
-       if (rc < 0)
-               LOGE("%s: s ctrl failed!", __func__);
-
-       if (EXYNOS_CAMERA_MSG_ENABLED(CAMERA_MSG_FOCUS) && EXYNOS_CAMERA_CALLBACK_DEFINED(notify))
-               exynos_camera->callbacks.notify(CAMERA_MSG_FOCUS,
-                       (int32_t) auto_focus_result, 0, exynos_camera->callbacks.user);
-               
-       exynos_camera->auto_focus_thread_running = 0;
-       exynos_camera->auto_focus_enabled = 0;
-
-       LOGE("%s: Exiting thread", __func__);
-
-       return NULL;
-}
-
-int exynos_camera_auto_focus_start(struct exynos_camera *exynos_camera)
-{
-       pthread_attr_t thread_attr;
-       int rc;
-
-       if (exynos_camera == NULL)
-               return -EINVAL;
-
-       // Thread
-
-       if (exynos_camera->auto_focus_thread_running) {
-               LOGE("Auto-focus thread is already running!");
-               return -1;
-       }
-
-       pthread_mutex_init(&exynos_camera->auto_focus_mutex, NULL);
-
-       pthread_attr_init(&thread_attr);
-       pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
-
-       exynos_camera->auto_focus_enabled = 1;
-
-       rc = pthread_create(&exynos_camera->auto_focus_thread, &thread_attr,
-               exynos_camera_auto_focus_thread, (void *) exynos_camera);
-       if (rc < 0) {
-               LOGE("%s: Unable to create thread", __func__);
-               return -1;
-       }
-
-       return 0;
-}
-
-void exynos_camera_auto_focus_stop(struct exynos_camera *exynos_camera)
-{
-       int rc;
-       int i;
-
-       if (exynos_camera == NULL)
-               return;
-
-       if (!exynos_camera->auto_focus_enabled) {
-               LOGE("Auto-focus was already stopped!");
-               return;
-       }
-
-       pthread_mutex_lock(&exynos_camera->auto_focus_mutex);
-
-       // Disable auto-focus to make the thread end
-       exynos_camera->auto_focus_enabled = 0;
-
-       pthread_mutex_unlock(&exynos_camera->auto_focus_mutex);
-
-       // Wait for the thread to end
-       for (i=0 ; i < 10 ; i++) {
-               if (!exynos_camera->auto_focus_thread_running)
-                       break;
-
-               usleep(500);
-       }
-
-       pthread_mutex_destroy(&exynos_camera->auto_focus_mutex);
-}
-
 // Picture
 
 int exynos_camera_picture(struct exynos_camera *exynos_camera)
@@ -1240,6 +1105,172 @@ int exynos_camera_picture_start(struct exynos_camera *exynos_camera)
        return 0;
 }
 
+void exynos_camera_picture_stop(struct exynos_camera *exynos_camera)
+{
+       int rc;
+       int i;
+
+       if (exynos_camera == NULL)
+               return;
+
+       if (!exynos_camera->picture_enabled) {
+               LOGE("Picture was already stopped!");
+               return;
+       }
+
+       pthread_mutex_lock(&exynos_camera->picture_mutex);
+
+       // Disable picture to make the thread end
+       exynos_camera->picture_enabled = 0;
+
+       pthread_mutex_unlock(&exynos_camera->picture_mutex);
+
+       // Wait for the thread to end
+       for (i=0 ; i < 10 ; i++) {
+               if (!exynos_camera->picture_thread_running)
+                       break;
+
+               usleep(500);
+       }
+
+       pthread_mutex_destroy(&exynos_camera->picture_mutex);
+}
+
+// Auto-focus
+
+void *exynos_camera_auto_focus_thread(void *data)
+{
+       struct exynos_camera *exynos_camera;
+       int auto_focus_status = -1;
+       int auto_focus_result = 0;
+       int rc;
+       int i;
+
+       if (data == NULL)
+               return NULL;
+
+       exynos_camera = (struct exynos_camera *) data;
+
+       LOGE("%s: Starting thread", __func__);
+       exynos_camera->auto_focus_thread_running = 1;
+
+       rc = exynos_v4l2_s_ctrl(exynos_camera, 0, V4L2_CID_CAMERA_SET_AUTO_FOCUS, AUTO_FOCUS_ON);
+       if (rc < 0) {
+               LOGE("%s: s ctrl failed!", __func__);
+               auto_focus_result = 0;
+               goto thread_exit;
+       }
+
+       while (exynos_camera->auto_focus_enabled == 1) {
+               pthread_mutex_lock(&exynos_camera->auto_focus_mutex);
+
+               rc = exynos_v4l2_g_ctrl(exynos_camera, 0, V4L2_CID_CAMERA_AUTO_FOCUS_RESULT, &auto_focus_status);
+               if (rc < 0) {
+                       LOGE("%s: g ctrl failed!", __func__);
+                       auto_focus_result = 0;
+                       pthread_mutex_unlock(&exynos_camera->auto_focus_mutex);
+                       goto thread_exit;
+               }
+
+               switch (auto_focus_status) {
+                       case CAMERA_AF_STATUS_IN_PROGRESS:
+                               usleep(500);
+                               break;
+                       case CAMERA_AF_STATUS_SUCCESS:
+                       case CAMERA_AF_STATUS_1ST_SUCCESS:
+                               auto_focus_result = 1;
+                               pthread_mutex_unlock(&exynos_camera->auto_focus_mutex);
+                               goto thread_exit;
+                       case CAMERA_AF_STATUS_FAIL:
+                       default:
+                               auto_focus_result = 0;
+                               pthread_mutex_unlock(&exynos_camera->auto_focus_mutex);
+                               goto thread_exit;                               
+               }
+
+               pthread_mutex_unlock(&exynos_camera->auto_focus_mutex);
+       }
+
+thread_exit:
+       rc = exynos_v4l2_s_ctrl(exynos_camera, 0, V4L2_CID_CAMERA_SET_AUTO_FOCUS, AUTO_FOCUS_OFF);
+       if (rc < 0)
+               LOGE("%s: s ctrl failed!", __func__);
+
+       if (EXYNOS_CAMERA_MSG_ENABLED(CAMERA_MSG_FOCUS) && EXYNOS_CAMERA_CALLBACK_DEFINED(notify))
+               exynos_camera->callbacks.notify(CAMERA_MSG_FOCUS,
+                       (int32_t) auto_focus_result, 0, exynos_camera->callbacks.user);
+               
+       exynos_camera->auto_focus_thread_running = 0;
+       exynos_camera->auto_focus_enabled = 0;
+
+       LOGE("%s: Exiting thread", __func__);
+
+       return NULL;
+}
+
+int exynos_camera_auto_focus_start(struct exynos_camera *exynos_camera)
+{
+       pthread_attr_t thread_attr;
+       int rc;
+
+       if (exynos_camera == NULL)
+               return -EINVAL;
+
+       // Thread
+
+       if (exynos_camera->auto_focus_thread_running) {
+               LOGE("Auto-focus thread is already running!");
+               return -1;
+       }
+
+       pthread_mutex_init(&exynos_camera->auto_focus_mutex, NULL);
+
+       pthread_attr_init(&thread_attr);
+       pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
+
+       exynos_camera->auto_focus_enabled = 1;
+
+       rc = pthread_create(&exynos_camera->auto_focus_thread, &thread_attr,
+               exynos_camera_auto_focus_thread, (void *) exynos_camera);
+       if (rc < 0) {
+               LOGE("%s: Unable to create thread", __func__);
+               return -1;
+       }
+
+       return 0;
+}
+
+void exynos_camera_auto_focus_stop(struct exynos_camera *exynos_camera)
+{
+       int rc;
+       int i;
+
+       if (exynos_camera == NULL)
+               return;
+
+       if (!exynos_camera->auto_focus_enabled) {
+               LOGE("Auto-focus was already stopped!");
+               return;
+       }
+
+       pthread_mutex_lock(&exynos_camera->auto_focus_mutex);
+
+       // Disable auto-focus to make the thread end
+       exynos_camera->auto_focus_enabled = 0;
+
+       pthread_mutex_unlock(&exynos_camera->auto_focus_mutex);
+
+       // Wait for the thread to end
+       for (i=0 ; i < 10 ; i++) {
+               if (!exynos_camera->auto_focus_thread_running)
+                       break;
+
+               usleep(500);
+       }
+
+       pthread_mutex_destroy(&exynos_camera->auto_focus_mutex);
+}
+
 // Preview
 
 int exynos_camera_preview(struct exynos_camera *exynos_camera)
@@ -1837,9 +1868,16 @@ int exynos_camera_take_picture(struct camera_device *dev)
 
 int exynos_camera_cancel_picture(struct camera_device *dev)
 {
+       struct exynos_camera *exynos_camera;
+
        LOGD("%s(%p)", __func__, dev);
 
-       // TODO FIXME
+       if (dev == NULL || dev->priv == NULL)
+               return -EINVAL;
+
+       exynos_camera = (struct exynos_camera *) dev->priv;
+
+       exynos_camera_picture_stop(exynos_camera);
 
        return 0;
 }
index 8022cb6..07b4278 100644 (file)
@@ -143,6 +143,22 @@ struct exynos_camera {
 
        gralloc_module_t *gralloc;
 
+       // Picture
+       pthread_t picture_thread;
+       pthread_mutex_t picture_mutex;
+       int picture_thread_running;
+
+       int picture_enabled;
+       camera_memory_t *picture_memory;
+       int picture_buffer_length;
+
+       // Auto-focus
+       pthread_t auto_focus_thread;
+       pthread_mutex_t auto_focus_mutex;
+       int auto_focus_thread_running;
+
+       int auto_focus_enabled;
+
        // Preview
        pthread_t preview_thread;
        pthread_mutex_t preview_mutex;
@@ -154,21 +170,6 @@ struct exynos_camera {
        camera_memory_t *preview_memory;
        int preview_buffers_count;
 
-       // Auto-focus
-       pthread_t auto_focus_thread;
-       pthread_mutex_t auto_focus_mutex;
-       int auto_focus_thread_running;
-
-       int auto_focus_enabled;
-
-       // Picture
-       pthread_t picture_thread;
-       pthread_mutex_t picture_mutex;
-       int picture_thread_running;
-
-       int picture_enabled;
-       camera_memory_t *picture_memory;
-       int picture_buffer_length;
 
        // Camera params
        int camera_rotation;
@@ -215,6 +216,16 @@ struct exynos_v4l2_ext_control {
 int exynos_camera_params_init(struct exynos_camera *exynos_camera, int id);
 int exynos_camera_params_apply(struct exynos_camera *exynos_camera);
 
+int exynos_camera_auto_focus_start(struct exynos_camera *exynos_camera);
+void exynos_camera_auto_focus_stop(struct exynos_camera *exynos_camera);
+
+int exynos_camera_picture(struct exynos_camera *exynos_camera);
+int exynos_camera_picture_start(struct exynos_camera *exynos_camera);
+
+int exynos_camera_preview(struct exynos_camera *exynos_camera);
+int exynos_camera_preview_start(struct exynos_camera *exynos_camera);
+void exynos_camera_preview_stop(struct exynos_camera *exynos_camera);
+
 /*
  * EXIF
  */