NVIDIA DeepStream SDK API Reference

6.4 Release
gst-nvdstexttospeech/includes/nvdscustomlib_factory.h
Go to the documentation of this file.
1 
23 #ifndef __NVDS_TTS_CUSTOMLIB_FACTORY_HPP__
24 #define __NVDS_TTS_CUSTOMLIB_FACTORY_HPP__
25 
26 #include <dlfcn.h>
27 #include <errno.h>
28 
29 #include <functional>
30 #include <iostream>
31 
33 
34 namespace nvdstts {
35 
36 template <class T>
37 T*
38 dlsym_ptr(void* handle, char const* name)
39 {
40  return reinterpret_cast<T*>(dlsym(handle, name));
41 }
42 
44 public:
45  DSCustomLibrary_Factory() = default;
46 
48  {
49  if (m_libHandle) {
50  dlclose(m_libHandle);
51  }
52  }
53 
55  const std::string& libName, const std::string& symName)
56  {
57  m_libName.assign(libName);
58 
59  // Usiing RTLD_GLOBAL to avoid libprotobuf.so 'file already exists in
60  // database' error when using common .proto file in two plugins.
61  // For e.g. riva_audio.proto in Riva ASR and TTS services.
62  m_libHandle = dlopen(m_libName.c_str(), RTLD_NOW | RTLD_GLOBAL);
63  if (m_libHandle) {
64  std::cout << "Library Opened Successfully" << std::endl;
65 
67  dlsym_ptr<IDSCustomLibrary*()>(m_libHandle, symName.c_str());
68  if (!m_CreateAlgoCtx) {
69  throw std::runtime_error(
70  "createCustomAlgoCtx function not found in library");
71  }
72  } else {
73  throw std::runtime_error(dlerror());
74  }
75 
76  return m_CreateAlgoCtx();
77  }
78 
79 public:
80  void* m_libHandle;
81  std::string m_libName;
82  std::function<IDSCustomLibrary*()> m_CreateAlgoCtx;
83 };
84 
85 } // namespace nvdstts
86 
87 #endif
nvdstts::IDSCustomLibrary
Definition: gst-nvdstexttospeech/includes/nvdscustomlib_interface.hpp:64
nvdstts::DSCustomLibrary_Factory::~DSCustomLibrary_Factory
~DSCustomLibrary_Factory()
Definition: gst-nvdstexttospeech/includes/nvdscustomlib_factory.h:47
nvdstts::DSCustomLibrary_Factory
Definition: gst-nvdstexttospeech/includes/nvdscustomlib_factory.h:43
nvdstts::dlsym_ptr
T * dlsym_ptr(void *handle, char const *name)
Definition: gst-nvdstexttospeech/includes/nvdscustomlib_factory.h:38
nvdscustomlib_interface.hpp
nvdstts::DSCustomLibrary_Factory::DSCustomLibrary_Factory
DSCustomLibrary_Factory()=default
nvdstts
Copyright (c) 2021, NVIDIA CORPORATION.
Definition: gst-nvdstexttospeech/includes/nvdscustomlib_factory.h:34
nvdstts::DSCustomLibrary_Factory::CreateCustomAlgoCtx
IDSCustomLibrary * CreateCustomAlgoCtx(const std::string &libName, const std::string &symName)
Definition: gst-nvdstexttospeech/includes/nvdscustomlib_factory.h:54
nvdstts::DSCustomLibrary_Factory::m_libName
std::string m_libName
Definition: gst-nvdstexttospeech/includes/nvdscustomlib_factory.h:81
nvdstts::DSCustomLibrary_Factory::m_libHandle
void * m_libHandle
Definition: gst-nvdstexttospeech/includes/nvdscustomlib_factory.h:80
nvdstts::DSCustomLibrary_Factory::m_CreateAlgoCtx
std::function< IDSCustomLibrary *()> m_CreateAlgoCtx
Definition: gst-nvdstexttospeech/includes/nvdscustomlib_factory.h:82