@@ -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 () );
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+ 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,32 @@ 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 ) 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+ if ( index == stream.first .index )
488+ {
489+ index++;
490+ index_adjusted = true ;
491+ }
492+ }
493+ }
494+ while ( index_adjusted );
495+
496+ return index;
497+ }
498+
499+
470500void dds_device_proxy::set_profile_intrinsics ( std::shared_ptr< stream_profile_interface > const & profile,
471501 const std::shared_ptr< realdds::dds_stream > & stream ) const
472502{
@@ -582,7 +612,8 @@ void dds_device_proxy::tag_default_profile_of_stream(
582612 // Superset = picked up in pipeline with enable_all_stream() config
583613 // We want color and depth to be default, and add infrared as superset
584614 int tag = PROFILE_TAG_SUPERSET;
585- if ( strcmp ( stream->type_string (), " color" ) == 0 || strcmp ( stream->type_string (), " depth" ) == 0 )
615+ 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
616+ strcmp ( stream->type_string (), " depth" ) == 0 )
586617 tag |= PROFILE_TAG_DEFAULT;
587618 else if ( strcmp ( stream->type_string (), " ir" ) != 0 || profile->get_stream_index () >= 2 )
588619 return ; // leave untagged
0 commit comments