pyrs_pipeline.cpp
Go to the documentation of this file.
1 /* License: Apache 2.0. See LICENSE file in root directory.
2 Copyright(c) 2017 Intel Corporation. All Rights Reserved. */
3 
4 #include "python.hpp"
5 #include "../include/librealsense2/hpp/rs_pipeline.hpp"
6 
7 void init_pipeline(py::module &m) {
9  py::class_<rs2::pipeline_profile> pipeline_profile(m, "pipeline_profile", "The pipeline profile includes a device and a selection of active streams, with specific profiles.\n"
10  "The profile is a selection of the above under filters and conditions defined by the pipeline.\n"
11  "Streams may belong to more than one sensor of the device.");
12  pipeline_profile.def(py::init<>())
13  .def("get_streams", &rs2::pipeline_profile::get_streams, "Return the selected streams profiles, which are enabled in this profile.")
14  .def("get_stream", &rs2::pipeline_profile::get_stream, "Return the stream profile that is enabled for the specified stream in this profile.", "stream_type"_a, "stream_index"_a = -1)
15  .def("get_device", &rs2::pipeline_profile::get_device, "Retrieve the device used by the pipeline.\n"
16  "The device class provides the application access to control camera additional settings - get device "
17  "information, sensor options information, options value query and set, sensor specific extensions.\n"
18  "Since the pipeline controls the device streams configuration, activation state and frames reading, "
19  "calling the device API functions, which execute those operations, results in unexpected behavior.\n"
20  "The pipeline streaming device is selected during pipeline start(). Devices of profiles, which are not returned "
21  "by pipeline start() or get_active_profile(), are not guaranteed to be used by the pipeline.");
22 
23  // Workaround to allow python implicit conversion of pipeline to std::shared_ptr<rs2_pipeline>
24  struct pipeline_wrapper // TODO: not sure this is necessary
25  {
26  std::shared_ptr<rs2_pipeline> _ptr;
27  };
28  py::class_<pipeline_wrapper>(m, "pipeline_wrapper")
29  .def(py::init([](rs2::pipeline p) { return pipeline_wrapper{ p }; }));
30 
31  py::implicitly_convertible<rs2::pipeline, pipeline_wrapper>();
32 
33  py::class_<rs2::config> config(m, "config", "The config allows pipeline users to request filters for the pipeline streams and device selection and configuration.\n"
34  "This is an optional step in pipeline creation, as the pipeline resolves its streaming device internally.\n"
35  "Config provides its users a way to set the filters and test if there is no conflict with the pipeline requirements from the device.\n"
36  "It also allows the user to find a matching device for the config filters and the pipeline, in order to select a device explicitly, "
37  "and modify its controls before streaming starts.");
38  config.def(py::init<>())
39  .def("enable_stream", (void (rs2::config::*)(rs2_stream, int, int, int, rs2_format, int)) &rs2::config::enable_stream, "Enable a device stream explicitly, with selected stream parameters.\n"
40  "The method allows the application to request a stream with specific configuration.\n"
41  "If no stream is explicitly enabled, the pipeline configures the device and its streams according to the attached computer vision modules and processing blocks "
42  "requirements, or default configuration for the first available device.\n"
43  "The application can configure any of the input stream parameters according to its requirement, or set to 0 for don't care value.\n"
44  "The config accumulates the application calls for enable configuration methods, until the configuration is applied.\n"
45  "Multiple enable stream calls for the same stream override each other, and the last call is maintained.\n"
46  "Upon calling resolve(), the config checks for conflicts between the application configuration requests and the attached computer vision "
47  "modules and processing blocks requirements, and fails if conflicts are found.\n"
48  "Before resolve() is called, no conflict check is done.", "stream_type"_a, "stream_index"_a, "width"_a, "height"_a, "format"_a = RS2_FORMAT_ANY, "framerate"_a = 0)
49  .def("enable_stream", (void (rs2::config::*)(rs2_stream, int)) &rs2::config::enable_stream, "Stream type and possibly also stream index. Other parameters are resolved internally.", "stream_type"_a, "stream_index"_a = -1)
50  .def("enable_stream", (void (rs2::config::*)(rs2_stream, rs2_format, int))&rs2::config::enable_stream, "Stream type and format, and possibly frame rate. Other parameters are resolved internally.", "stream_type"_a, "format"_a, "framerate"_a = 0)
51  .def("enable_stream", (void (rs2::config::*)(rs2_stream, int, int, rs2_format, int)) &rs2::config::enable_stream, "Stream type and resolution, and possibly format and frame rate. Other parameters are resolved internally.", "stream_type"_a, "width"_a, "height"_a, "format"_a = RS2_FORMAT_ANY, "framerate"_a = 0)
52  .def("enable_stream", (void (rs2::config::*)(rs2_stream, int, rs2_format, int)) &rs2::config::enable_stream, "Stream type, index, and format, and possibly framerate. Other parameters are resolved internally.", "stream_type"_a, "stream_index"_a, "format"_a, "framerate"_a = 0)
53  .def("enable_all_streams", &rs2::config::enable_all_streams, "Enable all device streams explicitly.\n"
54  "The conditions and behavior of this method are similar to those of enable_stream().\n"
55  "This filter enables all raw streams of the selected device. The device is either selected explicitly by the application, "
56  "or by the pipeline requirements or default. The list of streams is device dependent.")
57  .def("enable_device", &rs2::config::enable_device, "Select a specific device explicitly by its serial number, to be used by the pipeline.\n"
58  "The conditions and behavior of this method are similar to those of enable_stream().\n"
59  "This method is required if the application needs to set device or sensor settings prior to pipeline streaming, "
60  "to enforce the pipeline to use the configured device.", "serial"_a)
61  .def("enable_device_from_file", &rs2::config::enable_device_from_file, "Select a recorded device from a file, to be used by the pipeline through playback.\n"
62  "The device available streams are as recorded to the file, and resolve() considers only this device and configuration as available.\n"
63  "This request cannot be used if enable_record_to_file() is called for the current config, and vice versa.", "file_name"_a, "repeat_playback"_a = true)
64  .def("enable_record_to_file", &rs2::config::enable_record_to_file, "Requires that the resolved device would be recorded to file.\n"
65  "This request cannot be used if enable_device_from_file() is called for the current config, and vice versa as available.", "file_name"_a)
66  .def("disable_stream", &rs2::config::disable_stream, "Disable a device stream explicitly, to remove any requests on this stream profile.\n"
67  "The stream can still be enabled due to pipeline computer vision module request. This call removes any filter on the stream configuration.", "stream"_a, "index"_a = -1)
68  .def("disable_all_streams", &rs2::config::disable_all_streams, "Disable all device stream explicitly, to remove any requests on the streams profiles.\n"
69  "The streams can still be enabled due to pipeline computer vision module request. This call removes any filter on the streams configuration.")
70  .def("resolve", [](rs2::config* c, pipeline_wrapper pw) -> rs2::pipeline_profile { return c->resolve(pw._ptr); }, "Resolve the configuration filters, "
71  "to find a matching device and streams profiles.\n"
72  "The method resolves the user configuration filters for the device and streams, and combines them with the requirements of the computer vision modules "
73  "and processing blocks attached to the pipeline. If there are no conflicts of requests, it looks for an available device, which can satisfy all requests, "
74  "and selects the first matching streams configuration.\n"
75  "In the absence of any request, the config object selects the first available device and the first color and depth streams configuration."
76  "The pipeline profile selection during start() follows the same method. Thus, the selected profile is the same, if no change occurs to the available devices."
77  "Resolving the pipeline configuration provides the application access to the pipeline selected device for advanced control."
78  "The returned configuration is not applied to the device, so the application doesn't own the device sensors. However, the application can call enable_device(), "
79  "to enforce the device returned by this method is selected by pipeline start(), and configure the device and sensors options or extensions before streaming starts.", "p"_a)
80  .def("can_resolve", [](rs2::config* c, pipeline_wrapper pw) -> bool { return c->can_resolve(pw._ptr); }, "Check if the config can resolve the configuration filters, "
81  "to find a matching device and streams profiles. The resolution conditions are as described in resolve().", "p"_a);
82 
83  py::class_<rs2::pipeline> pipeline(m, "pipeline", "The pipeline simplifies the user interaction with the device and computer vision processing modules.\n"
84  "The class abstracts the camera configuration and streaming, and the vision modules triggering and threading.\n"
85  "It lets the application focus on the computer vision output of the modules, or the device output data.\n"
86  "The pipeline can manage computer vision modules, which are implemented as a processing blocks.\n"
87  "The pipeline is the consumer of the processing block interface, while the application consumes the computer vision interface.");
88  pipeline.def(py::init<rs2::context>(), "The caller can provide a context created by the application, usually for playback or testing purposes.", "ctx"_a = rs2::context())
89  // TODO: Streamline this wall of text
90  .def("start", (rs2::pipeline_profile(rs2::pipeline::*)()) &rs2::pipeline::start, "Start the pipeline streaming with its default configuration.\n"
91  "The pipeline streaming loop captures samples from the device, and delivers them to the attached computer vision modules and processing "
92  "blocks, according to each module requirements and threading model.\n"
93  "During the loop execution, the application can access the camera streams by calling wait_for_frames() or poll_for_frames().\n"
94  "The streaming loop runs until the pipeline is stopped.\n"
95  "Starting the pipeline is possible only when it is not started. If the pipeline was started, an exception is raised.\n")
96  .def("start", (rs2::pipeline_profile(rs2::pipeline::*)(const rs2::config&)) &rs2::pipeline::start, "Start the pipeline streaming according to the configuraion.\n"
97  "The pipeline streaming loop captures samples from the device, and delivers them to the attached computer vision modules and processing blocks, according to "
98  "each module requirements and threading model.\n"
99  "During the loop execution, the application can access the camera streams by calling wait_for_frames() or poll_for_frames().\n"
100  "The streaming loop runs until the pipeline is stopped.\n"
101  "Starting the pipeline is possible only when it is not started. If the pipeline was started, an exception is raised.\n"
102  "The pipeline selects and activates the device upon start, according to configuration or a default configuration.\n"
103  "When the rs2::config is provided to the method, the pipeline tries to activate the config resolve() result.\n"
104  "If the application requests are conflicting with pipeline computer vision modules or no matching device is available on the platform, the method fails.\n"
105  "Available configurations and devices may change between config resolve() call and pipeline start, in case devices are connected or disconnected, or another "
106  "application acquires ownership of a device.", "config"_a)
107  .def("start", [](rs2::pipeline& self, std::function<void(rs2::frame)> f) { return self.start(f); }, "Start the pipeline streaming with its default configuration.\n"
108  "The pipeline captures samples from the device, and delivers them to the provided frame callback.\n"
109  "Starting the pipeline is possible only when it is not started. If the pipeline was started, an exception is raised.\n"
110  "When starting the pipeline with a callback both wait_for_frames() and poll_for_frames() will throw exception.", "callback"_a)
111  .def("start", [](rs2::pipeline& self, const rs2::config& config, std::function<void(rs2::frame)> f) { return self.start(config, f); }, "Start the pipeline streaming according to the configuraion.\n"
112  "The pipeline captures samples from the device, and delivers them to the provided frame callback.\n"
113  "Starting the pipeline is possible only when it is not started. If the pipeline was started, an exception is raised.\n"
114  "When starting the pipeline with a callback both wait_for_frames() and poll_for_frames() will throw exception.\n"
115  "The pipeline selects and activates the device upon start, according to configuration or a default configuration.\n"
116  "When the rs2::config is provided to the method, the pipeline tries to activate the config resolve() result.\n"
117  "If the application requests are conflicting with pipeline computer vision modules or no matching device is available on the platform, the method fails.\n"
118  "Available configurations and devices may change between config resolve() call and pipeline start, in case devices are connected or disconnected, "
119  "or another application acquires ownership of a device.", "config"_a, "callback"_a)
120  .def("start", [](rs2::pipeline& self, rs2::frame_queue& queue) { return self.start(queue); },"Start the pipeline streaming with its default configuration.\n"
121  "The pipeline captures samples from the device, and delivers them to the provided frame queue.\n"
122  "Starting the pipeline is possible only when it is not started. If the pipeline was started, an exception is raised.\n"
123  "When starting the pipeline with a callback both wait_for_frames() and poll_for_frames() will throw exception.", "queue"_a)
124  .def("start", [](rs2::pipeline& self, const rs2::config& config, rs2::frame_queue queue) { return self.start(config, queue); }, "Start the pipeline streaming according to the configuraion.\n"
125  "The pipeline captures samples from the device, and delivers them to the provided frame queue.\n"
126  "Starting the pipeline is possible only when it is not started. If the pipeline was started, an exception is raised.\n"
127  "When starting the pipeline with a callback both wait_for_frames() and poll_for_frames() will throw exception.\n"
128  "The pipeline selects and activates the device upon start, according to configuration or a default configuration.\n"
129  "When the rs2::config is provided to the method, the pipeline tries to activate the config resolve() result.\n"
130  "If the application requests are conflicting with pipeline computer vision modules or no matching device is available on the platform, the method fails.\n"
131  "Available configurations and devices may change between config resolve() call and pipeline start, in case devices are connected or disconnected, "
132  "or another application acquires ownership of a device.", "config"_a, "queue"_a)
133  .def("stop", &rs2::pipeline::stop, "Stop the pipeline streaming.\n"
134  "The pipeline stops delivering samples to the attached computer vision modules and processing blocks, stops the device streaming and releases "
135  "the device resources used by the pipeline. It is the application's responsibility to release any frame reference it owns.\n"
136  "The method takes effect only after start() was called, otherwise an exception is raised.", py::call_guard<py::gil_scoped_release>())
137  .def("wait_for_frames", &rs2::pipeline::wait_for_frames, "Wait until a new set of frames becomes available.\n"
138  "The frames set includes time-synchronized frames of each enabled stream in the pipeline.\n"
139  "In case of different frame rates of the streams, the frames set include a matching frame of the slow stream, which may have been included in previous frames set.\n"
140  "The method blocks the calling thread, and fetches the latest unread frames set.\n"
141  "Device frames, which were produced while the function wasn't called, are dropped. To avoid frame drops, this method should be called as fast as the device frame rate.\n"
142  "The application can maintain the frames handles to defer processing. However, if the application maintains too long history, "
143  "the device may lack memory resources to produce new frames, and the following call to this method shall fail to retrieve new "
144  "frames, until resources become available.", "timeout_ms"_a = 5000, py::call_guard<py::gil_scoped_release>())
145  .def("poll_for_frames", [](const rs2::pipeline &self) {
147  self.poll_for_frames(&frames);
148  return frames;
149  }, "Check if a new set of frames is available and retrieve the latest undelivered set.\n"
150  "The frames set includes time-synchronized frames of each enabled stream in the pipeline.\n"
151  "The method returns without blocking the calling thread, with status of new frames available or not.\n"
152  "If available, it fetches the latest frames set.\n"
153  "Device frames, which were produced while the function wasn't called, are dropped.\n"
154  "To avoid frame drops, this method should be called as fast as the device frame rate.\n"
155  "The application can maintain the frames handles to defer processing. However, if the application maintains too long "
156  "history, the device may lack memory resources to produce new frames, and the following calls to this method shall "
157  "return no new frames, until resources become available.")
158  .def("try_wait_for_frames", [](const rs2::pipeline &self, unsigned int timeout_ms) {
159  rs2::frameset fs;
160  auto success = self.try_wait_for_frames(&fs, timeout_ms);
161  return std::make_tuple(success, fs);
162  }, "timeout_ms"_a = 5000, py::call_guard<py::gil_scoped_release>())
163  .def("get_active_profile", &rs2::pipeline::get_active_profile); // No docstring in C++
165 }
frameset wait_for_frames(unsigned int timeout_ms=RS2_DEFAULT_TIMEOUT) const
void init_pipeline(py::module &m)
GLfloat GLfloat p
Definition: glext.h:12687
const GLfloat * m
Definition: glext.h:6814
void enable_device(const std::string &serial)
GLdouble f
const GLubyte * c
Definition: glext.h:12690
void disable_all_streams()
stream_profile get_stream(rs2_stream stream_type, int stream_index=-1) const
Definition: rs_pipeline.hpp:60
void disable_stream(rs2_stream stream, int index=-1)
void init(void)
Definition: boing.c:180
rs2_format
A stream&#39;s format identifies how binary data is encoded within a frame.
Definition: rs_sensor.h:59
void enable_all_streams()
void enable_stream(rs2_stream stream_type, int stream_index, int width, int height, rs2_format format=RS2_FORMAT_ANY, int framerate=0)
bool can_resolve(std::shared_ptr< rs2_pipeline > p) const
rs2_stream
Streams are different types of data provided by RealSense devices.
Definition: rs_sensor.h:42
device get_device() const
Definition: rs_pipeline.hpp:83
pipeline_profile resolve(std::shared_ptr< rs2_pipeline > p) const
std::vector< stream_profile > get_streams() const
Definition: rs_pipeline.hpp:29
void enable_record_to_file(const std::string &file_name)
void enable_device_from_file(const std::string &file_name, bool repeat_playback=true)
pipeline_profile get_active_profile() const
pipeline_profile start()


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:39