NVIDIA DeepStream SDK API Reference

8.0 Release
element.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: LicenseRef-NvidiaProprietary
4  *
5  * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
6  * property and proprietary rights in and to this material, related
7  * documentation and any modifications thereto. Any use, reproduction,
8  * disclosure or distribution of this material and related documentation
9  * without an express license agreement from NVIDIA CORPORATION or
10  * its affiliates is strictly prohibited.
11  */
12 
24 #ifndef ELEMENT_HPP
25 #define ELEMENT_HPP
26 
27 #include <string>
28 #include <memory>
29 #include <vector>
30 #include <typeinfo>
31 #include <algorithm>
32 
33 #include "yaml-cpp/yaml.h"
34 #include "object.hpp"
35 #include "buffer_probe.hpp"
36 #include "signal_emitter.hpp"
37 #include "signal_handler.hpp"
38 
39 namespace deepstream {
40 
41 class Pipeline;
42 
49 class Element : public Object {
50  public:
51 
52  typedef enum {
58  } State;
59 
66  Element(const std::string& type_name, std::string name = std::string());
67 
69  Element(const Object&);
70 
72  Element(Object&&);
73 
75  virtual ~Element();
76 
84  Element & link(Element &dst, std::pair<std::string, std::string> hint);
85 
92  Element& link(Element &other);
93 
95  BufferProbe* getProbe(const std::string& name) {
96  return find_<BufferProbe>(name);
97  }
98 
109  Element& addProbe(const std::string& plugin_name,
110  const std::string& probe_name,
111  const std::string probe_tip = "");
112 
114  template<typename... Args>
115  Element& addProbe(const std::string& plugin_name,
116  const std::string& probe_name,
117  const std::string probe_tip = "",
118  const Args&... args) {
119  addProbe(plugin_name, probe_name, probe_tip);
120  auto probe = getProbe(probe_name);
121  if (probe && (sizeof...(args) > 0)) {
122  probe->set(args...);
123  }
124  return *this;
125  }
126 
136  Element& addProbe(BufferProbe* probe, const std::string probe_tip = "");
137 
139  SignalHandler* getSignalHandler(const std::string& name) {
140  return find_<SignalHandler>(name);
141  }
142 
157  Element& connectSignal(const std::string&signal_name, SignalHandler* handler);
158 
169  Element& connectSignal(const std::string& plugin_name,
170  const std::string& handler_name,
171  const std::string& signal_names);
172 
174  template<typename... Args>
175  Element& connectSignal(const std::string& plugin_name,
176  const std::string& handler_name,
177  const std::string& signal_names,
178  const Args&... args) {
179  connectSignal(plugin_name, handler_name, signal_names);
180  auto handler = getSignalHandler(handler_name);
181  if (handler && (sizeof...(args) > 0)) {
182  handler->set(args...);
183  }
184  return *this;
185  }
186 
188  return *pipeline_;
189  }
190 
192  bool setState (Element::State state);
193 
194 protected:
195  Element(GstObject* object);
196 
197  Element& add_(CustomObject* object);
198 
199  // buffer probes, signal handlers, signal emitters are held by its target
200  // element as shared pointers.
201  std::shared_ptr<std::unordered_map<std::string, std::unique_ptr<CustomObject>>> objects_;
202  // pointer to the pipeline
203  Pipeline* pipeline_=nullptr;
204 
205  template<class T>
206  T* find_(const std::string& name) {
207  auto itr = find_if(
208  objects_->begin(),
209  objects_->end(),
210  [&](const auto& pair) {
211  return pair.first == name && dynamic_cast<T*>(pair.second.get());
212  }
213  );
214  if (itr != objects_->end()) return dynamic_cast<T*>(itr->second.get());
215  return nullptr;
216  }
217 
218 friend class Pipeline;
219 };
220 
221 } // namespace deepstream
222 
223 #endif
buffer_probe.hpp
deepstream::Element::pipeline_
Pipeline * pipeline_
Definition: element.hpp:203
deepstream::Element::setState
bool setState(Element::State state)
Set the Element in particular state.
signal_handler.hpp
deepstream::Element::getSignalHandler
SignalHandler * getSignalHandler(const std::string &name)
Find the signal handler attached to the element by name.
Definition: element.hpp:139
deepstream::CustomObject
Base class for all the custom objects.
Definition: custom_object.hpp:34
deepstream::Element::EMPTY
@ EMPTY
Definition: element.hpp:54
deepstream::Element
Element class definition.
Definition: element.hpp:49
deepstream::BufferProbe
Represent a custom object for the purpose of probing output buffers.
Definition: buffer_probe.hpp:58
GstObject
struct _GstObject GstObject
Definition: object.hpp:34
deepstream::Element::getProbe
BufferProbe * getProbe(const std::string &name)
Find the buffer probe attached to the elmenent by name.
Definition: element.hpp:95
deepstream::Pipeline
Pipeline class definition.
Definition: pipeline.hpp:46
deepstream::Element::State
State
Definition: element.hpp:52
deepstream::Element::~Element
virtual ~Element()
Destructor.
deepstream::Element::PLAYING
@ PLAYING
Definition: element.hpp:57
deepstream::Element::objects_
std::shared_ptr< std::unordered_map< std::string, std::unique_ptr< CustomObject > > > objects_
Definition: element.hpp:201
deepstream::Element::find_
T * find_(const std::string &name)
Definition: element.hpp:206
deepstream
Definition: buffer.hpp:33
deepstream::Object::Element
friend class Element
Definition: object.hpp:205
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: element.hpp:175
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::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: element.hpp:115
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)
deepstream::Element::INVALID
@ INVALID
Definition: element.hpp:53
signal_emitter.hpp
deepstream::SignalHandler
SignalHandler class.
Definition: signal_handler.hpp:40
object.hpp
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: element.hpp:187
deepstream::Object
Base Object class.
Definition: object.hpp:44
deepstream::Element::READY
@ READY
Definition: element.hpp:55
deepstream::Element::PAUSED
@ PAUSED
Definition: element.hpp:56