Skip to content

Commit d014218

Browse files
committed
fix problems with type-index mapping
1 parent 54c3b1d commit d014218

File tree

4 files changed

+61
-45
lines changed

4 files changed

+61
-45
lines changed

src/core/stream-profile-interface.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// License: Apache 2.0. See LICENSE file in root directory.
2-
// Copyright(c) 2023 Intel Corporation. All Rights Reserved.
2+
// Copyright(c) 2023-4 Intel Corporation. All Rights Reserved.
33
#pragma once
44

55
#include "stream-interface.h"
@@ -9,7 +9,7 @@
99
#include <functional>
1010
#include <memory>
1111
#include <vector>
12-
#include <ostream>
12+
#include <iosfwd>
1313

1414

1515
namespace librealsense {
@@ -38,14 +38,8 @@ class stream_profile_interface
3838
using stream_profiles = std::vector< std::shared_ptr< stream_profile_interface > >;
3939

4040

41-
inline std::ostream & operator<<( std::ostream & os, const stream_profiles & profiles )
42-
{
43-
for( auto & p : profiles )
44-
{
45-
os << rs2_format_to_string( p->get_format() ) << " " << rs2_stream_to_string( p->get_stream_type() ) << ", ";
46-
}
47-
return os;
48-
}
41+
std::ostream & operator<<( std::ostream &, const std::shared_ptr< stream_profile_interface > & );
42+
std::ostream & operator<<( std::ostream &, const stream_profiles & );
4943

5044

5145
} // namespace librealsense

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

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ dds_device_proxy::dds_device_proxy( std::shared_ptr< const device_info > const &
176176
std::shared_ptr< dds_sensor_proxy > proxy;
177177
int sensor_index = 0;
178178
rs2_stream type = RS2_STREAM_ANY;
179+
// dds_streams bear stream type and index information, we add it to a dds_sensor_proxy mapped by a newly generated
180+
// unique ID. After the sensor initialization we get all the "final" profiles from formats-converter with type and
181+
// index but without IDs. We need to find the dds_stream that each profile was created from so we create a map from
182+
// type and index to dds_stream ID and index, because the dds_sensor_proxy holds a map from sidx to dds_stream. We
183+
// need both the ID from that map key and the stream itself (for intrinsics information)
184+
std::map< sid_index, sid_index > type_and_index_to_dds_stream_sidx;
179185
};
180186
std::map< std::string, sensor_info > sensor_name_to_info;
181187

@@ -185,7 +191,7 @@ dds_device_proxy::dds_device_proxy( std::shared_ptr< const device_info > const &
185191
{
186192
auto & sensor = sensor_name_to_info[stream->sensor_name()];
187193
if( stream->type_string() == "depth"
188-
|| stream->type_string() == "infrared" )
194+
|| stream->type_string() == "ir" )
189195
{
190196
// If there's depth or infrared, it is a depth sensor regardless of what else is in there
191197
// E.g., the D405 has a color stream in the depth sensor
@@ -208,13 +214,6 @@ dds_device_proxy::dds_device_proxy( std::shared_ptr< const device_info > const &
208214
}
209215
} ); // End foreach_stream lambda
210216

211-
// dds_streams bear stream type and index information, we add it to a dds_sensor_proxy mapped by a newly generated
212-
// unique ID. After the sensor initialization we get all the "final" profiles from formats-converter with type and
213-
// index but without IDs. We need to find the dds_stream that each profile was created from so we create a map from
214-
// type and index to dds_stream ID and index, because the dds_sensor_proxy holds a map from sidx to dds_stream. We
215-
// need both the ID from that map key and the stream itself (for intrinsics information)
216-
std::map< sid_index, sid_index > type_and_index_to_dds_stream_sidx;
217-
218217
_dds_dev->foreach_stream(
219218
[&]( std::shared_ptr< realdds::dds_stream > const & stream )
220219
{
@@ -235,9 +234,14 @@ dds_device_proxy::dds_device_proxy( std::shared_ptr< const device_info > const &
235234
= std::make_shared< librealsense::stream >( stream_type, sidx.index );
236235
sensor_info.proxy->add_dds_stream( sidx, stream );
237236
_stream_name_to_owning_sensor[stream->name()] = sensor_info.proxy;
238-
type_and_index_to_dds_stream_sidx.insert( { type_and_index, sidx } );
239-
//LOG_DEBUG( sidx.to_string() << " " << get_string( sensor_info.type ) << " '" << stream->sensor_name()
240-
// << "' : '" << stream->name() << "' " << get_string( stream_type ) );
237+
if( ! sensor_info.type_and_index_to_dds_stream_sidx.insert( { type_and_index, sidx } ).second )
238+
LOG_ERROR( "Failed to insert '" << stream->sensor_name() << "' " << type_and_index.to_string() << " "
239+
<< get_string( sensor_info.type ) << " -> " << get_string( stream_type )
240+
<< " " << sidx.to_string() << " '" << stream->name() << "' mapping" );
241+
//else
242+
// LOG_DEBUG( "'" << stream->sensor_name() << "' " << type_and_index.to_string() << " "
243+
// << get_string( sensor_info.type ) << " -> " << get_string( stream_type ) << " "
244+
// << sidx.to_string() << " '" << stream->name() << "'" );
241245

242246
software_sensor & sensor = get_software_sensor( sensor_info.sensor_index );
243247
auto video_stream = std::dynamic_pointer_cast< realdds::dds_video_stream >( stream );
@@ -279,36 +283,35 @@ dds_device_proxy::dds_device_proxy( std::shared_ptr< const device_info > const &
279283
}
280284
} ); // End foreach_stream lambda
281285

282-
for( auto & sensor_info : sensor_name_to_info )
286+
for( auto & name_info : sensor_name_to_info )
283287
{
288+
auto & sensor_name = name_info.first;
289+
auto & sensor_info = name_info.second;
290+
auto & sensor_proxy = sensor_info.proxy;
284291
//LOG_DEBUG( sensor_info.first );
285292

286293
// Set profile's ID based on the dds_stream's ID (index already set). Connect the profile to the extrinsics graph.
287-
for( auto & profile : sensor_info.second.proxy->get_stream_profiles() )
294+
// The get_stream_profiles() call will initialize the profiles (calling dds_sensor_proxy::init_stream_profiles())
295+
for( auto & profile : sensor_proxy->get_stream_profiles() )
288296
{
289-
//if( auto p = std::dynamic_pointer_cast< librealsense::video_stream_profile_interface >( profile ) )
290-
//{
291-
// LOG_DEBUG( " " << get_string( p->get_stream_type() ) << ' ' << p->get_stream_index() << ' '
292-
// << get_string( p->get_format() ) << ' ' << p->get_width() << 'x' << p->get_height()
293-
// << " @ " << p->get_framerate() );
294-
//}
295-
//else if( auto p = std::dynamic_pointer_cast<librealsense::motion_stream_profile_interface>( profile ) )
296-
//{
297-
// LOG_DEBUG( " " << get_string( p->get_stream_type() ) << ' ' << p->get_stream_index() << ' '
298-
// << get_string( p->get_format() ) << " @ " << p->get_framerate() );
299-
//}
300-
sid_index type_and_index( profile->get_stream_type(), profile->get_stream_index() );
301-
302-
auto & streams = sensor_info.second.proxy->streams();
303-
304-
sid_index sidx = type_and_index_to_dds_stream_sidx.at( type_and_index );
297+
auto & source_profiles = sensor_proxy->_formats_converter.get_source_profiles_from_target( profile );
298+
if( source_profiles.size() != 1 )
299+
LOG_ERROR( "More than one source profile available for [" << profile << "]: " << source_profiles );
300+
auto source_profile = source_profiles[0];
301+
302+
sid_index type_and_index( source_profile->get_stream_type(), source_profile->get_stream_index() );
303+
sid_index sidx = sensor_info.type_and_index_to_dds_stream_sidx.at( type_and_index );
304+
305+
auto & streams = sensor_proxy->streams();
305306
auto stream_iter = streams.find( sidx );
306307
if( stream_iter == streams.end() )
307308
{
308-
LOG_DEBUG( " no dds stream" );
309+
LOG_ERROR( "No dds stream " << sidx.to_string() << " found for '" << sensor_name << "' " << profile
310+
<< " -> " << source_profile << " " << type_and_index.to_string() );
309311
continue;
310312
}
311313

314+
//LOG_DEBUG( " " << profile << " -> " << source_profile << " " << type_and_index.to_string() );
312315
profile->set_unique_id( sidx.sid ); // Was lost on clone
313316

314317
// NOTE: the 'initialization_done' call above creates target profiles from the raw profiles we supplied it.

src/proc/formats-converter.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <src/composite-frame.h>
77
#include <src/core/frame-callback.h>
88

9+
#include <rsutils/string/from.h>
910
#include <ostream>
1011

1112
namespace librealsense
@@ -73,15 +74,18 @@ std::ostream & operator<<( std::ostream & os, const std::shared_ptr< stream_prof
7374
{
7475
if( profile )
7576
{
76-
os << "(" << rs2_stream_to_string( profile->get_stream_type() ) << ")";
77-
os << " " << rs2_format_to_string( profile->get_format() );
78-
os << " " << profile->get_stream_index();
77+
os << rs2_stream_to_string( profile->get_stream_type() );
78+
if( auto stream_index = profile->get_stream_index() )
79+
os << " " << stream_index;
7980
if( auto vsp = As< video_stream_profile, stream_profile_interface >( profile ) )
8081
{
8182
os << " " << vsp->get_width();
8283
os << "x" << vsp->get_height();
8384
}
84-
os << " @ " << profile->get_framerate();
85+
os << " " << rs2_format_to_string( profile->get_format() );
86+
os << " @ " << profile->get_framerate() << " Hz";
87+
if( auto bsp = std::dynamic_pointer_cast< backend_stream_profile >( profile ) )
88+
bsp->to_stream( os );
8589
}
8690

8791
return os;
@@ -222,6 +226,7 @@ bool formats_converter::is_profile_in_list( const std::shared_ptr< stream_profil
222226
// Not passing const & because we modify from_profiles, would otherwise need to create a copy
223227
void formats_converter::prepare_to_convert( stream_profiles from_profiles )
224228
{
229+
LOG_DEBUG( "Requested: " << from_profiles );
225230
clear_active_cache();
226231

227232
// Add missing data to target profiles (was not available during get_all_possible_target_profiles)
@@ -264,10 +269,22 @@ void formats_converter::prepare_to_convert( stream_profiles from_profiles )
264269
}
265270
}
266271
const stream_profiles & print_current_resolved_reqs = { current_resolved_reqs.begin(), current_resolved_reqs.end() };
267-
LOG_INFO( "Request: " << from_profiles_of_best_match << "\nResolved to: " << print_current_resolved_reqs );
272+
LOG_DEBUG( "Resolved to: " << print_current_resolved_reqs );
268273
}
269274
}
270275

276+
277+
stream_profiles const & formats_converter::get_source_profiles_from_target(
278+
std::shared_ptr< stream_profile_interface > const & target_profile ) const
279+
{
280+
auto it = _target_profiles_to_raw_profiles.find( to_profile( target_profile.get() ) );
281+
if( it == _target_profiles_to_raw_profiles.end() )
282+
throw invalid_value_exception( rsutils::string::from()
283+
<< "target profile [" << target_profile << "] not found" );
284+
return it->second;
285+
}
286+
287+
271288
void formats_converter::update_target_profiles_data( const stream_profiles & from_profiles )
272289
{
273290
for( auto & from_profile : from_profiles )

src/proc/formats-converter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ namespace librealsense
4343
rs2_frame_callback_sptr get_frames_callback() const { return _converted_frames_callback; }
4444
void convert_frame( frame_holder & f );
4545

46+
stream_profiles const & get_source_profiles_from_target( std::shared_ptr< stream_profile_interface > const & target_profile ) const;
47+
4648
protected:
4749
void clear_active_cache();
4850
void update_target_profiles_data( const stream_profiles & from_profiles );

0 commit comments

Comments
 (0)