Skip to content

Commit 1136412

Browse files
committed
Support multiple DDS streams of same type in sensor without index
1 parent de9ee91 commit 1136412

File tree

2 files changed

+55
-21
lines changed

2 files changed

+55
-21
lines changed

src/dds/rs-dds-device-proxy.cpp

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ dds_device_proxy::dds_device_proxy( std::shared_ptr< const device_info > const &
229229
_software_sensors.push_back( sensor_info.proxy );
230230
}
231231
auto stream_type = to_rs2_stream_type( stream->type_string() );
232-
int index = get_index_from_stream_name( stream->name() );
232+
int index = get_unique_index_in_sensor( sensor_info.proxy, stream->name(), stream_type );
233233
sid_index sidx( environment::get_instance().generate_stream_id(), index);
234234
sid_index type_and_index( stream_type, index );
235235
_stream_name_to_librs_stream[stream->name()]
@@ -317,28 +317,32 @@ dds_device_proxy::dds_device_proxy( std::shared_ptr< const device_info > const &
317317
auto source_profile = source_profiles[0];
318318

319319
sid_index type_and_index( source_profile->get_stream_type(), source_profile->get_stream_index() );
320-
sid_index sidx = sensor_info.type_and_index_to_dds_stream_sidx.at( type_and_index );
321-
322-
auto & streams = sensor_proxy->streams();
323-
auto stream_iter = streams.find( sidx );
324-
if( stream_iter == streams.end() )
320+
const auto & it = sensor_info.type_and_index_to_dds_stream_sidx.find( type_and_index );
321+
if( it != sensor_info.type_and_index_to_dds_stream_sidx.end())
325322
{
326-
LOG_ERROR( "No dds stream " << sidx.to_string() << " found for '" << sensor_name << "' " << profile
327-
<< " -> " << source_profile << " " << type_and_index.to_string() );
328-
continue;
329-
}
323+
sid_index sidx = (*it).second;
324+
325+
auto & streams = sensor_proxy->streams();
326+
auto stream_iter = streams.find( sidx );
327+
if( stream_iter == streams.end() )
328+
{
329+
LOG_ERROR( "No dds stream " << sidx.to_string() << " found for '" << sensor_name << "' " << profile
330+
<< " -> " << source_profile << " " << type_and_index.to_string() );
331+
continue;
332+
}
330333

331-
//LOG_DEBUG( " " << profile << " -> " << source_profile << " " << type_and_index.to_string() );
332-
profile->set_unique_id( sidx.sid ); // Was lost on clone
334+
//LOG_DEBUG( " " << profile << " -> " << source_profile << " " << type_and_index.to_string() );
335+
profile->set_unique_id( sidx.sid ); // Was lost on clone
333336

334-
// NOTE: the 'initialization_done' call above creates target profiles from the raw profiles we supplied it.
335-
// The raw profile intrinsics will be overriden to call the target's intrinsics function (which by default
336-
// calls the raw again, creating an infinite loop), so we must override the target:
337-
set_profile_intrinsics( profile, stream_iter->second );
337+
// NOTE: the 'get_stream_profiles' call above creates target profiles from the raw profiles we supplied it.
338+
// The raw profile intrinsics will be overriden to call the target's intrinsics function (which by default
339+
// calls the raw again, creating an infinite loop), so we must override the target:
340+
set_profile_intrinsics( profile, stream_iter->second );
338341

339-
_stream_name_to_profiles.at( stream_iter->second->name() ).push_back( profile ); // For extrinsics
342+
_stream_name_to_profiles.at( stream_iter->second->name() ).push_back( profile ); // For extrinsics
340343

341-
tag_default_profile_of_stream( profile, stream_iter->second );
344+
tag_default_profile_of_stream( profile, stream_iter->second );
345+
}
342346
}
343347
}
344348

@@ -447,8 +451,8 @@ int dds_device_proxy::get_index_from_stream_name( const std::string & name ) con
447451
{
448452
int index = 0;
449453

450-
// If index is not 0 we expect the index to be appended to the stream name with underscore after the name
451-
// e.g 'Infrared_1'. There might be other underscores in the name, e.g. 'Compressed_Color_1'
454+
// If camera sends stream index the info is appended to the stream name with underscore after the name
455+
// e.g 'Infrared_1'. However, there might be other underscores in the name, e.g. 'Compressed_Color_1'
452456
auto delimiter_pos = name.find_last_of( '_' );
453457
if( delimiter_pos != std::string::npos )
454458
{
@@ -467,6 +471,33 @@ int dds_device_proxy::get_index_from_stream_name( const std::string & name ) con
467471
}
468472

469473

474+
int dds_device_proxy::get_unique_index_in_sensor( const std::shared_ptr< dds_sensor_proxy > & sensor,
475+
const std::string & stream_name, rs2_stream stream_type ) const
476+
{
477+
bool index_adjusted = false;
478+
int index = get_index_from_stream_name( stream_name );
479+
480+
// Sending stream index as part of stream name is optional. We want to distinguish streams of same type in the
481+
// sensor so we create an internal, running index for it.
482+
do
483+
{
484+
index_adjusted = false;
485+
for( auto & stream : sensor->streams() )
486+
{
487+
// We can have multiple streams with same index (e.g. 0) but not two of the same type
488+
if( index == stream.first.index && stream_type == to_rs2_stream_type( stream.second->type_string() ) )
489+
{
490+
index++;
491+
index_adjusted = true;
492+
}
493+
}
494+
}
495+
while( index_adjusted );
496+
497+
return index;
498+
}
499+
500+
470501
void dds_device_proxy::set_profile_intrinsics( std::shared_ptr< stream_profile_interface > const & profile,
471502
const std::shared_ptr< realdds::dds_stream > & stream ) const
472503
{
@@ -582,7 +613,8 @@ void dds_device_proxy::tag_default_profile_of_stream(
582613
// Superset = picked up in pipeline with enable_all_stream() config
583614
// We want color and depth to be default, and add infrared as superset
584615
int tag = PROFILE_TAG_SUPERSET;
585-
if( strcmp( stream->type_string(), "color" ) == 0 || strcmp( stream->type_string(), "depth" ) == 0 )
616+
if( ( strcmp( stream->type_string(), "color" ) == 0 && profile->get_stream_index() == 0 ) || // Now we have cameras with more then one color stream, take the first
617+
strcmp( stream->type_string(), "depth" ) == 0 )
586618
tag |= PROFILE_TAG_DEFAULT;
587619
else if( strcmp( stream->type_string(), "ir" ) != 0 || profile->get_stream_index() >= 2 )
588620
return; // leave untagged

src/dds/rs-dds-device-proxy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class dds_device_proxy
5555
rsutils::subscription _metadata_subscription;
5656

5757
int get_index_from_stream_name( const std::string & name ) const;
58+
int get_unique_index_in_sensor( const std::shared_ptr< dds_sensor_proxy > & sensor,
59+
const std::string & stream_name, rs2_stream stream_type ) const;
5860
void set_profile_intrinsics( std::shared_ptr< stream_profile_interface > const & profile,
5961
const std::shared_ptr< realdds::dds_stream > & stream ) const;
6062
void set_video_profile_intrinsics( std::shared_ptr< stream_profile_interface > const & profile,

0 commit comments

Comments
 (0)