6 #include "../../include/librealsense2/h/rs_internal.h" 64 int dist(uint32_t x, uint32_t y)
const;
66 std::vector<uint8_t> decode(
const std::vector<uint8_t>& input)
const;
68 std::vector<uint8_t> encode(uint8_t* data,
size_t size)
const;
88 bool had_error =
false;
110 recording(std::shared_ptr<time_service> ts =
nullptr, std::shared_ptr<playback_device_watcher> watcher =
nullptr);
113 void save(
const char* filename,
const char* section,
bool append =
false)
const;
114 static std::shared_ptr<recording> load(
const char* filename,
const char* section, std::shared_ptr<playback_device_watcher> watcher =
nullptr);
116 int save_blob(
const void* ptr,
size_t size);
119 std::pair<int, int>
insert_list(std::vector<T> list, std::vector<T>& target)
121 std::pair<int, int> range;
123 range.first =
static_cast<int>(target.size());
124 for (
auto&& i : list) target.push_back(i);
125 range.second =
static_cast<int>(target.size());
133 std::lock_guard<std::recursive_mutex> lock(_mutex);
137 auto range = insert_list(list, target);
147 std::lock_guard<std::recursive_mutex> lock(_mutex);
153 return calls[calls.size() - 1];
159 std::vector<T> results;
160 std::lock_guard<std::recursive_mutex> lock(_mutex);
163 results.push_back(source[i]);
169 std::vector<T>
load_list(
const std::vector<T>& source,
const int range_start,
const int range_end)
171 std::vector<T> results;
172 std::lock_guard<std::recursive_mutex> lock(_mutex);
173 for (
auto i = range_start; i < range_end; i++)
175 results.push_back(source[i]);
181 std::lock_guard<std::recursive_mutex> lock(_mutex);
186 auto range = insert_list(old.
uvc_devices, uvc_device_infos);
190 range = insert_list(old.
usb_devices, usb_device_infos);
194 range = insert_list(old.
hid_devices, hid_device_infos);
198 range = insert_list(curr.
uvc_devices, uvc_device_infos);
202 range = insert_list(curr.
usb_devices, usb_device_infos);
206 range = insert_list(curr.
hid_devices, hid_device_infos);
247 auto&& c = find_call(type,
id);
255 old.
uvc_devices = load_list(uvc_device_infos, c.param1, c.param2);
256 old.
usb_devices = load_list(usb_device_infos, c.param3, c.param4);
257 old.
hid_devices = load_list(hid_device_infos, c.param5, c.param6);
259 curr.
uvc_devices = load_list(uvc_device_infos, c.param7, c.param8);
260 curr.
usb_devices = load_list(usb_device_infos, c.param9, c.param10);
261 curr.
hid_devices = load_list(hid_device_infos, c.param11, c.param12);
268 return load_list(usb_device_infos, c);
274 return load_list(uvc_device_infos, c);
280 return load_list(hid_device_infos, c);
286 return load_list(hid_sensors, c);
294 call& find_call(
call_type t,
int entity_id, std::function<
bool(
const call& c)> history_match_validation = [](
const call& c) {
return true; });
296 call* pick_next_call(
int id = 0);
297 size_t size()
const {
return calls.size(); }
300 std::vector<call> calls;
301 std::vector<std::vector<uint8_t>> blobs;
302 std::vector<uvc_device_info> uvc_device_infos;
303 std::vector<usb_device_info> usb_device_infos;
305 std::vector<hid_device_info> hid_device_infos;
306 std::vector<hid_sensor> hid_sensors;
307 std::vector<hid_sensor_input> hid_sensor_inputs;
308 std::shared_ptr<playback_device_watcher> _watcher;
310 std::recursive_mutex _mutex;
311 std::shared_ptr<time_service> _ts;
313 std::map<size_t, size_t> _cursors;
314 std::map<size_t, size_t> _cycles;
316 double get_current_time();
318 void invoke_device_changed_event();
320 double _curr_time = 0;
330 void start_callbacks()
override;
331 void stop_callbacks()
override;
336 bool set_xu(
const extension_unit& xu, uint8_t ctrl,
const uint8_t* data,
int len)
override;
337 bool get_xu(
const extension_unit& xu, uint8_t ctrl, uint8_t* data,
int len)
const override;
340 bool set_pu(
rs2_option opt, int32_t value)
override;
342 std::vector<stream_profile> get_profiles()
const override;
343 void lock()
const override;
344 void unlock()
const override;
345 std::string get_device_location()
const override;
346 usb_spec get_usb_specification()
const override;
349 std::shared_ptr<uvc_device> source,
350 std::shared_ptr<compression_algorithm> compression,
352 : _source(source), _entity_id(id),
353 _compression(compression), _owner(owner) {}
356 std::shared_ptr<uvc_device> _source;
358 std::shared_ptr<compression_algorithm> _compression;
365 void open(
const std::vector<hid_profile>& hid_profiles)
override;
366 void close()
override;
367 void stop_capture()
override;
369 std::vector<hid_sensor> get_sensors()
override;
370 std::vector<uint8_t> get_custom_report_data(
const std::string& custom_sensor_name,
371 const std::string& report_name,
376 : _source(source), _entity_id(id), _owner(owner) {}
379 std::shared_ptr<hid_device> _source;
387 std::vector<uint8_t> send_receive(
const std::vector<uint8_t>& data,
int timeout_ms,
bool require_response)
override;
391 : _source(source), _entity_id(id), _owner(owner) {}
394 std::shared_ptr<usb_device> _source;
404 _source_watcher(source_watcher), _owner(owner), _entity_id(id) {}
413 void stop()
override;
417 std::shared_ptr<device_watcher> _source_watcher;
430 std::shared_ptr<time_service> create_time_service()
const override;
431 std::shared_ptr<device_watcher> create_device_watcher()
const override;
434 const char* filename,
449 return t(_rec.get(), k);
451 catch (
const std::exception& ex)
453 auto&& c = _rec->add_call(k);
455 c.inline_string = ex.what();
461 auto&& c = _rec->add_call(k);
463 c.inline_string =
"Unknown exception has occurred!";
470 void write_to_file()
const;
472 std::shared_ptr<backend> _source;
474 std::shared_ptr<recording> _rec;
475 mutable std::atomic<int> _entity_count;
476 std::string _filename;
477 std::string _section;
478 std::shared_ptr<compression_algorithm> _compression;
491 void stop()
override;
497 std::atomic<bool> _alive;
498 std::thread _callback_thread;
501 std::recursive_mutex _mutex;
509 void start_callbacks()
override;
510 void stop_callbacks()
override;
515 bool set_xu(
const extension_unit& xu, uint8_t ctrl,
const uint8_t* data,
int len)
override;
516 bool get_xu(
const extension_unit& xu, uint8_t ctrl, uint8_t* data,
int len)
const override;
519 bool set_pu(
rs2_option opt, int32_t value)
override;
521 std::vector<stream_profile> get_profiles()
const override;
522 void lock()
const override;
523 void unlock()
const override;
524 std::string get_device_location()
const override;
525 usb_spec get_usb_specification()
const override;
529 void callback_thread();
535 std::shared_ptr<recording> _rec;
537 std::atomic<bool> _alive;
538 std::thread _callback_thread;
539 configurations _callbacks;
540 configurations _commitments;
541 std::mutex _callback_mutex;
549 std::vector<uint8_t> send_receive(
const std::vector<uint8_t>& data,
int timeout_ms,
bool require_response)
override;
552 int id) : _rec(rec), _entity_id(id) {}
555 std::shared_ptr<recording> _rec;
562 void open(
const std::vector<hid_profile>& hid_profiles)
override;
563 void close()
override;
564 void stop_capture()
override;
566 std::vector<hid_sensor> get_sensors()
override;
567 std::vector<uint8_t> get_custom_report_data(
const std::string& custom_sensor_name,
568 const std::string& report_name,
570 void callback_thread();
576 std::shared_ptr<recording> _rec;
577 std::mutex _callback_mutex;
580 std::thread _callback_thread;
581 std::atomic<bool> _alive;
593 std::shared_ptr<time_service> create_time_service()
const override;
594 std::shared_ptr<device_watcher> create_device_watcher()
const override;
599 std::shared_ptr<playback_device_watcher> _device_watcher;
600 std::shared_ptr<recording> _rec;
611 return _rec.get_time();
rs2_option
Defines general configuration controls. These can generally be mapped to camera UVC controls...
Definition: rs_option.h:22
rs2_recording_mode
Definition: rs_internal.h:25
Definition: concurrency.h:125
std::vector< std::shared_ptr< stream_profile_interface >> stream_profiles
Definition: streaming.h:104
double rs2_time_t
Definition: rs_types.h:179
double get_time()
Definition: rs_internal.hpp:61