[Release version 0.2.65] Add new APIs - camera_change_device, camera_set/get_display_... 88/80788/4
authorJeongmo Yang <jm80.yang@samsung.com>
Wed, 20 Jul 2016 07:50:16 +0000 (16:50 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Thu, 21 Jul 2016 23:32:01 +0000 (08:32 +0900)
Change-Id: I8dd625d7a4159cd96f9a8037e3ecbefbfaaff21b
Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
include/camera.h
packaging/capi-media-camera.spec
src/camera.c
test/camera_test.c

index ab40935..d86074f 100644 (file)
@@ -739,11 +739,37 @@ typedef bool (*camera_supported_preview_format_cb)(camera_pixel_format_e format,
  * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported
  * @post If it succeeds, the camera state will be #CAMERA_STATE_CREATED.
  *
- * @see        camera_destroy()
+ * @see camera_destroy()
  */
 int camera_create(camera_device_e device, camera_h *camera);
 
 /**
+ * @brief Changes the camera device.
+ *
+ * @since_tizen 3.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/camera
+ * @remarks This function can be used to change camera device simply without camera_destroy() and camera_create().\n
+ *          If display reuse hint is set by camera_set_display_reuse_hint() before stopping the preview,\n
+ *          display handle will be reused and last frame on display can be kept even though camera device is changed.
+ * @param[in] camera The handle to the camera
+ * @param[in] device The hardware camera to access
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #CAMERA_ERROR_NONE Successful
+ * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #CAMERA_ERROR_INVALID_STATE Invalid state
+ * @retval #CAMERA_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #CAMERA_ERROR_INVALID_OPERATION Invalid operation
+ * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported
+ * @pre    The camera state must be set to #CAMERA_STATE_CREATED.
+ * @post   If it succeeds, the camera attributes and settings will be reset.
+ *
+ * @see camera_set_display_reuse_hint()
+ * @see camera_get_display_reuse_hint()
+ */
+int camera_change_device(camera_h camera, camera_device_e device);
+
+/**
  * @brief Destroys the camera handle and releases all its resources.
  *
  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
@@ -1310,6 +1336,39 @@ int camera_set_display_mode(camera_h camera , camera_display_mode_e mode);
 int camera_get_display_mode(camera_h camera, camera_display_mode_e *mode);
 
 /**
+ * @brief Sets the hint for display reuse.
+ * @since_tizen 3.0
+ * @details If the hint is set to true, the display will be reused when the camera device is changed with camera_change_device().
+ * @remarks If the current display type is #CAMERA_DISPLAY_TYPE_NONE, this function will return #CAMERA_ERROR_INVALID_OPERATION.
+ * @param[in] camera The handle to the camera
+ * @param[in] hint The hint for display reuse; true - reuse the display, false - do not reuse
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #CAMERA_ERROR_NONE Successful
+ * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #CAMERA_ERROR_INVALID_STATE Invalid state
+ * @retval #CAMERA_ERROR_INVALID_OPERATION Internal error
+ * @pre    The camera state must be set to #CAMERA_STATE_PREVIEW.
+ * @see camera_get_display_reuse_hint()
+ * @see camera_change_device()
+ */
+int camera_set_display_reuse_hint(camera_h camera, bool hint);
+
+/**
+ * @brief Gets the hint for display reuse.
+ * @since_tizen 3.0
+ * @remarks If the current display type is #CAMERA_DISPLAY_TYPE_NONE, this function will return #CAMERA_ERROR_INVALID_OPERATION.
+ * @param[in] camera The handle to the camera
+ * @param[out] hint The hint for display reuse; true - reuse the display, false - do not reuse
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #CAMERA_ERROR_NONE Successful
+ * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #CAMERA_ERROR_INVALID_OPERATION Internal error
+ * @see camera_get_display_reuse_hint()
+ * @see camera_change_device()
+ */
+int camera_get_display_reuse_hint(camera_h camera, bool *hint);
+
+/**
  * @brief Sets the resolution of the captured image.
  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @privlevel public
index 7a7b450..38a3cac 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-camera
 Summary:    A Camera API
-Version:    0.2.64
+Version:    0.2.65
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 765bb93..16620f2 100644 (file)
@@ -2207,6 +2207,24 @@ ErrorExit:
        return ret;
 }
 
+
+int camera_change_device(camera_h camera, camera_device_e device)
+{
+       int ret = CAMERA_ERROR_NONE;
+       muse_camera_api_e api = MUSE_CAMERA_API_CHANGE_DEVICE;
+       camera_cli_s *pc = (camera_cli_s *)camera;
+
+       if (camera == NULL || pc->cb_info == NULL) {
+               LOGE("NULL handle, INVALID_PARAMETER");
+               return CAMERA_ERROR_INVALID_PARAMETER;
+       }
+
+       muse_camera_msg_send1(api, pc->cb_info->fd, pc->cb_info, ret, INT, device);
+
+       return ret;
+}
+
+
 int camera_destroy(camera_h camera)
 {
        if (camera == NULL) {
@@ -3245,6 +3263,64 @@ int camera_get_display_mode(camera_h camera, camera_display_mode_e *mode)
        return ret;
 }
 
+
+int camera_set_display_reuse_hint(camera_h camera, bool hint)
+{
+       int ret = CAMERA_ERROR_NONE;
+       int set_hint = (int)hint;
+       camera_cli_s *pc = (camera_cli_s *)camera;
+
+       if (camera == NULL) {
+               LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
+               return CAMERA_ERROR_INVALID_PARAMETER;
+       }
+
+       if (pc->cb_info == NULL) {
+               LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
+               return CAMERA_ERROR_INVALID_PARAMETER;
+       }
+
+       LOGD("set display reuse hint %d", set_hint);
+
+       muse_camera_msg_send1(MUSE_CAMERA_API_SET_DISPLAY_REUSE_HINT,
+               pc->cb_info->fd, pc->cb_info, ret, INT, set_hint);
+
+       return ret;
+}
+
+
+int camera_get_display_reuse_hint(camera_h camera, bool *hint)
+{
+       int ret = CAMERA_ERROR_NONE;
+       int get_hint = 0;
+       camera_cli_s *pc = (camera_cli_s *)camera;
+       muse_camera_api_e api = MUSE_CAMERA_API_GET_DISPLAY_REUSE_HINT;
+
+       if (camera == NULL || hint == NULL) {
+               LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
+               return CAMERA_ERROR_INVALID_PARAMETER;
+       }
+
+       if (pc->cb_info == NULL) {
+               LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
+               return CAMERA_ERROR_INVALID_PARAMETER;
+       }
+
+       muse_camera_msg_send(api, pc->cb_info->fd, pc->cb_info, ret);
+
+       if (ret == CAMERA_ERROR_NONE) {
+               muse_camera_msg_get(get_hint, pc->cb_info->recv_msg);
+               *hint = (bool)get_hint;
+
+               LOGD("display reuse hint %d", *hint);
+       } else {
+               LOGE("failed 0x%x", ret);
+       }
+
+       return ret;
+}
+
+
 int camera_get_capture_resolution(camera_h camera, int *width, int *height)
 {
        if (camera == NULL || width == NULL || height == NULL) {
index 9970843..cd2e446 100644 (file)
@@ -116,7 +116,7 @@ GTimeVal res;
 #define EXT_AMR                         "amr"
 #define EXT_MKV                         "mkv"
 
-#define TARGET_FILENAME_PATH            "/opt/usr/media/"
+#define TARGET_FILENAME_PATH            "/home/owner/content/"
 #define STILL_CAPTURE_FILE_PATH_NAME    TARGET_FILENAME_PATH"StillshotCapture"
 #define MULTI_CAPTURE_FILE_PATH_NAME    TARGET_FILENAME_PATH"MultishotCapture"
 #define IMAGE_CAPTURE_THUMBNAIL_PATH    TARGET_FILENAME_PATH"thumbnail.jpg"
@@ -177,6 +177,7 @@ enum {
   -----------------------------------------------------------------------*/
 typedef struct _cam_handle {
        camera_h camera;
+       int type;
        int mode;                       /* image(capture)/video(recording) mode */
        int isMultishot;               /* flag for multishot mode */
        int stillshot_count;            /* total stillshot count */
@@ -661,6 +662,7 @@ static void print_menu()
                        g_print("\t   '1' Stillshot test\n");
                        g_print("\t   '2' Multishot test\n");
                        g_print("\t   '3' Setting\n");
+                       g_print("\t   '4' Change device (Rear <-> Front)\n");
                        g_print("\t   'b' back\n");
                        g_print("\t=======================================\n");
                }
@@ -678,6 +680,7 @@ static void print_menu()
                g_print("\t     '5' Exposure mode \n");
                g_print("\t     '6' Exposure value \n");
                g_print("\t     '7' F number \n");
+               g_print("\t     '8' Display reuse hint \n");
                g_print("\t     'i' ISO \n");
                g_print("\t     'r' Rotate camera input \n");
                g_print("\t     'f' Flip camera input \n");
@@ -750,6 +753,21 @@ static void main_menu(gchar buf)
                case '3': /* Setting */
                        hcamcorder->menu_state = MENU_STATE_SETTING;
                        break;
+               case '4': /* Change device (Rear <-> Front) */
+                       camera_stop_preview(hcamcorder->camera);
+
+                       if (hcamcorder->type == CAMERA_DEVICE_CAMERA0) {
+                               hcamcorder->type = CAMERA_DEVICE_CAMERA1;
+                       } else {
+                               hcamcorder->type = CAMERA_DEVICE_CAMERA0;
+                       }
+
+                       camera_change_device(hcamcorder->camera, hcamcorder->type);
+
+                       camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_LETTER_BOX);
+
+                       camera_start_preview(hcamcorder->camera);
+                       break;
                case 'b': /* back */
                        camera_stop_preview(hcamcorder->camera);
                        camera_destroy(hcamcorder->camera);
@@ -900,6 +918,22 @@ static void setting_menu(gchar buf)
                case '7': /* Setting > F number */
                        g_print("Not supported !! \n");
                        break;
+               case '8': /* Setting > Display reuse hint */
+                       {
+                               bool reuse_hint = false;
+
+                               err = camera_get_display_reuse_hint(hcamcorder->camera, &reuse_hint);
+                               if (err != CAMERA_ERROR_NONE) {
+                                       g_print("failed to get display reuse hint 0x%x\n", err);
+                                       break;
+                               }
+
+                               g_print("*Display reuse hint : current %d -> set %d\n", reuse_hint, !reuse_hint);
+                               reuse_hint = !reuse_hint;
+                               err = camera_set_display_reuse_hint(hcamcorder->camera, reuse_hint);
+                               g_print("set display reuse hint result : 0x%x\n", err);
+                       }
+                       break;
                case 'i': /* Setting > ISO */
                        g_print("*ISO !\n");
                        camera_attr_foreach_supported_iso(hcamcorder->camera, iso_mode_cb, NULL);
@@ -1307,12 +1341,12 @@ static gboolean mode_change(gchar buf)
        switch (buf) {
        case '1':
                hcamcorder->mode = MODE_VIDEO_CAPTURE;
-               cam_info = CAMERA_DEVICE_CAMERA1;
+               hcamcorder->type = cam_info = CAMERA_DEVICE_CAMERA1;
                check = TRUE;
                break;
        case '2':
                hcamcorder->mode = MODE_VIDEO_CAPTURE;
-               cam_info = CAMERA_DEVICE_CAMERA0;
+               hcamcorder->type = cam_info = CAMERA_DEVICE_CAMERA0;
                check = TRUE;
                break;
        case 'q':