NVIDIA DeepStream SDK API Reference

9.1 Release
service-maker/includes/element.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
29 #ifndef ELEMENT_HPP
30 #define ELEMENT_HPP
31 
32 #include <string>
33 #include <memory>
34 #include <vector>
35 #include <typeinfo>
36 #include <algorithm>
37 
38 #include "yaml-cpp/yaml.h"
39 #include "object.hpp"
40 #include "buffer_probe.hpp"
41 #include "signal_emitter.hpp"
42 #include "signal_handler.hpp"
43 
44 namespace deepstream {
45 
46 class Pipeline;
47 
54 class Element : public Object {
55  public:
56 
57  typedef enum {
63  } State;
64 
71  Element(const std::string& type_name, std::string name = std::string());
72 
74  Element(const Object&);
75 
77  Element(Object&&);
78 
80  virtual ~Element();
81 
89  Element & link(Element &dst, std::pair<std::string, std::string> hint);
90 
97  Element& link(Element &other);
98 
100  BufferProbe* getProbe(const std::string& name) {
101  return find_<BufferProbe>(name);
102  }
103 
114  Element& addProbe(const std::string& plugin_name,
115  const std::string& probe_name,
116  const std::string probe_tip = "");
117 
119  template<typename... Args>
120  Element& addProbe(const std::string& plugin_name,
121  const std::string& probe_name,
122  const std::string probe_tip = "",
123  const Args&... args) {
124  addProbe(plugin_name, probe_name, probe_tip);
125  auto probe = getProbe(probe_name);
126  if (probe && (sizeof...(args) > 0)) {
127  probe->set(args...);
128  }
129  return *this;
130  }
131 
141  Element& addProbe(BufferProbe* probe, const std::string probe_tip = "");
142 
144  SignalHandler* getSignalHandler(const std::string& name) {
145  return find_<SignalHandler>(name);
146  }
147 
162  Element& connectSignal(const std::string&signal_name, SignalHandler* handler);
163 
174  Element& connectSignal(const std::string& plugin_name,
175  const std::string& handler_name,
176  const std::string& signal_names);
177 
179  template<typename... Args>
180  Element& connectSignal(const std::string& plugin_name,
181  const std::string& handler_name,
182  const std::string& signal_names,
183  const Args&... args) {
184  connectSignal(plugin_name, handler_name, signal_names);
185  auto handler = getSignalHandler(handler_name);
186  if (handler && (sizeof...(args) > 0)) {
187  handler->set(args...);
188  }
189  return *this;
190  }
191 
193  return *pipeline_;
194  }
195 
197  bool setState (Element::State state);
198 
199 protected:
200  Element(GstObject* object);
201 
202  Element& add_(CustomObject* object);
203 
204  // buffer probes, signal handlers, signal emitters are held by its target
205  // element as shared pointers.
206  std::shared_ptr<std::unordered_map<std::string, std::unique_ptr<CustomObject>>> objects_;
207  // pointer to the pipeline
208  Pipeline* pipeline_=nullptr;
209 
210  template<class T>
211  T* find_(const std::string& name) {
212  auto itr = find_if(
213  objects_->begin(),
214  objects_->end(),
215  [&](const auto& pair) {
216  return pair.first == name && dynamic_cast<T*>(pair.second.get());
217  }
218  );
219  if (itr != objects_->end()) return dynamic_cast<T*>(itr->second.get());
220  return nullptr;
221  }
222 
223 friend class Pipeline;
224 };
225 
226 } // namespace deepstream
227 
228 #endif
deepstream::Object::Element
friend class Element
Definition: service-maker/includes/object.hpp:210
signal_emitter.hpp
deepstream::Element::setState
bool setState(Element::State state)
Set the Element in particular state.
deepstream::Element::PLAYING
@ PLAYING
Definition: service-maker/includes/element.hpp:62
deepstream::Element::getSignalHandler
SignalHandler * getSignalHandler(const std::string &name)
Find the signal handler attached to the element by name.
Definition: service-maker/includes/element.hpp:144
deepstream::CustomObject
Base class for all the custom objects.
Definition: service-maker/includes/custom_object.hpp:39
deepstream::Element
Element class definition.
Definition: service-maker/includes/element.hpp:54
deepstream::BufferProbe
Represent a custom object for the purpose of probing output buffers.
Definition: service-maker/includes/buffer_probe.hpp:63
deepstream::Element::getProbe
BufferProbe * getProbe(const std::string &name)
Find the buffer probe attached to the elmenent by name.
Definition: service-maker/includes/element.hpp:100
object.hpp
deepstream::Element::EMPTY
@ EMPTY
Definition: service-maker/includes/element.hpp:59
deepstream::Pipeline
Pipeline class definition.
Definition: service-maker/includes/pipeline.hpp:96
deepstream::Element::State
State
Definition: service-maker/includes/element.hpp:57
deepstream::Element::~Element
virtual ~Element()
Destructor.
deepstream::Element::PAUSED
@ PAUSED
Definition: service-maker/includes/element.hpp:61
deepstream::Element::pipeline_
Pipeline * pipeline_
Definition: service-maker/includes/element.hpp:208
deepstream::Element::find_
T * find_(const std::string &name)
Definition: service-maker/includes/element.hpp:211
deepstream
Definition: service-maker/includes/buffer.hpp:38
deepstream::Element::connectSignal
Element & connectSignal(const std::string &plugin_name, const std::string &handler_name, const std::string &signal_names, const Args &... args)
Template function for creating and connecting signal with properties.
Definition: service-maker/includes/element.hpp:180
deepstream::Element::addProbe
Element & addProbe(const std::string &plugin_name, const std::string &probe_name, const std::string probe_tip="")
Create and add a buffer probe to the element.
deepstream::Element::READY
@ READY
Definition: service-maker/includes/element.hpp:60
deepstream::Element::addProbe
Element & addProbe(const std::string &plugin_name, const std::string &probe_name, const std::string probe_tip="", const Args &... args)
Template function for creating and adding buffer probe with properties.
Definition: service-maker/includes/element.hpp:120
deepstream::Element::connectSignal
Element & connectSignal(const std::string &signal_name, SignalHandler *handler)
Connect a signal handler to the element.
deepstream::Element::add_
Element & add_(CustomObject *object)
GstObject
struct _GstObject GstObject
Definition: service-maker/includes/object.hpp:39
deepstream::Element::objects_
std::shared_ptr< std::unordered_map< std::string, std::unique_ptr< CustomObject > > > objects_
Definition: service-maker/includes/element.hpp:206
buffer_probe.hpp
signal_handler.hpp
deepstream::Element::INVALID
@ INVALID
Definition: service-maker/includes/element.hpp:58
deepstream::SignalHandler
SignalHandler class.
Definition: service-maker/includes/signal_handler.hpp:45
deepstream::Element::link
Element & link(Element &dst, std::pair< std::string, std::string > hint)
Link two Element instances using hint.
deepstream::Element::getPipeline
const Pipeline & getPipeline()
Definition: service-maker/includes/element.hpp:192
deepstream::Object
Base Object class.
Definition: service-maker/includes/object.hpp:49