18 #include "pipelinedoc.h"
20 class __attribute__ ((visibility("hidden"))) PipelineWrapper :
public Pipeline {
22 PipelineWrapper(
const string& name)
23 :Pipeline(name.c_str()) {}
25 PipelineWrapper(
const string& name,
const string& config_path)
26 :Pipeline(name.c_str(), config_path) {}
28 function<void(py::object)> on_message;
32 PipelineWrapper &pipeline =
dynamic_cast<PipelineWrapper&
>(p);
33 py::gil_scoped_acquire acquire;
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);
46 Pipeline::EOSMessage message = *eos;
47 object = py::cast(message);
50 if (pipeline.on_message && !
object.is_none()) {
52 pipeline.on_message(
object);
60 .value(
"INVALID", Pipeline::State::INVALID)
62 .value(
"READY", Pipeline::State::READY)
63 .value(
"PAUSED", Pipeline::State::PAUSED)
64 .value(
"PLAYING", Pipeline::State::PLAYING);
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]);
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]);
78 .def_property_readonly(
"origin", [](Pipeline::StateTransitionMessage&
self) {
79 string name =
self.getName();
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() +
")";
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() +
")";
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()) +
")";
130 .def(
"add", [](PipelineWrapper&
self,
const string& type_name,
const string& name) {
131 self.add(type_name, name);
134 .def(
"__getitem__", [](PipelineWrapper&
self,
const string& name) ->
Node& {
136 return reinterpret_cast<Node&
>(
self[name]);
139 .def(
"start_with_callback", [](PipelineWrapper&
self, std::function<
void(py::object)> on_message){
140 self.on_message = on_message;
144 .def(
"prepare_with_callback", [](PipelineWrapper&
self, std::function<
void(py::object)> on_message){
145 self.on_message = on_message;
149 .def(
"wait", [](PipelineWrapper&
self) {
150 py::gil_scoped_release release;
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;
162 return self.startRecording(source_name, start_time, duration, callback);
164 return self.startRecording(source_name, start_time, duration);
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);