Skip to content

Commit a10e3dc

Browse files
authored
PR #13984 from OhadMeir: Convert mjpeg images to RGB8 for DDS streams
2 parents b36bc61 + 153f680 commit a10e3dc

File tree

4 files changed

+101
-35
lines changed

4 files changed

+101
-35
lines changed

src/core/matcher-factory.cpp

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,27 @@ std::shared_ptr< matcher > matcher_factory::create( rs2_matchers matcher,
3838

3939
std::shared_ptr< matcher > matcher_factory::create_DLR_C_matcher( std::vector< stream_interface * > const & profiles )
4040
{
41-
auto color = find_profile( RS2_STREAM_COLOR, 0, profiles );
42-
if( ! color )
41+
auto color = get_color_profiles( profiles );
42+
if( color.empty() )
4343
{
4444
LOG_DEBUG( "Created default matcher" );
4545
return create_timestamp_matcher( profiles );
4646
}
4747

48-
return create_timestamp_composite_matcher( { create_DLR_matcher( profiles ), create_identity_matcher( color ) } );
48+
return create_timestamp_composite_matcher( { create_DLR_matcher( profiles ), create_color_composite_matcher( color ) } );
4949
}
5050

5151

5252
std::shared_ptr< matcher > matcher_factory::create_DI_C_matcher( std::vector< stream_interface * > const & profiles )
5353
{
54-
auto color = find_profile( RS2_STREAM_COLOR, 0, profiles );
55-
if( ! color )
54+
auto color = get_color_profiles( profiles );
55+
if( color.empty() )
5656
{
5757
LOG_DEBUG( "Created default matcher" );
5858
return create_timestamp_matcher( profiles );
5959
}
6060

61-
return create_timestamp_composite_matcher( { create_DI_matcher( profiles ), create_identity_matcher( color ) } );
61+
return create_timestamp_composite_matcher( { create_DI_matcher( profiles ), create_color_composite_matcher( color ) } );
6262
}
6363

6464

@@ -115,11 +115,11 @@ std::shared_ptr< matcher > matcher_factory::create_DIC_matcher( std::vector< str
115115

116116
std::shared_ptr< matcher > matcher_factory::create_DIC_C_matcher( std::vector< stream_interface * > const & profiles )
117117
{
118-
auto color = find_profile( RS2_STREAM_COLOR, 0, profiles );
119-
if( ! color )
118+
auto color = get_color_profiles( profiles );
119+
if( color.empty() )
120120
throw std::runtime_error( "no color stream found for matcher" );
121121

122-
return create_timestamp_composite_matcher( { create_DIC_matcher( profiles ), create_identity_matcher( color ) } );
122+
return create_timestamp_composite_matcher( { create_DIC_matcher( profiles ), create_color_composite_matcher( color ) } );
123123
}
124124

125125

@@ -164,4 +164,33 @@ matcher_factory::create_timestamp_composite_matcher( std::vector< std::shared_pt
164164
}
165165

166166

167-
} // namespace librealsense
167+
std::vector< stream_interface * >
168+
matcher_factory::get_color_profiles( std::vector< stream_interface * > const & profiles )
169+
{
170+
// We need one profile per stream - matcher use only UID and type
171+
std::map< int, stream_interface * > color_profiles;
172+
for( auto & profile : profiles )
173+
if( profile->get_stream_type() == RS2_STREAM_COLOR )
174+
color_profiles[profile->get_stream_index()] = profile;
175+
176+
std::vector< stream_interface * > ret;
177+
for( auto & profile : color_profiles )
178+
ret.push_back( profile.second );
179+
180+
return ret;
181+
}
182+
183+
184+
std::shared_ptr< matcher >
185+
matcher_factory::create_color_composite_matcher( std::vector< stream_interface * > const & profiles )
186+
{
187+
std::vector< std::shared_ptr< matcher > > color_matchers;
188+
for( auto & profile : profiles )
189+
color_matchers.push_back( std::make_shared< identity_matcher >( profile->get_unique_id(),
190+
profile->get_stream_type() ) );
191+
192+
return create_frame_number_composite_matcher( color_matchers );
193+
}
194+
195+
196+
} // namespace librealsense

src/core/matcher-factory.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ class matcher_factory
3434
static std::shared_ptr< matcher > create_frame_number_matcher( std::vector< stream_interface * > const & profiles );
3535
static std::shared_ptr< matcher > create_timestamp_matcher( std::vector< stream_interface * > const & profiles );
3636

37+
static std::vector< stream_interface * > get_color_profiles( std::vector< stream_interface * > const & profiles );
38+
static std::shared_ptr< matcher >
39+
create_color_composite_matcher( std::vector< stream_interface * > const & profiles );
3740
static std::shared_ptr< matcher >
3841
create_timestamp_composite_matcher( std::vector< std::shared_ptr< matcher > > const & matchers );
3942
static std::shared_ptr< matcher >

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

Lines changed: 58 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ stream_profiles dds_sensor_proxy::init_stream_profiles()
9191
}
9292
else
9393
{
94-
register_basic_converters();
94+
register_converters();
9595
if( format_conversion::basic == format )
9696
_formats_converter.drop_non_basic_formats();
9797
profiles = _formats_converter.get_all_possible_profiles( profiles );
@@ -102,8 +102,27 @@ stream_profiles dds_sensor_proxy::init_stream_profiles()
102102
}
103103

104104

105-
void dds_sensor_proxy::register_basic_converters()
105+
void dds_sensor_proxy::register_converters()
106106
{
107+
// Some stream types have typicaly more then one stream, indexes must be used to differentiate them and needs to be
108+
// set in converter target profiles. Gather info for such stream types in one loop over all profiles.
109+
std::set< int > y8_indexes;
110+
std::set< int > y16_indexes;
111+
std::set< int > jpeg_indexes;
112+
for( auto & stream : streams() )
113+
{
114+
for( auto & profile : stream.second->profiles() )
115+
{
116+
if( auto vsp = std::dynamic_pointer_cast< realdds::dds_video_stream_profile >( profile ) )
117+
if( vsp->encoding().to_rs2() == RS2_FORMAT_Y8 )
118+
y8_indexes.insert( stream.first.index );
119+
else if( vsp->encoding().to_rs2() == RS2_FORMAT_Y16 )
120+
y16_indexes.insert( stream.first.index );
121+
else if( vsp->encoding().to_rs2() == RS2_FORMAT_MJPEG )
122+
jpeg_indexes.insert( stream.first.index );
123+
}
124+
}
125+
107126
// Color
108127
_formats_converter.register_converter( processing_block_factory::create_id_pbf( RS2_FORMAT_RGB8, RS2_STREAM_COLOR ) );
109128
_formats_converter.register_converter( processing_block_factory::create_id_pbf( RS2_FORMAT_RGBA8, RS2_STREAM_COLOR ) );
@@ -122,33 +141,48 @@ void dds_sensor_proxy::register_basic_converters()
122141
{ RS2_FORMAT_YUYV, RS2_FORMAT_RGB8, RS2_FORMAT_Y8, RS2_FORMAT_RGBA8, RS2_FORMAT_BGR8, RS2_FORMAT_BGRA8 },
123142
RS2_STREAM_COLOR ) );
124143

144+
if( jpeg_indexes.size() > 0 )
145+
{
146+
std::vector< stream_profile > target_profiles;
147+
for( int index : jpeg_indexes )
148+
target_profiles.push_back( { RS2_FORMAT_RGB8, RS2_STREAM_COLOR, index } );
149+
_formats_converter.register_converter( { { RS2_FORMAT_MJPEG, RS2_STREAM_COLOR } }, target_profiles,
150+
[]() { return std::make_shared< mjpeg_converter >( RS2_FORMAT_RGB8 ); } );
151+
}
152+
125153
// Depth
126154
_formats_converter.register_converter(
127155
processing_block_factory::create_id_pbf( RS2_FORMAT_Z16, RS2_STREAM_DEPTH ) );
128156

129157
// Infrared (converter source needs type to be handled properly by formats_converter)
130-
_formats_converter.register_converter(
131-
{ { { RS2_FORMAT_Y8, RS2_STREAM_INFRARED } },
132-
{ { RS2_FORMAT_Y8, RS2_STREAM_INFRARED, 0 },
133-
{ RS2_FORMAT_Y8, RS2_STREAM_INFRARED, 1 },
134-
{ RS2_FORMAT_Y8, RS2_STREAM_INFRARED, 2 } },
135-
[]() { return std::make_shared< identity_processing_block >(); } } );
136-
std::string product_line = get_device().get_info( RS2_CAMERA_INFO_PRODUCT_LINE );
137-
bool d400 = product_line.find("D400") != std::string::npos;
138-
_formats_converter.register_converter(
139-
{ { { RS2_FORMAT_Y16, RS2_STREAM_INFRARED } },
140-
{ { RS2_FORMAT_Y16, RS2_STREAM_INFRARED, 1 },
141-
{ RS2_FORMAT_Y16, RS2_STREAM_INFRARED, 2 } },
142-
[d400]() -> std::shared_ptr< stream_filter_processing_block >
143-
{
144-
// Y16 is calibration format, sent with 10bit data that needs conversion to 16bit.
145-
// D400 products don't have DDS so we use rs-dds-adapter that already converts.
146-
// Calibration with other products that use rs-dds-adapter is currently not supported.
147-
if( d400 )
148-
return std::make_shared< identity_processing_block >();
149-
150-
return std::make_shared< y16_10msb_to_y16 >();
151-
} } );
158+
if( y8_indexes.size() > 0 )
159+
{
160+
std::vector< stream_profile > target_profiles;
161+
for( int index : y8_indexes )
162+
target_profiles.push_back( { RS2_FORMAT_Y8, RS2_STREAM_INFRARED, index } );
163+
_formats_converter.register_converter( { { { RS2_FORMAT_Y8, RS2_STREAM_INFRARED } }, target_profiles,
164+
[]() { return std::make_shared< identity_processing_block >(); } } );
165+
}
166+
167+
if( y16_indexes.size() > 0 )
168+
{
169+
std::vector< stream_profile > target_profiles;
170+
for( int index : y16_indexes )
171+
target_profiles.push_back( { RS2_FORMAT_Y16, RS2_STREAM_INFRARED, index } );
172+
std::string product_line = get_device().get_info( RS2_CAMERA_INFO_PRODUCT_LINE );
173+
bool d400 = product_line.find("D400") != std::string::npos;
174+
_formats_converter.register_converter( { { { RS2_FORMAT_Y16, RS2_STREAM_INFRARED } }, target_profiles,
175+
[d400]() -> std::shared_ptr< stream_filter_processing_block >
176+
{
177+
// Y16 is calibration format, sent with 10bit data that needs conversion to 16bit.
178+
// D400 products don't have DDS so we use rs-dds-adapter that already converts.
179+
// Calibration with other products that use rs-dds-adapter is currently not supported.
180+
if( d400 )
181+
return std::make_shared< identity_processing_block >();
182+
183+
return std::make_shared< y16_10msb_to_y16 >();
184+
} } );
185+
}
152186

153187
// Motion
154188
_formats_converter.register_converter( processing_block_factory::create_id_pbf( RS2_FORMAT_COMBINED_MOTION, RS2_STREAM_MOTION ) );

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class dds_sensor_proxy : public software_sensor
9494
stream_profiles get_active_streams() const override;
9595

9696
protected:
97-
void register_basic_converters();
97+
void register_converters();
9898
stream_profiles init_stream_profiles() override;
9999

100100
std::shared_ptr< realdds::dds_video_stream_profile >

0 commit comments

Comments
 (0)