Add new internal API for timestamp in nsec 20/283420/3 accepted/tizen/unified/20221102.020612
authorJeongmo Yang <jm80.yang@samsung.com>
Sun, 23 Oct 2022 08:42:59 +0000 (17:42 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Sun, 23 Oct 2022 11:07:56 +0000 (20:07 +0900)
[Version] 0.4.94
[Issue Type] New feature

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

index 9775db8..913539d 100644 (file)
@@ -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
index c63cf24..94be33d 100644 (file)
@@ -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
index 75f5ddd..5bc1b69 100644 (file)
@@ -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)
index 9f28f7e..fe5468b 100644 (file)
@@ -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
index dbad1b3..bca41fe 100644 (file)
@@ -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, &timestamp);
+       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);