diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 04b797298c..f0064da8e0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -89,6 +89,8 @@ target_sources(${LRS_TARGET} "${CMAKE_CURRENT_LIST_DIR}/hid-sensor.cpp" "${CMAKE_CURRENT_LIST_DIR}/uvc-sensor.cpp" "${CMAKE_CURRENT_LIST_DIR}/software-device.cpp" + "${CMAKE_CURRENT_LIST_DIR}/software-device-info.cpp" + "${CMAKE_CURRENT_LIST_DIR}/software-sensor.cpp" "${CMAKE_CURRENT_LIST_DIR}/source.cpp" "${CMAKE_CURRENT_LIST_DIR}/stream.cpp" "${CMAKE_CURRENT_LIST_DIR}/sync.cpp" @@ -140,6 +142,8 @@ target_sources(${LRS_TARGET} "${CMAKE_CURRENT_LIST_DIR}/hid-sensor.h" "${CMAKE_CURRENT_LIST_DIR}/uvc-sensor.h" "${CMAKE_CURRENT_LIST_DIR}/software-device.h" + "${CMAKE_CURRENT_LIST_DIR}/software-device-info.h" + "${CMAKE_CURRENT_LIST_DIR}/software-sensor.h" "${CMAKE_CURRENT_LIST_DIR}/source.h" "${CMAKE_CURRENT_LIST_DIR}/stream.h" "${CMAKE_CURRENT_LIST_DIR}/sync.h" diff --git a/src/archive.cpp b/src/archive.cpp index 1074df1474..f05e6b6aec 100644 --- a/src/archive.cpp +++ b/src/archive.cpp @@ -6,6 +6,8 @@ #include "core/pose-frame.h" #include "core/motion-frame.h" #include "core/disparity-frame.h" +#include "composite-frame.h" +#include "points.h" namespace librealsense diff --git a/src/archive.h b/src/archive.h index dc6f773822..92166337be 100644 --- a/src/archive.h +++ b/src/archive.h @@ -3,14 +3,15 @@ #pragma once -#include "types.h" -#include "core/streaming.h" +#include "core/stream-profile.h" +#include "core/frame-additional-data.h" #include "callback-invocation.h" namespace librealsense { - struct frame_additional_data; + class frame_interface; + class sensor_interface; class archive_interface { diff --git a/src/auto-calibrated-device.h b/src/auto-calibrated-device.h index 644c84ceaf..c9084ada01 100644 --- a/src/auto-calibrated-device.h +++ b/src/auto-calibrated-device.h @@ -1,10 +1,11 @@ // License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2019 Intel Corporation. All Rights Reserved. - #pragma once #include "types.h" -#include "core/streaming.h" +#include "core/extension.h" +#include + namespace librealsense { diff --git a/src/backend-device-factory.cpp b/src/backend-device-factory.cpp index 084f5ee4e7..dcb4fb498a 100644 --- a/src/backend-device-factory.cpp +++ b/src/backend-device-factory.cpp @@ -13,6 +13,9 @@ #include "fw-update/fw-update-factory.h" #include "platform-camera.h" +#include + +#include #include #include #include diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index ca731e6366..ca951d2b7a 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -2,7 +2,6 @@ # Copyright(c) 2019 Intel Corporation. All Rights Reserved. target_sources(${LRS_TARGET} PRIVATE - "${CMAKE_CURRENT_LIST_DIR}/streaming.h" "${CMAKE_CURRENT_LIST_DIR}/debug.h" "${CMAKE_CURRENT_LIST_DIR}/advanced_mode.h" "${CMAKE_CURRENT_LIST_DIR}/enum-helpers.h" @@ -29,7 +28,13 @@ target_sources(${LRS_TARGET} "${CMAKE_CURRENT_LIST_DIR}/extension.h" "${CMAKE_CURRENT_LIST_DIR}/pose-frame.h" "${CMAKE_CURRENT_LIST_DIR}/processing.h" + "${CMAKE_CURRENT_LIST_DIR}/processing-block-interface.h" + "${CMAKE_CURRENT_LIST_DIR}/recommended-proccesing-blocks-interface.h" + "${CMAKE_CURRENT_LIST_DIR}/recommended-proccesing-blocks-base.h" + "${CMAKE_CURRENT_LIST_DIR}/sensor-interface.h" "${CMAKE_CURRENT_LIST_DIR}/serialization.h" + "${CMAKE_CURRENT_LIST_DIR}/stream-interface.h" "${CMAKE_CURRENT_LIST_DIR}/stream-profile.h" + "${CMAKE_CURRENT_LIST_DIR}/stream-profile-interface.h" "${CMAKE_CURRENT_LIST_DIR}/tagged-profile.h" ) diff --git a/src/core/advanced_mode.h b/src/core/advanced_mode.h index fd645558c8..eedcd89fca 100644 --- a/src/core/advanced_mode.h +++ b/src/core/advanced_mode.h @@ -4,10 +4,9 @@ #include "ds/ds-private.h" #include "hw-monitor.h" -#include "streaming.h" #include "option.h" #include "ds/advanced_mode/presets.h" -#include "../../include/librealsense2/h/rs_advanced_mode_command.h" +#include #include "serializable-interface.h" #include diff --git a/src/core/disparity-frame.h b/src/core/disparity-frame.h index 025e049279..5a6583dc02 100644 --- a/src/core/disparity-frame.h +++ b/src/core/disparity-frame.h @@ -3,6 +3,8 @@ #pragma once #include "depth-frame.h" +#include "sensor-interface.h" +#include "depth-sensor.h" #include "extension.h" diff --git a/src/core/matcher-factory.cpp b/src/core/matcher-factory.cpp index e1b6aa198c..ea9420903b 100644 --- a/src/core/matcher-factory.cpp +++ b/src/core/matcher-factory.cpp @@ -3,6 +3,7 @@ #include "matcher-factory.h" #include "frame-holder.h" +#include "stream-interface.h" #include diff --git a/src/core/motion.h b/src/core/motion.h index 7062f20701..3c52c9ab4e 100644 --- a/src/core/motion.h +++ b/src/core/motion.h @@ -2,8 +2,9 @@ // Copyright(c) 2015 Intel Corporation. All Rights Reserved. #pragma once +#include "stream-profile-interface.h" +#include -#include "streaming.h" namespace librealsense { diff --git a/src/core/processing-block-interface.h b/src/core/processing-block-interface.h new file mode 100644 index 0000000000..25fb9aa2a6 --- /dev/null +++ b/src/core/processing-block-interface.h @@ -0,0 +1,38 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2023 Intel Corporation. All Rights Reserved. + +#pragma once + +#include "options.h" +#include "info-interface.h" +#include + +#include +#include + + +namespace librealsense { + + +class synthetic_source_interface; +class frame_holder; + + +class processing_block_interface + : public virtual options_interface + , public virtual info_interface +{ +public: + virtual ~processing_block_interface() = default; + + virtual void set_processing_callback( frame_processor_callback_ptr callback ) = 0; + virtual void set_output_callback( frame_callback_ptr callback ) = 0; + virtual void invoke( frame_holder frame ) = 0; + virtual synthetic_source_interface & get_source() = 0; +}; + + +using processing_blocks = std::vector< std::shared_ptr< processing_block_interface > >; + + +} // namespace librealsense diff --git a/src/core/processing.h b/src/core/processing.h index 2e8e75e6a5..28b28a1125 100644 --- a/src/core/processing.h +++ b/src/core/processing.h @@ -51,17 +51,6 @@ namespace librealsense virtual rs2_source* get_c_wrapper() = 0; }; - class processing_block_interface : public virtual options_interface, public virtual info_interface - { - public: - virtual void set_processing_callback(frame_processor_callback_ptr callback) = 0; - virtual void set_output_callback(frame_callback_ptr callback) = 0; - virtual void invoke(frame_holder frame) = 0; - virtual synthetic_source_interface& get_source() = 0; - - virtual ~processing_block_interface() = default; - }; - template class internal_frame_processor_callback : public rs2_frame_processor_callback { diff --git a/src/core/recommended-proccesing-blocks-base.h b/src/core/recommended-proccesing-blocks-base.h new file mode 100644 index 0000000000..a2634bb352 --- /dev/null +++ b/src/core/recommended-proccesing-blocks-base.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 "recommended-proccesing-blocks-interface.h" +#include "extension.h" + + +namespace librealsense +{ + class recommended_proccesing_blocks_base : public virtual recommended_proccesing_blocks_interface, public virtual recordable + { + public: + recommended_proccesing_blocks_base(recommended_proccesing_blocks_interface* owner) + :_owner(owner) + {} + + virtual processing_blocks get_recommended_processing_blocks() const override { return _owner->get_recommended_processing_blocks(); }; + + virtual void create_snapshot(std::shared_ptr& snapshot) const override + { + snapshot = std::make_shared(get_recommended_processing_blocks()); + } + + virtual void enable_recording(std::function recording_function) override {} + + private: + recommended_proccesing_blocks_interface* _owner; + }; + + +} diff --git a/src/core/recommended-proccesing-blocks-interface.h b/src/core/recommended-proccesing-blocks-interface.h new file mode 100644 index 0000000000..3d5804c757 --- /dev/null +++ b/src/core/recommended-proccesing-blocks-interface.h @@ -0,0 +1,45 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2023 Intel Corporation. All Rights Reserved. + +#pragma once + +#include "processing-block-interface.h" +#include "extension.h" + +#include +#include + + +namespace librealsense { + + +class recommended_proccesing_blocks_interface +{ +public: + virtual ~recommended_proccesing_blocks_interface() = default; + + virtual processing_blocks get_recommended_processing_blocks() const = 0; +}; + +MAP_EXTENSION( RS2_EXTENSION_RECOMMENDED_FILTERS, librealsense::recommended_proccesing_blocks_interface ); + + +class recommended_proccesing_blocks_snapshot + : public recommended_proccesing_blocks_interface + , public extension_snapshot +{ +public: + recommended_proccesing_blocks_snapshot( const processing_blocks & blocks ) + : _blocks( blocks ) + { + } + + virtual processing_blocks get_recommended_processing_blocks() const override { return _blocks; } + + void update( std::shared_ptr< extension_snapshot > ext ) override {} + + processing_blocks _blocks; +}; + + +} // namespace librealsense diff --git a/src/core/sensor-interface.h b/src/core/sensor-interface.h new file mode 100644 index 0000000000..d14261ef1b --- /dev/null +++ b/src/core/sensor-interface.h @@ -0,0 +1,57 @@ +// 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 "options.h" +#include "recommended-proccesing-blocks-interface.h" + +#include "tagged-profile.h" + +#include +#include + + +namespace librealsense { + + +class stream_profile_interface; +class device_interface; + + +class sensor_interface + : public virtual info_interface + , public virtual options_interface + , public virtual recommended_proccesing_blocks_interface +{ +public: + virtual ~sensor_interface() = default; + + virtual device_interface & get_device() = 0; + + using stream_profiles = std::vector< std::shared_ptr< stream_profile_interface > >; + + virtual stream_profiles get_stream_profiles( int tag = profile_tag::PROFILE_TAG_ANY ) const = 0; + virtual stream_profiles get_active_streams() const = 0; + virtual stream_profiles const & get_raw_stream_profiles() const = 0; + + virtual void open( const stream_profiles & requests ) = 0; + virtual void start( frame_callback_ptr callback ) = 0; + virtual void stop() = 0; + virtual void close() = 0; + + virtual bool is_streaming() const = 0; + + virtual notifications_callback_ptr get_notifications_callback() const = 0; + virtual void register_notifications_callback( notifications_callback_ptr callback ) = 0; + + virtual int register_before_streaming_changes_callback( std::function< void( bool ) > callback ) = 0; + virtual void unregister_before_start_callback( int token ) = 0; + + virtual frame_callback_ptr get_frames_callback() const = 0; + virtual void set_frames_callback( frame_callback_ptr cb ) = 0; +}; + + +} // namespace librealsense diff --git a/src/core/serialization.h b/src/core/serialization.h index 074d8df93c..9e6edd0744 100644 --- a/src/core/serialization.h +++ b/src/core/serialization.h @@ -8,12 +8,14 @@ #include #include "../types.h" #include "extension.h" -#include "streaming.h" #include "frame-holder.h" +#include "stream-profile-interface.h" namespace librealsense { + class option; + namespace device_serializer { struct sensor_identifier diff --git a/src/core/stream-interface.h b/src/core/stream-interface.h new file mode 100644 index 0000000000..397b7181c0 --- /dev/null +++ b/src/core/stream-interface.h @@ -0,0 +1,33 @@ +// 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 : public std::enable_shared_from_this< stream_interface > +{ +public: + virtual ~stream_interface() = default; + + virtual int get_stream_index() const = 0; + virtual void set_stream_index( int index ) = 0; + + virtual int get_unique_id() const = 0; + virtual void set_unique_id( int uid ) = 0; + + virtual rs2_stream get_stream_type() const = 0; + virtual void set_stream_type( rs2_stream stream ) = 0; +}; + + +// TODO this should be find_stream +stream_interface * find_profile( rs2_stream stream, int index, std::vector< stream_interface * > const & profiles ); + + +} // namespace librealsense diff --git a/src/core/stream-profile-interface.h b/src/core/stream-profile-interface.h new file mode 100644 index 0000000000..9745e5733d --- /dev/null +++ b/src/core/stream-profile-interface.h @@ -0,0 +1,51 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2023 Intel Corporation. All Rights Reserved. +#pragma once + +#include "stream-interface.h" +#include "extension.h" + +#include +#include +#include +#include +#include + + +namespace librealsense { + + +class stream_profile_interface + : public stream_interface + , public recordable< stream_profile_interface > +{ +public: + virtual rs2_format get_format() const = 0; + virtual void set_format( rs2_format format ) = 0; + + virtual uint32_t get_framerate() const = 0; + virtual void set_framerate( uint32_t val ) = 0; + + virtual int get_tag() const = 0; + virtual void tag_profile( int tag ) = 0; + + virtual std::shared_ptr< stream_profile_interface > clone() const = 0; + virtual rs2_stream_profile * get_c_wrapper() const = 0; + virtual void set_c_wrapper( rs2_stream_profile * wrapper ) = 0; +}; + + +using stream_profiles = std::vector< std::shared_ptr< stream_profile_interface > >; + + +inline std::ostream & operator<<( std::ostream & os, const stream_profiles & profiles ) +{ + for( auto & p : profiles ) + { + os << rs2_format_to_string( p->get_format() ) << " " << rs2_stream_to_string( p->get_stream_type() ) << ", "; + } + return os; +} + + +} // namespace librealsense diff --git a/src/core/streaming.h b/src/core/streaming.h deleted file mode 100644 index a75375556f..0000000000 --- a/src/core/streaming.h +++ /dev/null @@ -1,144 +0,0 @@ -// License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2015 Intel Corporation. All Rights Reserved. -#pragma once - -#include "options.h" -#include "../depth-sensor.h" -#include "../color-sensor.h" -#include "../composite-frame.h" -#include "../points.h" -#include "info-interface.h" -#include "tagged-profile.h" -#include -#include - - -namespace librealsense -{ - class sensor_interface; - class device_interface; - class processing_block_interface; - - class context; - - class stream_interface : public std::enable_shared_from_this - { - public: - virtual ~stream_interface() = default; - - virtual int get_stream_index() const = 0; - virtual void set_stream_index(int index) = 0; - - virtual int get_unique_id() const = 0; - virtual void set_unique_id(int uid) = 0; - - virtual rs2_stream get_stream_type() const = 0; - 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: - virtual rs2_format get_format() const = 0; - virtual void set_format(rs2_format format) = 0; - - virtual uint32_t get_framerate() const = 0; - virtual void set_framerate(uint32_t val) = 0; - - virtual int get_tag() const = 0; - virtual void tag_profile(int tag) = 0; - - virtual std::shared_ptr clone() const = 0; - virtual rs2_stream_profile* get_c_wrapper() const = 0; - virtual void set_c_wrapper(rs2_stream_profile* wrapper) = 0; - }; - - using on_frame = std::function; - using stream_profiles = std::vector>; - using processing_blocks = std::vector>; - - - inline std::ostream& operator << (std::ostream& os, const stream_profiles& profiles) - { - for (auto&& p : profiles) - { - os << rs2_format_to_string(p->get_format()) << " " << rs2_stream_to_string(p->get_stream_type()) << ", "; - } - return os; - } - - - class recommended_proccesing_blocks_interface - { - public: - virtual processing_blocks get_recommended_processing_blocks() const = 0; - virtual ~recommended_proccesing_blocks_interface() = default; - }; - MAP_EXTENSION(RS2_EXTENSION_RECOMMENDED_FILTERS, librealsense::recommended_proccesing_blocks_interface); - - class recommended_proccesing_blocks_snapshot : public recommended_proccesing_blocks_interface, public extension_snapshot - { - public: - recommended_proccesing_blocks_snapshot(const processing_blocks blocks) - :_blocks(blocks) {} - - virtual processing_blocks get_recommended_processing_blocks() const override - { - return _blocks; - } - - void update(std::shared_ptr ext) override {} - - processing_blocks _blocks; - }; - - - class recommended_proccesing_blocks_base : public virtual recommended_proccesing_blocks_interface, public virtual recordable - { - public: - recommended_proccesing_blocks_base(recommended_proccesing_blocks_interface* owner) - :_owner(owner) - {} - - virtual processing_blocks get_recommended_processing_blocks() const override { return _owner->get_recommended_processing_blocks(); }; - - virtual void create_snapshot(std::shared_ptr& snapshot) const override - { - snapshot = std::make_shared(get_recommended_processing_blocks()); - } - - virtual void enable_recording(std::function recording_function) override {} - - private: - recommended_proccesing_blocks_interface* _owner; - }; - - class sensor_interface : public virtual info_interface, public virtual options_interface, public virtual recommended_proccesing_blocks_interface - { - public: - virtual stream_profiles get_stream_profiles(int tag = profile_tag::PROFILE_TAG_ANY) const = 0; - virtual stream_profiles get_active_streams() const = 0; - virtual stream_profiles const & get_raw_stream_profiles() const = 0; - virtual void open(const stream_profiles& requests) = 0; - virtual void close() = 0; - virtual notifications_callback_ptr get_notifications_callback() const = 0; - - virtual void register_notifications_callback(notifications_callback_ptr callback) = 0; - virtual int register_before_streaming_changes_callback(std::function callback) = 0; - virtual void unregister_before_start_callback(int token) = 0; - virtual void start(frame_callback_ptr callback) = 0; - virtual void stop() = 0; - virtual frame_callback_ptr get_frames_callback() const = 0; - virtual void set_frames_callback(frame_callback_ptr cb) = 0; - virtual bool is_streaming() const = 0; - virtual device_interface& get_device() = 0; - - virtual ~sensor_interface() = default; - }; - - -} diff --git a/src/core/video.h b/src/core/video.h index f207c5a76f..a2dc35ea46 100644 --- a/src/core/video.h +++ b/src/core/video.h @@ -2,7 +2,7 @@ // Copyright(c) 2015 Intel Corporation. All Rights Reserved. #pragma once -#include "streaming.h" +#include "stream-profile-interface.h" namespace librealsense { diff --git a/src/dds/rs-dds-color-sensor-proxy.h b/src/dds/rs-dds-color-sensor-proxy.h index c9b9806af7..b552e2ec50 100644 --- a/src/dds/rs-dds-color-sensor-proxy.h +++ b/src/dds/rs-dds-color-sensor-proxy.h @@ -4,6 +4,7 @@ #pragma once #include "rs-dds-sensor-proxy.h" +#include namespace librealsense { diff --git a/src/dds/rs-dds-depth-sensor-proxy.h b/src/dds/rs-dds-depth-sensor-proxy.h index 251c5f4184..419ee48fdb 100644 --- a/src/dds/rs-dds-depth-sensor-proxy.h +++ b/src/dds/rs-dds-depth-sensor-proxy.h @@ -4,6 +4,7 @@ #pragma once #include "rs-dds-sensor-proxy.h" +#include namespace librealsense { diff --git a/src/dds/rs-dds-device-info.cpp b/src/dds/rs-dds-device-info.cpp index f94edf51a9..f871227143 100644 --- a/src/dds/rs-dds-device-info.cpp +++ b/src/dds/rs-dds-device-info.cpp @@ -9,6 +9,8 @@ #include #include +#include + namespace librealsense { diff --git a/src/dds/rs-dds-sensor-proxy.cpp b/src/dds/rs-dds-sensor-proxy.cpp index 0eb9bd5545..bf5a505726 100644 --- a/src/dds/rs-dds-sensor-proxy.cpp +++ b/src/dds/rs-dds-sensor-proxy.cpp @@ -4,6 +4,8 @@ #include "rs-dds-sensor-proxy.h" #include "rs-dds-option.h" +#include + #include #include diff --git a/src/dds/rs-dds-sensor-proxy.h b/src/dds/rs-dds-sensor-proxy.h index 184fbdc85a..8d504c40bf 100644 --- a/src/dds/rs-dds-sensor-proxy.h +++ b/src/dds/rs-dds-sensor-proxy.h @@ -5,7 +5,7 @@ #include "sid_index.h" -#include +#include #include #include diff --git a/src/debug-stream-sensor.h b/src/debug-stream-sensor.h index 682012bd7f..2dc9230aff 100644 --- a/src/debug-stream-sensor.h +++ b/src/debug-stream-sensor.h @@ -1,9 +1,10 @@ // License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2020 Intel Corporation. All Rights Reserved. - #pragma once -#include "core/streaming.h" +#include "core/extension.h" +#include "core/stream-profile-interface.h" + namespace librealsense { diff --git a/src/device-calibration.h b/src/device-calibration.h index 371648898d..ede166762d 100644 --- a/src/device-calibration.h +++ b/src/device-calibration.h @@ -1,10 +1,10 @@ // License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2020 Intel Corporation. All Rights Reserved. - #pragma once #include "types.h" -#include "core/streaming.h" +#include "core/extension.h" + namespace librealsense { @@ -15,6 +15,7 @@ namespace librealsense public: virtual void register_calibration_change_callback(calibration_change_callback_ptr) = 0; }; + MAP_EXTENSION(RS2_EXTENSION_CALIBRATION_CHANGE_DEVICE, calibration_change_device); // This extension should allow generic calibrations using the same interface @@ -24,5 +25,6 @@ namespace librealsense public: virtual void trigger_device_calibration( rs2_calibration_type ) = 0; }; + MAP_EXTENSION(RS2_EXTENSION_DEVICE_CALIBRATION, device_calibration ); } diff --git a/src/device.cpp b/src/device.cpp index 36e5e004f3..e218fa23cf 100644 --- a/src/device.cpp +++ b/src/device.cpp @@ -9,6 +9,7 @@ #include "core/frame-holder.h" #include "sync.h" #include "context.h" // rs2_device_info +#include "core/sensor-interface.h" #include #include diff --git a/src/ds/d400/d400-color.h b/src/ds/d400/d400-color.h index e1b2d3d79a..3e28a3d2bd 100644 --- a/src/ds/d400/d400-color.h +++ b/src/ds/d400/d400-color.h @@ -5,6 +5,7 @@ #include "d400-device.h" #include "ds/ds-color-common.h" +#include #include "stream.h" diff --git a/src/ds/d400/d400-device.cpp b/src/ds/d400/d400-device.cpp index 8e43e1b1a6..e0054dba5e 100644 --- a/src/ds/d400/d400-device.cpp +++ b/src/ds/d400/d400-device.cpp @@ -14,6 +14,7 @@ #include "ds/ds-timestamp.h" #include #include +#include #include "d400-color.h" #include "d400-nonmonochrome.h" #include diff --git a/src/ds/d500/d500-color.h b/src/ds/d500/d500-color.h index 6b9e85b336..2aca9210e6 100644 --- a/src/ds/d500/d500-color.h +++ b/src/ds/d500/d500-color.h @@ -5,6 +5,7 @@ #include "d500-device.h" #include "ds/ds-color-common.h" +#include #include "stream.h" diff --git a/src/ds/d500/d500-device.cpp b/src/ds/d500/d500-device.cpp index 363627944b..48b84db8f1 100644 --- a/src/ds/d500/d500-device.cpp +++ b/src/ds/d500/d500-device.cpp @@ -14,6 +14,7 @@ #include "d500-info.h" #include "ds/ds-options.h" #include "ds/ds-timestamp.h" +#include #include "stream.h" #include "environment.h" #include "d500-color.h" diff --git a/src/ds/ds-motion-common.h b/src/ds/ds-motion-common.h index 5bf57955e0..c4b0bc5f48 100644 --- a/src/ds/ds-motion-common.h +++ b/src/ds/ds-motion-common.h @@ -111,6 +111,7 @@ namespace librealsense struct backend_device_group; } + class context; class backend_device; class ds_motion_common diff --git a/src/environment.cpp b/src/environment.cpp index 8461298e73..ec9a15610c 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -2,6 +2,9 @@ // Copyright(c) 2015 Intel Corporation. All Rights Reserved. #include "environment.h" +#include "types.h" +#include "core/stream-interface.h" + namespace librealsense { diff --git a/src/environment.h b/src/environment.h index d90acdba74..fbbe56c99c 100644 --- a/src/environment.h +++ b/src/environment.h @@ -1,16 +1,22 @@ // License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2015 Intel Corporation. All Rights Reserved. - #pragma once -#include "core/streaming.h" -#include "types.h" + +#include #include #include #include #include +#include +#include +#include + namespace librealsense { + class stream_interface; + + /** * \brief The class stores and manages the inter - stream extrinsic information in a form of dis / connected graph. * The nodes of the graph represent the streaming profiles that the different sensors provide. diff --git a/src/frame.cpp b/src/frame.cpp index e963c13624..145e4017f4 100644 --- a/src/frame.cpp +++ b/src/frame.cpp @@ -2,9 +2,10 @@ // Copyright(c) 2021 Intel Corporation. All Rights Reserved. #include "core/depth-frame.h" +#include "composite-frame.h" +#include "core/stream-profile-interface.h" #include "archive.h" #include "metadata-parser.h" -#include "environment.h" #include diff --git a/src/fw-update/fw-update-device-interface.h b/src/fw-update/fw-update-device-interface.h index 6338db795c..0d95266866 100644 --- a/src/fw-update/fw-update-device-interface.h +++ b/src/fw-update/fw-update-device-interface.h @@ -4,7 +4,6 @@ #pragma once #include "../types.h" -#include "../core/streaming.h" #include #include "../usb/usb-types.h" #include @@ -39,6 +38,8 @@ namespace librealsense virtual void update_flash(const std::vector& image, update_progress_callback_ptr callback, int update_mode) = 0; }; + MAP_EXTENSION( RS2_EXTENSION_UPDATABLE, updatable ); + class update_device_interface : public device_interface, public firmware_check_interface { public: @@ -50,5 +51,4 @@ namespace librealsense }; MAP_EXTENSION(RS2_EXTENSION_UPDATE_DEVICE, update_device_interface); - MAP_EXTENSION(RS2_EXTENSION_UPDATABLE, updatable); } diff --git a/src/fw-update/fw-update-factory.h b/src/fw-update/fw-update-factory.h index f57c93a6c5..7d0dcaf5f9 100644 --- a/src/fw-update/fw-update-factory.h +++ b/src/fw-update/fw-update-factory.h @@ -4,7 +4,6 @@ #pragma once #include "platform/platform-device-info.h" -#include "core/streaming.h" namespace librealsense { diff --git a/src/gl/synthetic-stream-gl.h b/src/gl/synthetic-stream-gl.h index 46984ae09e..0c07ceab33 100644 --- a/src/gl/synthetic-stream-gl.h +++ b/src/gl/synthetic-stream-gl.h @@ -7,6 +7,7 @@ #include "../core/processing.h" #include "../image.h" #include "../source.h" +#include "../points.h" #include #include diff --git a/src/media/playback/playback_device.cpp b/src/media/playback/playback_device.cpp index 8c4547cc1e..64e8fe1ce5 100644 --- a/src/media/playback/playback_device.cpp +++ b/src/media/playback/playback_device.cpp @@ -9,6 +9,8 @@ #include "media/ros/ros_reader.h" #include "environment.h" #include "sync.h" +#include +#include #include diff --git a/src/media/playback/playback_device.h b/src/media/playback/playback_device.h index a1e365c033..e8598cf036 100644 --- a/src/media/playback/playback_device.h +++ b/src/media/playback/playback_device.h @@ -6,7 +6,6 @@ #include "../../core/roi.h" #include "../../core/extension.h" #include "../../core/serialization.h" -#include "../../core/streaming.h" #include #include "../../archive.h" #include "../../sensor.h" diff --git a/src/media/playback/playback_sensor.h b/src/media/playback/playback_sensor.h index da214b26a0..ad2751e455 100644 --- a/src/media/playback/playback_sensor.h +++ b/src/media/playback/playback_sensor.h @@ -5,7 +5,6 @@ #include "../../core/roi.h" #include "../../core/extension.h" #include "../../core/serialization.h" -#include "../../core/streaming.h" #include "../../archive.h" #include "../../sensor.h" #include "../../types.h" diff --git a/src/media/record/record_device.h b/src/media/record/record_device.h index 2b0cc5717c..317b6c7954 100644 --- a/src/media/record/record_device.h +++ b/src/media/record/record_device.h @@ -5,7 +5,6 @@ #include #include #include -#include "core/streaming.h" #include #include "archive.h" #include "sensor.h" diff --git a/src/media/record/record_sensor.cpp b/src/media/record/record_sensor.cpp index a4744505a3..07d7b0cd5c 100644 --- a/src/media/record/record_sensor.cpp +++ b/src/media/record/record_sensor.cpp @@ -4,6 +4,8 @@ #include "record_sensor.h" #include "api.h" #include "stream.h" +#include +#include #include diff --git a/src/media/record/record_sensor.h b/src/media/record/record_sensor.h index f8af933494..cff5f4e7d0 100644 --- a/src/media/record/record_sensor.h +++ b/src/media/record/record_sensor.h @@ -5,7 +5,6 @@ #include "core/roi.h" #include "core/extension.h" #include "core/serialization.h" -#include "core/streaming.h" #include "archive.h" #include "sensor.h" diff --git a/src/media/ros/ros_reader.cpp b/src/media/ros/ros_reader.cpp index 1d6738d1af..4c4f58ae68 100644 --- a/src/media/ros/ros_reader.cpp +++ b/src/media/ros/ros_reader.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include diff --git a/src/metadata-parser.h b/src/metadata-parser.h index 03aef1d08c..4eb0cefe04 100644 --- a/src/metadata-parser.h +++ b/src/metadata-parser.h @@ -4,8 +4,7 @@ #pragma once -#include "types.h" -#include "archive.h" +#include "frame.h" #include "metadata.h" #include diff --git a/src/option.h b/src/option.h index 527e17ffa0..ff86c486cc 100644 --- a/src/option.h +++ b/src/option.h @@ -6,7 +6,6 @@ #include "archive.h" #include "hw-monitor.h" #include "sensor.h" -#include "core/streaming.h" #include "platform/command-transfer.h" #include "error-handling.h" diff --git a/src/pipeline/aggregator.cpp b/src/pipeline/aggregator.cpp index 636b72871f..343580bb16 100644 --- a/src/pipeline/aggregator.cpp +++ b/src/pipeline/aggregator.cpp @@ -4,6 +4,7 @@ #include #include "stream.h" #include "aggregator.h" +#include namespace librealsense { diff --git a/src/pipeline/aggregator.h b/src/pipeline/aggregator.h index 9495b2d485..ed3a968058 100644 --- a/src/pipeline/aggregator.h +++ b/src/pipeline/aggregator.h @@ -1,20 +1,27 @@ // License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2015 Intel Corporation. All Rights Reserved. - #pragma once -#include "sync.h" #include "proc/synthetic-stream.h" -#include "proc/syncer-processing-block.h" +#include +#include +#include +#include +#include +#include + namespace librealsense { + class synthetic_source_interface; + class frame_holder; + namespace pipeline { class aggregator : public processing_block { std::mutex _mutex; - std::map _last_set; + std::map _last_set; std::unique_ptr> _queue; std::vector _streams_to_aggregate_ids; std::vector _streams_to_sync_ids; diff --git a/src/pipeline/pipeline.cpp b/src/pipeline/pipeline.cpp index ce2fb227b9..28eb06f0c7 100644 --- a/src/pipeline/pipeline.cpp +++ b/src/pipeline/pipeline.cpp @@ -7,6 +7,7 @@ #include "media/playback/playback_device.h" #include "media/record/record_device.h" #include "media/ros/ros_writer.h" +#include #include diff --git a/src/pipeline/pipeline.h b/src/pipeline/pipeline.h index 9799866917..0b87dd5baf 100644 --- a/src/pipeline/pipeline.h +++ b/src/pipeline/pipeline.h @@ -15,6 +15,8 @@ namespace librealsense { + class syncer_process_unit; + namespace pipeline { class pipeline : public std::enable_shared_from_this diff --git a/src/proc/disparity-transform.h b/src/proc/disparity-transform.h index 76004a450c..7090551993 100644 --- a/src/proc/disparity-transform.h +++ b/src/proc/disparity-transform.h @@ -8,6 +8,7 @@ #include #include #include +#include #include "synthetic-stream.h" namespace librealsense diff --git a/src/proc/formats-converter.cpp b/src/proc/formats-converter.cpp index 8b481f2e5a..c19c509d3b 100644 --- a/src/proc/formats-converter.cpp +++ b/src/proc/formats-converter.cpp @@ -3,6 +3,7 @@ #include "proc/formats-converter.h" #include "stream.h" +#include #include diff --git a/src/proc/pointcloud.cpp b/src/proc/pointcloud.cpp index f2d719fcb4..03032dbe80 100644 --- a/src/proc/pointcloud.cpp +++ b/src/proc/pointcloud.cpp @@ -1,18 +1,20 @@ // License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2017 Intel Corporation. All Rights Reserved. -#include -#include "environment.h" -#include "proc/occlusion-filter.h" -#include "proc/pointcloud.h" +#include "pointcloud.h" +#include "occlusion-filter.h" +#include #include -#include "option.h" -#include "environment.h" -#include "../device.h" -#include "../stream.h" -#include +#include +#include +#include +#include #include "device-calibration.h" +#include + +#include + #ifdef RS2_USE_CUDA #include "proc/cuda/cuda-pointcloud.h" #endif diff --git a/src/proc/processing-blocks-factory.h b/src/proc/processing-blocks-factory.h index 5784b85007..f9d786477a 100644 --- a/src/proc/processing-blocks-factory.h +++ b/src/proc/processing-blocks-factory.h @@ -4,6 +4,7 @@ #pragma once #include +#include #include diff --git a/src/proc/spatial-filter.cpp b/src/proc/spatial-filter.cpp index d2b90f4157..0270640457 100644 --- a/src/proc/spatial-filter.cpp +++ b/src/proc/spatial-filter.cpp @@ -1,15 +1,17 @@ // License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2017 Intel Corporation. All Rights Reserved. -#include -#include #include "option.h" #include "environment.h" -#include "software-device.h" +#include "software-sensor.h" +#include #include "proc/synthetic-stream.h" #include "proc/hole-filling-filter.h" #include "proc/spatial-filter.h" +#include +#include + #include diff --git a/src/proc/synthetic-stream.cpp b/src/proc/synthetic-stream.cpp index fe04964b35..b5d0449978 100644 --- a/src/proc/synthetic-stream.cpp +++ b/src/proc/synthetic-stream.cpp @@ -6,6 +6,7 @@ #include "core/video.h" #include "core/motion-frame.h" #include "core/depth-frame.h" +#include #include "option.h" #include "stream.h" #include "types.h" diff --git a/src/proc/synthetic-stream.h b/src/proc/synthetic-stream.h index 318d1eccff..d790ecb563 100644 --- a/src/proc/synthetic-stream.h +++ b/src/proc/synthetic-stream.h @@ -4,6 +4,7 @@ #pragma once #include "../core/processing.h" +#include "../core/processing-block-interface.h" #include "../image.h" #include "../source.h" #include diff --git a/src/proc/units-transform.cpp b/src/proc/units-transform.cpp index 1339f3a9be..8386b972f5 100644 --- a/src/proc/units-transform.cpp +++ b/src/proc/units-transform.cpp @@ -5,6 +5,7 @@ #include #include "core/depth-frame.h" +#include "core/sensor-interface.h" #include "proc/synthetic-stream.h" #include "environment.h" #include "units-transform.h" diff --git a/src/rs.cpp b/src/rs.cpp index df8af1625a..39eaaf3a95 100644 --- a/src/rs.cpp +++ b/src/rs.cpp @@ -44,6 +44,8 @@ #include "environment.h" #include "proc/temporal-filter.h" #include "software-device.h" +#include "software-device-info.h" +#include "software-sensor.h" #include "global_timestamp_reader.h" #include "auto-calibrated-device.h" #include "terminal-parser.h" @@ -53,6 +55,9 @@ #include "debug-stream-sensor.h" #include "max-usable-range-sensor.h" #include "fw-update/fw-update-device-interface.h" +#include "color-sensor.h" +#include "composite-frame.h" +#include "points.h" #include @@ -803,7 +808,7 @@ void rs2_software_device_set_destruction_callback(const rs2_device* dev, rs2_sof VALIDATE_NOT_NULL(dev); auto swdev = VALIDATE_INTERFACE(dev->device, librealsense::software_device); VALIDATE_NOT_NULL(on_destruction); - librealsense::software_device_destruction_callback_ptr callback( + librealsense::software_device::destruction_callback_ptr callback( new librealsense::software_device_destruction_callback(on_destruction, user), [](rs2_software_device_destruction_callback* p) { delete p; }); swdev->register_destruction_callback(std::move(callback)); @@ -867,10 +872,11 @@ void rs2_software_device_set_destruction_callback_cpp(const rs2_device* dev, rs2 // Take ownership of the callback ASAP or else memory leaks could result if we throw! (the caller usually does a // 'new' when calling us) VALIDATE_NOT_NULL( callback ); - software_device_destruction_callback_ptr callback_ptr{ callback, - []( rs2_software_device_destruction_callback * p ) { - p->release(); - } }; + software_device::destruction_callback_ptr callback_ptr{ callback, + []( rs2_software_device_destruction_callback * p ) + { + p->release(); + } }; VALIDATE_NOT_NULL(dev); auto swdev = VALIDATE_INTERFACE(dev->device, librealsense::software_device); diff --git a/src/sensor.cpp b/src/sensor.cpp index 46b495c309..b9295a64f8 100644 --- a/src/sensor.cpp +++ b/src/sensor.cpp @@ -11,6 +11,7 @@ #include "global_timestamp_reader.h" #include "device-calibration.h" #include "core/depth-frame.h" +#include "core/stream-profile-interface.h" #include #include diff --git a/src/sensor.h b/src/sensor.h index 1c22453f4f..f87ed43cd8 100644 --- a/src/sensor.h +++ b/src/sensor.h @@ -3,18 +3,12 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include -#include +#include "core/sensor-interface.h" + #include "core/debug.h" #include "archive.h" -#include "core/streaming.h" +#include "core/recommended-proccesing-blocks-base.h" #include "core/roi.h" #include "core/options.h" #include "source.h" @@ -26,11 +20,21 @@ #include #include +#include +#include +#include +#include +#include +#include +#include +#include + namespace librealsense { class device; class option; + class stream_interface; enum class format_conversion; diff --git a/src/software-device-info.cpp b/src/software-device-info.cpp new file mode 100644 index 0000000000..b862aba584 --- /dev/null +++ b/src/software-device-info.cpp @@ -0,0 +1,44 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2023 Intel Corporation. All Rights Reserved. + +#include "software-device-info.h" +#include "software-device.h" +#include "librealsense-exception.h" + +#include + + +namespace librealsense { + + +software_device_info::software_device_info( std::shared_ptr< context > const & ctx ) + : device_info( ctx ) + , _address() // leave empty until set_device() +{ +} + + +void software_device_info::set_device( std::shared_ptr< software_device > const & dev ) +{ + if( ! _address.empty() ) + throw wrong_api_call_sequence_exception( "software_device_info already initialized" ); + _dev = dev; + _address = rsutils::string::from() << "software-device://" << (unsigned long long)dev.get(); +} + + +bool software_device_info::is_same_as( std::shared_ptr< const device_info > const & other ) const +{ + if( auto rhs = std::dynamic_pointer_cast< const software_device_info >( other ) ) + return _address == rhs->_address; + return false; +} + + +std::shared_ptr< device_interface > software_device_info::create_device() +{ + return _dev.lock(); +} + + +} // namespace librealsense diff --git a/src/software-device-info.h b/src/software-device-info.h new file mode 100644 index 0000000000..aec6728129 --- /dev/null +++ b/src/software-device-info.h @@ -0,0 +1,35 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2023 Intel Corporation. All Rights Reserved. +#pragma once + +#include "device-info.h" + + +namespace librealsense { + + +class software_device; + + +class software_device_info : public device_info +{ + std::weak_ptr< software_device > _dev; + std::string _address; + +public: + explicit software_device_info( std::shared_ptr< context > const & ctx ); + + // The usage is dictated by the rs2 APIs: rather than creating the info and then using create_device() to create the + // device, it's the other way around (see rs2_context_add_software_device). + // + void set_device( std::shared_ptr< software_device > const & dev ); + + std::string get_address() const override { return _address; } + + bool is_same_as( std::shared_ptr< const device_info > const & other ) const override; + + std::shared_ptr< device_interface > create_device() override; +}; + + +} // namespace librealsense diff --git a/src/software-device.cpp b/src/software-device.cpp index cb68e1ad2b..75310c8da5 100644 --- a/src/software-device.cpp +++ b/src/software-device.cpp @@ -2,17 +2,10 @@ // Copyright(c) 2018 Intel Corporation. All Rights Reserved. #include "software-device.h" -#include "stream.h" -#include "option.h" -#include "core/video-frame.h" +#include "software-sensor.h" +#include "environment.h" #include "core/matcher-factory.h" -#include -#include -#include - -using rsutils::deferred; - namespace librealsense { @@ -52,7 +45,7 @@ namespace librealsense register_stream_to_extrinsic_group(stream, max_idx+1); } - void software_device::register_destruction_callback(software_device_destruction_callback_ptr callback) + void software_device::register_destruction_callback( destruction_callback_ptr callback ) { _user_destruction_callback = std::move(callback); } @@ -71,30 +64,6 @@ namespace librealsense _matcher = matcher; } - static std::shared_ptr< metadata_parser_map > create_software_metadata_parser_map() - { - auto md_parser_map = std::make_shared< metadata_parser_map >(); - for( int i = 0; i < static_cast< int >( rs2_frame_metadata_value::RS2_FRAME_METADATA_COUNT ); ++i ) - { - auto key = static_cast< rs2_frame_metadata_value >( i ); - md_parser_map->emplace( key, std::make_shared< md_array_parser >( key ) ); - } - return md_parser_map; - } - - software_sensor::software_sensor( std::string const & name, software_device * owner ) - : sensor_base( name, owner, &_pbs ) - , _stereo_extension( [this]() { return stereo_extension( this ); } ) - , _metadata_map{} // to all 0's - { - // At this time (and therefore for backwards compatibility) no register_metadata is required for SW sensors, - // and metadata persists between frames (!!!!!!!). All SW sensors support ALL metadata. We can therefore - // also share their parsers: - static auto software_metadata_parser_map = create_software_metadata_parser_map(); - _metadata_parsers = software_metadata_parser_map; - _unique_id = unique_id::generate_id(); - } - std::shared_ptr software_device::create_matcher(const frame_holder& frame) const { std::vector profiles; @@ -106,293 +75,6 @@ namespace librealsense return matcher_factory::create(_matcher, profiles); } - std::shared_ptr software_sensor::add_video_stream(rs2_video_stream video_stream, bool is_default) - { - auto profile = std::make_shared( - platform::stream_profile{ (uint32_t)video_stream.width, (uint32_t)video_stream.height, (uint32_t)video_stream.fps, 0 }); - profile->set_dims(video_stream.width, video_stream.height); - profile->set_format(video_stream.fmt); - profile->set_framerate(video_stream.fps); - profile->set_stream_index(video_stream.index); - profile->set_stream_type(video_stream.type); - profile->set_unique_id(video_stream.uid); - profile->set_intrinsics([=]() {return video_stream.intrinsics; }); - if (is_default) profile->tag_profile(profile_tag::PROFILE_TAG_DEFAULT); - _sw_profiles.push_back(profile); - - return profile; - } - - std::shared_ptr software_sensor::add_motion_stream(rs2_motion_stream motion_stream, bool is_default) - { - auto profile = std::make_shared( - platform::stream_profile{ 0, 0, (uint32_t)motion_stream.fps, 0 }); - profile->set_format(motion_stream.fmt); - profile->set_framerate(motion_stream.fps); - profile->set_stream_index(motion_stream.index); - profile->set_stream_type(motion_stream.type); - profile->set_unique_id(motion_stream.uid); - profile->set_intrinsics([=]() {return motion_stream.intrinsics; }); - if (is_default) profile->tag_profile(profile_tag::PROFILE_TAG_DEFAULT); - _sw_profiles.push_back(profile); - - return std::move(profile); - } - - std::shared_ptr software_sensor::add_pose_stream(rs2_pose_stream pose_stream, bool is_default) - { - auto profile = std::make_shared( - platform::stream_profile{ 0, 0, (uint32_t)pose_stream.fps, 0 }); - if (!profile) - throw librealsense::invalid_value_exception("null pointer passed for argument \"profile\"."); - - profile->set_format(pose_stream.fmt); - profile->set_framerate(pose_stream.fps); - profile->set_stream_index(pose_stream.index); - profile->set_stream_type(pose_stream.type); - profile->set_unique_id(pose_stream.uid); - if (is_default) profile->tag_profile(profile_tag::PROFILE_TAG_DEFAULT); - _sw_profiles.push_back(profile); - - return std::move(profile); - } - - - bool software_sensor::extend_to(rs2_extension extension_type, void ** ptr) - { - if (extension_type == RS2_EXTENSION_DEPTH_SENSOR) - { - if (supports_option(RS2_OPTION_DEPTH_UNITS)) - { - auto & ext = *_stereo_extension; - *ptr = static_cast< depth_sensor * >( &ext ); - return true; - } - } - else if (extension_type == RS2_EXTENSION_DEPTH_STEREO_SENSOR) - { - if (supports_option(RS2_OPTION_DEPTH_UNITS) && - supports_option(RS2_OPTION_STEREO_BASELINE)) - { - *ptr = &(*_stereo_extension); - return true; - } - } - return false; - } - - stream_profiles software_sensor::init_stream_profiles() - { - // By default the raw profiles we're given is what we output - return _sw_profiles; - } - - void software_sensor::open(const stream_profiles& requests) - { - if (_is_streaming) - throw wrong_api_call_sequence_exception("open(...) failed. Software device is streaming!"); - else if (_is_opened) - throw wrong_api_call_sequence_exception("open(...) failed. Software device is already opened!"); - _is_opened = true; - set_active_streams(requests); - } - - void software_sensor::close() - { - if (_is_streaming) - throw wrong_api_call_sequence_exception("close() failed. Software device is streaming!"); - else if (!_is_opened) - throw wrong_api_call_sequence_exception("close() failed. Software device was not opened!"); - _is_opened = false; - set_active_streams({}); - } - - void software_sensor::start(frame_callback_ptr callback) - { - if (_is_streaming) - throw wrong_api_call_sequence_exception("start_streaming(...) failed. Software device is already streaming!"); - else if (!_is_opened) - throw wrong_api_call_sequence_exception("start_streaming(...) failed. Software device was not opened!"); - _source.get_published_size_option()->set(0); - _source.init(_metadata_parsers); - _source.set_sensor(this->shared_from_this()); - _source.set_callback(callback); - _is_streaming = true; - raise_on_before_streaming_changes(true); - } - - void software_sensor::stop() - { - if (!_is_streaming) - throw wrong_api_call_sequence_exception("stop_streaming() failed. Software device is not streaming!"); - - _is_streaming = false; - raise_on_before_streaming_changes(false); - _source.flush(); - _source.reset(); - } - - - void software_sensor::set_metadata( rs2_frame_metadata_value key, rs2_metadata_type value ) - { - _metadata_map[key] = { true, value }; - } - - - void software_sensor::erase_metadata( rs2_frame_metadata_value key ) - { - _metadata_map[key].is_valid = false; - } - - - frame_interface * software_sensor::allocate_new_frame( rs2_extension extension, - stream_profile_interface * profile, - frame_additional_data && data ) - { - auto frame = _source.alloc_frame( extension, 0, std::move( data ), false ); - if( ! frame ) - { - LOG_WARNING( "Failed to allocate frame " << data.frame_number << " type " << extension ); - } - else - { - frame->set_stream( std::dynamic_pointer_cast< stream_profile_interface >( profile->shared_from_this() ) ); - } - return frame; - } - - - frame_interface * software_sensor::allocate_new_video_frame( video_stream_profile_interface * profile, - int stride, - int bpp, - frame_additional_data && data ) - { - auto frame = allocate_new_frame( profile->get_stream_type() == RS2_STREAM_DEPTH ? RS2_EXTENSION_DEPTH_FRAME - : RS2_EXTENSION_VIDEO_FRAME, - profile, - std::move( data ) ); - if( frame ) - { - auto vid_frame = dynamic_cast< video_frame * >( frame ); - vid_frame->assign( profile->get_width(), profile->get_height(), stride, bpp * 8 ); - auto sd = dynamic_cast< software_device * >( _owner ); - sd->register_extrinsic( *profile ); - } - return frame; - } - - - void software_sensor::invoke_new_frame( frame_holder && frame, - void const * pixels, - std::function< void() > on_release ) - { - // The frame pixels/data are stored in the continuation object! - if( pixels ) - frame->attach_continuation( frame_continuation( on_release, pixels ) ); - _source.invoke_callback( std::move( frame ) ); - } - - - void software_sensor::on_video_frame( rs2_software_video_frame const & software_frame ) - { - deferred on_release( [deleter = software_frame.deleter, data = software_frame.pixels]() { deleter( data ); } ); - - stream_profile_interface * profile = software_frame.profile->profile; - auto vid_profile = dynamic_cast< video_stream_profile_interface * >( profile ); - if( ! vid_profile ) - throw invalid_value_exception( "Non-video profile provided to on_video_frame" ); - - if( ! _is_streaming ) - return; - - frame_additional_data data( _metadata_map ); - data.timestamp = software_frame.timestamp; - data.timestamp_domain = software_frame.domain; - data.frame_number = software_frame.frame_number; - - // Depth units, if not provided by the user, should default to the current sensor value of DEPTH_UNITS: - if( vid_profile->get_stream_type() != RS2_STREAM_DEPTH ) - data.depth_units = 0; - else if( software_frame.depth_units ) - data.depth_units = software_frame.depth_units; - else if( auto opt = get_option_handler( RS2_OPTION_DEPTH_UNITS ) ) - data.depth_units = opt->query(); - else - data.depth_units = 0.f; - - auto frame - = allocate_new_video_frame( vid_profile, software_frame.stride, software_frame.bpp, std::move( data ) ); - if( frame ) - invoke_new_frame( frame, software_frame.pixels, on_release.detach() ); - } - - void software_sensor::on_motion_frame( rs2_software_motion_frame const & software_frame ) - { - deferred on_release( [deleter = software_frame.deleter, data = software_frame.data]() { deleter( data ); } ); - if( ! _is_streaming ) - return; - - frame_additional_data data( _metadata_map ); - data.timestamp = software_frame.timestamp; - data.timestamp_domain = software_frame.domain; - data.frame_number = software_frame.frame_number; - - auto frame - = allocate_new_frame( RS2_EXTENSION_MOTION_FRAME, software_frame.profile->profile, std::move( data ) ); - if( frame ) - invoke_new_frame( frame, software_frame.data, on_release.detach() ); - } - - void software_sensor::on_pose_frame( rs2_software_pose_frame const & software_frame ) - { - deferred on_release( [deleter = software_frame.deleter, data = software_frame.data]() { deleter( data ); } ); - if( ! _is_streaming ) - return; - - frame_additional_data data( _metadata_map ); - data.timestamp = software_frame.timestamp; - data.timestamp_domain = software_frame.domain; - data.frame_number = software_frame.frame_number; - - auto frame = allocate_new_frame( RS2_EXTENSION_POSE_FRAME, software_frame.profile->profile, std::move( data ) ); - if( frame ) - invoke_new_frame( frame, software_frame.data, on_release.detach() ); - } - - void software_sensor::on_notification( rs2_software_notification const & notif ) - { - notification n{ notif.category, notif.type, notif.severity, notif.description }; - n.serialized_data = notif.serialized_data; - _notifications_processor->raise_notification(n); - } - - void software_sensor::add_read_only_option(rs2_option option, float val) - { - register_option( option, std::make_shared< const_value_option >( "bypass sensor read only option", val ) ); - } - - void software_sensor::update_read_only_option(rs2_option option, float val) - { - if (auto opt = dynamic_cast(&get_option(option))) - opt->update(val); - else - throw invalid_value_exception( rsutils::string::from() << "option " << get_string( option ) - << " is not read-only or is deprecated type" ); - } - - void software_sensor::add_option(rs2_option option, option_range range, bool is_writable) - { - register_option(option, (is_writable? std::make_shared(range) : - std::make_shared(range))); - } - - void software_recommended_proccesing_blocks::add_processing_block( std::shared_ptr< processing_block_interface > const & block ) - { - if( ! block ) - throw invalid_value_exception( "trying to add an empty software processing block" ); - - _blocks.push_back( block ); - } } // namespace librealsense diff --git a/src/software-device.h b/src/software-device.h index 256d141b33..08d6db06df 100644 --- a/src/software-device.h +++ b/src/software-device.h @@ -2,169 +2,44 @@ // Copyright(c) 2018 Intel Corporation. All Rights Reserved. #pragma once -#include "core/streaming.h" #include "device.h" -#include "sensor.h" -#include -#include +#include "core/extension.h" +#include -namespace librealsense + +namespace librealsense { + + +class software_sensor; + + +class software_device : public device { - class software_sensor; - class software_device_info; - class video_stream_profile_interface; - - class software_device : public device - { - public: - software_device( std::shared_ptr< const device_info > const & ); - virtual ~software_device(); - - software_sensor& add_software_sensor(const std::string& name); - - software_sensor& get_software_sensor( size_t index); - - void set_matcher_type(rs2_matchers matcher); - - std::shared_ptr create_matcher(const frame_holder& frame) const override; - - std::vector get_profiles_tags() const override - { - std::vector markers; - return markers; - }; - void register_extrinsic(const stream_interface& stream); - - void register_destruction_callback(software_device_destruction_callback_ptr); - - protected: - std::vector> _software_sensors; - librealsense::software_device_destruction_callback_ptr _user_destruction_callback; - rs2_matchers _matcher = RS2_MATCHER_DEFAULT; - }; +public: + software_device( std::shared_ptr< const device_info > const & ); + virtual ~software_device(); + + software_sensor& add_software_sensor(const std::string& name); + software_sensor& get_software_sensor( size_t index); + + void set_matcher_type(rs2_matchers matcher); + + std::shared_ptr create_matcher(const frame_holder& frame) const override; + + std::vector< tagged_profile > get_profiles_tags() const override { return {}; }; - class software_device_info : public device_info - { - std::weak_ptr< software_device > _dev; - std::string _address; - - public: - explicit software_device_info( std::shared_ptr< context > const & ctx ) - : device_info( ctx ) - , _address() // leave empty until set_device() - { - } - - void set_device( std::shared_ptr< software_device > const & dev ) - { - if( ! _address.empty() ) - throw wrong_api_call_sequence_exception( "software_device_info already initialized" ); - _dev = dev; - _address = rsutils::string::from() << "software-device://" << (unsigned long long)dev.get(); - } - - std::string get_address() const override { return _address; } - - bool is_same_as( std::shared_ptr< const device_info > const & other ) const override - { - if( auto rhs = std::dynamic_pointer_cast(other) ) - return _address == rhs->_address; - return false; - } - - std::shared_ptr< device_interface > create_device() override - { - return _dev.lock(); - } - }; - - class software_recommended_proccesing_blocks : public recommended_proccesing_blocks_interface - { - public: - processing_blocks get_recommended_processing_blocks() const override { - return _blocks; - } - ~software_recommended_proccesing_blocks() override {} - - void add_processing_block( std::shared_ptr< processing_block_interface > const & block ); - - private: - processing_blocks _blocks; - }; - - class software_sensor : public sensor_base, public extendable_interface - { - public: - software_sensor( std::string const & name, software_device * owner ); - - virtual std::shared_ptr add_video_stream(rs2_video_stream video_stream, bool is_default = false); - virtual std::shared_ptr add_motion_stream(rs2_motion_stream motion_stream, bool is_default = false); - virtual std::shared_ptr add_pose_stream(rs2_pose_stream pose_stream, bool is_default = false); - - bool extend_to(rs2_extension extension_type, void** ptr) override; - - stream_profiles init_stream_profiles() override; - stream_profiles const & get_raw_stream_profiles() const override { return _sw_profiles; } - - void open(const stream_profiles& requests) override; - void close() override; - - void start(frame_callback_ptr callback) override; - void stop() override; - - void on_video_frame( rs2_software_video_frame const & ); - void on_motion_frame( rs2_software_motion_frame const & ); - void on_pose_frame( rs2_software_pose_frame const & ); - void on_notification( rs2_software_notification const & ); - void add_read_only_option(rs2_option option, float val); - void update_read_only_option(rs2_option option, float val); - void add_option(rs2_option option, option_range range, bool is_writable); - void set_metadata( rs2_frame_metadata_value key, rs2_metadata_type value ); - void erase_metadata( rs2_frame_metadata_value key ); - - protected: - frame_interface * allocate_new_frame( rs2_extension, stream_profile_interface *, frame_additional_data && ); - frame_interface * allocate_new_video_frame( video_stream_profile_interface *, int stride, int bpp, frame_additional_data && ); - void invoke_new_frame( frame_holder &&, void const * pixels, std::function< void() > on_release ); - - metadata_array _metadata_map; - - processing_blocks get_recommended_processing_blocks() const override - { - return _pbs.get_recommended_processing_blocks(); - } - - software_recommended_proccesing_blocks & get_software_recommended_proccesing_blocks() { return _pbs; } - - // We build profiles using add_video_stream(), etc., and feed those into init_stream_profiles() which could in - // theory change them: so these are our "raw" profiles before initialization... - stream_profiles _sw_profiles; - - private: - friend class software_device; - uint64_t _unique_id; - - class stereo_extension : public depth_stereo_sensor - { - public: - stereo_extension(software_sensor* owner) : _owner(owner) {} - - float get_depth_scale() const override { - return _owner->get_option(RS2_OPTION_DEPTH_UNITS).query(); - } - - float get_stereo_baseline_mm() const override { - return _owner->get_option(RS2_OPTION_STEREO_BASELINE).query(); - } - - private: - software_sensor* _owner; - }; - - rsutils::lazy< stereo_extension > _stereo_extension; - - software_recommended_proccesing_blocks _pbs; - }; - MAP_EXTENSION(RS2_EXTENSION_SOFTWARE_SENSOR, software_sensor); - MAP_EXTENSION(RS2_EXTENSION_SOFTWARE_DEVICE, software_device); -} + void register_extrinsic(const stream_interface& stream); + + using destruction_callback_ptr = std::shared_ptr< rs2_software_device_destruction_callback >; + void register_destruction_callback( destruction_callback_ptr ); + +protected: + std::vector> _software_sensors; + destruction_callback_ptr _user_destruction_callback; + rs2_matchers _matcher = RS2_MATCHER_DEFAULT; +}; + +MAP_EXTENSION(RS2_EXTENSION_SOFTWARE_DEVICE, software_device); + + +} // namespace librealsense diff --git a/src/software-sensor.cpp b/src/software-sensor.cpp new file mode 100644 index 0000000000..67b2e4850f --- /dev/null +++ b/src/software-sensor.cpp @@ -0,0 +1,376 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2023 Intel Corporation. All Rights Reserved. + +#include "software-sensor.h" +#include "software-device.h" +#include "stream.h" +#include "option.h" +#include "core/video-frame.h" +#include "depth-sensor.h" + +#include +#include + +using rsutils::deferred; + + +namespace librealsense { + + +static std::shared_ptr< metadata_parser_map > create_software_metadata_parser_map() +{ + auto md_parser_map = std::make_shared< metadata_parser_map >(); + for( int i = 0; i < static_cast< int >( rs2_frame_metadata_value::RS2_FRAME_METADATA_COUNT ); ++i ) + { + auto key = static_cast< rs2_frame_metadata_value >( i ); + md_parser_map->emplace( key, std::make_shared< md_array_parser >( key ) ); + } + return md_parser_map; +} + + +class software_sensor::stereo_extension : public depth_stereo_sensor +{ +public: + stereo_extension( software_sensor * owner ) + : _owner( owner ) + { + } + + float get_depth_scale() const override { return _owner->get_option( RS2_OPTION_DEPTH_UNITS ).query(); } + + float get_stereo_baseline_mm() const override { return _owner->get_option( RS2_OPTION_STEREO_BASELINE ).query(); } + +private: + software_sensor * _owner; +}; + + +software_sensor::software_sensor( std::string const & name, software_device * owner ) + : sensor_base( name, owner, &_pbs ) + , _stereo_extension( [this]() { return stereo_extension( this ); } ) + , _metadata_map{} // to all 0's +{ + // At this time (and therefore for backwards compatibility) no register_metadata is required for SW sensors, + // and metadata persists between frames (!!!!!!!). All SW sensors support ALL metadata. We can therefore + // also share their parsers: + static auto software_metadata_parser_map = create_software_metadata_parser_map(); + _metadata_parsers = software_metadata_parser_map; + _unique_id = unique_id::generate_id(); +} + + +software_sensor::~software_sensor() +{ +} + + +std::shared_ptr< stream_profile_interface > software_sensor::add_video_stream( rs2_video_stream video_stream, + bool is_default ) +{ + auto profile = std::make_shared< video_stream_profile >( platform::stream_profile{ (uint32_t)video_stream.width, + (uint32_t)video_stream.height, + (uint32_t)video_stream.fps, + 0 } ); + profile->set_dims( video_stream.width, video_stream.height ); + profile->set_format( video_stream.fmt ); + profile->set_framerate( video_stream.fps ); + profile->set_stream_index( video_stream.index ); + profile->set_stream_type( video_stream.type ); + profile->set_unique_id( video_stream.uid ); + profile->set_intrinsics( [=]() { return video_stream.intrinsics; } ); + if( is_default ) + profile->tag_profile( profile_tag::PROFILE_TAG_DEFAULT ); + _sw_profiles.push_back( profile ); + + return profile; +} + + +std::shared_ptr< stream_profile_interface > software_sensor::add_motion_stream( rs2_motion_stream motion_stream, + bool is_default ) +{ + auto profile + = std::make_shared< motion_stream_profile >( platform::stream_profile{ 0, 0, (uint32_t)motion_stream.fps, 0 } ); + profile->set_format( motion_stream.fmt ); + profile->set_framerate( motion_stream.fps ); + profile->set_stream_index( motion_stream.index ); + profile->set_stream_type( motion_stream.type ); + profile->set_unique_id( motion_stream.uid ); + profile->set_intrinsics( [=]() { return motion_stream.intrinsics; } ); + if( is_default ) + profile->tag_profile( profile_tag::PROFILE_TAG_DEFAULT ); + _sw_profiles.push_back( profile ); + + return std::move( profile ); +} + + +std::shared_ptr< stream_profile_interface > software_sensor::add_pose_stream( rs2_pose_stream pose_stream, + bool is_default ) +{ + auto profile + = std::make_shared< pose_stream_profile >( platform::stream_profile{ 0, 0, (uint32_t)pose_stream.fps, 0 } ); + if( ! profile ) + throw librealsense::invalid_value_exception( "null pointer passed for argument \"profile\"." ); + + profile->set_format( pose_stream.fmt ); + profile->set_framerate( pose_stream.fps ); + profile->set_stream_index( pose_stream.index ); + profile->set_stream_type( pose_stream.type ); + profile->set_unique_id( pose_stream.uid ); + if( is_default ) + profile->tag_profile( profile_tag::PROFILE_TAG_DEFAULT ); + _sw_profiles.push_back( profile ); + + return std::move( profile ); +} + + +bool software_sensor::extend_to( rs2_extension extension_type, void ** ptr ) +{ + if( extension_type == RS2_EXTENSION_DEPTH_SENSOR ) + { + if( supports_option( RS2_OPTION_DEPTH_UNITS ) ) + { + auto & ext = *_stereo_extension; + *ptr = static_cast< depth_sensor * >( &ext ); + return true; + } + } + else if( extension_type == RS2_EXTENSION_DEPTH_STEREO_SENSOR ) + { + if( supports_option( RS2_OPTION_DEPTH_UNITS ) && supports_option( RS2_OPTION_STEREO_BASELINE ) ) + { + *ptr = &( *_stereo_extension ); + return true; + } + } + return false; +} + + +stream_profiles software_sensor::init_stream_profiles() +{ + // By default the raw profiles we're given is what we output + return _sw_profiles; +} + + +void software_sensor::open( const stream_profiles & requests ) +{ + if( _is_streaming ) + throw wrong_api_call_sequence_exception( "open(...) failed. Software device is streaming!" ); + else if( _is_opened ) + throw wrong_api_call_sequence_exception( "open(...) failed. Software device is already opened!" ); + _is_opened = true; + set_active_streams( requests ); +} + + +void software_sensor::close() +{ + if( _is_streaming ) + throw wrong_api_call_sequence_exception( "close() failed. Software device is streaming!" ); + else if( ! _is_opened ) + throw wrong_api_call_sequence_exception( "close() failed. Software device was not opened!" ); + _is_opened = false; + set_active_streams( {} ); +} + + +void software_sensor::start( frame_callback_ptr callback ) +{ + if( _is_streaming ) + throw wrong_api_call_sequence_exception( "start_streaming(...) failed. Software device is already streaming!" ); + else if( ! _is_opened ) + throw wrong_api_call_sequence_exception( "start_streaming(...) failed. Software device was not opened!" ); + _source.get_published_size_option()->set( 0 ); + _source.init( _metadata_parsers ); + _source.set_sensor( this->shared_from_this() ); + _source.set_callback( callback ); + _is_streaming = true; + raise_on_before_streaming_changes( true ); +} + + +void software_sensor::stop() +{ + if( ! _is_streaming ) + throw wrong_api_call_sequence_exception( "stop_streaming() failed. Software device is not streaming!" ); + + _is_streaming = false; + raise_on_before_streaming_changes( false ); + _source.flush(); + _source.reset(); +} + + +void software_sensor::set_metadata( rs2_frame_metadata_value key, rs2_metadata_type value ) +{ + _metadata_map[key] = { true, value }; +} + + +void software_sensor::erase_metadata( rs2_frame_metadata_value key ) +{ + _metadata_map[key].is_valid = false; +} + + +frame_interface * software_sensor::allocate_new_frame( rs2_extension extension, + stream_profile_interface * profile, + frame_additional_data && data ) +{ + auto frame = _source.alloc_frame( extension, 0, std::move( data ), false ); + if( ! frame ) + { + LOG_WARNING( "Failed to allocate frame " << data.frame_number << " type " << extension ); + } + else + { + frame->set_stream( std::dynamic_pointer_cast< stream_profile_interface >( profile->shared_from_this() ) ); + } + return frame; +} + + +frame_interface * software_sensor::allocate_new_video_frame( video_stream_profile_interface * profile, + int stride, + int bpp, + frame_additional_data && data ) +{ + auto frame = allocate_new_frame( profile->get_stream_type() == RS2_STREAM_DEPTH ? RS2_EXTENSION_DEPTH_FRAME + : RS2_EXTENSION_VIDEO_FRAME, + profile, + std::move( data ) ); + if( frame ) + { + auto vid_frame = dynamic_cast< video_frame * >( frame ); + vid_frame->assign( profile->get_width(), profile->get_height(), stride, bpp * 8 ); + auto sd = dynamic_cast< software_device * >( _owner ); + sd->register_extrinsic( *profile ); + } + return frame; +} + + +void software_sensor::invoke_new_frame( frame_holder && frame, void const * pixels, std::function< void() > on_release ) +{ + // The frame pixels/data are stored in the continuation object! + if( pixels ) + frame->attach_continuation( frame_continuation( on_release, pixels ) ); + _source.invoke_callback( std::move( frame ) ); +} + + +void software_sensor::on_video_frame( rs2_software_video_frame const & software_frame ) +{ + deferred on_release( [deleter = software_frame.deleter, data = software_frame.pixels]() { deleter( data ); } ); + + stream_profile_interface * profile = software_frame.profile->profile; + auto vid_profile = dynamic_cast< video_stream_profile_interface * >( profile ); + if( ! vid_profile ) + throw invalid_value_exception( "Non-video profile provided to on_video_frame" ); + + if( ! _is_streaming ) + return; + + frame_additional_data data( _metadata_map ); + data.timestamp = software_frame.timestamp; + data.timestamp_domain = software_frame.domain; + data.frame_number = software_frame.frame_number; + + // Depth units, if not provided by the user, should default to the current sensor value of DEPTH_UNITS: + if( vid_profile->get_stream_type() != RS2_STREAM_DEPTH ) + data.depth_units = 0; + else if( software_frame.depth_units ) + data.depth_units = software_frame.depth_units; + else if( auto opt = get_option_handler( RS2_OPTION_DEPTH_UNITS ) ) + data.depth_units = opt->query(); + else + data.depth_units = 0.f; + + auto frame = allocate_new_video_frame( vid_profile, software_frame.stride, software_frame.bpp, std::move( data ) ); + if( frame ) + invoke_new_frame( frame, software_frame.pixels, on_release.detach() ); +} + + +void software_sensor::on_motion_frame( rs2_software_motion_frame const & software_frame ) +{ + deferred on_release( [deleter = software_frame.deleter, data = software_frame.data]() { deleter( data ); } ); + if( ! _is_streaming ) + return; + + frame_additional_data data( _metadata_map ); + data.timestamp = software_frame.timestamp; + data.timestamp_domain = software_frame.domain; + data.frame_number = software_frame.frame_number; + + auto frame = allocate_new_frame( RS2_EXTENSION_MOTION_FRAME, software_frame.profile->profile, std::move( data ) ); + if( frame ) + invoke_new_frame( frame, software_frame.data, on_release.detach() ); +} + + +void software_sensor::on_pose_frame( rs2_software_pose_frame const & software_frame ) +{ + deferred on_release( [deleter = software_frame.deleter, data = software_frame.data]() { deleter( data ); } ); + if( ! _is_streaming ) + return; + + frame_additional_data data( _metadata_map ); + data.timestamp = software_frame.timestamp; + data.timestamp_domain = software_frame.domain; + data.frame_number = software_frame.frame_number; + + auto frame = allocate_new_frame( RS2_EXTENSION_POSE_FRAME, software_frame.profile->profile, std::move( data ) ); + if( frame ) + invoke_new_frame( frame, software_frame.data, on_release.detach() ); +} + + +void software_sensor::on_notification( rs2_software_notification const & notif ) +{ + notification n{ notif.category, notif.type, notif.severity, notif.description }; + n.serialized_data = notif.serialized_data; + _notifications_processor->raise_notification( n ); +} + + +void software_sensor::add_read_only_option( rs2_option option, float val ) +{ + register_option( option, std::make_shared< const_value_option >( "bypass sensor read only option", val ) ); +} + + +void software_sensor::update_read_only_option( rs2_option option, float val ) +{ + if( auto opt = dynamic_cast< readonly_float_option * >( &get_option( option ) ) ) + opt->update( val ); + else + throw invalid_value_exception( rsutils::string::from() << "option " << get_string( option ) + << " is not read-only or is deprecated type" ); +} + + +void software_sensor::add_option( rs2_option option, option_range range, bool is_writable ) +{ + register_option( option, + ( is_writable ? std::make_shared< float_option >( range ) + : std::make_shared< readonly_float_option >( range ) ) ); +} + + +void software_recommended_proccesing_blocks::add_processing_block( + std::shared_ptr< processing_block_interface > const & block ) +{ + if( ! block ) + throw invalid_value_exception( "trying to add an empty software processing block" ); + + _blocks.push_back( block ); +} + + +} // namespace librealsense diff --git a/src/software-sensor.h b/src/software-sensor.h new file mode 100644 index 0000000000..7bc8477933 --- /dev/null +++ b/src/software-sensor.h @@ -0,0 +1,99 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2023 Intel Corporation. All Rights Reserved. +#pragma once + +#include "sensor.h" +#include "core/extension.h" +#include +#include +#include + +namespace librealsense { + + +class software_recommended_proccesing_blocks : public recommended_proccesing_blocks_interface +{ +public: + processing_blocks get_recommended_processing_blocks() const override { return _blocks; } + + void add_processing_block( std::shared_ptr< processing_block_interface > const & block ); + +private: + processing_blocks _blocks; +}; + + +class software_device; +class stream_profile_interface; +class video_stream_profile_interface; + + +class software_sensor + : public sensor_base + , public extendable_interface +{ +public: + software_sensor( std::string const & name, software_device * owner ); + ~software_sensor(); + + virtual std::shared_ptr< stream_profile_interface > add_video_stream( rs2_video_stream video_stream, + bool is_default = false ); + virtual std::shared_ptr< stream_profile_interface > add_motion_stream( rs2_motion_stream motion_stream, + bool is_default = false ); + virtual std::shared_ptr< stream_profile_interface > add_pose_stream( rs2_pose_stream pose_stream, + bool is_default = false ); + + bool extend_to( rs2_extension extension_type, void ** ptr ) override; + + stream_profiles init_stream_profiles() override; + stream_profiles const & get_raw_stream_profiles() const override { return _sw_profiles; } + + void open( const stream_profiles & requests ) override; + void close() override; + + using frame_callback_ptr = std::shared_ptr< rs2_frame_callback >; + void start( frame_callback_ptr callback ) override; + void stop() override; + + void on_video_frame( rs2_software_video_frame const & ); + void on_motion_frame( rs2_software_motion_frame const & ); + void on_pose_frame( rs2_software_pose_frame const & ); + void on_notification( rs2_software_notification const & ); + void add_read_only_option( rs2_option option, float val ); + void update_read_only_option( rs2_option option, float val ); + void add_option( rs2_option option, option_range range, bool is_writable ); + void set_metadata( rs2_frame_metadata_value key, rs2_metadata_type value ); + void erase_metadata( rs2_frame_metadata_value key ); + +protected: + frame_interface * allocate_new_frame( rs2_extension, stream_profile_interface *, frame_additional_data && ); + frame_interface * allocate_new_video_frame( video_stream_profile_interface *, int stride, int bpp, frame_additional_data && ); + void invoke_new_frame( frame_holder &&, void const * pixels, std::function< void() > on_release ); + + metadata_array _metadata_map; + + processing_blocks get_recommended_processing_blocks() const override + { + return _pbs.get_recommended_processing_blocks(); + } + + software_recommended_proccesing_blocks & get_software_recommended_proccesing_blocks() { return _pbs; } + + // We build profiles using add_video_stream(), etc., and feed those into init_stream_profiles() which could in + // theory change them: so these are our "raw" profiles before initialization... + stream_profiles _sw_profiles; + +private: + friend class software_device; + uint64_t _unique_id; + + class stereo_extension; + rsutils::lazy< stereo_extension > _stereo_extension; + + software_recommended_proccesing_blocks _pbs; +}; + +MAP_EXTENSION( RS2_EXTENSION_SOFTWARE_SENSOR, software_sensor ); + + +} // namespace librealsense diff --git a/src/stream.h b/src/stream.h index e63cbb5465..b92f67ea39 100644 --- a/src/stream.h +++ b/src/stream.h @@ -2,10 +2,12 @@ // Copyright(c) 2015 Intel Corporation. All Rights Reserved. #pragma once -#include "core/streaming.h" +#include "core/stream-interface.h" +#include "core/stream-profile-interface.h" #include "core/video.h" #include "core/motion.h" #include "core/stream-profile.h" +#include "core/tagged-profile.h" #include "context.h" #include "image.h" #include "environment.h" diff --git a/src/sync.cpp b/src/sync.cpp index 562b046c25..d34e01602f 100644 --- a/src/sync.cpp +++ b/src/sync.cpp @@ -1,11 +1,14 @@ // License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2015 Intel Corporation. All Rights Reserved. -#include "core/frame-holder.h" -#include "proc/synthetic-stream.h" #include "sync.h" -#include "environment.h" +#include "core/frame-holder.h" +#include "core/processing.h" +#include "core/stream-profile-interface.h" #include "core/device-interface.h" +#include "core/sensor-interface.h" +#include "composite-frame.h" +#include "core/time-service.h" namespace librealsense { diff --git a/src/sync.h b/src/sync.h index 803e2c9655..327d564c7e 100644 --- a/src/sync.h +++ b/src/sync.h @@ -1,19 +1,21 @@ // License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2015 Intel Corporation. All Rights Reserved. - #pragma once -#include "types.h" -#include "archive.h" +#include "callback-invocation.h" #include "core/frame-holder.h" +#include +#include #include #include #include #include +#include + + +namespace librealsense { -namespace librealsense -{ class synthetic_source_interface; @@ -197,4 +199,6 @@ namespace librealsense bool are_equivalent( double a, double b, double fps ); std::map _last_arrived; }; -} + + +} // namespace librealsense diff --git a/src/types.h b/src/types.h index 80f2143c7c..cb3baf105a 100644 --- a/src/types.h +++ b/src/types.h @@ -591,7 +591,6 @@ namespace librealsense typedef std::shared_ptr frame_processor_callback_ptr; typedef std::shared_ptr notifications_callback_ptr; typedef std::shared_ptr calibration_change_callback_ptr; - typedef std::shared_ptr software_device_destruction_callback_ptr; typedef std::shared_ptr devices_changed_callback_ptr; typedef std::shared_ptr update_progress_callback_ptr;