From ee4242f1ed2b36602e28a5c798fc7fe1fcdc1b42 Mon Sep 17 00:00:00 2001 From: Eran Date: Sat, 14 Oct 2023 11:52:21 +0300 Subject: [PATCH 1/7] hexdump better performance; make sure it listens to std::ios::uppercase --- third-party/rsutils/src/hexdump.cpp | 50 +++++++-------------- unit-tests/rsutils/string/test-hexarray.cpp | 6 +++ 2 files changed, 21 insertions(+), 35 deletions(-) diff --git a/third-party/rsutils/src/hexdump.cpp b/third-party/rsutils/src/hexdump.cpp index 28282acf49..6ad7db78a3 100644 --- a/third-party/rsutils/src/hexdump.cpp +++ b/third-party/rsutils/src/hexdump.cpp @@ -11,32 +11,18 @@ namespace { -struct _stream_saver -{ - std::ostream & _os; - std::ios_base::fmtflags _flags; - char _fill; - - _stream_saver( std::ostream & os ) - : _os( os ) - , _flags( os.flags() ) - , _fill( os.fill() ) - { - } - - ~_stream_saver() - { - _os.fill( _fill ); - _os.setf( _flags ); - } -}; - - size_t _write( std::ostream & os, uint8_t const * const data, size_t cb ) { + char const first_letter = ( os.flags() & std::ios::uppercase ) ? 'A' : 'a'; uint8_t const * pb = data; while( cb-- > 0 ) - os << std::setw( 2 ) << int( *pb++ ); + { + uint8_t const hb = ( *pb >> 4 ); + os.put( char( hb > 9 ? ( hb - 10 + first_letter) : ( hb + '0' ) ) ); + uint8_t const lb = ( *pb & 0x0f ); + os.put( char( lb > 9 ? ( lb - 10 + first_letter ) : ( lb + '0' ) ) ); + ++pb; + } return pb - data; } @@ -46,13 +32,15 @@ void _write_reverse( std::ostream & os, uint8_t const * const data, size_t cb, b if( skip_leading_0s ) while( cb > 1 && ! data[cb - 1] ) --cb; - else - os << std::setw( 2 ); + char const first_letter = ( os.flags() & std::ios::uppercase ) ? 'A' : 'a'; while( cb-- > 0 ) { - os << int( data[cb] ); - if( cb ) - os << std::setw( 2 ); + uint8_t const hb = ( data[cb] >> 4 ); + if( ! skip_leading_0s || hb != 0 ) + os.put( char( hb > 9 ? ( hb - 10 + first_letter ) : ( hb + '0' ) ) ); + uint8_t const lb = ( data[cb] & 0x0f ); + os.put( char( lb > 9 ? ( lb - 10 + first_letter ) : ( lb + '0' ) ) ); + skip_leading_0s = false; } } @@ -78,10 +66,6 @@ std::ostream & operator<<( std::ostream & os, hexdump const & h ) if( ! h._cb ) return os; - _stream_saver state( os ); - os << std::hex; - os.fill( '0' ); - auto pb = h._data; size_t n_left = h._cb; if( h._max_bytes ) @@ -112,10 +96,6 @@ std::ostream & operator<<( std::ostream & os, hexdump const & h ) std::ostream & operator<<( std::ostream & os, hexdump::_format const & f ) { - _stream_saver state( os ); - os << std::hex; - os.fill( '0' ); - auto pb = f._h._data; size_t n_left = f._h._max_bytes ? f._h._max_bytes : f._h._cb; auto pend = pb + f._h._cb; diff --git a/unit-tests/rsutils/string/test-hexarray.cpp b/unit-tests/rsutils/string/test-hexarray.cpp index 7ebe3e220c..62cdec7438 100644 --- a/unit-tests/rsutils/string/test-hexarray.cpp +++ b/unit-tests/rsutils/string/test-hexarray.cpp @@ -89,6 +89,12 @@ TEST_CASE( "hexdump", "[hexarray]" ) #pragma pack( pop ) CHECK( to_string( hexdump( s ) ) == "04030201060578" ); } + SECTION( "case" ) + { + int i = 0x0a0b0c0d; + CHECK( to_string( hexdump( i ) ) == "0a0b0c0d" ); + CHECK( ( from() << std::uppercase << hexdump( i ) ).str() == "0A0B0C0D" ); + } } TEST_CASE( "hexdump of bytearray", "[hexarray]" ) From 3bebea75767dfdaa5a36d16ab56875a530370669 Mon Sep 17 00:00:00 2001 From: Eran Date: Sat, 14 Oct 2023 12:11:53 +0300 Subject: [PATCH 2/7] remove hexify usage --- src/ds/advanced_mode/advanced_mode.cpp | 12 ++++++++---- src/ds/d400/d400-device.cpp | 3 ++- src/ds/d500/d500-device.cpp | 4 +++- src/fw-update/fw-update-device.cpp | 7 ++++++- src/hid/hid-device.cpp | 8 ++++++-- src/types.h | 10 ---------- 6 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/ds/advanced_mode/advanced_mode.cpp b/src/ds/advanced_mode/advanced_mode.cpp index 16bb0a3d66..ecfcf77dbe 100644 --- a/src/ds/advanced_mode/advanced_mode.cpp +++ b/src/ds/advanced_mode/advanced_mode.cpp @@ -5,7 +5,9 @@ #include "json_loader.hpp" #include "ds/d400/d400-color.h" #include "ds/d500/d500-color.h" + #include +#include namespace librealsense { @@ -128,8 +130,10 @@ namespace librealsense default_450_high_res(p); break; default: - throw invalid_value_exception( rsutils::string::from() << "apply_preset(...) failed! Given device doesn't support Default Preset (pid=0x" << - std::hex << device_pid << ")"); + throw invalid_value_exception( + rsutils::string::from() + << "apply_preset(...) failed! Given device doesn't support Default Preset (pid=0x" + << rsutils::string::hexdump( device_pid ) << ")" ); break; } case ds::RS405U_PID: @@ -147,8 +151,8 @@ namespace librealsense default: throw invalid_value_exception( rsutils::string::from() - << "apply_preset(...) failed! Given device doesn't support Default Preset (pid=0x" << std::hex - << device_pid << ")" ); + << "apply_preset(...) failed! Given device doesn't support Default Preset (pid=0x" + << rsutils::string::hexdump( device_pid ) << ")" ); break; } break; diff --git a/src/ds/d400/d400-device.cpp b/src/ds/d400/d400-device.cpp index 9aa0c143e3..e4f03d7c8f 100644 --- a/src/ds/d400/d400-device.cpp +++ b/src/ds/d400/d400-device.cpp @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -634,7 +635,7 @@ namespace librealsense } - pid_hex_str = hexify(_pid); + pid_hex_str = rsutils::string::from() << std::uppercase << rsutils::string::hexdump( _pid ); if ((_pid == RS416_PID || _pid == RS416_RGB_PID) && _fw_version >= firmware_version("5.12.0.1")) { diff --git a/src/ds/d500/d500-device.cpp b/src/ds/d500/d500-device.cpp index 725fccd79b..48c89ffcce 100644 --- a/src/ds/d500/d500-device.cpp +++ b/src/ds/d500/d500-device.cpp @@ -29,6 +29,8 @@ #include "hdr-config.h" #include "../common/fw/firmware-version.h" #include "fw-update/fw-update-unsigned.h" + +#include #include #include #include @@ -494,7 +496,7 @@ namespace librealsense []() {return std::make_shared(); } ); - pid_hex_str = hexify(_pid); + pid_hex_str = rsutils::string::from() << std::uppercase << rsutils::string::hexdump( _pid ); _is_locked = _ds_device_common->is_locked(GVD, is_camera_locked_offset); diff --git a/src/fw-update/fw-update-device.cpp b/src/fw-update/fw-update-device.cpp index f9ff9721bf..d214c090b1 100644 --- a/src/fw-update/fw-update-device.cpp +++ b/src/fw-update/fw-update-device.cpp @@ -7,6 +7,8 @@ #include "../device-info.h" #include "ds/d400/d400-private.h" +#include + #include #include #include @@ -112,7 +114,10 @@ namespace librealsense update_device::update_device( std::shared_ptr< const device_info > const & dev_info, std::shared_ptr< platform::usb_device > const & usb_device ) - : _dev_info(dev_info), _usb_device(usb_device), _physical_port( usb_device->get_info().id), _pid(hexify(usb_device->get_info().pid)) + : _dev_info( dev_info ) + , _usb_device( usb_device ) + , _physical_port( usb_device->get_info().id ) + , _pid( rsutils::string::from() << std::uppercase << rsutils::string::hexdump( usb_device->get_info().pid ) ) { if (auto messenger = _usb_device->open(FW_UPDATE_INTERFACE_NUMBER)) { diff --git a/src/hid/hid-device.cpp b/src/hid/hid-device.cpp index f5a9ec96da..c0db683d35 100644 --- a/src/hid/hid-device.cpp +++ b/src/hid/hid-device.cpp @@ -4,6 +4,10 @@ #include #include "hid-device.h" +#include +#include + + const int USB_REQUEST_COUNT = 1; namespace librealsense @@ -20,8 +24,8 @@ namespace librealsense if(info.cls != RS2_USB_CLASS_HID) continue; platform::hid_device_info device_info; - device_info.vid = hexify(info.vid); - device_info.pid = hexify(info.pid); + device_info.vid = rsutils::string::from() << std::uppercase << rsutils::string::hexdump( info.vid ); + device_info.pid = rsutils::string::from() << std::uppercase << rsutils::string::hexdump( info.pid ); device_info.unique_id = info.unique_id; device_info.device_path = info.unique_id;//the device unique_id is the USB port diff --git a/src/types.h b/src/types.h index dea8ac20e9..cc92c46c36 100644 --- a/src/types.h +++ b/src/types.h @@ -175,16 +175,6 @@ namespace librealsense return false; } - template - std::string hexify(const T& val) - { - static_assert((std::is_integral::value), "hexify supports integral built-in types only"); - - std::ostringstream oss; - oss << std::setw(sizeof(T)*2) << std::setfill('0') << std::uppercase << std::hex << val; - return oss.str().c_str(); - } - void copy(void* dst, void const* src, size_t size); std::string make_less_screamy(const char* str); From dd13027f032a5fd3dc1e7221554c65b0e5e19e10 Mon Sep 17 00:00:00 2001 From: Eran Date: Sat, 14 Oct 2023 12:13:26 +0300 Subject: [PATCH 3/7] move make_less_screamy to rsutils --- src/core/enum-helpers.h | 4 +++ src/ds/advanced_mode/rs_advanced_mode.cpp | 12 +++++-- src/to-string.cpp | 7 ++-- src/types.h | 3 -- .../rsutils/string/make-less-screamy.h | 23 +++++++++++++ third-party/rsutils/src/make-less-screamy.cpp | 33 +++++++++++++++++++ 6 files changed, 74 insertions(+), 8 deletions(-) create mode 100644 third-party/rsutils/include/rsutils/string/make-less-screamy.h create mode 100644 third-party/rsutils/src/make-less-screamy.cpp diff --git a/src/core/enum-helpers.h b/src/core/enum-helpers.h index 4c3c3d0801..c7626788d6 100644 --- a/src/core/enum-helpers.h +++ b/src/core/enum-helpers.h @@ -3,9 +3,13 @@ #pragma once +#include #include +#define UNKNOWN_VALUE "UNKNOWN" + + namespace librealsense { diff --git a/src/ds/advanced_mode/rs_advanced_mode.cpp b/src/ds/advanced_mode/rs_advanced_mode.cpp index 0513b63e02..eb5d9540f6 100644 --- a/src/ds/advanced_mode/rs_advanced_mode.cpp +++ b/src/ds/advanced_mode/rs_advanced_mode.cpp @@ -9,9 +9,15 @@ #include "core/advanced_mode.h" #include "api.h" -#define STRCASE(T, X) case RS2_##T##_##X: {\ - static std::string s##T##_##X##_str = make_less_screamy(#X);\ - return s##T##_##X##_str.c_str(); } +#include + + + +#define STRCASE( T, X ) \ + case RS2_##T##_##X: { \ + static std::string s##T##_##X##_str = rsutils::string::make_less_screamy( #X ); \ + return s##T##_##X##_str.c_str(); \ + } namespace librealsense { diff --git a/src/to-string.cpp b/src/to-string.cpp index cf3ddb4053..647f9eeab0 100644 --- a/src/to-string.cpp +++ b/src/to-string.cpp @@ -1,11 +1,14 @@ // License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2021 Intel Corporation. All Rights Reserved. -#include "types.h" #include "core/options-registry.h" +#include "core/enum-helpers.h" +#include +#include -#define STRX( X ) make_less_screamy( #X ) + +#define STRX( X ) rsutils::string::make_less_screamy( #X ) #define STRCASE( T, X ) \ case RS2_##T##_##X: { \ static const std::string s##T##_##X##_str = STRX( X ); \ diff --git a/src/types.h b/src/types.h index cc92c46c36..0987e7d6a0 100644 --- a/src/types.h +++ b/src/types.h @@ -58,7 +58,6 @@ using std::abs; #include "../common/android_helpers.h" #endif -#define UNKNOWN_VALUE "UNKNOWN" namespace librealsense { @@ -177,8 +176,6 @@ namespace librealsense void copy(void* dst, void const* src, size_t size); - std::string make_less_screamy(const char* str); - /////////////////////// // Logging mechanism // /////////////////////// diff --git a/third-party/rsutils/include/rsutils/string/make-less-screamy.h b/third-party/rsutils/include/rsutils/string/make-less-screamy.h new file mode 100644 index 0000000000..1d69110b9b --- /dev/null +++ b/third-party/rsutils/include/rsutils/string/make-less-screamy.h @@ -0,0 +1,23 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2023 Intel Corporation. All Rights Reserved. + +#pragma once + +#include + + +namespace rsutils { +namespace string { + + +// Convert a typically all-uppercase, underscore-delimited identifier (e.g., "PRODUCT_LINE_D500") to a more +// human-readable form (e.g., "Product Line D500"). +// +// - underscores are replaced by spaces +// - letters are made lower-case; the beginning of a words upper-case +// +std::string make_less_screamy( std::string ); + + +} // namespace string +} // namespace rsutils diff --git a/third-party/rsutils/src/make-less-screamy.cpp b/third-party/rsutils/src/make-less-screamy.cpp new file mode 100644 index 0000000000..1ccb3e2c6e --- /dev/null +++ b/third-party/rsutils/src/make-less-screamy.cpp @@ -0,0 +1,33 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2023 Intel Corporation. All Rights Reserved. + +#include + + +namespace rsutils { +namespace string { + + +std::string make_less_screamy( std::string res ) +{ + bool first = true; + for( char & ch : res ) + { + if( ch != '_' ) + { + if( ! first ) + ch = tolower( ch ); + first = false; + } + else + { + ch = ' '; + first = true; + } + } + return res; +} + + +} // namespace string +} // namespace rsutils From 5848a776832f8a29b7e9e32035f278e0b3dc5505 Mon Sep 17 00:00:00 2001 From: Eran Date: Sat, 14 Oct 2023 14:23:34 +0300 Subject: [PATCH 4/7] librealsense::copy -> std::memcpy --- src/ds/d400/d400-private.cpp | 2 +- src/ds/d500/d500-private.cpp | 4 ++- src/ds/ds-calib-parsers.cpp | 4 +-- src/ds/ds-private.cpp | 2 +- src/hw-monitor.cpp | 18 +++++++------ src/hw-monitor.h | 4 ++- src/linux/backend-v4l2.cpp | 2 +- src/mf/mf-uvc.cpp | 8 +++--- src/proc/color-formats-converter.cpp | 38 ++++++++++++++-------------- src/proc/depth-formats-converter.cpp | 6 ++--- src/proc/motion-transform.cpp | 2 +- src/proc/rotation-transform.cpp | 2 +- src/types.cpp | 9 +------ src/types.h | 2 -- 14 files changed, 50 insertions(+), 53 deletions(-) diff --git a/src/ds/d400/d400-private.cpp b/src/ds/d400/d400-private.cpp index 86aca2f1b3..d3cb525b6d 100644 --- a/src/ds/d400/d400-private.cpp +++ b/src/ds/d400/d400-private.cpp @@ -256,7 +256,7 @@ namespace librealsense intrin(1, 1) * height / 2.f, RS2_DISTORTION_INVERSE_BROWN_CONRADY // The coefficients shall be use for undistort }; - librealsense::copy(calc_intrinsic.coeffs, table->distortion, sizeof(table->distortion)); + std::memcpy(calc_intrinsic.coeffs, table->distortion, sizeof(table->distortion)); //LOG_DEBUG(endl << array2str((float_4&)(calc_intrinsic.fx, calc_intrinsic.fy, calc_intrinsic.ppx, calc_intrinsic.ppy)) << endl); static rs2_intrinsics ref{}; diff --git a/src/ds/d500/d500-private.cpp b/src/ds/d500/d500-private.cpp index 3ab924c4fd..0d604d77f1 100644 --- a/src/ds/d500/d500-private.cpp +++ b/src/ds/d500/d500-private.cpp @@ -228,7 +228,9 @@ namespace librealsense intrinsics.ppx = rect_params[2]; intrinsics.ppy = rect_params[3]; intrinsics.model = table->rgb_coefficients_table.distortion_model; - librealsense::copy(intrinsics.coeffs, table->rgb_coefficients_table.distortion_coeffs, sizeof(intrinsics.coeffs)); + std::memcpy( intrinsics.coeffs, + table->rgb_coefficients_table.distortion_coeffs, + sizeof( intrinsics.coeffs ) ); update_table_to_correct_fisheye_distortion(const_cast(*table), intrinsics); diff --git a/src/ds/ds-calib-parsers.cpp b/src/ds/ds-calib-parsers.cpp index ec5e6ad7cd..aa1e478576 100644 --- a/src/ds/ds-calib-parsers.cpp +++ b/src/ds/ds-calib-parsers.cpp @@ -189,7 +189,7 @@ namespace librealsense if (_valid_extrinsic) { // extrinsic from calibration table, by user custom calibration, The extrinsic is stored as array of floats / little-endian - librealsense::copy(&_extr, &_calib_table.module_info.dm_v2_calib_table.depth_to_imu, sizeof(rs2_extrinsics)); + std::memcpy( &_extr, &_calib_table.module_info.dm_v2_calib_table.depth_to_imu, sizeof( rs2_extrinsics ) ); } else { @@ -300,7 +300,7 @@ namespace librealsense if (_valid_extrinsic) { // only in case valid extrinsic is available in calibration data by calibration script in future or user custom calibration - librealsense::copy(&_extr, &imu_calib_table.depth_to_imu, sizeof(rs2_extrinsics)); + std::memcpy( &_extr, &imu_calib_table.depth_to_imu, sizeof( rs2_extrinsics ) ); } else { diff --git a/src/ds/ds-private.cpp b/src/ds/ds-private.cpp index ed0c8c1e37..e2beb52c39 100644 --- a/src/ds/ds-private.cpp +++ b/src/ds/ds-private.cpp @@ -35,7 +35,7 @@ namespace librealsense intrinsics.height = height; intrinsics.width = width; - librealsense::copy(intrinsics.coeffs, table->distortion, sizeof(table->distortion)); + std::memcpy( intrinsics.coeffs, table->distortion, sizeof( table->distortion ) ); LOG_DEBUG(endl << array2str((float_4&)(intrinsics.fx, intrinsics.fy, intrinsics.ppx, intrinsics.ppy)) << endl); diff --git a/src/hw-monitor.cpp b/src/hw-monitor.cpp index d835422f18..b24b7e6237 100644 --- a/src/hw-monitor.cpp +++ b/src/hw-monitor.cpp @@ -55,7 +55,7 @@ namespace librealsense if (dataLength) { - librealsense::copy(writePtr + cur_index, data, dataLength); + std::memcpy( writePtr + cur_index, data, dataLength ); cur_index += dataLength; } @@ -112,7 +112,7 @@ namespace librealsense // throw invalid_value_exception("bulk transfer failed - user buffer too small"); inSize = std::min(res.size(),inSize); // For D457 only - librealsense::copy(in, res.data(), inSize); + std::memcpy( in, res.data(), inSize ); } } @@ -126,10 +126,10 @@ namespace librealsense throw invalid_value_exception("received incomplete response to usb command"); details.receivedCommandDataLength -= 4; - librealsense::copy(details.receivedOpcode.data(), outputBuffer, 4); + std::memcpy( details.receivedOpcode.data(), outputBuffer, 4 ); if (details.receivedCommandDataLength > 0) - librealsense::copy(details.receivedCommandData.data(), outputBuffer + 4, details.receivedCommandDataLength); + std::memcpy( details.receivedCommandData.data(), outputBuffer + 4, details.receivedCommandDataLength ); } void hw_monitor::send_hw_monitor_command(hwmon_cmd_details& details) const @@ -182,8 +182,10 @@ namespace librealsense if( !newCommand.require_response ) return std::vector(); - librealsense::copy(newCommand.receivedOpcode, details.receivedOpcode.data(), 4); - librealsense::copy(newCommand.receivedCommandData, details.receivedCommandData.data(), details.receivedCommandDataLength); + std::memcpy( newCommand.receivedOpcode, details.receivedOpcode.data(), 4 ); + std::memcpy( newCommand.receivedCommandData, + details.receivedCommandData.data(), + details.receivedCommandDataLength ); newCommand.receivedCommandDataLength = details.receivedCommandDataLength; // endian? @@ -243,7 +245,7 @@ namespace librealsense command command(gvd_cmd); auto data = send(command); auto minSize = std::min(sz, data.size()); - librealsense::copy(gvd, data.data(), minSize); + std::memcpy( gvd, data.data(), minSize ); } bool hw_monitor::is_camera_locked(uint8_t gvd_cmd, uint32_t offset) const @@ -251,7 +253,7 @@ namespace librealsense std::vector gvd(HW_MONITOR_BUFFER_SIZE); get_gvd(gvd.size(), gvd.data(), gvd_cmd); bool value; - librealsense::copy(&value, gvd.data() + offset, 1); + std::memcpy( &value, gvd.data() + offset, 1 ); return value; } } diff --git a/src/hw-monitor.h b/src/hw-monitor.h index 1d133324e1..9161107049 100644 --- a/src/hw-monitor.h +++ b/src/hw-monitor.h @@ -6,6 +6,8 @@ #include "uvc-sensor.h" #include #include "platform/command-transfer.h" +#include + namespace librealsense { @@ -296,7 +298,7 @@ namespace librealsense require_response(cmd.require_response), receivedCommandDataLength(0) { - librealsense::copy(data, cmd.data.data(), sizeOfSendCommandData); + std::memcpy( data, cmd.data.data(), sizeOfSendCommandData ); } }; diff --git a/src/linux/backend-v4l2.cpp b/src/linux/backend-v4l2.cpp index fe0ae20505..b656865fe8 100644 --- a/src/linux/backend-v4l2.cpp +++ b/src/linux/backend-v4l2.cpp @@ -1296,7 +1296,7 @@ namespace librealsense { uint32_t device_fourcc = id; char fourcc_buff[sizeof(device_fourcc)+1]; - librealsense::copy(fourcc_buff, &device_fourcc, sizeof(device_fourcc)); + std::memcpy( fourcc_buff, &device_fourcc, sizeof( device_fourcc ) ); fourcc_buff[sizeof(device_fourcc)] = 0; return fourcc_buff; } diff --git a/src/mf/mf-uvc.cpp b/src/mf/mf-uvc.cpp index da3301a45d..6812262661 100644 --- a/src/mf/mf-uvc.cpp +++ b/src/mf/mf-uvc.cpp @@ -362,13 +362,13 @@ namespace librealsense auto pStruct = next_struct; cfg.step.resize(option_range_size); - librealsense::copy(cfg.step.data(), pStruct, field_width); + std::memcpy( cfg.step.data(), pStruct, field_width ); pStruct += length; cfg.min.resize(option_range_size); - librealsense::copy(cfg.min.data(), pStruct, field_width); + std::memcpy( cfg.min.data(), pStruct, field_width ); pStruct += length; cfg.max.resize(option_range_size); - librealsense::copy(cfg.max.data(), pStruct, field_width); + std::memcpy( cfg.max.data(), pStruct, field_width ); return; } case KSPROPERTY_MEMBER_VALUES: @@ -386,7 +386,7 @@ namespace librealsense } cfg.def.resize(option_range_size); - librealsense::copy(cfg.def.data(), next_struct, field_width); + std::memcpy( cfg.def.data(), next_struct, field_width ); } return; } diff --git a/src/proc/color-formats-converter.cpp b/src/proc/color-formats-converter.cpp index 3e32c38572..cb66c9c6f0 100644 --- a/src/proc/color-formats-converter.cpp +++ b/src/proc/color-formats-converter.cpp @@ -232,7 +232,7 @@ namespace librealsense src[16], src[18], src[20], src[22], src[24], src[26], src[28], src[30], }; - librealsense::copy(dst, out, sizeof out); + std::memcpy( dst, out, sizeof out ); dst += sizeof out; continue; } @@ -246,7 +246,7 @@ namespace librealsense 0, src[16], 0, src[18], 0, src[20], 0, src[22], 0, src[24], 0, src[26], 0, src[28], 0, src[30], }; - librealsense::copy(dst, out, sizeof out); + std::memcpy(dst, out, sizeof out); dst += sizeof out; continue; } @@ -295,7 +295,7 @@ namespace librealsense r[12], g[12], b[12], r[13], g[13], b[13], r[14], g[14], b[14], r[15], g[15], b[15], }; - librealsense::copy(dst, out, sizeof out); + std::memcpy( dst, out, sizeof out ); dst += sizeof out; continue; } @@ -312,7 +312,7 @@ namespace librealsense b[12], g[12], r[12], b[13], g[13], r[13], b[14], g[14], r[14], b[15], g[15], r[15], }; - librealsense::copy(dst, out, sizeof out); + std::memcpy( dst, out, sizeof out ); dst += sizeof out; continue; } @@ -329,7 +329,7 @@ namespace librealsense r[12], g[12], b[12], 255, r[13], g[13], b[13], 255, r[14], g[14], b[14], 255, r[15], g[15], b[15], 255, }; - librealsense::copy(dst, out, sizeof out); + std::memcpy( dst, out, sizeof out ); dst += sizeof out; continue; } @@ -346,7 +346,7 @@ namespace librealsense b[12], g[12], r[12], 255, b[13], g[13], r[13], 255, b[14], g[14], r[14], 255, b[15], g[15], r[15], 255, }; - librealsense::copy(dst, out, sizeof out); + std::memcpy( dst, out, sizeof out ); dst += sizeof out; continue; } @@ -362,7 +362,7 @@ namespace librealsense { // grabbing matching y,u,v values uint8_t y[16] = { 0 }; - librealsense::copy(y, &y_one_line[y_pix], 16); + std::memcpy( y, &y_one_line[y_pix], 16 ); uint8_t u[16] = { uv_one_line[uv_pix + 0], uv_one_line[uv_pix + 0], uv_one_line[uv_pix + 2], uv_one_line[uv_pix + 2], @@ -407,7 +407,7 @@ namespace librealsense r[12], g[12], b[12], r[13], g[13], b[13], r[14], g[14], b[14], r[15], g[15], b[15] }; - librealsense::copy(*dst, out, sizeof(out)); + std::memcpy( *dst, out, sizeof( out ) ); *dst += sizeof out; continue; } @@ -424,7 +424,7 @@ namespace librealsense b[12], g[12], r[12], b[13], g[13], r[13], b[14], g[14], r[14], b[15], g[15], r[15], }; - librealsense::copy(*dst, out, sizeof out); + std::memcpy( *dst, out, sizeof out ); *dst += sizeof out; continue; } @@ -441,7 +441,7 @@ namespace librealsense r[12], g[12], b[12], 255, r[13], g[13], b[13], 255, r[14], g[14], b[14], 255, r[15], g[15], b[15], 255, }; - librealsense::copy(*dst, out, sizeof out); + std::memcpy( *dst, out, sizeof out ); *dst += sizeof out; continue; } @@ -458,7 +458,7 @@ namespace librealsense b[12], g[12], r[12], 255, b[13], g[13], r[13], 255, b[14], g[14], r[14], 255, b[15], g[15], r[15], 255, }; - librealsense::copy(*dst, out, sizeof out); + std::memcpy( *dst, out, sizeof out ); *dst += sizeof out; continue; } @@ -700,7 +700,7 @@ namespace librealsense // fill the destination with y values // while y is on 2 lines, and uv on the third line auto start_of_y = src + k * width; - librealsense::copy(dst, start_of_y, 2 * width); + std::memcpy( dst, start_of_y, 2 * width ); dst += 2 * width; } return; @@ -720,7 +720,7 @@ namespace librealsense { y[dst_idx] = start_of_y[src_idx + pix] << 8; } - librealsense::copy(dst, y, sizeof y); + std::memcpy( dst, y, sizeof y ); dst += sizeof y; } } @@ -986,7 +986,7 @@ namespace librealsense r[12], g[12], b[12], r[13], g[13], b[13], r[14], g[14], b[14], r[15], g[15], b[15], }; - librealsense::copy(dst, out, sizeof out); + std::memcpy( dst, out, sizeof out ); dst += sizeof out; continue; } @@ -1003,7 +1003,7 @@ namespace librealsense b[12], g[12], r[12], b[13], g[13], r[13], b[14], g[14], r[14], b[15], g[15], r[15], }; - librealsense::copy(dst, out, sizeof out); + std::memcpy( dst, out, sizeof out ); dst += sizeof out; continue; } @@ -1020,7 +1020,7 @@ namespace librealsense r[12], g[12], b[12], 255, r[13], g[13], b[13], 255, r[14], g[14], b[14], 255, r[15], g[15], b[15], 255, }; - librealsense::copy(dst, out, sizeof out); + std::memcpy( dst, out, sizeof out ); dst += sizeof out; continue; } @@ -1037,7 +1037,7 @@ namespace librealsense b[12], g[12], r[12], 255, b[13], g[13], r[13], 255, b[14], g[14], r[14], 255, b[15], g[15], r[15], 255, }; - librealsense::copy(dst, out, sizeof out); + std::memcpy( dst, out, sizeof out ); dst += sizeof out; continue; } @@ -1077,7 +1077,7 @@ namespace librealsense if (uncompressed_rgb) { auto uncompressed_size = w * h * bpp; - librealsense::copy(dest[0], uncompressed_rgb, uncompressed_size); + std::memcpy( dest[0], uncompressed_rgb, uncompressed_size ); stbi_image_free(uncompressed_rgb); } else @@ -1093,7 +1093,7 @@ namespace librealsense auto in = reinterpret_cast(source); auto out = reinterpret_cast(dest[0]); - librealsense::copy(out, in, count * 3); + std::memcpy( out, in, count * 3 ); for (auto i = 0; i < count; i++) { std::swap(out[i * 3], out[i * 3 + 2]); diff --git a/src/proc/depth-formats-converter.cpp b/src/proc/depth-formats-converter.cpp index 40e6c235df..756b3896f1 100644 --- a/src/proc/depth-formats-converter.cpp +++ b/src/proc/depth-formats-converter.cpp @@ -22,7 +22,7 @@ namespace librealsense #else for (int i = 0; i < count; ++i) *out_ir++ = *in++ >> 2; #endif - librealsense::copy(dest[0], in, count * 2); + std::memcpy( dest[0], in, count * 2 ); } void unpack_z16_y16_from_sr300_inzi(byte * const dest[], const byte * source, int width, int height, int actual_size) @@ -36,7 +36,7 @@ namespace librealsense #else for (int i = 0; i < count; ++i) *out_ir++ = *in++ << 6; #endif - librealsense::copy(dest[0], in, count * 2); + std::memcpy( dest[0], in, count * 2 ); } void unpack_inzi(rs2_format dst_ir_format, byte * const d[], const byte * s, int width, int height, int actual_size) @@ -83,7 +83,7 @@ namespace librealsense void copy_raw10(byte * const dest[], const byte * source, int width, int height, int actual_size) { auto count = width * height; // num of pixels - librealsense::copy(dest[0], source, size_t(5.0 * (count / 4.0))); + std::memcpy( dest[0], source, size_t( 5.0 * ( count / 4.0 ) ) ); } void unpack_y10bpack(byte * const dest[], const byte * source, int width, int height, int actual_size) diff --git a/src/proc/motion-transform.cpp b/src/proc/motion-transform.cpp index edaa004ba1..f9ef263757 100644 --- a/src/proc/motion-transform.cpp +++ b/src/proc/motion-transform.cpp @@ -26,7 +26,7 @@ namespace librealsense res = float3{ float(hid->x), float(hid->y), float(hid->z) } *float(factor); } - librealsense::copy(dest[0], &res, sizeof(float3)); + std::memcpy( dest[0], &res, sizeof( float3 ) ); } // The Accelerometer input format: signed int 16bit. data units 1LSB=0.001g; diff --git a/src/proc/rotation-transform.cpp b/src/proc/rotation-transform.cpp index 13e8c1e057..2780e9eac0 100644 --- a/src/proc/rotation-transform.cpp +++ b/src/proc/rotation-transform.cpp @@ -55,7 +55,7 @@ namespace librealsense for (int j = 0; j < width; ++j) { auto out_index = (((height_out - j) * width_out) - i - 1) * SIZE; - librealsense::copy((void*)(&out[out_index]), &(source[(row_offset + j) * SIZE]), SIZE); + std::memcpy( &out[out_index], &( source[( row_offset + j ) * SIZE] ), SIZE ); } } } diff --git a/src/types.cpp b/src/types.cpp index a866eff2ed..23bbb3cdfc 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -9,8 +9,7 @@ #include #include -#include "core/streaming.h" -#include "../include/librealsense2/hpp/rs_processing.hpp" +#include const double SQRT_DBL_EPSILON = sqrt(std::numeric_limits::epsilon()); @@ -220,10 +219,4 @@ namespace librealsense { return _callback; } - - void copy(void* dst, void const* src, size_t size) - { - auto from = reinterpret_cast(src); - std::copy(from, from + size, reinterpret_cast(dst)); - } } diff --git a/src/types.h b/src/types.h index 0987e7d6a0..6871da5bd0 100644 --- a/src/types.h +++ b/src/types.h @@ -174,8 +174,6 @@ namespace librealsense return false; } - void copy(void* dst, void const* src, size_t size); - /////////////////////// // Logging mechanism // /////////////////////// From 33615aa1308ae238059622f6ba90f2bb8edb1eef Mon Sep 17 00:00:00 2001 From: Eran Date: Sat, 14 Oct 2023 20:46:57 +0300 Subject: [PATCH 5/7] fix rspy/devices --port --- unit-tests/py/rspy/devices.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/unit-tests/py/rspy/devices.py b/unit-tests/py/rspy/devices.py index 61e725c347..16f006752c 100644 --- a/unit-tests/py/rspy/devices.py +++ b/unit-tests/py/rspy/devices.py @@ -758,12 +758,6 @@ def get_phys_port(dev): for opt,arg in opts: if opt in ('--list'): action = 'list' - elif opt in ('--ports'): - printer = get_phys_port - elif opt in ('--all'): - if not acroname: - log.f( 'No acroname available' ) - acroname.enable_ports( sleep_on_change = MAX_ENUMERATION_TIME ) elif opt in ('--port'): if not acroname: log.f( 'No acroname available' ) @@ -773,6 +767,12 @@ def get_phys_port(dev): if len(ports) != len(str_ports): log.f( 'Invalid ports', str_ports ) acroname.enable_ports( ports, disable_other_ports = True, sleep_on_change = MAX_ENUMERATION_TIME ) + elif opt in ('--ports'): + printer = get_phys_port + elif opt in ('--all'): + if not acroname: + log.f( 'No acroname available' ) + acroname.enable_ports( sleep_on_change = MAX_ENUMERATION_TIME ) elif opt in ('--recycle'): action = 'recycle' else: From 5131412f1f045a7d77934470643741be9e8460f2 Mon Sep 17 00:00:00 2001 From: Eran Date: Sat, 14 Oct 2023 20:47:14 +0300 Subject: [PATCH 6/7] add rspy/acroname --disable --- unit-tests/py/rspy/acroname.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/unit-tests/py/rspy/acroname.py b/unit-tests/py/rspy/acroname.py index bd88cee928..466cbe4b5b 100644 --- a/unit-tests/py/rspy/acroname.py +++ b/unit-tests/py/rspy/acroname.py @@ -19,11 +19,12 @@ def usage(): print( ' Control the acroname USB hub' ) print( 'Options:' ) print( ' --enable Enable all ports' ) + print( ' --disable Disable all ports' ) print( ' --recycle Recycle all ports' ) sys.exit(2) try: opts,args = getopt.getopt( sys.argv[1:], '', - longopts = [ 'help', 'recycle', 'enable' ]) + longopts = [ 'help', 'recycle', 'enable', 'disable' ]) except getopt.GetoptError as err: print( '-F-', err ) # something like "option -a not recognized" usage() @@ -96,7 +97,7 @@ def find_all_hubs(): """ from rspy import lsusb # - # 24ff:8013 = + # 24ff:8013 = # iManufacturer Acroname Inc. # iProduct USBHub3p-3[A] hubs = set( lsusb.devices_by_vendor( '24ff' )) @@ -314,6 +315,9 @@ def get_port_from_usb( first_usb_index, second_usb_index ): if opt in ('--enable'): connect() enable_ports() # so ports() will return all + elif opt in ('--disable'): + connect() + disable_ports() elif opt in ('--recycle'): connect() enable_ports() # so ports() will return all From dfb14abf7876d54f0eaf4ca1694a083ef641b729 Mon Sep 17 00:00:00 2001 From: Eran Date: Sun, 15 Oct 2023 11:56:40 +0300 Subject: [PATCH 7/7] replace UNKNOWN_VALUE macro with constexpr --- src/core/enum-helpers.h | 4 ++-- src/to-string.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/enum-helpers.h b/src/core/enum-helpers.h index c7626788d6..ca9381b1b0 100644 --- a/src/core/enum-helpers.h +++ b/src/core/enum-helpers.h @@ -7,10 +7,10 @@ #include -#define UNKNOWN_VALUE "UNKNOWN" +namespace librealsense { -namespace librealsense { +constexpr static char const * UNKNOWN_VALUE = "UNKNOWN"; // Require the last enumerator value to be in format of RS2_#####_COUNT diff --git a/src/to-string.cpp b/src/to-string.cpp index 647f9eeab0..7515514621 100644 --- a/src/to-string.cpp +++ b/src/to-string.cpp @@ -17,7 +17,7 @@ #define STRARR( ARRAY, T, X ) ARRAY[RS2_##T##_##X] = STRX( X ) -static std::string const unknown_value_str( UNKNOWN_VALUE ); +static std::string const unknown_value_str( librealsense::UNKNOWN_VALUE ); namespace librealsense {