From 358ff6b8f45d5f993af6bbc1c47df6b36434e5b9 Mon Sep 17 00:00:00 2001 From: Eran Date: Mon, 7 Oct 2024 09:00:49 +0300 Subject: [PATCH] add backend_stream_profile::to_stream() --- src/dds/rs-dds-sensor-proxy.cpp | 4 +- src/ds/d400/d400-factory.cpp | 3 +- src/hid-sensor.cpp | 1 + src/media/ros/ros_reader.cpp | 3 +- src/media/ros/ros_reader.h | 3 +- src/platform/stream-profile-impl.h | 15 ++- src/proc/formats-converter.cpp | 2 +- src/proc/synthetic-stream.cpp | 3 +- src/proc/y8i-to-y8y8.cpp | 5 +- src/sensor.cpp | 4 +- src/stream.cpp | 196 ++++++++++++++++------------- src/stream.h | 14 +-- src/uvc-sensor.cpp | 3 +- 13 files changed, 149 insertions(+), 107 deletions(-) diff --git a/src/dds/rs-dds-sensor-proxy.cpp b/src/dds/rs-dds-sensor-proxy.cpp index e4861c0f699..75c8ad812a2 100644 --- a/src/dds/rs-dds-sensor-proxy.cpp +++ b/src/dds/rs-dds-sensor-proxy.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include @@ -250,9 +251,8 @@ void dds_sensor_proxy::open( const stream_profiles & profiles ) { auto & sp = source_profiles[i]; sid_index sidx( sp->get_unique_id(), sp->get_stream_index() ); - if( Is< video_stream_profile >( sp ) ) + if( auto const vsp = As< video_stream_profile >( sp ) ) { - const auto && vsp = As< video_stream_profile >( source_profiles[i] ); auto video_profile = find_profile( sidx, realdds::dds_video_stream_profile( sp->get_framerate(), diff --git a/src/ds/d400/d400-factory.cpp b/src/ds/d400/d400-factory.cpp index 56428ff9c8e..44867a2e97c 100644 --- a/src/ds/d400/d400-factory.cpp +++ b/src/ds/d400/d400-factory.cpp @@ -1,5 +1,5 @@ // License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2016 Intel Corporation. All Rights Reserved. +// Copyright(c) 2016-24 Intel Corporation. All Rights Reserved. #include #include @@ -10,6 +10,7 @@ #include "device.h" #include "image.h" #include "metadata-parser.h" +#include "context.h" #include diff --git a/src/hid-sensor.cpp b/src/hid-sensor.cpp index 44dd4a2778a..dd4559a3a2e 100644 --- a/src/hid-sensor.cpp +++ b/src/hid-sensor.cpp @@ -4,6 +4,7 @@ #include "hid-sensor.h" #include "device.h" #include "stream.h" +#include "image.h" #include "global_timestamp_reader.h" #include "metadata.h" #include "platform/stream-profile-impl.h" diff --git a/src/media/ros/ros_reader.cpp b/src/media/ros/ros_reader.cpp index 03e1c930842..ce5df084630 100644 --- a/src/media/ros/ros_reader.cpp +++ b/src/media/ros/ros_reader.cpp @@ -1,5 +1,5 @@ // License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2019 Intel Corporation. All Rights Reserved. +// Copyright(c) 2019-24 Intel Corporation. All Rights Reserved. #include "ros_reader.h" #include "ds/ds-device-common.h" @@ -10,6 +10,7 @@ #include #include #include +#include #include #include diff --git a/src/media/ros/ros_reader.h b/src/media/ros/ros_reader.h index 00ad56e0cd0..e71f5bba078 100644 --- a/src/media/ros/ros_reader.h +++ b/src/media/ros/ros_reader.h @@ -1,5 +1,5 @@ // License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2017 Intel Corporation. All Rights Reserved. +// Copyright(c) 2017-24 Intel Corporation. All Rights Reserved. #pragma once @@ -14,6 +14,7 @@ namespace librealsense { using namespace device_serializer; + class context; class frame_source; class info_container; class options_interface; diff --git a/src/platform/stream-profile-impl.h b/src/platform/stream-profile-impl.h index a0fd77a1e80..953d326ea4d 100644 --- a/src/platform/stream-profile-impl.h +++ b/src/platform/stream-profile-impl.h @@ -1,8 +1,10 @@ // License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2023 Intel Corporation. All Rights Reserved. +// Copyright(c) 2023-4 Intel Corporation. All Rights Reserved. #pragma once #include "stream-profile.h" +#include +#include namespace librealsense { @@ -23,7 +25,16 @@ class stream_profile_impl : public super { } - virtual stream_profile const & get_backend_profile() const override { return _backend_stream_profile; } + stream_profile const & get_backend_profile() const override { return _backend_stream_profile; } + + void to_stream( std::ostream & os ) const override + { + os << " ["; + os << _backend_stream_profile.width << 'x' << _backend_stream_profile.height; + os << ' ' << rsutils::type::fourcc( _backend_stream_profile.format ); + os << " @ " << _backend_stream_profile.fps << " Hz"; + os << "]"; + } }; diff --git a/src/proc/formats-converter.cpp b/src/proc/formats-converter.cpp index 1e7ee3c2f4b..f8bb9cd3d1f 100644 --- a/src/proc/formats-converter.cpp +++ b/src/proc/formats-converter.cpp @@ -1,5 +1,5 @@ // License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2023 Intel Corporation. All Rights Reserved. +// Copyright(c) 2023-4 Intel Corporation. All Rights Reserved. #include "proc/formats-converter.h" #include "stream.h" diff --git a/src/proc/synthetic-stream.cpp b/src/proc/synthetic-stream.cpp index 179337d457d..c49beb62b7d 100644 --- a/src/proc/synthetic-stream.cpp +++ b/src/proc/synthetic-stream.cpp @@ -1,5 +1,5 @@ // License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2017 Intel Corporation. All Rights Reserved. +// Copyright(c) 2017-24 Intel Corporation. All Rights Reserved. #include "proc/synthetic-stream.h" @@ -12,6 +12,7 @@ #include "option.h" #include "stream.h" #include "types.h" +#include #include #include diff --git a/src/proc/y8i-to-y8y8.cpp b/src/proc/y8i-to-y8y8.cpp index c268aa1bc8c..92f36f57915 100644 --- a/src/proc/y8i-to-y8y8.cpp +++ b/src/proc/y8i-to-y8y8.cpp @@ -1,9 +1,10 @@ // License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2019 Intel Corporation. All Rights Reserved. +// Copyright(c) 2019-24 Intel Corporation. All Rights Reserved. #include "y8i-to-y8y8.h" -#include "stream.h" +#include +#include #ifdef RS2_USE_CUDA #include "cuda/cuda-conversion.cuh" diff --git a/src/sensor.cpp b/src/sensor.cpp index d551ea25f74..f051cb2af41 100644 --- a/src/sensor.cpp +++ b/src/sensor.cpp @@ -1,11 +1,13 @@ // License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2015 Intel Corporation. All Rights Reserved. +// Copyright(c) 2015-24 Intel Corporation. All Rights Reserved. #include "uvc-sensor.h" #include "source.h" #include "device.h" #include "stream.h" +#include "context.h" +#include "image.h" #include "proc/synthetic-stream.h" #include "proc/decimation-filter.h" #include "global_timestamp_reader.h" diff --git a/src/stream.cpp b/src/stream.cpp index 9dcb4d5bcac..31fde0bb587 100644 --- a/src/stream.cpp +++ b/src/stream.cpp @@ -1,111 +1,137 @@ // License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2015 Intel Corporation. All Rights Reserved. +// Copyright(c) 2015-24 Intel Corporation. All Rights Reserved. #include "stream.h" +#include -namespace librealsense + +namespace librealsense { + + +stream::stream( rs2_stream stream_type, int index ) + : _index( index ) + , _type( stream_type ) { - stream::stream(rs2_stream stream_type, int index) - : _index(index), _type(stream_type) - { - _uid = environment::get_instance().generate_stream_id(); - } + _uid = environment::get_instance().generate_stream_id(); +} - int stream::get_stream_index() const - { - return _index; - } +int stream::get_stream_index() const +{ + return _index; +} - void stream::set_stream_index(int index) - { - _index = index; - } +void stream::set_stream_index( int index ) +{ + _index = index; +} - rs2_stream stream::get_stream_type() const - { - return _type; - } +rs2_stream stream::get_stream_type() const +{ + return _type; +} - void stream::set_stream_type(rs2_stream stream) - { - _type = stream; - } +void stream::set_stream_type( rs2_stream stream ) +{ + _type = stream; +} - stream_profile_base::stream_profile_base() - { - _c_ptr = &_c_wrapper; - _c_wrapper.profile = this; - _c_wrapper.clone = nullptr; - } +stream_profile_base::stream_profile_base() +{ + _c_ptr = &_c_wrapper; + _c_wrapper.profile = this; + _c_wrapper.clone = nullptr; +} - int stream_profile_base::get_stream_index() const - { - return _index; - } +int stream_profile_base::get_stream_index() const +{ + return _index; +} - void stream_profile_base::set_stream_index(int index) - { - _index = index; - } +void stream_profile_base::set_stream_index( int index ) +{ + _index = index; +} - rs2_stream stream_profile_base::get_stream_type() const - { - return _type; - } +rs2_stream stream_profile_base::get_stream_type() const +{ + return _type; +} - void stream_profile_base::set_stream_type(rs2_stream stream) - { - _type = stream; - } +void stream_profile_base::set_stream_type( rs2_stream stream ) +{ + _type = stream; +} - rs2_format stream_profile_base::get_format() const - { - return _format; - } +rs2_format stream_profile_base::get_format() const +{ + return _format; +} - void stream_profile_base::set_format(rs2_format format) - { - _format = format; - } +void stream_profile_base::set_format( rs2_format format ) +{ + _format = format; +} - uint32_t stream_profile_base::get_framerate() const - { - return _framerate; - } +uint32_t stream_profile_base::get_framerate() const +{ + return _framerate; +} - void stream_profile_base::set_framerate(uint32_t val) - { - _framerate = val; - } +void stream_profile_base::set_framerate( uint32_t val ) +{ + _framerate = val; +} - int stream_profile_base::get_tag() const - { - return _tag; - } +int stream_profile_base::get_tag() const +{ + return _tag; +} - void stream_profile_base::tag_profile(int tag) - { - _tag = tag; - } +void stream_profile_base::tag_profile( int tag ) +{ + _tag = tag; +} - rs2_stream_profile* stream_profile_base::get_c_wrapper() const - { - return _c_ptr; - } - void stream_profile_base::set_c_wrapper(rs2_stream_profile* wrapper) - { - _c_ptr = wrapper; - } - void stream_profile_base::create_snapshot(std::shared_ptr& snapshot) const - { - auto ptr = std::const_pointer_cast(shared_from_this()); - snapshot = std::dynamic_pointer_cast(ptr); - } - void stream_profile_base::enable_recording(std::function record_action) +rs2_stream_profile * stream_profile_base::get_c_wrapper() const +{ + return _c_ptr; +} + + +void stream_profile_base::set_c_wrapper( rs2_stream_profile * wrapper ) +{ + _c_ptr = wrapper; +} + + +void stream_profile_base::create_snapshot( std::shared_ptr< stream_profile_interface > & snapshot ) const +{ + auto ptr = std::const_pointer_cast< stream_interface >( shared_from_this() ); + snapshot = std::dynamic_pointer_cast< stream_profile_interface >( ptr ); +} + + +void stream_profile_base::enable_recording( std::function< void( const stream_profile_interface & ) > record_action ) +{ + // TODO: implement or remove inheritance from recordable + throw not_implemented_exception( __FUNCTION__ ); +} + + +std::ostream & operator<<( std::ostream & os, const stream_profiles & profiles ) +{ + bool first = true; + for( auto & p : profiles ) { - //TODO: implement or remove inheritance from recordable - throw not_implemented_exception(__FUNCTION__); + if( first ) + first = false; + else + os << ", "; + os << p; } + return os; } + +} // namespace librealsense diff --git a/src/stream.h b/src/stream.h index ad06f560657..d1f82b45e49 100644 --- a/src/stream.h +++ b/src/stream.h @@ -1,5 +1,5 @@ // License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2015 Intel Corporation. All Rights Reserved. +// Copyright(c) 2015-24 Intel Corporation. All Rights Reserved. #pragma once #include "core/stream-interface.h" @@ -8,16 +8,10 @@ #include "core/motion.h" #include "core/stream-profile.h" #include "core/tagged-profile.h" -#include "context.h" -#include "image.h" +#include "librealsense-exception.h" #include "environment.h" -namespace librealsense -{ - class stream_profile_interface; -} - struct rs2_stream_profile { librealsense::stream_profile_interface * profile; @@ -58,6 +52,8 @@ namespace librealsense throw not_implemented_exception( "not a backend profile!" ); } + virtual void to_stream( std::ostream & ) const {} + virtual ~backend_stream_profile() = default; }; @@ -136,7 +132,7 @@ namespace librealsense auto id = environment::get_instance().generate_stream_id(); res->set_unique_id( id ); - LOG_DEBUG( "video_stream_profile::clone, id= " << id ); + //LOG_DEBUG( "video_stream_profile::clone, id= " << id ); res->set_dims(get_width(), get_height()); std::function int_func = _calc_intrinsics; res->set_intrinsics([int_func]() { return int_func(); }); diff --git a/src/uvc-sensor.cpp b/src/uvc-sensor.cpp index 847647f7362..fab565af0f8 100644 --- a/src/uvc-sensor.cpp +++ b/src/uvc-sensor.cpp @@ -1,9 +1,10 @@ // License: Apache 2.0. See LICENSE file in root directory. -// Copyright(c) 2023 Intel Corporation. All Rights Reserved. +// Copyright(c) 2023-4 Intel Corporation. All Rights Reserved. #include "uvc-sensor.h" #include "device.h" #include "stream.h" +#include "image.h" #include "global_timestamp_reader.h" #include "core/video-frame.h" #include "core/notification.h"