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 [moved from packaging/dfs_adaptation.spec with 94% similarity]
src/dfs_adaptation_impl.cpp

index 647e55a..b3b553a 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 cc3af2a..64c67a3 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 cc78d1a..89dbd3e 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
similarity index 94%
rename from packaging/dfs_adaptation.spec
rename to packaging/dfs-adaptation.spec
index 619fd7e..db167ff 100644 (file)
@@ -1,6 +1,6 @@
 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
@@ -8,6 +8,7 @@ Source0:     %{name}-%{version}.tar.gz
 BuildRequires: cmake
 BuildRequires: pkgconfig(dlog)
 BuildRequires: pkgconfig(libtzplatform-config)
+BuildRequires: pkgconfig(iniparser)
 
 %description
 Adaptaion of depth-from-stereo
@@ -54,4 +55,4 @@ rm -rf %{buildroot}
 %files devel
 %{_includedir}/media/*.h
 %{_libdir}/pkgconfig/dfs*.pc
-%{_libdir}/libdfs-*.so
\ No newline at end of file
+%{_libdir}/libdfs-*.so
index d3e3db4..c16b637 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