From c083652f112a751972e2b88d54294a86271f86fc Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Sun, 23 Oct 2022 17:42:59 +0900 Subject: [PATCH] Add new internal API for timestamp in nsec [Version] 0.4.94 [Issue Type] New feature Change-Id: I9f154fe928a9c151cc36724f8109d0865fdcc1b5 Signed-off-by: Jeongmo Yang --- include/camera_internal.h | 15 +++++++++++++++ packaging/capi-media-camera.spec | 2 +- src/camera.c | 3 +-- src/camera_internal.c | 22 ++++++++++++++++++++++ test/camera_test.c | 8 +++++++- 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/include/camera_internal.h b/include/camera_internal.h index 9775db8..913539d 100644 --- a/include/camera_internal.h +++ b/include/camera_internal.h @@ -253,6 +253,21 @@ int camera_set_extra_preview_device(camera_h camera, int stream_id, camera_devic int camera_request_codec_config(camera_h camera); /** + * @internal + * @brief Gets the timestamp of preview frame in nano second. + * @since_tizen 7.0 + * @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] timestamp The timestamp of preview frame (in nsec) + * @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 + */ +int camera_attr_get_preview_frame_timestamp(camera_h camera, unsigned long *timestamp); + +/** * @} */ #ifdef __cplusplus diff --git a/packaging/capi-media-camera.spec b/packaging/capi-media-camera.spec index c63cf24..94be33d 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.93 +Version: 0.4.94 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/camera.c b/src/camera.c index 75f5ddd..5bc1b69 100644 --- a/src/camera.c +++ b/src/camera.c @@ -1383,8 +1383,7 @@ static int __camera_create_media_packet(camera_cb_info_s *cb_info, MMCamcorderVi goto _PACKET_CREATE_FAILED; } - /* set timestamp : msec -> nsec */ - if (media_packet_set_pts(pkt, (uint64_t)(stream->timestamp) * 1000000) != MEDIA_PACKET_ERROR_NONE) + if (media_packet_set_pts(pkt, stream->timestamp_nsec) != MEDIA_PACKET_ERROR_NONE) CAM_LOG_WARNING("media_packet_set_pts failed"); if (media_packet_set_rotate_method(pkt, (media_packet_rotate_method_e)stream->rotation) != MEDIA_PACKET_ERROR_NONE) diff --git a/src/camera_internal.c b/src/camera_internal.c index 9f28f7e..fe5468b 100644 --- a/src/camera_internal.c +++ b/src/camera_internal.c @@ -378,4 +378,26 @@ int camera_request_codec_config(camera_h camera) return ret; } + + +int camera_attr_get_preview_frame_timestamp(camera_h camera, unsigned long *timestamp) +{ + camera_cli_s *pc = (camera_cli_s *)camera; + + if (!pc || !pc->cb_info || !timestamp) { + CAM_LOG_ERROR("NULL pointer %p %p", pc, timestamp); + 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; + } + + *timestamp = pc->cb_info->stream_data->timestamp_nsec; + + CAM_LOG_DEBUG("frame timestamp[%lu]", *timestamp); + + return CAMERA_ERROR_NONE; +} //LCOV_EXCL_STOP diff --git a/test/camera_test.c b/test/camera_test.c index dbad1b3..bca41fe 100644 --- a/test/camera_test.c +++ b/test/camera_test.c @@ -459,6 +459,7 @@ static void _camera_preview_cb(camera_preview_data_s *frame, void *user_data) int ret = CAMERA_ERROR_NONE; camera_h cam_handle = (camera_h)user_data; camera_rotation_e rotation = CAMERA_ROTATION_NONE; + unsigned long timestamp = 0; if (!cam_handle || !frame) { g_print("\n[PREVIEW_CB] NULL param! %p %p\n", cam_handle, frame); @@ -469,7 +470,12 @@ static void _camera_preview_cb(camera_preview_data_s *frame, void *user_data) 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); + ret = camera_attr_get_preview_frame_timestamp(cam_handle, ×tamp); + if (ret != CAMERA_ERROR_NONE) + g_print("[PREVIEW_CB] get preview frame timestamp failed[0x%x]\n", ret); + + g_print("[PREVIEW_CB] preview[rotation:%d,timestamp:%lu] callback\n", + rotation, timestamp); _camera_print_preview_info(frame); -- 2.7.4