Add {get/set}_{priv_}timestamp 98/293798/3 accepted/tizen/unified/20230608.164349
authorKwanghoon Son <k.son@samsung.com>
Mon, 10 Apr 2023 05:25:45 +0000 (14:25 +0900)
committerKwanghoon Son <k.son@samsung.com>
Thu, 8 Jun 2023 02:02:36 +0000 (11:02 +0900)
[Version] 0.28.3
[Issue type] New

mv_source needs timestamp data.
Also put private timestamp data for extension.

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

index cff9a43..494cb2f 100644 (file)
@@ -655,6 +655,38 @@ typedef bool (*mv_supported_attribute_cb)(mv_config_attribute_type_e attribute_t
 int mv_engine_config_foreach_supported_attribute(mv_supported_attribute_cb callback, void *user_data);
 
 /**
+ * @brief Gets timestamp from mv_source.
+ *
+ * @since_tizen 8.0
+ * @param[in]  source    The handle to the source
+ * @param[out] timestamp The nano seconds(ns) timestamp
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #MEDIA_VISION_ERROR_NONE Successful
+ * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported
+ * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mv_source_set_timestamp()
+ */
+int mv_source_get_timestamp(mv_source_h source, uint64_t *timestamp);
+
+/**
+ * @brief Sets timestamp to mv_source.
+ *
+ * @since_tizen 8.0
+ * @param[in] source    The handle to the source
+ * @param[in] timestamp The nano seconds(ns) timestamp
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #MEDIA_VISION_ERROR_NONE Successful
+ * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported
+ * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mv_source_get_timestamp()
+ */
+int mv_source_set_timestamp(mv_source_h source, uint64_t timestamp);
+
+/**
  * @}
  */
 
diff --git a/include/mv_common_internal.h b/include/mv_common_internal.h
new file mode 100644 (file)
index 0000000..1c13893
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * 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 */
+
+/**
+ * @internal
+ * @brief Gets private timestamp from mv_source.
+ *
+ * @since_tizen 8.0
+ * @param[in]  source The handle to the source
+ * @param[out] priv   The private timestamp (user specific timestamp)
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #MEDIA_VISION_ERROR_NONE Successful
+ * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported
+ * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mv_source_set_priv_timestamp()
+ */
+int mv_source_get_priv_timestamp(mv_source_h source, void **priv);
+
+/**
+ * @internal
+ * @brief Sets private timestamp to mv_source.
+ *
+ * @since_tizen 8.0
+ * @param[in] source The handle to the source
+ * @param[in] priv   The private timestamp (user specific timestamp)
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #MEDIA_VISION_ERROR_NONE Successful
+ * @retval #MEDIA_VISION_ERROR_NOT_SUPPORTED Not supported
+ * @retval #MEDIA_VISION_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see mv_source_get_priv_timestamp()
+ */
+int mv_source_set_priv_timestamp(mv_source_h source, void *priv);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __TIZEN_MEDIAVISION_COMMON_INTERNAL_H__ */
index 75f775e..1ba4951 100644 (file)
@@ -35,6 +35,10 @@ struct Plane {
        unsigned int imageSize { 0 };
        unsigned int bytePerLine { 0 };
 };
+struct Timestamp {
+       uint64_t timestamp;
+       void *priv;
+};
 
 /**
  * @class   MediaSource
@@ -162,12 +166,17 @@ public:
 
        unsigned int getWidthStride();
 
+       const Timestamp &getTimestamp();
+
+       void setTimestamp(const Timestamp &timestamp);
+
 private:
        std::vector<Plane> _plane;
        unsigned int _width { 0 }; /**< The image width */
        unsigned int _height { 0 }; /**< The image height */
        mv_colorspace_e _colorspace { MEDIA_VISION_COLORSPACE_INVALID }; /**< The image colorspace */
        media_packet_h _packet { nullptr };
+       Timestamp _timestamp { 0, nullptr };
 };
 
 } /* Common */
index ac1abf0..3c8fa66 100644 (file)
@@ -222,5 +222,15 @@ unsigned int MediaSource::getWidthStride()
        return _plane[0].bytePerLine;
 }
 
+const Timestamp &MediaSource::getTimestamp()
+{
+       return _timestamp;
+}
+
+void MediaSource::setTimestamp(const Timestamp &timestamp)
+{
+       _timestamp = timestamp;
+}
+
 } /* Common */
 } /* MediaVision */
index 027707c..af64721 100644 (file)
@@ -20,6 +20,7 @@
 #include "EngineConfig.h"
 
 #include <mv_private.h>
+#include <mv_common_internal.h>
 
 #include <new>
 #include <memory>
@@ -669,3 +670,71 @@ int mv_engine_config_foreach_supported_attribute_c(mv_supported_attribute_cb cal
        LOGD("Attribute names/types has been gotten");
        return MEDIA_VISION_ERROR_NONE;
 }
+
+int mv_source_get_timestamp(mv_source_h source, uint64_t *timestamp)
+{
+       MEDIA_VISION_SUPPORT_CHECK(_mv_check_system_info_feature_supported());
+       MEDIA_VISION_INSTANCE_CHECK(source);
+
+       try {
+               auto mediaSource = static_cast<MediaVision::Common::MediaSource *>(source);
+               auto mediaTimestamp = mediaSource->getTimestamp();
+               *timestamp = mediaTimestamp.timestamp;
+       } catch (const std::exception &e) {
+               LOGE("%s", e.what());
+               return MEDIA_VISION_ERROR_INTERNAL;
+       }
+       return MEDIA_VISION_ERROR_NONE;
+}
+
+int mv_source_set_timestamp(mv_source_h source, uint64_t timestamp)
+{
+       MEDIA_VISION_SUPPORT_CHECK(_mv_check_system_info_feature_supported());
+       MEDIA_VISION_INSTANCE_CHECK(source);
+
+       try {
+               auto mediaSource = static_cast<MediaVision::Common::MediaSource *>(source);
+               auto mediaTimestamp = mediaSource->getTimestamp();
+               mediaTimestamp.timestamp = timestamp;
+               mediaSource->setTimestamp(mediaTimestamp);
+       } catch (const std::exception &e) {
+               LOGE("%s", e.what());
+               return MEDIA_VISION_ERROR_INTERNAL;
+       }
+       return MEDIA_VISION_ERROR_NONE;
+}
+
+int mv_source_get_priv_timestamp(mv_source_h source, void **priv)
+{
+       MEDIA_VISION_SUPPORT_CHECK(_mv_check_system_info_feature_supported());
+       MEDIA_VISION_INSTANCE_CHECK(source);
+       MEDIA_VISION_NULL_ARG_CHECK(priv);
+
+       try {
+               auto mediaSource = static_cast<MediaVision::Common::MediaSource *>(source);
+               auto mediaTimestamp = mediaSource->getTimestamp();
+               *priv = mediaTimestamp.priv;
+       } catch (const std::exception &e) {
+               LOGE("%s", e.what());
+               return MEDIA_VISION_ERROR_INTERNAL;
+       }
+       return MEDIA_VISION_ERROR_NONE;
+}
+
+int mv_source_set_priv_timestamp(mv_source_h source, void *priv)
+{
+       MEDIA_VISION_SUPPORT_CHECK(_mv_check_system_info_feature_supported());
+       MEDIA_VISION_INSTANCE_CHECK(source);
+       MEDIA_VISION_NULL_ARG_CHECK(priv);
+
+       try {
+               auto mediaSource = static_cast<MediaVision::Common::MediaSource *>(source);
+               auto mediaTimestamp = mediaSource->getTimestamp();
+               mediaTimestamp.priv = priv;
+               mediaSource->setTimestamp(mediaTimestamp);
+       } catch (const std::exception &e) {
+               LOGE("%s", e.what());
+               return MEDIA_VISION_ERROR_INTERNAL;
+       }
+       return MEDIA_VISION_ERROR_NONE;
+}
\ No newline at end of file
index 73019f9..a32a480 100644 (file)
@@ -1,6 +1,6 @@
 Name:        capi-media-vision
 Summary:     Media Vision library for Tizen Native API
-Version:     0.28.2
+Version:     0.28.3
 Release:     0
 Group:       Multimedia/Framework
 License:     Apache-2.0 and BSD-3-Clause
index 73d8a7a..5468647 100644 (file)
@@ -1,5 +1,6 @@
 #include <gtest/gtest.h>
 #include <mv_common.h>
+#include <mv_common_internal.h>
 
 TEST(MediaPKT, Format)
 {
@@ -69,4 +70,37 @@ TEST(MediaPKT, DISABLED_PacketToSourcePositive)
        ASSERT_EQ(media_format_unref(media_fmt), MEDIA_FORMAT_ERROR_NONE);
        ASSERT_EQ(mv_destroy_source(mv_source), MEDIA_VISION_ERROR_NONE);
        ASSERT_EQ(tbm_surface_destroy(surface), TBM_SURFACE_ERROR_NONE);
-}
\ No newline at end of file
+}
+
+TEST(MvSource, Timestamp)
+{
+       mv_source_h mv_source;
+       uint64_t timestamp;
+       ASSERT_EQ(mv_create_source(&mv_source), MEDIA_VISION_ERROR_NONE);
+       ASSERT_EQ(mv_source_get_timestamp(mv_source, &timestamp), MEDIA_VISION_ERROR_NONE);
+       ASSERT_EQ(timestamp, 0);
+       ASSERT_EQ(mv_source_set_timestamp(mv_source, 2), MEDIA_VISION_ERROR_NONE);
+       ASSERT_EQ(mv_source_get_timestamp(mv_source, &timestamp), MEDIA_VISION_ERROR_NONE);
+       ASSERT_EQ(timestamp, 2);
+       ASSERT_EQ(mv_destroy_source(mv_source), MEDIA_VISION_ERROR_NONE);
+}
+
+TEST(MvSource, TimestampPrivate)
+{
+       struct CustomTimestamp {
+               int a, b;
+       };
+       CustomTimestamp customTimestamp { 1, 2 };
+       CustomTimestamp *pCustomTimestamp = nullptr;
+       mv_source_h mv_source;
+       ASSERT_EQ(mv_create_source(&mv_source), MEDIA_VISION_ERROR_NONE);
+
+       ASSERT_EQ(mv_source_get_priv_timestamp(mv_source, nullptr), MEDIA_VISION_ERROR_INVALID_PARAMETER);
+       ASSERT_EQ(mv_source_set_priv_timestamp(mv_source, nullptr), MEDIA_VISION_ERROR_INVALID_PARAMETER);
+
+       ASSERT_EQ(mv_source_set_priv_timestamp(mv_source, (void *) &customTimestamp), MEDIA_VISION_ERROR_NONE);
+       customTimestamp.a = -1;
+       ASSERT_EQ(mv_source_get_priv_timestamp(mv_source, (void **) &pCustomTimestamp), MEDIA_VISION_ERROR_NONE);
+       ASSERT_EQ(pCustomTimestamp->a, -1);
+       ASSERT_EQ(mv_destroy_source(mv_source), MEDIA_VISION_ERROR_NONE);
+}