From: 정태영/Tizen Platform Lab(SR)/Staff Engineer/삼성전자 Date: Fri, 3 Dec 2021 04:50:50 +0000 (+0900) Subject: Release 1.0.0 (#1) X-Git-Tag: accepted/tizen/unified/20220701.055248~1^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e5d0a566524cc5b6164d4c89e7a5c20cbdd1ebed;p=platform%2Fcore%2Fmultimedia%2Fdfs-adaptation.git Release 1.0.0 (#1) * Add Bind()/Unbind() which binds and unbinds dfs-opencv Signed-off-by: Tae-Young Chung * Add Initialize() Initialize() initialize an adaptor with parameters. Signed-off-by: Tae-Young Chung * Add DepthParameter structure DepthParameter provides essential parameters for dfs. All plugins should provide the parameters as default. Signed-off-by: Tae-Young Chung * add Run() and GetDepthData() Signed-off-by: Tae-Young Chung * 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 * add error handling if Initialize() fails Signed-off-by: Tae-Young Chung * Add width and height parameters to Initialized()'s input parameters Signed-off-by: Tae-Young Chung * Add parameters of minimun and maximum disparities to Initialize() Signed-off-by: Tae-Young Chung * 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 * Fix erratum Signed-off-by: Tae-Young Chung * Release 1.0.0 [Version]: 1.0.0 [Issue type]: new feature Signed-off-by: Tae-Young Chung * 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 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 647e55a..b3b553a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/include/dfs_adaptation.h b/include/dfs_adaptation.h index cc3af2a..64c67a3 100644 --- a/include/dfs_adaptation.h +++ b/include/dfs_adaptation.h @@ -15,12 +15,14 @@ */ #ifndef __DFS_ADAPTATION_H__ -#define __DFS_ADAPTITION_H__ +#define __DFS_ADAPTATION_H__ #include #include #include +#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__ */ diff --git a/include/dfs_adaptation_impl.h b/include/dfs_adaptation_impl.h index cc78d1a..89dbd3e 100644 --- a/include/dfs_adaptation_impl.h +++ b/include/dfs_adaptation_impl.h @@ -15,23 +15,32 @@ */ #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 index 0000000..2f76033 --- /dev/null +++ b/include/dfs_parameter.h @@ -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 +/** + * @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 similarity index 94% rename from packaging/dfs_adaptation.spec rename to packaging/dfs-adaptation.spec index 619fd7e..db167ff 100644 --- a/packaging/dfs_adaptation.spec +++ b/packaging/dfs-adaptation.spec @@ -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 diff --git a/src/dfs_adaptation_impl.cpp b/src/dfs_adaptation_impl.cpp index d3e3db4..c16b637 100644 --- a/src/dfs_adaptation_impl.cpp +++ b/src/dfs_adaptation_impl.cpp @@ -14,6 +14,9 @@ * limitations under the License. */ +#include +#include +#include #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