Intel® RealSense™ Cross Platform API
Intel Realsense Cross-platform API
types.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 // This header defines vocabulary types and utility mechanisms used ubiquitously by the
5 // rest of the library. As clearer module boundaries form, declarations might be moved
6 // out of this file and into more appropriate locations.
7 
8 #pragma once
9 #ifndef LIBREALSENSE_TYPES_H
10 #define LIBREALSENSE_TYPES_H
11 
12 #include "../include/librealsense2/hpp/rs_types.hpp"
13 
14 #include <stdint.h>
15 #include <cassert> // For assert
16 #include <cstring> // For memcmp
17 #include <vector> // For vector
18 #include <sstream> // For ostringstream
19 #include <mutex> // For mutex, unique_lock
20 #include <memory> // For unique_ptr
21 #include <map>
22 #include <limits>
23 #include <algorithm>
24 #include <condition_variable>
25 #include <functional>
26 #include <utility> // For std::forward
27 #include "backend.h"
28 #include "concurrency.h"
29 #if BUILD_EASYLOGGINGPP
30 #include "../third-party/easyloggingpp/src/easylogging++.h"
31 #endif // BUILD_EASYLOGGINGPP
32 
33 typedef unsigned char byte;
34 
35 const int RS2_USER_QUEUE_SIZE = 128;
36 
37 #ifndef DBL_EPSILON
38 const double DBL_EPSILON = 2.2204460492503131e-016; // smallest such that 1.0+DBL_EPSILON != 1.0
39 #endif
40 
41 #pragma warning(disable: 4250)
42 
43 #ifdef ANDROID
44 #include "../common/android_helpers.h"
45 #endif
46 
47 namespace librealsense
48 {
49  #define UNKNOWN_VALUE "UNKNOWN"
50 
52  // Utility types for general use //
54  struct to_string
55  {
56  std::ostringstream ss;
57  template<class T> to_string & operator << (const T & val) { ss << val; return *this; }
58  operator std::string() const { return ss.str(); }
59  };
60 
61  template<typename T, size_t size>
62  inline size_t copy_array(T(&dst)[size], const T(&src)[size])
63  {
64  assert(dst != nullptr && src != nullptr);
65  for (size_t i = 0; i < size; i++)
66  {
67  dst[i] = src[i];
68  }
69  return size;
70  }
71 
72  template<typename T, size_t sizem, size_t sizen>
73  inline size_t copy_2darray(T(&dst)[sizem][sizen], const T(&src)[sizem][sizen])
74  {
75  assert(dst != nullptr && src != nullptr);
76  for (size_t i = 0; i < sizem; i++)
77  {
78  for (size_t j = 0; j < sizen; j++)
79  {
80  dst[i][j] = src[i][j];
81  }
82  }
83  return sizem * sizen;
84  }
85 
86  void copy(void* dst, void const* src, size_t size);
87 
88  std::string make_less_screamy(const char* str);
89 
91  // Logging mechanism //
93 
94  void log_to_console(rs2_log_severity min_severity);
95  void log_to_file(rs2_log_severity min_severity, const char * file_path);
96 
97 #if BUILD_EASYLOGGINGPP
98 
99 #define LOG_DEBUG(...) do { CLOG(DEBUG ,"librealsense") << __VA_ARGS__; } while(false)
100 #define LOG_INFO(...) do { CLOG(INFO ,"librealsense") << __VA_ARGS__; } while(false)
101 #define LOG_WARNING(...) do { CLOG(WARNING ,"librealsense") << __VA_ARGS__; } while(false)
102 #define LOG_ERROR(...) do { CLOG(ERROR ,"librealsense") << __VA_ARGS__; } while(false)
103 #define LOG_FATAL(...) do { CLOG(FATAL ,"librealsense") << __VA_ARGS__; } while(false)
104 
105 #else // BUILD_EASYLOGGINGPP
106 
107 #define LOG_DEBUG(...) do { ; } while(false)
108 #define LOG_INFO(...) do { ; } while(false)
109 #define LOG_WARNING(...) do { ; } while(false)
110 #define LOG_ERROR(...) do { ; } while(false)
111 #define LOG_FATAL(...) do { ; } while(false)
112 
113 #endif // BUILD_EASYLOGGINGPP
114 
115  // Enhancement for debug mode that incurs performance penalty with STL
116  // std::clamp to be introduced with c++17
117  template< typename T>
118  inline T clamp_val(T val, const T& min, const T& max)
119  {
120  static_assert((std::is_arithmetic<T>::value), "clamping supports arithmetic built-in types only");
121 #ifdef _DEBUG
122  const T t = val < min ? min : val;
123  return t > max ? max : t;
124 #else
125  return std::min(std::max(val, min), max);
126 #endif
127  }
128 
130  // Exceptions mechanism //
132 
133 
134  class librealsense_exception : public std::exception
135  {
136  public:
137  const char* get_message() const noexcept
138  {
139  return _msg.c_str();
140  }
141 
143  {
144  return _exception_type;
145  }
146 
147  const char* what() const noexcept override
148  {
149  return _msg.c_str();
150  }
151 
152  protected:
153  librealsense_exception(const std::string& msg,
154  rs2_exception_type exception_type) noexcept
155  : _msg(msg),
156  _exception_type(exception_type)
157  {}
158 
159  private:
160  std::string _msg;
161  rs2_exception_type _exception_type;
162  };
163 
165  {
166  public:
167  recoverable_exception(const std::string& msg,
168  rs2_exception_type exception_type) noexcept;
169  };
170 
172  {
173  public:
174  unrecoverable_exception(const std::string& msg,
175  rs2_exception_type exception_type) noexcept
176  : librealsense_exception(msg, exception_type)
177  {
178  LOG_ERROR(msg);
179  }
180  };
182  {
183  public:
184  io_exception(const std::string& msg) noexcept
186  {}
187  };
189  {
190  public:
191  camera_disconnected_exception(const std::string& msg) noexcept
193  {}
194  };
195 
197  {
198  public:
199  backend_exception(const std::string& msg,
200  rs2_exception_type exception_type) noexcept
201  : unrecoverable_exception(msg, exception_type)
202  {}
203  };
204 
206  {
207  public:
208  linux_backend_exception(const std::string& msg) noexcept
209  : backend_exception(generate_last_error_message(msg), RS2_EXCEPTION_TYPE_BACKEND)
210  {}
211 
212  private:
213  std::string generate_last_error_message(const std::string& msg) const
214  {
215  return msg + " Last Error: " + strerror(errno);
216  }
217  };
218 
220  {
221  public:
222  // TODO: get last error
223  windows_backend_exception(const std::string& msg) noexcept
225  {}
226  };
227 
229  {
230  public:
231  invalid_value_exception(const std::string& msg) noexcept
233  {}
234  };
235 
237  {
238  public:
239  wrong_api_call_sequence_exception(const std::string& msg) noexcept
241  {}
242  };
243 
245  {
246  public:
247  not_implemented_exception(const std::string& msg) noexcept
249  {}
250  };
251 
252 
253 #pragma pack(push, 1)
254  template<class T> class big_endian
255  {
256  T be_value;
257  public:
258  operator T () const
259  {
260  T le_value = 0;
261  for (unsigned int i = 0; i < sizeof(T); ++i) reinterpret_cast<char *>(&le_value)[i] = reinterpret_cast<const char *>(&be_value)[sizeof(T) - i - 1];
262  return le_value;
263  }
264  };
265 #pragma pack(pop)
266 
267  template <class T>
268  class lazy
269  {
270  public:
271  lazy() : _init([]() { T t{}; return t; }) {}
272  lazy(std::function<T()> initializer) : _init(std::move(initializer)) {}
273 
274  T* operator->() const
275  {
276  return operate();
277  }
278 
280  {
281  return *operate();
282  }
283 
284  const T& operator*() const
285  {
286  return *operate();
287  }
288 
289  lazy(lazy&& other) noexcept
290  {
291  std::lock_guard<std::mutex> lock(other._mtx);
292  if (!other._was_init)
293  {
294  _init = move(other._init);
295  _was_init = false;
296  }
297  else
298  {
299  _init = move(other._init);
300  _was_init = true;
301  _ptr = move(other._ptr);
302  }
303  }
304 
305  lazy& operator=(std::function<T()> func) noexcept
306  {
307  return *this = lazy<T>(std::move(func));
308  }
309 
310  lazy& operator=(lazy&& other) noexcept
311  {
312  std::lock_guard<std::mutex> lock1(_mtx);
313  std::lock_guard<std::mutex> lock2(other._mtx);
314  if (!other._was_init)
315  {
316  _init = move(other._init);
317  _was_init = false;
318  }
319  else
320  {
321  _init = move(other._init);
322  _was_init = true;
323  _ptr = move(other._ptr);
324  }
325 
326  return *this;
327  }
328 
329  private:
330  T* operate() const
331  {
332  std::lock_guard<std::mutex> lock(_mtx);
333  if (!_was_init)
334  {
335  _ptr = std::unique_ptr<T>(new T(_init()));
336  _was_init = true;
337  }
338  return _ptr.get();
339  }
340 
341  mutable std::mutex _mtx;
342  mutable bool _was_init = false;
343  std::function<T()> _init;
344  mutable std::unique_ptr<T> _ptr;
345  };
346 
347  class unique_id
348  {
349  public:
350  static uint64_t generate_id()
351  {
352  static std::atomic<uint64_t> id(0);
353  return ++id;
354  }
355 
356  unique_id(const unique_id&) = delete;
357  unique_id& operator=(const unique_id&) = delete;
358  };
359 
360  template<typename T, int sz>
361  int arr_size(T(&)[sz])
362  {
363  return sz;
364  }
365 
366  template<typename T>
367  std::string array2str(T& data)
368  {
369  std::stringstream ss;
370  for (auto i = 0; i < arr_size(data); i++)
371  ss << " [" << i << "] = " << data[i] << "\t";
372  return ss.str();
373  }
374 
375  typedef float float_4[4];
376 
378  // Enumerated type support //
380 
381 
382 #define RS2_ENUM_HELPERS(TYPE, PREFIX) const char* get_string(TYPE value); \
383  inline bool is_valid(TYPE value) { return value >= 0 && value < RS2_##PREFIX##_COUNT; } \
384  inline std::ostream & operator << (std::ostream & out, TYPE value) { if(is_valid(value)) return out << get_string(value); else return out << (int)value; } \
385  inline bool try_parse(const std::string& str, TYPE& res) \
386  { \
387  for (int i = 0; i < static_cast<int>(RS2_ ## PREFIX ## _COUNT); i++) { \
388  auto v = static_cast<TYPE>(i); \
389  if(str == get_string(v)) { res = v; return true; } \
390  } \
391  return false; \
392  }
393 
396  RS2_ENUM_HELPERS(rs2_distortion, DISTORTION)
398  RS2_ENUM_HELPERS(rs2_camera_info, CAMERA_INFO)
400  RS2_ENUM_HELPERS(rs2_timestamp_domain, TIMESTAMP_DOMAIN)
401  RS2_ENUM_HELPERS(rs2_sr300_visual_preset, SR300_VISUAL_PRESET)
402  RS2_ENUM_HELPERS(rs2_extension, EXTENSION)
403  RS2_ENUM_HELPERS(rs2_exception_type, EXCEPTION_TYPE)
404  RS2_ENUM_HELPERS(rs2_log_severity, LOG_SEVERITY)
405  RS2_ENUM_HELPERS(rs2_notification_category, NOTIFICATION_CATEGORY)
406  RS2_ENUM_HELPERS(rs2_playback_status, PLAYBACK_STATUS)
409  // World's tiniest linear algebra library //
411 #pragma pack(push, 1)
412  struct int2 { int x, y; };
413  struct float2 { float x, y; float & operator [] (int i) { return (&x)[i]; } };
414  struct float3 { float x, y, z; float & operator [] (int i) { return (&x)[i]; } };
415  struct float4 { float x, y, z, w; float & operator [] (int i) { return (&x)[i]; } };
416  struct float3x3 { float3 x, y, z; float & operator () (int i, int j) { return (&x)[j][i]; } }; // column-major
418 #pragma pack(pop)
419  inline bool operator == (const float3 & a, const float3 & b) { return a.x == b.x && a.y == b.y && a.z == b.z; }
420  inline float3 operator + (const float3 & a, const float3 & b) { return{ a.x + b.x, a.y + b.y, a.z + b.z }; }
421  inline float3 operator * (const float3 & a, float b) { return{ a.x*b, a.y*b, a.z*b }; }
422  inline bool operator == (const float4 & a, const float4 & b) { return a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w; }
423  inline float4 operator + (const float4 & a, const float4 & b) { return{ a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w }; }
424  inline bool operator == (const float3x3 & a, const float3x3 & b) { return a.x == b.x && a.y == b.y && a.z == b.z; }
425  inline float3 operator * (const float3x3 & a, const float3 & b) { return a.x*b.x + a.y*b.y + a.z*b.z; }
426  inline float3x3 operator * (const float3x3 & a, const float3x3 & b) { return{ a*b.x, a*b.y, a*b.z }; }
427  inline float3x3 transpose(const float3x3 & a) { return{ {a.x.x,a.y.x,a.z.x}, {a.x.y,a.y.y,a.z.y}, {a.x.z,a.y.z,a.z.z} }; }
428  inline bool operator == (const pose & a, const pose & b) { return a.orientation == b.orientation && a.position == b.position; }
429  inline float3 operator * (const pose & a, const float3 & b) { return a.orientation * b + a.position; }
430  inline pose operator * (const pose & a, const pose & b) { return{ a.orientation * b.orientation, a * b.position }; }
431  inline pose inverse(const pose & a) { auto inv = transpose(a.orientation); return{ inv, inv * a.position * -1 }; }
432  inline pose to_pose(const rs2_extrinsics& a)
433  {
434  pose r{};
435  for (int i = 0; i < 3; i++) r.position[i] = a.translation[i];
436  for (int j = 0; j < 3; j++)
437  for (int i = 0; i < 3; i++)
438  r.orientation(i, j) = a.rotation[j * 3 + i];
439  return r;
440  }
442  {
443  rs2_extrinsics r;
444  for (int i = 0; i < 3; i++) r.translation[i] = a.position[i];
445  for (int j = 0; j < 3; j++)
446  for (int i = 0; i < 3; i++)
447  r.rotation[j * 3 + i] = a.orientation(i, j);
448  return r;
449  }
451  rs2_extrinsics r;
452  // Do it the silly way to avoid infite warnings about the dangers of memset
453  for (int i = 0; i < 3; i++) r.translation[i] = 0.f;
454  for (int j = 0; j < 3; j++)
455  for (int i = 0; i < 3; i++)
456  r.rotation[j * 3 + i] = (i == j) ? 1.f : 0.f;
457  return r;
458  }
459  inline rs2_extrinsics inverse(const rs2_extrinsics& a) { auto p = to_pose(a); return from_pose(inverse(p)); }
460 
462  // Pixel formats //
464 
465  typedef std::tuple<uint32_t, int, size_t> native_pixel_format_tuple;
466  typedef std::tuple<rs2_stream, int, rs2_format> output_tuple;
467  typedef std::tuple<platform::stream_profile_tuple, native_pixel_format_tuple, std::vector<output_tuple>> request_mapping_tuple;
468 
470  {
472  int index;
473  uint32_t width, height, fps;
475  };
476 
477 
478  inline bool operator==(const stream_profile& a,
479  const stream_profile& b)
480  {
481  return (a.width == b.width) &&
482  (a.height == b.height) &&
483  (a.fps == b.fps) &&
484  (a.format == b.format) &&
485  (a.index == b.index);
486  }
487 
489  {
492 
494  int index;
495  };
496 
498  {
500  void(*unpack)(byte * const dest[], const byte * source, int count);
501  std::vector<std::pair<stream_descriptor, rs2_format>> outputs;
502 
503  bool satisfies(const stream_profile& request) const
504  {
505  return provides_stream(request.stream, request.index) &&
506  get_format(request.stream, request.index) == request.format;
507  }
508 
509  bool provides_stream(rs2_stream stream, int index) const
510  {
511  for (auto & o : outputs)
512  if (o.first.type == stream && o.first.index == index)
513  return true;
514 
515  return false;
516  }
518  {
519  for (auto & o : outputs)
520  if (o.first.type == stream && o.first.index == index)
521  return o.second;
522 
523  throw invalid_value_exception("missing output");
524  }
525 
526  operator std::vector<output_tuple>()
527  {
528  std::vector<output_tuple> tuple_outputs;
529 
530  for (auto output : outputs)
531  {
532  tuple_outputs.push_back(std::make_tuple(output.first.type, output.first.index, output.second));
533  }
534  return tuple_outputs;
535  }
536 
537  };
538 
540  {
541  uint32_t fourcc;
544  std::vector<pixel_format_unpacker> unpackers;
545 
546  size_t get_image_size(int width, int height) const { return width * height * plane_count * bytes_per_pixel; }
547 
548  operator native_pixel_format_tuple() const
549  {
550  return std::make_tuple(fourcc, plane_count, bytes_per_pixel);
551  }
552  };
553 
554  class stream_profile_interface;
555 
557  {
561 
562  // The request lists is there just for lookup and is not involved in object comparison
563  mutable std::vector<std::shared_ptr<stream_profile_interface>> original_requests;
564 
565  operator request_mapping_tuple() const
566  {
567  return std::make_tuple(profile, *pf, *unpacker);
568  }
569 
571 
572  };
573 
574  inline bool operator< (const request_mapping& first, const request_mapping& second)
575  {
576  return request_mapping_tuple(first) < request_mapping_tuple(second);
577  }
578 
579  inline bool operator==(const request_mapping& a,
580  const request_mapping& b)
581  {
582  return (a.profile == b.profile) && (a.pf == b.pf) && (a.unpacker == b.unpacker);
583  }
584 
585  class frame_interface;
586 
588  {
590 
592  {
593  return frame;
594  }
595 
596  operator bool() const { return frame != nullptr; }
597 
598  operator frame_interface*() const { return frame; }
599 
601  {
602  frame = f;
603  }
604 
605  ~frame_holder();
606 
608  : frame(other.frame)
609  {
610  other.frame = nullptr;
611  }
612 
613  frame_holder() : frame(nullptr) {}
614 
615 
617 
618  frame_holder clone() const;
619  private:
620  frame_holder& operator=(const frame_holder& other) = delete;
621  frame_holder(const frame_holder& other);
622  };
623 
625  {
626  int m_major, m_minor, m_patch, m_build;
627  bool is_any;
628  std::string string_representation;
629 
630  std::string to_string() const;
631  static std::vector<std::string> split(const std::string& str);
632  static int parse_part(const std::string& name, int part);
633 
634  public:
635  firmware_version() : m_major(0), m_minor(0), m_patch(0), m_build(0), is_any(true), string_representation(to_string()) {}
636 
637  firmware_version(int major, int minor, int patch, int build, bool is_any = false)
638  : m_major(major), m_minor(minor), m_patch(patch), m_build(build), is_any(is_any), string_representation(to_string()) {}
639 
641  {
642  return{};
643  }
644 
645  explicit firmware_version(const std::string& name)
646  : m_major(parse_part(name, 0)), m_minor(parse_part(name, 1)), m_patch(parse_part(name, 2)), m_build(parse_part(name, 3)), is_any(false), string_representation(to_string()) {}
647 
648  bool operator<=(const firmware_version& other) const
649  {
650  if (is_any || other.is_any) return true;
651  if (m_major > other.m_major) return false;
652  if ((m_major == other.m_major) && (m_minor > other.m_minor)) return false;
653  if ((m_major == other.m_major) && (m_minor == other.m_minor) && (m_patch > other.m_patch)) return false;
654  if ((m_major == other.m_major) && (m_minor == other.m_minor) && (m_patch == other.m_patch) && (m_build > other.m_build)) return false;
655  return true;
656  }
657  bool operator==(const firmware_version& other) const
658  {
659  return is_any || (other.m_major == m_major && other.m_minor == m_minor && other.m_patch == m_patch && other.m_build == m_build);
660  }
661 
662  bool operator> (const firmware_version& other) const { return !(*this < other) || is_any; }
663  bool operator!=(const firmware_version& other) const { return !(*this == other); }
664  bool operator<(const firmware_version& other) const { return !(*this == other) && (*this <= other); }
665  bool operator>=(const firmware_version& other) const { return (*this == other) || (*this > other); }
666 
667  bool is_between(const firmware_version& from, const firmware_version& until) const
668  {
669  return (from <= *this) && (*this <= until);
670  }
671 
672  operator const char*() const
673  {
674  return string_representation.c_str();
675  }
676 
677  operator std::string() const
678  {
679  return string_representation.c_str();
680  }
681  };
682 
683  // This class is used to buffer up several writes to a structure-valued XU control, and send the entire structure all at once
684  // Additionally, it will ensure that any fields not set in a given struct will retain their original values
685  template<class T, class R, class W> struct struct_interface
686  {
690  bool active;
691 
692  struct_interface(R r, W w) : reader(r), writer(w), active(false) {}
693 
694  void activate() { if (!active) { struct_ = reader(); active = true; } }
695  template<class U> double get(U T::* field) { activate(); return static_cast<double>(struct_.*field); }
696  template<class U, class V> void set(U T::* field, V value) { activate(); struct_.*field = static_cast<U>(value); }
697  void commit() { if (active) writer(struct_); }
698  };
699 
700  template<class T, class R, class W>
701  std::shared_ptr<struct_interface<T, R, W>> make_struct_interface(R r, W w)
702  {
703  return std::make_shared<struct_interface<T, R, W>>(r, w);
704  }
705 
706  // Provides an efficient wraparound for built-in arithmetic times, for use-cases such as a rolling timestamp
707  template <typename T, typename S>
709  {
710  public:
712  last_input(std::numeric_limits<T>::lowest()), accumulated(0) {
713  static_assert(
716  (std::numeric_limits<T>::max() < std::numeric_limits<S>::max()) &&
717  (std::numeric_limits<T>::lowest() >= std::numeric_limits<S>::lowest())
718  , "Wraparound class requirements are not met");
719  }
720 
721  S calc(const T input)
722  {
723  accumulated += static_cast<T>(input - last_input); // Automatically resolves wraparounds
724  last_input = input;
725  return (accumulated);
726  }
727 
728  void reset() { last_input = std::numeric_limits<T>::lowest(); accumulated = 0; }
729 
730  private:
731  T last_input;
732  S accumulated;
733  };
734 
735  typedef void(*frame_callback_function_ptr)(rs2_frame * frame, void * user);
736 
738  {
740  void * user;
741  public:
742  frame_callback() : frame_callback(nullptr, nullptr) {}
743  frame_callback(frame_callback_function_ptr on_frame, void * user) : fptr(on_frame), user(user) {}
744 
745  operator bool() const { return fptr != nullptr; }
746  void on_frame (rs2_frame * frame) override {
747  if (fptr)
748  {
749  try { fptr(frame, user); } catch (...)
750  {
751  LOG_ERROR("Received an execption from frame callback!");
752  }
753  }
754  }
755  void release() override { delete this; }
756  };
757 
758  template<class T>
760  {
761  T on_frame_function; //Callable of type: void(frame_interface* frame)
762  public:
763  explicit internal_frame_callback(T on_frame) : on_frame_function(on_frame) {}
764 
765  void on_frame(rs2_frame* fref) override
766  {
767  on_frame_function((frame_interface*)(fref));
768  }
769 
770  void release() override { delete this; }
771  };
772 
774 
776  {
778  void * user;
779  public:
782 
783  operator bool() const { return nptr != nullptr; }
785  if (nptr)
786  {
787  try { nptr(notification, user); }
788  catch (...)
789  {
790  LOG_ERROR("Received an execption from frame callback!");
791  }
792  }
793  }
794  void release() override { delete this; }
795  };
796 
797  typedef void(*devices_changed_function_ptr)(rs2_device_list* removed, rs2_device_list* added, void * user);
798 
800  {
802  void * user;
803  public:
806 
807  operator bool() const { return nptr != nullptr; }
808  void on_devices_changed(rs2_device_list* removed, rs2_device_list* added) override {
809  if (nptr)
810  {
811  try { nptr(removed, added, user); }
812  catch (...)
813  {
814  LOG_ERROR("Received an execption from frame callback!");
815  }
816  }
817  }
818  void release() override { delete this; }
819  };
820 
821  typedef std::unique_ptr<rs2_log_callback, void(*)(rs2_log_callback*)> log_callback_ptr;
822  typedef std::shared_ptr<rs2_frame_callback> frame_callback_ptr;
823  typedef std::shared_ptr<rs2_frame_processor_callback> frame_processor_callback_ptr;
824  typedef std::shared_ptr<rs2_notifications_callback> notifications_callback_ptr;
825  typedef std::shared_ptr<rs2_devices_changed_callback> devices_changed_callback_ptr;
826 
827  using internal_callback = std::function<void(rs2_device_list* removed, rs2_device_list* added)>;
829  {
830  internal_callback _callback;
831 
832  public:
834  : _callback(callback)
835  {}
836 
837  void on_devices_changed(rs2_device_list* removed, rs2_device_list* added) override
838  {
839  _callback(removed , added);
840  }
841 
842  void release() override { delete this; }
843  };
844 
845 
847  {
850  {
851  timestamp = std::chrono::duration<double, std::milli>(std::chrono::system_clock::now().time_since_epoch()).count();
853  }
854 
856  int type;
858  std::string description;
859  double timestamp;
860  std::string serialized_data;
861  };
862 
863 
865  {
866  public:
867  virtual ~notification_decoder() = default;
868  virtual notification decode(int value) = 0;
869  };
870 
872  {
873  public:
876 
879  void raise_notification(const notification);
880 
881  private:
882  notifications_callback_ptr _callback;
883  std::mutex _callback_mutex;
884  dispatcher _dispatcher;
885  };
887  // Helper functions for library types //
889 
890  inline rs2_intrinsics pad_crop_intrinsics(const rs2_intrinsics & i, int pad_crop)
891  {
892  return{ i.width + pad_crop * 2, i.height + pad_crop * 2, i.ppx + pad_crop, i.ppy + pad_crop,
893  i.fx, i.fy, i.model, {i.coeffs[0], i.coeffs[1], i.coeffs[2], i.coeffs[3], i.coeffs[4]} };
894  }
895 
896  inline rs2_intrinsics scale_intrinsics(const rs2_intrinsics & i, int width, int height)
897  {
898  const float sx = static_cast<float>(width) / i.width, sy = static_cast<float>(height) / i.height;
899  return{ width, height, i.ppx*sx, i.ppy*sy, i.fx*sx, i.fy*sy, i.model,
900  {i.coeffs[0], i.coeffs[1], i.coeffs[2], i.coeffs[3], i.coeffs[4]} };
901  }
902 
903  inline bool operator == (const rs2_intrinsics & a, const rs2_intrinsics & b) { return std::memcmp(&a, &b, sizeof(a)) == 0; }
904 
905  inline uint32_t pack(uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3)
906  {
907  return (c0 << 24) | (c1 << 16) | (c2 << 8) | c3;
908  }
909 
910  template<class T, int C>
912  {
913  T buffer[C];
914  bool is_free[C];
915  std::mutex mutex;
916  bool keep_allocating = true;
917  std::condition_variable cv;
918  int size = 0;
919 
920  public:
922  {
923  for (auto i = 0; i < C; i++)
924  {
925  is_free[i] = true;
926  buffer[i] = std::move(T());
927  }
928  }
929 
930  T * allocate()
931  {
932  std::unique_lock<std::mutex> lock(mutex);
933  if (!keep_allocating) return nullptr;
934 
935  for (auto i = 0; i < C; i++)
936  {
937  if (is_free[i])
938  {
939  is_free[i] = false;
940  size++;
941  return &buffer[i];
942  }
943  }
944  return nullptr;
945  }
946 
947  void deallocate(T * item)
948  {
949  if (item < buffer || item >= buffer + C)
950  {
951  throw invalid_value_exception("Trying to return item to a heap that didn't allocate it!");
952  }
953  auto i = item - buffer;
954  auto old_value = std::move(buffer[i]);
955  buffer[i] = std::move(T());
956 
957  {
958  std::unique_lock<std::mutex> lock(mutex);
959 
960  is_free[i] = true;
961  size--;
962 
963  if (size == 0)
964  {
965  lock.unlock();
966  cv.notify_one();
967  }
968  }
969  }
970 
972  {
973  std::unique_lock<std::mutex> lock(mutex);
974  keep_allocating = false;
975  }
976 
978  {
979  std::unique_lock<std::mutex> lock(mutex);
980 
981  const auto ready = [this]()
982  {
983  return is_empty();
984  };
985  if (!ready() && !cv.wait_for(lock, std::chrono::hours(1000), ready)) // for some reason passing std::chrono::duration::max makes it return instantly
986  {
987  throw invalid_value_exception("Could not flush one of the user controlled objects!");
988  }
989  }
990 
991  bool is_empty() const { return size == 0; }
992  int get_size() const { return size; }
993  };
994 
996  {
997  std::string id = ""; // to distinguish between different pins of the same device
998  uint16_t vid;
999  uint16_t pid;
1000  uint16_t mi;
1001  std::string unique_id;
1002  std::string device_path;
1003 
1004  operator std::string()
1005  {
1006  std::stringstream s;
1007  s << "id- " << id <<
1008  "\nvid- " << std::hex << vid <<
1009  "\npid- " << std::hex << pid <<
1010  "\nmi- " << mi <<
1011  "\nunique_id- " << unique_id <<
1012  "\npath- " << device_path;
1013 
1014  return s.str();
1015  }
1016  };
1017 
1018  inline bool operator==(const uvc_device_info& a,
1019  const uvc_device_info& b)
1020  {
1021  return (a.vid == b.vid) &&
1022  (a.pid == b.pid) &&
1023  (a.mi == b.mi) &&
1024  (a.unique_id == b.unique_id) &&
1025  (a.id == b.id) &&
1026  (a.device_path == b.device_path);
1027  }
1028 
1030  {
1031  std::string id;
1032 
1033  uint16_t vid;
1034  uint16_t pid;
1035  uint16_t mi;
1036  std::string unique_id;
1037 
1038  operator std::string()
1039  {
1040  std::stringstream s;
1041 
1042  s << "vid- " << std::hex << vid <<
1043  "\npid- " << std::hex << pid <<
1044  "\nmi- " << mi <<
1045  "\nunique_id- " << unique_id;
1046 
1047  return s.str();
1048  }
1049  };
1050 
1051  inline bool operator==(const usb_device_info& a,
1052  const usb_device_info& b)
1053  {
1054  return (a.id == b.id) &&
1055  (a.vid == b.vid) &&
1056  (a.pid == b.pid) &&
1057  (a.mi == b.mi) &&
1058  (a.unique_id == b.unique_id);
1059  }
1060 
1062  {
1063  std::string id;
1064  std::string vid;
1065  std::string pid;
1066  std::string unique_id;
1067  std::string device_path;
1068 
1069  operator std::string()
1070  {
1071  std::stringstream s;
1072  s << "id- " << id <<
1073  "\nvid- " << std::hex << vid <<
1074  "\npid- " << std::hex << pid <<
1075  "\nunique_id- " << unique_id <<
1076  "\npath- " << device_path;
1077 
1078  return s.str();
1079  }
1080  };
1081 
1082  inline bool operator==(const hid_device_info& a,
1083  const hid_device_info& b)
1084  {
1085  return (a.id == b.id) &&
1086  (a.vid == b.vid) &&
1087  (a.pid == b.pid) &&
1088  (a.unique_id == b.unique_id) &&
1089  (a.device_path == b.device_path);
1090  }
1091 
1092 
1094  {
1095  devices_data(std::vector<uvc_device_info> uvc_devices, std::vector<usb_device_info> usb_devices, std::vector<hid_device_info> hid_devices)
1096  :_uvc_devices(uvc_devices), _usb_devices(usb_devices), _hid_devices(hid_devices) {}
1097 
1098  devices_data(std::vector<usb_device_info> usb_devices)
1099  :_usb_devices(usb_devices) {}
1100 
1101  devices_data(std::vector<uvc_device_info> uvc_devices, std::vector<usb_device_info> usb_devices)
1102  :_uvc_devices(uvc_devices), _usb_devices(usb_devices) {}
1103 
1104  std::vector<uvc_device_info> _uvc_devices;
1105  std::vector<usb_device_info> _usb_devices;
1106  std::vector<hid_device_info> _hid_devices;
1107 
1108  bool operator == (const devices_data& other)
1109  {
1110  return !list_changed(_uvc_devices, other._uvc_devices) &&
1112  }
1113 
1114  operator std::string()
1115  {
1116  std::string s;
1117  s = _uvc_devices.size()>0 ? "uvc devices:\n" : "";
1118  for (auto uvc : _uvc_devices)
1119  {
1120  s += uvc;
1121  s += "\n\n";
1122  }
1123 
1124  s += _usb_devices.size()>0 ? "usb devices:\n" : "";
1125  for (auto usb : _usb_devices)
1126  {
1127  s += usb;
1128  s += "\n\n";
1129  }
1130 
1131  s += _hid_devices.size()>0 ? "hid devices: \n" : "";
1132  for (auto hid : _hid_devices)
1133  {
1134  s += hid;
1135  s += "\n\n";
1136  }
1137  return s;
1138  }
1139  };
1140 
1141 
1142  typedef std::function<void(devices_data old, devices_data curr)> device_changed_callback;
1144  {
1145  std::chrono::high_resolution_clock::time_point started;
1146  std::chrono::high_resolution_clock::time_point ended;
1147  };
1148 
1150 
1152  {
1153  callback_invocation_holder() : invocation(nullptr), owner(nullptr) {}
1156 
1158  : invocation(other.invocation), owner(other.owner)
1159  {
1160  other.invocation = nullptr;
1161  }
1162 
1164  : invocation(invocation), owner(owner)
1165  { }
1166 
1168  {
1169  if (invocation) owner->deallocate(invocation);
1170  }
1171 
1173  {
1174  invocation = other.invocation;
1175  owner = other.owner;
1176  other.invocation = nullptr;
1177  return *this;
1178  }
1179 
1180  operator bool()
1181  {
1182  return invocation != nullptr;
1183  }
1184 
1185  private:
1186  callback_invocation* invocation;
1187  callbacks_heap* owner;
1188  };
1189 
1191  {
1192  std::function<void()> continuation;
1193  const void* protected_data = nullptr;
1194 
1195  frame_continuation(const frame_continuation &) = delete;
1196  frame_continuation & operator=(const frame_continuation &) = delete;
1197  public:
1198  frame_continuation() : continuation([]() {}) {}
1199 
1200  explicit frame_continuation(std::function<void()> continuation, const void* protected_data) : continuation(continuation), protected_data(protected_data) {}
1201 
1202 
1203  frame_continuation(frame_continuation && other) : continuation(std::move(other.continuation)), protected_data(other.protected_data)
1204  {
1205  other.continuation = []() {};
1206  other.protected_data = nullptr;
1207  }
1208 
1209  void operator()()
1210  {
1211  continuation();
1212  continuation = []() {};
1213  protected_data = nullptr;
1214  }
1215 
1216  void reset()
1217  {
1218  protected_data = nullptr;
1219  continuation = [](){};
1220  }
1221 
1222  const void* get_data() const { return protected_data; }
1223 
1225  {
1226  continuation();
1227  protected_data = other.protected_data;
1228  continuation = other.continuation;
1229  other.continuation = []() {};
1230  other.protected_data = nullptr;
1231  return *this;
1232  }
1233 
1235  {
1236  continuation();
1237  }
1238 
1239  };
1240 
1241  // this class is a convinience wrapper for intrinsics / extrinsics validation methods
1243  {
1244  public:
1245  calibration_validator(std::function<bool(rs2_stream, rs2_stream)> extrinsic_validator,
1246  std::function<bool(rs2_stream)> intrinsic_validator);
1248 
1249  bool validate_extrinsics(rs2_stream from_stream, rs2_stream to_stream) const;
1251 
1252  private:
1253  std::function<bool(rs2_stream from_stream, rs2_stream to_stream)> extrinsic_validator;
1254  std::function<bool(rs2_stream stream)> intrinsic_validator;
1255  };
1256 
1257  inline bool check_not_all_zeros(std::vector<byte> data)
1258  {
1259  return std::find_if(data.begin(), data.end(), [](byte b){ return b!=0; }) != data.end();
1260  }
1261 
1262  std::string datetime_string();
1263 
1264  bool file_exists(const char* filename);
1265 
1267  // Extrinsic auxillary routines routines //
1269  float3x3 calc_rotation_from_rodrigues_angles(const std::vector<double> rot);
1270  // Auxillary function that calculates standard 32bit CRC code. used in verificaiton
1271  uint32_t calc_crc32(const uint8_t *buf, size_t bufsize);
1272 
1273 
1275  {
1276  public:
1278  _backend(backend_ref),_active_object([this](dispatcher::cancellable_timer cancellable_timer)
1279  {
1280  polling(cancellable_timer);
1281  }), _devices_data()
1282  {
1283  }
1284 
1286  {
1287  stop();
1288  }
1289 
1290  void polling(dispatcher::cancellable_timer cancellable_timer)
1291  {
1292  if(cancellable_timer.try_sleep(5000))
1293  {
1294  platform::backend_device_group curr(_backend->query_uvc_devices(), _backend->query_usb_devices(), _backend->query_hid_devices());
1295  if(list_changed(_devices_data.uvc_devices, curr.uvc_devices ) ||
1296  list_changed(_devices_data.usb_devices, curr.usb_devices ) ||
1297  list_changed(_devices_data.hid_devices, curr.hid_devices ))
1298  {
1299  callback_invocation_holder callback = { _callback_inflight.allocate(), &_callback_inflight };
1300  if(callback)
1301  {
1302  _callback(_devices_data, curr);
1303  _devices_data = curr;
1304  }
1305  }
1306  }
1307  }
1308 
1310  {
1311  stop();
1312  _callback = std::move(callback);
1313  _devices_data = { _backend->query_uvc_devices(),
1314  _backend->query_usb_devices(),
1315  _backend->query_hid_devices() };
1316 
1317  _active_object.start();
1318  }
1319 
1320  void stop() override
1321  {
1322  _active_object.stop();
1323 
1324  _callback_inflight.wait_until_empty();
1325  }
1326 
1327  private:
1328  active_object<> _active_object;
1329 
1330  callbacks_heap _callback_inflight;
1331  const platform::backend* _backend;
1332 
1333  platform::backend_device_group _devices_data;
1335 
1336  };
1337 
1338 
1339  template<typename HostingClass, typename... Args>
1340  class signal
1341  {
1342  friend HostingClass;
1343  public:
1345  {
1346  }
1347 
1348  signal(signal&& other)
1349  {
1350  std::lock_guard<std::mutex> locker(other.m_mutex);
1351  m_subscribers = std::move(other.m_subscribers);
1352 
1353  other.m_subscribers.clear();
1354  }
1355 
1357  {
1358  std::lock_guard<std::mutex> locker(other.m_mutex);
1359  m_subscribers = std::move(other.m_subscribers);
1360 
1361  other.m_subscribers.clear();
1362  return *this;
1363  }
1364 
1365  int subscribe(const std::function<void(Args...)>& func)
1366  {
1367  std::lock_guard<std::mutex> locker(m_mutex);
1368 
1369  int token = -1;
1370  for (int i = 0; i < (std::numeric_limits<int>::max)(); i++)
1371  {
1372  if (m_subscribers.find(i) == m_subscribers.end())
1373  {
1374  token = i;
1375  break;
1376  }
1377  }
1378 
1379  if (token != -1)
1380  {
1381  m_subscribers.emplace(token, func);
1382  }
1383 
1384  return token;
1385  }
1386 
1387  bool unsubscribe(int token)
1388  {
1389  std::lock_guard<std::mutex> locker(m_mutex);
1390 
1391  bool retVal = false;
1392  typename std::map<int, std::function<void(Args...)>>::iterator it = m_subscribers.find(token);
1393  if (it != m_subscribers.end())
1394  {
1395  m_subscribers.erase(token);
1396  retVal = true;
1397  }
1398 
1399  return retVal;
1400  }
1401 
1402  int operator+=(const std::function<void(Args...)>& func)
1403  {
1404  return subscribe(func);
1405  }
1406 
1407  bool operator-=(int token)
1408  {
1409  return unsubscribe(token);
1410  }
1411 
1412  private:
1413  signal(const signal& other); // non construction-copyable
1414  signal& operator=(const signal&); // non copyable
1415 
1416  bool raise(Args... args)
1417  {
1418  std::vector<std::function<void(Args...)>> functions;
1419  bool retVal = false;
1420 
1421  std::unique_lock<std::mutex> locker(m_mutex);
1422  if (m_subscribers.size() > 0)
1423  {
1424  typename std::map<int, std::function<void(Args...)>>::iterator it = m_subscribers.begin();
1425  while (it != m_subscribers.end())
1426  {
1427  functions.emplace_back(it->second);
1428  ++it;
1429  }
1430  }
1431  locker.unlock();
1432 
1433  if (functions.size() > 0)
1434  {
1435  for (auto func : functions)
1436  {
1437  func(std::forward<Args>(args)...);
1438  }
1439 
1440  retVal = true;
1441  }
1442 
1443  return retVal;
1444  }
1445 
1446  bool operator()(Args... args)
1447  {
1448  return raise(std::forward<Args>(args)...);
1449  }
1450 
1451  std::mutex m_mutex;
1452  std::map<int, std::function<void(Args...)>> m_subscribers;
1453  };
1454 
1455  template <typename T>
1457  {
1458  public:
1459  optional_value() : _valid(false) {}
1460  explicit optional_value(const T& v) : _valid(true), _value(v) {}
1461 
1462  operator bool() const
1463  {
1464  return has_value();
1465  }
1466  bool has_value() const
1467  {
1468  return _valid;
1469  }
1470 
1471  T& operator=(const T& v)
1472  {
1473  _valid = true;
1474  _value = v;
1475  return _value;
1476  }
1477 
1478  T& value() &
1479  {
1480  if (!_valid) throw std::runtime_error("bad optional access");
1481  return _value;
1482  }
1483 
1484  T&& value() &&
1485  {
1486  if (!_valid) throw std::runtime_error("bad optional access");
1487  return std::move(_value);
1488  }
1489 
1490  const T* operator->() const
1491  {
1492  return &_value;
1493  }
1495  {
1496  return &_value;
1497  }
1498  const T& operator*() const&
1499  {
1500  return _value;
1501  }
1502  T& operator*() &
1503  {
1504  return _value;
1505  }
1506  T&& operator*() &&
1507  {
1508  return std::move(_value);
1509  }
1510  private:
1511  bool _valid;
1512  T _value;
1513  };
1514 }
1515 
1516 namespace std {
1517 
1518  template <>
1519  struct hash<librealsense::stream_profile>
1520  {
1522  {
1523  using std::hash;
1524 
1525  return (hash<uint32_t>()(k.height))
1526  ^ (hash<uint32_t>()(k.width))
1527  ^ (hash<uint32_t>()(k.fps))
1528  ^ (hash<uint32_t>()(k.format))
1529  ^ (hash<uint32_t>()(k.stream));
1530  }
1531  };
1532 
1533  template <>
1534  struct hash<librealsense::platform::stream_profile>
1535  {
1537  {
1538  using std::hash;
1539 
1540  return (hash<uint32_t>()(k.height))
1541  ^ (hash<uint32_t>()(k.width))
1542  ^ (hash<uint32_t>()(k.fps))
1543  ^ (hash<uint32_t>()(k.format));
1544  }
1545  };
1546 
1547  template <>
1548  struct hash<librealsense::request_mapping>
1549  {
1551  {
1552  using std::hash;
1553 
1555  ^ (hash<librealsense::pixel_format_unpacker*>()(k.unpacker))
1556  ^ (hash<librealsense::native_pixel_format*>()(k.pf));
1557  }
1558  };
1559 }
1560 
1561 template<class T>
1562 bool contains(const T& first, const T& second)
1563 {
1564  return first == second;
1565 }
1566 
1567 template<class T>
1568 std::vector<std::shared_ptr<T>> subtract_sets(const std::vector<std::shared_ptr<T>>& first, const std::vector<std::shared_ptr<T>>& second)
1569 {
1570  std::vector<std::shared_ptr<T>> results;
1571  std::for_each(first.begin(), first.end(), [&](std::shared_ptr<T> data)
1572  {
1573  if (std::find_if(second.begin(), second.end(), [&](std::shared_ptr<T> new_dev) {
1574  return contains(data, new_dev);
1575  }) == second.end())
1576  {
1577  results.push_back(data);
1578  }
1579  });
1580  return results;
1581 }
1582 
1583  enum res_type {
1587  };
1588 
1589  inline res_type get_res_type(uint32_t width, uint32_t height)
1590  {
1591  if (width == 640)
1593  else if (width < 640)
1594  return res_type::low_resolution;
1595 
1597  }
1598 
1599 #endif
bool operator<(const request_mapping &first, const request_mapping &second)
Definition: types.h:574
uint32_t fps
Definition: backend.h:135
int arr_size(T(&)[sz])
Definition: types.h:361
internal_frame_callback(T on_frame)
Definition: types.h:763
S calc(const T input)
Definition: types.h:721
rs2_camera_info
Read-only strings that can be queried from the device. Not all information attributes are available o...
Definition: rs_sensor.h:22
float3x3 orientation
Definition: types.h:417
Definition: rs_types.hpp:27
const double DBL_EPSILON
Definition: types.h:38
rs2_intrinsics scale_intrinsics(const rs2_intrinsics &i, int width, int height)
Definition: types.h:896
float3 x
Definition: types.h:416
bool requires_processing() const
Definition: types.h:570
T & value() &
Definition: types.h:1478
void deallocate(T *item)
Definition: types.h:947
virtual std::vector< uvc_device_info > query_uvc_devices() const =0
void stop_allocation()
Definition: types.h:971
std::string device_path
Definition: types.h:1002
T * allocate()
Definition: types.h:930
camera_disconnected_exception(const std::string &msg) noexcept
Definition: types.h:191
rs2_exception_type
Exception types are the different categories of errors that RealSense API might return.
Definition: rs_types.h:28
size_t get_image_size(int width, int height) const
Definition: types.h:546
T & operator*() &
Definition: types.h:1502
int get_size() const
Definition: types.h:992
Definition: backend.h:347
bool validate_extrinsics(rs2_stream from_stream, rs2_stream to_stream) const
wrong_api_call_sequence_exception(const std::string &msg) noexcept
Definition: types.h:239
float x
Definition: types.h:414
std::vector< usb_device_info > _usb_devices
Definition: types.h:1105
virtual std::vector< hid_device_info > query_hid_devices() const =0
Definition: types.h:737
Definition: backend.h:351
Definition: backend.h:621
Definition: types.h:417
signal()
Definition: types.h:1344
rs2_option
Defines general configuration controls. These can generally be mapped to camera UVC controls...
Definition: rs_option.h:22
rs2_extrinsics from_pose(pose a)
Definition: types.h:441
unsigned char byte
Definition: types.h:33
Definition: types.h:413
io_exception(const std::string &msg) noexcept
Definition: types.h:184
Definition: streaming.h:63
Definition: types.h:254
std::tuple< rs2_stream, int, rs2_format > output_tuple
Definition: types.h:466
bool has_value() const
Definition: types.h:1466
Definition: rs_types.hpp:41
rs2_notification_category category
Definition: types.h:855
bool operator==(const devices_data &other)
Definition: types.h:1108
std::shared_ptr< rs2_frame_callback > frame_callback_ptr
Definition: types.h:822
Definition: serialization.h:324
notifications_callback()
Definition: types.h:780
void stop() override
Definition: types.h:1320
float w
Definition: types.h:415
rs2_distortion
Distortion model: defines how pixel coordinates should be mapped to sensor coordinates.
Definition: rs_types.h:43
std::vector< pixel_format_unpacker > unpackers
Definition: types.h:544
float translation[3]
Definition: rs_sensor.h:82
Definition: concurrency.h:268
std::shared_ptr< struct_interface< T, R, W > > make_struct_interface(R r, W w)
Definition: types.h:701
Definition: rs_types.h:35
std::string array2str(T &data)
Definition: types.h:367
Definition: types.h:268
bool operator==(const firmware_version &other) const
Definition: types.h:657
std::string make_less_screamy(const char *str)
rs2_sr300_visual_preset
For SR300 devices: provides optimized settings (presets) for specific types of usage.
Definition: rs_option.h:70
bool requires_processing
Definition: types.h:499
res_type get_res_type(uint32_t width, uint32_t height)
Definition: types.h:1589
float y
Definition: types.h:414
frame_holder(frame_holder &&other)
Definition: types.h:607
const char * what() const noexcept override
Definition: types.h:147
Definition: types.h:539
size_t operator()(const librealsense::platform::stream_profile &k) const
Definition: types.h:1536
Definition: concurrency.h:125
std::vector< std::shared_ptr< stream_profile_interface > > original_requests
Definition: types.h:563
float & operator[](int i)
Definition: types.h:413
virtual ~notification_decoder()=default
Definition: types.h:911
std::chrono::high_resolution_clock::time_point started
Definition: types.h:1145
float3 operator*(const float3 &a, float b)
Definition: types.h:421
uint32_t format
Definition: backend.h:136
bool operator==(const float3 &a, const float3 &b)
Definition: types.h:419
float & operator()(int i, int j)
Definition: types.h:416
void polling(dispatcher::cancellable_timer cancellable_timer)
Definition: types.h:1290
stream_descriptor(rs2_stream type, int index=0)
Definition: types.h:491
uint32_t width
Definition: types.h:473
R reader
Definition: types.h:688
std::function< void(frame_interface *)> on_frame
Definition: streaming.h:103
Definition: types.h:1585
void(* frame_callback_function_ptr)(rs2_frame *frame, void *user)
Definition: types.h:735
unique_id & operator=(const unique_id &)=delete
T struct_
Definition: types.h:687
frame()
Definition: archive.h:69
Definition: types.h:488
backend_exception(const std::string &msg, rs2_exception_type exception_type) noexcept
Definition: types.h:199
std::string unique_id
Definition: types.h:1066
void stop()
Definition: concurrency.h:284
float & operator[](int i)
Definition: types.h:414
devices_changed_callback()
Definition: types.h:804
frame_callback(frame_callback_function_ptr on_frame, void *user)
Definition: types.h:743
float3 y
Definition: types.h:416
lazy(std::function< T()> initializer)
Definition: types.h:272
T * operator->() const
Definition: types.h:274
Definition: stream.h:188
float coeffs[5]
Definition: rs_types.h:64
void(* notifications_callback_function_ptr)(rs2_notification *notification, void *user)
Definition: types.h:773
std::vector< std::shared_ptr< T > > subtract_sets(const std::vector< std::shared_ptr< T >> &first, const std::vector< std::shared_ptr< T >> &second)
Definition: types.h:1568
void release() override
Definition: types.h:818
virtual notification decode(int value)=0
bool check_not_all_zeros(std::vector< byte > data)
Definition: types.h:1257
bool operator>(const firmware_version &other) const
Definition: types.h:662
void log_to_file(rs2_log_severity min_severity, const char *file_path)
Definition: rs.hpp:26
Definition: types.h:1274
signal & operator=(signal &&other)
Definition: types.h:1356
librealsense::small_heap< callback_invocation, 1 > callbacks_heap
Definition: types.h:1149
Definition: types.h:1061
void on_frame(rs2_frame *fref) override
Definition: types.h:765
static firmware_version any()
Definition: types.h:640
uint32_t height
Definition: types.h:473
T * operator->()
Definition: types.h:1494
Definition: types.h:1340
notifications_callback_ptr get_callback() const
bool unsubscribe(int token)
Definition: types.h:1387
void activate()
Definition: types.h:694
rs2_extrinsics identity_matrix()
Definition: types.h:450
Definition: types.h:1093
void release() override
Definition: types.h:842
native_pixel_format * pf
Definition: types.h:559
pixel_format_unpacker * unpacker
Definition: types.h:560
frame_holder clone() const
std::tuple< platform::stream_profile_tuple, native_pixel_format_tuple, std::vector< output_tuple > > request_mapping_tuple
Definition: types.h:467
float rotation[9]
Definition: rs_sensor.h:81
uint32_t fps
Definition: types.h:473
lazy & operator=(lazy &&other) noexcept
Definition: types.h:310
lazy & operator=(std::function< T()> func) noexcept
Definition: types.h:305
res_type
Definition: types.h:1583
Definition: types.h:181
float3x3 transpose(const float3x3 &a)
Definition: types.h:427
float ppx
Definition: rs_types.h:59
Definition: types.h:864
bool list_changed(const std::vector< T > &list1, const std::vector< T > &list2, std::function< bool(T, T)> equal=[](T first, T second) { return first==second;})
Definition: backend.h:38
bool active
Definition: types.h:690
pose inverse(const pose &a)
Definition: types.h:431
Definition: archive.h:63
float3 position
Definition: types.h:417
Definition: types.h:1584
bool try_sleep(int ms)
Definition: concurrency.h:135
Definition: algo.h:16
pose to_pose(const rs2_extrinsics &a)
Definition: types.h:432
struct_interface(R r, W w)
Definition: types.h:692
Definition: types.h:1242
std::unique_ptr< rs2_log_callback, void(*)(rs2_log_callback *)> log_callback_ptr
Definition: types.h:821
recoverable_exception(const std::string &msg, rs2_exception_type exception_type) noexcept
std::vector< hid_device_info > hid_devices
Definition: backend.h:570
uint16_t mi
Definition: types.h:1035
arithmetic_wraparound()
Definition: types.h:711
std::function< void(devices_data old, devices_data curr)> device_changed_callback
Definition: types.h:1142
Definition: types.h:347
invalid_value_exception(const std::string &msg) noexcept
Definition: types.h:231
Definition: types.h:416
bool validate_intrinsics(rs2_stream stream) const
Definition: rs_types.h:37
T & operator*()
Definition: types.h:279
W writer
Definition: types.h:689
unrecoverable_exception(const std::string &msg, rs2_exception_type exception_type) noexcept
Definition: types.h:174
~polling_device_watcher()
Definition: types.h:1285
bool operator!=(const firmware_version &other) const
Definition: types.h:663
frame_continuation(frame_continuation &&other)
Definition: types.h:1203
Definition: rs_types.h:32
Definition: context.h:29
frame_continuation & operator=(frame_continuation &&other)
Definition: types.h:1224
std::string pid
Definition: types.h:1065
devices_changed_callback_internal(internal_callback callback)
Definition: types.h:833
std::shared_ptr< rs2_frame_processor_callback > frame_processor_callback_ptr
Definition: types.h:823
frame_holder & operator=(frame_holder &&other)
float z
Definition: types.h:414
Definition: types.h:414
std::function< void(backend_device_group old, backend_device_group curr)> device_changed_callback
Definition: backend.h:619
std::vector< uvc_device_info > _uvc_devices
Definition: types.h:1104
void(* unpack)(byte *const dest[], const byte *source, int count)
Definition: types.h:500
rs2_matchers
Specifies types of different matchers.
Definition: rs_types.h:126
bool file_exists(const char *filename)
devices_changed_callback(devices_changed_function_ptr on_devices_changed, void *user)
Definition: types.h:805
T & operator=(const T &v)
Definition: types.h:1471
std::ostringstream ss
Definition: types.h:56
std::shared_ptr< rs2_notifications_callback > notifications_callback_ptr
Definition: types.h:824
T clamp_val(T val, const T &min, const T &max)
Definition: types.h:118
callback_invocation_holder & operator=(const callback_invocation_holder &)=delete
Definition: concurrency.h:128
firmware_version(const std::string &name)
Definition: types.h:645
uint16_t vid
Definition: types.h:998
const void * get_data() const
Definition: types.h:1222
std::string datetime_string()
const int RS2_USER_QUEUE_SIZE
Definition: types.h:35
platform::stream_profile profile
Definition: types.h:558
notifications_callback(notifications_callback_function_ptr on_notification, void *user)
Definition: types.h:781
rs2_playback_status
Definition: rs_record_playback.h:19
T && value() &&
Definition: types.h:1484
bool operator<=(const firmware_version &other) const
Definition: types.h:648
bool is_empty() const
Definition: types.h:991
~frame_continuation()
Definition: types.h:1234
std::function< void(rs2_device_list *removed, rs2_device_list *added)> internal_callback
Definition: types.h:827
void start()
Definition: concurrency.h:276
std::chrono::high_resolution_clock::time_point ended
Definition: types.h:1146
int width
Definition: rs_types.h:57
int type
Definition: types.h:856
frame_holder()
Definition: types.h:613
size_t operator()(const librealsense::stream_profile &k) const
Definition: types.h:1521
uint16_t mi
Definition: types.h:1000
rs2_format get_format(rs2_stream stream, int index) const
Definition: types.h:517
rs2_format
Format identifies how binary data is encoded within a frame.
Definition: rs_sensor.h:52
callback_invocation_holder(callback_invocation *invocation, callbacks_heap *owner)
Definition: types.h:1163
void wait_until_empty()
Definition: types.h:977
void release() override
Definition: types.h:794
optional_value()
Definition: types.h:1459
std::string id
Definition: types.h:1063
std::string id
Definition: types.h:1031
int x
Definition: types.h:412
devices_data(std::vector< uvc_device_info > uvc_devices, std::vector< usb_device_info > usb_devices, std::vector< hid_device_info > hid_devices)
Definition: types.h:1095
frame_callback()
Definition: types.h:742
rs2_stream
Streams are different types of data provided by RealSense devices.
Definition: rs_sensor.h:36
void on_notification(rs2_notification *notification) override
Definition: types.h:784
windows_backend_exception(const std::string &msg) noexcept
Definition: types.h:223
size_t copy_array(T(&dst)[size], const T(&src)[size])
Definition: types.h:62
bool operator<(const firmware_version &other) const
Definition: types.h:664
uint32_t fourcc
Definition: types.h:541
float3 z
Definition: types.h:416
#define LOG_INFO(...)
Definition: types.h:108
#define RS2_ENUM_HELPERS(TYPE, PREFIX)
Definition: types.h:382
int operator+=(const std::function< void(Args...)> &func)
Definition: types.h:1402
void commit()
Definition: types.h:697
int index
Definition: types.h:494
notification(rs2_notification_category category, int type, rs2_log_severity severity, std::string description)
Definition: types.h:848
Definition: types.h:54
int index
Definition: types.h:472
float x
Definition: types.h:415
uint32_t width
Definition: backend.h:133
frame_continuation()
Definition: types.h:1198
rs2_stream stream
Definition: types.h:471
Cross-stream extrinsics: encode the topology describing how the different devices are connected...
Definition: rs_sensor.h:79
Definition: types.h:415
const T & operator*() const &
Definition: types.h:1498
callback_invocation_holder()
Definition: types.h:1153
optional_value(const T &v)
Definition: types.h:1460
std::string unique_id
Definition: types.h:1036
const T * operator->() const
Definition: types.h:1490
rs2_exception_type get_exception_type() const noexcept
Definition: types.h:142
rs2_distortion model
Definition: rs_types.h:63
float y
Definition: types.h:415
uint32_t height
Definition: backend.h:134
Definition: types.h:469
std::string device_path
Definition: types.h:1067
bool operator>=(const firmware_version &other) const
Definition: types.h:665
frame_interface * frame
Definition: types.h:589
Definition: types.h:624
~callback_invocation_holder()
Definition: types.h:1167
int plane_count
Definition: types.h:542
rs2_extension
Specifies advanced interfaces (capabilities) objects may implement.
Definition: rs_types.h:93
lazy(lazy &&other) noexcept
Definition: types.h:289
Definition: types.h:1190
rs2_notification_category
Category of the librealsense notifications.
Definition: rs_types.h:17
Definition: rs_sensor.h:38
devices_data(std::vector< uvc_device_info > uvc_devices, std::vector< usb_device_info > usb_devices)
Definition: types.h:1101
not_implemented_exception(const std::string &msg) noexcept
Definition: types.h:247
signal(signal &&other)
Definition: types.h:1348
double timestamp
Definition: types.h:859
Definition: stream.h:14
Definition: backend.h:348
std::vector< usb_device_info > usb_devices
Definition: backend.h:569
size_t bytes_per_pixel
Definition: types.h:543
Definition: types.h:587
float fy
Definition: rs_types.h:62
float fx
Definition: rs_types.h:61
frame_interface * operator->()
Definition: types.h:591
T && operator*() &&
Definition: types.h:1506
void set_callback(notifications_callback_ptr callback)
int y
Definition: types.h:412
std::string serialized_data
Definition: types.h:860
void on_frame(rs2_frame *frame) override
Definition: types.h:746
void release() override
Definition: types.h:770
Definition: types.h:995
Video stream intrinsics.
Definition: rs_types.h:55
callback_invocation_holder(callback_invocation_holder &&other)
Definition: types.h:1157
uint16_t vid
Definition: types.h:1033
polling_device_watcher(const platform::backend *backend_ref)
Definition: types.h:1277
small_heap()
Definition: types.h:921
rs2_intrinsics pad_crop_intrinsics(const rs2_intrinsics &i, int pad_crop)
Definition: types.h:890
stream_descriptor()
Definition: types.h:490
std::vector< std::pair< stream_descriptor, rs2_format > > outputs
Definition: types.h:501
Definition: types.h:1029
void on_devices_changed(rs2_device_list *removed, rs2_device_list *added) override
Definition: types.h:808
float z
Definition: types.h:415
virtual std::vector< usb_device_info > query_usb_devices() const =0
Definition: types.h:846
Definition: api.h:26
std::string description
Definition: types.h:858
Definition: types.h:685
firmware_version(int major, int minor, int patch, int build, bool is_any=false)
Definition: types.h:637
librealsense_exception(const std::string &msg, rs2_exception_type exception_type) noexcept
Definition: types.h:153
uint16_t pid
Definition: types.h:999
bool is_between(const firmware_version &from, const firmware_version &until) const
Definition: types.h:667
void start(platform::device_changed_callback callback) override
Definition: types.h:1309
std::shared_ptr< rs2_devices_changed_callback > devices_changed_callback_ptr
Definition: types.h:825
static uint64_t generate_id()
Definition: types.h:350
int subscribe(const std::function< void(Args...)> &func)
Definition: types.h:1365
size_t copy_2darray(T(&dst)[sizem][sizen], const T(&src)[sizem][sizen])
Definition: types.h:73
float & operator[](int i)
Definition: types.h:415
callback_invocation_holder & operator=(callback_invocation_holder &&other)
Definition: types.h:1172
void release() override
Definition: types.h:755
int height
Definition: rs_types.h:58
Definition: types.h:1586
std::string unique_id
Definition: types.h:1001
Definition: types.h:196
void log_to_console(rs2_log_severity min_severity)
Definition: rs.hpp:19
firmware_version()
Definition: types.h:635
std::tuple< uint32_t, int, size_t > native_pixel_format_tuple
Definition: types.h:465
std::vector< uvc_device_info > uvc_devices
Definition: backend.h:568
to_string & operator<<(const T &val)
Definition: types.h:57
devices_data(std::vector< usb_device_info > usb_devices)
Definition: types.h:1098
float3 operator+(const float3 &a, const float3 &b)
Definition: types.h:420
bool satisfies(const stream_profile &request) const
Definition: types.h:503
Definition: rs_types.hpp:55
float float_4[4]
Definition: types.h:375
void on_devices_changed(rs2_device_list *removed, rs2_device_list *added) override
Definition: types.h:837
bool operator-=(int token)
Definition: types.h:1407
unique_id(const unique_id &)=delete
void(* devices_changed_function_ptr)(rs2_device_list *removed, rs2_device_list *added, void *user)
Definition: types.h:797
rs2_log_severity
Severity of the librealsense logger.
Definition: rs_types.h:81
float y
Definition: types.h:413
void raise_notification(const notification)
rs2_log_severity severity
Definition: types.h:857
Definition: types.h:1143
uint32_t pack(uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3)
Definition: types.h:905
const char * get_message() const noexcept
Definition: types.h:137
void operator()()
Definition: types.h:1209
void reset()
Definition: types.h:1216
frame_continuation(std::function< void()> continuation, const void *protected_data)
Definition: types.h:1200
size_t operator()(const librealsense::request_mapping &k) const
Definition: types.h:1550
Definition: types.h:556
Definition: types.h:412
Definition: rs_types.h:33
void reset()
Definition: types.h:728
linux_backend_exception(const std::string &msg) noexcept
Definition: types.h:208
lazy()
Definition: types.h:271
bool provides_stream(rs2_stream stream, int index) const
Definition: types.h:509
bool contains(const T &first, const T &second)
Definition: types.h:1562
float3x3 calc_rotation_from_rodrigues_angles(const std::vector< double > rot)
rs2_frame_metadata_value
Per-Frame-Metadata are set of read-only properties that might be exposed for each individual frame...
Definition: rs_frame.h:28
rs2_stream type
Definition: types.h:493
std::vector< hid_device_info > _hid_devices
Definition: types.h:1106
Definition: types.h:1456
const T & operator*() const
Definition: types.h:284
struct rs2_frame rs2_frame
Definition: rs_types.h:150
std::string vid
Definition: types.h:1064
#define LOG_ERROR(...)
Definition: types.h:110
void copy(void *dst, void const *src, size_t size)
float ppy
Definition: rs_types.h:60
float x
Definition: types.h:413
uint32_t calc_crc32(const uint8_t *buf, size_t bufsize)
Definition: serialization.h:336
uint16_t pid
Definition: types.h:1034
rs2_format format
Definition: types.h:474
frame_holder(frame_interface *f)
Definition: types.h:600
rs2_timestamp_domain
Specifies the clock in relation to which the frame timestamp was measured.
Definition: rs_frame.h:19
std::string id
Definition: types.h:997