Add da timestamp 75/288975/11
authorKwanghoon Son <k.son@samsung.com>
Mon, 27 Feb 2023 06:04:42 +0000 (15:04 +0900)
committerKwanghoon Son <k.son@samsung.com>
Fri, 3 Mar 2023 02:23:08 +0000 (11:23 +0900)
[Issue type] new feature
[Version] 0.23.43

Change-Id: I988e4ee27300e8a1510c606ec8cc6c5f24675125
Signed-off-by: Kwanghoon Son <k.son@samsung.com>
CMakeLists.txt
include/mv_common_internal.h [new file with mode: 0644]
mv_common/CMakeLists.txt
mv_common/include/MediaSource.h
mv_common/include/mv_common_c.h
mv_common/src/MediaSource.cpp
mv_common/src/mv_common.c
mv_common/src/mv_common_c.cpp
packaging/capi-media-vision.spec
test/CMakeLists.txt
test/testsuites/common/test_common.cpp [new file with mode: 0644]

index fab7f73..5fc0127 100644 (file)
@@ -58,12 +58,20 @@ install(
         PATTERN "*_inference*.h"
         PATTERN "*_common*.h"
         )
+elseif(WITH_DA_PROFILE)
+install(
+        DIRECTORY include/ DESTINATION include/media
+        FILES_MATCHING
+        PATTERN "*_private.h" EXCLUDE
+        PATTERN "*.h"
+        )
 else()
 install(
         DIRECTORY include/ DESTINATION include/media
         FILES_MATCHING
         PATTERN "*_private.h" EXCLUDE
         PATTERN "*.h"
+        PATTERN "*_common_internal.h" EXCLUDE
         )
 endif()
 
diff --git a/include/mv_common_internal.h b/include/mv_common_internal.h
new file mode 100644 (file)
index 0000000..884af1b
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __TIZEN_MEDIAVISION_COMMON_INTERNAL_H__
+#define __TIZEN_MEDIAVISION_COMMON_INTERNAL_H__
+
+#include "mv_common.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#ifdef WITH_DA_PROFILE
+typedef struct
+{
+       uint64_t timestamp;
+       uint64_t ts_soe;
+       uint64_t ts_eoe;
+       uint64_t ts_sof;
+       uint64_t ts_eof;
+       uint64_t ts_hal;
+       uint64_t ts_qmf;
+       uint64_t td_exp;
+       uint64_t ts_aux;
+       uint64_t td_aux;
+       uint64_t seqnum;
+       uint64_t flags;
+} da_timestamp_s;
+
+int mv_source_get_timestamp(mv_source_h source, da_timestamp_s *stamp);
+int mv_source_fill_by_buffer_da(mv_source_h source, unsigned char *data_buffer, unsigned int buffer_size,
+                                                               unsigned int image_width, unsigned int image_height, unsigned int stride,
+                                                               mv_colorspace_e image_colorspace, da_timestamp_s *stamp);
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __TIZEN_MEDIAVISION_COMMON_INTERNAL_H__ */
index 6434960..1abf217 100644 (file)
@@ -18,6 +18,10 @@ else()
     add_library(${PROJECT_NAME} SHARED ${MV_COMMON_SRC_LIST})
 endif()
 
+if(WITH_DA_PROFILE)
+    target_compile_definitions(${PROJECT_NAME} PUBLIC -DWITH_DA_PROFILE)
+endif()
+
 target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS} ${${PROJECT_NAME}_DEP_LIBRARIES})
 target_include_directories(${PROJECT_NAME} PUBLIC include ${${PROJECT_NAME}_DEP_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/include)
 target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Werror)
index 69c1ca7..4f990d9 100644 (file)
 // Need for a colorspace
 #include <mv_common.h>
 #include <stddef.h>
+
+#ifdef WITH_DA_PROFILE
+#include <mv_common_internal.h>
+#endif
 /**
  * @file MediaSource.h
  * @brief This file contains the MediaSource class.
@@ -102,6 +106,12 @@ public:
        bool fill(const unsigned char *buffer, unsigned int bufferSize, unsigned int width, unsigned int height,
                          mv_colorspace_e colorspace);
 
+#ifdef WITH_DA_PROFILE
+       da_timestamp_s getTimeStamp();
+       bool fill(const unsigned char *buffer, unsigned int bufferSize, unsigned int width, unsigned int height,
+                         unsigned int stride, mv_colorspace_e colorspace, da_timestamp_s &stamp);
+#endif
+
        /**
         * @brief Fills the MediaSource based on the buffer and metadata.
         *
@@ -171,6 +181,9 @@ protected:
        unsigned int m_height; /**< The image height */
 
        mv_colorspace_e m_colorspace; /**< The image colorspace */
+#ifdef WITH_DA_PROFILE
+       da_timestamp_s m_stamp;
+#endif
 };
 
 } /* Common */
index cbcb731..dc18769 100644 (file)
@@ -18,6 +18,7 @@
 #define __MEDIA_VISION_COMMON_C_H__
 
 #include "mv_common.h"
+#include "mv_common_internal.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -99,6 +100,14 @@ int mv_source_fill_by_media_packet_c(mv_source_h source, media_packet_h media_pa
 int mv_source_fill_by_buffer_c(mv_source_h source, unsigned char *data_buffer, unsigned int buffer_size,
                                                           unsigned int image_width, unsigned int image_height, mv_colorspace_e image_colorspace);
 
+#ifdef WITH_DA_PROFILE
+int mv_source_get_timestamp_c(mv_source_h source, da_timestamp_s *stamp);
+
+int mv_source_fill_by_buffer_da_c(mv_source_h source, unsigned char *data_buffer, unsigned int buffer_size,
+                                                                 unsigned int image_width, unsigned int image_height, unsigned int stride,
+                                                                 mv_colorspace_e image_colorspace, da_timestamp_s *stamp);
+#endif
+
 /**
  * @brief Clears the buffer of the media source.
  *
index 84d815b..85b304d 100644 (file)
@@ -158,6 +158,62 @@ bool MediaSource::fill(const unsigned char *buffer, unsigned int bufferSize, uns
        return true;
 }
 
+#ifdef WITH_DA_PROFILE
+da_timestamp_s MediaSource::getTimeStamp()
+{
+       return m_stamp;
+}
+
+bool MediaSource::fill(const unsigned char *buffer, unsigned int bufferSize, unsigned int width, unsigned int height,
+                                          unsigned int stride, mv_colorspace_e colorspace, da_timestamp_s &stamp)
+{
+       if (!buffer || bufferSize == 0)
+               return false;
+
+       LOGD("Call clear() first for media source %p", this);
+       clear();
+
+       LOGD("Allocate memory [%i] for buffer in media source %p", bufferSize, this);
+       LOGD("Assign new size (%ui x %ui) of the internal buffer image for "
+                "the media source %p",
+                width, height, this);
+       LOGD("Assign new colorspace (%i) of the internal buffer image for "
+                "the media source %p",
+                colorspace, this);
+       m_pBuffer = new (std::nothrow) unsigned char[bufferSize];
+       if (m_pBuffer == NULL) {
+               LOGE("Memory allocating for buffer in media source %p failed!", this);
+               return false;
+       }
+
+       LOGD("Copy data from external buffer (%p) to the internal buffer (%p) of "
+                "media source %p",
+                buffer, m_pBuffer, this);
+       for (unsigned h = 0; h < height; h++) {
+               std::memcpy(m_pBuffer + (width * h), buffer + (stride * h), width);
+       }
+
+       LOGD("Assign new size of the internal buffer of media source %p. "
+                "New size is %ui.",
+                this, bufferSize);
+       m_bufferSize = bufferSize;
+
+       LOGD("Assign new size (%ui x %ui) of the internal buffer image for "
+                "the media source %p",
+                width, height, this);
+       m_width = width;
+       m_height = height;
+
+       LOGD("Assign new colorspace (%i) of the internal buffer image for "
+                "the media source %p",
+                colorspace, this);
+       m_colorspace = colorspace;
+       m_stamp = stamp;
+
+       return true;
+}
+#endif
+
 unsigned char *MediaSource::getBuffer(void) const
 {
        return m_pBuffer;
index 19b5432..6b7d528 100644 (file)
@@ -17,6 +17,7 @@
 #include "mv_private.h"
 #include "mv_common.h"
 #include "mv_common_c.h"
+#include "mv_common_internal.h"
 
 int mv_create_source(mv_source_h *source)
 {
@@ -69,6 +70,38 @@ int mv_source_fill_by_buffer(mv_source_h source, unsigned char *data_buffer, uns
        return ret;
 }
 
+#ifdef WITH_DA_PROFILE
+int mv_source_get_timestamp(mv_source_h source, da_timestamp_s *stamp)
+{
+       MEDIA_VISION_SUPPORT_CHECK(_mv_check_system_info_feature_supported());
+       MEDIA_VISION_INSTANCE_CHECK(source);
+       MEDIA_VISION_INSTANCE_CHECK(stamp);
+       MEDIA_VISION_FUNCTION_ENTER();
+       int ret = mv_source_get_timestamp_c(source, stamp);
+       MEDIA_VISION_FUNCTION_LEAVE();
+
+       return ret;
+}
+
+int mv_source_fill_by_buffer_da(mv_source_h source, unsigned char *data_buffer, unsigned int buffer_size,
+                                                               unsigned int image_width, unsigned int image_height, unsigned int stride,
+                                                               mv_colorspace_e image_colorspace, da_timestamp_s *stamp)
+{
+       MEDIA_VISION_SUPPORT_CHECK(_mv_check_system_info_feature_supported());
+       MEDIA_VISION_INSTANCE_CHECK(source);
+       MEDIA_VISION_NULL_ARG_CHECK(data_buffer);
+       MEDIA_VISION_INSTANCE_CHECK(stamp);
+
+       MEDIA_VISION_FUNCTION_ENTER();
+       int ret = mv_source_fill_by_buffer_da_c(source, data_buffer, buffer_size, image_width, image_height, stride,
+                                                                                       image_colorspace, stamp);
+       MEDIA_VISION_FUNCTION_LEAVE();
+
+       return ret;
+}
+
+#endif
+
 int mv_source_clear(mv_source_h source)
 {
        MEDIA_VISION_SUPPORT_CHECK(_mv_check_system_info_feature_supported());
index 67ac10e..c9edcd2 100644 (file)
@@ -231,6 +231,41 @@ int mv_source_fill_by_buffer_c(mv_source_h source, unsigned char *data_buffer, u
        return MEDIA_VISION_ERROR_NONE;
 }
 
+#ifdef WITH_DA_PROFILE
+int mv_source_get_timestamp_c(mv_source_h source, da_timestamp_s *stamp)
+{
+       try {
+               MediaVision::Common::MediaSource *mediaSource = static_cast<MediaVision::Common::MediaSource *>(source);
+               *stamp = mediaSource->getTimeStamp();
+       } catch (const std::exception &e) {
+               LOGE("%s", e.what());
+               return MEDIA_VISION_ERROR_INTERNAL;
+       }
+       return MEDIA_VISION_ERROR_NONE;
+}
+int mv_source_fill_by_buffer_da_c(mv_source_h source, unsigned char *data_buffer, unsigned int buffer_size,
+                                                                 unsigned int image_width, unsigned int image_height, unsigned int stride,
+                                                                 mv_colorspace_e image_colorspace, da_timestamp_s *stamp)
+{
+       if (!source || buffer_size == 0 || data_buffer == NULL) {
+               LOGE("Media source can't be filled by buffer because "
+                        "one of the source or data_buffer is NULL or buffer_size = 0. "
+                        "source = %p; data_buffer = %p; buffer_size = %u",
+                        source, data_buffer, buffer_size);
+               return MEDIA_VISION_ERROR_INVALID_PARAMETER;
+       }
+
+       if (!(static_cast<MediaVision::Common::MediaSource *>(source))
+                                ->fill(data_buffer, buffer_size, image_width, image_height, stride, image_colorspace, *stamp)) {
+               LOGE("mv_source_h filling from buffer failed");
+               return MEDIA_VISION_ERROR_OUT_OF_MEMORY;
+       }
+
+       LOGD("Media source has been filled from buffer");
+       return MEDIA_VISION_ERROR_NONE;
+}
+#endif
+
 int mv_source_clear_c(mv_source_h source)
 {
        if (!source) {
index 83bb446..fd442b3 100644 (file)
@@ -1,7 +1,7 @@
 Name:        capi-media-vision
 Summary:     Media Vision library for Tizen Native API
-Version:     0.23.41
-Release:     3
+Version:     0.23.43
+Release:     0
 Group:       Multimedia/Framework
 License:     Apache-2.0 and BSD-3-Clause
 Source0:     %{name}-%{version}.tar.gz
@@ -278,7 +278,11 @@ export FFLAGS+=" -fprofile-arcs -ftest-coverage"
 export LDFLAGS+=" -lgcov"
 %endif
 
+
 %cmake . -DCMAKE_BUILD_TYPE=RelWithDebInfo %{build_options} \
+%if 0%{?_with_da_profile:1}
+ -DWITH_DA_PROFILE=ON \
+%endif
 %if 0%{?ml_only:1}
  -DBUILD_ML_ONLY=ON \
 %endif
@@ -321,6 +325,9 @@ find . -name '*.gcno' -exec cp --parents '{}' "$gcno_obj_dir" ';'
 
 %files common-devel
 %{_includedir}/media/mv_common.h
+%if 0%{?_with_da_profile:1}
+%{_includedir}/media/mv_common_internal.h
+%endif
 %{_libdir}/pkgconfig/*common.pc
 
 %if !0%{?ml_only:1}
index 0cf0ac3..6d990bc 100644 (file)
@@ -26,9 +26,16 @@ if (${BUILD_DEPTH_STREAM_TESTSUITE})
 set(SRC_FILES ${SRC_FILES} testsuites/mv3d/test_3d.cpp)
 endif()
 
+if (WITH_DA_PROFILE)
+set(SRC_FILES ${SRC_FILES} testsuites/common/test_common.cpp)
+endif()
+
 add_executable(${PROJECT_NAME} ${SRC_FILES})
 target_link_libraries(${PROJECT_NAME} gtest gtest_main mv_inference mv_image_helper mv_barcode_detector)
 
+if (WITH_DA_PROFILE)
+target_link_libraries(${PROJECT_NAME} vision-source)
+endif()
 if (${BUILD_DEPTH_STREAM_TESTSUITE})
 target_link_libraries(${PROJECT_NAME} mv_3d)
 endif()
diff --git a/test/testsuites/common/test_common.cpp b/test/testsuites/common/test_common.cpp
new file mode 100644 (file)
index 0000000..afd99cc
--- /dev/null
@@ -0,0 +1,77 @@
+/**
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <mv_common_internal.h>
+#include <vision_source.h>
+#include <gtest/gtest.h>
+
+TEST(Common_DA, Simple)
+{
+       mv_source_h mv_source;
+       unsigned char fake_data[10];
+       da_timestamp_s fake_stamp;
+
+       ASSERT_EQ(mv_create_source(&mv_source), VISION_SOURCE_ERROR_NONE);
+       ASSERT_EQ(mv_source_fill_by_buffer_da(mv_source, fake_data, 6, 3, 2, 5, MEDIA_VISION_COLORSPACE_Y800, &fake_stamp),
+                         VISION_SOURCE_ERROR_NONE);
+       ASSERT_EQ(mv_destroy_source(mv_source), VISION_SOURCE_ERROR_NONE);
+}
+
+static int nv12_test_cb(vision_source_buffer_s *buffer, void *user_data)
+{
+       clock_t end = clock();
+       clock_t *start = (clock_t *) user_data;
+
+       double delta_ms = (double) (end - *start) / CLOCKS_PER_SEC * 1000;
+
+       std::cout << "delta_ms :" << delta_ms << std::endl;
+
+       mv_source_h mv_source;
+       mv_create_source(&mv_source);
+       da_timestamp_s *fake_stamp = (da_timestamp_s *) buffer->priv;
+       std::cout << "buffer timestamp : " << fake_stamp->timestamp << std::endl;
+
+       mv_source_fill_by_buffer_da(mv_source, buffer->planes[0].data, buffer->resolution.width * buffer->resolution.height,
+                                                               buffer->resolution.width, buffer->resolution.height, buffer->planes[0].align_width,
+                                                               MEDIA_VISION_COLORSPACE_Y800, fake_stamp);
+       da_timestamp_s copy_stamp;
+       mv_source_get_timestamp(mv_source, &copy_stamp);
+       std::cout << "copy timestamp : " << copy_stamp.timestamp << std::endl;
+       mv_destroy_source(mv_source);
+       return 0;
+}
+
+TEST(Common_DA, Callback)
+{
+       vision_source_h ms_handle_cam3;
+       vision_source_format_s format;
+
+       format.pixel_format = VISION_SOURCE_PIXEL_FORMAT_NV12;
+       format.resolution.width = 640;
+       format.resolution.height = 800;
+       format.fps = 10;
+       ASSERT_EQ(vision_source_init(&ms_handle_cam3), VISION_SOURCE_ERROR_NONE);
+       ASSERT_EQ(vision_source_open_device(ms_handle_cam3, 3), VISION_SOURCE_ERROR_NONE);
+       ASSERT_EQ(vision_source_set_stream_format(ms_handle_cam3, &format), VISION_SOURCE_ERROR_NONE);
+
+       clock_t start = clock();
+       ASSERT_EQ(vision_source_start_stream(ms_handle_cam3, nv12_test_cb, &start), VISION_SOURCE_ERROR_NONE);
+       sleep(1);
+       ASSERT_EQ(vision_source_stop_stream(ms_handle_cam3), VISION_SOURCE_ERROR_NONE);
+
+       ASSERT_EQ(vision_source_close_device(ms_handle_cam3), VISION_SOURCE_ERROR_NONE);
+       ASSERT_EQ(vision_source_exit(ms_handle_cam3), VISION_SOURCE_ERROR_NONE);
+}
\ No newline at end of file