{
namespace mv3d
{
+static void __destroyNotifyCb(gpointer data)
+{
+ if (!data)
+ return;
+
+ LOGW("Cleanup remained DfsInputData (%p)", data);
+ auto remained = static_cast<DfsInputData *>(data);
+
+ delete[] static_cast<unsigned char *>(remained->data);
+ delete[] static_cast<unsigned char *>(remained->extraData);
+
+ delete remained;
+}
+
Mv3d::Mv3d()
: mDfsParameter()
, mDfsAdaptor(nullptr)
}
if (mDfsAsyncQueue) {
- gpointer base = nullptr;
- while ((base = g_async_queue_try_pop(mDfsAsyncQueue))) {
- auto pItem = static_cast<std::shared_ptr<DfsInputData> *>(base);
- auto item = std::move(*pItem);
- delete pItem;
- item.reset();
- }
g_async_queue_unref(mDfsAsyncQueue);
}
{
try {
if (!mDfsAsyncQueue) {
- mDfsAsyncQueue = g_async_queue_new();
+ mDfsAsyncQueue = g_async_queue_new_full(__destroyNotifyCb);
if (!mDfsAsyncQueue) {
LOGE("Fail to g_async_queue_new()");
return MEDIA_VISION_ERROR_INTERNAL;
mDfsIsLive = true;
}
- std::shared_ptr<DfsInputData> input(new DfsInputData);
+ auto input = std::make_unique<DfsInputData>();
GetDfsDataFromSources(baseSource, extraSource, *input);
if (!mInternalSource) {
int ret = mv_create_source(&mInternalSource);
return MEDIA_VISION_ERROR_INTERNAL;
}
}
- g_async_queue_push(mDfsAsyncQueue, static_cast<void *>(new std::shared_ptr<DfsInputData>(std::move(input))));
+ g_async_queue_push(mDfsAsyncQueue, static_cast<gpointer>(input.release()));
} catch (const std::exception &e) {
LOGE("Failed to Run with %s", e.what());
return MEDIA_VISION_ERROR_INVALID_OPERATION;
gpointer Mv3d::DfsThreadLoop(gpointer data)
{
- Mv3d *handle = static_cast<Mv3d *>(data);
+ auto handle = static_cast<Mv3d *>(data);
while (handle->mDfsIsLive) {
auto base = g_async_queue_timeout_pop(handle->mDfsAsyncQueue, MV_3D_TIMEOUT_SEC * G_TIME_SPAN_SECOND);
if (!base) {
break;
}
- auto queueRemaining = static_cast<int>(g_async_queue_length(handle->mDfsAsyncQueue));
+ auto queueRemaining = g_async_queue_length(handle->mDfsAsyncQueue);
LOGI("%d remaining", queueRemaining);
while (queueRemaining > 0) {
- auto pItem = static_cast<std::shared_ptr<DfsInputData> *>(base);
- auto item = std::move(*pItem);
- delete pItem;
- item.reset();
+ auto itemToDelete = static_cast<DfsInputData *>(base);
+ delete[] static_cast<unsigned char *>(itemToDelete->data);
+ delete[] static_cast<unsigned char *>(itemToDelete->extraData);
+ delete itemToDelete;
- gpointer base = g_async_queue_pop(handle->mDfsAsyncQueue);
+ base = g_async_queue_pop(handle->mDfsAsyncQueue);
queueRemaining--;
LOGI("%d remaining", queueRemaining);
}
- auto pInput = static_cast<std::shared_ptr<DfsInputData> *>(base);
- auto input = std::move(*pInput);
- delete pInput;
- handle->mDfsAdaptor->run(*input);
+ std::unique_ptr<DfsInputData> pInput(static_cast<DfsInputData *>(base));
+ handle->mDfsAdaptor->run(*pInput);
auto depthData = handle->mDfsAdaptor->getOutputData();
auto leftData = handle->mDfsAdaptor->getLeftData();
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);
+ MEDIA_VISION_COLORSPACE_Y800);
if (MEDIA_VISION_ERROR_NONE != ret) {
LOGW("Errors were occurred during source filling %i", ret);
continue;
//mPointcloudThread = g_thread_new("pointcloud_thread",
// &Mv3d::PointcloudThreadLoop,
// static_cast<gpointer>(this));
- handle->GetPointcloudFromSource(*input, depthData, p);
+ handle->GetPointcloudFromSource(*pInput, depthData, p);
mv_3d_pointcloud_h pcd = &p;
handle->mPointcloudCallback(static_cast<mv_source_h>(handle->mInternalSource), pcd,
delete _pcd;
}
#endif
- delete[] static_cast<unsigned char *>(input->data);
- delete[] static_cast<unsigned char *>(input->extraData);
+ delete[] static_cast<unsigned char *>(pInput->data);
+ delete[] static_cast<unsigned char *>(pInput->extraData);
mv_source_clear(handle->mInternalSource);
- input.reset();
}
return nullptr;