diff --git a/orbbec_camera/SDK/include/libobsensor/h/Context.h b/orbbec_camera/SDK/include/libobsensor/h/Context.h index ad97dc94..df39a41b 100644 --- a/orbbec_camera/SDK/include/libobsensor/h/Context.h +++ b/orbbec_camera/SDK/include/libobsensor/h/Context.h @@ -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). * diff --git a/orbbec_camera/SDK/include/libobsensor/h/ObTypes.h b/orbbec_camera/SDK/include/libobsensor/h/ObTypes.h index 283360b2..dfd34dae 100644 --- a/orbbec_camera/SDK/include/libobsensor/h/ObTypes.h +++ b/orbbec_camera/SDK/include/libobsensor/h/ObTypes.h @@ -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 * diff --git a/orbbec_camera/SDK/include/libobsensor/hpp/Context.hpp b/orbbec_camera/SDK/include/libobsensor/hpp/Context.hpp index 6e84633b..2b922370 100644 --- a/orbbec_camera/SDK/include/libobsensor/hpp/Context.hpp +++ b/orbbec_camera/SDK/include/libobsensor/hpp/Context.hpp @@ -16,6 +16,8 @@ #include #include #include +#include +#include namespace ob { @@ -42,9 +44,20 @@ public: */ typedef std::function 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> 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 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(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 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 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(userData); - if(ctx && ctx->deviceChangedCallback_) { + auto cbCtx = static_cast(userData); + if(cbCtx && cbCtx->ctx && cbCtx->callbackId != INVALID_CALLBACK_ID) { + DeviceChangedCallback callbackCopy; + { + // preventing the captured variables from being released. + std::unique_lock lock(cbCtx->ctx->callbackMtx_); + if(cbCtx->ctx->devChangedCallbacks_.count(cbCtx->callbackId)) { + callbackCopy = cbCtx->callback; + } + } auto removed = std::make_shared(removedList); auto added = std::make_shared(addedList); - ctx->deviceChangedCallback_(removed, added); + callbackCopy(removed, added); } } diff --git a/orbbec_camera/SDK/lib/arm64/OrbbecSDKConfig-release.cmake b/orbbec_camera/SDK/lib/arm64/OrbbecSDKConfig-release.cmake index 25cd1e16..b9bc9249 100644 --- a/orbbec_camera/SDK/lib/arm64/OrbbecSDKConfig-release.cmake +++ b/orbbec_camera/SDK/lib/arm64/OrbbecSDKConfig-release.cmake @@ -8,12 +8,12 @@ set(CMAKE_IMPORT_FILE_VERSION 1) # Import target "ob::OrbbecSDK" for configuration "Release" set_property(TARGET ob::OrbbecSDK APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) set_target_properties(ob::OrbbecSDK PROPERTIES - IMPORTED_LOCATION_RELEASE "${_IMPORT_PREFIX}/lib/libOrbbecSDK.so.2.6.1" + IMPORTED_LOCATION_RELEASE "${_IMPORT_PREFIX}/lib/libOrbbecSDK.so.2.6.2" IMPORTED_SONAME_RELEASE "libOrbbecSDK.so.2" ) list(APPEND _cmake_import_check_targets ob::OrbbecSDK ) -list(APPEND _cmake_import_check_files_for_ob::OrbbecSDK "${_IMPORT_PREFIX}/lib/libOrbbecSDK.so.2.6.1" ) +list(APPEND _cmake_import_check_files_for_ob::OrbbecSDK "${_IMPORT_PREFIX}/lib/libOrbbecSDK.so.2.6.2" ) # Commands beyond this point should not need to know the version. set(CMAKE_IMPORT_FILE_VERSION) diff --git a/orbbec_camera/SDK/lib/arm64/OrbbecSDKVersion.cmake b/orbbec_camera/SDK/lib/arm64/OrbbecSDKVersion.cmake index 25db8760..df97cb61 100644 --- a/orbbec_camera/SDK/lib/arm64/OrbbecSDKVersion.cmake +++ b/orbbec_camera/SDK/lib/arm64/OrbbecSDKVersion.cmake @@ -9,19 +9,19 @@ # The variable CVF_VERSION must be set before calling configure_file(). -set(PACKAGE_VERSION "2.6.1") +set(PACKAGE_VERSION "2.6.2") if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) set(PACKAGE_VERSION_COMPATIBLE FALSE) else() - if("2.6.1" MATCHES "^([0-9]+)\\.") + if("2.6.2" MATCHES "^([0-9]+)\\.") set(CVF_VERSION_MAJOR "${CMAKE_MATCH_1}") if(NOT CVF_VERSION_MAJOR VERSION_EQUAL 0) string(REGEX REPLACE "^0+" "" CVF_VERSION_MAJOR "${CVF_VERSION_MAJOR}") endif() else() - set(CVF_VERSION_MAJOR "2.6.1") + set(CVF_VERSION_MAJOR "2.6.2") endif() if(PACKAGE_FIND_VERSION_RANGE) diff --git a/orbbec_camera/SDK/lib/arm64/extensions/filters/libFilterProcessor.so b/orbbec_camera/SDK/lib/arm64/extensions/filters/libFilterProcessor.so index e80ad6f9..7017f18b 100644 Binary files a/orbbec_camera/SDK/lib/arm64/extensions/filters/libFilterProcessor.so and b/orbbec_camera/SDK/lib/arm64/extensions/filters/libFilterProcessor.so differ diff --git a/orbbec_camera/SDK/lib/arm64/extensions/filters/libob_priv_filter.so b/orbbec_camera/SDK/lib/arm64/extensions/filters/libob_priv_filter.so index 45b9ba6c..6d6850a0 100644 Binary files a/orbbec_camera/SDK/lib/arm64/extensions/filters/libob_priv_filter.so and b/orbbec_camera/SDK/lib/arm64/extensions/filters/libob_priv_filter.so differ diff --git a/orbbec_camera/SDK/lib/arm64/extensions/firmwareupdater/libfirmwareupdater.so b/orbbec_camera/SDK/lib/arm64/extensions/firmwareupdater/libfirmwareupdater.so index cdd35e81..04ab676e 100644 Binary files a/orbbec_camera/SDK/lib/arm64/extensions/firmwareupdater/libfirmwareupdater.so and b/orbbec_camera/SDK/lib/arm64/extensions/firmwareupdater/libfirmwareupdater.so differ diff --git a/orbbec_camera/SDK/lib/arm64/extensions/frameprocessor/libob_frame_processor.so b/orbbec_camera/SDK/lib/arm64/extensions/frameprocessor/libob_frame_processor.so index 1b76c54e..7c121f43 100644 Binary files a/orbbec_camera/SDK/lib/arm64/extensions/frameprocessor/libob_frame_processor.so and b/orbbec_camera/SDK/lib/arm64/extensions/frameprocessor/libob_frame_processor.so differ diff --git a/orbbec_camera/SDK/lib/arm64/libOrbbecSDK.so.2 b/orbbec_camera/SDK/lib/arm64/libOrbbecSDK.so.2 index 8577b513..22383a54 120000 --- a/orbbec_camera/SDK/lib/arm64/libOrbbecSDK.so.2 +++ b/orbbec_camera/SDK/lib/arm64/libOrbbecSDK.so.2 @@ -1 +1 @@ -libOrbbecSDK.so.2.6.1 \ No newline at end of file +libOrbbecSDK.so.2.6.2 \ No newline at end of file diff --git a/orbbec_camera/SDK/lib/arm64/libOrbbecSDK.so.2.6.1 b/orbbec_camera/SDK/lib/arm64/libOrbbecSDK.so.2.6.2 similarity index 66% rename from orbbec_camera/SDK/lib/arm64/libOrbbecSDK.so.2.6.1 rename to orbbec_camera/SDK/lib/arm64/libOrbbecSDK.so.2.6.2 index b6c92878..1bab3613 100644 Binary files a/orbbec_camera/SDK/lib/arm64/libOrbbecSDK.so.2.6.1 and b/orbbec_camera/SDK/lib/arm64/libOrbbecSDK.so.2.6.2 differ diff --git a/orbbec_camera/SDK/lib/x64/OrbbecSDKConfig-release.cmake b/orbbec_camera/SDK/lib/x64/OrbbecSDKConfig-release.cmake index 25cd1e16..b9bc9249 100644 --- a/orbbec_camera/SDK/lib/x64/OrbbecSDKConfig-release.cmake +++ b/orbbec_camera/SDK/lib/x64/OrbbecSDKConfig-release.cmake @@ -8,12 +8,12 @@ set(CMAKE_IMPORT_FILE_VERSION 1) # Import target "ob::OrbbecSDK" for configuration "Release" set_property(TARGET ob::OrbbecSDK APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) set_target_properties(ob::OrbbecSDK PROPERTIES - IMPORTED_LOCATION_RELEASE "${_IMPORT_PREFIX}/lib/libOrbbecSDK.so.2.6.1" + IMPORTED_LOCATION_RELEASE "${_IMPORT_PREFIX}/lib/libOrbbecSDK.so.2.6.2" IMPORTED_SONAME_RELEASE "libOrbbecSDK.so.2" ) list(APPEND _cmake_import_check_targets ob::OrbbecSDK ) -list(APPEND _cmake_import_check_files_for_ob::OrbbecSDK "${_IMPORT_PREFIX}/lib/libOrbbecSDK.so.2.6.1" ) +list(APPEND _cmake_import_check_files_for_ob::OrbbecSDK "${_IMPORT_PREFIX}/lib/libOrbbecSDK.so.2.6.2" ) # Commands beyond this point should not need to know the version. set(CMAKE_IMPORT_FILE_VERSION) diff --git a/orbbec_camera/SDK/lib/x64/OrbbecSDKVersion.cmake b/orbbec_camera/SDK/lib/x64/OrbbecSDKVersion.cmake index 25db8760..df97cb61 100644 --- a/orbbec_camera/SDK/lib/x64/OrbbecSDKVersion.cmake +++ b/orbbec_camera/SDK/lib/x64/OrbbecSDKVersion.cmake @@ -9,19 +9,19 @@ # The variable CVF_VERSION must be set before calling configure_file(). -set(PACKAGE_VERSION "2.6.1") +set(PACKAGE_VERSION "2.6.2") if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) set(PACKAGE_VERSION_COMPATIBLE FALSE) else() - if("2.6.1" MATCHES "^([0-9]+)\\.") + if("2.6.2" MATCHES "^([0-9]+)\\.") set(CVF_VERSION_MAJOR "${CMAKE_MATCH_1}") if(NOT CVF_VERSION_MAJOR VERSION_EQUAL 0) string(REGEX REPLACE "^0+" "" CVF_VERSION_MAJOR "${CVF_VERSION_MAJOR}") endif() else() - set(CVF_VERSION_MAJOR "2.6.1") + set(CVF_VERSION_MAJOR "2.6.2") endif() if(PACKAGE_FIND_VERSION_RANGE) diff --git a/orbbec_camera/SDK/lib/x64/extensions/filters/libFilterProcessor.so b/orbbec_camera/SDK/lib/x64/extensions/filters/libFilterProcessor.so index c8e93a36..a0c632e6 100644 Binary files a/orbbec_camera/SDK/lib/x64/extensions/filters/libFilterProcessor.so and b/orbbec_camera/SDK/lib/x64/extensions/filters/libFilterProcessor.so differ diff --git a/orbbec_camera/SDK/lib/x64/extensions/filters/libob_priv_filter.so b/orbbec_camera/SDK/lib/x64/extensions/filters/libob_priv_filter.so index f7c7656c..9a409463 100644 Binary files a/orbbec_camera/SDK/lib/x64/extensions/filters/libob_priv_filter.so and b/orbbec_camera/SDK/lib/x64/extensions/filters/libob_priv_filter.so differ diff --git a/orbbec_camera/SDK/lib/x64/extensions/firmwareupdater/libfirmwareupdater.so b/orbbec_camera/SDK/lib/x64/extensions/firmwareupdater/libfirmwareupdater.so index 470d5f24..1403f507 100644 Binary files a/orbbec_camera/SDK/lib/x64/extensions/firmwareupdater/libfirmwareupdater.so and b/orbbec_camera/SDK/lib/x64/extensions/firmwareupdater/libfirmwareupdater.so differ diff --git a/orbbec_camera/SDK/lib/x64/extensions/frameprocessor/libob_frame_processor.so b/orbbec_camera/SDK/lib/x64/extensions/frameprocessor/libob_frame_processor.so index 5c82a8b6..97c11920 100644 Binary files a/orbbec_camera/SDK/lib/x64/extensions/frameprocessor/libob_frame_processor.so and b/orbbec_camera/SDK/lib/x64/extensions/frameprocessor/libob_frame_processor.so differ diff --git a/orbbec_camera/SDK/lib/x64/libOrbbecSDK.so.2 b/orbbec_camera/SDK/lib/x64/libOrbbecSDK.so.2 index 8577b513..22383a54 120000 --- a/orbbec_camera/SDK/lib/x64/libOrbbecSDK.so.2 +++ b/orbbec_camera/SDK/lib/x64/libOrbbecSDK.so.2 @@ -1 +1 @@ -libOrbbecSDK.so.2.6.1 \ No newline at end of file +libOrbbecSDK.so.2.6.2 \ No newline at end of file diff --git a/orbbec_camera/SDK/lib/x64/libOrbbecSDK.so.2.6.1 b/orbbec_camera/SDK/lib/x64/libOrbbecSDK.so.2.6.2 similarity index 66% rename from orbbec_camera/SDK/lib/x64/libOrbbecSDK.so.2.6.1 rename to orbbec_camera/SDK/lib/x64/libOrbbecSDK.so.2.6.2 index fa75323e..5fc3c84c 100644 Binary files a/orbbec_camera/SDK/lib/x64/libOrbbecSDK.so.2.6.1 and b/orbbec_camera/SDK/lib/x64/libOrbbecSDK.so.2.6.2 differ diff --git a/orbbec_camera/config/OrbbecSDKConfig_v2.0.xml b/orbbec_camera/config/OrbbecSDKConfig_v2.0.xml index 78c1563f..20b7716a 100644 --- a/orbbec_camera/config/OrbbecSDKConfig_v2.0.xml +++ b/orbbec_camera/config/OrbbecSDKConfig_v2.0.xml @@ -12,7 +12,7 @@ 3 + path will be used: Win/Linux: "./Log"; Android: "/sdcard/orbbec/Log" --> 100