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