Skip to content

Commit

Permalink
Type in stream not profile and other PR#11045 comments
Browse files Browse the repository at this point in the history
  • Loading branch information
OhadMeir committed Oct 31, 2022
1 parent a655f4d commit e7f0b59
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 67 deletions.
24 changes: 12 additions & 12 deletions src/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,10 +501,11 @@ namespace librealsense
{
std::shared_ptr< realdds::dds_device > _dds_dev;

rs2_video_stream to_rs2_video_stream( std::shared_ptr< realdds::dds_video_stream_profile > const & profile )
rs2_video_stream to_rs2_video_stream( std::shared_ptr< realdds::dds_video_stream_profile > const & profile,
int stream_type)
{
rs2_video_stream prof;
prof.type = static_cast< rs2_stream >(profile->type());
prof.type = static_cast< rs2_stream >( stream_type );
prof.index = profile->uid().index;
prof.uid = profile->uid().sid;
prof.width = profile->width();
Expand All @@ -516,10 +517,11 @@ namespace librealsense
return prof;
}

rs2_motion_stream to_rs2_motion_stream( std::shared_ptr< realdds::dds_motion_stream_profile > const & profile )
rs2_motion_stream to_rs2_motion_stream( std::shared_ptr< realdds::dds_motion_stream_profile > const & profile,
int stream_type )
{
rs2_motion_stream prof;
prof.type = static_cast< rs2_stream >( profile->type() );
prof.type = static_cast< rs2_stream >( stream_type );
prof.index = profile->uid().index;
prof.uid = profile->uid().sid;
prof.fps = profile->frequency();
Expand Down Expand Up @@ -565,17 +567,15 @@ namespace librealsense
{
if( video_stream )
{
sensor.add_video_stream(
to_rs2_video_stream(
std::static_pointer_cast< realdds::dds_video_stream_profile >( profile ) ),
profile == default_profile );
auto const & vp = std::static_pointer_cast< realdds::dds_video_stream_profile >( profile );
sensor.add_video_stream( to_rs2_video_stream( vp, stream->type() ),
profile == default_profile );
}
else if( motion_stream )
{
sensor.add_motion_stream(
to_rs2_motion_stream(
std::static_pointer_cast< realdds::dds_motion_stream_profile >( profile ) ),
profile == default_profile );
auto const & mp = std::static_pointer_cast< realdds::dds_motion_stream_profile >( profile );
sensor.add_motion_stream( to_rs2_motion_stream( mp, stream->type() ),
profile == default_profile );
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion third-party/realdds/include/realdds/dds-stream-base.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ class dds_stream_base : public std::enable_shared_from_this< dds_stream_base >
std::string const _sensor_name;
int _default_profile_index = 0;
dds_stream_profiles _profiles;
int _type;

dds_stream_base( std::string const & stream_name, std::string const & sensor_name );
dds_stream_base( std::string const & stream_name, std::string const & sensor_name, int type = 0);

public:
virtual ~dds_stream_base() = default;
Expand All @@ -39,6 +40,7 @@ class dds_stream_base : public std::enable_shared_from_this< dds_stream_base >
std::string const & sensor_name() const { return _sensor_name; }
dds_stream_profiles const & profiles() const { return _profiles; }
int default_profile_index() const { return _default_profile_index; }
int type() const { return _type; }

virtual bool is_open() const = 0;
virtual bool is_streaming() const = 0;
Expand Down
13 changes: 5 additions & 8 deletions third-party/realdds/include/realdds/dds-stream-profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,17 @@ class dds_stream_profile
dds_stream_uid _uid;
dds_stream_format _format;
int16_t _frequency; // "Frames" per second
int8_t _inner_type; // User defined type

std::weak_ptr< dds_stream_base > _stream;

public:
virtual ~dds_stream_profile() {}

protected:
dds_stream_profile( dds_stream_uid uid, dds_stream_format format, int16_t frequency, int8_t inner_type = 0 )
dds_stream_profile( dds_stream_uid uid, dds_stream_format format, int16_t frequency )
: _uid( uid )
, _format( format )
, _frequency( frequency )
, _inner_type( inner_type )
{
}
dds_stream_profile( dds_stream_profile && ) = default;
Expand All @@ -109,7 +107,6 @@ class dds_stream_profile
dds_stream_uid uid() const { return _uid; }
dds_stream_format format() const { return _format; }
int16_t frequency() const { return _frequency; }
int8_t type() const { return _inner_type; }

// These are for debugging - not functional
virtual std::string to_string() const;
Expand All @@ -129,8 +126,8 @@ class dds_video_stream_profile : public dds_stream_profile

public:
dds_video_stream_profile( dds_stream_uid uid, dds_stream_format format, int16_t frequency, uint16_t width, uint16_t height,
uint8_t bytes_per_pixel, int8_t inner_type = 0 )
: dds_stream_profile( uid, format, frequency, inner_type )
uint8_t bytes_per_pixel )
: dds_stream_profile( uid, format, frequency )
, _width( width )
, _height( height )
, _bytes_per_pixel( bytes_per_pixel )
Expand All @@ -150,8 +147,8 @@ class dds_video_stream_profile : public dds_stream_profile
class dds_motion_stream_profile : public dds_stream_profile
{
public:
dds_motion_stream_profile( dds_stream_uid uid, dds_stream_format format, int16_t frequency, int8_t inner_type = 0 )
: dds_stream_profile( uid, format, frequency, inner_type )
dds_motion_stream_profile( dds_stream_uid uid, dds_stream_format format, int16_t frequency )
: dds_stream_profile( uid, format, frequency )
{
}
dds_motion_stream_profile( dds_motion_stream_profile && ) = default;
Expand Down
6 changes: 3 additions & 3 deletions third-party/realdds/include/realdds/dds-stream-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct image_header
class dds_stream_server : public dds_stream_base
{
protected:
dds_stream_server( std::string const & stream_name, std::string const & sensor_name );
dds_stream_server( std::string const & stream_name, std::string const & sensor_name, int type = 0 );

public:
virtual ~dds_stream_server();
Expand All @@ -63,7 +63,7 @@ class dds_video_stream_server : public dds_stream_server
typedef dds_stream_server super;

public:
dds_video_stream_server( std::string const & stream_name, std::string const & sensor_name );
dds_video_stream_server( std::string const & stream_name, std::string const & sensor_name, int type = 0 );

void open( std::string const & topic_name, std::shared_ptr< dds_publisher > const & ) override;

Expand All @@ -77,7 +77,7 @@ class dds_motion_stream_server : public dds_stream_server
typedef dds_stream_server super;

public:
dds_motion_stream_server( std::string const & stream_name, std::string const & sensor_name );
dds_motion_stream_server( std::string const & stream_name, std::string const & sensor_name, int type = 0 );

void open( std::string const & topic_name, std::shared_ptr< dds_publisher > const & ) override;

Expand Down
6 changes: 3 additions & 3 deletions third-party/realdds/include/realdds/dds-stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class dds_stream : public dds_stream_base
typedef dds_stream_base super;

protected:
dds_stream( std::string const & stream_name, std::string const & sensor_name );
dds_stream( std::string const & stream_name, std::string const & sensor_name, int type = 0 );

// dds_stream_base
public:
Expand All @@ -38,7 +38,7 @@ class dds_video_stream : public dds_stream
typedef dds_stream super;

public:
dds_video_stream( std::string const & stream_name, std::string const & sensor_name );
dds_video_stream( std::string const & stream_name, std::string const & sensor_name, int type = 0 );

private:
class impl;
Expand All @@ -50,7 +50,7 @@ class dds_motion_stream : public dds_stream
typedef dds_stream super;

public:
dds_motion_stream( std::string const & stream_name, std::string const & sensor_name );
dds_motion_stream( std::string const & stream_name, std::string const & sensor_name, int type = 0 );

private:
class impl;
Expand Down
10 changes: 5 additions & 5 deletions third-party/realdds/src/dds-control-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ dds_control_server::dds_control_server( std::shared_ptr< dds_subscriber > const
_reader = std::make_shared< dds_topic_reader >( topic, subscriber );

dds_topic_reader::qos rqos( RELIABLE_RELIABILITY_QOS );
rqos.history().depth = 10; // default is 1
rqos.endpoint().history_memory_policy = eprosima::fastrtps::rtps::DYNAMIC_RESERVE_MEMORY_MODE;
rqos.history().depth = 10; // default is 1
// Does not allocate for every sample but still gives flexibility. See:
// https://github.com/eProsima/Fast-DDS/discussions/2707
// (default is PREALLOCATED_MEMORY_MODE)
rqos.endpoint().history_memory_policy = eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
_reader->run( rqos );
}

Expand All @@ -46,9 +49,6 @@ dds_control_server::~dds_control_server()

void dds_control_server::on_control_message_received( on_control_message_received_callback callback )
{
if ( !_reader )
DDS_THROW( runtime_error, "setting callback when reader is not created" );

_reader->on_data_available( callback );
}

Expand Down
22 changes: 16 additions & 6 deletions third-party/realdds/src/dds-device-impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ to_realdds_profile( const topics::device::notification::video_stream_profile & p
profile.framerate,
profile.width,
profile.height,
0, // TODO - bpp
profile.type);
0 ); // TODO - bpp
// TODO - add intrinsics

return prof;
Expand All @@ -72,8 +71,7 @@ to_realdds_profile( const topics::device::notification::motion_stream_profile &
{
auto prof = std::make_shared< dds_motion_stream_profile >( dds_stream_uid( profile.uid, profile.stream_index ),
dds_stream_format::from_rs2( profile.format ),
profile.framerate,
profile.type );
profile.framerate );
// TODO - add intrinsics

return prof;
Expand Down Expand Up @@ -198,7 +196,11 @@ bool dds_device::impl::init()
auto & stream = _streams[stream_name];
if( stream )
DDS_THROW( runtime_error, "stream '" + stream_name + "' already exists" );
stream = std::make_shared< dds_video_stream >( stream_name, sensor_name );
int stream_type = 0;
if ( video_stream_profiles->num_of_profiles > 0 )
stream_type = video_stream_profiles->profiles[0].type;
stream = std::make_shared< dds_video_stream >( stream_name, sensor_name, stream_type );

dds_stream_profiles profiles;
int default_profile_index = 0;
for( int i = 0; i < video_stream_profiles->num_of_profiles; ++i )
Expand All @@ -209,8 +211,10 @@ bool dds_device::impl::init()
default_profile_index = i;
}
stream->init_profiles( profiles, default_profile_index );

LOG_INFO( "... VIDEO_STREAM_PROFILES: " << _streams.size() << "/" << _expected_num_of_streams
<< " streams received" );

if( _streams.size() >= _expected_num_of_streams )
state = state_type::DONE;
}
Expand Down Expand Up @@ -238,7 +242,11 @@ bool dds_device::impl::init()
auto & stream = _streams[stream_name];
if( stream )
DDS_THROW( runtime_error, "stream '" + stream_name + "' already exists" );
stream = std::make_shared< dds_motion_stream >( stream_name, sensor_name );
int stream_type = 0;
if ( motion_stream_profiles->num_of_profiles > 0 )
stream_type = motion_stream_profiles->profiles[0].type;
stream = std::make_shared< dds_motion_stream >( stream_name, sensor_name, stream_type );

dds_stream_profiles profiles;
int default_profile_index = 0;
for( int i = 0; i < motion_stream_profiles->num_of_profiles; ++i )
Expand All @@ -249,8 +257,10 @@ bool dds_device::impl::init()
default_profile_index = i;
}
stream->init_profiles( profiles, default_profile_index );

LOG_INFO( "... MOTION_STREAM_PROFILES: " << _streams.size() << "/" << _expected_num_of_streams
<< " streams received" );

if( _streams.size() >= _expected_num_of_streams )
state = state_type::DONE;
}
Expand Down
12 changes: 6 additions & 6 deletions third-party/realdds/src/dds-device-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ static void on_discovery_video_stream( std::shared_ptr< dds_video_stream_server
topics::device::notification::video_stream_profile vsp_msg = { vsp->uid().index,
vsp->uid().sid,
vsp->frequency(),
(int8_t)vsp->format().to_rs2(),
vsp->type(),
(int16_t)vsp->width(),
(int16_t)vsp->height(),
static_cast< int8_t >( vsp->format().to_rs2() ),
static_cast< int8_t >( stream->type() ),
static_cast< int16_t >( vsp->width() ),
static_cast< int16_t >( vsp->height() ),
stream->default_profile_index() == index };

video_stream_profiles.profiles[index++] = std::move( vsp_msg );
Expand Down Expand Up @@ -140,8 +140,8 @@ static void on_discovery_motion_stream( std::shared_ptr< dds_motion_stream_serve
topics::device::notification::motion_stream_profile msp_msg = { msp->uid().index,
msp->uid().sid,
msp->frequency(),
(int8_t)msp->format().to_rs2(),
msp->type() };
static_cast< int8_t >( msp->format().to_rs2() ),
static_cast< int8_t >( stream->type() ) };

motion_stream_profiles.profiles[index++] = std::move( msp_msg );
}
Expand Down
7 changes: 5 additions & 2 deletions third-party/realdds/src/dds-notification-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ dds_notification_server::dds_notification_server( std::shared_ptr< dds_publisher
} );

dds_topic_writer::qos wqos( RELIABLE_RELIABILITY_QOS );
wqos.history().depth = 10; // default is 1
wqos.endpoint().history_memory_policy = eprosima::fastrtps::rtps::DYNAMIC_RESERVE_MEMORY_MODE; // TODO: why?
wqos.history().depth = 10; // default is 1
// Does not allocate for every sample but still gives flexibility. See:
// https://github.com/eProsima/Fast-DDS/discussions/2707
// (default is PREALLOCATED_MEMORY_MODE)
wqos.endpoint().history_memory_policy = eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
_writer->run( wqos );

_notifications_loop.start();
Expand Down
4 changes: 3 additions & 1 deletion third-party/realdds/src/dds-stream-base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ namespace realdds {


dds_stream_base::dds_stream_base( std::string const & name,
std::string const & sensor_name )
std::string const & sensor_name,
int type)
: _name( name )
, _sensor_name( name )
, _type( type )
{
}

Expand Down
16 changes: 10 additions & 6 deletions third-party/realdds/src/dds-stream-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ using namespace eprosima::fastdds::dds;
using namespace realdds;


dds_stream_server::dds_stream_server( std::string const & stream_name, std::string const & sensor_name )
: dds_stream_base( stream_name, sensor_name )
dds_stream_server::dds_stream_server( std::string const & stream_name, std::string const & sensor_name, int type )
: dds_stream_base( stream_name, sensor_name, type )
{
}

Expand All @@ -30,8 +30,10 @@ dds_stream_server::~dds_stream_server()
}


dds_video_stream_server::dds_video_stream_server( std::string const& stream_name, std::string const& sensor_name )
: dds_stream_server( stream_name, sensor_name )
dds_video_stream_server::dds_video_stream_server( std::string const& stream_name,
std::string const& sensor_name,
int type )
: dds_stream_server( stream_name, sensor_name, type )
{
}

Expand All @@ -44,8 +46,10 @@ void dds_video_stream_server::check_profile( std::shared_ptr< dds_stream_profile
}


dds_motion_stream_server::dds_motion_stream_server( std::string const & stream_name, std::string const & sensor_name )
: dds_stream_server( stream_name, sensor_name )
dds_motion_stream_server::dds_motion_stream_server( std::string const & stream_name,
std::string const & sensor_name,
int type )
: dds_stream_server( stream_name, sensor_name, type )
{
}

Expand Down
12 changes: 6 additions & 6 deletions third-party/realdds/src/dds-stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
namespace realdds {


dds_stream::dds_stream( std::string const & stream_name, std::string const & sensor_name )
: super( stream_name, sensor_name )
dds_stream::dds_stream( std::string const & stream_name, std::string const & sensor_name, int type )
: super( stream_name, sensor_name, type )
{
}

Expand All @@ -34,15 +34,15 @@ std::shared_ptr< dds_topic > const & dds_stream::get_topic() const
}


dds_video_stream::dds_video_stream( std::string const & stream_name, std::string const & sensor_name )
: super( stream_name, sensor_name )
dds_video_stream::dds_video_stream( std::string const & stream_name, std::string const & sensor_name, int type )
: super( stream_name, sensor_name, type )
, _impl( std::make_shared< dds_video_stream::impl >() )
{
}


dds_motion_stream::dds_motion_stream( std::string const & stream_name, std::string const & sensor_name )
: super( stream_name, sensor_name )
dds_motion_stream::dds_motion_stream( std::string const & stream_name, std::string const & sensor_name, int type )
: super( stream_name, sensor_name, type )
, _impl( std::make_shared< dds_motion_stream::impl >() )
{
}
Expand Down
Loading

0 comments on commit e7f0b59

Please sign in to comment.