It replaced with fill_by_media_packet.
timestamp data can be used with {get/set}_timstamp function.
Change-Id: I5de0042e7b9473337960e5c65b3b29ee750f423b
Signed-off-by: Kwanghoon Son <k.son@samsung.com>
} 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);
+int mv_source_set_timestamp(mv_source_h source, da_timestamp_s *stamp);
#endif
auto depthData = handle->mDfsAdaptor->getOutputData();
auto leftData = handle->mDfsAdaptor->getLeftData();
-#ifdef WITH_DA_PROFILE
- int ret = mv_source_fill_by_buffer_da(
- handle->mInternalSource, static_cast<unsigned char *>(leftData.data), leftData.stride * leftData.height,
- leftData.width, leftData.height, leftData.stride,
- leftData.type == DFS_DATA_TYPE_UINT8C3 ? MEDIA_VISION_COLORSPACE_RGB888 : MEDIA_VISION_COLORSPACE_Y800,
- static_cast<da_timestamp_s *>(pInput->timestamp));
-#else
+
int ret = mv_source_fill_by_buffer(handle->mInternalSource, static_cast<unsigned char *>(leftData.data),
leftData.stride * leftData.height, leftData.width, leftData.height,
leftData.type == DFS_DATA_TYPE_UINT8C3 ? MEDIA_VISION_COLORSPACE_RGB888 :
MEDIA_VISION_COLORSPACE_Y800);
+#ifdef WITH_DA_PROFILE
+ ret = mv_source_set_timestamp(handle->mInternalSource, static_cast<da_timestamp_s *>(pInput->timestamp));
+
#endif
if (MEDIA_VISION_ERROR_NONE != ret) {
LOGW("Errors were occurred during source filling %i", ret);
#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);
+ void setTimeStamp(da_timestamp_s &stamp);
#endif
/**
#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);
+int mv_source_set_timestamp_c(mv_source_h source, da_timestamp_s *stamp);
#endif
/**
{
return _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)
+void MediaSource::setTimeStamp(da_timestamp_s &stamp)
{
- if (!buffer || bufferSize == 0)
- return false;
-
- LOGD("Call clear() first for media source %p", this);
- clear();
-
- Plane plane;
- auto &pBuffer = plane.buffer;
- auto &pImageSize = plane.imageSize;
-
- 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);
- pBuffer = new (std::nothrow) unsigned char[bufferSize];
- if (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, pBuffer, this);
- for (unsigned h = 0; h < height; h++) {
- std::memcpy(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);
- pImageSize = bufferSize;
-
- LOGD("Assign new size (%ui x %ui) of the internal buffer image for "
- "the media source %p",
- width, height, this);
- _width = width;
- _height = height;
-
- LOGD("Assign new colorspace (%i) of the internal buffer image for "
- "the media source %p",
- colorspace, this);
- _colorspace = colorspace;
_stamp = stamp;
-
- return true;
}
+
#endif
unsigned char *MediaSource::getBuffer(void) const
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)
+int mv_source_set_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_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);
+ int ret = mv_source_set_timestamp_c(source, stamp);
MEDIA_VISION_FUNCTION_LEAVE();
return ret;
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);
+ auto mediaSource = static_cast<MediaVision::Common::MediaSource *>(source);
*stamp = mediaSource->getTimeStamp();
} catch (const std::exception &e) {
LOGE("%s", e.what());
}
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)
+int mv_source_set_timestamp_c(mv_source_h source, 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;
+ try {
+ auto mediaSource = static_cast<MediaVision::Common::MediaSource *>(source);
+ mediaSource->setTimeStamp(*stamp);
+ } catch (const std::exception &e) {
+ LOGE("%s", e.what());
+ return MEDIA_VISION_ERROR_INTERNAL;
}
-
- LOGD("Media source has been filled from buffer");
return MEDIA_VISION_ERROR_NONE;
}
#endif
TEST(Common_DA, Simple)
{
mv_source_h mv_source;
- unsigned char fake_data[10];
- da_timestamp_s fake_stamp;
+ da_timestamp_s fake_stamp { 1, 2, 3, 4, 5 };
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);
+ EXPECT_EQ(mv_source_set_timestamp(mv_source, nullptr), MEDIA_VISION_ERROR_INVALID_PARAMETER);
+ EXPECT_EQ(mv_source_set_timestamp(mv_source, &fake_stamp), VISION_SOURCE_ERROR_NONE);
+ fake_stamp.timestamp = -1;
+ EXPECT_EQ(mv_source_get_timestamp(mv_source, &fake_stamp), VISION_SOURCE_ERROR_NONE);
+ EXPECT_EQ(fake_stamp.timestamp, 1);
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
printf("_vision_source_cb: %lld ms\n", static_cast<long long int>(app->stopWatch.elapsedTime().count()));
-#ifdef WITH_DA_PROFILE
- mv_source_fill_by_buffer_da(app->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,
- static_cast<da_timestamp_s *>(buffer->priv));
-#else
for (unsigned int h = 0; h < buffer->resolution.height; h++) {
memcpy(app->buffer + buffer->resolution.width * h, buffer->planes[0].data + (buffer->planes[0].align_width * h),
buffer->resolution.width);
}
mv_source_fill_by_buffer(app->mv_source, app->buffer, app->imgWidth * app->imgHeight, app->imgWidth, app->imgHeight,
MEDIA_VISION_COLORSPACE_Y800);
+#ifdef WITH_DA_PROFILE
+ mv_source_set_timestamp(app->mv_source, static_cast<da_timestamp_s *>(buffer->priv));
#endif
if (isAsync)