SET(INC_DIR "${PROJECT_SOURCE_DIR}/include")
-SET(dependents "dlog")
+SET(dependents "dlog iniparser")
INCLUDE(FindPkgConfig)
pkg_check_modules(${fw_name} REQUIRED ${dependents})
aux_source_directory(src SOURCES)
ADD_LIBRARY(${fw_name} SHARED ${SOURCES})
-TARGET_LINK_LIBRARIES(${fw_name} dlog stdc++fs)
+TARGET_LINK_LIBRARIES(${fw_name} dlog iniparser stdc++fs)
SET_TARGET_PROPERTIES(${fw_name}
PROPERTIES
*/
#ifndef __DFS_ADAPTATION_H__
-#define __DFS_ADAPTITION_H__
+#define __DFS_ADAPTATION_H__
#include <map>
#include <vector>
#include <string>
+#include "dfs_parameter.h"
+
namespace DfsAdaptation
{
class IDfsAdaptation
public:
virtual ~IDfsAdaptation() {};
+ /**
+ * @brief Initialize dfs adaptor.
+ * @since_tizen 7.0
+ */
+ virtual void Initialize(DfsParameter& param,
+ size_t width,
+ size_t height,
+ size_t minDisp,
+ size_t maxDisp) = 0;
+
+ /**
+ * @brief Run dfs adaptor.
+ * @since_tizen 7.0
+ */
+ virtual void Run(DfsData& base, DfsData& extra) = 0;
+
+ /**
+ * @brief Run dfs adaptor.
+ * @since_tizen 7.0
+ */
+ virtual DfsData& GetDepthData() = 0;
};
typedef void destroy_t(IDfsAdaptation *);
typedef IDfsAdaptation *init_t(void);
-} /* InferenceEngineInterface */
+} /* DfsAdaptation */
#endif /* __DFS_ADAPTATION_H__ */
*/
#ifndef __DFS_ADAPTATION_IMPL_H__
-#define __DFS_ADAPTITION_IMPL_H_
+#define __DFS_ADAPTATION_IMPL_H_
#include "dfs_adaptation.h"
+#include "dfs_parameter.h"
namespace DfsAdaptation
{
class DfsAdaptor
{
private:
- IDfsAdaptation *mDfsAdaptor;
+ void *mDfsAdaptor;
+ IDfsAdaptation *mDfsAdaptorHandle;
public:
DfsAdaptor();
~DfsAdaptor();
- };
+ void Bind();
+ void Unbind();
+
+ void Initialize(DfsParameter& param, size_t width, size_t height,
+ size_t minDisp, size_t maxDisp);
+ void Run(DfsData& base, DfsData& extra);
+ DfsData& GetDepthData();
+ };
} /* DfsAdaptation */
-#endif /* __DFS_ADAPTITION_IMPL_H_ */
+#endif /* __DFS_ADAPTATION_IMPL_H_ */
--- /dev/null
+/*
+ * Copyright (c) 2021 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 __DFS_PARAMETER_H__
+#define __DFS_PARAMETER_H__
+
+#include <cstddef>
+/**
+ * @file dfs_parameter.h
+ * @brief This file contains the depth parameter structure.
+ */
+
+namespace DfsAdaptation
+{
+ struct DfsParameter {
+ double textureThreshold;
+ size_t aggregationWindowWidth;
+ size_t aggregationWindowHeight;
+ size_t maxSpeckleSize;
+
+ DfsParameter()
+ {
+ textureThreshold = 1;
+ aggregationWindowWidth = 10;
+ aggregationWindowWidth = 10;
+ maxSpeckleSize = 10;
+ }
+ };
+
+ struct DfsData {
+ void *data;
+ int type;
+ size_t width;
+ size_t height;
+ size_t stride;
+
+ DfsData()
+ {
+ data = nullptr;
+ type = 0;
+ width = height = stride = 0;
+ }
+ };
+
+ enum
+ {
+ DFS_DATA_TYPE_UINT8C1 = 1,
+ DFS_DATA_TYPE_UINT8C3 = 2,
+ };
+
+}
+#endif /* __DFS_PARAMETER_H__ */
\ No newline at end of file
Name: dfs-adaptation
Summary: Adaptation of depth-from-stereo
-Version: 0.0.1
+Version: 1.0.0
Release: 0
Group: Multimedia/Framework
License: Apache-2.0
BuildRequires: cmake
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(libtzplatform-config)
+BuildRequires: pkgconfig(iniparser)
%description
Adaptaion of depth-from-stereo
%files devel
%{_includedir}/media/*.h
%{_libdir}/pkgconfig/dfs*.pc
-%{_libdir}/libdfs-*.so
\ No newline at end of file
+%{_libdir}/libdfs-*.so
* limitations under the License.
*/
+#include <dlfcn.h>
+#include <iniparser.h>
+#include <string.h>
#include "dfs_adaptation_impl.h"
extern "C"
#define LOG_TAG "DFS_ADAPTATION"
}
+#define CHECK_INSTANCE(object) \
+ if (object == nullptr) { \
+ throw std::invalid_argument("handle is null"); \
+ }
+
namespace DfsAdaptation
{
+ const char *BACKEND_PATH_INI_FILENAME =
+ SYSCONFDIR"/vision/depth/backend_path.ini";
+
DfsAdaptor::DfsAdaptor() :
- mDfsAdaptor(nullptr)
+ mDfsAdaptor(nullptr),
+ mDfsAdaptorHandle(nullptr)
{
LOGI("ENTER");
LOGI("LEAVE");
LOGI("ENTER");
LOGI("LEAVE");
}
+
+
+ void DfsAdaptor::Bind()
+ {
+ LOGI("ENTER");
+
+ dictionary *dict = iniparser_load(BACKEND_PATH_INI_FILENAME);
+ if (!dict) {
+ throw std::invalid_argument("invalid backend path ini");
+ }
+
+ std::string adaptorName = std::string(iniparser_getstring(dict, "DFS backend:type", NULL));
+ iniparser_freedict(dict);
+
+ if (adaptorName.empty()) {
+ throw std::runtime_error("not supported dfs backend");
+ }
+
+ std::string adaptorLibName = "libdfs-" + adaptorName + ".so";
+
+ mDfsAdaptor = dlopen(adaptorLibName.c_str(), RTLD_NOW);
+ LOGI("%s DfsAdaptor: %p", adaptorLibName.c_str(), mDfsAdaptor);
+
+ if (!mDfsAdaptor) {
+ LOGE("Failed to open %s: %s", adaptorLibName.c_str(), dlerror());
+ throw std::runtime_error(adaptorLibName.c_str());
+ }
+
+ dlerror(); /* clear any old error conditions */
+ init_t *AdaptorInit = (init_t*)dlsym(mDfsAdaptor, "AdaptorInit");
+ char *error = dlerror();
+ if (error || !AdaptorInit) {
+ LOGE("dlsym returns %p and error %s", AdaptorInit, error ? error : "none");
+ dlclose(mDfsAdaptor);
+ mDfsAdaptor = nullptr;
+ throw std::runtime_error(adaptorLibName.c_str());
+ }
+
+ mDfsAdaptorHandle = AdaptorInit();
+ if (!mDfsAdaptorHandle) {
+ LOGE("Failed to AdaptorInit");
+ dlclose(mDfsAdaptor);
+ mDfsAdaptor = nullptr;
+ throw std::runtime_error(adaptorLibName.c_str());
+ }
+
+ LOGI("LEAVE");
+ }
+
+ void DfsAdaptor::Unbind()
+ {
+ LOGI("ENTER");
+
+ if (mDfsAdaptor) {
+ destroy_t *adaptorDestroy = (destroy_t*)dlsym(mDfsAdaptor, "AdaptorDestroy");
+ adaptorDestroy(mDfsAdaptorHandle);
+ dlclose(mDfsAdaptor);
+ mDfsAdaptor = mDfsAdaptorHandle = nullptr;
+ }
+
+ LOGI("LEAVE");
+ }
+
+ void DfsAdaptor::Initialize(DfsParameter& param, size_t width, size_t height,
+ size_t minDisp, size_t maxDisp)
+ {
+ LOGI("ENTER");
+
+ CHECK_INSTANCE(mDfsAdaptorHandle);
+
+ mDfsAdaptorHandle->Initialize(param, width, height, minDisp, maxDisp);
+
+ LOGI("LEAVE");
+ }
+
+ void DfsAdaptor::Run(DfsData& base, DfsData& extra)
+ {
+ LOGI("ENTER");
+
+ CHECK_INSTANCE(mDfsAdaptorHandle);
+
+ mDfsAdaptorHandle->Run(base, extra);
+
+ LOGI("LEAVE");
+ }
+
+ DfsData& DfsAdaptor::GetDepthData()
+ {
+ LOGI("ENTER");
+
+ CHECK_INSTANCE(mDfsAdaptorHandle);
+
+ return mDfsAdaptorHandle->GetDepthData();
+
+ LOGI("LEAVE");
+ }
}
\ No newline at end of file