Skip to content

Commit

Permalink
metadata values changes from map to multimap
Browse files Browse the repository at this point in the history
  • Loading branch information
remibettan committed Feb 17, 2021
1 parent f2c027b commit cfe686c
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 49 deletions.
42 changes: 34 additions & 8 deletions src/archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,33 @@ namespace librealsense
if (!metadata_parsers)
throw invalid_value_exception(to_string() << "metadata not available for "
<< get_string(get_stream()->get_stream_type()) << " stream");

auto it = metadata_parsers.get()->find(frame_metadata);
if (it == metadata_parsers.get()->end()) // Possible user error - md attribute is not supported by this frame type
auto parsers = metadata_parsers->equal_range(frame_metadata);
if (parsers.first == metadata_parsers->end()) // Possible user error - md attribute is not supported by this frame type
throw invalid_value_exception(to_string() << get_string(frame_metadata)
<< " attribute is not applicable for "
<< get_string(get_stream()->get_stream_type()) << " stream ");

// Proceed to parse and extract the required data attribute
return it->second->get(*this);
rs2_metadata_type result = -1;
bool value_retreived = false;
std::string exc_str;
for (auto it = parsers.first; it != parsers.second; ++it)
{
try
{
result = it->second->get(*this);
value_retreived = true;
break;
}
catch (invalid_value_exception& e)
{
exc_str = e.what();
}
}
if (!value_retreived)
throw invalid_value_exception(exc_str);

return result;
}

bool frame::supports_frame_metadata(const rs2_frame_metadata_value& frame_metadata) const
Expand All @@ -235,11 +253,19 @@ namespace librealsense
if (!metadata_parsers)
return false; // No parsers are available or no metadata was attached

auto it = metadata_parsers.get()->find(frame_metadata);
if (it == metadata_parsers.get()->end()) // Possible user error - md attribute is not supported by this frame type
bool ret = false;
auto found = metadata_parsers->equal_range(frame_metadata);
if (found.first == metadata_parsers->end())
return false;

return it->second->supports(*this);
for (auto it = found.first; it != found.second; ++it)
if (it->second->supports(*this))
{
ret = true;
break;
}

return ret;
}

int frame::get_frame_data_size() const
Expand Down
2 changes: 1 addition & 1 deletion src/archive.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace librealsense
class md_attribute_parser_base;
class frame;

typedef std::map<rs2_frame_metadata_value, std::shared_ptr<md_attribute_parser_base>> metadata_parser_map;
typedef std::multimap<rs2_frame_metadata_value, std::shared_ptr<md_attribute_parser_base>> metadata_parser_map;

/*
Each frame is attached with a static header
Expand Down
68 changes: 34 additions & 34 deletions src/ds5/ds5-color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ namespace librealsense
{
color_ep.register_pu(RS2_OPTION_AUTO_EXPOSURE_PRIORITY);
}

auto gain_option = std::make_shared<uvc_pu_option>(raw_color_ep, RS2_OPTION_GAIN);
auto exposure_option = std::make_shared<uvc_pu_option>(raw_color_ep, RS2_OPTION_EXPOSURE);
auto auto_exposure_option = std::make_shared<uvc_pu_option>(raw_color_ep, RS2_OPTION_ENABLE_AUTO_EXPOSURE);
Expand All @@ -169,51 +169,51 @@ namespace librealsense
std::make_shared<auto_disabling_control>(
gain_option,
auto_exposure_option));
}

color_ep.register_metadata(RS2_FRAME_METADATA_FRAME_TIMESTAMP, make_uvc_header_parser(&platform::uvc_header::timestamp));
color_ep.register_metadata(RS2_FRAME_METADATA_ACTUAL_FPS, std::make_shared<ds5_md_attribute_actual_fps>(false, [](const rs2_metadata_type& param)
{return param * 100; })); //the units of the exposure of the RGB sensor are 100 microseconds so the md_attribute_actual_fps need the lambda to convert it to microseconds

color_ep.register_metadata(RS2_FRAME_METADATA_FRAME_TIMESTAMP, make_uvc_header_parser(&platform::uvc_header::timestamp));
color_ep.register_metadata(RS2_FRAME_METADATA_ACTUAL_FPS, std::make_shared<ds5_md_attribute_actual_fps>(false, [](const rs2_metadata_type& param)
{return param * 100; })); //the units of the exposure of the RGB sensor are 100 microseconds so the md_attribute_actual_fps need the lambda to convert it to microseconds

// attributes of md_capture_timing
auto md_prop_offset = offsetof(metadata_raw, mode) +
offsetof(md_rgb_mode, rgb_mode) +
offsetof(md_rgb_normal_mode, intel_capture_timing);
// attributes of md_capture_timing
auto md_prop_offset = offsetof(metadata_raw, mode) +
offsetof(md_rgb_mode, rgb_mode) +
offsetof(md_rgb_normal_mode, intel_capture_timing);

color_ep.register_metadata(RS2_FRAME_METADATA_FRAME_COUNTER, make_attribute_parser(&md_capture_timing::frame_counter, md_capture_timing_attributes::frame_counter_attribute, md_prop_offset));
color_ep.register_metadata(RS2_FRAME_METADATA_SENSOR_TIMESTAMP, make_rs400_sensor_ts_parser(make_uvc_header_parser(&platform::uvc_header::timestamp),
make_attribute_parser(&md_capture_timing::sensor_timestamp, md_capture_timing_attributes::sensor_timestamp_attribute, md_prop_offset)));
color_ep.register_metadata(RS2_FRAME_METADATA_FRAME_COUNTER, make_attribute_parser(&md_capture_timing::frame_counter, md_capture_timing_attributes::frame_counter_attribute, md_prop_offset));
color_ep.register_metadata(RS2_FRAME_METADATA_SENSOR_TIMESTAMP, make_rs400_sensor_ts_parser(make_uvc_header_parser(&platform::uvc_header::timestamp),
make_attribute_parser(&md_capture_timing::sensor_timestamp, md_capture_timing_attributes::sensor_timestamp_attribute, md_prop_offset)));

// Starting with firmware 5.10.9, auto-exposure ROI is available for color sensor
if (_fw_version >= firmware_version("5.10.9.0"))
{
roi_sensor_interface* roi_sensor;
if ((roi_sensor = dynamic_cast<roi_sensor_interface*>(&color_ep)))
roi_sensor->set_roi_method(std::make_shared<ds5_auto_exposure_roi_method>(*_hw_monitor, ds::fw_cmd::SETRGBAEROI));
}
// Starting with firmware 5.10.9, auto-exposure ROI is available for color sensor
if (_fw_version >= firmware_version("5.10.9.0"))
{
roi_sensor_interface* roi_sensor;
if ((roi_sensor = dynamic_cast<roi_sensor_interface*>(&color_ep)))
roi_sensor->set_roi_method(std::make_shared<ds5_auto_exposure_roi_method>(*_hw_monitor, ds::fw_cmd::SETRGBAEROI));
}

// attributes of md_rgb_control
md_prop_offset = offsetof(metadata_raw, mode) +
offsetof(md_rgb_mode, rgb_mode) +
offsetof(md_rgb_normal_mode, intel_rgb_control);
// attributes of md_rgb_control
md_prop_offset = offsetof(metadata_raw, mode) +
offsetof(md_rgb_mode, rgb_mode) +
offsetof(md_rgb_normal_mode, intel_rgb_control);

color_ep.register_metadata(RS2_FRAME_METADATA_GAIN_LEVEL, make_attribute_parser(&md_rgb_control::gain, md_rgb_control_attributes::gain_attribute, md_prop_offset));
color_ep.register_metadata(RS2_FRAME_METADATA_ACTUAL_EXPOSURE, make_attribute_parser(&md_rgb_control::manual_exp, md_rgb_control_attributes::manual_exp_attribute, md_prop_offset));
color_ep.register_metadata(RS2_FRAME_METADATA_AUTO_EXPOSURE, make_attribute_parser(&md_rgb_control::ae_mode, md_rgb_control_attributes::ae_mode_attribute, md_prop_offset,
[](rs2_metadata_type param) { return (param != 1); }));
color_ep.register_metadata(RS2_FRAME_METADATA_GAIN_LEVEL, make_attribute_parser(&md_rgb_control::gain, md_rgb_control_attributes::gain_attribute, md_prop_offset));
color_ep.register_metadata(RS2_FRAME_METADATA_ACTUAL_EXPOSURE, make_attribute_parser(&md_rgb_control::manual_exp, md_rgb_control_attributes::manual_exp_attribute, md_prop_offset));
color_ep.register_metadata(RS2_FRAME_METADATA_AUTO_EXPOSURE, make_attribute_parser(&md_rgb_control::ae_mode, md_rgb_control_attributes::ae_mode_attribute, md_prop_offset,
[](rs2_metadata_type param) { return (param != 1); }));

// attributes of md_capture_stats
md_prop_offset = offsetof(metadata_raw, mode) +
offsetof(md_rgb_mode, rgb_mode) +
offsetof(md_rgb_normal_mode, intel_capture_stats);
// attributes of md_capture_stats
md_prop_offset = offsetof(metadata_raw, mode) +
offsetof(md_rgb_mode, rgb_mode) +
offsetof(md_rgb_normal_mode, intel_capture_stats);

color_ep.register_metadata(RS2_FRAME_METADATA_WHITE_BALANCE, make_attribute_parser(&md_capture_stats::white_balance, md_capture_stat_attributes::white_balance_attribute, md_prop_offset));
color_ep.register_metadata(RS2_FRAME_METADATA_WHITE_BALANCE, make_attribute_parser(&md_capture_stats::white_balance, md_capture_stat_attributes::white_balance_attribute, md_prop_offset));

}



// attributes of md_rgb_control
auto md_prop_offset = offsetof(metadata_raw, mode) +
md_prop_offset = offsetof(metadata_raw, mode) +
offsetof(md_rgb_mode, rgb_mode) +
offsetof(md_rgb_normal_mode, intel_rgb_control);

Expand Down
1 change: 0 additions & 1 deletion src/ds5/ds5-nonmonochrome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ namespace librealsense
depth_ep.register_processing_block({ {RS2_FORMAT_BGR8} }, { {RS2_FORMAT_RGB8, RS2_STREAM_INFRARED} }, []() { return std::make_shared<bgr_to_rgb>(); });
}

depth_ep.register_processing_block(processing_block_factory::create_pbf_vector<yuy2_converter>(RS2_FORMAT_YUYV, map_supported_color_formats(RS2_FORMAT_YUYV), RS2_STREAM_INFRARED));
depth_ep.register_processing_block(processing_block_factory::create_pbf_vector<uyvy_converter>(RS2_FORMAT_UYVY, map_supported_color_formats(RS2_FORMAT_UYVY), RS2_STREAM_INFRARED));

if (RS455_PID != pid && RS405_PID != pid)
Expand Down
9 changes: 6 additions & 3 deletions src/sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,12 @@ namespace librealsense
void sensor_base::register_metadata(rs2_frame_metadata_value metadata, std::shared_ptr<md_attribute_parser_base> metadata_parser) const
{
if (_metadata_parsers.get()->end() != _metadata_parsers.get()->find(metadata))
throw invalid_value_exception(to_string() << "Metadata attribute parser for " << rs2_frame_metadata_to_string(metadata)
<< " is already defined");

{
std::string metadata_type_str(rs2_frame_metadata_to_string(metadata));
std::string metadata_found_str = "Metadata attribute parser for " + metadata_type_str + " is already defined";
LOG_INFO(metadata_found_str.c_str());
}

_metadata_parsers.get()->insert(std::pair<rs2_frame_metadata_value, std::shared_ptr<md_attribute_parser_base>>(metadata, metadata_parser));
}

Expand Down
4 changes: 2 additions & 2 deletions src/tm2/tm-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ namespace librealsense
register_metadata(RS2_FRAME_METADATA_ACTUAL_EXPOSURE, std::make_shared<md_tm2_parser>(RS2_FRAME_METADATA_ACTUAL_EXPOSURE));
register_metadata(RS2_FRAME_METADATA_TEMPERATURE , std::make_shared<md_tm2_parser>(RS2_FRAME_METADATA_TEMPERATURE));
//Replacing md parser for RS2_FRAME_METADATA_TIME_OF_ARRIVAL
_metadata_parsers->operator[](RS2_FRAME_METADATA_TIME_OF_ARRIVAL) = std::make_shared<md_tm2_parser>(RS2_FRAME_METADATA_TIME_OF_ARRIVAL);
_metadata_parsers->operator[](RS2_FRAME_METADATA_FRAME_TIMESTAMP) = std::make_shared<md_tm2_parser>(RS2_FRAME_METADATA_FRAME_TIMESTAMP);
_metadata_parsers->find(RS2_FRAME_METADATA_TIME_OF_ARRIVAL)->second = std::make_shared<md_tm2_parser>(RS2_FRAME_METADATA_TIME_OF_ARRIVAL);
_metadata_parsers->find(RS2_FRAME_METADATA_FRAME_TIMESTAMP)->second = std::make_shared<md_tm2_parser>(RS2_FRAME_METADATA_FRAME_TIMESTAMP);

// Set log level
bulk_message_request_log_control log_request = {{ sizeof(log_request), DEV_LOG_CONTROL }};
Expand Down

0 comments on commit cfe686c

Please sign in to comment.