NVIDIA DeepStream SDK API Reference

9.2 Release
service-maker/sources/python/src/bindings/pipeline.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 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 
18 #include "pipelinedoc.h"
19 
20 class __attribute__ ((visibility("hidden"))) PipelineWrapper : public Pipeline {
21  public:
22  PipelineWrapper(const string& name)
23  :Pipeline(name.c_str()) {}
24 
25  PipelineWrapper(const string& name, const string& config_path)
26  :Pipeline(name.c_str(), config_path) {}
27 
28  function<void(py::object)> on_message;
29 };
30 
31 static void on_pipeline_message(Pipeline& p, const Pipeline::Message& m) {
32  PipelineWrapper &pipeline = dynamic_cast<PipelineWrapper&>(p);
33  py::gil_scoped_acquire acquire;
34  py::object object;
35 
36  const Pipeline::StateTransitionMessage* state_transition = dynamic_cast<const Pipeline::StateTransitionMessage*>(&m);
37  const Pipeline::DynamicSourceMessage* dynamic_source = dynamic_cast<const Pipeline::DynamicSourceMessage*>(&m);
38  const Pipeline::EOSMessage* eos = dynamic_cast<const Pipeline::EOSMessage*>(&m);
39  if (state_transition) {
40  Pipeline::StateTransitionMessage message = *state_transition;
41  object = py::cast(message);
42  } else if (dynamic_source) {
43  Pipeline::DynamicSourceMessage message = *dynamic_source;
44  object = py::cast(message);
45  } else if (eos) {
46  Pipeline::EOSMessage message = *eos;
47  object = py::cast(message);
48  }
49 
50  if (pipeline.on_message && !object.is_none()) {
51  // invoke python callback
52  pipeline.on_message(object);
53  }
54 }
55 
56 void module_pipeline_bind(py::module &m);
57 
58 void module_pipeline_bind(py::module &m) {
59  py::enum_<Pipeline::State>(m, "PipelineState", pydeepstreamdoc::pipeline::PipelineStateDoc::descr)
60  .value("INVALID", Pipeline::State::INVALID)
61  .value("EMPTY", Pipeline::State::EMPTY)
62  .value("READY", Pipeline::State::READY)
63  .value("PAUSED", Pipeline::State::PAUSED)
64  .value("PLAYING", Pipeline::State::PLAYING);
65  auto pipeline_message = py::class_<Pipeline::Message>(m, "PipelineMessage", pydeepstreamdoc::pipeline::PipelineMessageDoc::descr);
66  auto eos_message = py::class_<Pipeline::EOSMessage, Pipeline::Message>(m, "EOSMessage", pydeepstreamdoc::pipeline::EOSMessageDoc::descr);
67  py::class_<Pipeline::StateTransitionMessage, Pipeline::Message>(m, "StateTransitionMessage", pydeepstreamdoc::pipeline::StateTransitionMessageDoc::descr)
68  .def_property_readonly("old_state", [](Pipeline::StateTransitionMessage& self){
69  Pipeline::State states[2] = {Pipeline::State::INVALID,Pipeline::State::INVALID };
70  self.getState(states[0], states[1]);
71  return states[0];
72  })
73  .def_property_readonly("new_state", [](Pipeline::StateTransitionMessage& self){
74  Pipeline::State states[2] = {Pipeline::State::INVALID,Pipeline::State::INVALID };
75  self.getState(states[0], states[1]);
76  return states[1];
77  })
78  .def_property_readonly("origin", [](Pipeline::StateTransitionMessage& self) {
79  string name = self.getName();
80  return name;
81  })
82  .def("__repr__", [](Pipeline::StateTransitionMessage& self) {
83  Pipeline::State states[2] = {Pipeline::State::INVALID,Pipeline::State::INVALID };
84  self.getState(states[0], states[1]);
85  return "StateTransitionMessage(old_state=" + std::to_string(states[0]) +
86  ", new_state=" + std::to_string(states[1]) +
87  ", origin=" + self.getName() + ")";
88  });
89  py::class_<Pipeline::DynamicSourceMessage, Pipeline::Message>(m, "DynamicSourceMessage", pydeepstreamdoc::pipeline::DynamicSourceMessageDoc::descr)
90  .def_property_readonly("source_added", &Pipeline::DynamicSourceMessage::isSourceAdded)
91  .def_property_readonly("source_id", &Pipeline::DynamicSourceMessage::getSourceId)
92  .def_property_readonly("sensor_id", &Pipeline::DynamicSourceMessage::getSensorId)
93  .def_property_readonly("sensor_name", &Pipeline::DynamicSourceMessage::getSensorName)
94  .def_property_readonly("uri", &Pipeline::DynamicSourceMessage::getUri)
95  .def("__repr__", [](Pipeline::DynamicSourceMessage& self) {
96  return "DynamicSourceMessage(source_added=" + std::to_string(self.isSourceAdded()) +
97  ", source_id=" + std::to_string(self.getSourceId()) +
98  ", sensor_id=" + self.getSensorId() +
99  ", sensor_name=" + self.getSensorName() +
100  ", uri=" + self.getUri() + ")";
101  });
102  py::class_<RecordingInfo>(m, "RecordingInfo", pydeepstreamdoc::pipeline::RecordingInfoDoc::descr)
103  .def_property_readonly("session_id", &RecordingInfo::getSessionId)
104  .def_property_readonly("file_name", &RecordingInfo::getFileName)
105  .def_property_readonly("file_directory", &RecordingInfo::getFileDirectory)
106  .def_property_readonly("duration", &RecordingInfo::getDuration)
107  .def_property_readonly("container_type", &RecordingInfo::getContainerType)
108  .def_property_readonly("width", &RecordingInfo::getWidth)
109  .def_property_readonly("height", &RecordingInfo::getHeight)
110  .def_property_readonly("contains_video", &RecordingInfo::containsVideo)
111  .def_property_readonly("contains_audio", &RecordingInfo::containsAudio)
112  .def_property_readonly("channels", &RecordingInfo::getChannels)
113  .def_property_readonly("sampling_rate", &RecordingInfo::getSamplingRate)
114  .def("__repr__", [](RecordingInfo& self) {
115  return "RecordingInfo(session_id=" + std::to_string(self.getSessionId()) +
116  ", file_name=" + self.getFileName() +
117  ", file_directory=" + self.getFileDirectory() +
118  ", duration=" + std::to_string(self.getDuration()) +
119  ", container_type=" + self.getContainerType() +
120  ", width=" + std::to_string(self.getWidth()) +
121  ", height=" + std::to_string(self.getHeight()) +
122  ", contains_video=" + std::to_string(self.containsVideo()) +
123  ", contains_audio=" + std::to_string(self.containsAudio()) +
124  ", channels=" + std::to_string(self.getChannels()) +
125  ", sampling_rate=" + std::to_string(self.getSamplingRate()) + ")";
126  });
127  py::class_<PipelineWrapper>(m, "Pipeline", pydeepstreamdoc::pipeline::PipelineDoc::descr)
128  .def(py::init<const string&>(), py::arg("name"), pydeepstreamdoc::pipeline::PipelineDoc::init)
129  .def(py::init<const string&, const string&>(), py::arg("name"), py::arg("config_file"), pydeepstreamdoc::pipeline::PipelineDoc::init_with_config)
130  .def("add", [](PipelineWrapper& self, const string& type_name, const string& name) {
131  self.add(type_name, name);
133  .def("attach", (Pipeline& (Pipeline::*)(const string&, const string&, const string&, const string)) &Pipeline::attach, pydeepstreamdoc::pipeline::PipelineDoc::attach)
134  .def("__getitem__", [](PipelineWrapper& self, const string& name) -> Node& {
136  return reinterpret_cast<Node&>(self[name]);
138  .def("start", (Pipeline& (Pipeline::*)()) &Pipeline::start, pydeepstreamdoc::pipeline::PipelineDoc::start)
139  .def("start_with_callback", [](PipelineWrapper& self, std::function<void(py::object)> on_message){
140  self.on_message = on_message;
141  self.start(on_pipeline_message);
143  .def("prepare", (int (Pipeline::*)()) &Pipeline::prepare, pydeepstreamdoc::pipeline::PipelineDoc::prepare)
144  .def("prepare_with_callback", [](PipelineWrapper& self, std::function<void(py::object)> on_message){
145  self.on_message = on_message;
146  self.prepare(on_pipeline_message);
148  .def("activate", (Pipeline& (Pipeline::*)()) &Pipeline::activate, pydeepstreamdoc::pipeline::PipelineDoc::activate)
149  .def("wait", [](PipelineWrapper& self) {
150  py::gil_scoped_release release;
151  self.wait();
154  .def("start_rtsp_server", &Pipeline::startRTSP, pydeepstreamdoc::pipeline::PipelineDoc::start_rtsp_server)
155  .def("seek", [](PipelineWrapper& self, uint64_t timestamp) {
156  py::gil_scoped_release release;
157  self.seek(timestamp);
159  .def("start_recording", [](PipelineWrapper& self, const string& source_name, uint64_t start_time, uint64_t duration, std::function<void(RecordingInfo)> callback = nullptr) {
160  py::gil_scoped_release release;
161  if (callback) {
162  return self.startRecording(source_name, start_time, duration, callback);
163  } else {
164  return self.startRecording(source_name, start_time, duration);
165  }
167  .def("stop_recording", [](PipelineWrapper& self, const string& source_name) {
168  py::gil_scoped_release release;
169  return self.stopRecording(source_name);
171  .def("stop_recording_by_session_id", [](PipelineWrapper& self, uint32_t session_id) {
172  py::gil_scoped_release release;
173  return self.stopRecording(session_id);
175 
176 }
module_pipeline_bind
void module_pipeline_bind(py::module &m)
Definition: service-maker/sources/python/src/bindings/pipeline.h:58
pydeepstreamdoc::pipeline::PipelineDoc::prepare_with_callback
constexpr const char * prepare_with_callback
Definition: service-maker/sources/python/src/bindings/docstrings/pipelinedoc.h:100
pydeepstreamdoc::pipeline::PipelineDoc::stop
constexpr const char * stop
Definition: service-maker/sources/python/src/bindings/docstrings/pipelinedoc.h:103
pydeepstreamdoc::pipeline::PipelineDoc::prepare
constexpr const char * prepare
Definition: service-maker/sources/python/src/bindings/docstrings/pipelinedoc.h:99
pydeepstreamdoc::pipeline::PipelineDoc::seek
constexpr const char * seek
Definition: service-maker/sources/python/src/bindings/docstrings/pipelinedoc.h:105
pydeepstreamdoc::pipeline::RecordingInfoDoc::descr
constexpr const char * descr
Definition: service-maker/sources/python/src/bindings/docstrings/pipelinedoc.h:63
pydeepstreamdoc::pipeline::PipelineDoc::start_rtsp_server
constexpr const char * start_rtsp_server
Definition: service-maker/sources/python/src/bindings/docstrings/pipelinedoc.h:104
pydeepstreamdoc::pipeline::PipelineDoc::descr
constexpr const char * descr
Definition: service-maker/sources/python/src/bindings/docstrings/pipelinedoc.h:81
__attribute__
void __attribute__((constructor)) nvmsgbroker_init(void)
pydeepstreamdoc::pipeline::PipelineDoc::wait
constexpr const char * wait
Definition: service-maker/sources/python/src/bindings/docstrings/pipelinedoc.h:102
pydeepstreamdoc::pipeline::PipelineDoc::start_with_callback
constexpr const char * start_with_callback
Definition: service-maker/sources/python/src/bindings/docstrings/pipelinedoc.h:98
pydeepstreamdoc::osd::ArrowHeadDoc::start
constexpr const char * start
Definition: service-maker/sources/python/src/bindings/docstrings/osddoc.h:33
pydeepstreamdoc::pipeline::PipelineDoc::init
constexpr const char * init
Definition: service-maker/sources/python/src/bindings/docstrings/pipelinedoc.h:82
pydeepstreamdoc::pipeline::EOSMessageDoc::descr
constexpr const char * descr
Definition: service-maker/sources/python/src/bindings/docstrings/pipelinedoc.h:36
pydeepstreamdoc::pipeline::PipelineStateDoc::descr
constexpr const char * descr
Definition: service-maker/sources/python/src/bindings/docstrings/pipelinedoc.h:26
pydeepstreamdoc::pipeline::PipelineDoc::attach
constexpr const char * attach
Definition: service-maker/sources/python/src/bindings/docstrings/pipelinedoc.h:89
pydeepstreamdoc::pipeline::PipelineDoc::stop_recording
constexpr const char * stop_recording
Definition: service-maker/sources/python/src/bindings/docstrings/pipelinedoc.h:112
pydeepstreamdoc::pipeline::PipelineDoc::stop_recording_by_session_id
constexpr const char * stop_recording_by_session_id
Definition: service-maker/sources/python/src/bindings/docstrings/pipelinedoc.h:116
pydeepstreamdoc::pipeline::PipelineDoc::add
constexpr const char * add
Definition: service-maker/sources/python/src/bindings/docstrings/pipelinedoc.h:84
pydeepstreamdoc::pipeline::PipelineDoc::start_recording
constexpr const char * start_recording
Definition: service-maker/sources/python/src/bindings/docstrings/pipelinedoc.h:106
ds3d::State
State
All custom-libs need create the abi reference for DataLoader, DataRender, and DataFilter.
Definition: includes/ds3d/common/abi_dataprocess.h:55
Node
Definition: service-maker/sources/python/src/bindings/node.h:20
pydeepstreamdoc::pipeline::PipelineDoc::activate
constexpr const char * activate
Definition: service-maker/sources/python/src/bindings/docstrings/pipelinedoc.h:101
pydeepstreamdoc::pipeline::PipelineDoc::start
constexpr const char * start
Definition: service-maker/sources/python/src/bindings/docstrings/pipelinedoc.h:97
pydeepstreamdoc::pipeline::PipelineDoc::init_with_config
constexpr const char * init_with_config
Definition: service-maker/sources/python/src/bindings/docstrings/pipelinedoc.h:83
pydeepstreamdoc::pipeline::StateTransitionMessageDoc::descr
constexpr const char * descr
Definition: service-maker/sources/python/src/bindings/docstrings/pipelinedoc.h:41
pydeepstreamdoc::pipeline::DynamicSourceMessageDoc::descr
constexpr const char * descr
Definition: service-maker/sources/python/src/bindings/docstrings/pipelinedoc.h:51
EMPTY
@ EMPTY
Definition: includes/nvds_tracker_meta.h:42
on_pipeline_message
class static __attribute__((visibility("hidden"))) PipelineWrapper void on_pipeline_message(Pipeline &p, const Pipeline::Message &m)
Definition: service-maker/sources/python/src/bindings/pipeline.h:31
pydeepstreamdoc::pipeline::PipelineMessageDoc::descr
constexpr const char * descr
Definition: service-maker/sources/python/src/bindings/docstrings/pipelinedoc.h:31
pydeepstreamdoc::pipeline::PipelineDoc::getitem
constexpr const char * getitem
Definition: service-maker/sources/python/src/bindings/docstrings/pipelinedoc.h:96
pydeepstreamdoc::osd::EventHandlerDoc::stop
constexpr const char * stop
Definition: service-maker/sources/python/src/bindings/docstrings/osddoc.h:159