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