9#ifndef LIBREALSENSE_TYPES_H
10#define LIBREALSENSE_TYPES_H
12#include "../include/librealsense/rs.h"
13#include "../include/librealsense/rscore.hpp"
20#include <condition_variable>
46 std::ostringstream
ss;
48 operator std::string()
const {
return ss.str(); }
59 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];
76#define LOG(SEVERITY, ...) do { if(static_cast<int>(SEVERITY) >= rsimpl::get_minimum_severity()) { std::ostringstream ss; ss << __VA_ARGS__; rsimpl::log(SEVERITY, ss.str()); } } while(false)
77#define LOG_DEBUG(...) LOG(RS_LOG_SEVERITY_DEBUG, __VA_ARGS__)
78#define LOG_INFO(...) LOG(RS_LOG_SEVERITY_INFO, __VA_ARGS__)
79#define LOG_WARNING(...) LOG(RS_LOG_SEVERITY_WARN, __VA_ARGS__)
80#define LOG_ERROR(...) LOG(RS_LOG_SEVERITY_ERROR, __VA_ARGS__)
81#define LOG_FATAL(...) LOG(RS_LOG_SEVERITY_FATAL, __VA_ARGS__)
87#define RS_ENUM_HELPERS(TYPE, PREFIX) const char * get_string(TYPE value); \
88 inline bool is_valid(TYPE value) { return value >= 0 && value < RS_##PREFIX##_COUNT; } \
89 inline std::ostream & operator << (std::ostream & out, TYPE value) { if(is_valid(value)) return out << get_string(value); else return out << (int)value; }
103 #undef RS_ENUM_HELPERS
132 void(*
unpack)(
byte *
const dest[],
const byte * source,
int count);
133 std::vector<std::pair<rs_stream, rs_format>>
outputs;
202 int m_major, m_minor, m_patch, m_build;
204 std::string string_representation;
207 static std::vector<std::string> split(
const std::string& str);
208 static int parse_part(
const std::string& name,
int part);
214 : m_major(major), m_minor(minor), m_patch(patch), m_build(build), is_any(is_any), string_representation(
to_string()) {}
222 : 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()) {}
226 if (is_any || other.is_any)
return true;
227 if (m_major > other.m_major)
return false;
228 if ((m_major == other.m_major) && (m_minor > other.m_minor))
return false;
229 if ((m_major == other.m_major) && (m_minor == other.m_minor) && (m_patch > other.m_patch))
return false;
230 if ((m_major == other.m_major) && (m_minor == other.m_minor) && (m_patch == other.m_patch) && (m_build > other.m_build))
return false;
235 return is_any || (other.m_major == m_major && other.m_minor == m_minor && other.m_patch == m_patch && other.m_build == m_build);
245 return (from <= *
this) && (*
this <= until);
248 operator const char*()
const
250 return string_representation.c_str();
306 throw std::runtime_error(
"failed to fetch an unpakcer, most likely because enable_stream was not called!");
319 void unpack(
byte *
const dest[],
const byte * source)
const;
341 operator bool() {
return fptr !=
nullptr; }
345 try { fptr(dev, frame, user); }
catch (...)
347 LOG_ERROR(
"Received an execption from frame callback!");
363 operator bool() {
return fptr !=
nullptr; }
369 try { fptr(device, data, user); }
catch (...)
371 LOG_ERROR(
"Received an execption from motion events callback!");
388 operator bool() {
return fptr !=
nullptr; }
392 try { fptr(device, data, user); }
catch (...)
394 LOG_ERROR(
"Received an execption from timestamp events callback!");
409 operator bool() {
return fptr !=
nullptr; }
415 try { fptr(severity, message, user); }
418 LOG_ERROR(
"Received an execption from log callback!");
438 if (callback) callback->
release();
439 callback = other.callback;
440 other.callback =
nullptr;
479 return{ i.
width + pad_crop * 2, i.
height + pad_crop * 2, i.
ppx + pad_crop, i.
ppy + pad_crop, i.
fx, i.
fy, i.
model, {i.
coeffs[0], i.
coeffs[1], i.
coeffs[2], i.
coeffs[3], i.
coeffs[4]} };
484 const float sx = (float)width / i.
width, sy = (
float)height / i.
height;
485 return{ width, height, i.
ppx*sx, i.
ppy*sy, i.
fx*sx, i.
fy*sy, i.
model, {i.
coeffs[0], i.
coeffs[1], i.
coeffs[2], i.
coeffs[3], i.
coeffs[4]} };
490 inline uint32_t
pack(uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3)
492 return (c0 << 24) | (c1 << 16) | (c2 << 8) | c3;
495 template<
class T,
int C>
501 bool keep_allocating =
true;
502 std::condition_variable cv;
508 for (
auto i = 0; i < C; i++)
511 buffer[i] = std::move(T());
517 std::unique_lock<std::mutex> lock(mutex);
518 if (!keep_allocating)
return nullptr;
520 for (
auto i = 0; i < C; i++)
534 if (item < buffer || item >= buffer + C)
536 throw std::runtime_error(
"Trying to return item to a heap that didn't allocate it!");
538 auto i = item - buffer;
539 buffer[i] = std::move(T());
542 std::unique_lock<std::mutex> lock(mutex);
557 std::unique_lock<std::mutex> lock(mutex);
558 keep_allocating =
false;
563 std::unique_lock<std::mutex> lock(mutex);
565 const auto ready = [
this]()
569 if (!ready() && !cv.wait_for(lock, std::chrono::hours(1000), ready))
571 throw std::runtime_error(
"Could not flush one of the user controlled objects!");
578 std::function<void()> continuation;
579 const void* protected_data =
nullptr;
586 explicit frame_continuation(std::function<
void()> continuation,
const void* protected_data) : continuation(continuation), protected_data(protected_data) {}
591 other.continuation = []() {};
592 other.protected_data =
nullptr;
598 continuation = []() {};
599 protected_data =
nullptr;
604 protected_data =
nullptr;
605 continuation = [](){};
608 const void*
get_data()
const {
return protected_data; }
613 protected_data = other.protected_data;
614 continuation = other.continuation;
615 other.continuation = []() {};
616 other.protected_data =
nullptr;
632 std::function<
bool(
rs_stream)> intrinsic_validator);
640 std::function<bool(
rs_stream stream)> intrinsic_validator;
645 return std::find_if(data.begin(), data.end(), [](
byte b){ return b!=0; }) != data.end();
bool validate_intrinsics(rs_stream stream) const
calibration_validator(std::function< bool(rs_stream, rs_stream)> extrinsic_validator, std::function< bool(rs_stream)> intrinsic_validator)
bool validate_extrinsics(rs_stream from_stream, rs_stream to_stream) const
bool operator==(const firmware_version &other) const
Definition: types.h:233
bool operator>(const firmware_version &other) const
Definition: types.h:238
static firmware_version any()
Definition: types.h:216
firmware_version(int major, int minor, int patch, int build, bool is_any=false)
Definition: types.h:213
bool operator<=(const firmware_version &other) const
Definition: types.h:224
firmware_version(const std::string &name)
Definition: types.h:221
bool is_between(const firmware_version &from, const firmware_version &until)
Definition: types.h:243
bool operator>=(const firmware_version &other) const
Definition: types.h:241
bool operator<(const firmware_version &other) const
Definition: types.h:240
bool operator!=(const firmware_version &other) const
Definition: types.h:239
firmware_version()
Definition: types.h:211
frame_callback_ptr(rs_frame_callback *callback)
Definition: types.h:434
~frame_callback_ptr()
Definition: types.h:443
rs_frame_callback * operator*()
Definition: types.h:445
frame_callback_ptr & operator=(frame_callback_ptr &&other)
Definition: types.h:436
frame_callback_ptr()
Definition: types.h:433
frame_callback_ptr(const frame_callback_ptr &)=delete
void release() override
Definition: types.h:351
frame_callback()
Definition: types.h:338
frame_callback(rs_device *dev, frame_callback_function_ptr on_frame, void *user)
Definition: types.h:339
void on_frame(rs_device *dev, rs_frame_ref *frame) override
Definition: types.h:342
frame_continuation & operator=(frame_continuation &&other)
Definition: types.h:610
void operator()()
Definition: types.h:595
frame_continuation(frame_continuation &&other)
Definition: types.h:589
void reset()
Definition: types.h:602
const void * get_data() const
Definition: types.h:608
frame_continuation()
Definition: types.h:584
~frame_continuation()
Definition: types.h:620
frame_continuation(std::function< void()> continuation, const void *protected_data)
Definition: types.h:586
log_callback()
Definition: types.h:406
void release() override
Definition: types.h:423
void on_event(rs_log_severity severity, const char *message) override
Definition: types.h:411
log_callback(log_callback_function_ptr fptr, void *user)
Definition: types.h:407
void on_event(rs_motion_data data) override
Definition: types.h:365
motion_events_callback()
Definition: types.h:360
motion_events_callback(rs_device *dev, motion_callback_function_ptr fptr, void *user)
Definition: types.h:361
void release() override
Definition: types.h:376
void deallocate(T *item)
Definition: types.h:532
void wait_until_empty()
Definition: types.h:561
small_heap()
Definition: types.h:506
void stop_allocation()
Definition: types.h:555
T * allocate()
Definition: types.h:515
void release() override
Definition: types.h:398
void on_event(rs_timestamp_data data) override
Definition: types.h:389
timestamp_events_callback(rs_device *dev, timestamp_callback_function_ptr fptr, void *user)
Definition: types.h:386
timestamp_events_callback()
Definition: types.h:385
void log_to_file(rs_log_severity min_severity, const char *file_path)
float3x3 transpose(const float3x3 &a)
Definition: types.h:119
void(* log_callback_function_ptr)(rs_log_severity severity, const char *message, void *user)
Definition: types.h:330
float3 operator*(const float3 &a, float b)
Definition: types.h:115
std::unique_ptr< rs_timestamp_callback, void(*)(rs_timestamp_callback *)> timestamp_callback_ptr
Definition: types.h:428
rs_log_severity get_minimum_severity()
void log_to_console(rs_log_severity min_severity)
std::unique_ptr< rs_motion_callback, void(*)(rs_motion_callback *)> motion_callback_ptr
Definition: types.h:427
bool operator==(const float3 &a, const float3 &b)
Definition: types.h:113
void(* timestamp_callback_function_ptr)(rs_device *dev, rs_timestamp_data data, void *user)
Definition: types.h:329
float3 operator+(const float3 &a, const float3 &b)
Definition: types.h:114
pose inverse(const pose &a)
Definition: types.h:123
std::unique_ptr< rs_log_callback, void(*)(rs_log_callback *)> log_callback_ptr
Definition: types.h:426
rs_intrinsics scale_intrinsics(const rs_intrinsics &i, int width, int height)
Definition: types.h:482
rs_intrinsics pad_crop_intrinsics(const rs_intrinsics &i, int pad_crop)
Definition: types.h:477
uint8_t byte
Definition: types.h:42
void(* frame_callback_function_ptr)(rs_device *dev, rs_frame_ref *frame, void *user)
Definition: types.h:327
void log(rs_log_severity severity, const std::string &message)
void log_to_callback(rs_log_severity min_severity, rs_log_callback *callback)
void(* motion_callback_function_ptr)(rs_device *dev, rs_motion_data data, void *user)
Definition: types.h:328
uint32_t pack(uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3)
Definition: types.h:490
bool check_not_all_zeros(std::vector< byte > data)
Definition: types.h:643
rs_stream
Streams are different types of data provided by RealSense devices.
Definition: rs.h:34
rs_frame_metadata
Types of value provided from the device with each frame.
Definition: rs.h:204
rs_event_source
Source device that triggered a specific timestamp event from the motion module.
Definition: rs.h:277
rs_distortion
Distortion model: defines how pixel coordinates should be mapped to sensor coordinates.
Definition: rs.h:100
rs_output_buffer_format
Output buffer format: sets how librealsense works with frame memory.
Definition: rs.h:74
@ RS_OUTPUT_BUFFER_FORMAT_CONTINUOUS
Definition: rs.h:75
rs_preset
Presets: general preferences that are translated by librealsense into concrete resolution and FPS.
Definition: rs.h:82
@ RS_PRESET_COUNT
Definition: rs.h:86
rs_log_severity
Severity of the librealsense logger.
Definition: rs.h:265
rs_option
Defines general configuration controls.
Definition: rs.h:129
rs_format
Formats: defines how each stream can be encoded.
Definition: rs.h:54
rs_timestamp_domain
Specifies the clock in relation to which the frame timestamp was measured.
Definition: rs.h:293
rs_blob_type
Proprietary formats for direct communication with device firmware.
Definition: rs.h:228
rs_source
Source: allows you to choose between available hardware subdevices.
Definition: rs.h:91
rs_camera_info
Read-only strings that can be queried from the device.
Definition: rs.h:237
@ RS_CAMERA_INFO_CAMERA_FIRMWARE_VERSION
Definition: rs.h:240
rs_capabilities
Specifies various capabilities of a RealSense device.
Definition: rs.h:214
Definition: rscore.hpp:65
Definition: rscore.hpp:133
Definition: rscore.hpp:45
Video stream intrinsics.
Definition: rs.h:301
float fy
Definition: rs.h:307
float coeffs[5]
Definition: rs.h:309
rs_distortion model
Definition: rs.h:308
float ppy
Definition: rs.h:305
float fx
Definition: rs.h:306
int height
Definition: rs.h:303
int width
Definition: rs.h:302
float ppx
Definition: rs.h:304
Definition: rscore.hpp:147
Definition: rscore.hpp:126
Motion data from gyroscope and accelerometer from the microcontroller.
Definition: rs.h:348
Definition: rscore.hpp:140
Timestamp data from the motion microcontroller.
Definition: rs.h:340
data_polling_request()
Definition: types.h:197
bool enabled
Definition: types.h:195
motion_callback_ptr motion_callback
Definition: types.h:454
bool validate_requests(stream_request(&requests)[RS_STREAM_NATIVE_COUNT], bool throw_exception=false) const
const static_device_info info
Definition: types.h:450
subdevice_mode_selection select_mode(const stream_request(&requests)[RS_STREAM_NATIVE_COUNT], int subdevice_index) const
float depth_scale
Definition: types.h:456
data_polling_request data_request
Definition: types.h:453
std::vector< subdevice_mode_selection > select_modes() const
Definition: types.h:469
bool all_requests_filled(const stream_request(&original_requests)[RS_STREAM_NATIVE_COUNT]) const
bool fill_requests(stream_request(&requests)[RS_STREAM_NATIVE_COUNT]) const
stream_request requests[RS_STREAM_NATIVE_COUNT]
Definition: types.h:451
std::vector< subdevice_mode_selection > select_modes(const stream_request(&requests)[RS_STREAM_NATIVE_COUNT]) const
timestamp_callback_ptr timestamp_callback
Definition: types.h:455
frame_callback_ptr callbacks[RS_STREAM_NATIVE_COUNT]
Definition: types.h:452
void get_all_possible_requestes(std::vector< stream_request >(&stream_requests)[RS_STREAM_NATIVE_COUNT]) const
bool find_good_requests_combination(stream_request(&output_requests)[RS_STREAM_NATIVE_COUNT], std::vector< stream_request > stream_requests[RS_STREAM_NATIVE_COUNT]) const
device_config(const rsimpl::static_device_info &info)
Definition: types.h:458
float x
Definition: types.h:110
float & operator[](int i)
Definition: types.h:110
float z
Definition: types.h:110
float y
Definition: types.h:110
float3 x
Definition: types.h:111
float & operator()(int i, int j)
Definition: types.h:111
float3 y
Definition: types.h:111
float3 z
Definition: types.h:111
int y
Definition: types.h:109
int x
Definition: types.h:109
rs_stream bigger
Definition: types.h:182
bool divides
Definition: types.h:183
bool divides2
Definition: types.h:183
int delta
Definition: types.h:181
int stream_request::* field
Definition: types.h:180
bool same_format
Definition: types.h:184
int delta2
Definition: types.h:181
rs_stream b
Definition: types.h:179
rs_stream a
Definition: types.h:179
float3x3 orientation
Definition: types.h:112
float3 position
Definition: types.h:112
std::vector< supported_option > options
Definition: types.h:276
std::string firmware_version
Definition: types.h:279
std::string serial
Definition: types.h:280
int num_libuvc_transfer_buffers
Definition: types.h:278
std::vector< subdevice_mode > subdevice_modes
Definition: types.h:273
int stream_subdevices[RS_STREAM_NATIVE_COUNT]
Definition: types.h:271
stream_request presets[RS_STREAM_NATIVE_COUNT][RS_PRESET_COUNT]
Definition: types.h:275
float nominal_depth_scale
Definition: types.h:281
std::string name
Definition: types.h:270
int data_subdevices[RS_STREAM_NATIVE_COUNT]
Definition: types.h:272
std::vector< supported_capability > capabilities_vector
Definition: types.h:282
std::vector< interstream_rule > interstream_rules
Definition: types.h:274
std::map< rs_camera_info, std::string > camera_info
Definition: types.h:284
std::vector< rs_frame_metadata > supported_metadata_vector
Definition: types.h:283
pose stream_poses[RS_STREAM_NATIVE_COUNT]
Definition: types.h:277
bool enabled
Definition: types.h:167
int width
Definition: types.h:168
int fps
Definition: types.h:170
int height
Definition: types.h:168
bool contradict(stream_request req) const
rs_output_buffer_format output_format
Definition: types.h:171
rs_format format
Definition: types.h:169
size_t unpacker_index
Definition: types.h:297
int get_stride_x() const
Definition: types.h:312
void unpack(byte *const dest[], const byte *source) const
size_t get_image_size(rs_stream stream) const
const std::vector< std::pair< rs_stream, rs_format > > & get_outputs() const
Definition: types.h:308
bool provides_stream(rs_stream stream) const
Definition: types.h:315
int pad_crop
Definition: types.h:296
subdevice_mode_selection()
Definition: types.h:300
int get_width() const
Definition: types.h:309
subdevice_mode mode
Definition: types.h:295
subdevice_mode_selection(const subdevice_mode &mode, int pad_crop, int unpacker_index)
Definition: types.h:301
int get_stride_y() const
Definition: types.h:313
rs_format get_format(rs_stream stream) const
Definition: types.h:316
int get_unpacked_width() const
const pixel_format_unpacker & get_unpacker() const
Definition: types.h:303
int get_unpacked_height() const
int get_height() const
Definition: types.h:310
int get_framerate() const
Definition: types.h:311
void set_output_buffer_format(const rs_output_buffer_format in_output_format)
bool requires_processing() const
Definition: types.h:323
rs_output_buffer_format output_format
Definition: types.h:298
native_pixel_format pf
Definition: types.h:158
int subdevice
Definition: types.h:156
int2 native_dims
Definition: types.h:157
int fps
Definition: types.h:159
rs_intrinsics native_intrinsics
Definition: types.h:160
std::vector< rs_intrinsics > rect_modes
Definition: types.h:161
std::vector< int > pad_crop_options
Definition: types.h:162
rs_camera_info firmware_type
Definition: types.h:259
supported_capability(rs_capabilities capability, firmware_version from, firmware_version until, rs_camera_info firmware_type=RS_CAMERA_INFO_CAMERA_FIRMWARE_VERSION)
Definition: types.h:261
supported_capability(rs_capabilities capability)
Definition: types.h:264
rs_capabilities capability
Definition: types.h:256
firmware_version until
Definition: types.h:258
firmware_version from
Definition: types.h:257
double max
Definition: types.h:190
double def
Definition: types.h:190
double min
Definition: types.h:190
rs_option option
Definition: types.h:189
double step
Definition: types.h:190
std::ostringstream ss
Definition: types.h:46
to_string & operator<<(const T &val)
Definition: types.h:47
const int RS_MAX_EVENT_QUEUE_SIZE
Definition: types.h:31
const int RS_USER_QUEUE_SIZE
Definition: types.h:28
#define RS_ENUM_HELPERS(TYPE, PREFIX)
Definition: types.h:87
const uint8_t RS_STREAM_NATIVE_COUNT
Definition: types.h:27
#define LOG_ERROR(...)
Definition: types.h:80
const int RS_MAX_EVENT_TIME_OUT
Definition: types.h:32