Release 1.0.0 (#1)
author정태영/Tizen Platform Lab(SR)/Staff Engineer/삼성전자 <ty83.chung@samsung.com>
Fri, 3 Dec 2021 04:50:50 +0000 (13:50 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Fri, 3 Dec 2021 04:50:50 +0000 (13:50 +0900)
* Add Bind()/Unbind() which binds and unbinds dfs-opencv

Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
* Add Initialize()

Initialize() initialize an adaptor with parameters.

Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
* Add DepthParameter structure

DepthParameter provides essential parameters for dfs.
All plugins should provide the parameters as default.

Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
* add Run() and GetDepthData()

Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
* Change to bind adaptor which is defined at ini file path

Whenever run mv_depth_* apis dfs-adaptation loads backend_path.ini
and then tries to bind the adaptor defined in it.

Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
* add error handling if Initialize() fails

Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
* Add width and height parameters to Initialized()'s input parameters

Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
* Add parameters of minimun and maximum disparities to Initialize()

Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
* Change enumeration and add new type

To support various types, change the enumeration
from DFS_DATA_TYPE_UINT8 to DFS_DATA_TYPE_UINT8C1
which indicates unsinged integer 8 bits with 1 channel.
Add DFS_DATA_TYPE_UINT8C3.

Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
* Fix erratum

Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
* Release 1.0.0

[Version]: 1.0.0
[Issue type]: new feature

Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
* Check return of dlsym and clear old error conditions

dlsym can return NULL but not error. So code to check return of dlsym
is added. dlerror() can clear old error conditions. So call dlerror() before
dlsym() and call dlerror() again to get errors.
In addition, remove unnecessary try-catch in DfsAdaptor::Initialize() method.

Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
CMakeLists.txt
include/dfs_adaptation.h
include/dfs_adaptation_impl.h
include/dfs_parameter.h [new file with mode: 0644]
packaging/dfs-adaptation.spec [new file with mode: 0644]
packaging/dfs_adaptation.spec [deleted file]
src/dfs_adaptation_impl.cpp

index 647e55aac4a2140d718174419aea4a76ed2ecdb1..b3b553ad76167dde99ac69fa526e2c44ad025703 100644 (file)
@@ -9,7 +9,7 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX})
 
 SET(INC_DIR "${PROJECT_SOURCE_DIR}/include")
 
-SET(dependents "dlog")
+SET(dependents "dlog iniparser")
 INCLUDE(FindPkgConfig)
 
 pkg_check_modules(${fw_name} REQUIRED ${dependents})
@@ -32,7 +32,7 @@ SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}")
 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
index cc3af2af543da19eaa0c44cc516896fccf4b4ac0..64c67a39b6ba672bcb1e89f936fb4c8ca00e6c1b 100644 (file)
  */
 
 #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
@@ -28,10 +30,31 @@ namespace DfsAdaptation
        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__ */
index cc78d1aa558e03839c5c111f3ecd186527b3023d..89dbd3e42701367ca754de63a4376e48c339c99a 100644 (file)
  */
 
 #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_ */
diff --git a/include/dfs_parameter.h b/include/dfs_parameter.h
new file mode 100644 (file)
index 0000000..2f76033
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * 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
diff --git a/packaging/dfs-adaptation.spec b/packaging/dfs-adaptation.spec
new file mode 100644 (file)
index 0000000..db167ff
--- /dev/null
@@ -0,0 +1,58 @@
+Name:        dfs-adaptation
+Summary:     Adaptation of depth-from-stereo
+Version:     1.0.0
+Release:     0
+Group:       Multimedia/Framework
+License:     Apache-2.0
+Source0:     %{name}-%{version}.tar.gz
+BuildRequires: cmake
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(libtzplatform-config)
+BuildRequires: pkgconfig(iniparser)
+
+%description
+Adaptaion of depth-from-stereo
+
+%package devel
+Summary:    Adaptaion of depth-from-stereo
+Group:      Multimedia/Framework
+Requires:   %{name} = %{version}-%{release}
+
+%description devel
+Adaptaion of depth-from-stereo (Dev)
+
+%prep
+%setup -q
+
+%build
+%if 0%{?sec_build_binary_debug_enable}
+export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE"
+export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE"
+export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE"
+%endif
+
+export CFLAGS+=" -DPATH_LIBDIR=\\\"%{_libdir}\\\" -DSYSCONFDIR=\\\"%{_hal_sysconfdir}\\\""
+export CXXFLAGS+=" -DPATH_LIBDIR=\\\"%{_libdir}\\\" -DSYSCONFDIR=\\\"%{_hal_sysconfdir}\\\""
+
+MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
+%cmake . -DFULLVER=%{version} -DMAJORVER=${MAJORVER} -DTZ_SYS_BIN=%TZ_SYS_BIN \
+
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+
+%make_install
+
+%post -p /sbin/ldconfig
+%postun -p /sbin/ldconfig
+
+%files
+%manifest %{name}.manifest
+%license LICENSE.APLv2
+%{_libdir}/libdfs-*.so.*
+
+%files devel
+%{_includedir}/media/*.h
+%{_libdir}/pkgconfig/dfs*.pc
+%{_libdir}/libdfs-*.so
diff --git a/packaging/dfs_adaptation.spec b/packaging/dfs_adaptation.spec
deleted file mode 100644 (file)
index 619fd7e..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-Name:        dfs-adaptation
-Summary:     Adaptation of depth-from-stereo
-Version:     0.0.1
-Release:     0
-Group:       Multimedia/Framework
-License:     Apache-2.0
-Source0:     %{name}-%{version}.tar.gz
-BuildRequires: cmake
-BuildRequires: pkgconfig(dlog)
-BuildRequires: pkgconfig(libtzplatform-config)
-
-%description
-Adaptaion of depth-from-stereo
-
-%package devel
-Summary:    Adaptaion of depth-from-stereo
-Group:      Multimedia/Framework
-Requires:   %{name} = %{version}-%{release}
-
-%description devel
-Adaptaion of depth-from-stereo (Dev)
-
-%prep
-%setup -q
-
-%build
-%if 0%{?sec_build_binary_debug_enable}
-export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE"
-export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE"
-export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE"
-%endif
-
-export CFLAGS+=" -DPATH_LIBDIR=\\\"%{_libdir}\\\" -DSYSCONFDIR=\\\"%{_hal_sysconfdir}\\\""
-export CXXFLAGS+=" -DPATH_LIBDIR=\\\"%{_libdir}\\\" -DSYSCONFDIR=\\\"%{_hal_sysconfdir}\\\""
-
-MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
-%cmake . -DFULLVER=%{version} -DMAJORVER=${MAJORVER} -DTZ_SYS_BIN=%TZ_SYS_BIN \
-
-make %{?jobs:-j%jobs}
-
-%install
-rm -rf %{buildroot}
-
-%make_install
-
-%post -p /sbin/ldconfig
-%postun -p /sbin/ldconfig
-
-%files
-%manifest %{name}.manifest
-%license LICENSE.APLv2
-%{_libdir}/libdfs-*.so.*
-
-%files devel
-%{_includedir}/media/*.h
-%{_libdir}/pkgconfig/dfs*.pc
-%{_libdir}/libdfs-*.so
\ No newline at end of file
index d3e3db4a2b4b155d99215a688c128976455724d5..c16b6375d35faa6759507853505188f9dcfab005 100644 (file)
@@ -14,6 +14,9 @@
  * limitations under the License.
  */
 
+#include <dlfcn.h>
+#include <iniparser.h>
+#include <string.h>
 #include "dfs_adaptation_impl.h"
 
 extern "C"
@@ -27,10 +30,19 @@ 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");
@@ -41,4 +53,100 @@ namespace DfsAdaptation
                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