mirror of
https://github.com/orbbec/OrbbecSDK_ROS2.git
synced 2026-10-04 03:57:46 +08:00
Update OrbbecSDK version to 2.6.2
This commit is contained in:
@@ -110,6 +110,8 @@ OB_EXPORT ob_device *ob_create_net_device_ex(ob_context *context, const char *ad
|
||||
|
||||
/**
|
||||
* @brief Set a device plug-in callback function
|
||||
*
|
||||
* @deprecated This function is deprecated. Please use ob_register_device_changed_callback() instead.
|
||||
*
|
||||
* @attention The added and removed device lists returned through the callback interface need to be released manually
|
||||
* @attention This function supports multiple callbacks. Each call to this function adds a new callback to an internal list.
|
||||
@@ -121,6 +123,36 @@ OB_EXPORT ob_device *ob_create_net_device_ex(ob_context *context, const char *ad
|
||||
*/
|
||||
OB_EXPORT void ob_set_device_changed_callback(ob_context *context, ob_device_changed_callback callback, void *user_data, ob_error **error);
|
||||
|
||||
/**
|
||||
* @brief Register a device plug-in callback function.
|
||||
*
|
||||
* This function registers a callback that will be triggered whenever a device is plugged in or unplugged.
|
||||
*
|
||||
* @attention The added and removed device lists returned through the callback interface need to be released manually.
|
||||
* @attention This function supports multiple callbacks. Each call to this function adds a new callback to an internal list.
|
||||
*
|
||||
* @param[in] context Pointer to the context object.
|
||||
* @param[in] callback Pointer to the callback function triggered when a device is plugged or unplugged.
|
||||
* @param[in] user_data Pointer to user data that can be passed to and retrieved from the callback function.
|
||||
* @param[out] error Pointer to an error object that will be populated if an error occurs during callback function setting.
|
||||
*
|
||||
* @return A ob_callback_id that uniquely identifies the registered callback.
|
||||
* This ID can be used later to unregister the callback with ob_unregister_device_changed_callback().
|
||||
* Returns INVALID_DEVICE_CHANGED_CALLBACK_ID if the registration fails.
|
||||
*/
|
||||
OB_EXPORT ob_callback_id ob_register_device_changed_callback(ob_context *context, ob_device_changed_callback callback, void *user_data, ob_error **error);
|
||||
|
||||
/**
|
||||
* @brief Unregister a previously registered device plug-in callback function.
|
||||
*
|
||||
* This function removes a callback that was registered by ob_register_device_changed_callback().
|
||||
*
|
||||
* @param[in] context Pointer to the context object.
|
||||
* @param[in] callback_id The callback ID returned by ob_register_device_changed_callback().
|
||||
* @param[out] error Pointer to an error object that will be populated if an error occurs during callback function setting.
|
||||
*/
|
||||
OB_EXPORT void ob_unregister_device_changed_callback(ob_context *context, ob_callback_id callback_id, ob_error **error);
|
||||
|
||||
/**
|
||||
* @brief Activates device clock synchronization to synchronize the clock of the host and all created devices (if supported).
|
||||
*
|
||||
|
||||
@@ -260,26 +260,27 @@ typedef enum {
|
||||
* @brief Enumeration value describing the firmware upgrade status
|
||||
*/
|
||||
typedef enum {
|
||||
STAT_DONE_WITH_DUPLICATES = 6, /**< update completed, but some files were duplicated and ignored */
|
||||
STAT_VERIFY_SUCCESS = 5, /**< Image file verifify success */
|
||||
STAT_FILE_TRANSFER = 4, /**< file transfer */
|
||||
STAT_DONE = 3, /**< update completed */
|
||||
STAT_IN_PROGRESS = 2, /**< upgrade in process */
|
||||
STAT_START = 1, /**< start the upgrade */
|
||||
STAT_VERIFY_IMAGE = 0, /**< Image file verification */
|
||||
ERR_VERIFY = -1, /**< Verification failed */
|
||||
ERR_PROGRAM = -2, /**< Program execution failed */
|
||||
ERR_ERASE = -3, /**< Flash parameter failed */
|
||||
ERR_FLASH_TYPE = -4, /**< Flash type error */
|
||||
ERR_IMAGE_SIZE = -5, /**< Image file size error */
|
||||
ERR_OTHER = -6, /**< other errors */
|
||||
ERR_DDR = -7, /**< DDR access error */
|
||||
ERR_TIMEOUT = -8, /**< timeout error */
|
||||
ERR_MISMATCH = -9, /**< Mismatch firmware error */
|
||||
ERR_UNSUPPORT_DEV = -10, /**< Unsupported device error */
|
||||
ERR_INVALID_COUNT = -11, /**< invalid firmware/preset count */
|
||||
ERR_FILE_READ = -12, /**< Read image file error */
|
||||
ERR_TRANSFER = -13 /**< Transfer failed */
|
||||
STAT_DONE_REBOOT_AND_REUPDATE = 7, /**< update completed and device requires manual reboot and a second update*/
|
||||
STAT_DONE_WITH_DUPLICATES = 6, /**< update completed, but some files were duplicated and ignored */
|
||||
STAT_VERIFY_SUCCESS = 5, /**< Image file verifify success */
|
||||
STAT_FILE_TRANSFER = 4, /**< file transfer */
|
||||
STAT_DONE = 3, /**< update completed */
|
||||
STAT_IN_PROGRESS = 2, /**< upgrade in process */
|
||||
STAT_START = 1, /**< start the upgrade */
|
||||
STAT_VERIFY_IMAGE = 0, /**< Image file verification */
|
||||
ERR_VERIFY = -1, /**< Verification failed */
|
||||
ERR_PROGRAM = -2, /**< Program execution failed */
|
||||
ERR_ERASE = -3, /**< Flash parameter failed */
|
||||
ERR_FLASH_TYPE = -4, /**< Flash type error */
|
||||
ERR_IMAGE_SIZE = -5, /**< Image file size error */
|
||||
ERR_OTHER = -6, /**< other errors */
|
||||
ERR_DDR = -7, /**< DDR access error */
|
||||
ERR_TIMEOUT = -8, /**< timeout error */
|
||||
ERR_MISMATCH = -9, /**< Mismatch firmware error */
|
||||
ERR_UNSUPPORT_DEV = -10, /**< Unsupported device error */
|
||||
ERR_INVALID_COUNT = -11, /**< invalid firmware/preset count */
|
||||
ERR_FILE_READ = -12, /**< Read image file error */
|
||||
ERR_TRANSFER = -13 /**< Transfer failed */
|
||||
} OBUpgradeState,
|
||||
OBFwUpdateState, ob_upgrade_state, ob_fw_update_state;
|
||||
|
||||
@@ -1925,6 +1926,13 @@ typedef void(ob_frame_destroy_callback)(uint8_t *buffer, void *user_data);
|
||||
typedef void(ob_log_callback)(ob_log_severity severity, const char *message, void *user_data);
|
||||
|
||||
typedef void (*ob_playback_status_changed_callback)(ob_playback_status status, void *user_data);
|
||||
|
||||
/**
|
||||
* @brief Callback Id
|
||||
*/
|
||||
typedef uint64_t OBCallbackId, ob_callback_id;
|
||||
#define INVALID_CALLBACK_ID (0)
|
||||
|
||||
/**
|
||||
* @brief Check if the sensor_type is a video sensor
|
||||
*
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <mutex>
|
||||
|
||||
namespace ob {
|
||||
|
||||
@@ -42,9 +44,20 @@ public:
|
||||
*/
|
||||
typedef std::function<void(OBLogSeverity severity, const char *logMsg)> LogCallback;
|
||||
|
||||
struct DeviceChangedCallbackContext {
|
||||
Context *ctx;
|
||||
uint64_t callbackId;
|
||||
DeviceChangedCallback callback;
|
||||
};
|
||||
|
||||
private:
|
||||
ob_context *impl_ = nullptr;
|
||||
DeviceChangedCallback deviceChangedCallback_;
|
||||
ob_context *impl_ = nullptr;
|
||||
std::mutex callbackMtx_;
|
||||
|
||||
std::mutex legacyCallbackMtx_;
|
||||
OBCallbackId legacyCallbackId_ = INVALID_CALLBACK_ID;
|
||||
|
||||
std::unordered_map<OBCallbackId, std::unique_ptr<DeviceChangedCallbackContext>> devChangedCallbacks_;
|
||||
// static LogCallback logCallback_;
|
||||
|
||||
public:
|
||||
@@ -66,6 +79,7 @@ public:
|
||||
* @brief Context destructor.
|
||||
*/
|
||||
~Context() noexcept {
|
||||
// delete contex of C API, which will auto unregister all callbacks
|
||||
ob_error *error = nullptr;
|
||||
ob_delete_context(impl_, &error);
|
||||
Error::handle(&error, false);
|
||||
@@ -136,14 +150,45 @@ public:
|
||||
|
||||
/**
|
||||
* @brief Set the device plug-in callback function.
|
||||
*
|
||||
* @deprecated This function is deprecated. Please use registerDeviceChangedCallback() instead.
|
||||
*
|
||||
* @attention This function supports multiple callbacks. Each call to this function adds a new callback to an internal list.
|
||||
*
|
||||
* @param[in] callback The function triggered when the device is plugged and unplugged.
|
||||
*/
|
||||
void setDeviceChangedCallback(DeviceChangedCallback callback) {
|
||||
deviceChangedCallback_ = callback;
|
||||
ob_error *error = nullptr;
|
||||
ob_set_device_changed_callback(impl_, &Context::deviceChangedCallback, this, &error);
|
||||
std::lock_guard<std::mutex> lock(legacyCallbackMtx_);
|
||||
// remove the last callback first
|
||||
unregisterDeviceChangedCallback(legacyCallbackId_);
|
||||
// register the new callback
|
||||
legacyCallbackId_ = registerDeviceChangedCallback(callback);
|
||||
}
|
||||
|
||||
OBCallbackId registerDeviceChangedCallback(DeviceChangedCallback callback) {
|
||||
ob_error *error = nullptr;
|
||||
auto cbCtxHolder = std::unique_ptr<DeviceChangedCallbackContext>(new DeviceChangedCallbackContext({ this, 0, nullptr }));
|
||||
auto id = ob_register_device_changed_callback(impl_, &Context::deviceChangedCallback, (void *)cbCtxHolder.get(), &error);
|
||||
Error::handle(&error);
|
||||
|
||||
cbCtxHolder->callbackId = id;
|
||||
cbCtxHolder->callback = callback;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(callbackMtx_);
|
||||
devChangedCallbacks_[id] = std::move(cbCtxHolder);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
void unregisterDeviceChangedCallback(OBCallbackId id) {
|
||||
ob_error *error = nullptr;
|
||||
ob_unregister_device_changed_callback(impl_, id, &error);
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(callbackMtx_);
|
||||
if(devChangedCallbacks_.count(id)) {
|
||||
devChangedCallbacks_.erase(id);
|
||||
}
|
||||
}
|
||||
Error::handle(&error);
|
||||
}
|
||||
|
||||
@@ -277,11 +322,19 @@ public:
|
||||
|
||||
private:
|
||||
static void deviceChangedCallback(ob_device_list *removedList, ob_device_list *addedList, void *userData) {
|
||||
auto ctx = static_cast<Context *>(userData);
|
||||
if(ctx && ctx->deviceChangedCallback_) {
|
||||
auto cbCtx = static_cast<DeviceChangedCallbackContext *>(userData);
|
||||
if(cbCtx && cbCtx->ctx && cbCtx->callbackId != INVALID_CALLBACK_ID) {
|
||||
DeviceChangedCallback callbackCopy;
|
||||
{
|
||||
// preventing the captured variables from being released.
|
||||
std::unique_lock<std::mutex> lock(cbCtx->ctx->callbackMtx_);
|
||||
if(cbCtx->ctx->devChangedCallbacks_.count(cbCtx->callbackId)) {
|
||||
callbackCopy = cbCtx->callback;
|
||||
}
|
||||
}
|
||||
auto removed = std::make_shared<DeviceList>(removedList);
|
||||
auto added = std::make_shared<DeviceList>(addedList);
|
||||
ctx->deviceChangedCallback_(removed, added);
|
||||
callbackCopy(removed, added);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user