diff --git a/.github/workflows/build-ROS2-package-CI.yaml b/.github/workflows/build-ROS2-package-CI.yaml index 1c492b5fdb..ac9358194f 100644 --- a/.github/workflows/build-ROS2-package-CI.yaml +++ b/.github/workflows/build-ROS2-package-CI.yaml @@ -43,12 +43,12 @@ jobs: steps: - name: setup ROS environment - uses: ros-tooling/setup-ros@44e00e21351330f8dbc9f298bc179cd0c7910477 # v0.7 + uses: ros-tooling/setup-ros@v0.7 with: required-ros-distributions: ${{ matrix.ros_distribution }} - name: build librealsense ROS 2 - uses: ros-tooling/action-ros-ci@0c87ffc035492b66c9afb9159ca9664fb0b513e1 # v0.3 + uses: ros-tooling/action-ros-ci@v0.3 with: target-ros2-distro: ${{ matrix.ros_distribution }} skip-tests: true diff --git a/.github/workflows/buildsCI.yaml b/.github/workflows/buildsCI.yaml index 7bfb3651ce..bc46e5bed6 100644 --- a/.github/workflows/buildsCI.yaml +++ b/.github/workflows/buildsCI.yaml @@ -260,7 +260,7 @@ jobs: #-------------------------------------------------------------------------------- - U20_U24_ST_Py_EX_CfU_LiveTest: # Ubuntu, Static, Python, Examples & Tools, Check for Updates, Legacy Live-Tests + U22_U24_ST_Py_EX_CfU: # Ubuntu, Static, Python, Examples & Tools, Check for Updates runs-on: ${{ matrix.os }} strategy: matrix: @@ -270,7 +270,7 @@ jobs: name: U22 - os: ubuntu-24.04 name: U24 - name: ${{ matrix.name }}_ST_Py_EX_CfU_LiveTest + name: ${{ matrix.name }}_ST_Py_EX_CfU timeout-minutes: 60 steps: - uses: actions/checkout@v4 @@ -291,35 +291,8 @@ jobs: shell: bash run: | cd build - cmake .. -DCMAKE_BUILD_TYPE=${{env.LRS_RUN_CONFIG}} -DBUILD_SHARED_LIBS=false -DBUILD_EXAMPLES=true -DBUILD_TOOLS=true -DCHECK_FOR_UPDATES=true -DBUILD_LEGACY_LIVE_TEST=true -DBUILD_PYTHON_BINDINGS=true -DPYTHON_EXECUTABLE=$(which python3) + cmake .. -DCMAKE_BUILD_TYPE=${{env.LRS_RUN_CONFIG}} -DBUILD_SHARED_LIBS=false -DBUILD_EXAMPLES=true -DBUILD_TOOLS=true -DCHECK_FOR_UPDATES=true -DBUILD_PYTHON_BINDINGS=true -DPYTHON_EXECUTABLE=$(which python3) cmake --build . -- -j4 - - - name: Test - shell: bash - id: test-step - # We set continue-on-error: true as a workaround for not skipping the upload log step on failure, - # The final step will check the return value from the test step and decide if to fail/pass the job - continue-on-error: true - run: | - export LRS_LOG_LEVEL="DEBUG"; - cd build/${{env.LRS_RUN_CONFIG}}/ - ./live-test -d yes -i [software-device] - - - name: Upload RS log artifact - uses: actions/upload-artifact@v4 - with: - name: Log file - ${{ matrix.name }}_ST_Py_EX_CfU_LiveTest - path: build/${{env.LRS_RUN_CONFIG}}/*.log - - - name: Provide correct exit status for job - shell: bash - run: | - if [ ${{steps.test-step.outcome}} = "failure" ];then - echo "Test step failed, please open it to view the reported issue" - exit 1 - else - exit 0 - fi #-------------------------------------------------------------------------------- @@ -469,79 +442,6 @@ jobs: shell: bash run: | python3 unit-tests/run-unit-tests.py --no-color --debug --stdout --not-live --context "dds linux" --tag dds - - - #-------------------------------------------------------------------------------- - U22_U24_SH_RSUSB_LiveTest: # Ubuntu, Shared, Legacy live-tests - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-22.04, ubuntu-24.04] - include: - - os: ubuntu-22.04 - name: U22 - - os: ubuntu-24.04 - name: U24 - name: ${{ matrix.name }}_SH_RSUSB_LiveTest - timeout-minutes: 60 - env: - LRS_BUILD_NODEJS: true - steps: - - uses: actions/checkout@v4 - - - name: Check_API - shell: bash - run: | - cd scripts - ./api_check.sh - cd .. - - - name: Prebuild - shell: bash - run: | - set -x - - mkdir build - sudo apt-get update; - sudo apt-get install -qq build-essential xorg-dev libgl1-mesa-dev libglu1-mesa-dev libglew-dev libglm-dev; - sudo apt-get install -qq libusb-1.0-0-dev; - sudo apt-get install -qq libgtk-3-dev; - sudo apt-get install libglfw3-dev libglfw3; - - - name: Build - shell: bash - run: | - cd build - cmake .. -DCMAKE_BUILD_TYPE=${{env.LRS_BUILD_CONFIG}} -DBUILD_SHARED_LIBS=true -DBUILD_EXAMPLES=false -DBUILD_TOOLS=false -DCHECK_FOR_UPDATES=false -DFORCE_RSUSB_BACKEND=true -DBUILD_LEGACY_LIVE_TEST=true - cmake --build . -- -j4 - - - name: Test - shell: bash - id: test-step - # We set continue-on-error: true as a workaround for not skipping the upload log step on failure, - # The final step will check the return value from the test step and decide if to fail/pass the job - continue-on-error: true - run: | - export LRS_LOG_LEVEL="DEBUG"; - cd build/${{env.LRS_BUILD_CONFIG}}/ - ./live-test -d yes -i [software-device] - - - name: Upload RS log artifact - uses: actions/upload-artifact@v4 - with: - name: Log file - ${{ matrix.name }}_SH_RSUSB_LiveTest - path: build/${{env.LRS_BUILD_CONFIG}}/*.log - - - name: Provide correct exit status for job - shell: bash - run: | - if [ ${{steps.test-step.outcome}} = "failure" ];then - echo "Test step failed, please open it to view the reported issue" - exit 1 - else - exit 0 - fi - #-------------------------------------------------------------------------------- Mac_cpp: diff --git a/.github/workflows/static_analysis.yaml b/.github/workflows/static_analysis.yaml index 95930b7a3c..fb299cd34a 100644 --- a/.github/workflows/static_analysis.yaml +++ b/.github/workflows/static_analysis.yaml @@ -14,7 +14,7 @@ jobs: timeout-minutes: 30 runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 + - uses: actions/checkout@v3 - name: Install shell: bash @@ -64,7 +64,7 @@ jobs: && echo "No diffs found in cppcheck_run.parsed.log" - name: Upload logs - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3 + uses: actions/upload-artifact@v3 with: name: cppcheck_log path: | @@ -105,7 +105,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 + uses: actions/checkout@v3 - name: "Install Dependencies" run: | diff --git a/CMake/android_config.cmake b/CMake/android_config.cmake index 3cc1d1f88e..203003eb6a 100644 --- a/CMake/android_config.cmake +++ b/CMake/android_config.cmake @@ -6,7 +6,6 @@ macro(os_set_flags) unset(UNIX) unset(APPLE) set(BUILD_UNIT_TESTS OFF) - set(BUILD_LEGACY_LIVE_TEST OFF) set(BUILD_EXAMPLES OFF) set(BUILD_TOOLS OFF) set(BUILD_WITH_OPENMP OFF) diff --git a/CMake/lrs_options.cmake b/CMake/lrs_options.cmake index be2e2febe5..cc2b21de13 100644 --- a/CMake/lrs_options.cmake +++ b/CMake/lrs_options.cmake @@ -8,7 +8,6 @@ option(HWM_OVER_XU "Send HWM commands over UVC XU control" ON) option(COM_MULTITHREADED "Set OFF to initialize COM library with COINIT_APARTMENTTHREADED (Windows only)" ON) option(BUILD_SHARED_LIBS "Build shared library" ON) option(BUILD_UNIT_TESTS "Build LibCI unit tests. If enabled, additional test data may be downloaded" OFF) -option(BUILD_LEGACY_LIVE_TEST "Build the live-test.exe test used in Travis. If enabled, additional test data may be downloaded" OFF) option(BUILD_EXAMPLES "Build examples (not including graphical examples -- see BUILD_GRAPHICAL_EXAMPLES)" ON) option(BUILD_GRAPHICAL_EXAMPLES "Build graphical examples (Viewer & DQT) -- Implies BUILD_GLSL_EXTENSIONS" ON) option(BUILD_CV_EXAMPLES "Build OpenCV examples" OFF) diff --git a/CMake/opengl_config.cmake b/CMake/opengl_config.cmake index 8c7e9fcf90..43ec4bac16 100644 --- a/CMake/opengl_config.cmake +++ b/CMake/opengl_config.cmake @@ -4,4 +4,4 @@ if (POLICY CMP0072) endif() find_package(OpenGL REQUIRED) -set(DEPENDENCIES realsense2 glfw ${OPENGL_LIBRARIES}) +list( APPEND DEPENDENCIES glfw ${OPENGL_LIBRARIES} ) diff --git a/CMake/unix_config.cmake b/CMake/unix_config.cmake index d611d7fe61..711434c2ef 100644 --- a/CMake/unix_config.cmake +++ b/CMake/unix_config.cmake @@ -28,6 +28,9 @@ macro(os_set_flags) elseif(${MACHINE} MATCHES "powerpc64(le)?-linux-gnu") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftree-vectorize") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftree-vectorize") + elseif(${MACHINE} MATCHES "riscv64-*") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mstrict-align -ftree-vectorize") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mstrict-align -ftree-vectorize") else() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mssse3") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mssse3") diff --git a/CMakeLists.txt b/CMakeLists.txt index 9210570264..467c844b09 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,7 +101,7 @@ elseif(BUILD_TOOLS) add_subdirectory(tools) endif() -if(BUILD_UNIT_TESTS OR BUILD_LEGACY_LIVE_TEST) +if(BUILD_UNIT_TESTS) include( CMake/external_catch2.cmake ) add_subdirectory(unit-tests) endif() diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 4178d7c5f2..b46dd01701 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -3,6 +3,7 @@ set(COMMON_SRC "${CMAKE_CURRENT_LIST_DIR}/animated.h" + "${CMAKE_CURRENT_LIST_DIR}/cli.h" "${CMAKE_CURRENT_LIST_DIR}/float2.h" "${CMAKE_CURRENT_LIST_DIR}/float3.h" "${CMAKE_CURRENT_LIST_DIR}/float4.h" diff --git a/common/cli.h b/common/cli.h new file mode 100644 index 0000000000..488adeb102 --- /dev/null +++ b/common/cli.h @@ -0,0 +1,260 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2024 Intel Corporation. All Rights Reserved. +#pragma once + +// Command-Line Interface for our tools/examples/etc. +// Requires that 'tclap' be added to project dependencies! + +#include +#include + +#include + +#include +#include + + +namespace rs2 { + + +// Base version of CLI without any context functionality +class cli_no_context : public TCLAP::CmdLine +{ + using super = TCLAP::CmdLine; + + rs2_log_severity _default_log_level; + +public: + cli_no_context( std::string const & tool_name, std::string const & version_string ) + : super( tool_name, // The message to be used in the usage output + ' ', // Separates the argument flag/name from the value; leave default + version_string ) + , debug_arg( "debug", "Turn on librealsense debug logs" ) + , _default_log_level( RS2_LOG_SEVERITY_ERROR ) // By default, log ERROR messages only + { +#ifdef BUILD_EASYLOGGINGPP + add( debug_arg ); +#endif + // There isn't always a console... so if we need to show an error/usage, we need to enable it: + setOutput( &_our_cmdline_output ); + } + cli_no_context( std::string const & tool_name ) + : cli_no_context( tool_name, RS2_API_FULL_VERSION_STR ) {} + +public: + enum _required { required }; + + class flag : public TCLAP::SwitchArg + { + using super = TCLAP::SwitchArg; + + // Override so we push to the back and reverse ordering isn't needed! + void addToList( std::list< TCLAP::Arg * > & argList ) const override + { argList.push_back( const_cast< flag * >( this ) ); } + + public: + flag( std::string const & long_name, std::string const & description ) + : flag( long_name, false, description ) {} + flag( char short_name, std::string const & long_name, std::string const & description ) + : flag( short_name, long_name, false, description ) {} + // Avoid treating "string" as a boolean + flag( std::string const &, char const *, std::string const & ) = delete; + flag( std::string const & long_name, bool value, std::string const & description ) + : super( {}, long_name, description, value ) {} + flag( char short_name, std::string const & long_name, bool value, std::string const & description ) + : super( std::string( 1, short_name ), long_name, description, value ) {} + }; + + template< class T > + class value : public TCLAP::ValueArg< T > + { + using super = TCLAP::ValueArg< T >; + + // Override so we push to the back and reverse ordering isn't needed! + void addToList( std::list< TCLAP::Arg * > & argList ) const override + { argList.push_back( const_cast< value * >( this ) ); } + + public: + value( std::string const & long_name, std::string const & type_description, T value, std::string const & description ) + : super( {}, long_name, description, false /* not required */, value, type_description ) {} + value( std::string const & long_name, std::string const & type_description, T value, std::string const & description, cli_no_context::_required ) + : super( {}, long_name, description, true /* required */, value, type_description ) {} + value( char short_name, std::string const & long_name, std::string const & type_description, T value, std::string const & description ) + : super( std::string( 1, short_name ), long_name, description, false /* not required */, value, type_description ) {} + value( char short_name, std::string const & long_name, std::string const & type_description, T value, std::string const & description, cli_no_context::_required ) + : super( std::string( 1, short_name ), long_name, description, true /* required */, value, type_description ) {} + }; + + // One-line operation: + // auto settings = cli( "description" ).arg( arg1, arg2 ).process( argc, argv ); + // add() is still available: + // cli cmd( "description" ); + // cmd.add( arg1 ); +public: + template< typename... Rest > + cli_no_context & arg( TCLAP::Arg & a ) + { + super::add( a ); + return *this; + } + template< typename... Rest > + cli_no_context & arg( TCLAP::Arg & a, Rest... rest ) + { + super::add( a ); + return arg( std::forward< Rest >( rest )... ); + } + + cli_no_context & default_log_level( rs2_log_severity severity ) + { + _default_log_level = severity; + return *this; + } + + // Replace parse() with our own process() +protected: + using super::parse; // don't let user call parse() - enforce using process() + + virtual void apply() + { +#ifdef BUILD_EASYLOGGINGPP + if( debug_arg.getValue() ) + rsutils::os::ensure_console(); + if( rsutils::os::has_console() ) + rs2_log_to_console( debug_arg.getValue() ? RS2_LOG_SEVERITY_DEBUG : _default_log_level, nullptr ); +#endif + } + + virtual rsutils::json build_cli_settings() + { + return rsutils::json::object(); + } + +public: + rsutils::json process( int argc, const char * const * argv ) + { + parse( argc, argv ); + apply(); + return build_cli_settings(); + } + +protected: + // Override basic output methods: + // If help is needed, for example, usage() will get called but we have not even ensured we have a console yet! + class cmdline_output : public TCLAP::StdOutput + { + using super = TCLAP::StdOutput; + + public: + void usage( TCLAP::CmdLineInterface & c ) override + { + rsutils::os::ensure_console(); + super::usage( c ); + } + + void version( TCLAP::CmdLineInterface & c ) override + { + rsutils::os::ensure_console(); + super::version( c ); + } + + void failure( TCLAP::CmdLineInterface & c, TCLAP::ArgException & e ) override + { + rsutils::os::ensure_console(); + super::failure( c, e ); + } + }; + + cmdline_output _our_cmdline_output; + + // Public args that can be retrieved by the user +public: + flag debug_arg; +}; + + +// CLI with additional context-controlling behavior: +// (none at this time) +// +class cli_no_dds : public cli_no_context +{ + using super = cli_no_context; + +public: + using super::super; // inherit same ctors +}; + + +// CLI with additional DDS-controlling behavior: +// --eth +// --eth-only +// --no-eth +// --domain-id <0-232> +// +class cli : public cli_no_dds +{ + using super = cli_no_dds; + +public: + cli( std::string const & tool_name, std::string const & version_string ) + : super( tool_name, version_string ) + , eth_arg( "eth", "Detect DDS devices, even if disabled in the configuration" ) + , eth_only_arg( "eth-only", "Use ONLY DDS devices; do not look for USB/MIPI devices" ) + , no_eth_arg( "no-eth", "Do not detect DDS devices, even if enabled in the configuration" ) + , domain_id_arg( "domain-id", "0-232", 0, "Domain ID to use with DDS devices" ) + { +#ifdef BUILD_WITH_DDS + add( eth_arg ); + add( eth_only_arg ); + add( no_eth_arg ); + add( domain_id_arg ); +#endif + } + cli( std::string const & tool_name ) + : cli( tool_name, RS2_API_FULL_VERSION_STR ) {} + +public: + rsutils::json build_cli_settings() override + { + auto settings = super::build_cli_settings(); + +#ifdef BUILD_WITH_DDS + if( eth_arg.isSet() + eth_only_arg.isSet() + no_eth_arg.isSet() > 1 ) + throw TCLAP::CmdLineParseException( "--eth, --eth-only, and --no-eth are mutually exclusive", "FATAL" ); + if( domain_id_arg.isSet() + no_eth_arg.isSet() > 1 ) + throw TCLAP::CmdLineParseException( "--domain-id and --no-eth are mutually exclusive", "FATAL" ); + + if( eth_arg.isSet() ) + { + settings["dds"]["enabled"] = true; + } + else if( eth_only_arg.isSet() ) + { + settings["device-mask"] = RS2_PRODUCT_LINE_SW_ONLY | RS2_PRODUCT_LINE_ANY; + settings["dds"]["enabled"] = true; + } + else if( no_eth_arg.isSet() ) + { + settings["dds"]["enabled"] = false; + } + + if( domain_id_arg.isSet() ) + { + if( domain_id_arg.getValue() < 0 || domain_id_arg.getValue() > 232 ) + throw TCLAP::ArgParseException( "expecting [0, 232]", domain_id_arg.toString() ); + settings["dds"]["domain"] = domain_id_arg.getValue(); + } +#endif + + return settings; + } + + // Public args that can be retrieved by the user +public: + flag eth_arg; + flag eth_only_arg; + flag no_eth_arg; + value< int > domain_id_arg; +}; + + +} // namespace rs2 diff --git a/common/d500-on-chip-calib.cpp b/common/d500-on-chip-calib.cpp index 494702a10a..9fe4994951 100644 --- a/common/d500-on-chip-calib.cpp +++ b/common/d500-on-chip-calib.cpp @@ -82,12 +82,17 @@ namespace rs2 void d500_on_chip_calib_manager::prepare_for_calibration() { // set depth preset as default preset, turn projector ON and depth AE ON - if (_sub->s->is ()) + if (_sub->s->supports(RS2_CAMERA_INFO_NAME) && + (std::string(_sub->s->get_info(RS2_CAMERA_INFO_NAME)) == "Stereo Module")) { auto depth_sensor = _sub->s->as (); - // set depth preset as default preset - set_option_if_needed(depth_sensor, RS2_OPTION_VISUAL_PRESET, 1); + // disabling the depth visual preset change for D555 - not needed + if (get_device_pid() != "0B56" && get_device_pid() != "DDS") + { + // set depth preset as default preset + set_option_if_needed(depth_sensor, RS2_OPTION_VISUAL_PRESET, 1); + } // turn projector ON set_option_if_needed(depth_sensor, RS2_OPTION_EMITTER_ENABLED, 1); @@ -289,13 +294,13 @@ namespace rs2 void d500_autocalib_notification_model::update_ui_after_abort_called(ux_window& win, int x, int y) { ImGui::Text("%s", "Calibration Aborting"); - ImGui::SetCursorScreenPos({ float(x + 10), float(y + 50) }); + ImGui::SetCursorScreenPos({ float(x + 10), float(y + 40) }); ImGui::PushFont(win.get_large_font()); std::string txt = rsutils::string::from() << textual_icons::stop; ImGui::Text("%s", txt.c_str()); ImGui::PopFont(); - ImGui::SetCursorScreenPos({ float(x + 40), float(y + 50) }); + ImGui::SetCursorScreenPos({ float(x + 40), float(y + 40) }); if (_has_abort_succeeded) { ImGui::Text("%s", "Camera Calibration Aborted Successfully"); diff --git a/common/device-model.cpp b/common/device-model.cpp index 4b0419feee..2ec5e9ec21 100644 --- a/common/device-model.cpp +++ b/common/device-model.cpp @@ -266,8 +266,7 @@ namespace rs2 auto dev_name = get_device_name(dev); - // TODO - D421. Don't suggest to update FW as it doesn't support D421. Revert after 5.17 release with supporting FW - if( ( dev.is() || is_upgradeable( fw, recommended_fw_ver) ) && pid != "1155" ) // 0x1155 is D421 PID + if( ( dev.is() || is_upgradeable( fw, recommended_fw_ver) ) ) { std::stringstream msg; @@ -951,7 +950,7 @@ namespace rs2 else return; // Aborted by the user - auto manager = std::make_shared(viewer.not_model, *this, dev, viewer.ctx, data, false); + auto manager = std::make_shared(viewer.not_model, *this, dev, viewer.ctx, std::move( data ), false); auto n = std::make_shared( "Manual Update requested", manager, true); @@ -1000,7 +999,7 @@ namespace rs2 else return; // Aborted by the user } - auto manager = std::make_shared(viewer.not_model, *this, dev, viewer.ctx, data, true); + auto manager = std::make_shared(viewer.not_model, *this, dev, viewer.ctx, std::move( data ), true); auto n = std::make_shared( "Manual Update requested", manager, true); @@ -2620,11 +2619,11 @@ namespace rs2 std::vector so_ordered; - for (auto const & id_model : supported_options) + for( auto const id_model : sub->supported_options ) { - auto it = find( color_options.begin(), color_options.end(), id_model.first ); + auto it = find( color_options.begin(), color_options.end(), id_model ); if (it == color_options.end()) - so_ordered.push_back( id_model.first ); + so_ordered.push_back( id_model ); } std::for_each( color_options.begin(), @@ -3416,8 +3415,15 @@ namespace rs2 ImGui::SetTooltip("%s", tooltip.c_str()); } - bool is_d555 = dev.supports( RS2_CAMERA_INFO_PRODUCT_ID ) ? - std::string( dev.get_info( RS2_CAMERA_INFO_PRODUCT_ID ) ) == "0B56" : false; + bool is_d555 = false; + + if (dev.supports(RS2_CAMERA_INFO_PRODUCT_ID)) + { + auto pid_str = std::string(dev.get_info(RS2_CAMERA_INFO_PRODUCT_ID)); + if (pid_str == "0B56" || pid_str == "DDS") + is_d555 = true; + } + if( is_d555 && ImGui::Selectable( "Focal Length Calibration" ) ) { try diff --git a/common/fw-update-helper.cpp b/common/fw-update-helper.cpp index badc98f457..68cf8a1d2e 100644 --- a/common/fw-update-helper.cpp +++ b/common/fw-update-helper.cpp @@ -179,7 +179,8 @@ namespace rs2 "and restart the realsense-viewer"); } _done = true; - // need to find a way to update the fw version field in the viewer + // Restart the device to reconstruct with the new version information + _dev.hardware_reset(); } void firmware_update_manager::process_flow( diff --git a/common/notifications.cpp b/common/notifications.cpp index c783fad1b7..33e40e8ae6 100644 --- a/common/notifications.cpp +++ b/common/notifications.cpp @@ -737,6 +737,12 @@ namespace rs2 _log += line + "\n"; } + const std::string process_manager::get_log() const + { + std::lock_guard< std::mutex > lock( _log_lock ); + return _log; + } + void process_manager::reset() { _progress = 0; diff --git a/common/notifications.h b/common/notifications.h index 71787a17f1..abb15b32ff 100644 --- a/common/notifications.h +++ b/common/notifications.h @@ -122,7 +122,7 @@ namespace rs2 bool done() const { return _done; } bool started() const { return _started; } bool failed() const { return _failed; } - const std::string& get_log() const { return _log; } + const std::string get_log() const; void reset(); void check_error(std::string& error) { if (_failed) error = _last_error; } @@ -141,7 +141,7 @@ namespace rs2 bool _failed = false; float _progress = 0; - std::mutex _log_lock; + mutable std::mutex _log_lock; std::string _last_error; std::string _process_name; }; diff --git a/common/on-chip-calib.cpp b/common/on-chip-calib.cpp index d49ca4a047..c0c7d602c2 100644 --- a/common/on-chip-calib.cpp +++ b/common/on-chip-calib.cpp @@ -132,6 +132,9 @@ namespace rs2 if( it != _sub->options_metadata.end() ) // Option supported { it->second.set_option( RS2_OPTION_EMITTER_ENABLED, value, ignored_error_message ); + if( it->second.value_as_float() != value ) + throw std::runtime_error( rsutils::string::from() + << "Failed to set laser " << ( value == off_value ? "off" : "on" ) ); } } @@ -143,6 +146,9 @@ namespace rs2 if( it != _sub->options_metadata.end() ) // Option supported { it->second.set_option( RS2_OPTION_THERMAL_COMPENSATION, value, ignored_error_message ); + if( it->second.value_as_float() != value ) + throw std::runtime_error( rsutils::string::from() + << "Failed to set laser " << ( value == off_value ? "off" : "on" ) ); } } diff --git a/common/option-model.cpp b/common/option-model.cpp index f0eb431b2a..1ccac91525 100644 --- a/common/option-model.cpp +++ b/common/option-model.cpp @@ -442,7 +442,7 @@ bool option_model::draw_slider( notifications_model & model, char buff[TEXT_BUFF_SIZE]; memset( buff, 0, TEXT_BUFF_SIZE ); - strcpy( buff, buff_str.c_str() ); + strncpy( buff, buff_str.c_str(), TEXT_BUFF_SIZE - 1 ); if( ImGui::InputText( id.c_str(), buff, @@ -453,7 +453,7 @@ bool option_model::draw_slider( notifications_model & model, { buff_str = convert_float_str( std::string( buff ), 0.01f ); memset( buff, 0, TEXT_BUFF_SIZE ); - strcpy( buff, buff_str.c_str() ); + strncpy( buff, buff_str.c_str(), TEXT_BUFF_SIZE - 1 ); } float new_value; if( ! rsutils::string::string_to_value< float >( buff, new_value ) ) @@ -486,7 +486,7 @@ bool option_model::draw_slider( notifications_model & model, { buff_str = convert_float_str( buff_str, 0.01f ); memset( buff, 0, TEXT_BUFF_SIZE ); - strcpy( buff, buff_str.c_str() ); + strncpy( buff, buff_str.c_str(), TEXT_BUFF_SIZE - 1 ); } edit_value = buff; } diff --git a/common/realsense-ui-advanced-mode.h b/common/realsense-ui-advanced-mode.h index 3ce4830442..1ede7cda45 100644 --- a/common/realsense-ui-advanced-mode.h +++ b/common/realsense-ui-advanced-mode.h @@ -74,7 +74,7 @@ inline void slider_int(std::string& error_message, const char* id, T* val, S T:: { char buff[TEXT_BUFF_SIZE]; memset(buff, 0, TEXT_BUFF_SIZE); - strcpy(buff, val_ptr->c_str()); + strncpy(buff, val_ptr->c_str(), TEXT_BUFF_SIZE - 1); if (ImGui::InputText(slider_id.c_str(), buff, TEXT_BUFF_SIZE, ImGuiInputTextFlags_EnterReturnsTrue)) { @@ -139,7 +139,7 @@ inline void slider_float(std::string& error_message, const char* id, T* val, S T { char buff[TEXT_BUFF_SIZE]; memset(buff, 0, TEXT_BUFF_SIZE); - strcpy(buff, val_ptr->c_str()); + strncpy(buff, val_ptr->c_str(), TEXT_BUFF_SIZE - 1); if (ImGui::InputText(slider_id.c_str(), buff, TEXT_BUFF_SIZE, ImGuiInputTextFlags_EnterReturnsTrue)) { diff --git a/common/rs-config.cpp b/common/rs-config.cpp index 81443816c2..c6a0077040 100644 --- a/common/rs-config.cpp +++ b/common/rs-config.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include using json = rsutils::json; @@ -69,7 +70,7 @@ void config_file::save(const char* filename) try { std::ofstream out(filename); - out << _j.dump( 2 ); + out << std::setw( 2 ) << _j; out.close(); } catch (...) @@ -89,9 +90,9 @@ config_file::config_file( std::string const & filename ) { try { - std::ifstream t(_filename); - if (!t.good()) return; - _j = json::parse( t ); + auto j = rsutils::json_config::load_from_file( filename ); + if( j.exists() ) + _j = std::move( j ); } catch(...) { diff --git a/common/viewer.cpp b/common/viewer.cpp index 0754f8dd33..e515c7234e 100644 --- a/common/viewer.cpp +++ b/common/viewer.cpp @@ -176,8 +176,7 @@ namespace rs2 ImGui::PopStyleColor(2); // button color auto apply = [&]() { - config_file::instance() = temp_cfg; - update_configuration(); + update_configuration(&temp_cfg); }; ImGui::PushStyleColor(ImGuiCol_Button, button_color); @@ -794,8 +793,10 @@ namespace rs2 _hidden_options.emplace(RS2_OPTION_REGION_OF_INTEREST); } - void viewer_model::update_configuration() + void viewer_model::update_configuration(config_file* new_cfg) { + if (new_cfg) + config_file::instance() = *new_cfg; rs2_error* e = nullptr; auto version = rs2_get_api_version(&e); if (e) rs2::error::handle(e); @@ -1680,42 +1681,45 @@ namespace rs2 { case RS2_STREAM_GYRO: /* Fall Through */ case RS2_STREAM_ACCEL: - { - auto motion = streams[stream].texture->get_last_frame().as(); - if (motion.get()) + if( rs2::frame frame = streams[stream].texture->get_last_frame() ) + { + auto motion = frame.as< motion_frame >(); + if( motion.get() ) + { + auto axis = motion.get_motion_data(); + stream_mv.show_stream_imu( font1, + stream_rect, + axis, + mouse, + stream_type == RS2_STREAM_GYRO ? "Radians/Sec" : "Meter/Sec^2" ); + } + } + break; + + case RS2_STREAM_MOTION: + if( rs2::frame frame = streams[stream].texture->get_last_frame() ) { - auto axis = motion.get_motion_data(); + auto & motion = *reinterpret_cast< const rs2_combined_motion * >( frame.get_data() ); + auto height = stream_mv.show_stream_imu( font1, + stream_rect, + { (float)motion.linear_acceleration.x, + (float)motion.linear_acceleration.y, + (float)motion.linear_acceleration.z }, + mouse, + "Meter/Sec^2", + "Linear Acceletion" ); stream_mv.show_stream_imu( font1, stream_rect, - axis, + { (float)motion.angular_velocity.x, + (float)motion.angular_velocity.y, + (float)motion.angular_velocity.z }, mouse, - stream_type == RS2_STREAM_GYRO ? "Radians/Sec" : "Meter/Sec^2" ); + "Radians/Sec", + "Angular Velocity", + height + 9 ); } break; - } - case RS2_STREAM_MOTION: - { - auto & motion = *reinterpret_cast< const rs2_combined_motion * >( - streams[stream].texture->get_last_frame().get_data() ); - auto height = stream_mv.show_stream_imu( font1, - stream_rect, - { (float)motion.linear_acceleration.x, - (float)motion.linear_acceleration.y, - (float)motion.linear_acceleration.z }, - mouse, - "Meter/Sec^2", - "Linear Acceletion" ); - stream_mv.show_stream_imu( font1, - stream_rect, - { (float)motion.angular_velocity.x, - (float)motion.angular_velocity.y, - (float)motion.angular_velocity.z }, - mouse, - "Radians/Sec", - "Angular Velocity", - height + 9 ); - break; - } + case RS2_STREAM_POSE: { if (streams[stream].show_stream_details) @@ -2879,13 +2883,12 @@ namespace rs2 } auto apply = [&](){ - config_file::instance() = temp_cfg; window.on_reload_complete = [this](){ _skybox.reset(); }; if (reload_required) window.reload(); else if (refresh_required) window.refresh(); - update_configuration(); + update_configuration(&temp_cfg); if (refresh_updates) for (auto&& dev : devices) diff --git a/common/viewer.h b/common/viewer.h index e0e7b28b93..a16ffdf0a1 100644 --- a/common/viewer.h +++ b/common/viewer.h @@ -64,7 +64,7 @@ namespace rs2 public: void reset_camera(float3 pos = { 0.0f, 0.0f, -1.0f }); - void update_configuration(); + void update_configuration(config_file* new_cfg = nullptr); const float panel_width = 340.f; const float panel_y = 50.f; diff --git a/examples/C/color/rs-color.c b/examples/C/color/rs-color.c index 4ed963a938..4b696b5a49 100644 --- a/examples/C/color/rs-color.c +++ b/examples/C/color/rs-color.c @@ -1,5 +1,5 @@ // License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2017 Intel Corporation. All Rights Reserved. +// Copyright(c) 2017-24 Intel Corporation. All Rights Reserved. /* Include the librealsense C header files */ #include @@ -15,12 +15,12 @@ //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // These parameters are reconfigurable // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -#define STREAM RS2_STREAM_COLOR // rs2_stream is a types of data provided by RealSense device // -#define FORMAT RS2_FORMAT_RGB8 // rs2_format identifies how binary data is encoded within a frame // -#define WIDTH 640 // Defines the number of columns for each frame // -#define HEIGHT 480 // Defines the number of lines for each frame // -#define FPS 30 // Defines the rate of frames per second // -#define STREAM_INDEX 0 // Defines the stream index, used for multiple streams of the same type // +#define STREAM RS2_STREAM_COLOR // Type of data provided by RealSense device // +#define FORMAT RS2_FORMAT_ANY // How binary data is encoded within a frame (ANY) // +#define WIDTH 0 // Number of columns for each frame (ANY) // +#define HEIGHT 0 // Number of lines for each frame (ANY) // +#define FPS 0 // Rate of frames per second (ANY) // +#define STREAM_INDEX -1 // Used for multiple streams of the same type (ANY) // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -74,7 +74,7 @@ int main() exit(EXIT_FAILURE); } - while (1) + while (1) // Until user presses Ctrl+C { // This call waits until a new composite_frame is available // composite_frame holds a set of frames. It is used to prevent frame drops @@ -125,18 +125,4 @@ int main() rs2_release_frame(frames); } - - // Stop the pipeline streaming - rs2_pipeline_stop(pipeline, &e); - check_error(e); - - // Release resources - rs2_delete_pipeline_profile(pipeline_profile); - rs2_delete_config(config); - rs2_delete_pipeline(pipeline); - rs2_delete_device(dev); - rs2_delete_device_list(device_list); - rs2_delete_context(ctx); - - return EXIT_SUCCESS; } diff --git a/examples/C/depth/rs-depth.c b/examples/C/depth/rs-depth.c index f21e4ebac5..d191e12d2e 100644 --- a/examples/C/depth/rs-depth.c +++ b/examples/C/depth/rs-depth.c @@ -1,5 +1,5 @@ // License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2017 Intel Corporation. All Rights Reserved. +// Copyright(c) 2017-24 Intel Corporation. All Rights Reserved. /* Include the librealsense C header files */ #include @@ -159,7 +159,7 @@ int main() char* buffer = calloc(display_size, sizeof(char)); char* out = NULL; - while (1) + while (1) // Until user presses Ctrl+C { // This call waits until a new composite_frame is available // composite_frame holds a set of frames. It is used to prevent frame drops @@ -227,21 +227,4 @@ int main() rs2_release_frame(frames); } - - // Stop the pipeline streaming - rs2_pipeline_stop(pipeline, &e); - check_error(e); - - // Release resources - free(buffer); - rs2_delete_pipeline_profile(pipeline_profile); - rs2_delete_stream_profiles_list(stream_profile_list); - rs2_delete_stream_profile(stream_profile); - rs2_delete_config(config); - rs2_delete_pipeline(pipeline); - rs2_delete_device(dev); - rs2_delete_device_list(device_list); - rs2_delete_context(ctx); - - return EXIT_SUCCESS; } diff --git a/examples/C/distance/rs-distance.c b/examples/C/distance/rs-distance.c index 8bb0e73c2b..142ddde0d1 100644 --- a/examples/C/distance/rs-distance.c +++ b/examples/C/distance/rs-distance.c @@ -1,5 +1,5 @@ // License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2017 Intel Corporation. All Rights Reserved. +// Copyright(c) 2017-24 Intel Corporation. All Rights Reserved. /* Include the librealsense C header files */ #include @@ -75,7 +75,7 @@ int main() exit(EXIT_FAILURE); } - while (1) + while (1) // Until user presses Ctrl+C { // This call waits until a new composite_frame is available // composite_frame holds a set of frames. It is used to prevent frame drops @@ -117,18 +117,4 @@ int main() rs2_release_frame(frames); } - - // Stop the pipeline streaming - rs2_pipeline_stop(pipeline, &e); - check_error(e); - - // Release resources - rs2_delete_pipeline_profile(pipeline_profile); - rs2_delete_config(config); - rs2_delete_pipeline(pipeline); - rs2_delete_device(dev); - rs2_delete_device_list(device_list); - rs2_delete_context(ctx); - - return EXIT_SUCCESS; } diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 083e15493c..652656e589 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -7,17 +7,19 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS 1) # View the makefile commands during build #set(CMAKE_VERBOSE_MAKEFILE on) +set( DEPENDENCIES ${LRS_TARGET} ) if(BUILD_GRAPHICAL_EXAMPLES) include(${CMAKE_SOURCE_DIR}/CMake/opengl_config.cmake) else() if(ANDROID_NDK_TOOLCHAIN_INCLUDED) find_library(log-lib log) - set(DEPENDENCIES realsense2 log) - else() - set(DEPENDENCIES realsense2) + list( APPEND DEPENDENCIES log ) endif() endif() +# We need tclap for command-line interface +list(APPEND DEPENDENCIES tclap) + add_subdirectory(hello-realsense) add_subdirectory(software-device) add_subdirectory(capture) diff --git a/examples/align-advanced/CMakeLists.txt b/examples/align-advanced/CMakeLists.txt index d8e5639519..7e17b5e6ab 100644 --- a/examples/align-advanced/CMakeLists.txt +++ b/examples/align-advanced/CMakeLists.txt @@ -2,13 +2,18 @@ # Copyright(c) 2019-2024 Intel Corporation. All Rights Reserved. cmake_minimum_required(VERSION 3.8) -project(RealsenseExamplesAlignAdvanced) - -if(BUILD_GRAPHICAL_EXAMPLES) - add_executable(rs-align-advanced rs-align-advanced.cpp ../../third-party/imgui/imgui.cpp ../../third-party/imgui/imgui_draw.cpp ../../third-party/imgui/imgui_impl_glfw.cpp) - set_property(TARGET rs-align-advanced PROPERTY CXX_STANDARD 11) - target_link_libraries(rs-align-advanced ${DEPENDENCIES}) - include_directories(../../common ../../third-party/imgui ../../examples) - set_target_properties (rs-align-advanced PROPERTIES FOLDER Examples) - install(TARGETS rs-align-advanced RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +project( rs-align-advanced ) + +if( BUILD_GRAPHICAL_EXAMPLES ) + +add_executable( ${PROJECT_NAME} rs-align-advanced.cpp + ../../third-party/imgui/imgui.cpp ../../third-party/imgui/imgui_draw.cpp ../../third-party/imgui/imgui_impl_glfw.cpp + ) +set_property( TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11 ) +target_link_libraries( ${PROJECT_NAME} ${DEPENDENCIES} ) +include_directories( ../../third-party/imgui ../../examples ) +set_target_properties( ${PROJECT_NAME} PROPERTIES FOLDER Examples ) +using_easyloggingpp( ${PROJECT_NAME} SHARED ) +install( TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) + endif() diff --git a/examples/align-advanced/rs-align-advanced.cpp b/examples/align-advanced/rs-align-advanced.cpp index ee09444474..c8168287f5 100644 --- a/examples/align-advanced/rs-align-advanced.cpp +++ b/examples/align-advanced/rs-align-advanced.cpp @@ -3,6 +3,7 @@ #include #include "example-imgui.hpp" +#include #include #include @@ -18,6 +19,9 @@ bool profile_changed(const std::vector& current, const std: int main(int argc, char * argv[]) try { + auto settings = rs2::cli( "rs-aligned-advanced example" ) + .process( argc, argv ); + // Create and initialize GUI related objects window app(1280, 720, "RealSense Align (Advanced) Example"); // Simple window handling ImGui_ImplGlfw_Init(app, false); // ImGui library intializition @@ -25,7 +29,7 @@ int main(int argc, char * argv[]) try texture renderer; // Helper for renderig images // Create a pipeline to easily configure and start the camera - rs2::pipeline pipe; + rs2::pipeline pipe( settings.dump() ); //Calling pipeline's start() without any additional parameters will start the first device // with its default streams. //The start function returns the pipeline profile which the pipeline used to start the device diff --git a/examples/align-gl/CMakeLists.txt b/examples/align-gl/CMakeLists.txt index 4c80488eb4..2a0fddb2c7 100644 --- a/examples/align-gl/CMakeLists.txt +++ b/examples/align-gl/CMakeLists.txt @@ -2,16 +2,21 @@ # Copyright(c) 2024 Intel Corporation. All Rights Reserved. cmake_minimum_required(VERSION 3.8) -project(RealsenseExamplesAlignGl ) +project( rs-align-gl ) # Save the command line compile commands in the build output set(CMAKE_EXPORT_COMPILE_COMMANDS 1) if(BUILD_GRAPHICAL_EXAMPLES AND NOT APPLE) - add_executable(rs-align-gl rs-align-gl.cpp ../../third-party/imgui/imgui.cpp ../../third-party/imgui/imgui_draw.cpp ../../third-party/imgui/imgui_impl_glfw.cpp) - set_property(TARGET rs-align-gl PROPERTY CXX_STANDARD 11) - target_link_libraries(rs-align-gl ${DEPENDENCIES} realsense2-gl) - include_directories(../../common ../../third-party/imgui ../../examples) - set_target_properties (rs-align-gl PROPERTIES FOLDER Examples) - install(TARGETS rs-align-gl RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +add_executable( ${PROJECT_NAME} rs-align-gl.cpp + ../../third-party/imgui/imgui.cpp ../../third-party/imgui/imgui_draw.cpp ../../third-party/imgui/imgui_impl_glfw.cpp + ) +set_property( TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11 ) +target_link_libraries( ${PROJECT_NAME} ${DEPENDENCIES} realsense2-gl ) +include_directories( ../../third-party/imgui ../../examples ) +set_target_properties( ${PROJECT_NAME} PROPERTIES FOLDER Examples ) +using_easyloggingpp( ${PROJECT_NAME} SHARED ) +install( TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) + endif() diff --git a/examples/align-gl/rs-align-gl.cpp b/examples/align-gl/rs-align-gl.cpp index 63e4305bcf..c6e5007c72 100644 --- a/examples/align-gl/rs-align-gl.cpp +++ b/examples/align-gl/rs-align-gl.cpp @@ -4,6 +4,7 @@ #include #include "example-imgui.hpp" #include // Include GPU-Processing API +#include /* @@ -35,8 +36,12 @@ void render_slider(rect location, float* alpha, direction* dir); int main(int argc, char * argv[]) try { + auto settings = rs2::cli( "rs-align-gl example" ) + .process( argc, argv ); + std::string serial; - if (!device_with_streams({ RS2_STREAM_COLOR,RS2_STREAM_DEPTH }, serial)) + rs2::context ctx( settings.dump() ); + if( ! device_with_streams( ctx, { RS2_STREAM_COLOR, RS2_STREAM_DEPTH }, serial ) ) return EXIT_SUCCESS; // The following toggle is going to control @@ -57,7 +62,7 @@ int main(int argc, char * argv[]) try texture depth_image, color_image; // Helpers for renderig images // Create a pipeline to easily configure and start the camera - rs2::pipeline pipe; + rs2::pipeline pipe( ctx ); rs2::config cfg; if (!serial.empty()) cfg.enable_device(serial); diff --git a/examples/align/CMakeLists.txt b/examples/align/CMakeLists.txt index dc56ad2ab2..b63f5bd90c 100644 --- a/examples/align/CMakeLists.txt +++ b/examples/align/CMakeLists.txt @@ -2,13 +2,16 @@ # Copyright(c) 2019-2024 Intel Corporation. All Rights Reserved. cmake_minimum_required(VERSION 3.8) -project(RealsenseExamplesAlign) +project( rs-align ) if(BUILD_GRAPHICAL_EXAMPLES) - add_executable(rs-align rs-align.cpp ../../third-party/imgui/imgui.cpp ../../third-party/imgui/imgui_draw.cpp ../../third-party/imgui/imgui_impl_glfw.cpp) - set_property(TARGET rs-align PROPERTY CXX_STANDARD 11) - target_link_libraries(rs-align ${DEPENDENCIES}) - include_directories(../../common ../../third-party/imgui ../../examples) - set_target_properties (rs-align PROPERTIES FOLDER Examples) - install(TARGETS rs-align RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +add_executable( ${PROJECT_NAME} rs-align.cpp ../../third-party/imgui/imgui.cpp ../../third-party/imgui/imgui_draw.cpp ../../third-party/imgui/imgui_impl_glfw.cpp) +set_property( TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11 ) +target_link_libraries( ${PROJECT_NAME} ${DEPENDENCIES} ) +include_directories( ../../third-party/imgui ../../examples ) +set_target_properties( ${PROJECT_NAME} PROPERTIES FOLDER Examples ) +using_easyloggingpp( ${PROJECT_NAME} SHARED ) +install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() diff --git a/examples/align/rs-align.cpp b/examples/align/rs-align.cpp index dc3a376397..8074aec955 100644 --- a/examples/align/rs-align.cpp +++ b/examples/align/rs-align.cpp @@ -1,8 +1,9 @@ // License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2019 Intel Corporation. All Rights Reserved. +// Copyright(c) 2019-24 Intel Corporation. All Rights Reserved. #include #include "example-imgui.hpp" +#include /* This example introduces the concept of spatial stream alignment. @@ -33,8 +34,12 @@ void render_slider(rect location, float* alpha, direction* dir); int main(int argc, char * argv[]) try { + auto settings = rs2::cli( "rs-align example" ) + .process( argc, argv ); + + rs2::context ctx( settings.dump() ); std::string serial; - if (!device_with_streams({ RS2_STREAM_COLOR,RS2_STREAM_DEPTH }, serial)) + if( ! device_with_streams( ctx, { RS2_STREAM_COLOR, RS2_STREAM_DEPTH }, serial ) ) return EXIT_SUCCESS; // Create and initialize GUI related objects @@ -44,7 +49,7 @@ int main(int argc, char * argv[]) try texture depth_image, color_image; // Helpers for renderig images // Create a pipeline to easily configure and start the camera - rs2::pipeline pipe; + rs2::pipeline pipe( ctx ); rs2::config cfg; if (!serial.empty()) cfg.enable_device(serial); diff --git a/examples/callback/CMakeLists.txt b/examples/callback/CMakeLists.txt index 973e9116df..d9e6e7148e 100644 --- a/examples/callback/CMakeLists.txt +++ b/examples/callback/CMakeLists.txt @@ -4,12 +4,10 @@ cmake_minimum_required(VERSION 3.8) project(rs-callback) -if(BUILD_GRAPHICAL_EXAMPLES) - add_executable(${PROJECT_NAME} ${PROJECT_NAME}.cpp) - set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11) - target_link_libraries( ${PROJECT_NAME} ${DEPENDENCIES} tclap ) - include_directories(${PROJECT_NAME} ../ ) - set_target_properties (${PROJECT_NAME} PROPERTIES FOLDER "Examples") - - install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) -endif() +add_executable(${PROJECT_NAME} ${PROJECT_NAME}.cpp) +set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11) +target_link_libraries( ${PROJECT_NAME} ${DEPENDENCIES} ) +include_directories(${PROJECT_NAME} ../ ) +set_target_properties (${PROJECT_NAME} PROPERTIES FOLDER "Examples") +using_easyloggingpp( ${PROJECT_NAME} SHARED ) +install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/examples/callback/rs-callback.cpp b/examples/callback/rs-callback.cpp index 7c90ff22bc..c3d6035ac3 100644 --- a/examples/callback/rs-callback.cpp +++ b/examples/callback/rs-callback.cpp @@ -1,7 +1,10 @@ // License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2017 Intel Corporation. All Rights Reserved. +// Copyright(c) 2017-24 Intel Corporation. All Rights Reserved. #include // Include RealSense Cross Platform API + +#include + #include #include #include @@ -11,7 +14,8 @@ // The callback example demonstrates asynchronous usage of the pipeline int main(int argc, char * argv[]) try { - //rs2::log_to_console(RS2_LOG_SEVERITY_ERROR); + auto settings = rs2::cli( "rs-callback example" ) + .process( argc, argv ); std::map counters; std::map stream_names; @@ -37,7 +41,7 @@ int main(int argc, char * argv[]) try }; // Declare RealSense pipeline, encapsulating the actual device and sensors. - rs2::pipeline pipe; + rs2::pipeline pipe( settings.dump() ); // Start streaming through the callback with default recommended configuration // The default video configuration contains Depth and Color streams diff --git a/examples/example-utils.hpp b/examples/example-utils.hpp index 90e6d10e59..2ae6bc7803 100644 --- a/examples/example-utils.hpp +++ b/examples/example-utils.hpp @@ -13,9 +13,8 @@ ////////////////////////////// // Find devices with specified streams -bool device_with_streams(std::vector stream_requests, std::string& out_serial) +bool device_with_streams( rs2::context & ctx, std::vector< rs2_stream > stream_requests, std::string & out_serial ) { - rs2::context ctx; auto devs = ctx.query_devices(); std::vector unavailable_streams = stream_requests; for (auto dev : devs) diff --git a/examples/hello-realsense/CMakeLists.txt b/examples/hello-realsense/CMakeLists.txt index ceb6a7910a..29b9f1b679 100644 --- a/examples/hello-realsense/CMakeLists.txt +++ b/examples/hello-realsense/CMakeLists.txt @@ -2,11 +2,13 @@ # Copyright(c) 2019-2024 Intel Corporation. All Rights Reserved. cmake_minimum_required(VERSION 3.8) -project(RealsenseExamplesHelloRealSense) +project( rs-hello-realsense ) -add_executable(rs-hello-realsense rs-hello-realsense.cpp) -set_property(TARGET rs-hello-realsense PROPERTY CXX_STANDARD 11) -target_link_libraries(rs-hello-realsense ${DEPENDENCIES}) -set_target_properties (rs-hello-realsense PROPERTIES FOLDER "Examples") +add_executable( ${PROJECT_NAME} rs-hello-realsense.cpp ) +set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11) +target_link_libraries( ${PROJECT_NAME} ${DEPENDENCIES} ) +set_target_properties( ${PROJECT_NAME} PROPERTIES FOLDER "Examples" ) -install(TARGETS rs-hello-realsense RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +using_easyloggingpp( ${PROJECT_NAME} SHARED ) + +install( TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) diff --git a/examples/hello-realsense/rs-hello-realsense.cpp b/examples/hello-realsense/rs-hello-realsense.cpp index 46be1804f4..07fed49c99 100644 --- a/examples/hello-realsense/rs-hello-realsense.cpp +++ b/examples/hello-realsense/rs-hello-realsense.cpp @@ -1,15 +1,20 @@ // License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2019 Intel Corporation. All Rights Reserved. +// Copyright(c) 2019-24 Intel Corporation. All Rights Reserved. -#include // Include RealSense Cross Platform API -#include // for cout +#include // RealSense Cross Platform API +#include + +#include // Hello RealSense example demonstrates the basics of connecting to a RealSense device // and taking advantage of depth data int main(int argc, char * argv[]) try { + auto settings = rs2::cli( "hello-realsense example" ) + .process( argc, argv ); + // Create a Pipeline - this serves as a top-level API for streaming and processing frames - rs2::pipeline p; + rs2::pipeline p( settings.dump() ); // Configure and start the pipeline p.start(); diff --git a/examples/measure/CMakeLists.txt b/examples/measure/CMakeLists.txt index 1909939708..ed9e74493d 100644 --- a/examples/measure/CMakeLists.txt +++ b/examples/measure/CMakeLists.txt @@ -2,17 +2,19 @@ # Copyright(c) 2019-2024 Intel Corporation. All Rights Reserved. cmake_minimum_required(VERSION 3.8) -project(RealsenseExamplesMeasure) +project( rs-measure ) set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) if(BUILD_GRAPHICAL_EXAMPLES) - add_executable(rs-measure rs-measure.cpp ../example.hpp) - set_property(TARGET rs-measure PROPERTY CXX_STANDARD 11) - target_link_libraries(rs-measure ${DEPENDENCIES} Threads::Threads) + add_executable(${PROJECT_NAME} rs-measure.cpp ../example.hpp) + set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11) + target_link_libraries(${PROJECT_NAME} ${DEPENDENCIES} Threads::Threads) include_directories(../) - set_target_properties (rs-measure PROPERTIES FOLDER "Examples") + set_target_properties( ${PROJECT_NAME} PROPERTIES FOLDER "Examples") - install(TARGETS rs-measure RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + using_easyloggingpp( ${PROJECT_NAME} SHARED ) + + install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/examples/measure/rs-measure.cpp b/examples/measure/rs-measure.cpp index 79e7f0ca10..9109c82fd5 100644 --- a/examples/measure/rs-measure.cpp +++ b/examples/measure/rs-measure.cpp @@ -1,9 +1,11 @@ // License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2017 Intel Corporation. All Rights Reserved. +// Copyright(c) 2017-24 Intel Corporation. All Rights Reserved. #include // Include RealSense Cross Platform API #include "example.hpp" // Include short list of convenience functions for rendering +#include + // This example will require several standard data-structures and algorithms: #define _USE_MATH_DEFINES #include @@ -98,8 +100,12 @@ void render_simple_distance(const rs2::depth_frame& depth, int main(int argc, char * argv[]) try { + auto settings = rs2::cli( "rs-measure example" ) + .process( argc, argv ); + + rs2::context ctx( settings.dump() ); std::string serial; - if (!device_with_streams({ RS2_STREAM_COLOR,RS2_STREAM_DEPTH }, serial)) + if( ! device_with_streams( ctx, { RS2_STREAM_COLOR, RS2_STREAM_DEPTH }, serial ) ) return EXIT_SUCCESS; // OpenGL textures for the color and depth frames @@ -133,7 +139,7 @@ int main(int argc, char * argv[]) try rs2::align align_to(RS2_STREAM_DEPTH); // Declare RealSense pipeline, encapsulating the actual device and sensors - rs2::pipeline pipe; + rs2::pipeline pipe( ctx ); rs2::config cfg; if (!serial.empty()) diff --git a/include/librealsense2/h/rs_context.h b/include/librealsense2/h/rs_context.h index 6226842bf2..9999973f5d 100644 --- a/include/librealsense2/h/rs_context.h +++ b/include/librealsense2/h/rs_context.h @@ -32,7 +32,8 @@ rs2_context* rs2_create_context(int api_version, rs2_error** error); * the 'context' key in the file is taken as-is * '/context' is merged, if it exists * then the context-settings are merged -* dds: {} - (requires BUILD_WITH_DDS) false disables DDS; otherwise the DDS settings: +* dds: {} - DDS settings: (requires BUILD_WITH_DDS) +* enabled: false - (bool) whether DDS is enabled * domain: 0 - (int) the number of the DDS domain [0-232] * participant: - (string) the name of the participant * (see additional settings in realdds/doc/device.md#Settings) diff --git a/include/librealsense2/h/rs_types.h b/include/librealsense2/h/rs_types.h index bedc711143..775fb5dd83 100644 --- a/include/librealsense2/h/rs_types.h +++ b/include/librealsense2/h/rs_types.h @@ -280,53 +280,6 @@ const char* rs2_get_failed_args (const rs2_error* error); const char* rs2_get_error_message (const rs2_error* error); void rs2_free_error (rs2_error* error); -#pragma pack(push, 1) -/* rs2_calibration_roi - Array of four corners in Deph Frame Coordinate system that define a closed simple quadrangle (non-intersecting)*/ -typedef struct rs2_calibration_roi -{ - uint16_t mask_pixel[4][2]; -}rs2_calibration_roi; - -typedef struct float3_row_major { float x, y, z; } float3_row_major; -typedef struct float3x3_row_major { float3_row_major x, y, z; } float3x3_row_major; - -typedef struct rs2_extrinsics_row_major -{ - float3x3_row_major rotation; // Rotation matrix - float3_row_major translation; // Metric units -} rs2_extrinsics_row_major; - -typedef struct rs2_calibration_config -{ - uint8_t calib_roi_num_of_segments; // Within 0-4 range: 0 - Default.No limitations.Full FOV can be used in TC - // 1 - 4: Segments defined.The segment must be sequential - rs2_calibration_roi roi[4]; // Segment 0 = convex tetragon - The vertices of the tetragon are ordered clockwise - // Vertex = [x, y] = pixel coordinates in the reference depth map - // 0 - based coordinates : [0, 0] = center of the top - left pixel - // Segments 1-3 - structured identical to segment_#0 (reserved) - // The ROI segments can intersect, but each must be convex(angles <= 180 degrees). - uint8_t reserved1[12]; - rs2_extrinsics_row_major camera_position; - uint8_t reserved2[300]; - uint8_t crypto_signature[32]; - uint8_t reserved3[39]; -} rs2_calibration_config; - -typedef struct rs2_calibration_config_header -{ - uint16_t version; // major.minor. Big-endian - uint16_t table_type; // type - uint32_t table_size; // full size including: header footer - uint32_t calib_version; // major.minor.index - uint32_t crc32; // crc of all the data in table excluding this header/CRC -} rs2_calibration_config_header; - -typedef struct rs2_calibration_config_with_header -{ - rs2_calibration_config_header header; - rs2_calibration_config payload; -} rs2_calibration_config_with_header; -#pragma pack(pop) #ifdef __cplusplus } diff --git a/include/librealsense2/hpp/rs_types.hpp b/include/librealsense2/hpp/rs_types.hpp index d747f14bbc..26390ae07c 100644 --- a/include/librealsense2/hpp/rs_types.hpp +++ b/include/librealsense2/hpp/rs_types.hpp @@ -211,9 +211,4 @@ namespace rs2 inline std::ostream & operator << (std::ostream & o, rs2_vector v) { return o << v.x << ", " << v.y << ", " << v.z; } inline std::ostream & operator << (std::ostream & o, rs2_quaternion q) { return o << q.x << ", " << q.y << ", " << q.z << ", " << q.w; } -inline bool operator==(rs2_calibration_config const& self, rs2_calibration_config const& other) -{ - return !std::memcmp(&self, &other, sizeof(rs2_calibration_config)); -} - #endif // LIBREALSENSE_RS2_TYPES_HPP diff --git a/include/librealsense2/rs.h b/include/librealsense2/rs.h index 7fd0793069..15ee7deaea 100644 --- a/include/librealsense2/rs.h +++ b/include/librealsense2/rs.h @@ -25,7 +25,7 @@ extern "C" { #define RS2_API_MAJOR_VERSION 2 #define RS2_API_MINOR_VERSION 56 -#define RS2_API_PATCH_VERSION 1 +#define RS2_API_PATCH_VERSION 2 #define RS2_API_BUILD_VERSION 0 #ifndef STRINGIFY diff --git a/package.xml b/package.xml index a6a9cde521..0cea9f5df1 100644 --- a/package.xml +++ b/package.xml @@ -6,7 +6,7 @@ librealsense2 - 2.56.1 + 2.56.2 Library for controlling and capturing data from the Intel(R) RealSense(TM) D400 devices. diff --git a/scripts/patch-realsense-ubuntu-lts-hwe.sh b/scripts/patch-realsense-ubuntu-lts-hwe.sh index da42db9830..5471d9fb1d 100755 --- a/scripts/patch-realsense-ubuntu-lts-hwe.sh +++ b/scripts/patch-realsense-ubuntu-lts-hwe.sh @@ -69,9 +69,10 @@ fi #Include usability functions source ./scripts/patch-utils-hwe.sh LINUX_BRANCH=${LINUX_BRANCH:-$(uname -r)} +UBUNTU_VERSION=$(uname -v | cut -d '-' -f 1 | cut -d '~' -f 2) # Get the required tools and headers to build the kernel -sudo apt-get install linux-headers-generic linux-headers-$LINUX_BRANCH build-essential git bc -y +sudo apt-get install linux-headers-$LINUX_BRANCH build-essential git bc -y #Packages to build the patched modules require_package libusb-1.0-0-dev require_package libssl-dev @@ -137,11 +138,17 @@ if [ $rebuild_ko -eq 0 ]; then #Search the repository for the tag that matches the mmaj.min.patch-build of Ubuntu kernel kernel_full_num=$(echo $LINUX_BRANCH | cut -d '-' -f 1,2) - if [ "${ubuntu_codename}" != "jammy" ]; + if [[ "${ubuntu_codename}" != "jammy" && "${ubuntu_codename}" != "noble" ]]; then kernel_git_tag=$(git ls-remote --tags origin | grep "${kernel_full_num}\." | grep '[^^{}]$' | tail -n 1 | awk -F/ '{print $NF}') else - kernel_git_tag=$(git ls-remote --tags origin | grep "${kernel_full_num}\." | grep '[^^{}]$' | head -n 1 | awk -F/ '{print $NF}') + # Search for the tag name with suitable UBUNTU_VERSION. If not there, pick the one with matching kernel version alone. + if [[ -z "$(git ls-remote --tags origin | grep "${kernel_full_num}\." | grep '[^^{}]$' | grep "${UBUNTU_VERSION}" )" ]]; + then + kernel_git_tag=$(git ls-remote --tags origin | grep "${kernel_full_num}\." | grep '[^^{}]$' | head -n 1 | awk -F/ '{print $NF}') + else + kernel_git_tag=$(git ls-remote --tags origin | grep "${kernel_full_num}\." | grep '[^^{}]$' | grep "${UBUNTU_VERSION}" | head -n 1 | awk -F/ '{print $NF}') + fi fi echo -e "\e[32mFetching Ubuntu LTS tag \e[47m${kernel_git_tag}\e[0m \e[32m to the local kernel sources folder\e[0m" git fetch origin tag ${kernel_git_tag} --no-tags --depth 1 @@ -330,6 +337,7 @@ fi # As a precausion start with unloading the core uvcvideo: try_unload_module uvcvideo try_unload_module videobuf2_v4l2 +[ ${k_maj_min} -ge 608 ] && try_unload_module videobuf2_memops [ ${k_maj_min} -ge 500 ] && try_unload_module videobuf2_common [ ${k_maj_min} -ge 605 ] && try_unload_module uvc try_unload_module videodev diff --git a/scripts/patch-utils-hwe.sh b/scripts/patch-utils-hwe.sh index ed8fb22cae..e96d89a39d 100644 --- a/scripts/patch-utils-hwe.sh +++ b/scripts/patch-utils-hwe.sh @@ -135,15 +135,29 @@ function choose_kernel_branch { "6.5") echo hwe-6.5 ;; + "6.8") + echo hwe-6.8 + ;; *) #error message shall be redirected to stderr to be printed properly echo -e "\e[31mUnsupported kernel version $1 . The Jammy patches are maintained for Ubuntu LTS with kernel 5.15, 5.19 only\e[0m" >&2 exit 1 ;; esac - + elif [ "$2" == "noble" ]; # Ubuntu 24 + then + case "${kernel_version[0]}.${kernel_version[1]}" in + "6.8") + echo hwe-6.8 + ;; + *) + #error message shall be redirected to stderr to be printed properly + echo -e "\e[31mUnsupported kernel version $1 . The Noble patches are maintained for Ubuntu LTS with kernel 6.8 only\e[0m" >&2 + exit 1 + ;; + esac else - echo -e "\e[31mUnsupported distribution $2, kernel version $1 . The patches are maintained for Ubuntu 16/18/20 LTS\e[0m" >&2 + echo -e "\e[31mUnsupported distribution $2, kernel version $1 . The patches are maintained for Ubuntu 20/22/24 LTS\e[0m" >&2 exit 1 fi } @@ -218,7 +232,10 @@ function try_module_insert { fi # backup the existing module (if available) for recovery - if [ -f ${tgt_ko} ]; + if [ -f ${tgt_ko}.zst ]; + then + sudo cp ${tgt_ko}.zst ${tgt_ko}.zst.bckup + elif [ -f ${tgt_ko} ]; then sudo cp ${tgt_ko} ${tgt_ko}.bckup else @@ -240,7 +257,12 @@ function try_module_insert { echo -e "\e[31mVerify that the current kernel version is aligned to the patched module version\e[0m" if [ ${backup_available} -ne 0 ]; then - sudo cp ${tgt_ko}.bckup ${tgt_ko} + if [ -f ${tgt_ko}.zst.bckup ]; + then + sudo cp ${tgt_ko}.zst.bckup ${tgt_ko}.zst + else + sudo cp ${tgt_ko}.bckup ${tgt_ko} + fi sudo modprobe ${module_name} printf "\e[34mThe original \e[33m %s \e[34m module was reloaded\n\e[0m" ${module_name} fi @@ -248,7 +270,8 @@ function try_module_insert { else # Everything went OK, delete backup printf "\e[32m succeeded\e[0m" - sudo rm ${tgt_ko}.bckup + sudo rm -f ${tgt_ko}.zst.bckup + sudo rm -f ${tgt_ko}.bckup fi # Reload all dependent modules recursively diff --git a/scripts/realsense-camera-formats-jammy-hwe-6.8.patch b/scripts/realsense-camera-formats-jammy-hwe-6.8.patch new file mode 100644 index 0000000000..665eca353e --- /dev/null +++ b/scripts/realsense-camera-formats-jammy-hwe-6.8.patch @@ -0,0 +1,107 @@ +From 77a530efa9334bab58155c688245859f231be397 Mon Sep 17 00:00:00 2001 +From: Arun-Prasad-V +Date: Mon, 5 Aug 2024 15:02:34 +0530 +Subject: [PATCH] Realsense camera formats support for kernel 6.8 + +--- + drivers/media/common/uvc.c | 20 ++++++++++++++++++++ + drivers/media/v4l2-core/v4l2-ioctl.c | 3 +++ + include/linux/usb/uvc.h | 15 +++++++++++++++ + include/uapi/linux/videodev2.h | 3 +++ + 4 files changed, 41 insertions(+) + +diff --git a/drivers/media/common/uvc.c b/drivers/media/common/uvc.c +index 9c0ba7a6c..a00b743cc 100644 +--- a/drivers/media/common/uvc.c ++++ b/drivers/media/common/uvc.c +@@ -120,6 +120,10 @@ static const struct uvc_format_desc uvc_fmts[] = { + .guid = UVC_GUID_FORMAT_Y12I, + .fcc = V4L2_PIX_FMT_Y12I, + }, ++ { ++ .guid = UVC_GUID_FORMAT_Y16I, ++ .fcc = V4L2_PIX_FMT_Y16I, ++ }, + { + .guid = UVC_GUID_FORMAT_Z16, + .fcc = V4L2_PIX_FMT_Z16, +@@ -164,6 +168,22 @@ static const struct uvc_format_desc uvc_fmts[] = { + .guid = UVC_GUID_FORMAT_HEVC, + .fcc = V4L2_PIX_FMT_HEVC, + }, ++ { ++ .guid = UVC_GUID_FORMAT_RAW8, ++ .fcc = V4L2_PIX_FMT_GREY, ++ }, ++ { ++ .guid = UVC_GUID_FORMAT_RW16, ++ .fcc = V4L2_PIX_FMT_RW16, ++ }, ++ { ++ .guid = UVC_GUID_FORMAT_D16, ++ .fcc = V4L2_PIX_FMT_Z16, ++ }, ++ { ++ .guid = UVC_GUID_FORMAT_W10, ++ .fcc = V4L2_PIX_FMT_W10, ++ }, + }; + + const struct uvc_format_desc *uvc_format_by_guid(const u8 guid[16]) +diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c +index 33076af4d..a04fef879 100644 +--- a/drivers/media/v4l2-core/v4l2-ioctl.c ++++ b/drivers/media/v4l2-core/v4l2-ioctl.c +@@ -1314,6 +1314,9 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt) + case V4L2_PIX_FMT_IPU3_Y10: descr = "10-bit greyscale (IPU3 Packed)"; break; + case V4L2_PIX_FMT_Y8I: descr = "Interleaved 8-bit Greyscale"; break; + case V4L2_PIX_FMT_Y12I: descr = "Interleaved 12-bit Greyscale"; break; ++ case V4L2_PIX_FMT_Y16I: descr = "Interleaved 16-bit Greyscale"; break; ++ case V4L2_PIX_FMT_RW16: descr = "16-bit Raw data"; break; ++ case V4L2_PIX_FMT_W10: descr = "10-bit packed 8888[2222]"; break; + case V4L2_PIX_FMT_Z16: descr = "16-bit Depth"; break; + case V4L2_PIX_FMT_INZI: descr = "Planar 10:16 Greyscale Depth"; break; + case V4L2_PIX_FMT_CNF4: descr = "4-bit Depth Confidence (Packed)"; break; +diff --git a/include/linux/usb/uvc.h b/include/linux/usb/uvc.h +index 88d96095b..11456a014 100644 +--- a/include/linux/usb/uvc.h ++++ b/include/linux/usb/uvc.h +@@ -118,6 +118,21 @@ + #define UVC_GUID_FORMAT_Y12I \ + { 'Y', '1', '2', 'I', 0x00, 0x00, 0x10, 0x00, \ + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} ++#define UVC_GUID_FORMAT_Y16I \ ++ { 'Y', '1', '6', 'I', 0x00, 0x00, 0x10, 0x00, \ ++ 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} ++#define UVC_GUID_FORMAT_RAW8 \ ++ { 'R', 'A', 'W', '8', 0x66, 0x1a, 0x42, 0xa2, \ ++ 0x90, 0x65, 0xd0, 0x18, 0x14, 0xa8, 0xef, 0x8a} ++#define UVC_GUID_FORMAT_RW16 \ ++ { 'R', 'W', '1', '6', 0x66, 0x1a, 0x42, 0xa2, \ ++ 0x90, 0x65, 0xd0, 0x18, 0x14, 0xa8, 0xef, 0x8a} ++#define UVC_GUID_FORMAT_D16 \ ++ { 'P', 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, \ ++ 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} ++#define UVC_GUID_FORMAT_W10 \ ++ { 'W', '1', '0', ' ', 0x00, 0x00, 0x10, 0x00, \ ++ 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} + #define UVC_GUID_FORMAT_Z16 \ + { 'Z', '1', '6', ' ', 0x00, 0x00, 0x10, 0x00, \ + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} +diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h +index 68e7ac178..c156981ab 100644 +--- a/include/uapi/linux/videodev2.h ++++ b/include/uapi/linux/videodev2.h +@@ -793,6 +793,9 @@ struct v4l2_pix_format { + #define V4L2_PIX_FMT_S5C_UYVY_JPG v4l2_fourcc('S', '5', 'C', 'I') /* S5C73M3 interleaved UYVY/JPEG */ + #define V4L2_PIX_FMT_Y8I v4l2_fourcc('Y', '8', 'I', ' ') /* Greyscale 8-bit L/R interleaved */ + #define V4L2_PIX_FMT_Y12I v4l2_fourcc('Y', '1', '2', 'I') /* Greyscale 12-bit L/R interleaved */ ++#define V4L2_PIX_FMT_Y16I v4l2_fourcc('Y', '1', '6', 'I') /* Greyscale 16-bit L/R interleaved */ ++#define V4L2_PIX_FMT_RW16 v4l2_fourcc('R', 'W', '1', '6') /* Raw data 16-bit */ ++#define V4L2_PIX_FMT_W10 v4l2_fourcc('W', '1', '0', ' ') /* Packed raw data 10-bit */ + #define V4L2_PIX_FMT_Z16 v4l2_fourcc('Z', '1', '6', ' ') /* Depth data 16-bit */ + #define V4L2_PIX_FMT_MT21C v4l2_fourcc('M', 'T', '2', '1') /* Mediatek compressed block mode */ + #define V4L2_PIX_FMT_MM21 v4l2_fourcc('M', 'M', '2', '1') /* Mediatek 8-bit block mode, two non-contiguous planes */ +-- +2.43.0 + diff --git a/scripts/realsense-camera-formats-noble-hwe-6.8.patch b/scripts/realsense-camera-formats-noble-hwe-6.8.patch new file mode 100644 index 0000000000..665eca353e --- /dev/null +++ b/scripts/realsense-camera-formats-noble-hwe-6.8.patch @@ -0,0 +1,107 @@ +From 77a530efa9334bab58155c688245859f231be397 Mon Sep 17 00:00:00 2001 +From: Arun-Prasad-V +Date: Mon, 5 Aug 2024 15:02:34 +0530 +Subject: [PATCH] Realsense camera formats support for kernel 6.8 + +--- + drivers/media/common/uvc.c | 20 ++++++++++++++++++++ + drivers/media/v4l2-core/v4l2-ioctl.c | 3 +++ + include/linux/usb/uvc.h | 15 +++++++++++++++ + include/uapi/linux/videodev2.h | 3 +++ + 4 files changed, 41 insertions(+) + +diff --git a/drivers/media/common/uvc.c b/drivers/media/common/uvc.c +index 9c0ba7a6c..a00b743cc 100644 +--- a/drivers/media/common/uvc.c ++++ b/drivers/media/common/uvc.c +@@ -120,6 +120,10 @@ static const struct uvc_format_desc uvc_fmts[] = { + .guid = UVC_GUID_FORMAT_Y12I, + .fcc = V4L2_PIX_FMT_Y12I, + }, ++ { ++ .guid = UVC_GUID_FORMAT_Y16I, ++ .fcc = V4L2_PIX_FMT_Y16I, ++ }, + { + .guid = UVC_GUID_FORMAT_Z16, + .fcc = V4L2_PIX_FMT_Z16, +@@ -164,6 +168,22 @@ static const struct uvc_format_desc uvc_fmts[] = { + .guid = UVC_GUID_FORMAT_HEVC, + .fcc = V4L2_PIX_FMT_HEVC, + }, ++ { ++ .guid = UVC_GUID_FORMAT_RAW8, ++ .fcc = V4L2_PIX_FMT_GREY, ++ }, ++ { ++ .guid = UVC_GUID_FORMAT_RW16, ++ .fcc = V4L2_PIX_FMT_RW16, ++ }, ++ { ++ .guid = UVC_GUID_FORMAT_D16, ++ .fcc = V4L2_PIX_FMT_Z16, ++ }, ++ { ++ .guid = UVC_GUID_FORMAT_W10, ++ .fcc = V4L2_PIX_FMT_W10, ++ }, + }; + + const struct uvc_format_desc *uvc_format_by_guid(const u8 guid[16]) +diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c +index 33076af4d..a04fef879 100644 +--- a/drivers/media/v4l2-core/v4l2-ioctl.c ++++ b/drivers/media/v4l2-core/v4l2-ioctl.c +@@ -1314,6 +1314,9 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt) + case V4L2_PIX_FMT_IPU3_Y10: descr = "10-bit greyscale (IPU3 Packed)"; break; + case V4L2_PIX_FMT_Y8I: descr = "Interleaved 8-bit Greyscale"; break; + case V4L2_PIX_FMT_Y12I: descr = "Interleaved 12-bit Greyscale"; break; ++ case V4L2_PIX_FMT_Y16I: descr = "Interleaved 16-bit Greyscale"; break; ++ case V4L2_PIX_FMT_RW16: descr = "16-bit Raw data"; break; ++ case V4L2_PIX_FMT_W10: descr = "10-bit packed 8888[2222]"; break; + case V4L2_PIX_FMT_Z16: descr = "16-bit Depth"; break; + case V4L2_PIX_FMT_INZI: descr = "Planar 10:16 Greyscale Depth"; break; + case V4L2_PIX_FMT_CNF4: descr = "4-bit Depth Confidence (Packed)"; break; +diff --git a/include/linux/usb/uvc.h b/include/linux/usb/uvc.h +index 88d96095b..11456a014 100644 +--- a/include/linux/usb/uvc.h ++++ b/include/linux/usb/uvc.h +@@ -118,6 +118,21 @@ + #define UVC_GUID_FORMAT_Y12I \ + { 'Y', '1', '2', 'I', 0x00, 0x00, 0x10, 0x00, \ + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} ++#define UVC_GUID_FORMAT_Y16I \ ++ { 'Y', '1', '6', 'I', 0x00, 0x00, 0x10, 0x00, \ ++ 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} ++#define UVC_GUID_FORMAT_RAW8 \ ++ { 'R', 'A', 'W', '8', 0x66, 0x1a, 0x42, 0xa2, \ ++ 0x90, 0x65, 0xd0, 0x18, 0x14, 0xa8, 0xef, 0x8a} ++#define UVC_GUID_FORMAT_RW16 \ ++ { 'R', 'W', '1', '6', 0x66, 0x1a, 0x42, 0xa2, \ ++ 0x90, 0x65, 0xd0, 0x18, 0x14, 0xa8, 0xef, 0x8a} ++#define UVC_GUID_FORMAT_D16 \ ++ { 'P', 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, \ ++ 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} ++#define UVC_GUID_FORMAT_W10 \ ++ { 'W', '1', '0', ' ', 0x00, 0x00, 0x10, 0x00, \ ++ 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} + #define UVC_GUID_FORMAT_Z16 \ + { 'Z', '1', '6', ' ', 0x00, 0x00, 0x10, 0x00, \ + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} +diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h +index 68e7ac178..c156981ab 100644 +--- a/include/uapi/linux/videodev2.h ++++ b/include/uapi/linux/videodev2.h +@@ -793,6 +793,9 @@ struct v4l2_pix_format { + #define V4L2_PIX_FMT_S5C_UYVY_JPG v4l2_fourcc('S', '5', 'C', 'I') /* S5C73M3 interleaved UYVY/JPEG */ + #define V4L2_PIX_FMT_Y8I v4l2_fourcc('Y', '8', 'I', ' ') /* Greyscale 8-bit L/R interleaved */ + #define V4L2_PIX_FMT_Y12I v4l2_fourcc('Y', '1', '2', 'I') /* Greyscale 12-bit L/R interleaved */ ++#define V4L2_PIX_FMT_Y16I v4l2_fourcc('Y', '1', '6', 'I') /* Greyscale 16-bit L/R interleaved */ ++#define V4L2_PIX_FMT_RW16 v4l2_fourcc('R', 'W', '1', '6') /* Raw data 16-bit */ ++#define V4L2_PIX_FMT_W10 v4l2_fourcc('W', '1', '0', ' ') /* Packed raw data 10-bit */ + #define V4L2_PIX_FMT_Z16 v4l2_fourcc('Z', '1', '6', ' ') /* Depth data 16-bit */ + #define V4L2_PIX_FMT_MT21C v4l2_fourcc('M', 'T', '2', '1') /* Mediatek compressed block mode */ + #define V4L2_PIX_FMT_MM21 v4l2_fourcc('M', 'M', '2', '1') /* Mediatek 8-bit block mode, two non-contiguous planes */ +-- +2.43.0 + diff --git a/scripts/realsense-metadata-jammy-hwe-6.8.patch b/scripts/realsense-metadata-jammy-hwe-6.8.patch new file mode 100644 index 0000000000..7374ac88d9 --- /dev/null +++ b/scripts/realsense-metadata-jammy-hwe-6.8.patch @@ -0,0 +1,66 @@ +From 25a687e89e8f365caccef1b9bbb11406e53cc1be Mon Sep 17 00:00:00 2001 +From: Arun-Prasad-V +Date: Mon, 5 Aug 2024 15:02:57 +0530 +Subject: [PATCH] Realsense camera metadata support for kernel 6.8 + +--- + drivers/media/usb/uvc/uvc_driver.c | 36 ++++++++++++++++++++++++++++++ + 1 file changed, 36 insertions(+) + +diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c +index bbd90123a..1cd98a8cc 100644 +--- a/drivers/media/usb/uvc/uvc_driver.c ++++ b/drivers/media/usb/uvc/uvc_driver.c +@@ -3102,6 +3102,15 @@ static const struct usb_device_id uvc_ids[] = { + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) }, ++ /* Intel D555 Depth Camera */ ++ { .match_flags = USB_DEVICE_ID_MATCH_DEVICE ++ | USB_DEVICE_ID_MATCH_INT_INFO, ++ .idVendor = 0x8086, ++ .idProduct = 0x0b56, ++ .bInterfaceClass = USB_CLASS_VIDEO, ++ .bInterfaceSubClass = 1, ++ .bInterfaceProtocol = UVC_PC_PROTOCOL_15, ++ .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) }, + /* Intel D405 Depth Camera */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, +@@ -3120,6 +3129,33 @@ static const struct usb_device_id uvc_ids[] = { + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) }, ++ /* Intel D585 Depth Camera */ ++ { .match_flags = USB_DEVICE_ID_MATCH_DEVICE ++ | USB_DEVICE_ID_MATCH_INT_INFO, ++ .idVendor = 0x8086, ++ .idProduct = 0x0b6a, ++ .bInterfaceClass = USB_CLASS_VIDEO, ++ .bInterfaceSubClass = 1, ++ .bInterfaceProtocol = UVC_PC_PROTOCOL_15, ++ .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) }, ++ /* Intel 585 Camera */ ++ { .match_flags = USB_DEVICE_ID_MATCH_DEVICE ++ | USB_DEVICE_ID_MATCH_INT_INFO, ++ .idVendor = 0x8086, ++ .idProduct = 0x0b6b, ++ .bInterfaceClass = USB_CLASS_VIDEO, ++ .bInterfaceSubClass = 1, ++ .bInterfaceProtocol = UVC_PC_PROTOCOL_15, ++ .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) }, ++ /* Intel D421 Depth Module */ ++ { .match_flags = USB_DEVICE_ID_MATCH_DEVICE ++ | USB_DEVICE_ID_MATCH_INT_INFO, ++ .idVendor = 0x8086, ++ .idProduct = 0x1155, ++ .bInterfaceClass = USB_CLASS_VIDEO, ++ .bInterfaceSubClass = 1, ++ .bInterfaceProtocol = 0, ++ .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) }, + /* Generic USB Video Class */ + { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, UVC_PC_PROTOCOL_UNDEFINED) }, + { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, UVC_PC_PROTOCOL_15) }, +-- +2.43.0 + diff --git a/scripts/realsense-metadata-noble-hwe-6.8.patch b/scripts/realsense-metadata-noble-hwe-6.8.patch new file mode 100644 index 0000000000..7374ac88d9 --- /dev/null +++ b/scripts/realsense-metadata-noble-hwe-6.8.patch @@ -0,0 +1,66 @@ +From 25a687e89e8f365caccef1b9bbb11406e53cc1be Mon Sep 17 00:00:00 2001 +From: Arun-Prasad-V +Date: Mon, 5 Aug 2024 15:02:57 +0530 +Subject: [PATCH] Realsense camera metadata support for kernel 6.8 + +--- + drivers/media/usb/uvc/uvc_driver.c | 36 ++++++++++++++++++++++++++++++ + 1 file changed, 36 insertions(+) + +diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c +index bbd90123a..1cd98a8cc 100644 +--- a/drivers/media/usb/uvc/uvc_driver.c ++++ b/drivers/media/usb/uvc/uvc_driver.c +@@ -3102,6 +3102,15 @@ static const struct usb_device_id uvc_ids[] = { + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) }, ++ /* Intel D555 Depth Camera */ ++ { .match_flags = USB_DEVICE_ID_MATCH_DEVICE ++ | USB_DEVICE_ID_MATCH_INT_INFO, ++ .idVendor = 0x8086, ++ .idProduct = 0x0b56, ++ .bInterfaceClass = USB_CLASS_VIDEO, ++ .bInterfaceSubClass = 1, ++ .bInterfaceProtocol = UVC_PC_PROTOCOL_15, ++ .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) }, + /* Intel D405 Depth Camera */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, +@@ -3120,6 +3129,33 @@ static const struct usb_device_id uvc_ids[] = { + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) }, ++ /* Intel D585 Depth Camera */ ++ { .match_flags = USB_DEVICE_ID_MATCH_DEVICE ++ | USB_DEVICE_ID_MATCH_INT_INFO, ++ .idVendor = 0x8086, ++ .idProduct = 0x0b6a, ++ .bInterfaceClass = USB_CLASS_VIDEO, ++ .bInterfaceSubClass = 1, ++ .bInterfaceProtocol = UVC_PC_PROTOCOL_15, ++ .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) }, ++ /* Intel 585 Camera */ ++ { .match_flags = USB_DEVICE_ID_MATCH_DEVICE ++ | USB_DEVICE_ID_MATCH_INT_INFO, ++ .idVendor = 0x8086, ++ .idProduct = 0x0b6b, ++ .bInterfaceClass = USB_CLASS_VIDEO, ++ .bInterfaceSubClass = 1, ++ .bInterfaceProtocol = UVC_PC_PROTOCOL_15, ++ .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) }, ++ /* Intel D421 Depth Module */ ++ { .match_flags = USB_DEVICE_ID_MATCH_DEVICE ++ | USB_DEVICE_ID_MATCH_INT_INFO, ++ .idVendor = 0x8086, ++ .idProduct = 0x1155, ++ .bInterfaceClass = USB_CLASS_VIDEO, ++ .bInterfaceSubClass = 1, ++ .bInterfaceProtocol = 0, ++ .driver_info = UVC_INFO_META(V4L2_META_FMT_D4XX) }, + /* Generic USB Video Class */ + { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, UVC_PC_PROTOCOL_UNDEFINED) }, + { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, UVC_PC_PROTOCOL_15) }, +-- +2.43.0 + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4223252b9e..1b75328682 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -163,6 +163,9 @@ target_sources(${LRS_TARGET} "${CMAKE_CURRENT_LIST_DIR}/types.h" "${CMAKE_CURRENT_LIST_DIR}/platform/command-transfer.h" "${CMAKE_CURRENT_LIST_DIR}/auto-calibrated-device.h" + "${CMAKE_CURRENT_LIST_DIR}/auto-calibrated-proxy.h" + "${CMAKE_CURRENT_LIST_DIR}/auto-calibrated-proxy.cpp" + "${CMAKE_CURRENT_LIST_DIR}/calibration-engine-interface.h" "${CMAKE_CURRENT_LIST_DIR}/device-calibration.h" "${CMAKE_CURRENT_LIST_DIR}/serializable-interface.h" "${CMAKE_CURRENT_LIST_DIR}/max-usable-range-sensor.h" diff --git a/src/algo.cpp b/src/algo.cpp index bf7af03290..e6b3210f3a 100644 --- a/src/algo.cpp +++ b/src/algo.cpp @@ -224,14 +224,20 @@ void auto_exposure_algorithm::modify_exposure(float& exposure_value, bool& exp_m bool auto_exposure_algorithm::analyze_image(const frame_interface* image) { - region_of_interest image_roi = roi; + bool roi_initialized; + region_of_interest image_roi; + { + std::lock_guard< std::recursive_mutex > lock( state_mutex ); + roi_initialized = is_roi_initialized; + image_roi = roi; + } auto number_of_pixels = (image_roi.max_x - image_roi.min_x + 1)*(image_roi.max_y - image_roi.min_y + 1); if (number_of_pixels == 0) return false; // empty image auto frame = ((video_frame*)image); - if (!is_roi_initialized) + if (!roi_initialized) { auto width = frame->get_width(); auto height = frame->get_height(); diff --git a/src/auto-calibrated-device.h b/src/auto-calibrated-device.h index 50b2ff6dc6..a8835bbe0d 100644 --- a/src/auto-calibrated-device.h +++ b/src/auto-calibrated-device.h @@ -5,6 +5,7 @@ #include "types.h" #include "core/extension.h" #include +#include namespace librealsense diff --git a/src/auto-calibrated-proxy.cpp b/src/auto-calibrated-proxy.cpp new file mode 100644 index 0000000000..51713a51aa --- /dev/null +++ b/src/auto-calibrated-proxy.cpp @@ -0,0 +1,114 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2024 Intel Corporation. All Rights Reserved. + + +#include "auto-calibrated-proxy.h" +#include +#include +#include +#include + + +namespace librealsense +{ +auto_calibrated_proxy::auto_calibrated_proxy() +: _auto_calib_capability(nullptr){} + + +std::vector auto_calibrated_proxy::run_on_chip_calibration(int timeout_ms, std::string json, + float* const health, rs2_update_progress_callback_sptr progress_callback) +{ + if (_auto_calib_capability) + return _auto_calib_capability->run_on_chip_calibration(timeout_ms, json, health, progress_callback); + throw std::runtime_error("Auto Calibration capability has not been initiated"); +} + +void auto_calibrated_proxy::set_auto_calibration_capability(std::shared_ptr ac_cap) +{ + _auto_calib_capability = ac_cap; +} + +std::vector auto_calibrated_proxy::run_tare_calibration(int timeout_ms, float ground_truth_mm, std::string json, float* const health, rs2_update_progress_callback_sptr progress_callback) +{ + if (_auto_calib_capability) + return _auto_calib_capability->run_tare_calibration(timeout_ms, ground_truth_mm, json, health, progress_callback); + throw std::runtime_error("Auto Calibration capability has not been initiated"); +} + +std::vector auto_calibrated_proxy::process_calibration_frame(int timeout_ms, const rs2_frame* f, float* const health, rs2_update_progress_callback_sptr progress_callback) +{ + if (_auto_calib_capability) + return _auto_calib_capability->process_calibration_frame(timeout_ms, f, health, progress_callback); + throw std::runtime_error("Auto Calibration capability has not been initiated"); +} + +std::vector auto_calibrated_proxy::get_calibration_table() const +{ + if (_auto_calib_capability) + return _auto_calib_capability->get_calibration_table(); + throw std::runtime_error("Auto Calibration capability has not been initiated"); +} + +void auto_calibrated_proxy::write_calibration() const +{ + if (_auto_calib_capability) + _auto_calib_capability->write_calibration(); + else + throw std::runtime_error("Auto Calibration capability has not been initiated"); +} + +void auto_calibrated_proxy::set_calibration_table(const std::vector& calibration) +{ + if (_auto_calib_capability) + _auto_calib_capability->set_calibration_table(calibration); + else + throw std::runtime_error("Auto Calibration capability has not been initiated"); +} + +void auto_calibrated_proxy::reset_to_factory_calibration() const +{ + if (_auto_calib_capability) + return _auto_calib_capability->reset_to_factory_calibration(); + throw std::runtime_error("Auto Calibration capability has not been initiated"); +} + +std::vector auto_calibrated_proxy::run_focal_length_calibration(rs2_frame_queue* left, rs2_frame_queue* right, float target_w, float target_h, + int adjust_both_sides, float *ratio, float * angle, rs2_update_progress_callback_sptr progress_callback) +{ + if (_auto_calib_capability) + return _auto_calib_capability->run_focal_length_calibration(left, right, target_w, target_h, adjust_both_sides, ratio, angle, progress_callback); + throw std::runtime_error("Auto Calibration capability has not been initiated"); +} + +std::vector auto_calibrated_proxy::run_uv_map_calibration(rs2_frame_queue* left, rs2_frame_queue* color, rs2_frame_queue* depth, int py_px_only, + float* const health, int health_size, rs2_update_progress_callback_sptr progress_callback) +{ + if (_auto_calib_capability) + return _auto_calib_capability->run_uv_map_calibration(left, color, depth, py_px_only, health, health_size, progress_callback); + throw std::runtime_error("Auto Calibration capability has not been initiated"); +} + +float auto_calibrated_proxy::calculate_target_z(rs2_frame_queue* queue1, rs2_frame_queue* queue2, rs2_frame_queue* queue3, + float target_w, float target_h, rs2_update_progress_callback_sptr progress_callback) +{ + if (_auto_calib_capability) + return _auto_calib_capability->calculate_target_z(queue1, queue2, queue3, target_w, target_h, progress_callback); + throw std::runtime_error("Auto Calibration capability has not been initiated"); +} + +std::string auto_calibrated_proxy::get_calibration_config() const +{ + if (_auto_calib_capability) + return _auto_calib_capability->get_calibration_config(); + throw std::runtime_error("Auto Calibration capability has not been initiated"); +} + +void auto_calibrated_proxy::set_calibration_config(const std::string& calibration_config_json_str) const +{ + if (_auto_calib_capability) + _auto_calib_capability->set_calibration_config(calibration_config_json_str); + else + throw std::runtime_error("Auto Calibration capability has not been initiated"); +} + +} //namespace librealsense diff --git a/src/auto-calibrated-proxy.h b/src/auto-calibrated-proxy.h new file mode 100644 index 0000000000..cee84f4b01 --- /dev/null +++ b/src/auto-calibrated-proxy.h @@ -0,0 +1,39 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2024 Intel Corporation. All Rights Reserved. + +#pragma once + +#include + + +namespace librealsense +{ + +class calibration_engine_interface; +class auto_calibrated_proxy : public auto_calibrated_interface +{ +public: + auto_calibrated_proxy(); + void write_calibration() const override; + std::vector run_on_chip_calibration(int timeout_ms, std::string json, float* const health, rs2_update_progress_callback_sptr progress_callback) override; + std::vector run_tare_calibration(int timeout_ms, float ground_truth_mm, std::string json, float* const health, rs2_update_progress_callback_sptr progress_callback) override; + std::vector process_calibration_frame(int timeout_ms, const rs2_frame* f, float* const health, rs2_update_progress_callback_sptr progress_callback) override; + std::vector get_calibration_table() const override; + void set_calibration_table(const std::vector& calibration) override; + void reset_to_factory_calibration() const override; + std::vector run_focal_length_calibration(rs2_frame_queue* left, rs2_frame_queue* right, float target_w, float target_h, + int adjust_both_sides, float* ratio, float* angle, rs2_update_progress_callback_sptr progress_callback) override; + std::vector run_uv_map_calibration(rs2_frame_queue* left, rs2_frame_queue* color, rs2_frame_queue* depth, int py_px_only, + float* const health, int health_size, rs2_update_progress_callback_sptr progress_callback) override; + float calculate_target_z(rs2_frame_queue* queue1, rs2_frame_queue* queue2, rs2_frame_queue* queue3, + float target_width, float target_height, rs2_update_progress_callback_sptr progress_callback) override; + std::string get_calibration_config() const override; + void set_calibration_config(const std::string& calibration_config_json_str) const override; + + void set_auto_calibration_capability(std::shared_ptr ac_cap); + +private: + std::shared_ptr _auto_calib_capability; +}; + +} // namespace librealsense diff --git a/src/calibration-engine-interface.h b/src/calibration-engine-interface.h new file mode 100644 index 0000000000..611ca68ff7 --- /dev/null +++ b/src/calibration-engine-interface.h @@ -0,0 +1,52 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2024 Intel Corporation. All Rights Reserved. + +#pragma once + +#include + + +namespace librealsense +{ + +enum class calibration_state : uint8_t +{ + IDLE = 0, + PROCESS, + SUCCESS, + FAILURE, + FLASH_UPDATE, + COMPLETE +}; + +enum class calibration_result : uint8_t +{ + UNKNOWN = 0, + SUCCESS, + FAILED_TO_CONVERGE, + FAILED_TO_RUN +}; + +enum class calibration_mode +{ + RESERVED = 0, + RUN, + ABORT, + DRY_RUN +}; + +class calibration_engine_interface +{ +public: + virtual void update_triggered_calibration_status() = 0; + virtual std::vector run_triggered_calibration(calibration_mode _mode) = 0; + virtual calibration_state get_triggered_calibration_state() const = 0; + virtual calibration_result get_triggered_calibration_result() const = 0; + virtual int8_t get_triggered_calibration_progress() const = 0; + virtual std::vector get_calibration_table(std::vector& current_calibration) const = 0; + virtual void write_calibration(std::vector& calibration) const = 0; + virtual std::string get_calibration_config() const = 0; + virtual void set_calibration_config(const std::string& calibration_config_json_str) const = 0; +}; + +} // namespace librealsense diff --git a/src/context.h b/src/context.h index 807bcea842..f8151ac648 100644 --- a/src/context.h +++ b/src/context.h @@ -67,10 +67,11 @@ namespace librealsense std::shared_ptr< processing_block_interface > create_pp_block( std::string const & name, rsutils::json const & settings ); - private: + void invoke_devices_changed_callbacks( std::vector< std::shared_ptr< device_info > > const & devices_removed, std::vector< std::shared_ptr< device_info > > const & devices_added ); + private: std::map< std::string /*address*/, std::weak_ptr< device_info > > _user_devices; rsutils::signal< std::vector< std::shared_ptr< device_info > > const & /*removed*/, diff --git a/src/core/notification.cpp b/src/core/notification.cpp index 8998c6edd5..6105305886 100644 --- a/src/core/notification.cpp +++ b/src/core/notification.cpp @@ -48,6 +48,7 @@ void notifications_processor::set_callback( rs2_notifications_callback_sptr call rs2_notifications_callback_sptr notifications_processor::get_callback() const { + std::lock_guard< std::mutex > lock( _callback_mutex ); return _callback; } diff --git a/src/core/notification.h b/src/core/notification.h index f023323b68..b9c70ef9f7 100644 --- a/src/core/notification.h +++ b/src/core/notification.h @@ -47,7 +47,7 @@ class notifications_processor private: rs2_notifications_callback_sptr _callback; - std::mutex _callback_mutex; + mutable std::mutex _callback_mutex; dispatcher _dispatcher; }; diff --git a/src/core/options-container.cpp b/src/core/options-container.cpp index 3058e15810..f38ece59d1 100644 --- a/src/core/options-container.cpp +++ b/src/core/options-container.cpp @@ -1,5 +1,5 @@ // License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2023 Intel Corporation. All Rights Reserved. +// Copyright(c) 2023-4 Intel Corporation. All Rights Reserved. #include "options-container.h" #include "enum-helpers.h" @@ -12,8 +12,8 @@ namespace librealsense { const option & options_container::get_option( rs2_option id ) const { - auto it = _options.find( id ); - if( it == _options.end() ) + auto it = _options_by_id.find( id ); + if( it == _options_by_id.end() ) { throw invalid_value_exception( rsutils::string::from() << "option '" << get_option_name( id ) << "' not supported" ); @@ -27,17 +27,47 @@ void options_container::update( std::shared_ptr< extension_snapshot > ext ) auto ctr = As< options_container >( ext ); if( ! ctr ) return; - for( auto && opt : ctr->_options ) + for( auto id : ctr->_ordered_options ) { - _options[opt.first] = opt.second; + auto & opt = _options_by_id[id]; + if( ! opt ) + _ordered_options.push_back( id ); + opt = ctr->_options_by_id[id]; } } +void options_container::register_option( rs2_option id, std::shared_ptr< option > option ) +{ + auto & opt = _options_by_id[id]; + if( ! opt ) + _ordered_options.push_back( id ); + opt = option; + _recording_function( *this ); +} + + +void options_container::unregister_option( rs2_option id ) +{ + for( auto it = _ordered_options.begin(); it != _ordered_options.end(); ++it ) + { + if( *it == id ) + { + _ordered_options.erase( it ); + break; + } + } + _options_by_id.erase( id ); +} + + std::vector< rs2_option > options_container::get_supported_options() const { + // Return options ordered by their ID values! This means custom options will be first! + // Kept for backwards compatibility with existing devices; software sensors will return the _ordered_options + std::vector< rs2_option > options; - for( auto option : _options ) + for( auto option : _options_by_id ) options.push_back( option.first ); return options; diff --git a/src/core/options-container.h b/src/core/options-container.h index fb7f7e8f2f..8ddd80ec85 100644 --- a/src/core/options-container.h +++ b/src/core/options-container.h @@ -1,5 +1,5 @@ // License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2015 Intel Corporation. All Rights Reserved. +// Copyright(c) 2015-24 Intel Corporation. All Rights Reserved. #pragma once #include "options-interface.h" @@ -24,8 +24,9 @@ class LRS_EXTENSION_API options_container : public virtual options_interface, pu public: bool supports_option(rs2_option id) const override { - auto it = _options.find(id); - if (it == _options.end()) return false; + auto it = _options_by_id.find( id ); + if( it == _options_by_id.end() ) + return false; return it->second->is_enabled(); } @@ -41,22 +42,16 @@ class LRS_EXTENSION_API options_container : public virtual options_interface, pu return (const_cast(this)->get_option_handler(id)); } - std::shared_ptr