Provide the rotation of each preview frame 37/266237/5 accepted/tizen/unified/20211112.135809 submit/tizen/20211110.120232
authorJeongmo Yang <jm80.yang@samsung.com>
Tue, 9 Nov 2021 10:53:44 +0000 (19:53 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Tue, 9 Nov 2021 12:13:32 +0000 (21:13 +0900)
- A new internal API is added.
 : camera_attr_get_preview_frame_rotation()
 : It should be called in camera_preview_cb(),
   otherwise, it will return CAMERA_ERROR_INVALID_OPERATION.
- A rotation method is set in media packet for preview frame.
  It could be get with media_packet_get_rotate_method().

[Version] 0.4.65
[Issue Type] New feature

Change-Id: Ic728c4a9a6d285f6fb5ca570ee85bc4e53cfd859
Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
include/camera_internal.h
include/camera_private.h
packaging/capi-media-camera.spec
src/camera.c
src/camera_internal.c
test/camera_test.c

index b14a8d9..82fcb85 100644 (file)
@@ -83,6 +83,10 @@ typedef struct _camera_stream_data_s {
        int stride[BUFFER_MAX_PLANE_NUM];    /**< Stride of each plane */
        int elevation[BUFFER_MAX_PLANE_NUM]; /**< Elevation of each plane */
        int extra_stream_id;            /**< ID of extra preview stream */
+       int focus_state;                /**< Focus state */
+       int facing_direction;           /**< Facing direction */
+       int flip;                       /**< Flip */
+       int rotation;                   /**< Rotation */
 } camera_stream_data_s;
 
 
@@ -548,6 +552,22 @@ int camera_attr_set_extra_preview_gop_interval(camera_h camera, int stream_id, i
 int camera_attr_get_extra_preview_gop_interval(camera_h camera, int stream_id, int *interval);
 
 /**
+ * @internal
+ * @brief Gets the rotation of preview frame.
+ * @since_tizen 6.5
+ * @remarks The function should be called in camera_preview_cb(),\n
+ *          otherwise, it will return #CAMERA_ERROR_INVALID_OPERATION.
+ * @param[in] camera    The handle to the camera
+ * @param[out] rotation The rotation of preview frame
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #CAMERA_ERROR_NONE Successful
+ * @retval #CAMERA_ERROR_INVALID_OPERATION Internal error
+ * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #CAMERA_ERROR_SERVICE_DISCONNECTED The socket to multimedia server is disconnected
+ */
+int camera_attr_get_preview_frame_rotation(camera_h camera, camera_rotation_e *rotation);
+
+/**
  * @}
  */
 #ifdef __cplusplus
index 4704c38..01fbddf 100644 (file)
@@ -175,6 +175,9 @@ typedef struct _camera_cb_info_s {
        /* media bridge */
        media_bridge_h bridge;
        GMutex bridge_lock;
+
+       /* preview stream */
+       camera_stream_data_s *stream_data;
 } camera_cb_info_s;
 
 typedef struct _camera_message_s {
index e16061c..931f3c3 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-camera
 Summary:    A Camera API
-Version:    0.4.64
+Version:    0.4.65
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 78323e0..4f0e2b9 100644 (file)
@@ -321,17 +321,20 @@ static void __camera_event_handler_preview(camera_cb_info_s *cb_info, char *recv
                cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW]) {
                camera_create_preview_frame(stream, num_buffer_fd, buffer_bo_handle, &data_bo_handle, &frame);
 
-               if (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW] &&
-                       stream->extra_stream_id < 0) {
-                       ((camera_preview_cb)cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW])(&frame,
-                               cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
-               }
+               /* set stream data for camera_get_preview_frame_rotation() */
+               cb_info->stream_data = stream;
 
-               if (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW] &&
-                       stream->extra_stream_id >= 0) {
-                       ((camera_extra_preview_cb)cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW])(&frame,
-                               stream->extra_stream_id, cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW]);
+               if (stream->extra_stream_id < 0) {
+                       if (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW])
+                               ((camera_preview_cb)cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_PREVIEW])(&frame,
+                                       cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_PREVIEW]);
+               } else {
+                       if (cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW])
+                               ((camera_extra_preview_cb)cb_info->user_cb[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW])(&frame,
+                                       stream->extra_stream_id, cb_info->user_data[MUSE_CAMERA_EVENT_TYPE_EXTRA_PREVIEW]);
                }
+
+               cb_info->stream_data = NULL;
        }
 
        if (stream->extra_stream_id >= 0)
@@ -1291,6 +1294,10 @@ static int __camera_media_packet_create(camera_cb_info_s *cb_info, camera_stream
        if (media_packet_set_pts(pkt, (uint64_t)(stream->timestamp) * 1000000) != MEDIA_PACKET_ERROR_NONE)
                CAM_LOG_WARNING("media_packet_set_pts failed");
 
+       /* set rotation */
+       if (media_packet_set_rotate_method(pkt, (media_packet_rotate_method_e)stream->rotation) != MEDIA_PACKET_ERROR_NONE)
+               CAM_LOG_WARNING("media_packet_set_rotate_method failed");
+
        CAM_LOG_VERBOSE("new media packet[%p], tbm surface[%p]", pkt, tsurf);
 
        *packet = pkt;
index f84ecea..15e50d6 100644 (file)
@@ -773,4 +773,26 @@ int camera_attr_get_extra_preview_gop_interval(camera_h camera, int stream_id, i
        return ret;
 }
 
+
+int camera_attr_get_preview_frame_rotation(camera_h camera, camera_rotation_e *rotation)
+{
+       camera_cli_s *pc = (camera_cli_s *)camera;
+
+       if (!pc || !pc->cb_info || !rotation) {
+               CAM_LOG_ERROR("NULL pointer %p %p", pc, rotation);
+               return CAMERA_ERROR_INVALID_PARAMETER;
+       }
+
+       if (!pc->cb_info->stream_data) {
+               CAM_LOG_ERROR("no stream data, maybe it's not in preview callback");
+               return CAMERA_ERROR_INVALID_OPERATION;
+       }
+
+       *rotation = pc->cb_info->stream_data->rotation;
+
+       CAM_LOG_DEBUG("frame rotation[%d]", *rotation);
+
+       return CAMERA_ERROR_NONE;
+}
+
 //LCOV_EXCL_STOP
index 311fa63..3e00513 100644 (file)
@@ -582,12 +582,20 @@ static void _camera_print_preview_info(camera_preview_data_s *frame)
 
 static void _camera_preview_cb(camera_preview_data_s *frame, void *user_data)
 {
-       if (!frame) {
-               g_print("\n[PREVIEW_CB] NULL frame!\n");
+       int ret = CAMERA_ERROR_NONE;
+       camera_h cam_handle = (camera_h)user_data;
+       camera_rotation_e rotation = CAMERA_ROTATION_NONE;
+
+       if (!cam_handle || !frame) {
+               g_print("\n[PREVIEW_CB] NULL param! %p %p\n", cam_handle, frame);
                return;
        }
 
-       g_print("[PREVIEW_CB] preview callback - ");
+       ret = camera_attr_get_preview_frame_rotation(cam_handle, &rotation);
+       if (ret != CAMERA_ERROR_NONE)
+               g_print("[PREVIEW_CB] get preview frame rotation failed[0x%x]\n", ret);
+
+       g_print("[PREVIEW_CB] preview[rotation:%d] callback - ", rotation);
 
        _camera_print_preview_info(frame);