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()
--- /dev/null
+/*
+ * 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__ */
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)
// 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.
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.
*
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 */
#define __MEDIA_VISION_COMMON_C_H__
#include "mv_common.h"
+#include "mv_common_internal.h"
#ifdef __cplusplus
extern "C" {
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.
*
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;
#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)
{
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());
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) {
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
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
%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}
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()
--- /dev/null
+/**
+ * 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, ©_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