diff --git a/src/basics.h b/src/basics.h index 5be455178b..ec42546c3a 100644 --- a/src/basics.h +++ b/src/basics.h @@ -9,6 +9,14 @@ // Any extension relying on these APIs must be compiled and distributed together with realsense2.dll #pragma warning(disable : 4275) /* disable: C4275: non dll-interface class used as base for dll-interface class */ #pragma warning(disable : 4251) /* disable: C4251: class needs to have dll-interface to be used by clients of class */ + +// Compiler Warning (level 2) C4250: 'class1' : inherits 'class2::member' via dominance +// This happens for librealsense::device, basically warning us of something that we know and is OK: +// 'librealsense::device': inherits 'info_container::create_snapshot' via dominance (and repeats for 3 more functions) +// And for anything else using both an interface and a container, options_container etc. +#pragma warning(disable: 4250) + + #ifdef WIN32 #define LRS_EXTENSION_API __declspec(dllexport) #else diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index bf8b122f97..ca731e6366 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -7,13 +7,17 @@ target_sources(${LRS_TARGET} "${CMAKE_CURRENT_LIST_DIR}/advanced_mode.h" "${CMAKE_CURRENT_LIST_DIR}/enum-helpers.h" "${CMAKE_CURRENT_LIST_DIR}/depth-frame.h" + "${CMAKE_CURRENT_LIST_DIR}/device-interface.h" "${CMAKE_CURRENT_LIST_DIR}/disparity-frame.h" "${CMAKE_CURRENT_LIST_DIR}/frame-continuation.h" "${CMAKE_CURRENT_LIST_DIR}/frame-additional-data.h" "${CMAKE_CURRENT_LIST_DIR}/frame-header.h" "${CMAKE_CURRENT_LIST_DIR}/frame-holder.h" "${CMAKE_CURRENT_LIST_DIR}/frame-interface.h" + "${CMAKE_CURRENT_LIST_DIR}/info-interface.h" "${CMAKE_CURRENT_LIST_DIR}/roi.h" + "${CMAKE_CURRENT_LIST_DIR}/matcher-factory.h" + "${CMAKE_CURRENT_LIST_DIR}/matcher-factory.cpp" "${CMAKE_CURRENT_LIST_DIR}/motion.h" "${CMAKE_CURRENT_LIST_DIR}/motion-frame.h" "${CMAKE_CURRENT_LIST_DIR}/video.h" @@ -26,4 +30,6 @@ target_sources(${LRS_TARGET} "${CMAKE_CURRENT_LIST_DIR}/pose-frame.h" "${CMAKE_CURRENT_LIST_DIR}/processing.h" "${CMAKE_CURRENT_LIST_DIR}/serialization.h" + "${CMAKE_CURRENT_LIST_DIR}/stream-profile.h" + "${CMAKE_CURRENT_LIST_DIR}/tagged-profile.h" ) diff --git a/src/core/device-interface.h b/src/core/device-interface.h new file mode 100644 index 0000000000..15577a78bf --- /dev/null +++ b/src/core/device-interface.h @@ -0,0 +1,73 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2023 Intel Corporation. All Rights Reserved. + +#pragma once + +#include "info-interface.h" +#include "tagged-profile.h" +#include "stream-profile.h" + +#include +#include +#include +#include +#include // std::pair + + +namespace librealsense { + + +class sensor_interface; +class matcher; +class frame_holder; +class context; +class device_info; +class stream_interface; +class stream_profile_interface; + + +// Base class for all devices in librealsense +// +class device_interface + : public virtual info_interface + , public std::enable_shared_from_this< device_interface > +{ +public: + virtual ~device_interface() = default; + + // Return the context to which this device belongs + // Typically, same as get_device_info()->context() + // + virtual std::shared_ptr< context > get_context() const = 0; + + // Returns the device_info object from which this device was created + // + virtual std::shared_ptr< const device_info > get_device_info() const = 0; + + virtual sensor_interface & get_sensor( size_t i ) = 0; + virtual const sensor_interface & get_sensor( size_t i ) const = 0; + virtual size_t get_sensors_count() const = 0; + + virtual void hardware_reset() = 0; + + virtual std::shared_ptr< matcher > create_matcher( const frame_holder & frame ) const = 0; + + virtual std::pair< uint32_t, rs2_extrinsics > get_extrinsics( const stream_interface & ) const = 0; + + virtual bool is_valid() const = 0; + + virtual std::vector< tagged_profile > get_profiles_tags() const = 0; + + using stream_profiles = std::vector< std::shared_ptr< stream_profile_interface > >; + virtual void tag_profiles( stream_profiles profiles ) const = 0; + + // Return true if this device should use compression when recording to a bag file + // + virtual bool compress_while_record() const = 0; + + virtual bool contradicts( const stream_profile_interface * a, + const std::vector< stream_profile > & others ) const = 0; +}; + + +} // namespace librealsense diff --git a/src/core/info-interface.h b/src/core/info-interface.h new file mode 100644 index 0000000000..7c4a92ba30 --- /dev/null +++ b/src/core/info-interface.h @@ -0,0 +1,30 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2023 Intel Corporation. All Rights Reserved. + +#pragma once + +#include "extension.h" +#include + +#include +#include + + +namespace librealsense { + + +// Anything that can support getting rs2_camera_info should implement this. +// +class info_interface : public virtual recordable< info_interface > +{ +public: + virtual const std::string & get_info( rs2_camera_info info ) const = 0; + virtual bool supports_info( rs2_camera_info info ) const = 0; + + virtual ~info_interface() = default; +}; + +MAP_EXTENSION( RS2_EXTENSION_INFO, librealsense::info_interface ); + + +} // namespace librealsense diff --git a/src/core/info.h b/src/core/info.h index 4e8f3486db..1aae63b397 100644 --- a/src/core/info.h +++ b/src/core/info.h @@ -1,37 +1,40 @@ // License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2017 Intel Corporation. All Rights Reserved. +// Copyright(c) 2023 Intel Corporation. All Rights Reserved. #pragma once -#include "extension.h" +#include "info-interface.h" + +#include #include +#include + + +namespace librealsense { -namespace librealsense + +// Simple implementation of info_interface +// +class LRS_EXTENSION_API info_container + : public virtual info_interface + , public extension_snapshot { - class info_interface : public virtual recordable - { - public: - virtual const std::string& get_info(rs2_camera_info info) const = 0; - virtual bool supports_info(rs2_camera_info info) const = 0; - - virtual ~info_interface() = default; - }; - - MAP_EXTENSION(RS2_EXTENSION_INFO, librealsense::info_interface); - - class LRS_EXTENSION_API info_container : public virtual info_interface, public extension_snapshot - { - public: - const std::string& get_info(rs2_camera_info info) const override; - bool supports_info(rs2_camera_info info) const override; - - void register_info(rs2_camera_info info, const std::string& val); - void update_info(rs2_camera_info info, const std::string& val); - void create_snapshot(std::shared_ptr& snapshot) const override; - void enable_recording(std::function record_action) override; - void update(std::shared_ptr ext) override; - private: - std::map _camera_info; - }; - -} +public: + void register_info( rs2_camera_info info, const std::string & val ); + void update_info( rs2_camera_info info, const std::string & val ); + + // info_interface + const std::string & get_info( rs2_camera_info info ) const override; + bool supports_info( rs2_camera_info info ) const override; + + // extension_snapshot + void create_snapshot( std::shared_ptr< info_interface > & snapshot ) const override; + void enable_recording( std::function< void( const info_interface & ) > record_action ) override; + void update( std::shared_ptr< extension_snapshot > ext ) override; + +private: + std::map< rs2_camera_info, std::string > _camera_info; +}; + + +} // namespace librealsense diff --git a/src/core/matcher-factory.cpp b/src/core/matcher-factory.cpp new file mode 100644 index 0000000000..e1b6aa198c --- /dev/null +++ b/src/core/matcher-factory.cpp @@ -0,0 +1,166 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2023 Intel Corporation. All Rights Reserved. + +#include "matcher-factory.h" +#include "frame-holder.h" + +#include + + +namespace librealsense { + + +std::shared_ptr< matcher > matcher_factory::create( rs2_matchers matcher, + std::vector< stream_interface * > const & profiles ) +{ + switch( matcher ) + { + case RS2_MATCHER_DI: + return create_DI_matcher( profiles ); + case RS2_MATCHER_DI_C: + return create_DI_C_matcher( profiles ); + case RS2_MATCHER_DLR_C: + return create_DLR_C_matcher( profiles ); + case RS2_MATCHER_DLR: + return create_DLR_matcher( profiles ); + case RS2_MATCHER_DIC: + return create_DIC_matcher( profiles ); + case RS2_MATCHER_DIC_C: + return create_DIC_C_matcher( profiles ); + + case RS2_MATCHER_DEFAULT: + default: + return create_timestamp_matcher( profiles ); + } +} + + +std::shared_ptr< matcher > matcher_factory::create_DLR_C_matcher( std::vector< stream_interface * > const & profiles ) +{ + auto color = find_profile( RS2_STREAM_COLOR, 0, profiles ); + if( ! color ) + { + LOG_DEBUG( "Created default matcher" ); + return create_timestamp_matcher( profiles ); + } + + return create_timestamp_composite_matcher( { create_DLR_matcher( profiles ), create_identity_matcher( color ) } ); +} + + +std::shared_ptr< matcher > matcher_factory::create_DI_C_matcher( std::vector< stream_interface * > const & profiles ) +{ + auto color = find_profile( RS2_STREAM_COLOR, 0, profiles ); + if( ! color ) + { + LOG_DEBUG( "Created default matcher" ); + return create_timestamp_matcher( profiles ); + } + + return create_timestamp_composite_matcher( { create_DI_matcher( profiles ), create_identity_matcher( color ) } ); +} + + +std::shared_ptr< matcher > matcher_factory::create_DLR_matcher( std::vector< stream_interface * > const & profiles ) +{ + auto depth = find_profile( RS2_STREAM_DEPTH, 0, profiles ); + auto left = find_profile( RS2_STREAM_INFRARED, 1, profiles ); + auto right = find_profile( RS2_STREAM_INFRARED, 2, profiles ); + + if( ! depth || ! left || ! right ) + { + LOG_DEBUG( "Created default matcher" ); + return create_timestamp_matcher( profiles ); + } + return create_frame_number_matcher( { depth, left, right } ); +} + + +std::shared_ptr< matcher > matcher_factory::create_DI_matcher( std::vector< stream_interface * > const & profiles ) +{ + auto depth = find_profile( RS2_STREAM_DEPTH, 0, profiles ); + auto ir = find_profile( RS2_STREAM_INFRARED, 1, profiles ); + + if( ! depth || ! ir ) + { + LOG_DEBUG( "Created default matcher" ); + return create_timestamp_matcher( profiles ); + } + return create_frame_number_matcher( { depth, ir } ); +} + + +std::shared_ptr< matcher > matcher_factory::create_DIC_matcher( std::vector< stream_interface * > const & profiles ) +{ + std::vector< std::shared_ptr< matcher > > matchers; + if( auto depth = find_profile( RS2_STREAM_DEPTH, -1, profiles ) ) + matchers.push_back( create_identity_matcher( depth ) ); + if( auto ir = find_profile( RS2_STREAM_INFRARED, -1, profiles ) ) + matchers.push_back( create_identity_matcher( ir ) ); + if( auto confidence = find_profile( RS2_STREAM_CONFIDENCE, -1, profiles ) ) + matchers.push_back( create_identity_matcher( confidence ) ); + + if( matchers.empty() ) + { + LOG_ERROR( "no depth, ir, or confidence streams found for matcher" ); + for( auto && p : profiles ) + LOG_DEBUG( p->get_stream_type() << '/' << p->get_unique_id() ); + throw std::runtime_error( "no depth, ir, or confidence streams found for matcher" ); + } + + return create_timestamp_composite_matcher( matchers ); +} + + +std::shared_ptr< matcher > matcher_factory::create_DIC_C_matcher( std::vector< stream_interface * > const & profiles ) +{ + auto color = find_profile( RS2_STREAM_COLOR, 0, profiles ); + if( ! color ) + throw std::runtime_error( "no color stream found for matcher" ); + + return create_timestamp_composite_matcher( { create_DIC_matcher( profiles ), create_identity_matcher( color ) } ); +} + + +std::shared_ptr< matcher > +matcher_factory::create_frame_number_matcher( std::vector< stream_interface * > const & profiles ) +{ + std::vector< std::shared_ptr< matcher > > matchers; + for( auto & p : profiles ) + matchers.push_back( std::make_shared< identity_matcher >( p->get_unique_id(), p->get_stream_type() ) ); + + return create_frame_number_composite_matcher( matchers ); +} + + +std::shared_ptr< matcher > +matcher_factory::create_timestamp_matcher( std::vector< stream_interface * > const & profiles ) +{ + std::vector< std::shared_ptr< matcher > > matchers; + for( auto & p : profiles ) + matchers.push_back( std::make_shared< identity_matcher >( p->get_unique_id(), p->get_stream_type() ) ); + + return create_timestamp_composite_matcher( matchers ); +} + + +std::shared_ptr< matcher > matcher_factory::create_identity_matcher( stream_interface * profile ) +{ + return std::make_shared< identity_matcher >( profile->get_unique_id(), profile->get_stream_type() ); +} + +std::shared_ptr< matcher > +matcher_factory::create_frame_number_composite_matcher( std::vector< std::shared_ptr< matcher > > const & matchers ) +{ + return std::make_shared< frame_number_composite_matcher >( matchers ); +} + + +std::shared_ptr< matcher > +matcher_factory::create_timestamp_composite_matcher( std::vector< std::shared_ptr< matcher > > const & matchers ) +{ + return std::make_shared< timestamp_composite_matcher >( matchers ); +} + + +} // namespace librealsense \ No newline at end of file diff --git a/src/core/matcher-factory.h b/src/core/matcher-factory.h new file mode 100644 index 0000000000..00f342236e --- /dev/null +++ b/src/core/matcher-factory.h @@ -0,0 +1,44 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2023 Intel Corporation. All Rights Reserved. + +#pragma once + +#include + +#include +#include + + +namespace librealsense { + + +class stream_interface; +class matcher; + + +class matcher_factory +{ +public: + static std::shared_ptr< matcher > create( rs2_matchers matcher, + std::vector< stream_interface * > const & profiles ); + +private: + static std::shared_ptr< matcher > create_DLR_C_matcher( std::vector< stream_interface * > const & profiles ); + static std::shared_ptr< matcher > create_DLR_matcher( std::vector< stream_interface * > const & profiles ); + static std::shared_ptr< matcher > create_DI_C_matcher( std::vector< stream_interface * > const & profiles ); + static std::shared_ptr< matcher > create_DI_matcher( std::vector< stream_interface * > const & profiles ); + static std::shared_ptr< matcher > create_DIC_matcher( std::vector< stream_interface * > const & profiles ); + static std::shared_ptr< matcher > create_DIC_C_matcher( std::vector< stream_interface * > const & profiles ); + + static std::shared_ptr< matcher > create_identity_matcher( stream_interface * profiles ); + static std::shared_ptr< matcher > create_frame_number_matcher( std::vector< stream_interface * > const & profiles ); + static std::shared_ptr< matcher > create_timestamp_matcher( std::vector< stream_interface * > const & profiles ); + + static std::shared_ptr< matcher > + create_timestamp_composite_matcher( std::vector< std::shared_ptr< matcher > > const & matchers ); + static std::shared_ptr< matcher > + create_frame_number_composite_matcher( std::vector< std::shared_ptr< matcher > > const & matchers ); +}; + + +} // namespace librealsense \ No newline at end of file diff --git a/src/core/stream-profile.h b/src/core/stream-profile.h new file mode 100644 index 0000000000..d256a0a5fe --- /dev/null +++ b/src/core/stream-profile.h @@ -0,0 +1,101 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2023 Intel Corporation. All Rights Reserved. + +#pragma once + +#include +#include // std::hash +#include // std::swap +#include + + +namespace librealsense { + + +struct stream_profile +{ + rs2_format format; + rs2_stream stream; + int index; + uint32_t width; + uint32_t height; + uint32_t fps; + + // Certain cameras may introduce transformed resolutions in their target profiles. E.g., this was the case with the + // L500 (both rotation, plus expansion for confidence). This is not in use with the D series. + // + // See provided implementations below... + // + typedef void ( *resolution_transform_fn )( uint32_t & width, uint32_t & height ); + + static void same_resolution( uint32_t & w, uint32_t & h ) {} + static void rotate_resolution( uint32_t & w, uint32_t & h ) { std::swap( w, h ); } + + // Transformation function, to adjust width/height when a profile is cloned as part of a sensor's defined + // processing block. The formats_converter uses this when doing its thing. + // + resolution_transform_fn resolution_transform; + + stream_profile( + rs2_format fmt = RS2_FORMAT_ANY, + rs2_stream strm = RS2_STREAM_ANY, + int idx = 0, + uint32_t w = 0, + uint32_t h = 0, + uint32_t framerate = 0, + resolution_transform_fn res_transform = &same_resolution ) + : format( fmt ) + , stream( strm ) + , index( idx ) + , width( w ) + , height( h ) + , fps( framerate ) + , resolution_transform( res_transform ) + { + } +}; + + +inline bool operator==( const stream_profile & a, const stream_profile & b ) +{ + return ( a.width == b.width ) && ( a.height == b.height ) && ( a.fps == b.fps ) && ( a.format == b.format ) + && ( a.index == b.index ) && ( a.stream == b.stream ); +} + +inline bool operator<( const stream_profile & lhs, const stream_profile & rhs ) +{ + if( lhs.format != rhs.format ) + return lhs.format < rhs.format; + if( lhs.index != rhs.index ) + return lhs.index < rhs.index; + return lhs.stream < rhs.stream; +} + + +} // namespace librealsense + + +namespace std { + + +template<> +struct hash< librealsense::stream_profile > +{ + size_t operator()( const librealsense::stream_profile & k ) const + { + using std::hash; + + return ( hash< uint32_t >()( k.height ) ) ^ ( hash< uint32_t >()( k.width ) ) ^ ( hash< uint32_t >()( k.fps ) ) + ^ ( hash< uint32_t >()( k.format ) ) ^ ( hash< uint32_t >()( k.stream ) ); + } +}; + + +template<> +struct hash< rs2_format > +{ + size_t operator()( const rs2_format & f ) const { return std::hash< uint32_t >()( f ); } +}; + + +} // namespace std diff --git a/src/core/streaming.h b/src/core/streaming.h index 9a6ce81822..a75375556f 100644 --- a/src/core/streaming.h +++ b/src/core/streaming.h @@ -7,43 +7,20 @@ #include "../color-sensor.h" #include "../composite-frame.h" #include "../points.h" -#include "info.h" +#include "info-interface.h" +#include "tagged-profile.h" #include +#include + namespace librealsense { class sensor_interface; - class archive_interface; class device_interface; class processing_block_interface; class context; - enum class format_conversion - { - raw, - basic, - full - }; - - typedef enum profile_tag - { - PROFILE_TAG_SUPERSET = 1, // to be included in enable_all - PROFILE_TAG_DEFAULT = 2, // to be included in default pipeline start - PROFILE_TAG_ANY = 4, // does not include PROFILE_TAG_DEBUG - PROFILE_TAG_DEBUG = 8, // tag for debug formats - } profile_tag; - - struct tagged_profile - { - rs2_stream stream; - int stream_index; - int width, height; - rs2_format format; - int fps; - int tag; - }; - class stream_interface : public std::enable_shared_from_this { public: @@ -59,6 +36,10 @@ namespace librealsense virtual void set_stream_type(rs2_stream stream) = 0; }; + + stream_interface * find_profile( rs2_stream stream, int index, std::vector< stream_interface * > const & profiles ); + + class stream_profile_interface : public stream_interface, public recordable { public: @@ -160,39 +141,4 @@ namespace librealsense }; - class matcher; - class device_info; - - - class device_interface : public virtual info_interface, public std::enable_shared_from_this - { - public: - virtual sensor_interface& get_sensor(size_t i) = 0; - - virtual const sensor_interface& get_sensor(size_t i) const = 0; - - virtual size_t get_sensors_count() const = 0; - - virtual void hardware_reset() = 0; - - virtual std::shared_ptr create_matcher(const frame_holder& frame) const = 0; - - virtual std::shared_ptr get_context() const = 0; - - virtual std::shared_ptr< const device_info > get_device_info() const = 0; - - virtual std::pair get_extrinsics(const stream_interface& stream) const = 0; - - virtual bool is_valid() const = 0; - - virtual ~device_interface() = default; - - virtual std::vector get_profiles_tags() const = 0; - - virtual void tag_profiles(stream_profiles profiles) const = 0; - - virtual bool compress_while_record() const = 0; - - virtual bool contradicts(const stream_profile_interface* a, const std::vector& others) const = 0; - }; } diff --git a/src/core/tagged-profile.h b/src/core/tagged-profile.h new file mode 100644 index 0000000000..9990439b84 --- /dev/null +++ b/src/core/tagged-profile.h @@ -0,0 +1,32 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2023 Intel Corporation. All Rights Reserved. + +#pragma once + +#include + + +namespace librealsense { + + +typedef enum profile_tag +{ + PROFILE_TAG_SUPERSET = 1, // to be included in enable_all + PROFILE_TAG_DEFAULT = 2, // to be included in default pipeline start + PROFILE_TAG_ANY = 4, // does not include PROFILE_TAG_DEBUG + PROFILE_TAG_DEBUG = 8, // tag for debug formats +} profile_tag; + + +struct tagged_profile +{ + rs2_stream stream; + int stream_index; + int width, height; + rs2_format format; + int fps; + int tag; +}; + + +} // namespace librealsense diff --git a/src/device.cpp b/src/device.cpp index 21d67afc15..99e3ee4741 100644 --- a/src/device.cpp +++ b/src/device.cpp @@ -1,38 +1,20 @@ // License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2015 Intel Corporation. All Rights Reserved. +#include "device.h" + #include "environment.h" #include "core/video.h" #include "core/motion.h" -#include "device.h" +#include "core/frame-holder.h" +#include "sync.h" +#include "context.h" // rs2_device_info #include #include using namespace librealsense; -std::shared_ptr< matcher > matcher_factory::create( rs2_matchers matcher, - std::vector< stream_interface * > const & profiles ) -{ - switch (matcher) - { - case RS2_MATCHER_DI: - return create_DI_matcher(profiles); - case RS2_MATCHER_DI_C: - return create_DI_C_matcher(profiles); - case RS2_MATCHER_DLR_C: - return create_DLR_C_matcher(profiles); - case RS2_MATCHER_DLR: - return create_DLR_matcher(profiles); - case RS2_MATCHER_DIC: - return create_DIC_matcher( profiles ); - case RS2_MATCHER_DIC_C: - return create_DIC_C_matcher( profiles ); - case RS2_MATCHER_DEFAULT: - default: - return create_timestamp_matcher(profiles); - } -} stream_interface * librealsense::find_profile( rs2_stream stream, int index, std::vector< stream_interface * > const & profiles ) @@ -48,135 +30,15 @@ librealsense::find_profile( rs2_stream stream, int index, std::vector< stream_in return nullptr; } -std::shared_ptr< matcher > matcher_factory::create_DLR_C_matcher( std::vector< stream_interface * > const & profiles ) -{ - auto color = find_profile(RS2_STREAM_COLOR, 0, profiles); - if (!color) - { - LOG_DEBUG("Created default matcher"); - return create_timestamp_matcher(profiles); - } - - return create_timestamp_composite_matcher({ create_DLR_matcher(profiles), - create_identity_matcher(color) }); -} - -std::shared_ptr< matcher > matcher_factory::create_DI_C_matcher( std::vector< stream_interface * > const & profiles ) -{ - auto color = find_profile(RS2_STREAM_COLOR, 0, profiles); - if (!color) - { - LOG_DEBUG("Created default matcher"); - return create_timestamp_matcher(profiles); - } - - return create_timestamp_composite_matcher({ create_DI_matcher(profiles), - create_identity_matcher(color) }); -} - -std::shared_ptr< matcher > matcher_factory::create_DLR_matcher( std::vector< stream_interface * > const & profiles ) -{ - auto depth = find_profile(RS2_STREAM_DEPTH, 0, profiles); - auto left = find_profile(RS2_STREAM_INFRARED, 1, profiles); - auto right = find_profile(RS2_STREAM_INFRARED, 2, profiles); - - if (!depth || !left || !right) - { - LOG_DEBUG("Created default matcher"); - return create_timestamp_matcher(profiles); - } - return create_frame_number_matcher({ depth , left , right }); -} - -std::shared_ptr< matcher > matcher_factory::create_DI_matcher( std::vector< stream_interface * > const & profiles ) -{ - auto depth = find_profile(RS2_STREAM_DEPTH, 0, profiles); - auto ir = find_profile(RS2_STREAM_INFRARED, 1, profiles); - - if (!depth || !ir) - { - LOG_DEBUG("Created default matcher"); - return create_timestamp_matcher(profiles); - } - return create_frame_number_matcher({ depth , ir }); -} - -std::shared_ptr< matcher > matcher_factory::create_DIC_matcher( std::vector< stream_interface * > const & profiles ) -{ - std::vector< std::shared_ptr< matcher > > matchers; - if( auto depth = find_profile( RS2_STREAM_DEPTH, -1, profiles ) ) - matchers.push_back( create_identity_matcher( depth )); - if( auto ir = find_profile( RS2_STREAM_INFRARED, -1, profiles ) ) - matchers.push_back( create_identity_matcher( ir ) ); - if( auto confidence = find_profile( RS2_STREAM_CONFIDENCE, -1, profiles ) ) - matchers.push_back( create_identity_matcher( confidence ) ); - - if( matchers.empty() ) - { - LOG_ERROR( "no depth, ir, or confidence streams found for matcher" ); - for( auto && p : profiles ) - LOG_DEBUG( p->get_stream_type() << '/' << p->get_unique_id() ); - throw std::runtime_error( "no depth, ir, or confidence streams found for matcher" ); - } - - return create_timestamp_composite_matcher( matchers ); -} - -std::shared_ptr< matcher > matcher_factory::create_DIC_C_matcher( std::vector< stream_interface * > const & profiles ) -{ - auto color = find_profile( RS2_STREAM_COLOR, 0, profiles ); - if( ! color ) - throw std::runtime_error( "no color stream found for matcher" ); - - return create_timestamp_composite_matcher( { create_DIC_matcher( profiles ), create_identity_matcher( color ) } ); -} - -std::shared_ptr< matcher > -matcher_factory::create_frame_number_matcher( std::vector< stream_interface * > const & profiles ) -{ - std::vector> matchers; - for (auto& p : profiles) - matchers.push_back(std::make_shared(p->get_unique_id(), p->get_stream_type())); - - return create_frame_number_composite_matcher(matchers); -} - -std::shared_ptr< matcher > -matcher_factory::create_timestamp_matcher( std::vector< stream_interface * > const & profiles ) -{ - std::vector> matchers; - for (auto& p : profiles) - matchers.push_back(std::make_shared(p->get_unique_id(), p->get_stream_type())); - - return create_timestamp_composite_matcher(matchers); -} - -std::shared_ptr matcher_factory::create_identity_matcher(stream_interface *profile) -{ - return std::make_shared(profile->get_unique_id(), profile->get_stream_type()); -} - -std::shared_ptr< matcher > -matcher_factory::create_frame_number_composite_matcher( std::vector< std::shared_ptr< matcher > > const & matchers ) -{ - return std::make_shared(matchers); -} - -std::shared_ptr< matcher > -matcher_factory::create_timestamp_composite_matcher( std::vector< std::shared_ptr< matcher > > const & matchers ) -{ - return std::make_shared(matchers); -} device::device( std::shared_ptr< const device_info > const & dev_info, bool device_changed_notifications ) : _dev_info( dev_info ) , _is_valid( true ) - , _device_changed_notifications( device_changed_notifications ) , _is_alive( std::make_shared< bool >( true ) ) , _profiles_tags( [this]() { return get_profiles_tags(); } ) { - if (_device_changed_notifications) + if( device_changed_notifications ) { std::weak_ptr< bool > weak = _is_alive; auto cb = new devices_changed_callback_internal([this, weak](rs2_device_list* removed, rs2_device_list* added) @@ -199,11 +61,12 @@ device::device( std::shared_ptr< const device_info > const & dev_info, } }); - _callback_id = get_context()->register_internal_device_callback( { cb, - []( rs2_devices_changed_callback * p ) - { - p->release(); - } } ); + _device_changed_callback_id + = get_context()->register_internal_device_callback( { cb, + []( rs2_devices_changed_callback * p ) + { + p->release(); + } } ); } } @@ -211,10 +74,9 @@ device::~device() { *_is_alive = false; - if (_device_changed_notifications) - { - get_context()->unregister_internal_device_callback(_callback_id); - } + if( _device_changed_callback_id ) + get_context()->unregister_internal_device_callback( _device_changed_callback_id ); + _sensors.clear(); } diff --git a/src/device.h b/src/device.h index 8b2861b536..c2f538d22d 100644 --- a/src/device.h +++ b/src/device.h @@ -3,51 +3,35 @@ #pragma once -#include "archive.h" -#include "hw-monitor.h" -#include "option.h" -#include "sensor.h" -#include "sync.h" -#include "core/streaming.h" +#include "basics.h" // C4250 +#include "core/device-interface.h" +#include "core/info.h" -#include "context.h" +#include "device-info.h" #include - #include #include #include -namespace librealsense -{ +namespace librealsense { - -stream_interface * find_profile( rs2_stream stream, int index, std::vector< stream_interface * > const & profiles ); -class matcher_factory +enum class format_conversion { -public: - static std::shared_ptr< matcher > create( rs2_matchers matcher, - std::vector< stream_interface * > const & profiles ); - -private: - static std::shared_ptr< matcher > create_DLR_C_matcher( std::vector< stream_interface * > const & profiles ); - static std::shared_ptr< matcher > create_DLR_matcher( std::vector< stream_interface * > const & profiles ); - static std::shared_ptr< matcher > create_DI_C_matcher( std::vector< stream_interface * > const & profiles ); - static std::shared_ptr< matcher > create_DI_matcher( std::vector< stream_interface * > const & profiles ); - static std::shared_ptr< matcher > create_DIC_matcher( std::vector< stream_interface* > const& profiles ); - static std::shared_ptr< matcher > create_DIC_C_matcher( std::vector< stream_interface * > const & profiles ); - - static std::shared_ptr< matcher > create_identity_matcher( stream_interface * profiles ); - static std::shared_ptr< matcher > create_frame_number_matcher( std::vector< stream_interface * > const & profiles ); - static std::shared_ptr< matcher > create_timestamp_matcher( std::vector< stream_interface * > const & profiles ); - - static std::shared_ptr< matcher > create_timestamp_composite_matcher( std::vector< std::shared_ptr< matcher > > const & matchers ); - static std::shared_ptr< matcher > create_frame_number_composite_matcher( std::vector< std::shared_ptr< matcher > > const & matchers ); + raw, + basic, + full }; -class device : public virtual device_interface, public info_container + +// Base implementation for most devices in librealsense. While it's not necessary to derive from this class, it greatly +// simplifies implementations. +// +class device + : public virtual device_interface + , public info_container { public: virtual ~device(); @@ -82,11 +66,10 @@ class device : public virtual device_interface, public info_container virtual void stop_activity() const; - bool device_changed_notifications_on() const { return _device_changed_notifications; } + bool device_changed_notifications_on() const { return _device_changed_callback_id; } format_conversion get_format_conversion() const; - uint16_t _pid; protected: int add_sensor(const std::shared_ptr& sensor_base); int assign_sensor(const std::shared_ptr& sensor_base, uint8_t idx); @@ -100,23 +83,13 @@ class device : public virtual device_interface, public info_container private: std::vector> _sensors; std::shared_ptr< const device_info > _dev_info; - bool _is_valid, _device_changed_notifications; + bool _is_valid; mutable std::mutex _device_changed_mtx; - uint64_t _callback_id; + uint64_t _device_changed_callback_id = 0; rsutils::lazy< std::vector< tagged_profile > > _profiles_tags; std::shared_ptr< bool > _is_alive; // Ensures object can be accessed }; -// Helper function that should be used when multiple FW calls needs to be made. -// This function change the USB power to D0 (Operational) using the invoke_power function -// activate the received function and power down the state to D3 (Idle) -template -auto group_multiple_fw_calls(synthetic_sensor& s, T action) --> decltype(action()) -{ - auto& us = dynamic_cast(*s.get_raw_sensor()); - return us.invoke_powered([&](platform::uvc_device& dev) { return action(); }); -} } diff --git a/src/ds/CMakeLists.txt b/src/ds/CMakeLists.txt index f9a0d7e22f..fac500a41e 100644 --- a/src/ds/CMakeLists.txt +++ b/src/ds/CMakeLists.txt @@ -18,6 +18,7 @@ target_sources(${LRS_TARGET} "${CMAKE_CURRENT_LIST_DIR}/advanced_mode/advanced_mode.cpp" "${CMAKE_CURRENT_LIST_DIR}/ds-calib-parsers.cpp" "${CMAKE_CURRENT_LIST_DIR}/ds-device-common.h" + "${CMAKE_CURRENT_LIST_DIR}/ds-device.h" "${CMAKE_CURRENT_LIST_DIR}/ds-motion-common.h" "${CMAKE_CURRENT_LIST_DIR}/ds-color-common.h" "${CMAKE_CURRENT_LIST_DIR}/ds-active-common.h" diff --git a/src/ds/d400/d400-device.cpp b/src/ds/d400/d400-device.cpp index 83de344c8d..fca3dc4ad9 100644 --- a/src/ds/d400/d400-device.cpp +++ b/src/ds/d400/d400-device.cpp @@ -498,7 +498,7 @@ namespace librealsense } d400_device::d400_device( std::shared_ptr< const d400_info > const & dev_info ) - : device(dev_info), global_time_interface(), + : ds_device(dev_info), global_time_interface(), auto_calibrated(), _device_capabilities(ds::ds_caps::CAP_UNDEFINED), _depth_stream(new stream(RS2_STREAM_DEPTH)), diff --git a/src/ds/d400/d400-device.h b/src/ds/d400/d400-device.h index 05ed96491b..09be80f9ab 100644 --- a/src/ds/d400/d400-device.h +++ b/src/ds/d400/d400-device.h @@ -16,13 +16,19 @@ #include "d400-options.h" #include "ds/ds-device-common.h" +#include "ds/ds-device.h" namespace librealsense { class hdr_config; class d400_thermal_monitor; - class d400_device : public virtual device, public debug_interface, public global_time_interface, public updatable, public auto_calibrated + class d400_device + : public virtual ds_device + , public debug_interface + , public global_time_interface + , public updatable + , public auto_calibrated { public: std::shared_ptr create_depth_device(std::shared_ptr ctx, diff --git a/src/ds/d400/d400-factory.cpp b/src/ds/d400/d400-factory.cpp index 02b37a560d..2e10794481 100644 --- a/src/ds/d400/d400-factory.cpp +++ b/src/ds/d400/d400-factory.cpp @@ -12,6 +12,8 @@ #include "image.h" #include "metadata-parser.h" +#include + #include "d400-info.h" #include "d400-private.h" #include "d400-options.h" @@ -39,6 +41,7 @@ namespace librealsense public: rs400_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) : device( dev_info, register_device_notifications ) + , ds_device( dev_info, register_device_notifications ) , d400_device( dev_info ) , d400_nonmonochrome( dev_info ) , ds_advanced_mode_base( d400_device::_hw_monitor, get_depth_sensor() ) @@ -77,6 +80,7 @@ namespace librealsense public: rs405u_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) : device(dev_info, register_device_notifications), + ds_device( dev_info, register_device_notifications ), ds5u_device(dev_info), ds_advanced_mode_base(d400_device::_hw_monitor, get_depth_sensor()), firmware_logger_device(dev_info, d400_device::_hw_monitor, @@ -125,16 +129,17 @@ namespace librealsense public firmware_logger_device { public: - rs410_device( std::shared_ptr< const d400_info > const & dev_info, - bool register_device_notifications) - : device(dev_info, register_device_notifications), - d400_device(dev_info), - d400_nonmonochrome(dev_info), - d400_active(dev_info), - ds_advanced_mode_base(d400_device::_hw_monitor, get_depth_sensor()), - firmware_logger_device(dev_info, d400_device::_hw_monitor, - get_firmware_logs_command(), - get_flash_logs_command()) {} + rs410_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) + : device( dev_info, register_device_notifications ) + , ds_device( dev_info, register_device_notifications ) + , d400_device( dev_info ) + , d400_nonmonochrome( dev_info ) + , d400_active( dev_info ) + , ds_advanced_mode_base( d400_device::_hw_monitor, get_depth_sensor() ) + , firmware_logger_device( + dev_info, d400_device::_hw_monitor, get_firmware_logs_command(), get_flash_logs_command() ) + { + } std::shared_ptr create_matcher(const frame_holder& frame) const override; @@ -163,17 +168,18 @@ namespace librealsense public firmware_logger_device { public: - rs415_device( std::shared_ptr< const d400_info > const & dev_info, - bool register_device_notifications) - : device(dev_info, register_device_notifications), - d400_device(dev_info), - d400_nonmonochrome(dev_info), - d400_active(dev_info), - d400_color(dev_info), - ds_advanced_mode_base(d400_device::_hw_monitor, get_depth_sensor()), - firmware_logger_device(dev_info, d400_device::_hw_monitor, - get_firmware_logs_command(), - get_flash_logs_command()) {} + rs415_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) + : device( dev_info, register_device_notifications ) + , ds_device( dev_info, register_device_notifications ) + , d400_device( dev_info ) + , d400_nonmonochrome( dev_info ) + , d400_active( dev_info ) + , d400_color( dev_info ) + , ds_advanced_mode_base( d400_device::_hw_monitor, get_depth_sensor() ) + , firmware_logger_device( + dev_info, d400_device::_hw_monitor, get_firmware_logs_command(), get_flash_logs_command() ) + { + } std::shared_ptr create_matcher(const frame_holder& frame) const override; @@ -203,16 +209,17 @@ namespace librealsense public firmware_logger_device { public: - rs416_device( std::shared_ptr< const d400_info > const & dev_info, - bool register_device_notifications) - : device(dev_info, register_device_notifications), - d400_device(dev_info), - d400_nonmonochrome(dev_info), - d400_active(dev_info), - ds_advanced_mode_base(d400_device::_hw_monitor, get_depth_sensor()), - firmware_logger_device(dev_info, d400_device::_hw_monitor, - get_firmware_logs_command(), - get_flash_logs_command()) {} + rs416_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) + : device( dev_info, register_device_notifications ) + , ds_device( dev_info, register_device_notifications ) + , d400_device( dev_info ) + , d400_nonmonochrome( dev_info ) + , d400_active( dev_info ) + , ds_advanced_mode_base( d400_device::_hw_monitor, get_depth_sensor() ) + , firmware_logger_device( + dev_info, d400_device::_hw_monitor, get_firmware_logs_command(), get_flash_logs_command() ) + { + } std::shared_ptr create_matcher(const frame_holder& frame) const override; @@ -256,17 +263,18 @@ namespace librealsense { public: - rs416_rgb_device( std::shared_ptr< const d400_info > const & dev_info, - bool register_device_notifications) - : device(dev_info, register_device_notifications), - d400_device(dev_info), - d400_nonmonochrome(dev_info), - d400_active(dev_info), - d400_color(dev_info), - ds_advanced_mode_base(d400_device::_hw_monitor, get_depth_sensor()), - firmware_logger_device(dev_info, d400_device::_hw_monitor, - get_firmware_logs_command(), - get_flash_logs_command()) {} + rs416_rgb_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) + : device( dev_info, register_device_notifications ) + , ds_device( dev_info, register_device_notifications ) + , d400_device( dev_info ) + , d400_nonmonochrome( dev_info ) + , d400_active( dev_info ) + , d400_color( dev_info ) + , ds_advanced_mode_base( d400_device::_hw_monitor, get_depth_sensor() ) + , firmware_logger_device( + dev_info, d400_device::_hw_monitor, get_firmware_logs_command(), get_flash_logs_command() ) + { + } std::shared_ptr create_matcher(const frame_holder& frame) const override; @@ -309,15 +317,16 @@ namespace librealsense public firmware_logger_device { public: - rs420_mm_device( std::shared_ptr< const d400_info > const & dev_info, - bool register_device_notifications) - : device(dev_info, register_device_notifications), - d400_device(dev_info), - d400_motion(dev_info), - ds_advanced_mode_base(d400_device::_hw_monitor, get_depth_sensor()), - firmware_logger_device(dev_info, d400_device::_hw_monitor, - get_firmware_logs_command(), - get_flash_logs_command()) {} + rs420_mm_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) + : device( dev_info, register_device_notifications ) + , ds_device( dev_info, register_device_notifications ) + , d400_device( dev_info ) + , d400_motion( dev_info ) + , ds_advanced_mode_base( d400_device::_hw_monitor, get_depth_sensor() ) + , firmware_logger_device( + dev_info, d400_device::_hw_monitor, get_firmware_logs_command(), get_flash_logs_command() ) + { + } std::shared_ptr create_matcher(const frame_holder& frame) const override; @@ -356,14 +365,15 @@ namespace librealsense public firmware_logger_device { public: - rs420_device( std::shared_ptr< const d400_info > const & dev_info, - bool register_device_notifications) - : device(dev_info, register_device_notifications), - d400_device(dev_info), - ds_advanced_mode_base(d400_device::_hw_monitor, get_depth_sensor()), - firmware_logger_device(dev_info, d400_device::_hw_monitor, - get_firmware_logs_command(), - get_flash_logs_command()) {} + rs420_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) + : device( dev_info, register_device_notifications ) + , ds_device( dev_info, register_device_notifications ) + , d400_device( dev_info ) + , ds_advanced_mode_base( d400_device::_hw_monitor, get_depth_sensor() ) + , firmware_logger_device( + dev_info, d400_device::_hw_monitor, get_firmware_logs_command(), get_flash_logs_command() ) + { + } std::shared_ptr create_matcher(const frame_holder& frame) const override; @@ -393,15 +403,16 @@ namespace librealsense public firmware_logger_device { public: - rs430_device( std::shared_ptr< const d400_info > const & dev_info, - bool register_device_notifications) - : device(dev_info, register_device_notifications), - d400_device(dev_info), - d400_active(dev_info), - ds_advanced_mode_base(d400_device::_hw_monitor, get_depth_sensor()), - firmware_logger_device(dev_info, d400_device::_hw_monitor, - get_firmware_logs_command(), - get_flash_logs_command()) {} + rs430_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) + : device( dev_info, register_device_notifications ) + , ds_device( dev_info, register_device_notifications ) + , d400_device( dev_info ) + , d400_active( dev_info ) + , ds_advanced_mode_base( d400_device::_hw_monitor, get_depth_sensor() ) + , firmware_logger_device( + dev_info, d400_device::_hw_monitor, get_firmware_logs_command(), get_flash_logs_command() ) + { + } std::shared_ptr create_matcher(const frame_holder& frame) const override; @@ -431,17 +442,17 @@ namespace librealsense public firmware_logger_device { public: - rs430i_device( std::shared_ptr< const d400_info > const & dev_info, - bool register_device_notifications) - : device(dev_info, register_device_notifications), - d400_device(dev_info), - d400_active(dev_info), - ds_advanced_mode_base(d400_device::_hw_monitor, get_depth_sensor()), - d400_motion(dev_info), - firmware_logger_device(dev_info, d400_device::_hw_monitor, - get_firmware_logs_command(), - get_flash_logs_command()) - {} + rs430i_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) + : device( dev_info, register_device_notifications ) + , ds_device( dev_info, register_device_notifications ) + , d400_device( dev_info ) + , d400_active( dev_info ) + , ds_advanced_mode_base( d400_device::_hw_monitor, get_depth_sensor() ) + , d400_motion( dev_info ) + , firmware_logger_device( + dev_info, d400_device::_hw_monitor, get_firmware_logs_command(), get_flash_logs_command() ) + { + } std::vector get_profiles_tags() const override { @@ -475,16 +486,17 @@ namespace librealsense public firmware_logger_device { public: - rs430_mm_device( std::shared_ptr< const d400_info > const & dev_info, - bool register_device_notifications) - : device(dev_info, register_device_notifications), - d400_device(dev_info), - d400_active(dev_info), - d400_motion(dev_info), - ds_advanced_mode_base(d400_device::_hw_monitor, get_depth_sensor()), - firmware_logger_device(dev_info, d400_device::_hw_monitor, - get_firmware_logs_command(), - get_flash_logs_command()) {} + rs430_mm_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) + : device( dev_info, register_device_notifications ) + , ds_device( dev_info, register_device_notifications ) + , d400_device( dev_info ) + , d400_active( dev_info ) + , d400_motion( dev_info ) + , ds_advanced_mode_base( d400_device::_hw_monitor, get_depth_sensor() ) + , firmware_logger_device( + dev_info, d400_device::_hw_monitor, get_firmware_logs_command(), get_flash_logs_command() ) + { + } std::shared_ptr create_matcher(const frame_holder& frame) const override; @@ -525,16 +537,17 @@ namespace librealsense public firmware_logger_device { public: - rs435_device( std::shared_ptr< const d400_info > const & dev_info, - bool register_device_notifications) - : device(dev_info, register_device_notifications), - d400_device(dev_info), - d400_active(dev_info), - d400_color(dev_info), - ds_advanced_mode_base(d400_device::_hw_monitor, get_depth_sensor()), - firmware_logger_device(dev_info, d400_device::_hw_monitor, - get_firmware_logs_command(), - get_flash_logs_command()) {} + rs435_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) + : device( dev_info, register_device_notifications ) + , ds_device( dev_info, register_device_notifications ) + , d400_device( dev_info ) + , d400_active( dev_info ) + , d400_color( dev_info ) + , ds_advanced_mode_base( d400_device::_hw_monitor, get_depth_sensor() ) + , firmware_logger_device( + dev_info, d400_device::_hw_monitor, get_firmware_logs_command(), get_flash_logs_command() ) + { + } std::shared_ptr create_matcher(const frame_holder& frame) const override; @@ -566,17 +579,18 @@ namespace librealsense public firmware_logger_device { public: - rs457_device( std::shared_ptr< const d400_info > const & dev_info, - bool register_device_notifications) - : device(dev_info, register_device_notifications), - d400_device(dev_info), - d400_active(dev_info), - d400_color(dev_info), - d400_motion_uvc(dev_info), - ds_advanced_mode_base(d400_device::_hw_monitor, get_depth_sensor()), - firmware_logger_device(dev_info, d400_device::_hw_monitor, - get_firmware_logs_command(), - get_flash_logs_command()){} + rs457_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) + : device( dev_info, register_device_notifications ) + , ds_device( dev_info, register_device_notifications ) + , d400_device( dev_info ) + , d400_active( dev_info ) + , d400_color( dev_info ) + , d400_motion_uvc( dev_info ) + , ds_advanced_mode_base( d400_device::_hw_monitor, get_depth_sensor() ) + , firmware_logger_device( + dev_info, d400_device::_hw_monitor, get_firmware_logs_command(), get_flash_logs_command() ) + { + } std::shared_ptr create_matcher(const frame_holder& frame) const override; @@ -599,17 +613,18 @@ namespace librealsense public firmware_logger_device { public: - rs430_rgb_mm_device( std::shared_ptr< const d400_info > const & dev_info, - bool register_device_notifications) - : device(dev_info, register_device_notifications), - d400_device(dev_info), - d400_active(dev_info), - d400_color(dev_info), - d400_motion(dev_info), - ds_advanced_mode_base(d400_device::_hw_monitor, get_depth_sensor()), - firmware_logger_device(dev_info, d400_device::_hw_monitor, - get_firmware_logs_command(), - get_flash_logs_command()) {} + rs430_rgb_mm_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) + : device( dev_info, register_device_notifications ) + , ds_device( dev_info, register_device_notifications ) + , d400_device( dev_info ) + , d400_active( dev_info ) + , d400_color( dev_info ) + , d400_motion( dev_info ) + , ds_advanced_mode_base( d400_device::_hw_monitor, get_depth_sensor() ) + , firmware_logger_device( + dev_info, d400_device::_hw_monitor, get_firmware_logs_command(), get_flash_logs_command() ) + { + } std::shared_ptr create_matcher(const frame_holder& frame) const override; @@ -641,17 +656,16 @@ namespace librealsense public firmware_logger_device { public: - rs435i_device( std::shared_ptr< const d400_info > const & dev_info, - bool register_device_notifications) - : device(dev_info, register_device_notifications), - d400_device(dev_info), - d400_active(dev_info), - d400_color(dev_info), - d400_motion(dev_info), - ds_advanced_mode_base(d400_device::_hw_monitor, get_depth_sensor()), - firmware_logger_device(dev_info, d400_device::_hw_monitor, - get_firmware_logs_command(), - get_flash_logs_command()) + rs435i_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) + : device( dev_info, register_device_notifications ) + , ds_device( dev_info, register_device_notifications ) + , d400_device( dev_info ) + , d400_active( dev_info ) + , d400_color( dev_info ) + , d400_motion( dev_info ) + , ds_advanced_mode_base( d400_device::_hw_monitor, get_depth_sensor() ) + , firmware_logger_device( + dev_info, d400_device::_hw_monitor, get_firmware_logs_command(), get_flash_logs_command() ) { check_and_restore_rgb_stream_extrinsic(); } @@ -860,18 +874,19 @@ namespace librealsense public firmware_logger_device { public: - rs465_device( std::shared_ptr< const d400_info > const & dev_info, - bool register_device_notifications) - : device(dev_info, register_device_notifications), - d400_device(dev_info), - d400_active(dev_info), - d400_color(dev_info), - d400_motion(dev_info), - d400_nonmonochrome(dev_info), - ds_advanced_mode_base(d400_device::_hw_monitor, get_depth_sensor()), - firmware_logger_device(dev_info, d400_device::_hw_monitor, - get_firmware_logs_command(), - get_flash_logs_command()) {} + rs465_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) + : device( dev_info, register_device_notifications ) + , ds_device( dev_info, register_device_notifications ) + , d400_device( dev_info ) + , d400_active( dev_info ) + , d400_color( dev_info ) + , d400_motion( dev_info ) + , d400_nonmonochrome( dev_info ) + , ds_advanced_mode_base( d400_device::_hw_monitor, get_depth_sensor() ) + , firmware_logger_device( + dev_info, d400_device::_hw_monitor, get_firmware_logs_command(), get_flash_logs_command() ) + { + } std::shared_ptr create_matcher(const frame_holder& frame) const override; @@ -900,15 +915,16 @@ namespace librealsense public firmware_logger_device { public: - rs400_imu_device( std::shared_ptr< const d400_info > const & dev_info, - bool register_device_notifications) - : device(dev_info, register_device_notifications), - d400_device(dev_info), - d400_motion(dev_info), - ds_advanced_mode_base(d400_device::_hw_monitor, get_depth_sensor()), - firmware_logger_device(dev_info, d400_device::_hw_monitor, - get_firmware_logs_command(), - get_flash_logs_command()) {} + rs400_imu_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) + : device( dev_info, register_device_notifications ) + , ds_device( dev_info, register_device_notifications ) + , d400_device( dev_info ) + , d400_motion( dev_info ) + , ds_advanced_mode_base( d400_device::_hw_monitor, get_depth_sensor() ) + , firmware_logger_device( + dev_info, d400_device::_hw_monitor, get_firmware_logs_command(), get_flash_logs_command() ) + { + } std::shared_ptr create_matcher(const frame_holder& frame) const override; @@ -929,16 +945,17 @@ namespace librealsense public firmware_logger_device { public: - rs405_device( std::shared_ptr< const d400_info > const & dev_info, - bool register_device_notifications) - : device(dev_info, register_device_notifications), - d400_device(dev_info), - d400_color(dev_info), - d400_nonmonochrome(dev_info), - ds_advanced_mode_base(d400_device::_hw_monitor, get_depth_sensor()), - firmware_logger_device(dev_info, d400_device::_hw_monitor, - get_firmware_logs_command(), - get_flash_logs_command()) {} + rs405_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) + : device( dev_info, register_device_notifications ) + , ds_device( dev_info, register_device_notifications ) + , d400_device( dev_info ) + , d400_color( dev_info ) + , d400_nonmonochrome( dev_info ) + , ds_advanced_mode_base( d400_device::_hw_monitor, get_depth_sensor() ) + , firmware_logger_device( + dev_info, d400_device::_hw_monitor, get_firmware_logs_command(), get_flash_logs_command() ) + { + } std::shared_ptr create_matcher(const frame_holder& frame) const override; @@ -1015,20 +1032,20 @@ namespace librealsense public d400_thermal_tracking { public: - rs455_device( std::shared_ptr< const d400_info > const & dev_info, - bool register_device_notifications) - : device(dev_info, register_device_notifications), - d400_device(dev_info), - d400_nonmonochrome(dev_info), - d400_active(dev_info), - d400_color(dev_info), - d400_motion(dev_info), - ds_advanced_mode_base(d400_device::_hw_monitor, get_depth_sensor()), - firmware_logger_device(dev_info, d400_device::_hw_monitor, - get_firmware_logs_command(), - get_flash_logs_command()), - d400_thermal_tracking(d400_device::_thermal_monitor) - {} + rs455_device( std::shared_ptr< const d400_info > const & dev_info, bool register_device_notifications ) + : device( dev_info, register_device_notifications ) + , ds_device( dev_info, register_device_notifications ) + , d400_device( dev_info ) + , d400_nonmonochrome( dev_info ) + , d400_active( dev_info ) + , d400_color( dev_info ) + , d400_motion( dev_info ) + , ds_advanced_mode_base( d400_device::_hw_monitor, get_depth_sensor() ) + , firmware_logger_device( + dev_info, d400_device::_hw_monitor, get_firmware_logs_command(), get_flash_logs_command() ) + , d400_thermal_tracking( d400_device::_thermal_monitor ) + { + } std::shared_ptr create_matcher(const frame_holder& frame) const override; diff --git a/src/ds/d500/d500-device.cpp b/src/ds/d500/d500-device.cpp index e357d187b9..a03caf3427 100644 --- a/src/ds/d500/d500-device.cpp +++ b/src/ds/d500/d500-device.cpp @@ -375,7 +375,7 @@ namespace librealsense } d500_device::d500_device( std::shared_ptr< const d500_info > const & dev_info ) - : device(dev_info), global_time_interface(), + : ds_device(dev_info), global_time_interface(), _device_capabilities(ds::ds_caps::CAP_UNDEFINED), _depth_stream(new stream(RS2_STREAM_DEPTH)), _left_ir_stream(new stream(RS2_STREAM_INFRARED, 1)), diff --git a/src/ds/d500/d500-device.h b/src/ds/d500/d500-device.h index 83299fca00..a32d8f9642 100644 --- a/src/ds/d500/d500-device.h +++ b/src/ds/d500/d500-device.h @@ -17,6 +17,7 @@ #include "ds/ds-options.h" #include "ds/ds-device-common.h" +#include "ds/ds-device.h" #include @@ -28,7 +29,15 @@ namespace librealsense class ds_devices_common; class d500_info; - class d500_device : public virtual device, public debug_interface, public global_time_interface, public updatable + namespace platform { + struct backend_device_group; + } + + class d500_device + : public virtual ds_device + , public debug_interface + , public global_time_interface + , public updatable { public: std::shared_ptr create_depth_device(std::shared_ptr ctx, diff --git a/src/ds/d500/d500-factory.cpp b/src/ds/d500/d500-factory.cpp index 3cc4ad8694..e090c90372 100644 --- a/src/ds/d500/d500-factory.cpp +++ b/src/ds/d500/d500-factory.cpp @@ -12,6 +12,8 @@ #include "image.h" #include "metadata-parser.h" +#include + #include "d500-info.h" #include "d500-private.h" #include "ds/ds-options.h" @@ -37,7 +39,8 @@ class d555e_device { public: d555e_device( std::shared_ptr< const d500_info > dev_info ) - : device( dev_info, true ) + : device( dev_info ) + , ds_device( dev_info ) , d500_device( dev_info ) , d500_active( dev_info ) , d500_color( dev_info ) diff --git a/src/ds/ds-active-common.cpp b/src/ds/ds-active-common.cpp index 0ad386592e..d58155867b 100644 --- a/src/ds/ds-active-common.cpp +++ b/src/ds/ds-active-common.cpp @@ -10,7 +10,7 @@ namespace librealsense ds_active_common::ds_active_common(uvc_sensor& raw_depth_ep, synthetic_sensor& depth_ep, - device* owner, + ds_device* owner, ds_caps device_capabilities, std::shared_ptr hw_monitor, firmware_version fw_version) : @@ -24,7 +24,7 @@ namespace librealsense void ds_active_common::register_options() { //Projector's capacity is established based on actual HW capabilities - auto pid = _owner->_pid; + auto pid = _owner->get_pid(); if ((pid != RS_USB2_PID) && ((_device_capabilities & ds_caps::CAP_ACTIVE_PROJECTOR) == ds_caps::CAP_ACTIVE_PROJECTOR)) { //EMITTER ENABLED OPTION diff --git a/src/ds/ds-active-common.h b/src/ds/ds-active-common.h index 08a2e9d3dd..e1c4d16318 100644 --- a/src/ds/ds-active-common.h +++ b/src/ds/ds-active-common.h @@ -10,12 +10,14 @@ namespace librealsense { + class ds_device; + class ds_active_common { public: ds_active_common(uvc_sensor& raw_color_ep, synthetic_sensor& color_ep, - device* owner, + ds_device* owner, ds::ds_caps device_capabilities, std::shared_ptr hw_monitor, firmware_version firmware_version); @@ -24,7 +26,7 @@ namespace librealsense private: uvc_sensor& _raw_depth_ep; synthetic_sensor& _depth_ep; - device* _owner; + ds_device* _owner; ds::ds_caps _device_capabilities; std::shared_ptr _hw_monitor; firmware_version _fw_version; diff --git a/src/ds/ds-color-common.cpp b/src/ds/ds-color-common.cpp index 10ad74b55b..bfc0d57170 100644 --- a/src/ds/ds-color-common.cpp +++ b/src/ds/ds-color-common.cpp @@ -3,6 +3,7 @@ #include "ds-color-common.h" #include "metadata.h" +#include #include diff --git a/src/ds/ds-device.h b/src/ds/ds-device.h new file mode 100644 index 0000000000..3e970e5f47 --- /dev/null +++ b/src/ds/ds-device.h @@ -0,0 +1,32 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2023 Intel Corporation. All Rights Reserved. + +#pragma once + +#include + + +namespace librealsense { + + +// Common base class for all Stereo devices +// +class ds_device : public virtual device +{ + typedef device super; + +protected: + ds_device( std::shared_ptr< const device_info > const & dev_info, bool device_changed_notifications = true ) + : super( dev_info, device_changed_notifications ) + { + } + +public: + uint16_t get_pid() const { return _pid; } + +protected: + uint16_t _pid = 0; +}; + + +} // namespace librealsense diff --git a/src/ds/ds-motion-common.cpp b/src/ds/ds-motion-common.cpp index 54f68f5319..99836ba3f7 100644 --- a/src/ds/ds-motion-common.cpp +++ b/src/ds/ds-motion-common.cpp @@ -260,7 +260,7 @@ namespace librealsense return auto_exposure; } - ds_motion_common::ds_motion_common(device* owner, + ds_motion_common::ds_motion_common(ds_device* owner, firmware_version fw_version, const ds::ds_caps& device_capabilities, std::shared_ptr hwm) : @@ -281,7 +281,7 @@ namespace librealsense { unsigned(odr::IMU_FPS_400), hid_fps_translation.at(odr::IMU_FPS_400)}}} }; // motion correction - _mm_calib = std::make_shared(_hw_monitor, _owner->_pid); + _mm_calib = std::make_shared(_hw_monitor, _owner->get_pid()); } rs2_motion_device_intrinsic ds_motion_common::get_motion_intrinsics(rs2_stream stream) const @@ -517,7 +517,7 @@ namespace librealsense if (!is_infos_empty) { // motion correction - _mm_calib = std::make_shared(_hw_monitor, _owner->_pid); + _mm_calib = std::make_shared< mm_calib_handler >( _hw_monitor, _owner->get_pid() ); _accel_intrinsic = std::make_shared< rsutils::lazy< ds::imu_intrinsic > >( [this]() { return _mm_calib->get_intrinsic( RS2_STREAM_ACCEL ); } ); diff --git a/src/ds/ds-motion-common.h b/src/ds/ds-motion-common.h index 58331f6746..e4a006d1fc 100644 --- a/src/ds/ds-motion-common.h +++ b/src/ds/ds-motion-common.h @@ -111,10 +111,12 @@ namespace librealsense struct backend_device_group; } + class ds_device; + class ds_motion_common { public: - ds_motion_common(device* owner, + ds_motion_common(ds_device* owner, firmware_version fw_version, const ds::ds_caps& device_capabilities, std::shared_ptr hwm); @@ -162,7 +164,7 @@ namespace librealsense friend class ds_motion_sensor; friend class ds_fisheye_sensor; - device* _owner; + ds_device * _owner; firmware_version _fw_version; ds::ds_caps _device_capabilities; std::shared_ptr _hw_monitor; diff --git a/src/firmware_logger_device.h b/src/firmware_logger_device.h index c6e5966c78..cd77dcf319 100644 --- a/src/firmware_logger_device.h +++ b/src/firmware_logger_device.h @@ -5,6 +5,7 @@ #include "core/extension.h" #include "device.h" +#include "hw-monitor.h" #include #include "fw-logs/fw-log-data.h" #include "fw-logs/fw-logs-parser.h" diff --git a/src/fw-update/fw-update-device-interface.h b/src/fw-update/fw-update-device-interface.h index 5b36438d80..6338db795c 100644 --- a/src/fw-update/fw-update-device-interface.h +++ b/src/fw-update/fw-update-device-interface.h @@ -5,6 +5,7 @@ #include "../types.h" #include "../core/streaming.h" +#include #include "../usb/usb-types.h" #include diff --git a/src/gl/camera-shader.cpp b/src/gl/camera-shader.cpp index 085dd5d3b5..84ab6292fa 100644 --- a/src/gl/camera-shader.cpp +++ b/src/gl/camera-shader.cpp @@ -4,6 +4,7 @@ #include "camera-shader.h" #include "rendering.h" #include "option.h" +#include using namespace rs2; diff --git a/src/image.cpp b/src/image.cpp index 80fdef6bc8..ec17560964 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -57,14 +57,6 @@ namespace librealsense } } - ////////////////////////////////////// - // Frame rotation routines // - ////////////////////////////////////// - resolution rotate_resolution(resolution res) - { - return resolution{ res.height , res.width}; - } - } #pragma pack(pop) diff --git a/src/image.h b/src/image.h index 8ae6f9364d..66b1b73b5a 100644 --- a/src/image.h +++ b/src/image.h @@ -25,8 +25,6 @@ namespace librealsense } } } - - resolution rotate_resolution(resolution res); } #endif diff --git a/src/media/playback/playback_device.h b/src/media/playback/playback_device.h index 5403b2c44f..5a0afff30f 100644 --- a/src/media/playback/playback_device.h +++ b/src/media/playback/playback_device.h @@ -7,6 +7,7 @@ #include "../../core/extension.h" #include "../../core/serialization.h" #include "../../core/streaming.h" +#include #include "../../archive.h" #include "../../sensor.h" #include "playback_sensor.h" diff --git a/src/media/record/record_device.h b/src/media/record/record_device.h index e1b075abef..1d4eb408f4 100644 --- a/src/media/record/record_device.h +++ b/src/media/record/record_device.h @@ -6,6 +6,7 @@ #include #include #include "core/streaming.h" +#include #include "archive.h" #include "sensor.h" #include "record_sensor.h" diff --git a/src/media/ros/ros_writer.cpp b/src/media/ros/ros_writer.cpp index 0949c8a3ea..d28d475ad5 100644 --- a/src/media/ros/ros_writer.cpp +++ b/src/media/ros/ros_writer.cpp @@ -12,6 +12,7 @@ #include "ros_writer.h" #include "core/pose-frame.h" #include "core/motion-frame.h" +#include #include diff --git a/src/pipeline/resolver.h b/src/pipeline/resolver.h index d991abd95a..b5a6b58721 100644 --- a/src/pipeline/resolver.h +++ b/src/pipeline/resolver.h @@ -12,6 +12,7 @@ #include "sensor.h" #include "types.h" #include "stream.h" +#include namespace librealsense { diff --git a/src/proc/formats-converter.cpp b/src/proc/formats-converter.cpp index b60b4dc952..8b481f2e5a 100644 --- a/src/proc/formats-converter.cpp +++ b/src/proc/formats-converter.cpp @@ -121,9 +121,11 @@ stream_profiles formats_converter::get_all_possible_profiles( const stream_profi auto cloned_vsp = As< video_stream_profile, stream_profile_interface >( cloned_profile ); if( cloned_vsp ) { - // Converter may rotate the image, invoke stream_resolution function to get actual result - const auto res = target.stream_resolution( { cloned_vsp->get_width(), cloned_vsp->get_height() } ); - cloned_vsp->set_dims( res.width, res.height ); + // Conversion may involve changing the resolution (rotation, expansion, etc.) + auto width = cloned_vsp->get_width(); + auto height = cloned_vsp->get_height(); + target.resolution_transform( width, height ); + cloned_vsp->set_dims( width, height ); } LOG_DEBUG( " -> " << cloned_profile ); diff --git a/src/proc/processing-blocks-factory.h b/src/proc/processing-blocks-factory.h index 59e588978f..5784b85007 100644 --- a/src/proc/processing-blocks-factory.h +++ b/src/proc/processing-blocks-factory.h @@ -3,6 +3,8 @@ #pragma once +#include + #include #include "align.h" diff --git a/src/sensor.h b/src/sensor.h index caaaaa5d61..88d7d759bb 100644 --- a/src/sensor.h +++ b/src/sensor.h @@ -30,6 +30,7 @@ namespace librealsense { class device; class option; + enum class format_conversion; typedef std::function)> on_open; diff --git a/src/serialized-utilities.cpp b/src/serialized-utilities.cpp index cebfce9381..e86fdcb4a8 100644 --- a/src/serialized-utilities.cpp +++ b/src/serialized-utilities.cpp @@ -2,6 +2,7 @@ // Copyright(c) 2021 Intel Corporation. All Rights Reserved. #include "serialized-utilities.h" +#include #include namespace librealsense { diff --git a/src/software-device.cpp b/src/software-device.cpp index 67a1de774c..cb68e1ad2b 100644 --- a/src/software-device.cpp +++ b/src/software-device.cpp @@ -3,7 +3,9 @@ #include "software-device.h" #include "stream.h" +#include "option.h" #include "core/video-frame.h" +#include "core/matcher-factory.h" #include #include diff --git a/src/software-device.h b/src/software-device.h index 48fcacf4ef..256d141b33 100644 --- a/src/software-device.h +++ b/src/software-device.h @@ -4,7 +4,7 @@ #include "core/streaming.h" #include "device.h" -#include "context.h" +#include "sensor.h" #include #include diff --git a/src/stream.h b/src/stream.h index caba88cc79..251c6b7cd3 100644 --- a/src/stream.h +++ b/src/stream.h @@ -5,6 +5,7 @@ #include "core/streaming.h" #include "core/video.h" #include "core/motion.h" +#include "core/stream-profile.h" #include "context.h" #include "image.h" #include "environment.h" diff --git a/src/sync.cpp b/src/sync.cpp index 2a9fe38aee..a66922fa7f 100644 --- a/src/sync.cpp +++ b/src/sync.cpp @@ -5,6 +5,7 @@ #include "proc/synthetic-stream.h" #include "sync.h" #include "environment.h" +#include "core/device-interface.h" namespace librealsense { diff --git a/src/sync.h b/src/sync.h index 46acc877f9..cebcccc92d 100644 --- a/src/sync.h +++ b/src/sync.h @@ -14,44 +14,6 @@ namespace librealsense { - typedef int stream_id; - - class sync_lock - { - public: - sync_lock(std::mutex& mutex) : _mutex(mutex) - { - mutex.lock(); - } - - void unlock_preemptively() - { - // NOTE: The Sync_Lock is itself a single-threaded object - // It maintains a state, and does not protect its state. - // That is acceptable for our use case, - // because we use it to communicate within a single thread - if (!_is_locked) return; - _mutex.unlock(); - _is_locked = false; - - } - - ~sync_lock() - { - if (_is_locked) - { - _mutex.unlock(); - - } - } - - private: - bool _is_locked = true; - - std::mutex& _mutex; - }; - //sync_lock::ref = 0; - class synthetic_source_interface; struct syncronization_environment @@ -65,7 +27,6 @@ namespace librealsense { } synthetic_source_interface * source; - // sync_lock& lock_ref; single_consumer_frame_queue< frame_holder > & matches; bool log = true; }; diff --git a/src/types.h b/src/types.h index 6dd4cc9ba4..50c0600ada 100644 --- a/src/types.h +++ b/src/types.h @@ -54,8 +54,6 @@ template T rad2deg(T val) { return T(val * r2d); } // C++ version in std! using std::abs; -#pragma warning(disable: 4250) - #ifdef ANDROID #include "../common/android_helpers.h" #endif @@ -378,51 +376,6 @@ namespace librealsense // Pixel formats // /////////////////// - struct resolution - { - uint32_t width, height; - }; - using resolution_func = std::function; - - struct stream_profile - { - stream_profile(rs2_format fmt = RS2_FORMAT_ANY, - rs2_stream strm = RS2_STREAM_ANY, - int idx = 0, - uint32_t w = 0, uint32_t h = 0, - uint32_t framerate = 0, - resolution_func res_func = [](resolution res) { return res; }) : - format(fmt), stream(strm), index(idx), width(w), height(h), fps(framerate), stream_resolution(res_func) - {} - - rs2_format format; - rs2_stream stream; - int index; - uint32_t width, height, fps; - resolution_func stream_resolution; // Calculates the relevant resolution from the given backend resolution. - - std::pair< uint32_t, uint32_t > width_height() const { return std::make_pair( width, height ); } - }; - - - inline bool operator==(const stream_profile& a, - const stream_profile& b) - { - return (a.width == b.width) && - (a.height == b.height) && - (a.fps == b.fps) && - (a.format == b.format) && - (a.index == b.index) && - (a.stream == b.stream); - } - - inline bool operator<(const stream_profile & lhs, - const stream_profile & rhs) - { - if (lhs.format != rhs.format) return lhs.format < rhs.format; - if (lhs.index != rhs.index) return lhs.index < rhs.index; - return lhs.stream < rhs.stream; - } struct stream_descriptor { @@ -433,20 +386,6 @@ namespace librealsense int index; }; - struct stream_output { - stream_output(stream_descriptor stream_desc_in, - rs2_format format_in, - resolution_func res_func = [](resolution res) {return res; }) - : stream_desc(stream_desc_in), - format(format_in), - stream_resolution(res_func) - {} - - stream_descriptor stream_desc; - rs2_format format; - resolution_func stream_resolution; - }; - class stream_profile_interface; class frame_interface; @@ -1109,34 +1048,6 @@ uint32_t rs_fourcc(const T a, const T b, const T c, const T d) (static_cast(d) << 0)); } -namespace std { - - template <> - struct hash - { - size_t operator()(const librealsense::stream_profile& k) const - { - using std::hash; - - return (hash()(k.height)) - ^ (hash()(k.width)) - ^ (hash()(k.fps)) - ^ (hash()(k.format)) - ^ (hash()(k.stream)); - } - }; - - template <> - struct hash - { - size_t operator()(const rs2_format& f) const - { - using std::hash; - - return hash()(f); - } - }; -} enum res_type { low_resolution, diff --git a/src/uvc-sensor.h b/src/uvc-sensor.h index 54a268aa66..799aecdc02 100644 --- a/src/uvc-sensor.h +++ b/src/uvc-sensor.h @@ -90,4 +90,17 @@ class uvc_sensor : public raw_sensor_base }; +// Helper function that should be used when multiple FW calls needs to be made. +// This function change the USB power to D0 (Operational) using the invoke_power function +// activate the received function and power down the state to D3 (Idle) +// +template< class T > +auto group_multiple_fw_calls( synthetic_sensor & s, T action ) -> decltype( action() ) +{ + auto & us = dynamic_cast< uvc_sensor & >( *s.get_raw_sensor() ); + + return us.invoke_powered( [&]( platform::uvc_device & dev ) { return action(); } ); +} + + } // namespace librealsense