Intel® RealSense™ Cross Platform API
Intel Realsense Cross-platform API
pipeline.h
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2015 Intel Corporation. All Rights Reserved.
3 
4 #pragma once
5 
6 #include <map>
7 #include <utility>
8 
9 #include "device_hub.h"
10 #include "sync.h"
11 #include "config.h"
12 
13 namespace librealsense
14 {
15  class processing_block;
17  {
18  std::mutex _mutex;
19  std::map<stream_id, frame_holder> _last_set;
20  std::unique_ptr<single_consumer_queue<frame_holder>> _queue;
21  std::vector<int> _streams_ids;
22  void handle_frame(frame_holder frame, synthetic_source_interface* source);
23  public:
24  pipeline_processing_block(const std::vector<int>& streams_to_aggregate);
25  bool dequeue(frame_holder* item, unsigned int timeout_ms = 5000);
26  bool try_dequeue(frame_holder* item);
27  };
28 
29  class pipeline;
31  {
32  public:
33  pipeline_profile(std::shared_ptr<device_interface> dev, util::config config, const std::string& file = "");
34  std::shared_ptr<device_interface> get_device();
35  stream_profiles get_active_streams() const;
37  private:
38  std::shared_ptr<device_interface> _dev;
39  std::string _to_file;
40  };
41 
42  class pipeline_config;
43  class pipeline : public std::enable_shared_from_this<pipeline>
44  {
45  public:
46  //Top level API
47  explicit pipeline(std::shared_ptr<librealsense::context> ctx);
48  ~pipeline();
49  std::shared_ptr<pipeline_profile> start(std::shared_ptr<pipeline_config> conf);
50  std::shared_ptr<pipeline_profile> start_with_record(std::shared_ptr<pipeline_config> conf, const std::string& file);
51  void stop();
52  std::shared_ptr<pipeline_profile> get_active_profile() const;
53  frame_holder wait_for_frames(unsigned int timeout_ms = 5000);
54  bool poll_for_frames(frame_holder* frame);
55 
56  //Non top level API
57  std::shared_ptr<device_interface> wait_for_device(const std::chrono::milliseconds& timeout = std::chrono::hours::max(),
58  const std::string& serial = "");
59  std::shared_ptr<librealsense::context> get_context() const;
60 
61 
62  private:
63  void unsafe_start(std::shared_ptr<pipeline_config> conf);
64  void unsafe_stop();
65  std::shared_ptr<pipeline_profile> unsafe_get_active_profile() const;
66 
67  std::shared_ptr<librealsense::context> _ctx;
68  mutable std::mutex _mtx;
69  device_hub _hub;
70  std::shared_ptr<pipeline_profile> _active_profile;
72  std::unique_ptr<syncer_process_unit> _syncer;
73  std::unique_ptr<pipeline_processing_block> _pipeline_process;
74  std::shared_ptr<pipeline_config> _prev_conf;
75  int _playback_stopped_token = -1;
76  dispatcher _dispatcher;
77  };
78 
80  {
81  public:
83  void enable_stream(rs2_stream stream, int index, int width, int height, rs2_format format, int framerate);
84  void enable_all_stream();
85  void enable_device(const std::string& serial);
86  void enable_device_from_file(const std::string& file, bool repeat_playback);
87  void enable_record_to_file(const std::string& file);
88  void disable_stream(rs2_stream stream, int index = -1);
89  void disable_all_streams();
90  std::shared_ptr<pipeline_profile> resolve(std::shared_ptr<pipeline> pipe, const std::chrono::milliseconds& timeout = std::chrono::milliseconds(0));
91  bool can_resolve(std::shared_ptr<pipeline> pipe);
92  bool get_repeat_playback();
93 
94  //Non top level API
95  std::shared_ptr<pipeline_profile> get_cached_resolved_profile();
96 
98  {
99  if (this == &other)
100  return;
101 
102  _device_request = other._device_request;
103  _stream_requests = other._stream_requests;
104  _enable_all_streams = other._enable_all_streams;
105  _stream_requests = other._stream_requests;
106  _resolved_profile = nullptr;
107  _playback_loop = other._playback_loop;
108  }
109  private:
110  struct device_request
111  {
112  std::string serial;
113  std::string filename;
114  std::string record_output;
115  };
116  std::shared_ptr<device_interface> get_or_add_playback_device(std::shared_ptr<pipeline> pipe, const std::string& file);
117  std::shared_ptr<device_interface> resolve_device_requests(std::shared_ptr<pipeline> pipe, const std::chrono::milliseconds& timeout);
118  stream_profiles get_default_configuration(std::shared_ptr<device_interface> dev);
119 
120  device_request _device_request;
121  std::map<std::pair<rs2_stream, int>, util::config::request_type> _stream_requests;
122  std::mutex _mtx;
123  bool _enable_all_streams = false;
124  std::shared_ptr<pipeline_profile> _resolved_profile;
125  bool _playback_loop;
126  };
127 
128 }
pipeline_processing_block(const std::vector< int > &streams_to_aggregate)
std::shared_ptr< rs2_frame_callback > frame_callback_ptr
Definition: types.h:896
Definition: concurrency.h:125
Definition: synthetic-stream.h:41
bool try_dequeue(frame_holder *item)
Definition: device_hub.h:15
frame_processor_callback_ptr _callback
Definition: synthetic-stream.h:56
Definition: archive.h:63
Definition: algo.h:16
Definition: pipeline.h:30
Definition: config.h:29
rs2_format
Format identifies how binary data is encoded within a frame.
Definition: rs_sensor.h:55
std::vector< std::shared_ptr< stream_profile_interface >> stream_profiles
Definition: streaming.h:104
rs2_stream
Streams are different types of data provided by RealSense devices.
Definition: rs_sensor.h:38
Definition: stream.h:14
Definition: types.h:637
Definition: processing.h:19
bool dequeue(frame_holder *item, unsigned int timeout_ms=5000)
pipeline_config(const pipeline_config &other)
Definition: pipeline.h:97
Definition: pipeline.h:79
Definition: pipeline.h:43
util::config::multistream _multistream
Definition: pipeline.h:36