NVIDIA DeepStream SDK API Reference

6.4 Release
gst-nvdsspeech/includes/nvdscustomlib_base.hpp
Go to the documentation of this file.
1 
23 #ifndef __NVDS_SPEECH_CUSTOMLIB_BASE_HPP__
24 #define __NVDS_SPEECH_CUSTOMLIB_BASE_HPP__
25 
26 #include <gst/audio/audio.h>
27 #include <gst/base/gstbasetransform.h>
28 
30 
31 
32 namespace nvdsspeech {
33 
35 public:
36  DSCustomLibraryBase() = default;
37  virtual ~DSCustomLibraryBase() override;
38 
39  bool Initialize() override;
40 
41  /* Set Init Parameters */
42  bool StartWithParams(DSCustom_CreateParams* params) override;
43 
44  /* Set Each Property */
45  bool SetProperty(const Property& prop) override;
46 
47  /* Get Compatible Input/Output Caps */
48  GstCaps* GetCompatibleCaps(
49  GstPadDirection direction, GstCaps* inCaps,
50  GstCaps* otherCaps) override;
51 
52  /* Handle event, e.g. EOS... */
53  bool HandleEvent(GstEvent* event) override { return true; }
54 
55  /* Process Input Buffer */
56  BufferResult ProcessBuffer(GstBuffer* inbuf) override = 0;
57 
58 protected:
59  /* Gstreamer dsspeech plugin's base class reference */
60  GstBaseTransform* m_element{nullptr};
61  /* Gst Caps Information */
62  GstCaps* m_inCaps{nullptr};
63  GstCaps* m_outCaps{nullptr};
64  std::string m_configFile;
65 
66  /* Audio Information */
67  GstAudioInfo m_inAudioInfo{nullptr, GST_AUDIO_FLAG_NONE};
68  GstAudioFormat m_inAudioFmt = GST_AUDIO_FORMAT_UNKNOWN;
69  /* Output Information */
71  GstAudioInfo m_outAudioInfo{nullptr, GST_AUDIO_FLAG_NONE};
72 };
73 
74 bool
76 {
77  if (prop.key == NVDS_CONFIG_FILE_PROPERTY) {
78  m_configFile = prop.value;
79  }
80  return true;
81 }
82 
83 bool
85 {
86  return true;
87 }
88 
89 bool
91 {
92  assert(params);
93  m_element = params->m_element;
94  m_inCaps = gst_caps_copy(params->m_inCaps);
95  m_outCaps = gst_caps_copy(params->m_outCaps);
96 
97  gst_audio_info_from_caps(&m_inAudioInfo, m_inCaps);
98 
99  GstStructure* outStr = gst_caps_get_structure(m_outCaps, 0);
100  if (gst_structure_has_name(outStr, "audio/x-raw")) {
102  gst_audio_info_from_caps(&m_outAudioInfo, m_outCaps);
103  } else {
105  }
106  gst_audio_info_from_caps(&m_outAudioInfo, m_outCaps);
107 
108  m_inAudioFmt = GST_AUDIO_FORMAT_INFO_FORMAT(m_inAudioInfo.finfo);
109 
110  return true;
111 }
112 
114 {
115  if (m_inCaps) {
116  gst_caps_unref(m_inCaps);
117  }
118  if (m_outCaps) {
119  gst_caps_unref(m_outCaps);
120  }
121 }
122 
123 GstCaps*
125  GstPadDirection direction, GstCaps* inCaps, GstCaps* otherCaps)
126 {
127  if (!otherCaps) {
128  g_print(
129  "WARNING: DSCustomLibraryBase detect empty otherCaps, will try "
130  "inCaps");
131  return gst_caps_ref(inCaps);
132  }
133 
134  GstCaps* result = nullptr;
135  if (!gst_caps_is_fixed(otherCaps)) {
136  result = gst_caps_fixate(otherCaps);
137  return result;
138  } else {
139  result = gst_caps_ref(otherCaps);
140  }
141  return result;
142 }
143 
144 } // namespace nvdsspeech
145 
146 #endif
nvdsspeech::CapsType::kText
@ kText
nvdsspeech::DSCustom_CreateParams::m_outCaps
GstCaps * m_outCaps
Definition: gst-nvdsspeech/includes/nvdscustomlib_interface.hpp:45
nvdsspeech::BufferResult
BufferResult
Definition: gst-nvdsspeech/includes/nvdscustomlib_interface.hpp:34
nvdsspeech::DSCustomLibraryBase
Definition: gst-nvdsspeech/includes/nvdscustomlib_base.hpp:34
nvdsspeech::DSCustomLibraryBase::m_outCaps
GstCaps * m_outCaps
Definition: gst-nvdsspeech/includes/nvdscustomlib_base.hpp:63
nvdsspeech::Property
Definition: gst-nvdsspeech/includes/nvdscustomlib_interface.hpp:48
nvdsspeech::DSCustomLibraryBase::m_element
GstBaseTransform * m_element
Definition: gst-nvdsspeech/includes/nvdscustomlib_base.hpp:60
nvdsspeech::DSCustomLibraryBase::SetProperty
bool SetProperty(const Property &prop) override
Definition: gst-nvdsspeech/includes/nvdscustomlib_base.hpp:75
nvdsspeech::DSCustom_CreateParams::m_element
GstBaseTransform * m_element
Definition: gst-nvdsspeech/includes/nvdscustomlib_interface.hpp:43
nvdsspeech::DSCustom_CreateParams::m_inCaps
GstCaps * m_inCaps
Definition: gst-nvdsspeech/includes/nvdscustomlib_interface.hpp:44
nvdsspeech::CapsType
CapsType
Definition: gst-nvdsspeech/includes/nvdscustomlib_interface.hpp:58
nvdsspeech::DSCustomLibraryBase::StartWithParams
bool StartWithParams(DSCustom_CreateParams *params) override
Definition: gst-nvdsspeech/includes/nvdscustomlib_base.hpp:90
nvdsspeech
Copyright (c) 2020-2021, NVIDIA CORPORATION.
Definition: gst-nvdsspeech/includes/nvdscustomlib_interface.hpp:32
nvdsspeech::IDSCustomLibrary
Definition: gst-nvdsspeech/includes/nvdscustomlib_interface.hpp:64
nvdsspeech::Property::key
std::string key
Definition: gst-nvdsspeech/includes/nvdscustomlib_interface.hpp:54
nvdsspeech::DSCustomLibraryBase::DSCustomLibraryBase
DSCustomLibraryBase()=default
nvdsspeech::DSCustomLibraryBase::m_configFile
std::string m_configFile
Definition: gst-nvdsspeech/includes/nvdscustomlib_base.hpp:64
nvdsspeech::DSCustomLibraryBase::Initialize
bool Initialize() override
Definition: gst-nvdsspeech/includes/nvdscustomlib_base.hpp:84
nvdsspeech::DSCustomLibraryBase::m_inAudioFmt
GstAudioFormat m_inAudioFmt
Definition: gst-nvdsspeech/includes/nvdscustomlib_base.hpp:68
nvdsspeech::DSCustomLibraryBase::m_outAudioInfo
GstAudioInfo m_outAudioInfo
Definition: gst-nvdsspeech/includes/nvdscustomlib_base.hpp:71
nvdsspeech::DSCustomLibraryBase::HandleEvent
bool HandleEvent(GstEvent *event) override
Definition: gst-nvdsspeech/includes/nvdscustomlib_base.hpp:53
nvdsspeech::DSCustomLibraryBase::m_OutType
CapsType m_OutType
Definition: gst-nvdsspeech/includes/nvdscustomlib_base.hpp:70
nvdsspeech::DSCustomLibraryBase::~DSCustomLibraryBase
virtual ~DSCustomLibraryBase() override
Definition: gst-nvdsspeech/includes/nvdscustomlib_base.hpp:113
NVDS_CONFIG_FILE_PROPERTY
#define NVDS_CONFIG_FILE_PROPERTY
Copyright (c) 2021, NVIDIA CORPORATION.
Definition: gst-nvdstexttospeech/includes/nvdscustomlib_interface.hpp:30
nvdsspeech::DSCustomLibraryBase::GetCompatibleCaps
GstCaps * GetCompatibleCaps(GstPadDirection direction, GstCaps *inCaps, GstCaps *otherCaps) override
Definition: gst-nvdsspeech/includes/nvdscustomlib_base.hpp:124
nvdsspeech::Property::value
std::string value
Definition: gst-nvdsspeech/includes/nvdscustomlib_interface.hpp:55
nvdsspeech::DSCustomLibraryBase::ProcessBuffer
BufferResult ProcessBuffer(GstBuffer *inbuf) override=0
nvdsspeech::CapsType::kNone
@ kNone
GstBuffer
struct _GstBuffer GstBuffer
Definition: idatatype.h:19
nvdsspeech::DSCustomLibraryBase::m_inCaps
GstCaps * m_inCaps
Definition: gst-nvdsspeech/includes/nvdscustomlib_base.hpp:62
nvdsspeech::CapsType::kAudio
@ kAudio
nvdsspeech::DSCustomLibraryBase::m_inAudioInfo
GstAudioInfo m_inAudioInfo
Definition: gst-nvdsspeech/includes/nvdscustomlib_base.hpp:67
nvdsspeech::DSCustom_CreateParams
Definition: gst-nvdsspeech/includes/nvdscustomlib_interface.hpp:42
nvdscustomlib_interface.hpp