Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move lazy to rsutils #12143

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include <nlohmann/json.hpp>
#include "media/playback/playback_device.h"

#include <rsutils/lazy.h>


namespace librealsense
{
class context;
Expand Down Expand Up @@ -163,7 +166,7 @@ namespace librealsense

devices_changed_callback_ptr _devices_changed_callback;
std::map<int, std::weak_ptr<const stream_interface>> _streams;
std::map<int, std::map<int, std::weak_ptr<lazy<rs2_extrinsics>>>> _extrinsics;
std::map< int, std::map< int, std::weak_ptr< rsutils::lazy< rs2_extrinsics > > > > _extrinsics;
std::mutex _streams_mutex, _devices_changed_callbacks_mtx;
};

Expand Down
9 changes: 5 additions & 4 deletions src/core/advanced_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "ds/advanced_mode/presets.h"
#include "../../include/librealsense2/h/rs_advanced_mode_command.h"
#include "serializable-interface.h"
#include <rsutils/lazy.h>

#undef RS400_ADVANCED_MODE_HPP

Expand Down Expand Up @@ -206,11 +207,11 @@ namespace librealsense

std::shared_ptr<hw_monitor> _hw_monitor;
synthetic_sensor& _depth_sensor;
lazy<synthetic_sensor*> _color_sensor;
lazy<bool> _enabled;
rsutils::lazy< synthetic_sensor * > _color_sensor;
rsutils::lazy< bool > _enabled;
std::shared_ptr<advanced_mode_preset_option> _preset_opt;
lazy<bool> _rgb_exposure_gain_bind;
lazy<bool> _amplitude_factor_support;
rsutils::lazy< bool > _rgb_exposure_gain_bind;
rsutils::lazy< bool > _amplitude_factor_support;

preset get_all() const;
void set_all(const preset& p);
Expand Down
13 changes: 8 additions & 5 deletions src/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@

#pragma once

#include <chrono>
#include <memory>
#include <vector>

#include "backend.h"
#include "archive.h"
#include "hw-monitor.h"
Expand All @@ -17,6 +13,13 @@

#include "context.h"

#include <rsutils/lazy.h>

#include <chrono>
#include <memory>
#include <vector>


namespace librealsense
{

Expand Down Expand Up @@ -109,7 +112,7 @@ class device : public virtual device_interface, public info_container
bool _is_valid, _device_changed_notifications;
mutable std::mutex _device_changed_mtx;
uint64_t _callback_id;
lazy<std::vector<tagged_profile>> _profiles_tags;
rsutils::lazy< std::vector< tagged_profile > > _profiles_tags;

std::shared_ptr< bool > _is_alive; // Ensures object can be accessed
};
Expand Down
3 changes: 2 additions & 1 deletion src/ds/d400/d400-color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ namespace librealsense
return get_d400_raw_calibration_table(d400_calibration_table_id::rgb_calibration_id);
};

_color_extrinsic = std::make_shared<lazy<rs2_extrinsics>>([this]() { return from_pose(get_d400_color_stream_extrinsic(*_color_calib_table_raw)); });
_color_extrinsic = std::make_shared< rsutils::lazy< rs2_extrinsics > >(
[this]() { return from_pose( get_d400_color_stream_extrinsic( *_color_calib_table_raw ) ); } );
environment::get_instance().get_extrinsics_graph().register_extrinsics(*_color_stream, *_depth_stream, _color_extrinsic);
register_stream_to_extrinsic_group(*_color_stream, 0);

Expand Down
9 changes: 5 additions & 4 deletions src/ds/d400/d400-color.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
#include "d400-device.h"
#include "ds/ds-color-common.h"

#include <map>

#include "stream.h"

#include <rsutils/lazy.h>
#include <map>

namespace librealsense
{
class d400_color : public virtual d400_device
Expand Down Expand Up @@ -52,8 +53,8 @@ namespace librealsense

uint8_t _color_device_idx = -1;
bool _separate_color;
lazy<std::vector<uint8_t>> _color_calib_table_raw;
std::shared_ptr<lazy<rs2_extrinsics>> _color_extrinsic;
rsutils::lazy< std::vector< uint8_t > > _color_calib_table_raw;
std::shared_ptr< rsutils::lazy< rs2_extrinsics > > _color_extrinsic;
};

class d400_color_sensor : public synthetic_sensor,
Expand Down
8 changes: 4 additions & 4 deletions src/ds/d400/d400-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,8 @@ namespace librealsense

// Define Left-to-Right extrinsics calculation (lazy)
// Reference CS - Right-handed; positive [X,Y,Z] point to [Left,Up,Forward] accordingly.
_left_right_extrinsics = std::make_shared<lazy<rs2_extrinsics>>([this]()
_left_right_extrinsics = std::make_shared< rsutils::lazy< rs2_extrinsics > >(
[this]()
{
rs2_extrinsics ext = identity_matrix();
auto table = check_calib<d400_coefficients_table>(*_coefficients_table_raw);
Expand Down Expand Up @@ -897,7 +898,7 @@ namespace librealsense
if (!val_in_range(_pid, { ds::RS457_PID }))
{
depth_sensor.register_option(RS2_OPTION_STEREO_BASELINE, std::make_shared<const_value_option>("Distance in mm between the stereo imagers",
lazy<float>([this]() { return get_stereo_baseline_mm(); })));
rsutils::lazy< float >( [this]() { return get_stereo_baseline_mm(); } ) ) );
}

if (advanced_mode && _fw_version >= firmware_version("5.6.3.0"))
Expand All @@ -920,8 +921,7 @@ namespace librealsense
if (_pid == RS405_PID)
default_depth_units = 0.0001f; //meters
depth_sensor.register_option(RS2_OPTION_DEPTH_UNITS, std::make_shared<const_value_option>("Number of meters represented by a single depth unit",
lazy<float>([default_depth_units]()
{ return default_depth_units; })));
rsutils::lazy< float >( [default_depth_units]() { return default_depth_units; } ) ) );
}
}); //group_multiple_fw_calls

Expand Down
10 changes: 5 additions & 5 deletions src/ds/d400/d400-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ namespace librealsense

uint8_t _depth_device_idx;

lazy<std::vector<uint8_t>> _coefficients_table_raw;
lazy<std::vector<uint8_t>> _new_calib_table_raw;
rsutils::lazy< std::vector< uint8_t > > _coefficients_table_raw;
rsutils::lazy< std::vector< uint8_t > > _new_calib_table_raw;

std::shared_ptr<polling_error_handler> _polling_error_handler;
std::shared_ptr<d400_thermal_monitor> _thermal_monitor;
std::shared_ptr<lazy<rs2_extrinsics>> _left_right_extrinsics;
lazy<std::vector<uint8_t>> _color_calib_table_raw;
std::shared_ptr<lazy<rs2_extrinsics>> _color_extrinsic;
std::shared_ptr< rsutils::lazy< rs2_extrinsics > > _left_right_extrinsics;
rsutils::lazy< std::vector< uint8_t > > _color_calib_table_raw;
std::shared_ptr< rsutils::lazy< rs2_extrinsics > > _color_extrinsic;
bool _is_locked = true;

std::shared_ptr<auto_gain_limit_option> _gain_limit_value_control;
Expand Down
7 changes: 4 additions & 3 deletions src/ds/d400/d400-motion.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "d400-device.h"
#include "ds/ds-motion-common.h"
#include <rsutils/lazy.h>

namespace librealsense
{
Expand All @@ -21,9 +22,9 @@ namespace librealsense
friend class ds_fisheye_sensor;
friend class ds_motion_common;

std::shared_ptr<lazy<ds::imu_intrinsic>> _accel_intrinsic;
std::shared_ptr<lazy<ds::imu_intrinsic>> _gyro_intrinsic;
std::shared_ptr<lazy<rs2_extrinsics>> _depth_to_imu; // Mechanical installation pose
std::shared_ptr< rsutils::lazy< ds::imu_intrinsic > > _accel_intrinsic;
std::shared_ptr< rsutils::lazy< ds::imu_intrinsic > > _gyro_intrinsic;
std::shared_ptr< rsutils::lazy< rs2_extrinsics > > _depth_to_imu; // Mechanical installation pose

protected:
d400_motion_base(std::shared_ptr<context> ctx,
Expand Down
9 changes: 7 additions & 2 deletions src/ds/d400/d400-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include "error-handling.h"
#include "../../hdr-config.h"

#include <rsutils/lazy.h>


namespace librealsense
{

Expand Down Expand Up @@ -48,7 +51,9 @@ namespace librealsense
rs2_option _option;
std::shared_ptr<hw_monitor> _hw_monitor;
};

class limits_option;

class auto_exposure_limit_option : public option_base
{
public:
Expand All @@ -67,7 +72,7 @@ namespace librealsense

private:
std::function<void(const option&)> _record_action = [](const option&) {};
lazy<option_range> _range;
rsutils::lazy< option_range > _range;
hw_monitor& _hwm;
sensor_base* _sensor;
std::weak_ptr<limits_option> _exposure_limit_toggle;
Expand All @@ -91,7 +96,7 @@ namespace librealsense

private:
std::function<void(const option&)> _record_action = [](const option&) {};
lazy<option_range> _range;
rsutils::lazy< option_range > _range;
hw_monitor& _hwm;
sensor_base* _sensor;
std::weak_ptr<limits_option> _gain_limit_toggle;
Expand Down
3 changes: 2 additions & 1 deletion src/ds/d500/d500-color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ namespace librealsense
return get_d500_raw_calibration_table(d500_calibration_table_id::rgb_calibration_id);
};

_color_extrinsic = std::make_shared<lazy<rs2_extrinsics>>([this]() { return from_pose(get_d500_color_stream_extrinsic(*_color_calib_table_raw)); });
_color_extrinsic = std::make_shared< rsutils::lazy< rs2_extrinsics > >(
[this]() { return from_pose( get_d500_color_stream_extrinsic( *_color_calib_table_raw ) ); } );
environment::get_instance().get_extrinsics_graph().register_extrinsics(*_color_stream, *_depth_stream, _color_extrinsic);
register_stream_to_extrinsic_group(*_color_stream, 0);

Expand Down
8 changes: 5 additions & 3 deletions src/ds/d500/d500-color.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
#include "d500-device.h"
#include "ds/ds-color-common.h"

#include "stream.h"

#include <rsutils/lazy.h>
#include <map>

#include "stream.h"

namespace librealsense
{
Expand Down Expand Up @@ -48,8 +50,8 @@ namespace librealsense

uint8_t _color_device_idx = -1;
bool _separate_color;
lazy<std::vector<uint8_t>> _color_calib_table_raw;
std::shared_ptr<lazy<rs2_extrinsics>> _color_extrinsic;
rsutils::lazy< std::vector< uint8_t > > _color_calib_table_raw;
std::shared_ptr< rsutils::lazy< rs2_extrinsics > > _color_extrinsic;
};

class d500_color_sensor : public synthetic_sensor,
Expand Down
13 changes: 6 additions & 7 deletions src/ds/d500/d500-device.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2022 Intel Corporation. All Rights Reserved.

#include <vector>
#include <string>

#include "device.h"
#include "context.h"
#include "image.h"
Expand All @@ -29,6 +26,8 @@
#include "../common/fw/firmware-version.h"
#include "fw-update/fw-update-unsigned.h"
#include <nlohmann/json.hpp>
#include <vector>
#include <string>

#ifdef HWM_OVER_XU
constexpr bool hw_mon_over_xu = true;
Expand Down Expand Up @@ -438,7 +437,8 @@ namespace librealsense

// Define Left-to-Right extrinsics calculation (lazy)
// Reference CS - Right-handed; positive [X,Y,Z] point to [Left,Up,Forward] accordingly.
_left_right_extrinsics = std::make_shared<lazy<rs2_extrinsics>>([this]()
_left_right_extrinsics = std::make_shared< rsutils::lazy< rs2_extrinsics > >(
[this]()
{
rs2_extrinsics ext = identity_matrix();
auto table = check_calib<d500_coefficients_table>(*_coefficients_table_raw);
Expand Down Expand Up @@ -628,7 +628,7 @@ namespace librealsense
roi_sensor->set_roi_method(std::make_shared<ds_auto_exposure_roi_method>(*_hw_monitor));

depth_sensor.register_option(RS2_OPTION_STEREO_BASELINE, std::make_shared<const_value_option>("Distance in mm between the stereo imagers",
lazy<float>([this]() { return get_stereo_baseline_mm(); })));
rsutils::lazy< float >( [this]() { return get_stereo_baseline_mm(); } ) ) );

if (advanced_mode)
{
Expand All @@ -647,8 +647,7 @@ namespace librealsense
{
float default_depth_units = 0.001f; //meters
depth_sensor.register_option(RS2_OPTION_DEPTH_UNITS, std::make_shared<const_value_option>("Number of meters represented by a single depth unit",
lazy<float>([default_depth_units]()
{ return default_depth_units; })));
rsutils::lazy< float >( [default_depth_units]() { return default_depth_units; } ) ) );
}

depth_sensor.register_option(RS2_OPTION_ASIC_TEMPERATURE,
Expand Down
13 changes: 8 additions & 5 deletions src/ds/d500/d500-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

#include "ds/ds-device-common.h"

#include <rsutils/lazy.h>


namespace librealsense
{
class hdr_config;
Expand Down Expand Up @@ -100,14 +103,14 @@ namespace librealsense

uint8_t _depth_device_idx;

lazy<std::vector<uint8_t>> _coefficients_table_raw;
lazy<std::vector<uint8_t>> _new_calib_table_raw;
rsutils::lazy< std::vector< uint8_t > > _coefficients_table_raw;
rsutils::lazy< std::vector< uint8_t > > _new_calib_table_raw;

std::shared_ptr<polling_error_handler> _polling_error_handler;
std::shared_ptr<d400_thermal_monitor> _thermal_monitor;
std::shared_ptr<lazy<rs2_extrinsics>> _left_right_extrinsics;
lazy<std::vector<uint8_t>> _color_calib_table_raw;
std::shared_ptr<lazy<rs2_extrinsics>> _color_extrinsic;
std::shared_ptr< rsutils::lazy< rs2_extrinsics > > _left_right_extrinsics;
rsutils::lazy< std::vector< uint8_t > > _color_calib_table_raw;
std::shared_ptr< rsutils::lazy< rs2_extrinsics > > _color_extrinsic;
bool _is_locked = true;
bool _is_symmetrization_enabled = true;
};
Expand Down
9 changes: 6 additions & 3 deletions src/ds/d500/d500-options.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2023 Intel Corporation. All Rights Reserved.

#pragma once

#include "ds/ds-private.h"
#include "core/options.h"
#include "option.h"

#pragma once
#include <rsutils/lazy.h>


namespace librealsense
{
Expand All @@ -29,7 +32,7 @@ namespace librealsense

private:
std::function<void(const option&)> _record_action = [](const option&) {};
lazy<option_range> _range;
rsutils::lazy< option_range > _range;
std::shared_ptr<hw_monitor> _hwm;
sensor_base* _sensor;
};
Expand Down Expand Up @@ -65,7 +68,7 @@ namespace librealsense

private:
std::function<void(const option&)> _record_action = [](const option&) {};
lazy<option_range> _range;
rsutils::lazy< option_range > _range;
std::shared_ptr<hw_monitor> _hwm;
sensor_base* _sensor;
temperature_component _component;
Expand Down
8 changes: 5 additions & 3 deletions src/ds/ds-calib-parsers.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include "ds-device-common.h"
#include "core/video.h"
#include <rsutils/lazy.h>


namespace librealsense
{
Expand All @@ -28,10 +30,10 @@ namespace librealsense
float3x3 imu_to_depth_alignment() { return (*_calib_parser)->imu_to_depth_alignment(); }
private:
std::shared_ptr<hw_monitor> _hw_monitor;
lazy< std::shared_ptr<mm_calib_parser>> _calib_parser;
lazy<std::vector<uint8_t>> _imu_eeprom_raw;
rsutils::lazy< std::shared_ptr< mm_calib_parser > > _calib_parser;
rsutils::lazy< std::vector< uint8_t > > _imu_eeprom_raw;
std::vector<uint8_t> get_imu_eeprom_raw() const;
lazy<std::vector<uint8_t>> _fisheye_calibration_table_raw;
rsutils::lazy< std::vector< uint8_t > > _fisheye_calibration_table_raw;
uint16_t _pid;
};

Expand Down
Loading
Loading