src/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 // Disable declspec(dllexport) warnings:
13 // Classes exported via LRS_EXTENSION_API are **not** part of official librealsense API (at least for now)
14 // Any extension relying on these APIs must be compiled and distributed together with realsense2.dll
15 #pragma warning(disable : 4275) /* disable: C4275: non dll-interface class used as base for dll-interface class */
16 #pragma warning(disable : 4251) /* disable: C4251: class needs to have dll-interface to be used by clients of class */
17 #ifdef WIN32
18 #define LRS_EXTENSION_API __declspec(dllexport)
19 #else
20 #define LRS_EXTENSION_API
21 #endif
22 
23 #include "../include/librealsense2/hpp/rs_types.hpp"
24 
25 #ifndef _USE_MATH_DEFINES
26 #define _USE_MATH_DEFINES
27 #endif
28 #include <cmath> // For acos
29 #include <ctime>
30 #include <stdint.h>
31 #include <cassert> // For assert
32 #include <cstring> // For memcmp
33 #include <vector> // For vector
34 #include <sstream> // For ostringstream
35 #include <mutex> // For mutex, unique_lock
36 #include <memory> // For unique_ptr
37 #include <map>
38 #include <limits>
39 #include <algorithm>
40 #include <condition_variable>
41 #include <functional>
42 #include <utility> // For std::forward
43 #include <limits>
44 #include <iomanip>
45 #include "backend.h"
46 #include "concurrency.h"
47 
48 #if BUILD_EASYLOGGINGPP
49 #include "../third-party/easyloggingpp/src/easylogging++.h"
50 #endif // BUILD_EASYLOGGINGPP
51 
52 typedef unsigned char byte;
53 
54 const int RS2_USER_QUEUE_SIZE = 128;
55 
56 // Usage of non-standard C++ PI derivatives is prohibitive, use local definitions
57 static const double pi = std::acos(-1);
58 static const double d2r = pi / 180;
59 static const double r2d = 180 / pi;
60 template<typename T> T deg2rad(T val) { return T(val * d2r); }
61 template<typename T> T rad2deg(T val) { return T(val * r2d); }
62 
63 // global abs() is only defined for int for some GCC impl on Linux, meaning we may
64 // get unwanted behavior without any warning whatsoever. Instead, we want to use the
65 // C++ version in std!
66 using std::abs;
67 
68 #pragma warning(disable: 4250)
69 
70 #ifdef ANDROID
71 #include "../common/android_helpers.h"
72 #endif
73 
74 #define UNKNOWN_VALUE "UNKNOWN"
75 
76 namespace librealsense
77 {
78 #pragma pack (push, 1)
79 
80  struct hid_data
81  {
82  short x;
84  short y;
86  short z;
88  };
89 
90 #pragma pack(pop)
91 
92  static const double TIMESTAMP_USEC_TO_MSEC = 0.001;
93 
95  // Utility types for general use //
97  struct to_string
98  {
99  std::ostringstream ss;
100  template<class T> to_string & operator << (const T & val) { ss << val; return *this; }
101  operator std::string() const { return ss.str(); }
102  };
103 
104  template<typename T>
105  constexpr size_t arr_size(T const&) { return 1; }
106 
107  template<typename T, size_t sz>
108  constexpr size_t arr_size(T(&arr)[sz])
109  {
110  return sz * arr_size(arr[0]);
111  }
112 
113  template<typename T, size_t sz>
114  constexpr size_t arr_size_bytes(T(&arr)[sz])
115  {
116  return arr_size(arr) * sizeof(T);
117  }
118 
119  template<typename T>
121  {
122  std::stringstream ss;
123  for (auto i = 0; i < arr_size(data); i++)
124  ss << " [" << i << "] = " << data[i] << "\t";
125  return ss.str();
126  }
127 
128  // Auxillary function for compiler to highlight the invoking user code
129  template <typename T, typename S>
130  struct isNarrowing { static bool constexpr value = std::numeric_limits<S>::max() > std::numeric_limits<T>::max(); };
131 
132  template<const bool force_narrowing=false, typename T, typename S, size_t size_tgt, size_t size_src>
133  inline size_t copy_array(T(&dst)[size_tgt], const S(&src)[size_src])
134  {
135  static_assert((size_tgt && (size_tgt == size_src)), "copy_array requires similar non-zero size for target and source containers");
136  static_assert((std::is_arithmetic<S>::value) && (std::is_arithmetic<T>::value), "copy_array supports arithmetic types only");
137  if (!force_narrowing && isNarrowing<T, S>::value)
138  {
139  static_assert(!(isNarrowing<T, S>::value && !force_narrowing), "Passing narrowing conversion to copy_array requires setting the force flag on");
140  }
141 
142  assert(dst != nullptr && src != nullptr);
143  for (size_t i = 0; i < size_tgt; i++)
144  {
145  dst[i] = static_cast<T>(src[i]);
146  }
147  return size_tgt;
148  }
149 
150  template<const bool force_narrowing=false, typename T, typename S, size_t tgt_m, size_t tgt_n, size_t src_m, size_t src_n>
151  inline size_t copy_2darray(T(&dst)[tgt_m][tgt_n], const S(&src)[src_m][src_n])
152  {
153  static_assert((src_m && src_n && (tgt_n == src_n) && (tgt_m == src_m)), "copy_array requires similar non-zero size for target and source containers");
154  static_assert((std::is_arithmetic<S>::value) && (std::is_arithmetic<T>::value), "copy_2darray supports arithmetic types only");
155  if (isNarrowing<T, S>::value && !force_narrowing)
156  {
157  static_assert(!(isNarrowing<T, S>::value && !force_narrowing), "Passing narrowing conversion to copy_2darray requires setting the force flag on");
158  }
159 
160  assert(dst != nullptr && src != nullptr);
161  for (size_t i = 0; i < src_m; i++)
162  {
163  for (size_t j = 0; j < src_n; j++)
164  {
165  dst[i][j] = static_cast<T>(src[i][j]);
166  }
167  }
168  return src_m * src_n;
169  }
170 
171  // Comparing parameter against a range of values of the same type
172  // https://stackoverflow.com/questions/15181579/c-most-efficient-way-to-compare-a-variable-to-multiple-values
173  template <typename T>
174  bool val_in_range(const T& val, const std::initializer_list<T>& list)
175  {
176  for (const auto& i : list) {
177  if (val == i) {
178  return true;
179  }
180  }
181  return false;
182  }
183 
184  template<class T>
186  {
187  static_assert((std::is_integral<T>::value), "hexify supports integral built-in types only");
188 
189  std::ostringstream oss;
190  oss << std::setw(sizeof(T)*2) << std::setfill('0') << std::uppercase << std::hex << val;
191  return oss.str().c_str();
192  }
193 
194  void copy(void* dst, void const* src, size_t size);
195 
196  std::string make_less_screamy(const char* str);
197 
199  // Logging mechanism //
201 
202  typedef std::shared_ptr< rs2_log_callback > log_callback_ptr;
203 
204  void log_to_console(rs2_log_severity min_severity);
205  void log_to_file( rs2_log_severity min_severity, const char* file_path );
206  void log_to_callback( rs2_log_severity min_severity, log_callback_ptr callback );
207  void reset_logger();
208  void enable_rolling_log_file( unsigned max_size );
209 
210 #if BUILD_EASYLOGGINGPP
211 
212 #ifdef RS2_USE_ANDROID_BACKEND
213 #include <android/log.h>
214 
215 #define LOG_TAG "librs"
216 
217 #define LOG_INFO(...) do { std::stringstream ss; ss << __VA_ARGS__; __android_log_write(librealsense::ANDROID_LOG_INFO, LOG_TAG, ss.str().c_str()); } while(false)
218 #define LOG_WARNING(...) do { std::stringstream ss; ss << __VA_ARGS__; __android_log_write(librealsense::ANDROID_LOG_WARN, LOG_TAG, ss.str().c_str()); } while(false)
219 #define LOG_ERROR(...) do { std::stringstream ss; ss << __VA_ARGS__; __android_log_write(librealsense::ANDROID_LOG_ERROR, LOG_TAG, ss.str().c_str()); } while(false)
220 #define LOG_FATAL(...) do { std::stringstream ss; ss << __VA_ARGS__; __android_log_write(librealsense::ANDROID_LOG_ERROR, LOG_TAG, ss.str().c_str()); } while(false)
221 #ifdef NDEBUG
222 #define LOG_DEBUG(...)
223 #else
224 #define LOG_DEBUG(...) do { std::stringstream ss; ss << __VA_ARGS__; __android_log_write(librealsense::ANDROID_LOG_DEBUG, LOG_TAG, ss.str().c_str()); } while(false)
225 #endif
226 
227 #else //RS2_USE_ANDROID_BACKEND
228 
229 #define LOG_DEBUG(...) do { CLOG(DEBUG ,"librealsense") << __VA_ARGS__; } while(false)
230 #define LOG_INFO(...) do { CLOG(INFO ,"librealsense") << __VA_ARGS__; } while(false)
231 #define LOG_WARNING(...) do { CLOG(WARNING ,"librealsense") << __VA_ARGS__; } while(false)
232 #define LOG_ERROR(...) do { CLOG(ERROR ,"librealsense") << __VA_ARGS__; } while(false)
233 #define LOG_FATAL(...) do { CLOG(FATAL ,"librealsense") << __VA_ARGS__; } while(false)
234 
235 #endif // RS2_USE_ANDROID_BACKEND
236 
237 #else // BUILD_EASYLOGGINGPP
238 
239  #define LOG_DEBUG(...) do { ; } while(false)
240 #define LOG_INFO(...) do { ; } while(false)
241 #define LOG_WARNING(...) do { ; } while(false)
242 #define LOG_ERROR(...) do { ; } while(false)
243 #define LOG_FATAL(...) do { ; } while(false)
244 
245 #endif // BUILD_EASYLOGGINGPP
246 
247  // Enhancement for debug mode that incurs performance penalty with STL
248  // std::clamp to be introduced with c++17
249  template< typename T>
250  inline T clamp_val(T val, const T& min, const T& max)
251  {
252  static_assert((std::is_arithmetic<T>::value), "clamping supports arithmetic built-in types only");
253 #ifdef _DEBUG
254  const T t = val < min ? min : val;
255  return t > max ? max : t;
256 #else
257  return std::min(std::max(val, min), max);
258 #endif
259  }
260 
261 #ifdef BUILD_INTERNAL_UNIT_TESTS
262 #define PRIVATE_TESTABLE public
263 #else
264 #define PRIVATE_TESTABLE private
265 #endif
266  // Exceptions mechanism //
269 
270 
271  class librealsense_exception : public std::exception
272  {
273  public:
274  const char* get_message() const noexcept
275  {
276  return _msg.c_str();
277  }
278 
280  {
281  return _exception_type;
282  }
283 
284  const char* what() const noexcept override
285  {
286  return _msg.c_str();
287  }
288 
289  protected:
291  rs2_exception_type exception_type) noexcept
292  : _msg(msg),
293  _exception_type(exception_type)
294  {}
295 
296  private:
299  };
300 
302  {
303  public:
305  rs2_exception_type exception_type) noexcept;
306  };
307 
309  {
310  public:
312  rs2_exception_type exception_type) noexcept
313  : librealsense_exception(msg, exception_type)
314  {
315  LOG_ERROR(msg);
316  }
317  };
319  {
320  public:
321  io_exception(const std::string& msg) noexcept
323  {}
324  };
326  {
327  public:
330  {}
331  };
332 
334  {
335  public:
337  rs2_exception_type exception_type) noexcept
338  : unrecoverable_exception(msg, exception_type)
339  {}
340  };
341 
343  {
344  public:
346  : backend_exception(generate_last_error_message(msg), RS2_EXCEPTION_TYPE_BACKEND)
347  {}
348 
349  private:
351  {
352  return msg + " Last Error: " + strerror(errno);
353  }
354  };
355 
357  {
358  public:
359  // TODO: get last error
362  {}
363  };
364 
366  {
367  public:
370  {}
371  };
372 
374  {
375  public:
378  {}
379  };
380 
382  {
383  public:
386  {}
387  };
388 
389 
390 #pragma pack(push, 1)
391  template<class T> class big_endian
392  {
394  public:
395  operator T () const
396  {
397  T le_value = 0;
398  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];
399  return le_value;
400  }
401  };
402 #pragma pack(pop)
403 
404  template <class T>
405  class lazy
406  {
407  public:
408  lazy() : _init([]() { T t{}; return t; }) {}
409  lazy(std::function<T()> initializer) : _init(std::move(initializer)) {}
410 
411  T* operator->() const
412  {
413  return operate();
414  }
415 
417  {
418  return *operate();
419  }
420 
421  const T& operator*() const
422  {
423  return *operate();
424  }
425 
426  lazy(lazy&& other) noexcept
427  {
428  std::lock_guard<std::mutex> lock(other._mtx);
429  if (!other._was_init)
430  {
431  _init = move(other._init);
432  _was_init = false;
433  }
434  else
435  {
436  _init = move(other._init);
437  _was_init = true;
438  _ptr = move(other._ptr);
439  }
440  }
441 
442  lazy& operator=(std::function<T()> func) noexcept
443  {
444  return *this = lazy<T>(std::move(func));
445  }
446 
447  lazy& operator=(lazy&& other) noexcept
448  {
449  std::lock_guard<std::mutex> lock1(_mtx);
450  std::lock_guard<std::mutex> lock2(other._mtx);
451  if (!other._was_init)
452  {
453  _init = move(other._init);
454  _was_init = false;
455  }
456  else
457  {
458  _init = move(other._init);
459  _was_init = true;
460  _ptr = move(other._ptr);
461  }
462 
463  return *this;
464  }
465 
466  void reset() const
467  {
468  std::lock_guard<std::mutex> lock(_mtx);
469  if (_was_init)
470  {
471  _ptr.reset();
472  _was_init = false;
473  }
474  }
475 
476  private:
477  T* operate() const
478  {
479  std::lock_guard<std::mutex> lock(_mtx);
480  if (!_was_init)
481  {
482  _ptr = std::unique_ptr<T>(new T(_init()));
483  _was_init = true;
484  }
485  return _ptr.get();
486  }
487 
488  mutable std::mutex _mtx;
489  mutable bool _was_init = false;
490  std::function<T()> _init;
491  mutable std::unique_ptr<T> _ptr;
492  };
493 
494  class unique_id
495  {
496  public:
498  {
499  static std::atomic<uint64_t> id(0);
500  return ++id;
501  }
502 
503  unique_id(const unique_id&) = delete;
504  unique_id& operator=(const unique_id&) = delete;
505  };
506 
507  typedef float float_4[4];
508 
510  // Enumerated type support //
512 
513 // Require the last enumerator value to be in format of RS2_#####_COUNT
514 #define RS2_ENUM_HELPERS( TYPE, PREFIX ) \
515  RS2_ENUM_HELPERS_CUSTOMIZED( TYPE, 0, RS2_##PREFIX##_COUNT - 1 )
516 
517 // This macro can be used directly if needed to support enumerators with no RS2_#####_COUNT last value
518 #define RS2_ENUM_HELPERS_CUSTOMIZED( TYPE, FIRST, LAST ) \
519  LRS_EXTENSION_API const char * get_string( TYPE value ); \
520  inline bool is_valid( TYPE value ) { return value >= FIRST && value <= LAST; } \
521  inline std::ostream & operator<<( std::ostream & out, TYPE value ) \
522  { \
523  if( is_valid( value ) ) \
524  return out << get_string( value ); \
525  else \
526  return out << (int)value; \
527  } \
528  inline bool try_parse( const std::string & str, TYPE & res ) \
529  { \
530  for( int i = FIRST; i <= LAST; i++ ) \
531  { \
532  auto v = static_cast< TYPE >( i ); \
533  if( str == get_string( v ) ) \
534  { \
535  res = v; \
536  return true; \
537  } \
538  } \
539  return false; \
540  }
541 
544  RS2_ENUM_HELPERS(rs2_distortion, DISTORTION)
546  RS2_ENUM_HELPERS(rs2_camera_info, CAMERA_INFO)
548  RS2_ENUM_HELPERS(rs2_timestamp_domain, TIMESTAMP_DOMAIN)
550  RS2_ENUM_HELPERS(rs2_sr300_visual_preset, SR300_VISUAL_PRESET)
551  RS2_ENUM_HELPERS(rs2_extension, EXTENSION)
552  RS2_ENUM_HELPERS(rs2_exception_type, EXCEPTION_TYPE)
553  RS2_ENUM_HELPERS(rs2_log_severity, LOG_SEVERITY)
554  RS2_ENUM_HELPERS(rs2_notification_category, NOTIFICATION_CATEGORY)
555  RS2_ENUM_HELPERS(rs2_playback_status, PLAYBACK_STATUS)
557  RS2_ENUM_HELPERS(rs2_sensor_mode, SENSOR_MODE)
558  RS2_ENUM_HELPERS(rs2_l500_visual_preset, L500_VISUAL_PRESET)
559  RS2_ENUM_HELPERS(rs2_calibration_type, CALIBRATION_TYPE)
563  RS2_ENUM_HELPERS(rs2_cah_trigger, CAH_TRIGGER)
565 
566 
568  // World's tiniest linear algebra library //
570 #pragma pack(push, 1)
571  struct int2 { int x, y; };
572  struct float2 { float x, y; float & operator [] (int i) { return (&x)[i]; } };
573  struct float3 { float x, y, z; float & operator [] (int i) { return (&x)[i]; } };
574  struct float4 { float x, y, z, w; float & operator [] (int i) { return (&x)[i]; } };
575  struct float3x3 { float3 x, y, z; float & operator () (int i, int j) { return (&x)[j][i]; } }; // column-major
577 #pragma pack(pop)
578  inline bool operator == (const float3 & a, const float3 & b) { return a.x == b.x && a.y == b.y && a.z == b.z; }
579  inline float3 operator + (const float3 & a, const float3 & b) { return{ a.x + b.x, a.y + b.y, a.z + b.z }; }
580  inline float3 operator - (const float3 & a, const float3 & b) { return{ a.x - b.x, a.y - b.y, a.z - b.z }; }
581  inline float3 operator * (const float3 & a, float b) { return{ a.x*b, a.y*b, a.z*b }; }
582  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; }
583  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 }; }
584  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 }; }
585  inline bool operator == (const float3x3 & a, const float3x3 & b) { return a.x == b.x && a.y == b.y && a.z == b.z; }
586  inline float3 operator * (const float3x3 & a, const float3 & b) { return a.x*b.x + a.y*b.y + a.z*b.z; }
587  inline float3x3 operator * (const float3x3 & a, const float3x3 & b) { return{ a*b.x, a*b.y, a*b.z }; }
588  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} }; }
589  inline bool operator == (const pose & a, const pose & b) { return a.orientation == b.orientation && a.position == b.position; }
590  inline float3 operator * (const pose & a, const float3 & b) { return a.orientation * b + a.position; }
591  inline pose operator * (const pose & a, const pose & b) { return{ a.orientation * b.orientation, a * b.position }; }
592  inline pose inverse(const pose & a) { auto inv = transpose(a.orientation); return{ inv, inv * a.position * -1 }; }
593  inline pose to_pose(const rs2_extrinsics& a)
594  {
595  pose r{};
596  for (int i = 0; i < 3; i++) r.position[i] = a.translation[i];
597  for (int j = 0; j < 3; j++)
598  for (int i = 0; i < 3; i++)
599  r.orientation(i, j) = a.rotation[j * 3 + i];
600  return r;
601  }
603  {
605  for (int i = 0; i < 3; i++) r.translation[i] = a.position[i];
606  for (int j = 0; j < 3; j++)
607  for (int i = 0; i < 3; i++)
608  r.rotation[j * 3 + i] = a.orientation(i, j);
609  return r;
610  }
613  // Do it the silly way to avoid infite warnings about the dangers of memset
614  for (int i = 0; i < 3; i++) r.translation[i] = 0.f;
615  for (int j = 0; j < 3; j++)
616  for (int i = 0; i < 3; i++)
617  r.rotation[j * 3 + i] = (i == j) ? 1.f : 0.f;
618  return r;
619  }
620  inline rs2_extrinsics inverse(const rs2_extrinsics& a) { auto p = to_pose(a); return from_pose(inverse(p)); }
621 
622  // The extrinsics on the camera ("raw extrinsics") are in milimeters, but LRS works in meters
623  // Additionally, LRS internal algorithms are
624  // written with a transposed matrix in mind! (see rs2_transform_point_to_point)
627 
628  inline std::ostream& operator <<(std::ostream& stream, const float3& elem)
629  {
630  return stream << elem.x << " " << elem.y << " " << elem.z;
631  }
632 
633  inline std::ostream& operator <<(std::ostream& stream, const float4& elem)
634  {
635  return stream << elem.x << " " << elem.y << " " << elem.z << " " << elem.w;
636  }
637 
638  inline std::ostream& operator <<(std::ostream& stream, const float3x3& elem)
639  {
640  return stream << elem.x << "\n" << elem.y << "\n" << elem.z;
641  }
642 
643  inline std::ostream& operator <<(std::ostream& stream, const pose& elem)
644  {
645  return stream << "Position:\n " << elem.position << "\n Orientation :\n" << elem.orientation;
646  }
647 
649  // Pixel formats //
651 
652  typedef std::tuple<uint32_t, int, size_t> native_pixel_format_tuple;
653  typedef std::tuple<rs2_stream, int, rs2_format> output_tuple;
654  typedef std::tuple<platform::stream_profile_tuple, native_pixel_format_tuple, std::vector<output_tuple>> request_mapping_tuple;
655 
656  struct resolution
657  {
659  };
660  using resolution_func = std::function<resolution(resolution res)>;
661 
663  {
665  rs2_stream strm = RS2_STREAM_ANY,
666  int idx = 0,
667  uint32_t w = 0, uint32_t h = 0,
668  uint32_t framerate = 0,
669  resolution_func res_func = [](resolution res) { return res; }) :
670  format(fmt), stream(strm), index(idx), width(w), height(h), fps(framerate), stream_resolution(res_func)
671  {}
672 
673  rs2_format format;
675  int index;
677  resolution_func stream_resolution; // Calculates the relevant resolution from the given backend resolution.
678 
679  std::pair< uint32_t, uint32_t > width_height() const { return std::make_pair( width, height ); }
680  };
681 
682 
683  inline bool operator==(const stream_profile& a,
684  const stream_profile& b)
685  {
686  return (a.width == b.width) &&
687  (a.height == b.height) &&
688  (a.fps == b.fps) &&
689  (a.format == b.format) &&
690  (a.index == b.index) &&
691  (a.stream == b.stream);
692  }
693 
694  inline bool operator<(const stream_profile & lhs,
695  const stream_profile & rhs)
696  {
697  if (lhs.format != rhs.format) return lhs.format < rhs.format;
698  if (lhs.index != rhs.index) return lhs.index < rhs.index;
699  return lhs.stream < rhs.stream;
700  }
701 
703  {
705  stream_descriptor(rs2_stream type, int index = 0) : type(type), index(index) {}
706 
708  int index;
709  };
710 
711  struct stream_output {
713  rs2_format format_in,
714  resolution_func res_func = [](resolution res) {return res; })
715  : stream_desc(stream_desc_in),
716  format(format_in),
717  stream_resolution(res_func)
718  {}
719 
721  rs2_format format;
723  };
724 
726  {
728  void(*unpack)(byte * const dest[], const byte * source, int width, int height, int actual_size, int input_size);
729  std::vector<stream_output> outputs;
730 
731  platform::stream_profile get_uvc_profile(const stream_profile& request, uint32_t fourcc, const std::vector<platform::stream_profile>& uvc_profiles) const
732  {
733  platform::stream_profile uvc_profile{};
734  auto it = std::find_if(begin(uvc_profiles), end(uvc_profiles),
735  [&fourcc, &request, this](const platform::stream_profile& uvc_p)
736  {
737  for (auto & o : outputs)
738  {
739  auto res = o.stream_resolution(resolution{ uvc_p.width, uvc_p.height });
740  if (o.stream_desc.type == request.stream && o.stream_desc.index == request.index &&
741  res.width == request.width && res.height == request.height &&
742  uvc_p.format == fourcc && request.fps == uvc_p.fps)
743  return true;
744  }
745  return false;
746  });
747  if (it != end(uvc_profiles))
748  {
749  uvc_profile = *it;
750  }
751  return uvc_profile;
752  }
753 
754  bool satisfies(const stream_profile& request, uint32_t fourcc, const std::vector<platform::stream_profile>& uvc_profiles) const
755  {
756  auto uvc_profile = get_uvc_profile(request, fourcc, uvc_profiles);
757  return provides_stream(request, fourcc, uvc_profile) &&
758  get_format(request.stream, request.index) == request.format;
759  }
760 
761  bool provides_stream(const stream_profile& request, uint32_t fourcc, const platform::stream_profile& uvc_profile) const
762  {
763  for (auto& o : outputs)
764  {
765  auto res = o.stream_resolution(resolution{ uvc_profile.width, uvc_profile.height });
766  if (o.stream_desc.type == request.stream && o.stream_desc.index == request.index &&
767  res.width == request.width && res.height == request.height)
768  return true;
769  }
770 
771  return false;
772  }
773  rs2_format get_format(rs2_stream stream, int index) const
774  {
775  for (auto& o : outputs)
776  if (o.stream_desc.type == stream && o.stream_desc.index == index)
777  return o.format;
778 
779  throw invalid_value_exception("missing output");
780  }
781 
782  operator std::vector<output_tuple>()
783  {
784  std::vector<output_tuple> tuple_outputs;
785 
786  for (auto output : outputs)
787  {
788  tuple_outputs.push_back(std::make_tuple(output.stream_desc.type, output.stream_desc.index, output.format));
789  }
790  return tuple_outputs;
791  }
792 
793  };
794 
796 
797  class frame_interface;
798 
800  {
801  int m_major, m_minor, m_patch, m_build;
802  bool is_any;
804 
805  std::string to_string() const;
806  static std::vector<std::string> split(const std::string& str);
807  static int parse_part(const std::string& name, int part);
808 
809  public:
810  firmware_version() : m_major(0), m_minor(0), m_patch(0), m_build(0), is_any(true), string_representation(to_string()) {}
811 
812  firmware_version(int major, int minor, int patch, int build, bool is_any = false)
813  : m_major(major), m_minor(minor), m_patch(patch), m_build(build), is_any(is_any), string_representation(to_string()) {}
814 
815  // CTO experimental firmware versions are marked with build >= 90
816  bool experimental() const { return m_build >= 90; }
817 
819  {
820  return{};
821  }
822 
824  : 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()) {}
825 
826  bool operator<=(const firmware_version& other) const
827  {
828  if (is_any || other.is_any) return true;
829  if (m_major > other.m_major) return false;
830  if ((m_major == other.m_major) && (m_minor > other.m_minor)) return false;
831  if ((m_major == other.m_major) && (m_minor == other.m_minor) && (m_patch > other.m_patch)) return false;
832  if ((m_major == other.m_major) && (m_minor == other.m_minor) && (m_patch == other.m_patch) && (m_build > other.m_build)) return false;
833  return true;
834  }
835  bool operator==(const firmware_version& other) const
836  {
837  return is_any || (other.m_major == m_major && other.m_minor == m_minor && other.m_patch == m_patch && other.m_build == m_build);
838  }
839 
840  bool operator> (const firmware_version& other) const { return !(*this < other) || is_any; }
841  bool operator!=(const firmware_version& other) const { return !(*this == other); }
842  bool operator<(const firmware_version& other) const { return !(*this == other) && (*this <= other); }
843  bool operator>=(const firmware_version& other) const { return (*this == other) || (*this > other); }
844 
845  bool is_between(const firmware_version& from, const firmware_version& until) const
846  {
847  return (from <= *this) && (*this <= until);
848  }
849 
850  operator const char*() const
851  {
852  return string_representation.c_str();
853  }
854 
855  operator std::string() const
856  {
857  return string_representation.c_str();
858  }
859  };
860 
861  // This class is used to buffer up several writes to a structure-valued XU control, and send the entire structure all at once
862  // Additionally, it will ensure that any fields not set in a given struct will retain their original values
863  template<class T, class R, class W> struct struct_interface
864  {
868  bool active;
869 
870  struct_interface(R r, W w) : reader(r), writer(w), active(false) {}
871 
872  void activate() { if (!active) { struct_ = reader(); active = true; } }
873  template<class U> double get(U T::* field) { activate(); return static_cast<double>(struct_.*field); }
874  template<class U, class V> void set(U T::* field, V value) { activate(); struct_.*field = static_cast<U>(value); }
875  void commit() { if (active) writer(struct_); }
876  };
877 
878  template<class T, class R, class W>
879  std::shared_ptr<struct_interface<T, R, W>> make_struct_interface(R r, W w)
880  {
881  return std::make_shared<struct_interface<T, R, W>>(r, w);
882  }
883 
884  // Provides an efficient wraparound for built-in arithmetic times, for use-cases such as a rolling timestamp
885  template <typename T, typename S>
887  {
888  public:
890  last_input(std::numeric_limits<T>::lowest()), accumulated(0) {
891  static_assert(
894  (std::numeric_limits<T>::max() < std::numeric_limits<S>::max()) &&
895  (std::numeric_limits<T>::lowest() >= std::numeric_limits<S>::lowest())
896  , "Wraparound class requirements are not met");
897  }
898 
899  S calc(const T input)
900  {
901  accumulated += static_cast<T>(input - last_input); // Automatically resolves wraparounds
902  last_input = input;
903  return (accumulated);
904  }
905 
906  void reset() { last_input = std::numeric_limits<T>::lowest(); accumulated = 0; }
907 
908  private:
911  };
912 
913  typedef void(*frame_callback_function_ptr)(rs2_frame * frame, void * user);
914 
916  {
918  void * user;
919  public:
920  frame_callback() : frame_callback(nullptr, nullptr) {}
921  frame_callback(frame_callback_function_ptr on_frame, void * user) : fptr(on_frame), user(user) {}
922 
923  operator bool() const { return fptr != nullptr; }
924  void on_frame (rs2_frame * frame) override {
925  if (fptr)
926  {
927  try { fptr(frame, user); } catch (...)
928  {
929  LOG_ERROR("Received an exception from frame callback!");
930  }
931  }
932  }
933  void release() override { delete this; }
934  };
935 
937  {
939  void * user;
940  public:
943  : fptr(on_frame), user(user) {}
944 
945  operator bool() const { return fptr != nullptr; }
946  void on_frame(rs2_frame * frame, rs2_source * source) override {
947  if (fptr)
948  {
949  try { fptr(frame, source, user); }
950  catch (...)
951  {
952  LOG_ERROR("Received an exception from frame callback!");
953  }
954  }
955  }
956  void release() override { delete this; }
957  };
958 
959 
960  template<class T>
962  {
963  T on_frame_function; //Callable of type: void(frame_interface* frame)
964  public:
965  explicit internal_frame_callback(T on_frame) : on_frame_function(on_frame) {}
966 
967  void on_frame(rs2_frame* fref) override
968  {
969  on_frame_function((frame_interface*)(fref));
970  }
971 
972  void release() override { delete this; }
973  };
974 
976 
978  {
980  void * user;
981  public:
983  notifications_callback(notifications_callback_function_ptr on_notification, void * user) : nptr(on_notification), user(user) {}
984 
985  operator bool() const { return nptr != nullptr; }
986  void on_notification(rs2_notification * notification) override {
987  if (nptr)
988  {
989  try { nptr(notification, user); }
990  catch (...)
991  {
992  LOG_ERROR("Received an exception from notification callback!");
993  }
994  }
995  }
996  void release() override { delete this; }
997  };
998 
1000 
1002  {
1004  void * user;
1005  public:
1008  : nptr(on_destruction), user(user) {}
1009 
1010  operator bool() const { return nptr != nullptr; }
1011  void on_destruction() override {
1012  if (nptr)
1013  {
1014  try { nptr(user); }
1015  catch (...)
1016  {
1017  LOG_ERROR("Received an exception from software device destruction callback!");
1018  }
1019  }
1020  }
1021  void release() override { delete this; }
1022  };
1023 
1024  typedef void(*devices_changed_function_ptr)(rs2_device_list* removed, rs2_device_list* added, void * user);
1025 
1027  {
1029  void * user;
1030  public:
1032  devices_changed_callback(devices_changed_function_ptr on_devices_changed, void * user) : nptr(on_devices_changed), user(user) {}
1033 
1034  operator bool() const { return nptr != nullptr; }
1035  void on_devices_changed(rs2_device_list* removed, rs2_device_list* added) override {
1036  if (nptr)
1037  {
1038  try { nptr(removed, added, user); }
1039  catch (...)
1040  {
1041  LOG_ERROR("Received an exception from devices_changed callback!");
1042  }
1043  }
1044  }
1045  void release() override { delete this; }
1046  };
1047 
1049  {
1052  public:
1054  update_progress_callback(rs2_update_progress_callback_ptr on_update_progress, void* client_data = NULL)
1055  : _nptr(on_update_progress), _client_data(client_data){}
1056 
1057  operator bool() const { return _nptr != nullptr; }
1058  void on_update_progress(const float progress) {
1059  if (_nptr)
1060  {
1061  try { _nptr(progress, _client_data); }
1062  catch (...)
1063  {
1064  LOG_ERROR("Received an exception from firmware update progress callback!");
1065  }
1066  }
1067  }
1068  void release() { delete this; }
1069  };
1070 
1071  typedef std::shared_ptr<rs2_frame_callback> frame_callback_ptr;
1072  typedef std::shared_ptr<rs2_frame_processor_callback> frame_processor_callback_ptr;
1073  typedef std::shared_ptr<rs2_notifications_callback> notifications_callback_ptr;
1074  typedef std::shared_ptr<rs2_calibration_change_callback> calibration_change_callback_ptr;
1075  typedef std::shared_ptr<rs2_software_device_destruction_callback> software_device_destruction_callback_ptr;
1076  typedef std::shared_ptr<rs2_devices_changed_callback> devices_changed_callback_ptr;
1077  typedef std::shared_ptr<rs2_update_progress_callback> update_progress_callback_ptr;
1078 
1079  using internal_callback = std::function<void(rs2_device_list* removed, rs2_device_list* added)>;
1081  {
1083 
1084  public:
1086  : _callback(callback)
1087  {}
1088 
1089  void on_devices_changed(rs2_device_list* removed, rs2_device_list* added) override
1090  {
1091  _callback(removed , added);
1092  }
1093 
1094  void release() override { delete this; }
1095  };
1096 
1097 
1098  struct notification
1099  {
1100  notification(rs2_notification_category category, int type, rs2_log_severity severity, std::string description)
1101  :category(category), type(type), severity(severity), description(description)
1102  {
1103  timestamp = std::chrono::duration<double, std::milli>(std::chrono::system_clock::now().time_since_epoch()).count();
1104  LOG_INFO(description);
1105  }
1106 
1107  rs2_notification_category category;
1108  int type;
1109  rs2_log_severity severity;
1111  double timestamp;
1113  };
1114 
1115 
1117  {
1118  public:
1119  virtual ~notification_decoder() = default;
1120  virtual notification decode(int value) = 0;
1121  };
1122 
1124  {
1125  public:
1128 
1129  void set_callback(notifications_callback_ptr callback);
1130  notifications_callback_ptr get_callback() const;
1131  void raise_notification(const notification);
1132 
1133  private:
1134  notifications_callback_ptr _callback;
1135  std::mutex _callback_mutex;
1137  };
1139  // Helper functions for library types //
1141 
1142  inline rs2_intrinsics pad_crop_intrinsics(const rs2_intrinsics & i, int pad_crop)
1143  {
1144  return{ i.width + pad_crop * 2, i.height + pad_crop * 2, i.ppx + pad_crop, i.ppy + pad_crop,
1145  i.fx, i.fy, i.model, {i.coeffs[0], i.coeffs[1], i.coeffs[2], i.coeffs[3], i.coeffs[4]} };
1146  }
1147 
1149  {
1150  const float sx = static_cast<float>(width) / i.width, sy = static_cast<float>(height) / i.height;
1151  return{ width, height, i.ppx*sx, i.ppy*sy, i.fx*sx, i.fy*sy, i.model,
1152  {i.coeffs[0], i.coeffs[1], i.coeffs[2], i.coeffs[3], i.coeffs[4]} };
1153  }
1154 
1155  inline bool operator == (const rs2_intrinsics & a, const rs2_intrinsics & b) { return std::memcmp(&a, &b, sizeof(a)) == 0; }
1156 
1157  inline uint32_t pack(uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3)
1158  {
1159  return (c0 << 24) | (c1 << 16) | (c2 << 8) | c3;
1160  }
1161 
1162  template<class T, int C>
1164  {
1165  T buffer[C];
1166  bool is_free[C];
1167  std::mutex mutex;
1168  bool keep_allocating = true;
1169  std::condition_variable cv;
1170  int size = 0;
1171 
1172  public:
1173  static const int CAPACITY = C;
1174 
1176  {
1177  for (auto i = 0; i < C; i++)
1178  {
1179  is_free[i] = true;
1180  buffer[i] = std::move(T());
1181  }
1182  }
1183 
1185  {
1186  std::unique_lock<std::mutex> lock(mutex);
1187  if (!keep_allocating) return nullptr;
1188 
1189  for (auto i = 0; i < C; i++)
1190  {
1191  if (is_free[i])
1192  {
1193  is_free[i] = false;
1194  size++;
1195  return &buffer[i];
1196  }
1197  }
1198  return nullptr;
1199  }
1200 
1201  void deallocate(T * item)
1202  {
1203  if (item < buffer || item >= buffer + C)
1204  {
1205  throw invalid_value_exception("Trying to return item to a heap that didn't allocate it!");
1206  }
1207  auto i = item - buffer;
1208  auto old_value = std::move(buffer[i]);
1209  buffer[i] = std::move(T());
1210 
1211  {
1212  std::unique_lock<std::mutex> lock(mutex);
1213 
1214  is_free[i] = true;
1215  size--;
1216 
1217  if (size == 0)
1218  {
1219  lock.unlock();
1220  cv.notify_one();
1221  }
1222  }
1223  }
1224 
1226  {
1227  std::unique_lock<std::mutex> lock(mutex);
1228  keep_allocating = false;
1229  }
1230 
1232  {
1233  std::unique_lock<std::mutex> lock(mutex);
1234 
1235  const auto ready = [this]()
1236  {
1237  return is_empty();
1238  };
1239  if (!ready() && !cv.wait_for(lock, std::chrono::hours(1000), ready)) // for some reason passing std::chrono::duration::max makes it return instantly
1240  {
1241  throw invalid_value_exception("Could not flush one of the user controlled objects!");
1242  }
1243  }
1244 
1245  bool is_empty() const { return size == 0; }
1246  int get_size() const { return size; }
1247  };
1248 
1250  {
1251  std::string id = ""; // to distinguish between different pins of the same device
1257 
1258  operator std::string()
1259  {
1260  std::stringstream s;
1261  s << "id- " << id <<
1262  "\nvid- " << std::hex << vid <<
1263  "\npid- " << std::hex << pid <<
1264  "\nmi- " << mi <<
1265  "\nunique_id- " << unique_id <<
1266  "\npath- " << device_path;
1267 
1268  return s.str();
1269  }
1270  };
1271 
1272  inline bool operator==(const uvc_device_info& a,
1273  const uvc_device_info& b)
1274  {
1275  return (a.vid == b.vid) &&
1276  (a.pid == b.pid) &&
1277  (a.mi == b.mi) &&
1278  (a.unique_id == b.unique_id) &&
1279  (a.id == b.id) &&
1280  (a.device_path == b.device_path);
1281  }
1282 
1284  {
1286 
1291 
1292  operator std::string()
1293  {
1294  std::stringstream s;
1295 
1296  s << "vid- " << std::hex << vid <<
1297  "\npid- " << std::hex << pid <<
1298  "\nmi- " << mi <<
1299  "\nunique_id- " << unique_id;
1300 
1301  return s.str();
1302  }
1303  };
1304 
1305  inline bool operator==(const usb_device_info& a,
1306  const usb_device_info& b)
1307  {
1308  return (a.id == b.id) &&
1309  (a.vid == b.vid) &&
1310  (a.pid == b.pid) &&
1311  (a.mi == b.mi) &&
1312  (a.unique_id == b.unique_id);
1313  }
1314 
1316  {
1322 
1323  operator std::string()
1324  {
1325  std::stringstream s;
1326  s << "id- " << id <<
1327  "\nvid- " << std::hex << vid <<
1328  "\npid- " << std::hex << pid <<
1329  "\nunique_id- " << unique_id <<
1330  "\npath- " << device_path;
1331 
1332  return s.str();
1333  }
1334  };
1335 
1336  inline bool operator==(const hid_device_info& a,
1337  const hid_device_info& b)
1338  {
1339  return (a.id == b.id) &&
1340  (a.vid == b.vid) &&
1341  (a.pid == b.pid) &&
1342  (a.unique_id == b.unique_id) &&
1343  (a.device_path == b.device_path);
1344  }
1345 
1346 
1348  {
1349  devices_data(std::vector<uvc_device_info> uvc_devices, std::vector<usb_device_info> usb_devices, std::vector<hid_device_info> hid_devices)
1350  :_uvc_devices(uvc_devices), _usb_devices(usb_devices), _hid_devices(hid_devices) {}
1351 
1352  devices_data(std::vector<usb_device_info> usb_devices)
1353  :_usb_devices(usb_devices) {}
1354 
1355  devices_data(std::vector<uvc_device_info> uvc_devices, std::vector<usb_device_info> usb_devices)
1356  :_uvc_devices(uvc_devices), _usb_devices(usb_devices) {}
1357 
1358  std::vector<uvc_device_info> _uvc_devices;
1359  std::vector<usb_device_info> _usb_devices;
1360  std::vector<hid_device_info> _hid_devices;
1361 
1362  bool operator == (const devices_data& other)
1363  {
1364  return !list_changed(_uvc_devices, other._uvc_devices) &&
1365  !list_changed(_hid_devices, other._hid_devices);
1366  }
1367 
1368  operator std::string()
1369  {
1370  std::string s;
1371  s = _uvc_devices.size()>0 ? "uvc devices:\n" : "";
1372  for (auto uvc : _uvc_devices)
1373  {
1374  s += uvc;
1375  s += "\n\n";
1376  }
1377 
1378  s += _usb_devices.size()>0 ? "usb devices:\n" : "";
1379  for (auto usb : _usb_devices)
1380  {
1381  s += usb;
1382  s += "\n\n";
1383  }
1384 
1385  s += _hid_devices.size()>0 ? "hid devices: \n" : "";
1386  for (auto hid : _hid_devices)
1387  {
1388  s += hid;
1389  s += "\n\n";
1390  }
1391  return s;
1392  }
1393  };
1394 
1395 
1396  typedef std::function<void(devices_data old, devices_data curr)> device_changed_callback;
1398  {
1399  std::chrono::high_resolution_clock::time_point started;
1400  std::chrono::high_resolution_clock::time_point ended;
1401  };
1402 
1404 
1406  {
1407  callback_invocation_holder() : invocation(nullptr), owner(nullptr) {}
1409  callback_invocation_holder& operator=(const callback_invocation_holder&) = delete;
1410 
1412  : invocation(other.invocation), owner(other.owner)
1413  {
1414  other.invocation = nullptr;
1415  }
1416 
1417  callback_invocation_holder(callback_invocation* invocation, callbacks_heap* owner)
1418  : invocation(invocation), owner(owner)
1419  { }
1420 
1422  {
1423  if (invocation) owner->deallocate(invocation);
1424  }
1425 
1427  {
1428  invocation = other.invocation;
1429  owner = other.owner;
1430  other.invocation = nullptr;
1431  return *this;
1432  }
1433 
1434  operator bool()
1435  {
1436  return invocation != nullptr;
1437  }
1438 
1439  private:
1441  callbacks_heap* owner;
1442  };
1443 
1445  {
1446  std::function<void()> continuation;
1447  const void* protected_data = nullptr;
1448 
1449  frame_continuation(const frame_continuation &) = delete;
1450  frame_continuation & operator=(const frame_continuation &) = delete;
1451  public:
1452  frame_continuation() : continuation([]() {}) {}
1453 
1454  explicit frame_continuation(std::function<void()> continuation, const void* protected_data) : continuation(continuation), protected_data(protected_data) {}
1455 
1456 
1457  frame_continuation(frame_continuation && other) : continuation(std::move(other.continuation)), protected_data(other.protected_data)
1458  {
1459  other.continuation = []() {};
1460  other.protected_data = nullptr;
1461  }
1462 
1463  void operator()()
1464  {
1465  continuation();
1466  continuation = []() {};
1467  protected_data = nullptr;
1468  }
1469 
1470  void reset()
1471  {
1472  protected_data = nullptr;
1473  continuation = [](){};
1474  }
1475 
1476  const void* get_data() const { return protected_data; }
1477 
1479  {
1480  continuation();
1481  protected_data = other.protected_data;
1482  continuation = other.continuation;
1483  other.continuation = []() {};
1484  other.protected_data = nullptr;
1485  return *this;
1486  }
1487 
1489  {
1490  continuation();
1491  }
1492 
1493  };
1494 
1495  // this class is a convinience wrapper for intrinsics / extrinsics validation methods
1497  {
1498  public:
1499  calibration_validator(std::function<bool(rs2_stream, rs2_stream)> extrinsic_validator,
1500  std::function<bool(rs2_stream)> intrinsic_validator);
1502 
1503  bool validate_extrinsics(rs2_stream from_stream, rs2_stream to_stream) const;
1504  bool validate_intrinsics(rs2_stream stream) const;
1505 
1506  private:
1507  std::function<bool(rs2_stream from_stream, rs2_stream to_stream)> extrinsic_validator;
1508  std::function<bool(rs2_stream stream)> intrinsic_validator;
1509  };
1510 
1511  inline bool check_not_all_zeros(std::vector<byte> data)
1512  {
1513  return std::find_if(data.begin(), data.end(), [](byte b){ return b!=0; }) != data.end();
1514  }
1515 
1517  {
1518  auto t = time(nullptr);
1519  char buffer[20] = {};
1520  const tm* time = localtime(&t);
1521  if (nullptr != time)
1522  strftime(buffer, sizeof(buffer), "%Y-%m-%d-%H_%M_%S", time);
1523  return to_string() << buffer;
1524  }
1525 
1526  bool file_exists(const char* filename);
1527 
1529  // Extrinsic auxillary routines routines //
1531  float3x3 calc_rotation_from_rodrigues_angles(const std::vector<double> rot);
1532  // Auxillary function that calculates standard 32bit CRC code. used in verificaiton
1533  uint32_t calc_crc32(const uint8_t *buf, size_t bufsize);
1534 
1535 
1537  {
1538  public:
1540  _backend(backend_ref),_active_object([this](dispatcher::cancellable_timer cancellable_timer)
1541  {
1542  polling(cancellable_timer);
1543  }), _devices_data()
1544  {
1545  _devices_data = { _backend->query_uvc_devices(),
1546  _backend->query_usb_devices(),
1547  _backend->query_hid_devices() };
1548  }
1549 
1551  {
1552  stop();
1553  }
1554 
1555  void polling(dispatcher::cancellable_timer cancellable_timer)
1556  {
1557  if(cancellable_timer.try_sleep(5000))
1558  {
1559  platform::backend_device_group curr(_backend->query_uvc_devices(), _backend->query_usb_devices(), _backend->query_hid_devices());
1560  if(list_changed(_devices_data.uvc_devices, curr.uvc_devices ) ||
1561  list_changed(_devices_data.usb_devices, curr.usb_devices ) ||
1562  list_changed(_devices_data.hid_devices, curr.hid_devices ))
1563  {
1564  callback_invocation_holder callback = { _callback_inflight.allocate(), &_callback_inflight };
1565  if(callback)
1566  {
1567  _callback(_devices_data, curr);
1568  _devices_data = curr;
1569  }
1570  }
1571  }
1572  }
1573 
1575  {
1576  stop();
1577  _callback = std::move(callback);
1578  _active_object.start();
1579  }
1580 
1581  void stop() override
1582  {
1583  _active_object.stop();
1584 
1585  _callback_inflight.wait_until_empty();
1586  }
1587 
1588  private:
1590 
1591  callbacks_heap _callback_inflight;
1593 
1596 
1597  };
1598 
1599 
1600  template<typename HostingClass, typename... Args>
1601  class signal
1602  {
1604  public:
1606  {
1607  }
1608 
1609  signal(signal&& other)
1610  {
1611  std::lock_guard<std::mutex> locker(other.m_mutex);
1612  m_subscribers = std::move(other.m_subscribers);
1613 
1614  other.m_subscribers.clear();
1615  }
1616 
1618  {
1619  std::lock_guard<std::mutex> locker(other.m_mutex);
1620  m_subscribers = std::move(other.m_subscribers);
1621 
1622  other.m_subscribers.clear();
1623  return *this;
1624  }
1625 
1626  int subscribe(const std::function<void(Args...)>& func)
1627  {
1628  std::lock_guard<std::mutex> locker(m_mutex);
1629 
1630  int token = -1;
1631  for (int i = 0; i < (std::numeric_limits<int>::max)(); i++)
1632  {
1633  if (m_subscribers.find(i) == m_subscribers.end())
1634  {
1635  token = i;
1636  break;
1637  }
1638  }
1639 
1640  if (token != -1)
1641  {
1642  m_subscribers.emplace(token, func);
1643  }
1644 
1645  return token;
1646  }
1647 
1648  bool unsubscribe(int token)
1649  {
1650  std::lock_guard<std::mutex> locker(m_mutex);
1651 
1652  bool retVal = false;
1653  typename std::map<int, std::function<void(Args...)>>::iterator it = m_subscribers.find(token);
1654  if (it != m_subscribers.end())
1655  {
1656  m_subscribers.erase(token);
1657  retVal = true;
1658  }
1659 
1660  return retVal;
1661  }
1662 
1663  int operator+=(const std::function<void(Args...)>& func)
1664  {
1665  return subscribe(func);
1666  }
1667 
1668  bool operator-=(int token)
1669  {
1670  return unsubscribe(token);
1671  }
1672 
1673  private:
1674  signal(const signal& other); // non construction-copyable
1675  signal& operator=(const signal&); // non copyable
1676 
1677  bool raise(Args... args)
1678  {
1679  std::vector<std::function<void(Args...)>> functions;
1680  bool retVal = false;
1681 
1682  std::unique_lock<std::mutex> locker(m_mutex);
1683  if (m_subscribers.size() > 0)
1684  {
1685  typename std::map<int, std::function<void(Args...)>>::iterator it = m_subscribers.begin();
1686  while (it != m_subscribers.end())
1687  {
1688  functions.emplace_back(it->second);
1689  ++it;
1690  }
1691  }
1692  locker.unlock();
1693 
1694  if (functions.size() > 0)
1695  {
1696  for (auto func : functions)
1697  {
1698  func(std::forward<Args>(args)...);
1699  }
1700 
1701  retVal = true;
1702  }
1703 
1704  return retVal;
1705  }
1706 
1707  bool operator()(Args... args)
1708  {
1709  return raise(std::forward<Args>(args)...);
1710  }
1711 
1712  std::mutex m_mutex;
1713  std::map<int, std::function<void(Args...)>> m_subscribers;
1714  };
1715 
1716  template <typename T>
1718  {
1719  public:
1720  optional_value() : _valid(false) {}
1721  explicit optional_value(const T& v) : _valid(true), _value(v) {}
1722 
1723  operator bool() const
1724  {
1725  return has_value();
1726  }
1727  bool has_value() const
1728  {
1729  return _valid;
1730  }
1731 
1732  T& operator=(const T& v)
1733  {
1734  _valid = true;
1735  _value = v;
1736  return _value;
1737  }
1738 
1739  T& value() &
1740  {
1741  if (!_valid) throw std::runtime_error("bad optional access");
1742  return _value;
1743  }
1744 
1745  T&& value() &&
1746  {
1747  if (!_valid) throw std::runtime_error("bad optional access");
1748  return std::move(_value);
1749  }
1750 
1751  const T* operator->() const
1752  {
1753  return &_value;
1754  }
1756  {
1757  return &_value;
1758  }
1759  const T& operator*() const&
1760  {
1761  return _value;
1762  }
1764  {
1765  return _value;
1766  }
1767  T&& operator*() &&
1768  {
1769  return std::move(_value);
1770  }
1771 
1772  bool operator==(const T& other) const
1773  {
1774  return this->_value == other;
1775  }
1776 
1777  bool operator!=(const T& other) const
1778  {
1779  return !(*this == other);
1780  }
1781  private:
1782  bool _valid;
1784  };
1785 }
1786 
1787 inline std::ostream& operator<<( std::ostream& out, rs2_extrinsics const & e )
1788 {
1789  return out
1790  << "[ r["
1791  << e.rotation[0] << "," << e.rotation[1] << "," << e.rotation[2] << "," << e.rotation[3] << "," << e.rotation[4] << ","
1792  << e.rotation[5] << "," << e.rotation[6] << "," << e.rotation[7] << "," << e.rotation[8]
1793  << "] t[" << e.translation[0] << "," << e.translation[1] << "," << e.translation[2] << "] ]";
1794 }
1795 
1796 inline std::ostream& operator<<( std::ostream& out, rs2_intrinsics const & i )
1797 {
1798  return out
1799  << "[ " << i.width << "x" << i.height
1800  << " p[" << i.ppx << " " << i.ppy << "]"
1801  << " f[" << i.fx << " " << i.fy << "]"
1802  << " " << librealsense::get_string( i.model )
1803  << " [" << i.coeffs[0] << " " << i.coeffs[1] << " " << i.coeffs[2]
1804  << " " << i.coeffs[3] << " " << i.coeffs[4]
1805  << "] ]";
1806 }
1807 
1808 inline std::ostream& operator<<( std::ostream& s, rs2_dsm_params const & self )
1809 {
1810  s << "[ ";
1811  if( self.timestamp )
1812  {
1813  time_t t = self.timestamp;
1814  auto ptm = localtime( &t );
1815  char buf[256];
1816  strftime( buf, sizeof( buf ), "%F.%T ", ptm );
1817  s << buf;
1818 
1819  unsigned patch = self.version & 0xF;
1820  unsigned minor = (self.version >> 4) & 0xFF;
1821  unsigned major = (self.version >> 12);
1822  s << major << '.' << minor << '.' << patch << ' ';
1823  }
1824  else
1825  {
1826  s << "new: ";
1827  }
1828  switch( self.model )
1829  {
1830  case RS2_DSM_CORRECTION_NONE: break;
1831  case RS2_DSM_CORRECTION_AOT: s << "AoT "; break;
1832  case RS2_DSM_CORRECTION_TOA: s << "ToA "; break;
1833  }
1834  s << "x[" << self.h_scale << " " << self.v_scale << "] ";
1835  s << "+[" << self.h_offset << " " << self.v_offset;
1836  if( self.rtd_offset )
1837  s << " rtd " << self.rtd_offset;
1838  s << "]";
1839  if( self.temp_x2 )
1840  s << " @" << float( self.temp_x2 ) / 2 << "degC";
1841  s << " ]";
1842  return s;
1843 }
1844 
1845 template<typename T>
1846 uint32_t rs_fourcc(const T a, const T b, const T c, const T d)
1847 {
1848  static_assert((std::is_integral<T>::value), "rs_fourcc supports integral built-in types only");
1849  return ((static_cast<uint32_t>(a) << 24) |
1850  (static_cast<uint32_t>(b) << 16) |
1851  (static_cast<uint32_t>(c) << 8) |
1852  (static_cast<uint32_t>(d) << 0));
1853 }
1854 
1855 namespace std {
1856 
1857  template <>
1858  struct hash<librealsense::stream_profile>
1859  {
1861  {
1862  using std::hash;
1863 
1864  return (hash<uint32_t>()(k.height))
1865  ^ (hash<uint32_t>()(k.width))
1866  ^ (hash<uint32_t>()(k.fps))
1867  ^ (hash<uint32_t>()(k.format))
1868  ^ (hash<uint32_t>()(k.stream));
1869  }
1870  };
1871 
1872  template <>
1873  struct hash<librealsense::platform::stream_profile>
1874  {
1876  {
1877  using std::hash;
1878 
1879  return (hash<uint32_t>()(k.height))
1880  ^ (hash<uint32_t>()(k.width))
1881  ^ (hash<uint32_t>()(k.fps))
1882  ^ (hash<uint32_t>()(k.format));
1883  }
1884  };
1885 
1886  template <>
1887  struct hash<rs2_format>
1888  {
1889  size_t operator()(const rs2_format& f) const
1890  {
1891  using std::hash;
1892 
1893  return hash<uint32_t>()(f);
1894  }
1895  };
1896 }
1897 
1898 template<class T>
1899 bool contains(const T& first, const T& second)
1900 {
1901  return first == second;
1902 }
1903 
1904 template<class T>
1905 std::vector<std::shared_ptr<T>> subtract_sets(const std::vector<std::shared_ptr<T>>& first, const std::vector<std::shared_ptr<T>>& second)
1906 {
1907  std::vector<std::shared_ptr<T>> results;
1908  std::for_each(first.begin(), first.end(), [&](std::shared_ptr<T> data)
1909  {
1910  if (std::find_if(second.begin(), second.end(), [&](std::shared_ptr<T> new_dev) {
1911  return contains(data, new_dev);
1912  }) == second.end())
1913  {
1914  results.push_back(data);
1915  }
1916  });
1917  return results;
1918 }
1919 
1920 enum res_type {
1924 };
1925 
1927 {
1928  if (width == 256) // Crop resolution
1930 
1931  if (width == 640)
1933  else if (width < 640)
1934  return res_type::low_resolution;
1935 
1937 }
1938 
1939 inline bool operator==( const rs2_extrinsics& a, const rs2_extrinsics& b )
1940 {
1941  for( int i = 0; i < 3; i++ )
1942  if( a.translation[i] != b.translation[i] )
1943  return false;
1944  for( int j = 0; j < 3; j++ )
1945  for( int i = 0; i < 3; i++ )
1946  if( std::fabs( a.rotation[j * 3 + i] - b.rotation[j * 3 + i] )
1947  > std::numeric_limits<float>::epsilon() )
1948  return false;
1949  return true;
1950 }
1951 
1952 #endif
static const textual_icon lock
Definition: model-views.h:218
platform::stream_profile get_uvc_profile(const stream_profile &request, uint32_t fourcc, const std::vector< platform::stream_profile > &uvc_profiles) const
Definition: src/types.h:731
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: src/types.h:576
rs2_intrinsics scale_intrinsics(const rs2_intrinsics &i, int width, int height)
Definition: src/types.h:1148
resolution_func stream_resolution
Definition: src/types.h:722
#define LOG_INFO(...)
Definition: src/types.h:240
static const double TIMESTAMP_USEC_TO_MSEC
Definition: src/types.h:92
GLuint GLuint end
void deallocate(T *item)
Definition: src/types.h:1201
GLboolean GLboolean GLboolean b
size_t operator()(const librealsense::platform::stream_profile &k) const
Definition: src/types.h:1875
void reset_logger()
Definition: log.cpp:59
std::function< bool(rs2_stream from_stream, rs2_stream to_stream)> extrinsic_validator
Definition: src/types.h:1507
camera_disconnected_exception(const std::string &msg) noexcept
Definition: src/types.h:328
rs2_exception_type
Exception types are the different categories of errors that RealSense API might return.
Definition: rs_types.h:30
GLenum GLuint GLenum severity
const char * get_string(rs2_rs400_visual_preset value)
typedef void(APIENTRY *GLDEBUGPROC)(GLenum source
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:42
GLuint const GLchar * name
wrong_api_call_sequence_exception(const std::string &msg) noexcept
Definition: src/types.h:376
pose inv(pose const &p)
Definition: test-pose.cpp:178
std::vector< usb_device_info > _usb_devices
Definition: src/types.h:1359
rs2_calibration_type
Definition: rs_device.h:344
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: src/types.h:602
GLdouble s
io_exception(const std::string &msg) noexcept
Definition: src/types.h:321
std::tuple< rs2_stream, int, rs2_format > output_tuple
Definition: src/types.h:653
rs2_notification_category category
Definition: src/types.h:1107
float3 operator-(const float3 &a, const float3 &b)
Definition: src/types.h:580
void(* rs2_frame_processor_callback_ptr)(rs2_frame *, rs2_source *, void *)
Definition: rs_types.h:297
std::shared_ptr< rs2_frame_callback > frame_callback_ptr
Definition: src/types.h:1071
GLfloat GLfloat p
Definition: glext.h:12687
std::vector< uint32_t > split(const std::string &s, char delim)
rs2_distortion
Distortion model: defines how pixel coordinates should be mapped to sensor coordinates.
Definition: rs_types.h:45
float translation[3]
Definition: rs_sensor.h:99
std::shared_ptr< struct_interface< T, R, W > > make_struct_interface(R r, W w)
Definition: src/types.h:879
std::string array2str(T &data)
Definition: src/types.h:120
std::mutex _mtx
Definition: src/types.h:488
void log_to_callback(rs2_log_severity min_severity, log_callback_ptr callback)
Definition: log.cpp:54
#define CAPACITY
std::string make_less_screamy(const char *str)
Definition: types.cpp:52
rs2_sr300_visual_preset
For SR300 devices: provides optimized settings (presets) for specific types of usage.
Definition: rs_option.h:119
bool val_in_range(const T &val, const std::initializer_list< T > &list)
Definition: src/types.h:174
const void * get_data() const
Definition: src/types.h:1476
Video DSM (Digital Sync Module) parameters for calibration (same layout as in FW ac_depth_params) Thi...
Definition: rs_types.h:74
GLfloat value
std::chrono::high_resolution_clock::time_point started
Definition: src/types.h:1399
float3 operator*(const float3 &a, float b)
Definition: src/types.h:581
T * operator->() const
Definition: src/types.h:411
void polling(dispatcher::cancellable_timer cancellable_timer)
Definition: src/types.h:1555
stream_descriptor(rs2_stream type, int index=0)
Definition: src/types.h:705
platform::device_changed_callback _callback
Definition: src/types.h:1595
rs2_calib_target_type
Calibration target type.
Definition: rs_frame.h:74
std::function< void(frame_interface *)> on_frame
Definition: streaming.h:164
void(* frame_callback_function_ptr)(rs2_frame *frame, void *user)
Definition: src/types.h:913
notifications_callback_ptr _callback
Definition: src/types.h:1134
bool satisfies(const stream_profile &request, uint32_t fourcc, const std::vector< platform::stream_profile > &uvc_profiles) const
Definition: src/types.h:754
backend_exception(const std::string &msg, rs2_exception_type exception_type) noexcept
Definition: src/types.h:336
stream_output(stream_descriptor stream_desc_in, rs2_format format_in, resolution_func res_func=[](resolution res){return res;})
Definition: src/types.h:712
def progress(args)
Definition: log.py:43
frame_callback(frame_callback_function_ptr on_frame, void *user)
Definition: src/types.h:921
GLenum GLenum dst
Definition: glext.h:1751
lazy(std::function< T()> initializer)
Definition: src/types.h:409
GLenum GLuint GLsizei bufsize
Definition: glext.h:1776
std::function< void()> continuation
Definition: src/types.h:1446
unsigned short uint16_t
Definition: stdint.h:79
float coeffs[5]
Definition: rs_types.h:67
void(* notifications_callback_function_ptr)(rs2_notification *notification, void *user)
Definition: src/types.h:975
update_progress_callback(rs2_update_progress_callback_ptr on_update_progress, void *client_data=NULL)
Definition: src/types.h:1054
GLdouble GLdouble GLdouble w
GLsizei const GLchar *const * string
d
Definition: rmse.py:171
bool check_not_all_zeros(std::vector< byte > data)
Definition: src/types.h:1511
void on_update_progress(const float progress)
Definition: src/types.h:1058
bool is_between(const firmware_version &from, const firmware_version &until) const
Definition: src/types.h:845
rs2_format get_format(rs2_stream stream, int index) const
Definition: src/types.h:773
void log_to_file(rs2_log_severity min_severity, const char *file_path)
Definition: log.cpp:49
rs2_host_perf_mode
values for RS2_OPTION_HOST_PERFORMANCE option.
Definition: rs_option.h:202
signal & operator=(signal &&other)
Definition: src/types.h:1617
GLuint GLuint stream
Definition: glext.h:1790
#define LRS_EXTENSION_API
Definition: src/types.h:20
librealsense::small_heap< callback_invocation, 1 > callbacks_heap
Definition: src/types.h:1403
GLenum src
Definition: glext.h:1751
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:1960
void on_frame(rs2_frame *fref) override
Definition: src/types.h:967
unsigned char uint8_t
Definition: stdint.h:78
static firmware_version any()
Definition: src/types.h:818
bool operator>(failed, failed)
e
Definition: rmse.py:177
GLenum GLfloat * buffer
bool unsubscribe(int token)
Definition: src/types.h:1648
static const textual_icon stop
Definition: model-views.h:225
rs2_cah_trigger
values for RS2_OPTION_TRIGGER_CAMERA_ACCURACY_HEALTH option.
Definition: rs_option.h:192
rs2_extrinsics identity_matrix()
Definition: src/types.h:611
frame_callback_function_ptr fptr
Definition: src/types.h:917
std::tuple< platform::stream_profile_tuple, native_pixel_format_tuple, std::vector< output_tuple > > request_mapping_tuple
Definition: src/types.h:654
std::map< int, std::function< void(Args...)> > m_subscribers
Definition: src/types.h:1713
float rotation[9]
Definition: rs_sensor.h:98
GLenum GLuint id
lazy & operator=(lazy &&other) noexcept
Definition: src/types.h:447
lazy & operator=(std::function< T()> func) noexcept
Definition: src/types.h:442
GLuint index
#define RS2_ENUM_HELPERS_CUSTOMIZED(TYPE, FIRST, LAST)
Definition: src/types.h:518
void(* rs2_update_progress_callback_ptr)(const float, void *)
Definition: rs_types.h:298
std::shared_ptr< rs2_update_progress_callback > update_progress_callback_ptr
Definition: src/types.h:1077
GLdouble t
std::ostream & operator<<(std::ostream &os, const stream_profiles &profiles)
Definition: streaming.h:168
GLboolean GLboolean GLboolean GLboolean a
GLenum GLuint GLenum GLsizei const GLchar * buf
#define RS2_ENUM_HELPERS(TYPE, PREFIX)
Definition: src/types.h:514
GLuint GLfloat * val
float3x3 transpose(const float3x3 &a)
Definition: src/types.h:588
pose inverse(const pose &a)
Definition: src/types.h:592
std::shared_ptr< rs2_log_callback > log_callback_ptr
Definition: src/types.h:202
static const double r2d
Definition: src/types.h:59
T rad2deg(T val)
Definition: src/types.h:61
const int RS2_USER_QUEUE_SIZE
Definition: src/types.h:54
pose to_pose(const rs2_extrinsics &a)
Definition: src/types.h:593
not_this_one begin(...)
GLdouble f
std::string hexify(const T &val)
Definition: src/types.h:185
const int W
constexpr size_t arr_size(T const &)
Definition: src/types.h:105
rs2_extrinsics to_raw_extrinsics(rs2_extrinsics extr)
Definition: types.cpp:26
std::function< void(devices_data old, devices_data curr)> device_changed_callback
Definition: src/types.h:1396
GLsizeiptr size
invalid_value_exception(const std::string &msg) noexcept
Definition: src/types.h:368
devices_changed_function_ptr nptr
Definition: src/types.h:1028
bool operator!=(const firmware_version &other) const
Definition: src/types.h:841
unrecoverable_exception(const std::string &msg, rs2_exception_type exception_type) noexcept
Definition: src/types.h:311
const GLubyte * c
Definition: glext.h:12690
platform::backend_device_group _devices_data
Definition: src/types.h:1594
frame_continuation(frame_continuation &&other)
Definition: src/types.h:1457
GLdouble GLdouble r
frame_continuation & operator=(frame_continuation &&other)
Definition: src/types.h:1478
rs2_extrinsics from_raw_extrinsics(rs2_extrinsics extr)
Definition: types.cpp:39
devices_changed_callback_internal(internal_callback callback)
Definition: src/types.h:1085
size_t operator()(const librealsense::stream_profile &k) const
Definition: src/types.h:1860
std::shared_ptr< rs2_frame_processor_callback > frame_processor_callback_ptr
Definition: src/types.h:1072
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: src/types.h:1905
rs2_calibration_status
Definition: rs_device.h:356
std::function< void(backend_device_group old, backend_device_group curr)> device_changed_callback
Definition: backend.h:574
std::vector< uvc_device_info > _uvc_devices
Definition: src/types.h:1358
unsigned int uint32_t
Definition: stdint.h:80
rs2_matchers
Specifies types of different matchers.
Definition: rs_types.h:230
bool file_exists(const char *filename)
Definition: types.cpp:81
devices_changed_callback(devices_changed_function_ptr on_devices_changed, void *user)
Definition: src/types.h:1032
T & operator=(const T &v)
Definition: src/types.h:1732
std::ostringstream ss
Definition: src/types.h:99
std::shared_ptr< rs2_notifications_callback > notifications_callback_ptr
Definition: src/types.h:1073
T clamp_val(T val, const T &min, const T &max)
Definition: src/types.h:250
bool operator<(const stream_profile &lhs, const stream_profile &rhs)
Definition: src/types.h:694
firmware_version(const std::string &name)
Definition: src/types.h:823
const T & operator*() const
Definition: src/types.h:421
rs2_exception_type _exception_type
Definition: src/types.h:298
std::string datetime_string()
Definition: src/types.h:1516
uint32_t rs_fourcc(const T a, const T b, const T c, const T d)
Definition: src/types.h:1846
internal_frame_processor_fptr_callback(rs2_frame_processor_callback_ptr on_frame, void *user)
Definition: src/types.h:942
std::string generate_last_error_message(const std::string &msg) const
Definition: src/types.h:350
GLint GLsizei GLsizei height
bool operator==(const T &other) const
Definition: src/types.h:1772
GLint GLint GLsizei GLint GLenum format
notifications_callback(notifications_callback_function_ptr on_notification, void *user)
Definition: src/types.h:983
rs2_playback_status
std::function< void(rs2_device_list *removed, rs2_device_list *added)> internal_callback
Definition: src/types.h:1079
std::chrono::high_resolution_clock::time_point ended
Definition: src/types.h:1400
def callback(frame)
Definition: t265_stereo.py:91
const T * operator->() const
Definition: src/types.h:1751
unsigned __int64 uint64_t
Definition: stdint.h:90
GLint j
void on_frame(rs2_frame *frame, rs2_source *source) override
Definition: src/types.h:946
rs2_update_progress_callback_ptr _nptr
Definition: src/types.h:1050
rs2_format
A stream&#39;s format identifies how binary data is encoded within a frame.
Definition: rs_sensor.h:59
callback_invocation_holder(callback_invocation *invocation, callbacks_heap *owner)
Definition: src/types.h:1417
bool operator<=(const firmware_version &other) const
Definition: src/types.h:826
GLint first
bool is_empty() const
Definition: src/types.h:1245
#define LOG_ERROR(...)
Definition: src/types.h:242
notifications_callback_function_ptr nptr
Definition: src/types.h:979
stream_profile(rs2_format fmt=RS2_FORMAT_ANY, rs2_stream strm=RS2_STREAM_ANY, int idx=0, uint32_t w=0, uint32_t h=0, uint32_t framerate=0, resolution_func res_func=[](resolution res){return res;})
Definition: src/types.h:664
size_t copy_2darray(T(&dst)[tgt_m][tgt_n], const S(&src)[src_m][src_n])
Definition: src/types.h:151
bool contains(const T &first, const T &second)
Definition: src/types.h:1899
devices_data(std::vector< uvc_device_info > uvc_devices, std::vector< usb_device_info > usb_devices, std::vector< hid_device_info > hid_devices)
Definition: src/types.h:1349
std::vector< stream_output > outputs
Definition: src/types.h:729
bool operator>=(const firmware_version &other) const
Definition: src/types.h:843
GLenum func
rs2_stream
Streams are different types of data provided by RealSense devices.
Definition: rs_sensor.h:42
bool operator==(const hdr_params &first, const hdr_params &second)
Definition: hdr-config.h:23
void on_notification(rs2_notification *notification) override
Definition: src/types.h:986
constexpr size_t arr_size_bytes(T(&arr)[sz])
Definition: src/types.h:114
windows_backend_exception(const std::string &msg) noexcept
Definition: src/types.h:360
bool operator<(const firmware_version &other) const
Definition: src/types.h:842
size_t operator()(const rs2_format &f) const
Definition: src/types.h:1889
rs2_sensor_mode
For setting the camera_mode option.
Definition: rs_option.h:165
static const double d2r
Definition: src/types.h:58
int operator+=(const std::function< void(Args...)> &func)
Definition: src/types.h:1663
bool operator!=(const T &other) const
Definition: src/types.h:1777
notification(rs2_notification_category category, int type, rs2_log_severity severity, std::string description)
Definition: src/types.h:1100
Cross-stream extrinsics: encodes the topology describing how the different devices are oriented...
Definition: rs_sensor.h:96
const T & operator*() const &
Definition: src/types.h:1759
std::function< T()> _init
Definition: src/types.h:490
rs2_exception_type get_exception_type() const noexcept
Definition: src/types.h:279
bool provides_stream(const stream_profile &request, uint32_t fourcc, const platform::stream_profile &uvc_profile) const
Definition: src/types.h:761
rs2_distortion model
Definition: rs_types.h:66
resolution_func stream_resolution
Definition: src/types.h:677
unsigned char byte
Definition: src/types.h:52
void enable_rolling_log_file(unsigned max_size)
Definition: log.cpp:64
software_device_destruction_callback(software_device_destruction_callback_function_ptr on_destruction, void *user)
Definition: src/types.h:1007
bool operator()(Args...args)
Definition: src/types.h:1707
T * operate() const
Definition: src/types.h:477
rs2_extension
Specifies advanced interfaces (capabilities) objects may implement.
Definition: rs_types.h:166
bool operator==(const firmware_version &other) const
Definition: src/types.h:835
rs2_frame_processor_callback_ptr fptr
Definition: src/types.h:938
lazy(lazy &&other) noexcept
Definition: src/types.h:426
rs2_notification_category
Category of the librealsense notification.
Definition: rs_types.h:17
static auto it
GLenum GLenum GLenum input
Definition: glext.h:10805
devices_data(std::vector< uvc_device_info > uvc_devices, std::vector< usb_device_info > usb_devices)
Definition: src/types.h:1355
not_implemented_exception(const std::string &msg) noexcept
Definition: src/types.h:384
signal(signal &&other)
Definition: src/types.h:1609
GLenum type
const char * what() const noexceptoverride
Definition: src/types.h:284
int min(int a, int b)
Definition: lz4s.c:73
stream_descriptor stream_desc
Definition: src/types.h:720
const platform::backend * _backend
Definition: src/types.h:1592
GLint GLsizei count
std::pair< uint32_t, uint32_t > width_height() const
Definition: src/types.h:679
static const double pi
Definition: src/types.h:57
void on_frame(rs2_frame *frame) override
Definition: src/types.h:924
size_t copy_array(T(&dst)[size_tgt], const S(&src)[size_src])
Definition: src/types.h:133
typename::boost::move_detail::remove_reference< T >::type && move(T &&t) BOOST_NOEXCEPT
Video stream intrinsics.
Definition: rs_types.h:58
callback_invocation_holder(callback_invocation_holder &&other)
Definition: src/types.h:1411
polling_device_watcher(const platform::backend *backend_ref)
Definition: src/types.h:1539
rs2_ambient_light
DEPRECATED! - Use RS2_OPTION_DIGITAL_GAIN instead.
Definition: rs_option.h:175
rs2_intrinsics pad_crop_intrinsics(const rs2_intrinsics &i, int pad_crop)
Definition: src/types.h:1142
GLsizei GLsizei GLchar * source
rs2_digital_gain
digital gain for RS2_OPTION_DIGITAL_GAIN option.
Definition: rs_option.h:183
void on_devices_changed(rs2_device_list *removed, rs2_device_list *added) override
Definition: src/types.h:1035
LZ4LIB_API char * dest
Definition: lz4.h:438
firmware_version(int major, int minor, int patch, int build, bool is_any=false)
Definition: src/types.h:812
librealsense_exception(const std::string &msg, rs2_exception_type exception_type) noexcept
Definition: src/types.h:290
#define NULL
Definition: tinycthread.c:47
void start(platform::device_changed_callback callback) override
Definition: src/types.h:1574
std::shared_ptr< rs2_devices_changed_callback > devices_changed_callback_ptr
Definition: src/types.h:1076
int i
static uint64_t generate_id()
Definition: src/types.h:497
int subscribe(const std::function< void(Args...)> &func)
Definition: src/types.h:1626
GLuint res
Definition: glext.h:8856
callback_invocation_holder & operator=(callback_invocation_holder &&other)
Definition: src/types.h:1426
void release() override
Definition: src/types.h:933
software_device_destruction_callback_function_ptr nptr
Definition: src/types.h:1003
void reset() const
Definition: src/types.h:466
std::function< bool(rs2_stream stream)> intrinsic_validator
Definition: src/types.h:1508
void log_to_console(rs2_log_severity min_severity)
Definition: log.cpp:44
void(* software_device_destruction_callback_function_ptr)(void *user)
Definition: src/types.h:999
std::tuple< uint32_t, int, size_t > native_pixel_format_tuple
Definition: src/types.h:652
devices_data(std::vector< usb_device_info > usb_devices)
Definition: src/types.h:1352
float3 operator+(const float3 &a, const float3 &b)
Definition: src/types.h:579
float float_4[4]
Definition: src/types.h:507
void on_devices_changed(rs2_device_list *removed, rs2_device_list *added) override
Definition: src/types.h:1089
bool operator-=(int token)
Definition: src/types.h:1668
void(* devices_changed_function_ptr)(rs2_device_list *removed, rs2_device_list *added, void *user)
Definition: src/types.h:1024
GLboolean * data
#define STREAM
Definition: rs-color.c:18
rs2_log_severity
Severity of the librealsense logger.
Definition: rs_types.h:153
std::shared_ptr< rs2_software_device_destruction_callback > software_device_destruction_callback_ptr
Definition: src/types.h:1075
rs2_log_severity severity
Definition: src/types.h:1109
std::condition_variable cv
Definition: src/types.h:1169
uint32_t pack(uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3)
Definition: src/types.h:1157
const char * get_message() const noexcept
Definition: src/types.h:274
std::unique_ptr< T > _ptr
Definition: src/types.h:491
bool try_sleep(std::chrono::milliseconds::rep ms)
Definition: concurrency.h:204
std::function< resolution(resolution res)> resolution_func
Definition: src/types.h:660
frame_continuation(std::function< void()> continuation, const void *protected_data)
Definition: src/types.h:1454
#define FORMAT
Definition: rs-color.c:19
GLdouble v
YYCODETYPE lhs
Definition: sqlite3.c:132469
linux_backend_exception(const std::string &msg) noexcept
Definition: src/types.h:345
res_type
Definition: src/types.h:1920
GeneratorWrapper< T > map(Func &&function, GeneratorWrapper< U > &&generator)
Definition: catch.hpp:4271
Definition: parser.hpp:150
float3x3 calc_rotation_from_rodrigues_angles(const std::vector< double > rot)
Definition: types.cpp:698
rs2_frame_metadata_value
Per-Frame-Metadata is the set of read-only properties that might be exposed for each individual frame...
Definition: rs_frame.h:29
std::vector< hid_device_info > _hid_devices
Definition: src/types.h:1360
struct rs2_frame rs2_frame
Definition: rs_types.h:261
GLint GLsizei width
std::shared_ptr< rs2_calibration_change_callback > calibration_change_callback_ptr
Definition: src/types.h:1074
void copy(void *dst, void const *src, size_t size)
Definition: types.cpp:836
uint32_t calc_crc32(const uint8_t *buf, size_t bufsize)
Calculate CRC code for arbitrary characters buffer.
Definition: types.cpp:803
res_type get_res_type(uint32_t width, uint32_t height)
Definition: src/types.h:1926
std::mutex m_mutex
Definition: src/types.h:1712
std::string to_string(T value)
rs2_l500_visual_preset
For L500 devices: provides optimized settings (presets) for specific types of usage.
Definition: rs_option.h:151
T deg2rad(T val)
Definition: src/types.h:60
rs2_timestamp_domain
Specifies the clock in relation to which the frame timestamp was measured.
Definition: rs_frame.h:19


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:50:13