From 630f2128c493630677f0289be13ba65483743011 Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Tue, 9 Nov 2021 19:53:44 +0900 Subject: [PATCH] Provide the rotation of each preview frame - 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 --- include/camera_internal.h | 20 ++++++++++++++++++++ include/camera_private.h | 3 +++ packaging/capi-media-camera.spec | 2 +- src/camera.c | 25 ++++++++++++++++--------- src/camera_internal.c | 22 ++++++++++++++++++++++ test/camera_test.c | 14 +++++++++++--- 6 files changed, 73 insertions(+), 13 deletions(-) diff --git a/include/camera_internal.h b/include/camera_internal.h index b14a8d9..82fcb85 100644 --- a/include/camera_internal.h +++ b/include/camera_internal.h @@ -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 diff --git a/include/camera_private.h b/include/camera_private.h index 4704c38..01fbddf 100644 --- a/include/camera_private.h +++ b/include/camera_private.h @@ -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 { diff --git a/packaging/capi-media-camera.spec b/packaging/capi-media-camera.spec index e16061c..931f3c3 100644 --- a/packaging/capi-media-camera.spec +++ b/packaging/capi-media-camera.spec @@ -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 diff --git a/src/camera.c b/src/camera.c index 78323e0..4f0e2b9 100644 --- a/src/camera.c +++ b/src/camera.c @@ -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; diff --git a/src/camera_internal.c b/src/camera_internal.c index f84ecea..15e50d6 100644 --- a/src/camera_internal.c +++ b/src/camera_internal.c @@ -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 diff --git a/test/camera_test.c b/test/camera_test.c index 311fa63..3e00513 100644 --- a/test/camera_test.c +++ b/test/camera_test.c @@ -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); -- 2.7.4