rs.cpp
Go to the documentation of this file.
00001 // License: Apache 2.0. See LICENSE file in root directory.
00002 // Copyright(c) 2015 Intel Corporation. All Rights Reserved.
00003 
00004 #include <functional>   // For function
00005 #include <climits>
00006 
00007 #include "context.h"
00008 #include "device.h"
00009 #include "sync.h"
00010 #include "archive.h"
00011 
00013 // API implementation //
00015 
00016 struct rs_error
00017 {
00018     std::string message;
00019     const char * function;
00020     std::string args;
00021 };
00022 
00023 // This facility allows for translation of exceptions to rs_error structs at the API boundary
00024 namespace rsimpl
00025 {
00026     template<class T> void stream_args(std::ostream & out, const char * names, const T & last) { out << names << ':' << last; }
00027     template<class T, class... U> void stream_args(std::ostream & out, const char * names, const T & first, const U &... rest)
00028     {
00029         while(*names && *names != ',') out << *names++;
00030         out << ':' << first << ", ";
00031         while(*names && (*names == ',' || isspace(*names))) ++names;
00032         stream_args(out, names, rest...);
00033     }
00034 
00035     static void translate_exception(const char * name, std::string args, rs_error ** error)
00036     {
00037         try { throw; }
00038         catch (const std::exception & e) { if (error) *error = new rs_error {e.what(), name, move(args)}; } // todo - Handle case where THIS code throws
00039         catch (...) { if (error) *error = new rs_error {"unknown error", name, move(args)}; } // todo - Handle case where THIS code throws
00040     }
00041 }
00042 #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; }
00043 #define VALIDATE_NOT_NULL(ARG) if(!(ARG)) throw std::runtime_error("null pointer passed for argument \"" #ARG "\"");
00044 #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()); }
00045 #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()); }
00046 #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()); }
00047 #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()); }
00048 
00049 int major(int version)
00050 {
00051     return version / 10000;
00052 }
00053 int minor(int version)
00054 {
00055     return (version % 10000) / 100;
00056 }
00057 int patch(int version)
00058 {
00059     return (version % 100);
00060 }
00061 
00062 std::string api_version_to_string(int version)
00063 {
00064     if (major(version) == 0) return rsimpl::to_string() << version;
00065     return rsimpl::to_string() << major(version) << "." << minor(version) << "." << patch(version);
00066 }
00067 
00068 void report_version_mismatch(int runtime, int compiletime)
00069 {
00070     throw std::runtime_error(rsimpl::to_string() << "API version mismatch: librealsense.so was compiled with API version " 
00071         << api_version_to_string(runtime) << " but the application was compiled with " 
00072         << api_version_to_string(compiletime) << "! Make sure correct version of the library is installed (make install)");
00073 }
00074 
00075 rs_context * rs_create_context(int api_version, rs_error ** error) try
00076 {
00077     rs_error * local_error = nullptr;
00078     auto runtime_api_version = rs_get_api_version(&local_error);
00079     if (local_error) throw std::runtime_error(rs_get_error_message(local_error));
00080 
00081     if ((runtime_api_version < 10) || (api_version < 10))
00082     {
00083         // when dealing with version < 1.0.0 that were still using single number for API version, require exact match
00084         if (api_version != runtime_api_version) 
00085             report_version_mismatch(runtime_api_version, api_version);
00086     }
00087     else if ((major(runtime_api_version) == 1 && minor(runtime_api_version) <= 9) 
00088           || (major(api_version) == 1 && minor(api_version) <= 9))
00089     {
00090         // when dealing with version < 1.10.0, API breaking changes are still possible without minor version change, require exact match
00091         if (api_version != runtime_api_version) 
00092             report_version_mismatch(runtime_api_version, api_version);
00093     }
00094     else
00095     {
00096         // starting with 1.10.0, versions with same patch are compatible
00097         if ((major(api_version) != major(runtime_api_version)) 
00098          || (minor(api_version) != minor(runtime_api_version))) 
00099             report_version_mismatch(runtime_api_version, api_version);
00100     }
00101 
00102     return rs_context_base::acquire_instance();
00103 }
00104 HANDLE_EXCEPTIONS_AND_RETURN(nullptr, api_version)
00105 
00106 void rs_delete_context(rs_context * context, rs_error ** error) try
00107 {
00108     VALIDATE_NOT_NULL(context);
00109     rs_context_base::release_instance();
00110 }
00111 HANDLE_EXCEPTIONS_AND_RETURN(, context)
00112 
00113 int rs_get_device_count(const rs_context * context, rs_error ** error) try
00114 {
00115     VALIDATE_NOT_NULL(context);
00116     return (int)context->get_device_count();
00117 }
00118 HANDLE_EXCEPTIONS_AND_RETURN(0, context)
00119 
00120 rs_device * rs_get_device(rs_context * context, int index, rs_error ** error) try
00121 {
00122     VALIDATE_NOT_NULL(context);
00123     VALIDATE_RANGE(index, 0, (int)context->get_device_count()-1);
00124     return context->get_device(index);
00125 }
00126 HANDLE_EXCEPTIONS_AND_RETURN(nullptr, context, index)
00127 
00128 const char * rs_get_device_name(const rs_device * device, rs_error ** error) try
00129 {
00130     VALIDATE_NOT_NULL(device);
00131     return device->get_name();
00132 }
00133 HANDLE_EXCEPTIONS_AND_RETURN(nullptr, device)
00134 
00135 const char * rs_get_device_serial(const rs_device * device, rs_error ** error) try
00136 {
00137     VALIDATE_NOT_NULL(device);
00138     return device->get_serial();
00139 }
00140 HANDLE_EXCEPTIONS_AND_RETURN(nullptr, device)
00141 
00142 const char * rs_get_device_info(const rs_device * device, rs_camera_info info, rs_error ** error) try
00143 {
00144     VALIDATE_NOT_NULL(device);
00145     return device->get_camera_info(info);
00146 }
00147 HANDLE_EXCEPTIONS_AND_RETURN(0, device, info)
00148 
00149 const char * rs_get_device_usb_port_id(const rs_device * device, rs_error **error) try
00150 {
00151     VALIDATE_NOT_NULL(device);
00152     return device->get_usb_port_id();
00153 }
00154 HANDLE_EXCEPTIONS_AND_RETURN(0, device)
00155 
00156 const char * rs_get_device_firmware_version(const rs_device * device, rs_error ** error) try
00157 {
00158     VALIDATE_NOT_NULL(device);
00159     return device->get_firmware_version();
00160 }
00161 HANDLE_EXCEPTIONS_AND_RETURN(nullptr, device)
00162 
00163 void rs_get_device_extrinsics(const rs_device * device, rs_stream from, rs_stream to, rs_extrinsics * extrin, rs_error ** error) try
00164 {
00165     VALIDATE_NOT_NULL(device);
00166     VALIDATE_ENUM(from);
00167     VALIDATE_ENUM(to);
00168     VALIDATE_NOT_NULL(extrin);
00169     *extrin = device->get_stream_interface(from).get_extrinsics_to(device->get_stream_interface(to));
00170 }
00171 HANDLE_EXCEPTIONS_AND_RETURN(, device, from, to, extrin)
00172 
00173 void rs_get_motion_extrinsics_from(const rs_device * device, rs_stream from, rs_extrinsics * extrin, rs_error ** error) try
00174 {
00175     VALIDATE_NOT_NULL(device);
00176     VALIDATE_ENUM(from);
00177     VALIDATE_NOT_NULL(extrin);
00178     *extrin = device->get_motion_extrinsics_from(from);
00179 }
00180 HANDLE_EXCEPTIONS_AND_RETURN(, device, from, extrin)
00181 
00182 int rs_device_supports_option(const rs_device * device, rs_option option, rs_error ** error) try
00183 {
00184     VALIDATE_NOT_NULL(device);
00185     VALIDATE_ENUM(option);
00186     return device->supports_option(option);
00187 }
00188 HANDLE_EXCEPTIONS_AND_RETURN(0, device, option)
00189 
00190 int rs_get_stream_mode_count(const rs_device * device, rs_stream stream, rs_error ** error) try
00191 {
00192     VALIDATE_NOT_NULL(device);
00193     VALIDATE_ENUM(stream);
00194     return device->get_stream_interface(stream).get_mode_count();
00195 }
00196 HANDLE_EXCEPTIONS_AND_RETURN(0, device, stream)
00197 
00198 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
00199 {
00200     VALIDATE_NOT_NULL(device);
00201     VALIDATE_ENUM(stream);
00202     VALIDATE_RANGE(index, 0, device->get_stream_interface(stream).get_mode_count()-1);
00203     device->get_stream_interface(stream).get_mode(index, width, height, format, framerate);
00204 }
00205 HANDLE_EXCEPTIONS_AND_RETURN(, device, stream, index, width, height, format, framerate)
00206 
00207 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) try
00208 {
00209     VALIDATE_NOT_NULL(device);
00210     VALIDATE_NATIVE_STREAM(stream);
00211     VALIDATE_RANGE(width, 0, INT_MAX);
00212     VALIDATE_RANGE(height, 0, INT_MAX);
00213     VALIDATE_ENUM(format);
00214     VALIDATE_ENUM(output);
00215     VALIDATE_RANGE(framerate, 0, INT_MAX);
00216     device->enable_stream(stream, width, height, format, framerate, output);
00217 }
00218 HANDLE_EXCEPTIONS_AND_RETURN(, device, stream, width, height, format, framerate)
00219 
00220 void rs_enable_stream(rs_device * device, rs_stream stream, int width, int height, rs_format format, int framerate, rs_error ** error) try
00221 {
00222     VALIDATE_NOT_NULL(device);
00223     VALIDATE_NATIVE_STREAM(stream);
00224     VALIDATE_RANGE(width, 0, INT_MAX);
00225     VALIDATE_RANGE(height, 0, INT_MAX);
00226     VALIDATE_ENUM(format);
00227     VALIDATE_RANGE(framerate, 0, INT_MAX);
00228     device->enable_stream(stream, width, height, format, framerate, RS_OUTPUT_BUFFER_FORMAT_CONTINUOUS);
00229 }
00230 HANDLE_EXCEPTIONS_AND_RETURN(, device, stream, width, height, format, framerate)
00231 
00232 void rs_enable_stream_preset(rs_device * device, rs_stream stream, rs_preset preset, rs_error ** error) try
00233 {
00234     VALIDATE_NOT_NULL(device);
00235     VALIDATE_NATIVE_STREAM(stream);
00236     VALIDATE_ENUM(preset);
00237     device->enable_stream_preset(stream, preset);
00238 }
00239 HANDLE_EXCEPTIONS_AND_RETURN(, device, stream, preset)
00240 
00241 void rs_disable_stream(rs_device * device, rs_stream stream, rs_error ** error) try
00242 {
00243     VALIDATE_NOT_NULL(device);
00244     VALIDATE_NATIVE_STREAM(stream);
00245     device->disable_stream(stream);
00246 }
00247 HANDLE_EXCEPTIONS_AND_RETURN(, device, stream)
00248 
00249 int rs_is_stream_enabled(const rs_device * device, rs_stream stream, rs_error ** error) try
00250 {
00251     VALIDATE_NOT_NULL(device);
00252     VALIDATE_NATIVE_STREAM(stream);
00253     return device->get_stream_interface(stream).is_enabled();
00254 }
00255 HANDLE_EXCEPTIONS_AND_RETURN(0, device, stream)
00256 
00257 int rs_get_stream_width(const rs_device * device, rs_stream stream, rs_error ** error) try
00258 {
00259     VALIDATE_NOT_NULL(device);
00260     VALIDATE_ENUM(stream);
00261     return device->get_stream_interface(stream).get_intrinsics().width;
00262 }
00263 HANDLE_EXCEPTIONS_AND_RETURN(0, device, stream)
00264 
00265 int rs_get_stream_height(const rs_device * device, rs_stream stream, rs_error ** error) try
00266 {
00267     VALIDATE_NOT_NULL(device);
00268     VALIDATE_ENUM(stream);
00269     return device->get_stream_interface(stream).get_intrinsics().height;
00270 }
00271 HANDLE_EXCEPTIONS_AND_RETURN(0, device, stream)
00272 
00273 rs_format rs_get_stream_format(const rs_device * device, rs_stream stream, rs_error ** error) try
00274 {
00275     VALIDATE_NOT_NULL(device);
00276     VALIDATE_ENUM(stream);
00277     return device->get_stream_interface(stream).get_format();
00278 }
00279 HANDLE_EXCEPTIONS_AND_RETURN(RS_FORMAT_ANY, device, stream)
00280 
00281 int rs_get_stream_framerate(const rs_device * device, rs_stream stream, rs_error ** error) try
00282 {
00283     VALIDATE_NOT_NULL(device);
00284     VALIDATE_ENUM(stream);
00285     return device->get_stream_interface(stream).get_framerate();
00286 }
00287 HANDLE_EXCEPTIONS_AND_RETURN(RS_FORMAT_ANY, device, stream)
00288 
00289 void rs_get_stream_intrinsics(const rs_device * device, rs_stream stream, rs_intrinsics * intrin, rs_error ** error) try
00290 {
00291     VALIDATE_NOT_NULL(device);
00292     VALIDATE_ENUM(stream);
00293     VALIDATE_NOT_NULL(intrin);
00294     *intrin = device->get_stream_interface(stream).get_intrinsics();
00295 }
00296 HANDLE_EXCEPTIONS_AND_RETURN(, device, stream, intrin)
00297 
00298 void rs_get_motion_intrinsics(const rs_device * device, rs_motion_intrinsics * intrinsic, rs_error ** error) try
00299 {
00300     VALIDATE_NOT_NULL(device);
00301     VALIDATE_NOT_NULL(intrinsic);
00302     *intrinsic = device->get_motion_intrinsics();
00303 }
00304 HANDLE_EXCEPTIONS_AND_RETURN(, device, intrinsic)
00305 
00306 void rs_set_frame_callback(rs_device * device, rs_stream stream, rs_frame_callback_ptr on_frame, void * user, rs_error ** error) try
00307 {
00308     VALIDATE_NOT_NULL(device);
00309     VALIDATE_NATIVE_STREAM(stream);
00310     VALIDATE_NOT_NULL(on_frame);
00311     device->set_stream_callback(stream, on_frame, user);
00312 }
00313 HANDLE_EXCEPTIONS_AND_RETURN(, device, stream, on_frame, user)
00314 
00315 void rs_set_frame_callback_cpp(rs_device * device, rs_stream stream, rs_frame_callback * callback, rs_error ** error) try
00316 {
00317     VALIDATE_NOT_NULL(device);
00318     VALIDATE_NATIVE_STREAM(stream);
00319     VALIDATE_NOT_NULL(callback);
00320     device->set_stream_callback(stream, callback);
00321 }
00322 HANDLE_EXCEPTIONS_AND_RETURN(, device, stream, callback)
00323 
00324 void rs_log_to_callback(rs_log_severity min_severity, rs_log_callback_ptr on_log, void * user, rs_error ** error) try
00325 {
00326     VALIDATE_NOT_NULL(on_log);
00327     rsimpl::log_to_callback(min_severity, on_log, user);
00328 }
00329 HANDLE_EXCEPTIONS_AND_RETURN(, min_severity, on_log, user)
00330 
00331 void rs_log_to_callback_cpp(rs_log_severity min_severity, rs_log_callback * callback, rs_error ** error) try
00332 {
00333     VALIDATE_NOT_NULL(callback);
00334     rsimpl::log_to_callback(min_severity, callback);
00335 }
00336 HANDLE_EXCEPTIONS_AND_RETURN(, min_severity, callback)
00337 
00338 void rs_enable_motion_tracking(rs_device * device,
00339     rs_motion_callback_ptr on_motion_event, void * motion_handler,
00340     rs_timestamp_callback_ptr on_timestamp_event, void * timestamp_handler,
00341     rs_error ** error) try
00342 {
00343     VALIDATE_NOT_NULL(device);
00344     VALIDATE_NOT_NULL(on_motion_event);
00345     VALIDATE_NOT_NULL(on_timestamp_event || on_motion_event);
00346     device->enable_motion_tracking();
00347     device->set_motion_callback(on_motion_event, motion_handler);
00348     device->set_timestamp_callback(on_timestamp_event, timestamp_handler);
00349 }
00350 HANDLE_EXCEPTIONS_AND_RETURN(, device, on_motion_event, motion_handler, on_timestamp_event, timestamp_handler)
00351 
00352 void rs_enable_motion_tracking_cpp(rs_device * device,
00353     rs_motion_callback * motion_callback,
00354     rs_timestamp_callback * ts_callback,
00355     rs_error ** error) try
00356 {
00357     VALIDATE_NOT_NULL(device);
00358     VALIDATE_NOT_NULL(motion_callback);
00359     VALIDATE_NOT_NULL(ts_callback);
00360     device->enable_motion_tracking();
00361     device->set_motion_callback(motion_callback);
00362     device->set_timestamp_callback(ts_callback);
00363 }
00364 HANDLE_EXCEPTIONS_AND_RETURN(, device, motion_callback, ts_callback)
00365 
00366 void rs_disable_motion_tracking(rs_device * device, rs_error ** error) try
00367 {
00368     VALIDATE_NOT_NULL(device);
00369     device->disable_motion_tracking();
00370     device->set_motion_callback(nullptr, nullptr);
00371     device->set_timestamp_callback(nullptr, nullptr);
00372 }
00373 HANDLE_EXCEPTIONS_AND_RETURN(, device)
00374 
00375 int rs_is_motion_tracking_active(rs_device * device, rs_error ** error) try
00376 {
00377     VALIDATE_NOT_NULL(device);  
00378 
00379     return device->is_motion_tracking_active();
00380 }
00381 HANDLE_EXCEPTIONS_AND_RETURN(0, device)
00382 
00383 void rs_start_device(rs_device * device, rs_error ** error) try
00384 {
00385     VALIDATE_NOT_NULL(device); 
00386     device->start(rs_source::RS_SOURCE_VIDEO);
00387 }
00388 HANDLE_EXCEPTIONS_AND_RETURN(, device)
00389 
00390 void rs_start_source(rs_device * device, rs_source source, rs_error ** error) try
00391 {
00392     VALIDATE_NOT_NULL(device); 
00393     VALIDATE_ENUM(source);
00394     device->start(source);
00395 }
00396 HANDLE_EXCEPTIONS_AND_RETURN(, device, source)
00397 
00398 void rs_stop_device(rs_device * device, rs_error ** error) try
00399 {
00400     VALIDATE_NOT_NULL(device);
00401     device->stop(rs_source::RS_SOURCE_VIDEO);
00402 }
00403 HANDLE_EXCEPTIONS_AND_RETURN(, device)
00404 
00405 void rs_stop_source(rs_device * device, rs_source source, rs_error ** error) try
00406 {
00407     VALIDATE_NOT_NULL(device);
00408     VALIDATE_ENUM(source);
00409     device->stop(source);
00410 }
00411 HANDLE_EXCEPTIONS_AND_RETURN(, device, source)
00412 
00413 int rs_is_device_streaming(const rs_device * device, rs_error ** error) try
00414 {
00415     VALIDATE_NOT_NULL(device);
00416     return device->is_capturing();
00417 }
00418 HANDLE_EXCEPTIONS_AND_RETURN(0, device)
00419 
00420 float rs_get_device_depth_scale(const rs_device * device, rs_error ** error) try
00421 {
00422     VALIDATE_NOT_NULL(device);
00423     return device->get_depth_scale();
00424 }
00425 HANDLE_EXCEPTIONS_AND_RETURN(0.0f, device)
00426 
00427 
00428 void rs_wait_for_frames(rs_device * device, rs_error ** error) try
00429 {
00430     VALIDATE_NOT_NULL(device);
00431     device->wait_all_streams();
00432 }
00433 HANDLE_EXCEPTIONS_AND_RETURN(, device)
00434 
00435 int rs_poll_for_frames(rs_device * device, rs_error ** error) try
00436 {
00437     VALIDATE_NOT_NULL(device);
00438     return device->poll_all_streams();
00439 }
00440 HANDLE_EXCEPTIONS_AND_RETURN(0, device)
00441 
00442 int rs_supports(rs_device * device, rs_capabilities capability, rs_error ** error) try
00443 {
00444     VALIDATE_NOT_NULL(device);
00445     VALIDATE_ENUM(capability);
00446     return device->supports(capability);
00447 }
00448 HANDLE_EXCEPTIONS_AND_RETURN(0, device)
00449 
00450 int rs_supports_camera_info(rs_device * device, rs_camera_info info_param, rs_error ** error) try
00451 {
00452     VALIDATE_NOT_NULL(device);
00453     VALIDATE_ENUM(info_param);
00454     return device->supports(info_param);
00455 }
00456 HANDLE_EXCEPTIONS_AND_RETURN(0, device)
00457 
00458 double rs_get_detached_frame_metadata(const rs_frame_ref * frame, rs_frame_metadata frame_metadata, rs_error ** error) try
00459 {
00460     VALIDATE_NOT_NULL(frame);
00461     VALIDATE_ENUM(frame_metadata);
00462     return frame->get_frame_metadata(frame_metadata);
00463 }
00464 HANDLE_EXCEPTIONS_AND_RETURN(0, frame)
00465 
00466 int rs_supports_frame_metadata(const rs_frame_ref * frame, rs_frame_metadata frame_metadata, rs_error ** error) try
00467 {
00468     VALIDATE_NOT_NULL(frame);
00469     VALIDATE_ENUM(frame_metadata);
00470     return frame->supports_frame_metadata(frame_metadata);
00471 }
00472 HANDLE_EXCEPTIONS_AND_RETURN(0, frame)
00473 
00474 double rs_get_frame_timestamp(const rs_device * device, rs_stream stream, rs_error ** error) try
00475 {
00476     VALIDATE_NOT_NULL(device);
00477     VALIDATE_ENUM(stream);
00478     return device->get_stream_interface(stream).get_frame_timestamp();
00479 }
00480 HANDLE_EXCEPTIONS_AND_RETURN(0, device, stream)
00481 
00482 unsigned long long rs_get_frame_number(const rs_device * device, rs_stream stream, rs_error ** error) try
00483 {
00484     VALIDATE_NOT_NULL(device);
00485     VALIDATE_ENUM(stream);
00486     return device->get_stream_interface(stream).get_frame_number();
00487 }
00488 HANDLE_EXCEPTIONS_AND_RETURN(0, device)
00489 
00490 const void * rs_get_frame_data(const rs_device * device, rs_stream stream, rs_error ** error) try
00491 {
00492     VALIDATE_NOT_NULL(device);
00493     VALIDATE_ENUM(stream);
00494     return device->get_stream_interface(stream).get_frame_data();
00495 }
00496 HANDLE_EXCEPTIONS_AND_RETURN(nullptr, device, stream)
00497 
00498 double rs_get_detached_frame_timestamp(const rs_frame_ref * frame_ref, rs_error ** error) try
00499 {
00500     VALIDATE_NOT_NULL(frame_ref);
00501     return frame_ref->get_frame_timestamp();
00502 }
00503 HANDLE_EXCEPTIONS_AND_RETURN(0, frame_ref)
00504 
00505 rs_timestamp_domain rs_get_detached_frame_timestamp_domain(const rs_frame_ref * frame_ref, rs_error ** error) try
00506 {
00507     VALIDATE_NOT_NULL(frame_ref);
00508     return frame_ref->get_frame_timestamp_domain();
00509 }
00510 HANDLE_EXCEPTIONS_AND_RETURN(RS_TIMESTAMP_DOMAIN_COUNT, frame_ref)
00511 
00512 const void * rs_get_detached_frame_data(const rs_frame_ref * frame_ref, rs_error ** error) try
00513 {
00514     VALIDATE_NOT_NULL(frame_ref);
00515     return frame_ref->get_frame_data();
00516 }
00517 HANDLE_EXCEPTIONS_AND_RETURN(nullptr, frame_ref)
00518 
00519 int rs_get_detached_frame_width(const rs_frame_ref * frame_ref, rs_error ** error) try
00520 {
00521     VALIDATE_NOT_NULL(frame_ref);
00522     return frame_ref->get_frame_width();
00523 }
00524 HANDLE_EXCEPTIONS_AND_RETURN(0, frame_ref)
00525 
00526 int rs_get_detached_frame_height(const rs_frame_ref * frame_ref, rs_error ** error) try
00527 {
00528     VALIDATE_NOT_NULL(frame_ref);
00529     return frame_ref->get_frame_height();
00530 }
00531 HANDLE_EXCEPTIONS_AND_RETURN(0, frame_ref)
00532 
00533 int rs_get_detached_framerate(const rs_frame_ref * frame_ref, rs_error ** error) try
00534 {
00535     VALIDATE_NOT_NULL(frame_ref);
00536     return frame_ref->get_frame_framerate();
00537 }
00538 HANDLE_EXCEPTIONS_AND_RETURN(0, frame_ref)
00539 
00540 int rs_get_detached_frame_stride(const rs_frame_ref * frame_ref, rs_error ** error) try
00541 {
00542     VALIDATE_NOT_NULL(frame_ref);
00543     return frame_ref->get_frame_stride();
00544 }
00545 HANDLE_EXCEPTIONS_AND_RETURN(0, frame_ref)
00546 
00547 
00548 int rs_get_detached_frame_bpp(const rs_frame_ref * frame_ref, rs_error ** error) try
00549 {
00550     VALIDATE_NOT_NULL(frame_ref);
00551     return frame_ref->get_frame_bpp();
00552 }
00553 HANDLE_EXCEPTIONS_AND_RETURN(0, frame_ref)
00554 
00555 rs_format rs_get_detached_frame_format(const rs_frame_ref * frame_ref, rs_error ** error) try
00556 {
00557     VALIDATE_NOT_NULL(frame_ref);
00558     return frame_ref->get_frame_format();
00559 }
00560 HANDLE_EXCEPTIONS_AND_RETURN(RS_FORMAT_ANY, frame_ref)
00561 
00562 rs_stream rs_get_detached_frame_stream_type(const rs_frame_ref * frame_ref, rs_error ** error) try
00563 {
00564     VALIDATE_NOT_NULL(frame_ref);
00565     return frame_ref->get_stream_type();
00566 }
00567 HANDLE_EXCEPTIONS_AND_RETURN(RS_STREAM_COUNT, frame_ref)
00568 
00569 
00570 unsigned long long rs_get_detached_frame_number(const rs_frame_ref * frame, rs_error ** error) try
00571 {
00572     VALIDATE_NOT_NULL(frame);
00573     return frame->get_frame_number();
00574 }
00575 HANDLE_EXCEPTIONS_AND_RETURN(0, frame)
00576 
00577 void rs_release_frame(rs_device * device, rs_frame_ref * frame, rs_error ** error) try
00578 {
00579     VALIDATE_NOT_NULL(device);
00580     VALIDATE_NOT_NULL(frame);
00581     device->release_frame(frame);
00582 }
00583 HANDLE_EXCEPTIONS_AND_RETURN(, device, frame)
00584 
00585 const char * rs_get_stream_name(rs_stream stream, rs_error ** error) try
00586 {
00587     VALIDATE_ENUM(stream);
00588     return rsimpl::get_string(stream);
00589 }
00590 HANDLE_EXCEPTIONS_AND_RETURN(nullptr, stream)
00591 
00592 const char * rs_get_format_name(rs_format format, rs_error ** error) try
00593 {
00594    VALIDATE_ENUM(format);
00595    return rsimpl::get_string(format);
00596 }
00597 HANDLE_EXCEPTIONS_AND_RETURN(nullptr, format)
00598 
00599 const char * rs_get_preset_name(rs_preset preset, rs_error ** error) try
00600 {
00601     VALIDATE_ENUM(preset);
00602     return rsimpl::get_string(preset);
00603 }
00604 HANDLE_EXCEPTIONS_AND_RETURN(nullptr, preset)
00605 
00606 const char * rs_get_distortion_name(rs_distortion distortion, rs_error ** error) try
00607 {
00608    VALIDATE_ENUM(distortion);
00609    return rsimpl::get_string(distortion);
00610 }
00611 HANDLE_EXCEPTIONS_AND_RETURN(nullptr, distortion)
00612 
00613 const char * rs_get_option_name(rs_option option, rs_error ** error) try
00614 {
00615     VALIDATE_ENUM(option);
00616     return rsimpl::get_string(option);
00617 }
00618 HANDLE_EXCEPTIONS_AND_RETURN(nullptr, option)
00619 
00620 const char * rs_get_capabilities_name(rs_capabilities capability, rs_error ** error) try
00621 {
00622     VALIDATE_ENUM(capability);
00623     return rsimpl::get_string(capability);
00624 }
00625 HANDLE_EXCEPTIONS_AND_RETURN(nullptr, capability)
00626 
00627 const char * rs_get_event_name(rs_event_source event, rs_error ** error) try
00628 {
00629     VALIDATE_ENUM(event);
00630     return rsimpl::get_string(event);
00631 }
00632 HANDLE_EXCEPTIONS_AND_RETURN(nullptr, event)
00633 
00634 
00635 void rs_get_device_option_range(rs_device * device, rs_option option, double * min, double * max, double * step, rs_error ** error) try
00636 {
00637     VALIDATE_NOT_NULL(device);
00638     VALIDATE_ENUM(option);
00639     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
00640     double def = 0;
00641     device->get_option_range(option, min ? *min : x, max ? *max : x, step ? *step : x, def);
00642 }
00643 HANDLE_EXCEPTIONS_AND_RETURN(, device, option, min, max, step)
00644 
00645 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
00646 {
00647     VALIDATE_NOT_NULL(device);
00648     VALIDATE_ENUM(option);
00649     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
00650     device->get_option_range(option, min ? *min : x, max ? *max : x, step ? *step : x, def ? *def : x);
00651 }
00652 HANDLE_EXCEPTIONS_AND_RETURN(, device, option, min, max, step)
00653 
00654 void rs_reset_device_options_to_default(rs_device * device, const rs_option* options, int count, rs_error ** error) try
00655 {
00656     VALIDATE_NOT_NULL(device);
00657     VALIDATE_RANGE(count, 0, INT_MAX);
00658     VALIDATE_NOT_NULL(options);
00659     for (int i = 0; i<count; ++i) VALIDATE_ENUM(options[i]);
00660 
00661     std::vector<double> values;
00662     for (int i = 0; i < count; ++i)
00663     {
00664         double def;
00665         rs_get_device_option_range_ex(device, options[i], NULL, NULL, NULL, &def, 0);
00666         values.push_back(def);
00667     }
00668     device->set_options(options, count, values.data());
00669 }
00670 HANDLE_EXCEPTIONS_AND_RETURN(, device, options, count)
00671 
00672 void rs_get_device_options(rs_device * device, const rs_option options[], unsigned int count, double values[], rs_error ** error) try
00673 {
00674     VALIDATE_NOT_NULL(device);
00675     VALIDATE_LE(count, INT_MAX);
00676     VALIDATE_NOT_NULL(options);
00677     for(size_t i=0; i<count; ++i) VALIDATE_ENUM(options[i]);
00678     VALIDATE_NOT_NULL(values);
00679     device->get_options(options, count, values);
00680 }
00681 HANDLE_EXCEPTIONS_AND_RETURN(, device, options, count, values)
00682 
00683 void rs_set_device_options(rs_device * device, const rs_option options[], unsigned int count, const double values[], rs_error ** error) try
00684 {
00685     VALIDATE_NOT_NULL(device);
00686     VALIDATE_LE(count, INT_MAX);
00687     VALIDATE_NOT_NULL(options);
00688     for(size_t i=0; i<count; ++i) VALIDATE_ENUM(options[i]);
00689     VALIDATE_NOT_NULL(values);
00690     device->set_options(options, count, values);
00691 }
00692 HANDLE_EXCEPTIONS_AND_RETURN(, device, options, count, values)
00693 
00694 double rs_get_device_option(rs_device * device, rs_option option, rs_error ** error) try
00695 {
00696     VALIDATE_NOT_NULL(device);
00697     VALIDATE_ENUM(option);
00698     double value = 0;
00699     device->get_options(&option, 1, &value);
00700     return value;
00701 }
00702 HANDLE_EXCEPTIONS_AND_RETURN(0, device, option)
00703 
00704 const char * rs_get_device_option_description(rs_device * device, rs_option option, rs_error ** error) try
00705 {
00706     VALIDATE_NOT_NULL(device);
00707     VALIDATE_ENUM(option);
00708     return device->get_option_description(option);
00709 }
00710 HANDLE_EXCEPTIONS_AND_RETURN("", device, option)
00711 
00712 void rs_set_device_option(rs_device * device, rs_option option, double value, rs_error ** error) try
00713 {
00714     VALIDATE_NOT_NULL(device);
00715     VALIDATE_ENUM(option);
00716     device->set_options(&option, 1, &value);
00717 }
00718 HANDLE_EXCEPTIONS_AND_RETURN(, device, option, value)
00719 
00720 // Verify  and provide API version encoded as integer value
00721 int rs_get_api_version(rs_error ** error) try
00722 {
00723     // Each component type is within [0-99] range
00724     VALIDATE_RANGE(RS_API_MAJOR_VERSION, 0, 99);
00725     VALIDATE_RANGE(RS_API_MINOR_VERSION, 0, 99);
00726     VALIDATE_RANGE(RS_API_PATCH_VERSION, 0, 99);
00727     return RS_API_VERSION;
00728 }
00729 HANDLE_EXCEPTIONS_AND_RETURN(0, RS_API_MAJOR_VERSION, RS_API_MINOR_VERSION, RS_API_PATCH_VERSION)
00730 
00731 void rs_send_blob_to_device(rs_device * device, rs_blob_type type, void * data, int size, rs_error ** error) try
00732 {
00733     VALIDATE_NOT_NULL(device);
00734     VALIDATE_NOT_NULL(data);
00735     auto lrs_device = dynamic_cast<rs_device_base*>(device);
00736     if (lrs_device)
00737     {
00738         lrs_device->send_blob_to_device(type, data, size);
00739     }
00740     else
00741     {
00742         throw std::runtime_error("sending binary data to the device is only available when using physical device!");
00743     }
00744 }
00745 HANDLE_EXCEPTIONS_AND_RETURN(, device, type, data, size)
00746 
00747 
00748 void rs_free_error(rs_error * error) { if (error) delete error; }
00749 const char * rs_get_failed_function(const rs_error * error) { return error ? error->function : nullptr; }
00750 const char * rs_get_failed_args(const rs_error * error) { return error ? error->args.c_str() : nullptr; }
00751 const char * rs_get_error_message(const rs_error * error) { return error ? error->message.c_str() : nullptr; }
00752 
00753 
00754 const char * rs_stream_to_string(rs_stream stream) { return rsimpl::get_string(stream); }
00755 const char * rs_format_to_string(rs_format format) { return rsimpl::get_string(format); }
00756 const char * rs_preset_to_string(rs_preset preset) { return rsimpl::get_string(preset); }
00757 const char * rs_distortion_to_string(rs_distortion distortion) { return rsimpl::get_string(distortion); }
00758 const char * rs_option_to_string(rs_option option) { return rsimpl::get_string(option); }
00759 const char * rs_capabilities_to_string(rs_capabilities capability) { return rsimpl::get_string(capability); }
00760 const char * rs_source_to_string(rs_source source)   { return rsimpl::get_string(source); }
00761 const char * rs_event_to_string(rs_event_source event)   { return rsimpl::get_string(event); }
00762 
00763 const char * rs_blob_type_to_string(rs_blob_type type) { return rsimpl::get_string(type); }
00764 const char * rs_camera_info_to_string(rs_camera_info info) { return rsimpl::get_string(info); }
00765 const char * rs_timestamp_domain_to_string(rs_timestamp_domain info){ return rsimpl::get_string(info); }
00766 
00767 const char * rs_frame_metadata_to_string(rs_frame_metadata md) { return rsimpl::get_string(md); }
00768 
00769 void rs_log_to_console(rs_log_severity min_severity, rs_error ** error) try
00770 {
00771     rsimpl::log_to_console(min_severity);
00772 }
00773 HANDLE_EXCEPTIONS_AND_RETURN(, min_severity)
00774 
00775 void rs_log_to_file(rs_log_severity min_severity, const char * file_path, rs_error ** error) try
00776 {
00777     rsimpl::log_to_file(min_severity, file_path);
00778 }
00779 HANDLE_EXCEPTIONS_AND_RETURN(, min_severity, file_path)


librealsense
Author(s): Sergey Dorodnicov , Mark Horn , Reagan Lopez
autogenerated on Tue Jun 25 2019 19:54:39