Intel® RealSense™ Cross Platform API  2.13.0
Intel Realsense Cross-platform API
rs_record_playback.hpp
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 #ifndef LIBREALSENSE_RS2_RECORD_PLAYBACK_HPP
5 #define LIBREALSENSE_RS2_RECORD_PLAYBACK_HPP
6 
7 #include "rs_types.hpp"
8 #include "rs_device.hpp"
9 
10 namespace rs2
11 {
12  template<class T>
14  {
15  T on_status_changed_function;
16  public:
17  explicit status_changed_callback(T on_status_changed) : on_status_changed_function(on_status_changed) {}
18 
20  {
21  on_status_changed_function(status);
22  }
23 
24  void release() override { delete this; }
25  };
26 
27  class playback : public device
28  {
29  public:
30  playback(device d) : playback(d.get()) {}
31 
37  void pause()
38  {
39  rs2_error* e = nullptr;
41  error::handle(e);
42  }
43 
48  void resume()
49  {
50  rs2_error* e = nullptr;
52  error::handle(e);
53  }
54 
59  std::string file_name() const
60  {
61  return m_file; //cached in construction
62  }
63 
68  uint64_t get_position() const
69  {
70  rs2_error* e = nullptr;
71  uint64_t pos = rs2_playback_get_position(_dev.get(), &e);
72  error::handle(e);
73  return pos;
74  }
75 
80  std::chrono::nanoseconds get_duration() const
81  {
82  rs2_error* e = nullptr;
83  std::chrono::nanoseconds duration(rs2_playback_get_duration(_dev.get(), &e));
84  error::handle(e);
85  return duration;
86  }
87 
92  void seek(std::chrono::nanoseconds time)
93  {
94  rs2_error* e = nullptr;
95  rs2_playback_seek(_dev.get(), time.count(), &e);
96  error::handle(e);
97  }
98 
103  bool is_real_time() const
104  {
105  rs2_error* e = nullptr;
106  bool real_time = rs2_playback_device_is_real_time(_dev.get(), &e) != 0;
107  error::handle(e);
108  return real_time;
109  }
110 
122  void set_real_time(bool real_time) const
123  {
124  rs2_error* e = nullptr;
125  rs2_playback_device_set_real_time(_dev.get(), (real_time ? 1 : 0), &e);
126  error::handle(e);
127  }
128 
133  void set_playback_speed(float speed) const
134  {
135  rs2_error* e = nullptr;
137  error::handle(e);
138  }
139 
152  template <typename T>
154  {
155  rs2_error* e = nullptr;
157  error::handle(e);
158  }
159 
165  {
166  rs2_error* e = nullptr;
168  error::handle(e);
169  return sts;
170  }
171 
176  void stop()
177  {
178  rs2_error* e = nullptr;
179  rs2_playback_device_stop(_dev.get(), &e);
180  error::handle(e);
181  }
182  protected:
183  friend context;
184  explicit playback(std::shared_ptr<rs2_device> dev) : device(dev)
185  {
186  rs2_error* e = nullptr;
187  if(rs2_is_device_extendable_to(_dev.get(), RS2_EXTENSION_PLAYBACK, &e) == 0 && !e)
188  {
189  _dev.reset();
190  }
191  error::handle(e);
192 
193  if(_dev)
194  {
195  e = nullptr;
196  m_file = rs2_playback_device_get_file_path(_dev.get(), &e);
197  error::handle(e);
198  }
199  }
200  private:
201  std::string m_file;
202  };
203  class recorder : public device
204  {
205  public:
207 
213  recorder(const std::string& file, rs2::device device)
214  {
215  rs2_error* e = nullptr;
216  _dev = std::shared_ptr<rs2_device>(
217  rs2_create_record_device(device.get().get(), file.c_str(), &e),
220  }
221 
225  void pause()
226  {
227  rs2_error* e = nullptr;
228  rs2_record_device_pause(_dev.get(), &e);
229  error::handle(e);
230  }
231 
235  void resume()
236  {
237  rs2_error* e = nullptr;
238  rs2_record_device_resume(_dev.get(), &e);
239  error::handle(e);
240  }
241 
246  std::string filename() const
247  {
248  rs2_error* e = nullptr;
249  std::string filename = rs2_record_device_filename(_dev.get(), &e);
250  error::handle(e);
251  return filename;
252  }
253  protected:
254  explicit recorder(std::shared_ptr<rs2_device> dev) : device(dev)
255  {
256  rs2_error* e = nullptr;
257  if (rs2_is_device_extendable_to(_dev.get(), RS2_EXTENSION_RECORD, &e) == 0 && !e)
258  {
259  _dev.reset();
260  }
261  error::handle(e);
262  }
263  };
264 }
265 #endif // LIBREALSENSE_RS2_RECORD_PLAYBACK_HPP
const char * rs2_playback_device_get_file_path(const rs2_device *device, rs2_error **error)
void on_playback_status_changed(rs2_playback_status status) override
Definition: rs_record_playback.hpp:19
Definition: rs_record_playback.hpp:27
uint64_t get_position() const
Definition: rs_record_playback.hpp:68
std::string file_name() const
Definition: rs_record_playback.hpp:59
void seek(std::chrono::nanoseconds time)
Definition: rs_record_playback.hpp:92
void rs2_playback_seek(const rs2_device *device, long long int time, rs2_error **error)
recorder(device d)
Definition: rs_record_playback.hpp:206
void rs2_delete_device(rs2_device *device)
void rs2_playback_device_set_status_changed_callback(const rs2_device *device, rs2_playback_status_changed_callback *callback, rs2_error **error)
void rs2_record_device_pause(const rs2_device *device, rs2_error **error)
int rs2_playback_device_is_real_time(const rs2_device *device, rs2_error **error)
void rs2_playback_device_pause(const rs2_device *device, rs2_error **error)
Definition: rs_types.hpp:60
Definition: rs_context.hpp:11
void set_real_time(bool real_time) const
Definition: rs_record_playback.hpp:122
void resume()
Definition: rs_record_playback.hpp:48
void rs2_playback_device_stop(const rs2_device *device, rs2_error **error)
unsigned long long int rs2_playback_get_position(const rs2_device *device, rs2_error **error)
void rs2_record_device_resume(const rs2_device *device, rs2_error **error)
std::chrono::nanoseconds get_duration() const
Definition: rs_record_playback.hpp:80
void pause()
Definition: rs_record_playback.hpp:225
int rs2_is_device_extendable_to(const rs2_device *device, rs2_extension extension, rs2_error **error)
playback(std::shared_ptr< rs2_device > dev)
Definition: rs_record_playback.hpp:184
const std::shared_ptr< rs2_device > & get() const
Definition: rs_device.hpp:116
Definition: rs_record_playback.hpp:203
void set_playback_speed(float speed) const
Definition: rs_record_playback.hpp:133
void resume()
Definition: rs_record_playback.hpp:235
rs2_playback_status
Definition: rs_record_playback.h:19
std::shared_ptr< rs2_device > _dev
Definition: rs_device.hpp:143
std::string filename() const
Definition: rs_record_playback.hpp:246
recorder(const std::string &file, rs2::device device)
Definition: rs_record_playback.hpp:213
void pause()
Definition: rs_record_playback.hpp:37
Definition: rs_types.h:110
rs2_playback_status current_status() const
Definition: rs_record_playback.hpp:164
friend context
Definition: rs_record_playback.hpp:183
recorder(std::shared_ptr< rs2_device > dev)
Definition: rs_record_playback.hpp:254
void stop()
Definition: rs_record_playback.hpp:176
void release() override
Definition: rs_record_playback.hpp:24
unsigned long long int rs2_playback_get_duration(const rs2_device *device, rs2_error **error)
static void handle(rs2_error *e)
Definition: rs_types.hpp:121
Definition: rs_record_playback.hpp:13
status_changed_callback(T on_status_changed)
Definition: rs_record_playback.hpp:17
bool is_real_time() const
Definition: rs_record_playback.hpp:103
rs2_device * rs2_create_record_device(const rs2_device *device, const char *file, rs2_error **error)
playback(device d)
Definition: rs_record_playback.hpp:30
rs2_playback_status rs2_playback_device_get_current_status(const rs2_device *device, rs2_error **error)
struct rs2_error rs2_error
Definition: rs_types.h:149
Definition: rs_types.h:112
Definition: rs_device.hpp:18
const char * rs2_record_device_filename(const rs2_device *device, rs2_error **error)
void rs2_playback_device_resume(const rs2_device *device, rs2_error **error)
void rs2_playback_device_set_real_time(const rs2_device *device, int real_time, rs2_error **error)
void rs2_playback_device_set_playback_speed(const rs2_device *device, float speed, rs2_error **error)
void set_status_changed_callback(T callback)
Definition: rs_record_playback.hpp:153