NVIDIA DeepStream SDK API Reference

7.1 Release
gst-nvdstexttospeech/includes/nvdscustomlib_factory.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: LicenseRef-NvidiaProprietary
4  *
5  * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
6  * property and proprietary rights in and to this material, related
7  * documentation and any modifications thereto. Any use, reproduction,
8  * disclosure or distribution of this material and related documentation
9  * without an express license agreement from NVIDIA CORPORATION or
10  * its affiliates is strictly prohibited.
11  */
12 
13 #ifndef __NVDS_TTS_CUSTOMLIB_FACTORY_HPP__
14 #define __NVDS_TTS_CUSTOMLIB_FACTORY_HPP__
15 
16 #include <dlfcn.h>
17 #include <errno.h>
18 
19 #include <functional>
20 #include <iostream>
21 
23 
24 namespace nvdstts {
25 
26 template <class T>
27 T*
28 dlsym_ptr(void* handle, char const* name)
29 {
30  return reinterpret_cast<T*>(dlsym(handle, name));
31 }
32 
34 public:
35  DSCustomLibrary_Factory() = default;
36 
38  {
39  if (m_libHandle) {
40  dlclose(m_libHandle);
41  }
42  }
43 
45  const std::string& libName, const std::string& symName)
46  {
47  m_libName.assign(libName);
48 
49  // Usiing RTLD_GLOBAL to avoid libprotobuf.so 'file already exists in
50  // database' error when using common .proto file in two plugins.
51  // For e.g. riva_audio.proto in Riva ASR and TTS services.
52  m_libHandle = dlopen(m_libName.c_str(), RTLD_NOW | RTLD_GLOBAL);
53  if (m_libHandle) {
54  std::cout << "Library Opened Successfully" << std::endl;
55 
57  dlsym_ptr<IDSCustomLibrary*()>(m_libHandle, symName.c_str());
58  if (!m_CreateAlgoCtx) {
59  throw std::runtime_error(
60  "createCustomAlgoCtx function not found in library");
61  }
62  } else {
63  throw std::runtime_error(dlerror());
64  }
65 
66  return m_CreateAlgoCtx();
67  }
68 
69 public:
70  void* m_libHandle;
71  std::string m_libName;
72  std::function<IDSCustomLibrary*()> m_CreateAlgoCtx;
73 };
74 
75 } // namespace nvdstts
76 
77 #endif
nvdstts::IDSCustomLibrary
Definition: gst-nvdstexttospeech/includes/nvdscustomlib_interface.hpp:54
nvdstts::DSCustomLibrary_Factory::~DSCustomLibrary_Factory
~DSCustomLibrary_Factory()
Definition: gst-nvdstexttospeech/includes/nvdscustomlib_factory.h:37
nvdstts::DSCustomLibrary_Factory
Definition: gst-nvdstexttospeech/includes/nvdscustomlib_factory.h:33
nvdstts::dlsym_ptr
T * dlsym_ptr(void *handle, char const *name)
Definition: gst-nvdstexttospeech/includes/nvdscustomlib_factory.h:28
nvdscustomlib_interface.hpp
nvdstts::DSCustomLibrary_Factory::DSCustomLibrary_Factory
DSCustomLibrary_Factory()=default
nvdstts
Definition: gst-nvdstexttospeech/includes/nvdscustomlib_factory.h:24
nvdstts::DSCustomLibrary_Factory::CreateCustomAlgoCtx
IDSCustomLibrary * CreateCustomAlgoCtx(const std::string &libName, const std::string &symName)
Definition: gst-nvdstexttospeech/includes/nvdscustomlib_factory.h:44
nvdstts::DSCustomLibrary_Factory::m_libName
std::string m_libName
Definition: gst-nvdstexttospeech/includes/nvdscustomlib_factory.h:71
nvdstts::DSCustomLibrary_Factory::m_libHandle
void * m_libHandle
Definition: gst-nvdstexttospeech/includes/nvdscustomlib_factory.h:70
nvdstts::DSCustomLibrary_Factory::m_CreateAlgoCtx
std::function< IDSCustomLibrary *()> m_CreateAlgoCtx
Definition: gst-nvdstexttospeech/includes/nvdscustomlib_factory.h:72