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();
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);
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;
71  frame_callback_ptr _callback;
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);
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 
93  //Non top level API
94  std::shared_ptr<pipeline_profile> get_cached_resolved_profile();
95 
97  {
98  if (this == &other)
99  return;
100 
101  _device_request = other._device_request;
102  _stream_requests = other._stream_requests;
103  _enable_all_streams = other._enable_all_streams;
104  _stream_requests = other._stream_requests;
105  _resolved_profile = nullptr;
106  }
107  private:
108  struct device_request
109  {
110  std::string serial;
111  std::string filename;
112  std::string record_output;
113  };
114  std::shared_ptr<device_interface> get_or_add_playback_device(std::shared_ptr<pipeline> pipe, const std::string& file);
115  std::shared_ptr<device_interface> resolve_device_requests(std::shared_ptr<pipeline> pipe, const std::chrono::milliseconds& timeout);
116  stream_profiles get_default_configuration(std::shared_ptr<device_interface> dev);
117 
118  device_request _device_request;
119  std::map<std::pair<rs2_stream, int>, util::config::request_type> _stream_requests;
120  std::mutex _mtx;
121  bool _enable_all_streams = false;
122  std::shared_ptr<pipeline_profile> _resolved_profile;
123  };
124 
125 }
pipeline_processing_block(const std::vector< int > &streams_to_aggregate)
void enable_device(const std::string &serial)
std::shared_ptr< rs2_frame_callback > frame_callback_ptr
Definition: types.h:822
bool poll_for_frames(frame_holder *frame)
std::shared_ptr< pipeline_profile > resolve(std::shared_ptr< pipeline > pipe, const std::chrono::milliseconds &timeout=std::chrono::milliseconds(0))
std::shared_ptr< device_interface > get_device()
std::shared_ptr< pipeline_profile > get_active_profile() const
void enable_stream(rs2_stream stream, int index, int width, int height, rs2_format format, int framerate)
std::shared_ptr< pipeline_profile > start_with_record(std::shared_ptr< pipeline_config > conf, const std::string &file)
Definition: concurrency.h:125
Definition: synthetic-stream.h:41
void enable_device_from_file(const std::string &file)
bool try_dequeue(frame_holder *item)
Definition: device_hub.h:15
Definition: archive.h:63
Definition: algo.h:16
std::shared_ptr< librealsense::context > get_context() const
stream_profiles get_active_streams() const
pipeline(std::shared_ptr< librealsense::context > ctx)
std::shared_ptr< pipeline_profile > start(std::shared_ptr< pipeline_config > conf)
Definition: pipeline.h:30
void enable_record_to_file(const std::string &file)
Definition: config.h:29
rs2_format
Format identifies how binary data is encoded within a frame.
Definition: rs_sensor.h:52
rs2_stream
Streams are different types of data provided by RealSense devices.
Definition: rs_sensor.h:36
std::shared_ptr< device_interface > wait_for_device(const std::chrono::milliseconds &timeout=std::chrono::hours::max(), const std::string &serial="")
std::shared_ptr< pipeline_profile > get_cached_resolved_profile()
Definition: stream.h:14
Definition: types.h:587
frame_holder wait_for_frames(unsigned int timeout_ms=5000)
Definition: processing.h:19
void disable_stream(rs2_stream stream, int index=-1)
bool dequeue(frame_holder *item, unsigned int timeout_ms=5000)
std::vector< std::shared_ptr< stream_profile_interface > > stream_profiles
Definition: streaming.h:104
pipeline_config(const pipeline_config &other)
Definition: pipeline.h:96
Definition: pipeline.h:79
bool can_resolve(std::shared_ptr< pipeline > pipe)
Definition: pipeline.h:43
util::config::multistream _multistream
Definition: pipeline.h:36
pipeline_profile(std::shared_ptr< device_interface > dev, util::config config, const std::string &file="")