NVIDIA DeepStream SDK API Reference

7.1 Release
nvdspostprocesslib_factory.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23 
24 #ifndef __NVDSPOSTPROCESSLIB_FACTORY_HPP__
25 #define __NVDSPOSTPROCESSLIB_FACTORY_HPP__
26 
27 #include <dlfcn.h>
28 #include <errno.h>
29 
30 #include <iostream>
31 #include <functional>
32 
34 
35 template<class T>
36 T* dlsym_ptr(void* handle, char const* name) {
37  return reinterpret_cast<T*>(dlsym(handle, name));
38 }
39 
41 {
42 public:
44  {
45  }
46 
48  {
49  if (m_libHandle)
50  {
51  dlclose(m_libHandle);
52  m_libHandle = NULL;
53  m_libName.clear();
54  }
55  }
56 
58  {
59  m_libName.assign(libName);
60 
61  m_libHandle = dlopen(m_libName.c_str(), RTLD_NOW);
62  if (m_libHandle)
63  {
64  m_CreateAlgoCtx = dlsym_ptr<IDSPostProcessLibrary*(DSPostProcess_CreateParams*)>(m_libHandle, "CreateCustomAlgoCtx");
65  if (!m_CreateAlgoCtx)
66  {
67  std::cout << "CreateCustomAlgoCtx function not found in library\n";
68  return nullptr;
69  }
70  }
71  else
72  {
73  // throw std::runtime_error(dlerror());
74  std::cout << dlerror() << std::endl;
75  return nullptr;
76  }
78  }
79 
80 public:
81  void *m_libHandle;
82  std::string m_libName;
84 };
85 
86 #endif
DSPostProcessLibrary_Factory::CreateCustomAlgoCtx
IDSPostProcessLibrary * CreateCustomAlgoCtx(std::string libName, DSPostProcess_CreateParams *params)
Definition: nvdspostprocesslib_factory.hpp:57
IDSPostProcessLibrary
Definition: nvdspostprocesslib_interface.hpp:54
DSPostProcessLibrary_Factory::m_CreateAlgoCtx
std::function< IDSPostProcessLibrary *(DSPostProcess_CreateParams *)> m_CreateAlgoCtx
Definition: nvdspostprocesslib_factory.hpp:83
DSPostProcessLibrary_Factory::~DSPostProcessLibrary_Factory
~DSPostProcessLibrary_Factory()
Definition: nvdspostprocesslib_factory.hpp:47
DSPostProcessLibrary_Factory::m_libHandle
void * m_libHandle
Definition: nvdspostprocesslib_factory.hpp:81
DSPostProcessLibrary_Factory::m_libName
std::string m_libName
Definition: nvdspostprocesslib_factory.hpp:82
DSPostProcessLibrary_Factory
Definition: nvdspostprocesslib_factory.hpp:40
DSPostProcess_CreateParams
Definition: nvdspostprocesslib_interface.hpp:37
nvdspostprocesslib_interface.hpp
dlsym_ptr
T * dlsym_ptr(void *handle, char const *name)
Definition: nvdspostprocesslib_factory.hpp:36
DSPostProcessLibrary_Factory::DSPostProcessLibrary_Factory
DSPostProcessLibrary_Factory()
Definition: nvdspostprocesslib_factory.hpp:43