rs.cpp
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 #include <functional> // For function
5 #include <climits>
6 
7 #include "context.h"
8 #include "device.h"
9 #include "sync.h"
10 #include "archive.h"
11 
13 // API implementation //
15 
16 struct rs_error
17 {
19  const char * function;
21 };
22 
23 // This facility allows for translation of exceptions to rs_error structs at the API boundary
24 namespace rsimpl
25 {
26  template<class T> void stream_args(std::ostream & out, const char * names, const T & last) { out << names << ':' << last; }
27  template<class T, class... U> void stream_args(std::ostream & out, const char * names, const T & first, const U &... rest)
28  {
29  while(*names && *names != ',') out << *names++;
30  out << ':' << first << ", ";
31  while(*names && (*names == ',' || isspace(*names))) ++names;
32  stream_args(out, names, rest...);
33  }
34 
35  static void translate_exception(const char * name, std::string args, rs_error ** error)
36  {
37  try { throw; }
38  catch (const std::exception & e) { if (error) *error = new rs_error {e.what(), name, move(args)}; } // todo - Handle case where THIS code throws
39  catch (...) { if (error) *error = new rs_error {"unknown error", name, move(args)}; } // todo - Handle case where THIS code throws
40  }
41 }
42 #define HANDLE_EXCEPTIONS_AND_RETURN(R, ...) catch(...) { std::ostringstream ss; rsimpl::stream_args(ss, #__VA_ARGS__, __VA_ARGS__); rsimpl::translate_exception(__FUNCTION__, ss.str(), error); return R; }
43 #define VALIDATE_NOT_NULL(ARG) if(!(ARG)) throw std::runtime_error("null pointer passed for argument \"" #ARG "\"");
44 #define VALIDATE_ENUM(ARG) if(!rsimpl::is_valid(ARG)) { std::ostringstream ss; ss << "bad enum value for argument \"" #ARG "\""; throw std::runtime_error(ss.str()); }
45 #define VALIDATE_RANGE(ARG, MIN, MAX) if((ARG) < (MIN) || (ARG) > (MAX)) { std::ostringstream ss; ss << "out of range value for argument \"" #ARG "\""; throw std::runtime_error(ss.str()); }
46 #define VALIDATE_LE(ARG, MAX) if((ARG) > (MAX)) { std::ostringstream ss; ss << "out of range value for argument \"" #ARG "\""; throw std::runtime_error(ss.str()); }
47 #define VALIDATE_NATIVE_STREAM(ARG) VALIDATE_ENUM(ARG); if(ARG >= RS_STREAM_NATIVE_COUNT) { std::ostringstream ss; ss << "argument \"" #ARG "\" must be a native stream"; throw std::runtime_error(ss.str()); }
48 
49 int major(int version)
50 {
51  return version / 10000;
52 }
53 int minor(int version)
54 {
55  return (version % 10000) / 100;
56 }
57 int patch(int version)
58 {
59  return (version % 100);
60 }
61 
63 {
64  if (major(version) == 0) return rsimpl::to_string() << version;
65  return rsimpl::to_string() << major(version) << "." << minor(version) << "." << patch(version);
66 }
67 
68 void report_version_mismatch(int runtime, int compiletime)
69 {
70  throw std::runtime_error(rsimpl::to_string() << "API version mismatch: librealsense.so was compiled with API version "
71  << api_version_to_string(runtime) << " but the application was compiled with "
72  << api_version_to_string(compiletime) << "! Make sure correct version of the library is installed (make install)");
73 }
74 
75 rs_context * rs_create_context(int api_version, rs_error ** error) try
76 {
77  rs_error * local_error = nullptr;
78  auto runtime_api_version = rs_get_api_version(&local_error);
79  if (local_error) throw std::runtime_error(rs_get_error_message(local_error));
80 
81  if ((runtime_api_version < 10) || (api_version < 10))
82  {
83  // when dealing with version < 1.0.0 that were still using single number for API version, require exact match
84  if (api_version != runtime_api_version)
85  report_version_mismatch(runtime_api_version, api_version);
86  }
87  else if ((major(runtime_api_version) == 1 && minor(runtime_api_version) <= 9)
88  || (major(api_version) == 1 && minor(api_version) <= 9))
89  {
90  // when dealing with version < 1.10.0, API breaking changes are still possible without minor version change, require exact match
91  if (api_version != runtime_api_version)
92  report_version_mismatch(runtime_api_version, api_version);
93  }
94  else
95  {
96  // starting with 1.10.0, versions with same patch are compatible
97  if ((major(api_version) != major(runtime_api_version))
98  || (minor(api_version) != minor(runtime_api_version)))
99  report_version_mismatch(runtime_api_version, api_version);
100  }
101 
103 }
104 HANDLE_EXCEPTIONS_AND_RETURN(nullptr, api_version)
105 
106 void rs_delete_context(rs_context * context, rs_error ** error) try
107 {
108  VALIDATE_NOT_NULL(context);
110 }
112 
113 int rs_get_device_count(const rs_context * context, rs_error ** error) try
114 {
115  VALIDATE_NOT_NULL(context);
116  return (int)context->get_device_count();
117 }
119 
120 rs_device * rs_get_device(rs_context * context, int index, rs_error ** error) try
121 {
122  VALIDATE_NOT_NULL(context);
123  VALIDATE_RANGE(index, 0, (int)context->get_device_count()-1);
124  return context->get_device(index);
125 }
126 HANDLE_EXCEPTIONS_AND_RETURN(nullptr, context, index)
127 
128 const char * rs_get_device_name(const rs_device * device, rs_error ** error) try
129 {
130  VALIDATE_NOT_NULL(device);
131  return device->get_name();
132 }
133 HANDLE_EXCEPTIONS_AND_RETURN(nullptr, device)
134 
135 const char * rs_get_device_serial(const rs_device * device, rs_error ** error) try
136 {
137  VALIDATE_NOT_NULL(device);
138  return device->get_serial();
139 }
140 HANDLE_EXCEPTIONS_AND_RETURN(nullptr, device)
141 
142 const char * rs_get_device_info(const rs_device * device, rs_camera_info info, rs_error ** error) try
143 {
144  VALIDATE_NOT_NULL(device);
145  return device->get_camera_info(info);
146 }
147 HANDLE_EXCEPTIONS_AND_RETURN(0, device, info)
148 
149 const char * rs_get_device_usb_port_id(const rs_device * device, rs_error **error) try
150 {
151  VALIDATE_NOT_NULL(device);
152  return device->get_usb_port_id();
153 }
155 
156 const char * rs_get_device_firmware_version(const rs_device * device, rs_error ** error) try
157 {
158  VALIDATE_NOT_NULL(device);
159  return device->get_firmware_version();
160 }
161 HANDLE_EXCEPTIONS_AND_RETURN(nullptr, device)
162 
163 void rs_get_device_extrinsics(const rs_device * device, rs_stream from, rs_stream to, rs_extrinsics * extrin, rs_error ** error) try
164 {
165  VALIDATE_NOT_NULL(device);
166  VALIDATE_ENUM(from);
167  VALIDATE_ENUM(to);
168  VALIDATE_NOT_NULL(extrin);
169  *extrin = device->get_stream_interface(from).get_extrinsics_to(device->get_stream_interface(to));
170 }
171 HANDLE_EXCEPTIONS_AND_RETURN(, device, from, to, extrin)
172 
173 void rs_get_motion_extrinsics_from(const rs_device * device, rs_stream from, rs_extrinsics * extrin, rs_error ** error) try
174 {
175  VALIDATE_NOT_NULL(device);
176  VALIDATE_ENUM(from);
177  VALIDATE_NOT_NULL(extrin);
178  *extrin = device->get_motion_extrinsics_from(from);
179 }
180 HANDLE_EXCEPTIONS_AND_RETURN(, device, from, extrin)
181 
183 {
184  VALIDATE_NOT_NULL(device);
186  return device->supports_option(option);
187 }
189 
191 {
192  VALIDATE_NOT_NULL(device);
194  return device->get_stream_interface(stream).get_mode_count();
195 }
197 
198 void rs_get_stream_mode(const rs_device * device, rs_stream stream, int index, int * width, int * height, rs_format * format, int * framerate, rs_error ** error) try
199 {
200  VALIDATE_NOT_NULL(device);
202  VALIDATE_RANGE(index, 0, device->get_stream_interface(stream).get_mode_count()-1);
203  device->get_stream_interface(stream).get_mode(index, width, height, format, framerate);
204 }
206 
208 {
209  VALIDATE_NOT_NULL(device);
211  VALIDATE_RANGE(width, 0, INT_MAX);
212  VALIDATE_RANGE(height, 0, INT_MAX);
214  VALIDATE_ENUM(output);
215  VALIDATE_RANGE(framerate, 0, INT_MAX);
216  device->enable_stream(stream, width, height, format, framerate, output);
217 }
218 HANDLE_EXCEPTIONS_AND_RETURN(, device, stream, width, height, format, framerate)
219 
220 void rs_enable_stream(rs_device * device, rs_stream stream, int width, int height, rs_format format, int framerate, rs_error ** error) try
221 {
222  VALIDATE_NOT_NULL(device);
224  VALIDATE_RANGE(width, 0, INT_MAX);
225  VALIDATE_RANGE(height, 0, INT_MAX);
227  VALIDATE_RANGE(framerate, 0, INT_MAX);
228  device->enable_stream(stream, width, height, format, framerate, RS_OUTPUT_BUFFER_FORMAT_CONTINUOUS);
229 }
230 HANDLE_EXCEPTIONS_AND_RETURN(, device, stream, width, height, format, framerate)
231 
233 {
234  VALIDATE_NOT_NULL(device);
237  device->enable_stream_preset(stream, preset);
238 }
240 
242 {
243  VALIDATE_NOT_NULL(device);
245  device->disable_stream(stream);
246 }
248 
250 {
251  VALIDATE_NOT_NULL(device);
253  return device->get_stream_interface(stream).is_enabled();
254 }
256 
258 {
259  VALIDATE_NOT_NULL(device);
261  return device->get_stream_interface(stream).get_intrinsics().width;
262 }
264 
266 {
267  VALIDATE_NOT_NULL(device);
269  return device->get_stream_interface(stream).get_intrinsics().height;
270 }
272 
274 {
275  VALIDATE_NOT_NULL(device);
277  return device->get_stream_interface(stream).get_format();
278 }
280 
282 {
283  VALIDATE_NOT_NULL(device);
285  return device->get_stream_interface(stream).get_framerate();
286 }
288 
290 {
291  VALIDATE_NOT_NULL(device);
293  VALIDATE_NOT_NULL(intrin);
294  *intrin = device->get_stream_interface(stream).get_intrinsics();
295 }
296 HANDLE_EXCEPTIONS_AND_RETURN(, device, stream, intrin)
297 
298 void rs_get_motion_intrinsics(const rs_device * device, rs_motion_intrinsics * intrinsic, rs_error ** error) try
299 {
300  VALIDATE_NOT_NULL(device);
301  VALIDATE_NOT_NULL(intrinsic);
302  *intrinsic = device->get_motion_intrinsics();
303 }
304 HANDLE_EXCEPTIONS_AND_RETURN(, device, intrinsic)
305 
306 void rs_set_frame_callback(rs_device * device, rs_stream stream, rs_frame_callback_ptr on_frame, void * user, rs_error ** error) try
307 {
308  VALIDATE_NOT_NULL(device);
310  VALIDATE_NOT_NULL(on_frame);
311  device->set_stream_callback(stream, on_frame, user);
312 }
313 HANDLE_EXCEPTIONS_AND_RETURN(, device, stream, on_frame, user)
314 
316 {
317  VALIDATE_NOT_NULL(device);
319  VALIDATE_NOT_NULL(callback);
320  device->set_stream_callback(stream, callback);
321 }
322 HANDLE_EXCEPTIONS_AND_RETURN(, device, stream, callback)
323 
324 void rs_log_to_callback(rs_log_severity min_severity, rs_log_callback_ptr on_log, void * user, rs_error ** error) try
325 {
326  VALIDATE_NOT_NULL(on_log);
327  rsimpl::log_to_callback(min_severity, on_log, user);
328 }
329 HANDLE_EXCEPTIONS_AND_RETURN(, min_severity, on_log, user)
330 
331 void rs_log_to_callback_cpp(rs_log_severity min_severity, rs_log_callback * callback, rs_error ** error) try
332 {
333  VALIDATE_NOT_NULL(callback);
334  rsimpl::log_to_callback(min_severity, callback);
335 }
336 HANDLE_EXCEPTIONS_AND_RETURN(, min_severity, callback)
337 
341  rs_error ** error) try
342 {
343  VALIDATE_NOT_NULL(device);
346  device->enable_motion_tracking();
347  device->set_motion_callback(on_motion_event, motion_handler);
348  device->set_timestamp_callback(on_timestamp_event, timestamp_handler);
349 }
351 
354  rs_timestamp_callback * ts_callback,
355  rs_error ** error) try
356 {
357  VALIDATE_NOT_NULL(device);
359  VALIDATE_NOT_NULL(ts_callback);
360  device->enable_motion_tracking();
361  device->set_motion_callback(motion_callback);
362  device->set_timestamp_callback(ts_callback);
363 }
364 HANDLE_EXCEPTIONS_AND_RETURN(, device, motion_callback, ts_callback)
365 
367 {
368  VALIDATE_NOT_NULL(device);
369  device->disable_motion_tracking();
370  device->set_motion_callback(nullptr, nullptr);
371  device->set_timestamp_callback(nullptr, nullptr);
372 }
374 
376 {
377  VALIDATE_NOT_NULL(device);
378 
379  return device->is_motion_tracking_active();
380 }
382 
383 void rs_start_device(rs_device * device, rs_error ** error) try
384 {
385  VALIDATE_NOT_NULL(device);
386  device->start(rs_source::RS_SOURCE_VIDEO);
387 }
389 
391 {
392  VALIDATE_NOT_NULL(device);
394  device->start(source);
395 }
397 
398 void rs_stop_device(rs_device * device, rs_error ** error) try
399 {
400  VALIDATE_NOT_NULL(device);
401  device->stop(rs_source::RS_SOURCE_VIDEO);
402 }
404 
406 {
407  VALIDATE_NOT_NULL(device);
409  device->stop(source);
410 }
412 
413 int rs_is_device_streaming(const rs_device * device, rs_error ** error) try
414 {
415  VALIDATE_NOT_NULL(device);
416  return device->is_capturing();
417 }
419 
420 float rs_get_device_depth_scale(const rs_device * device, rs_error ** error) try
421 {
422  VALIDATE_NOT_NULL(device);
423  return device->get_depth_scale();
424 }
426 
427 
428 void rs_wait_for_frames(rs_device * device, rs_error ** error) try
429 {
430  VALIDATE_NOT_NULL(device);
431  device->wait_all_streams();
432 }
434 
435 int rs_poll_for_frames(rs_device * device, rs_error ** error) try
436 {
437  VALIDATE_NOT_NULL(device);
438  return device->poll_all_streams();
439 }
441 
442 int rs_supports(rs_device * device, rs_capabilities capability, rs_error ** error) try
443 {
444  VALIDATE_NOT_NULL(device);
445  VALIDATE_ENUM(capability);
446  return device->supports(capability);
447 }
449 
450 int rs_supports_camera_info(rs_device * device, rs_camera_info info_param, rs_error ** error) try
451 {
452  VALIDATE_NOT_NULL(device);
453  VALIDATE_ENUM(info_param);
454  return device->supports(info_param);
455 }
457 
459 {
460  VALIDATE_NOT_NULL(frame);
462  return frame->get_frame_metadata(frame_metadata);
463 }
465 
467 {
468  VALIDATE_NOT_NULL(frame);
470  return frame->supports_frame_metadata(frame_metadata);
471 }
473 
474 double rs_get_frame_timestamp(const rs_device * device, rs_stream stream, rs_error ** error) try
475 {
476  VALIDATE_NOT_NULL(device);
478  return device->get_stream_interface(stream).get_frame_timestamp();
479 }
481 
482 unsigned long long rs_get_frame_number(const rs_device * device, rs_stream stream, rs_error ** error) try
483 {
484  VALIDATE_NOT_NULL(device);
486  return device->get_stream_interface(stream).get_frame_number();
487 }
489 
490 const void * rs_get_frame_data(const rs_device * device, rs_stream stream, rs_error ** error) try
491 {
492  VALIDATE_NOT_NULL(device);
494  return device->get_stream_interface(stream).get_frame_data();
495 }
496 HANDLE_EXCEPTIONS_AND_RETURN(nullptr, device, stream)
497 
498 double rs_get_detached_frame_timestamp(const rs_frame_ref * frame_ref, rs_error ** error) try
499 {
500  VALIDATE_NOT_NULL(frame_ref);
501  return frame_ref->get_frame_timestamp();
502 }
503 HANDLE_EXCEPTIONS_AND_RETURN(0, frame_ref)
504 
506 {
507  VALIDATE_NOT_NULL(frame_ref);
508  return frame_ref->get_frame_timestamp_domain();
509 }
511 
512 const void * rs_get_detached_frame_data(const rs_frame_ref * frame_ref, rs_error ** error) try
513 {
514  VALIDATE_NOT_NULL(frame_ref);
515  return frame_ref->get_frame_data();
516 }
517 HANDLE_EXCEPTIONS_AND_RETURN(nullptr, frame_ref)
518 
519 int rs_get_detached_frame_width(const rs_frame_ref * frame_ref, rs_error ** error) try
520 {
521  VALIDATE_NOT_NULL(frame_ref);
522  return frame_ref->get_frame_width();
523 }
524 HANDLE_EXCEPTIONS_AND_RETURN(0, frame_ref)
525 
526 int rs_get_detached_frame_height(const rs_frame_ref * frame_ref, rs_error ** error) try
527 {
528  VALIDATE_NOT_NULL(frame_ref);
529  return frame_ref->get_frame_height();
530 }
531 HANDLE_EXCEPTIONS_AND_RETURN(0, frame_ref)
532 
533 int rs_get_detached_framerate(const rs_frame_ref * frame_ref, rs_error ** error) try
534 {
535  VALIDATE_NOT_NULL(frame_ref);
536  return frame_ref->get_frame_framerate();
537 }
538 HANDLE_EXCEPTIONS_AND_RETURN(0, frame_ref)
539 
540 int rs_get_detached_frame_stride(const rs_frame_ref * frame_ref, rs_error ** error) try
541 {
542  VALIDATE_NOT_NULL(frame_ref);
543  return frame_ref->get_frame_stride();
544 }
545 HANDLE_EXCEPTIONS_AND_RETURN(0, frame_ref)
546 
547 
548 int rs_get_detached_frame_bpp(const rs_frame_ref * frame_ref, rs_error ** error) try
549 {
550  VALIDATE_NOT_NULL(frame_ref);
551  return frame_ref->get_frame_bpp();
552 }
553 HANDLE_EXCEPTIONS_AND_RETURN(0, frame_ref)
554 
556 {
557  VALIDATE_NOT_NULL(frame_ref);
558  return frame_ref->get_frame_format();
559 }
561 
563 {
564  VALIDATE_NOT_NULL(frame_ref);
565  return frame_ref->get_stream_type();
566 }
568 
569 
570 unsigned long long rs_get_detached_frame_number(const rs_frame_ref * frame, rs_error ** error) try
571 {
572  VALIDATE_NOT_NULL(frame);
573  return frame->get_frame_number();
574 }
576 
577 void rs_release_frame(rs_device * device, rs_frame_ref * frame, rs_error ** error) try
578 {
579  VALIDATE_NOT_NULL(device);
580  VALIDATE_NOT_NULL(frame);
581  device->release_frame(frame);
582 }
583 HANDLE_EXCEPTIONS_AND_RETURN(, device, frame)
584 
585 const char * rs_get_stream_name(rs_stream stream, rs_error ** error) try
586 {
588  return rsimpl::get_string(stream);
589 }
591 
592 const char * rs_get_format_name(rs_format format, rs_error ** error) try
593 {
595  return rsimpl::get_string(format);
596 }
598 
599 const char * rs_get_preset_name(rs_preset preset, rs_error ** error) try
600 {
602  return rsimpl::get_string(preset);
603 }
605 
607 {
610 }
612 
613 const char * rs_get_option_name(rs_option option, rs_error ** error) try
614 {
616  return rsimpl::get_string(option);
617 }
619 
620 const char * rs_get_capabilities_name(rs_capabilities capability, rs_error ** error) try
621 {
622  VALIDATE_ENUM(capability);
623  return rsimpl::get_string(capability);
624 }
625 HANDLE_EXCEPTIONS_AND_RETURN(nullptr, capability)
626 
627 const char * rs_get_event_name(rs_event_source event, rs_error ** error) try
628 {
630  return rsimpl::get_string(event);
631 }
633 
634 
635 void rs_get_device_option_range(rs_device * device, rs_option option, double * min, double * max, double * step, rs_error ** error) try
636 {
637  VALIDATE_NOT_NULL(device);
639  double x = 0; // Prevent internal code from having to worry about whether nulls are passed in for min/max/step by giving it somewhere to write to
640  double def = 0;
641  device->get_option_range(option, min ? *min : x, max ? *max : x, step ? *step : x, def);
642 }
643 HANDLE_EXCEPTIONS_AND_RETURN(, device, option, min, max, step)
644 
645 void rs_get_device_option_range_ex(rs_device * device, rs_option option, double * min, double * max, double * step, double * def, rs_error ** error) try
646 {
647  VALIDATE_NOT_NULL(device);
649  double x = 0; // Prevent internal code from having to worry about whether nulls are passed in for min/max/step by giving it somewhere to write to
650  device->get_option_range(option, min ? *min : x, max ? *max : x, step ? *step : x, def ? *def : x);
651 }
652 HANDLE_EXCEPTIONS_AND_RETURN(, device, option, min, max, step)
653 
654 void rs_reset_device_options_to_default(rs_device * device, const rs_option* options, int count, rs_error ** error) try
655 {
656  VALIDATE_NOT_NULL(device);
657  VALIDATE_RANGE(count, 0, INT_MAX);
658  VALIDATE_NOT_NULL(options);
659  for (int i = 0; i<count; ++i) VALIDATE_ENUM(options[i]);
660 
661  std::vector<double> values;
662  for (int i = 0; i < count; ++i)
663  {
664  double def;
665  rs_get_device_option_range_ex(device, options[i], NULL, NULL, NULL, &def, 0);
666  values.push_back(def);
667  }
668  device->set_options(options, count, values.data());
669 }
670 HANDLE_EXCEPTIONS_AND_RETURN(, device, options, count)
671 
672 void rs_get_device_options(rs_device * device, const rs_option options[], unsigned int count, double values[], rs_error ** error) try
673 {
674  VALIDATE_NOT_NULL(device);
675  VALIDATE_LE(count, INT_MAX);
676  VALIDATE_NOT_NULL(options);
677  for(size_t i=0; i<count; ++i) VALIDATE_ENUM(options[i]);
679  device->get_options(options, count, values);
680 }
681 HANDLE_EXCEPTIONS_AND_RETURN(, device, options, count, values)
682 
683 void rs_set_device_options(rs_device * device, const rs_option options[], unsigned int count, const double values[], rs_error ** error) try
684 {
685  VALIDATE_NOT_NULL(device);
686  VALIDATE_LE(count, INT_MAX);
687  VALIDATE_NOT_NULL(options);
688  for(size_t i=0; i<count; ++i) VALIDATE_ENUM(options[i]);
690  device->set_options(options, count, values);
691 }
692 HANDLE_EXCEPTIONS_AND_RETURN(, device, options, count, values)
693 
694 double rs_get_device_option(rs_device * device, rs_option option, rs_error ** error) try
695 {
696  VALIDATE_NOT_NULL(device);
698  double value = 0;
699  device->get_options(&option, 1, &value);
700  return value;
701 }
703 
705 {
706  VALIDATE_NOT_NULL(device);
708  return device->get_option_description(option);
709 }
711 
713 {
714  VALIDATE_NOT_NULL(device);
716  device->set_options(&option, 1, &value);
717 }
719 
720 // Verify and provide API version encoded as integer value
722 {
723  // Each component type is within [0-99] range
727  return RS_API_VERSION;
728 }
730 
732 {
733  VALIDATE_NOT_NULL(device);
735  auto lrs_device = dynamic_cast<rs_device_base*>(device);
736  if (lrs_device)
737  {
738  lrs_device->send_blob_to_device(type, data, size);
739  }
740  else
741  {
742  throw std::runtime_error("sending binary data to the device is only available when using physical device!");
743  }
744 }
746 
747 
748 void rs_free_error(rs_error * error) { if (error) delete error; }
749 const char * rs_get_failed_function(const rs_error * error) { return error ? error->function : nullptr; }
750 const char * rs_get_failed_args(const rs_error * error) { return error ? error->args.c_str() : nullptr; }
751 const char * rs_get_error_message(const rs_error * error) { return error ? error->message.c_str() : nullptr; }
752 
753 
754 const char * rs_stream_to_string(rs_stream stream) { return rsimpl::get_string(stream); }
755 const char * rs_format_to_string(rs_format format) { return rsimpl::get_string(format); }
756 const char * rs_preset_to_string(rs_preset preset) { return rsimpl::get_string(preset); }
758 const char * rs_option_to_string(rs_option option) { return rsimpl::get_string(option); }
759 const char * rs_capabilities_to_string(rs_capabilities capability) { return rsimpl::get_string(capability); }
760 const char * rs_source_to_string(rs_source source) { return rsimpl::get_string(source); }
762 
764 const char * rs_camera_info_to_string(rs_camera_info info) { return rsimpl::get_string(info); }
766 
768 
769 void rs_log_to_console(rs_log_severity min_severity, rs_error ** error) try
770 {
771  rsimpl::log_to_console(min_severity);
772 }
773 HANDLE_EXCEPTIONS_AND_RETURN(, min_severity)
774 
775 void rs_log_to_file(rs_log_severity min_severity, const char * file_path, rs_error ** error) try
776 {
777  rsimpl::log_to_file(min_severity, file_path);
778 }
779 HANDLE_EXCEPTIONS_AND_RETURN(, min_severity, file_path)
#define RS_API_VERSION
Definition: rs.h:28
void rs_set_device_option(rs_device *device, rs_option option, double value, rs_error **error)
Sets the current value of a single option.
Definition: rs.cpp:712
const GLint * first
Definition: glext.h:368
const char * rs_get_stream_name(rs_stream stream, rs_error **error)
Definition: rs.cpp:585
const char * rs_blob_type_to_string(rs_blob_type type)
Definition: rs.cpp:763
int major(int version)
Definition: rs.cpp:49
void on_timestamp_event(rs::timestamp_data entry)
Definition: rs.cpp:16
void(* rs_frame_callback_ptr)(rs_device *dev, rs_frame_ref *frame, void *user)
Definition: rs.h:365
const char * rs_get_preset_name(rs_preset preset, rs_error **error)
Definition: rs.cpp:599
const char * rs_timestamp_domain_to_string(rs_timestamp_domain info)
Definition: rs.cpp:765
rs_error * e
int rs_get_stream_width(const rs_device *device, rs_stream stream, rs_error **error)
Retrieves the width in pixels of a specific stream, equivalent to the width field from the stream&#39;s i...
Definition: rs.cpp:257
const char * rs_get_device_info(const rs_device *device, rs_camera_info info, rs_error **error)
Retrieves camera specific information, such as versions of various internal componnents.
Definition: rs.cpp:142
frame_metadata
Types of value provided from the device with each frame.
Definition: rs.hpp:160
GLint GLint GLsizei GLsizei height
Definition: glext.h:112
rs_blob_type
Proprietary formats for direct communication with device firmware.
Definition: rs.h:228
int rs_get_stream_mode_count(const rs_device *device, rs_stream stream, rs_error **error)
Determines the number of streaming modes available for a given stream.
Definition: rs.cpp:190
void motion_callback(rs_device *, rs_motion_data, void *)
void(* rs_motion_callback_ptr)(rs_device *, rs_motion_data, void *)
Definition: rs.h:366
void rs_set_frame_callback_cpp(rs_device *device, rs_stream stream, rs_frame_callback *callback, rs_error **error)
Sets up a frame callback that is called immediately when an image is available, with no synchronizati...
Definition: rs.cpp:315
void rs_send_blob_to_device(rs_device *device, rs_blob_type type, void *data, int size, rs_error **error)
Sends arbitrary binary data to the device.
Definition: rs.cpp:731
GLsizei const GLchar *const * string
Definition: glext.h:683
rs_format rs_get_detached_frame_format(const rs_frame_ref *frame_ref, rs_error **error)
Retrieves frame format.
Definition: rs.cpp:555
void rs_log_to_callback_cpp(rs_log_severity min_severity, rs_log_callback *callback, rs_error **error)
Starts logging to user-provided callback.
Definition: rs.cpp:331
const char * rs_stream_to_string(rs_stream stream)
Definition: rs.cpp:754
double rs_get_detached_frame_timestamp(const rs_frame_ref *frame_ref, rs_error **error)
Retrieves timestamp from frame reference.
Definition: rs.cpp:498
Definition: archive.h:12
int rs_get_detached_frame_height(const rs_frame_ref *frame_ref, rs_error **error)
Retrieves frame intrinsic height.
Definition: rs.cpp:526
void rs_disable_stream(rs_device *device, rs_stream stream, rs_error **error)
Disables a specific stream.
Definition: rs.cpp:241
void rs_stop_device(rs_device *device, rs_error **error)
Ends data acquisition for the specified source providers.
Definition: rs.cpp:398
void(* rs_log_callback_ptr)(rs_log_severity min_severity, const char *message, void *user)
Definition: rs.h:368
void rs_log_to_file(rs_log_severity min_severity, const char *file_path, rs_error **error)
Starts logging to file.
Definition: rs.cpp:775
const char * rs_option_to_string(rs_option option)
Definition: rs.cpp:758
void log_to_file(rs_log_severity min_severity, const char *file_path)
Definition: log.cpp:106
const char * rs_preset_to_string(rs_preset preset)
Definition: rs.cpp:756
rs_option
Defines general configuration controls.
Definition: rs.h:128
std::string message
Definition: rs.cpp:18
GLuint GLuint stream
Definition: glext.h:1774
rs_output_buffer_format
Output buffer format: sets how librealsense works with frame memory.
Definition: rs.h:73
void rs_set_device_options(rs_device *device, const rs_option options[], unsigned int count, const double values[], rs_error **error)
Definition: rs.cpp:683
rs_timestamp_domain
Specifies the clock in relation to which the frame timestamp was measured.
Definition: rs.h:292
void rs_get_device_option_range(rs_device *device, rs_option option, double *min, double *max, double *step, rs_error **error)
Retrieves the available range of values for a supported option.
Definition: rs.cpp:635
void rs_disable_motion_tracking(rs_device *device, rs_error **error)
Disables motion-tracking handlers.
Definition: rs.cpp:366
GLuint GLuint * names
Definition: glext.h:5325
#define RS_API_PATCH_VERSION
Definition: rs.h:19
unsigned long long rs_get_frame_number(const rs_device *device, rs_stream stream, rs_error **error)
Retrieves frame number.
Definition: rs.cpp:482
rs_device * rs_get_device(rs_context *context, int index, rs_error **error)
Retrieves connected device by index.
Definition: rs.cpp:120
int rs_supports_frame_metadata(const rs_frame_ref *frame, rs_frame_metadata frame_metadata, rs_error **error)
Determines device metadata.
Definition: rs.cpp:466
int rs_get_detached_framerate(const rs_frame_ref *frame_ref, rs_error **error)
Retrieves frame intrinsic frame rate.
Definition: rs.cpp:533
const char * rs_get_error_message(const rs_error *error)
Returns static pointer to error message.
Definition: rs.cpp:751
void rs_release_frame(rs_device *device, rs_frame_ref *frame, rs_error **error)
Releases frame handle.
Definition: rs.cpp:577
std::string api_version_to_string(int version)
Definition: rs.cpp:62
void rs_stop_source(rs_device *device, rs_source source, rs_error **error)
Ends data acquisition for the specified source providers.
Definition: rs.cpp:405
void stream_args(std::ostream &out, const char *names, const T &first, const U &...rest)
Definition: rs.cpp:27
#define VALIDATE_ENUM(ARG)
Definition: rs.cpp:44
const char * rs_distortion_to_string(rs_distortion distortion)
Definition: rs.cpp:757
rs_stream rs_get_detached_frame_stream_type(const rs_frame_ref *frame_ref, rs_error **error)
Retrieves frame stream type.
Definition: rs.cpp:562
virtual void send_blob_to_device(rs_blob_type, void *, int)
Definition: device.h:174
void log_to_console(rs_log_severity min_severity)
Definition: log.cpp:101
GLuint index
Definition: glext.h:655
GLuint GLuint GLsizei count
Definition: glext.h:111
void rs_log_to_console(rs_log_severity min_severity, rs_error **error)
Starts logging to console.
Definition: rs.cpp:769
rs_camera_info
Read-only strings that can be queried from the device.
Definition: rs.h:237
GLfloat f
Definition: glext.h:1868
std::string args
Definition: rs.cpp:20
void log_to_callback(rs_log_severity min_severity, rs_log_callback *callback)
Definition: log.cpp:111
Motion module intrinsics: includes accelerometer and gyroscope intrinsics structs of type rs_motion_d...
Definition: rs.h:325
auto timestamp_handler
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
float rs_get_device_depth_scale(const rs_device *device, rs_error **error)
Retrieves mapping between the units of the depth image and meters.
Definition: rs.cpp:420
#define RS_API_MINOR_VERSION
Definition: rs.h:18
int rs_get_detached_frame_stride(const rs_frame_ref *frame_ref, rs_error **error)
Retrieves frame stride, meaning the actual line width in memory in bytes (not the logical image width...
Definition: rs.cpp:540
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const void * data
Definition: glext.h:223
int patch(int version)
Definition: rs.cpp:57
void rs_enable_stream_ex(rs_device *device, rs_stream stream, int width, int height, rs_format format, int framerate, rs_output_buffer_format output, rs_error **error)
Enables a specific stream and requests specific properties.
Definition: rs.cpp:207
auto motion_handler
const char * rs_get_option_name(rs_option option, rs_error **error)
Definition: rs.cpp:613
double rs_get_device_option(rs_device *device, rs_option option, rs_error **error)
Retrieves the current value of a single option.
Definition: rs.cpp:694
double rs_get_frame_timestamp(const rs_device *device, rs_stream stream, rs_error **error)
Retrieves time at which the latest frame on a stream was captured.
Definition: rs.cpp:474
int rs_is_stream_enabled(const rs_device *device, rs_stream stream, rs_error **error)
Determines if a specific stream is enabled.
Definition: rs.cpp:249
rs_format
Formats: defines how each stream can be encoded.
Definition: rs.h:53
rs_timestamp_domain rs_get_detached_frame_timestamp_domain(const rs_frame_ref *frame_ref, rs_error **error)
Retrieves timestamp domain from frame reference.
Definition: rs.cpp:505
static void translate_exception(const char *name, std::string args, rs_error **error)
Definition: rs.cpp:35
const char * rs_format_to_string(rs_format format)
Definition: rs.cpp:755
int rs_get_api_version(rs_error **error)
Retrieves API version from the source code. Evaluate that the value is conformant to the established ...
Definition: rs.cpp:721
const char * rs_frame_metadata_to_string(rs_frame_metadata md)
Definition: rs.cpp:767
const char * rs_get_device_firmware_version(const rs_device *device, rs_error **error)
Retrieves the version of the firmware currently installed on the device.
Definition: rs.cpp:156
void rs_wait_for_frames(rs_device *device, rs_error **error)
Blocks until new frames are available.
Definition: rs.cpp:428
const char * rs_source_to_string(rs_source source)
Definition: rs.cpp:760
void rs_free_error(rs_error *error)
Frees memory of an error object.
Definition: rs.cpp:748
const char * rs_get_device_usb_port_id(const rs_device *device, rs_error **error)
Retrieves the USB port number of the device.
Definition: rs.cpp:149
GLsizei const GLfloat * value
Definition: glext.h:693
void rs_get_device_extrinsics(const rs_device *device, rs_stream from, rs_stream to, rs_extrinsics *extrin, rs_error **error)
Retrieves extrinsic transformation between the viewpoints of two different streams.
Definition: rs.cpp:163
const char * rs_get_format_name(rs_format format, rs_error **error)
Definition: rs.cpp:592
const char * rs_camera_info_to_string(rs_camera_info info)
Definition: rs.cpp:764
void(* rs_timestamp_callback_ptr)(rs_device *, rs_timestamp_data, void *)
Definition: rs.h:367
void rs_get_device_option_range_ex(rs_device *device, rs_option option, double *min, double *max, double *step, double *def, rs_error **error)
Retrieves the available range of values for a supported option.
Definition: rs.cpp:645
void rs_start_source(rs_device *device, rs_source source, rs_error **error)
Begins streaming on all enabled streams for this device.
Definition: rs.cpp:390
rs_source
Source: allows you to choose between available hardware subdevices.
Definition: rs.h:90
int rs_get_device_count(const rs_context *context, rs_error **error)
Determines number of connected devices.
Definition: rs.cpp:113
Video stream intrinsics.
Definition: rs.h:300
const char * rs_get_capabilities_name(rs_capabilities capability, rs_error **error)
Definition: rs.cpp:620
struct _cl_event * event
Definition: glext.h:2917
typedef void(APIENTRYP PFNGLDRAWRANGEELEMENTSPROC)(GLenum mode
int rs_supports_camera_info(rs_device *device, rs_camera_info info_param, rs_error **error)
Returns true if given camera information parameter is supported by the device.
Definition: rs.cpp:450
Cross-stream extrinsics: encode the topology describing how the different devices are connected...
Definition: rs.h:332
#define VALIDATE_NATIVE_STREAM(ARG)
Definition: rs.cpp:47
void rs_enable_motion_tracking_cpp(rs_device *device, rs_motion_callback *motion_callback, rs_timestamp_callback *ts_callback, rs_error **error)
Enables and configures motion-tracking data handlers.
Definition: rs.cpp:352
const char * get_string(rs_stream value)
Definition: types.cpp:19
const void * rs_get_frame_data(const rs_device *device, rs_stream stream, rs_error **error)
Retrieves the contents of the latest frame on a stream.
Definition: rs.cpp:490
int rs_supports(rs_device *device, rs_capabilities capability, rs_error **error)
Determines device capabilities.
Definition: rs.cpp:442
rs_preset
Presets: general preferences that are translated by librealsense into concrete resolution and FPS...
Definition: rs.h:81
const char * rs_get_device_name(const rs_device *device, rs_error **error)
Retrieves human-readable device model string.
Definition: rs.cpp:128
GLenum GLsizei GLsizei GLint * values
Definition: glext.h:1484
int rs_device_supports_option(const rs_device *device, rs_option option, rs_error **error)
Determines if the device allows a specific option to be queried and set.
Definition: rs.cpp:182
const char * rs_get_event_name(rs_event_source event, rs_error **error)
Definition: rs.cpp:627
distortion
Distortion model: defines how pixel coordinates should be mapped to sensor coordinates.
Definition: rs.hpp:76
const char * rs_get_distortion_name(rs_distortion distortion, rs_error **error)
Definition: rs.cpp:606
rs_stream
Streams are different types of data provided by RealSense devices.
Definition: rs.h:33
#define RS_API_MAJOR_VERSION
Definition: rs.h:17
void rs_get_device_options(rs_device *device, const rs_option options[], unsigned int count, double values[], rs_error **error)
Definition: rs.cpp:672
GLint GLint GLsizei width
Definition: glext.h:112
const char * rs_get_failed_args(const rs_error *error)
Returns static pointer to arguments of a failing function in case of error.
Definition: rs.cpp:750
GLuint const GLchar * name
Definition: glext.h:655
double rs_get_detached_frame_metadata(const rs_frame_ref *frame, rs_frame_metadata frame_metadata, rs_error **error)
Retrieves metadata from a frame reference.
Definition: rs.cpp:458
GLsizei GLsizei GLchar * source
Definition: glext.h:672
GLsizeiptr size
Definition: glext.h:532
void rs_get_stream_intrinsics(const rs_device *device, rs_stream stream, rs_intrinsics *intrin, rs_error **error)
Retrieves intrinsic camera parameters for a specific stream.
Definition: rs.cpp:289
int minor(int version)
Definition: rs.cpp:53
rs_log_severity
Severity of the librealsense logger.
Definition: rs.h:265
rs_format rs_get_stream_format(const rs_device *device, rs_stream stream, rs_error **error)
Retrieves the pixel format for a specific stream.
Definition: rs.cpp:273
const char * function
Definition: rs.cpp:19
void rs_enable_stream_preset(rs_device *device, rs_stream stream, rs_preset preset, rs_error **error)
Enables a specific stream and requests properties using a preset.
Definition: rs.cpp:232
void rs_get_stream_mode(const rs_device *device, rs_stream stream, int index, int *width, int *height, rs_format *format, int *framerate, rs_error **error)
Determines the properties of a specific streaming mode.
Definition: rs.cpp:198
void rs_get_motion_intrinsics(const rs_device *device, rs_motion_intrinsics *intrinsic, rs_error **error)
Retrieves intrinsic camera parameters for a motion module.
Definition: rs.cpp:298
int rs_get_stream_framerate(const rs_device *device, rs_stream stream, rs_error **error)
Retrieves the frame rate for a specific stream.
Definition: rs.cpp:281
rs_capabilities
Specifies various capabilities of a RealSense device.
Definition: rs.h:213
static rs_context * acquire_instance()
Definition: context.cpp:93
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: glext.h:112
void rs_start_device(rs_device *device, rs_error **error)
Begins streaming on all enabled streams for this device.
Definition: rs.cpp:383
int rs_is_device_streaming(const rs_device *device, rs_error **error)
Determines if the device is currently streaming.
Definition: rs.cpp:413
#define VALIDATE_LE(ARG, MAX)
Definition: rs.cpp:46
int rs_get_detached_frame_width(const rs_frame_ref *frame_ref, rs_error **error)
Retrieves frame intrinsic width in pixels.
Definition: rs.cpp:519
rs_distortion
Distortion model: defines how pixel coordinates should be mapped to sensor coordinates.
Definition: rs.h:99
void rs_get_motion_extrinsics_from(const rs_device *device, rs_stream from, rs_extrinsics *extrin, rs_error **error)
Retrieves extrinsic transformation between specific stream and the motion module. ...
Definition: rs.cpp:173
void rs_enable_motion_tracking(rs_device *device, rs_motion_callback_ptr on_motion_event, void *motion_handler, rs_timestamp_callback_ptr on_timestamp_event, void *timestamp_handler, rs_error **error)
Enables and configures motion-tracking data handlers.
Definition: rs.cpp:338
rs_frame_metadata
Types of value provided from the device with each frame.
Definition: rs.h:203
void rs_set_frame_callback(rs_device *device, rs_stream stream, rs_frame_callback_ptr on_frame, void *user, rs_error **error)
Sets up a frame callback that is called immediately when an image is available, with no synchronizati...
Definition: rs.cpp:306
int rs_is_motion_tracking_active(rs_device *device, rs_error **error)
Checks if data acquisition is active.
Definition: rs.cpp:375
const char * rs_get_device_option_description(rs_device *device, rs_option option, rs_error **error)
Retrieves a static description of what a particular option does on given device.
Definition: rs.cpp:704
const void * rs_get_detached_frame_data(const rs_frame_ref *frame_ref, rs_error **error)
Retrieves data from frame reference.
Definition: rs.cpp:512
void rs_log_to_callback(rs_log_severity min_severity, rs_log_callback_ptr on_log, void *user, rs_error **error)
Starts logging to user-provided callback (C version)
Definition: rs.cpp:324
void rs_reset_device_options_to_default(rs_device *device, const rs_option *options, int count, rs_error **error)
Efficiently resets the value of an arbitrary number of options to default.
Definition: rs.cpp:654
#define HANDLE_EXCEPTIONS_AND_RETURN(R,...)
Definition: rs.cpp:42
const char * rs_get_device_serial(const rs_device *device, rs_error **error)
Retrieves unique serial number of the device.
Definition: rs.cpp:135
unsigned long long rs_get_detached_frame_number(const rs_frame_ref *frame, rs_error **error)
Retrieves frame number from frame reference.
Definition: rs.cpp:570
void on_motion_event(rs::motion_data entry)
const char * rs_event_to_string(rs_event_source event)
Definition: rs.cpp:761
#define VALIDATE_NOT_NULL(ARG)
Definition: rs.cpp:43
void report_version_mismatch(int runtime, int compiletime)
Definition: rs.cpp:68
int rs_get_stream_height(const rs_device *device, rs_stream stream, rs_error **error)
Retrieves the height in pixels of a specific stream, equivalent to the height field from the stream&#39;s...
Definition: rs.cpp:265
GLint GLint GLint GLint GLint x
Definition: glext.h:114
rs_event_source
Source device that triggered a specific timestamp event from the motion module.
Definition: rs.h:276
int rs_poll_for_frames(rs_device *device, rs_error **error)
Checks if new frames are available, without blocking.
Definition: rs.cpp:435
void rs_delete_context(rs_context *context, rs_error **error)
Frees the relevant context object.
Definition: rs.cpp:106
int rs_get_detached_frame_bpp(const rs_frame_ref *frame_ref, rs_error **error)
Retrieves frame bits per pixel.
Definition: rs.cpp:548
#define VALIDATE_RANGE(ARG, MIN, MAX)
Definition: rs.cpp:45
const char * rs_get_failed_function(const rs_error *error)
Returns static pointer to name of a failing function in case of error.
Definition: rs.cpp:749
void rs_enable_stream(rs_device *device, rs_stream stream, int width, int height, rs_format format, int framerate, rs_error **error)
Enables a specific stream and requests specific properties.
Definition: rs.cpp:220
GLuint GLuint GLsizei GLenum type
Definition: glext.h:111
preset
Presets: general preferences that are translated by librealsense into concrete resolution and FPS...
Definition: rs.hpp:68
rs_context * rs_create_context(int api_version, rs_error **error)
Creates RealSense context that is required for the rest of the API.
Definition: rs.cpp:75
const char * rs_capabilities_to_string(rs_capabilities capability)
Definition: rs.cpp:759
static void release_instance()
Definition: context.cpp:103


librealsense
Author(s): Sergey Dorodnicov , Mark Horn , Reagan Lopez
autogenerated on Fri Mar 13 2020 03:16:17