NVIDIA DeepStream SDK API Reference

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