44 if (try_get(frm, v) ==
false)
53 return try_get(frm, v);
58 auto md_parser_map = std::make_shared<metadata_parser_map>();
62 md_parser_map->insert(std::make_pair(frame_md_type, std::make_shared<md_constant_parser>(frame_md_type)));
77 memcpy((
void*)&result, (
const void*)value,
sizeof(*value));
90 typedef std::function<rs2_metadata_type(const rs2_metadata_type& param)>
attrib_modifyer;
110 template<
class S,
class Attribute,
typename Flag>
115 _md_attribute(attribute_name), _md_flag(flag), _offset(offset), _modifyer(mod) {};
119 auto s =
reinterpret_cast<const S*
>(((
const uint8_t*)frm.additional_data.metadata_blob.data()) + _offset);
121 if (!is_attribute_valid(
s))
125 if (_modifyer) attrib = _modifyer(attrib);
134 return is_attribute_valid(
s);
146 if ((s->header.md_type_id != expected_type) || (s->header.md_size <
sizeof(*s)))
150 <<
"0x" << std::hex << static_cast<uint32_t>(s->header.md_type_id) << std::dec);
151 LOG_DEBUG(
"Metadata mismatch - actual: " << type
152 <<
", expected: 0x" << std::hex << (
uint32_t)expected_type << std::dec <<
" (" <<
md_type_desc.at(expected_type) <<
")");
157 auto attribute_enabled = (0 !=(s->flags &
static_cast<uint32_t>(_md_flag)));
158 if (!attribute_enabled)
159 LOG_DEBUG(
"Metadata attribute No: "<< (*s.*_md_attribute) <<
"is not active");
161 return attribute_enabled;
176 template<
class S,
class Attribute,
typename Flag>
184 template<
class St,
class Attribute>
189 _md_attribute(attribute_name), _modifyer(mod){};
196 auto attrib =
static_cast<rs2_metadata_type>((*
reinterpret_cast<const St*
>((
const uint8_t*)frm.additional_data.metadata_blob.data())).*_md_attribute);
197 if (_modifyer) attrib = _modifyer(attrib);
213 template<
class St,
class Attribute>
221 template<
class St,
class Attribute>
226 _md_attribute(attribute_name), _modifyer(mod) {};
233 auto attrib =
static_cast<rs2_metadata_type>((*
reinterpret_cast<const St*
>((
const uint8_t*)frm.additional_data.metadata_blob.data())).*_md_attribute);
234 attrib &= 0x00000000ffffffff;
235 if (_modifyer) attrib = _modifyer(attrib);
253 template<
class St,
class Attribute>
261 template<
class St,
class Attribute>
266 _md_attribute(attribute_name) {};
284 template<
class St,
class Attribute>
294 std::shared_ptr<md_attribute_parser_base> _sensor_ts_parser =
nullptr;
295 std::shared_ptr<md_attribute_parser_base> _frame_ts_parser =
nullptr;
299 std::shared_ptr<md_attribute_parser_base> frame_ts_parser) :
300 _sensor_ts_parser(sensor_ts_parser), _frame_ts_parser(frame_ts_parser) {};
308 return _frame_ts_parser->get(frm) - _sensor_ts_parser->get(frm);
313 return (_sensor_ts_parser->supports(frm) && _frame_ts_parser->supports(frm));
327 if (num_of_frames == 0)
333 return diff > 0 ? std::max(1000.
f / std::ceil(diff), (
double)1) : frm.
get_stream()->get_framerate();
342 : _fps_values{ 6, 15, 30, 60, 90 } , _exposure_modifyer(exposure_mod), _discrete(discrete)
352 if (
std::find(_fps_values.begin(), _fps_values.end(), 25) == _fps_values.end())
354 _fps_values.push_back(25);
355 std::sort(_fps_values.begin(), _fps_values.end());
362 auto exp_in_micro = _exposure_modifyer(exp);
363 if (exp_in_micro > 0)
365 auto fps = 1000000.f / exp_in_micro;
369 if (
fps >= _fps_values.back())
371 fps =
static_cast<float>(_fps_values.back());
375 for (
size_t i = 0;
i < _fps_values.size() - 1;
i++)
377 if (
fps < _fps_values[
i + 1])
379 fps =
static_cast<float>(_fps_values[
i]);
385 return std::min((
int)
fps, (
int)frm.get_stream()->get_framerate());
407 std::shared_ptr<md_attribute_parser_base> sensor_ts_parser)
414 template<
class S,
class Attribute>
419 _md_attribute(attribute_name), _offset(offset), _modifyer(mod){};
426 auto s =
reinterpret_cast<const S*
>((frm.additional_data.metadata_blob.data()) + _offset);
451 template<
class S,
class Attribute>
std::shared_ptr< stream_profile_interface > get_stream() const override
std::shared_ptr< md_attribute_parser_base > make_rs400_sensor_ts_parser(std::shared_ptr< md_attribute_parser_base > frame_ts_parser, std::shared_ptr< md_attribute_parser_base > sensor_ts_parser)
A helper function to create a specialized parser for RS4xx sensor timestamp.
double get_fps(const librealsense::frame &frm)
metadata parser class - support metadata in format: rs2_frame_metadata_value, rs2_metadata_type ...
Base class that establishes the interface for retrieving metadata attributes.
bool try_get(const frame &frm, rs2_metadata_type &result) const
ds5_md_attribute_actual_fps(bool discrete=true, attrib_modifyer exposure_mod=[](const rs2_metadata_type ¶m){return param;})
md_rs400_sensor_timestamp(std::shared_ptr< md_attribute_parser_base > sensor_ts_parser, std::shared_ptr< md_attribute_parser_base > frame_ts_parser)
The metadata parser class directly access the metadata attribute in the blob received from HW...
Optical timestamp for RS4xx devices is calculated internally.
unsigned long long _offset
bool supports(const librealsense::frame &frm) const override
attrib_modifyer _modifyer
md_additional_parser(Attribute St::*attribute_name)
static const std::map< md_type, std::string > md_type_desc
GLsizei const GLchar *const * string
rs2_time_t last_timestamp
bool supports(const librealsense::frame &frm) const override
void sort(sort_type m_sort_type, const std::string &in, const std::string &out)
virtual bool supports(const frame &frm) const =0
frame_additional_data additional_data
virtual ~md_attribute_parser_base()=default
std::function< rs2_metadata_type(const rs2_metadata_type ¶m)> attrib_modifyer
Post-processing adjustment of the metadata attribute e.g change auto_exposure enum to boolean...
Attribute St::* _md_attribute
provide attributes generated and stored internally by the library
md_attribute_parser(Attribute S::*attribute_name, Flag flag, unsigned long long offset, attrib_modifyer mod)
actual_fps_calculator _fps_calculator
unsigned long long frame_number
md_type
md_mode - enumerates the types of metadata modes(structs) supported
unsigned long long _offset
std::shared_ptr< md_attribute_parser_base > make_uvc_header_parser(Attribute St::*attribute, attrib_modifyer mod=nullptr)
A utility function to create UVC metadata header parser.
The SR300 metadata parser class.
virtual ~md_rs400_sensor_timestamp()
bool is_attribute_valid(const S *s) const
Attribute S::* _md_attribute
LOG_INFO("Log message using LOG_INFO()")
bool supports(const librealsense::frame &frm) const override
std::shared_ptr< md_attribute_parser_base > make_attribute_parser(Attribute S::*attribute, Flag flag, unsigned long long offset, attrib_modifyer mod=nullptr)
A helper function to create a specialized attribute parser. Return it as a pointer to a base-class...
bool supports(const frame &frm) const override
long long rs2_metadata_type
rs2_frame_metadata_value _type
attrib_modifyer _modifyer
md_constant_parser(rs2_frame_metadata_value type)
attrib_modifyer _exposure_modifyer
Attribute S::* _md_attribute
static std::shared_ptr< metadata_parser_map > create_metadata_parser_map()
std::shared_ptr< md_attribute_parser_base > make_additional_data_parser(Attribute St::*attribute)
A utility function to create additional_data parser.
frame_metadata_internal
Metadata fields that are utilized internally by librealsense Provides extention to the r2_frame_metad...
bool supports(const librealsense::frame &frm) const override
std::array< uint8_t, MAX_META_DATA_SIZE > metadata_blob
bool supports(const librealsense::frame &frm) const override
std::vector< uint32_t > _fps_values
std::shared_ptr< md_attribute_parser_base > make_sr300_attribute_parser(Attribute S::*attribute, unsigned long long offset, attrib_modifyer mod=nullptr)
A helper function to create a specialized attribute parser. Return it as a pointer to a base-class...
std::shared_ptr< md_attribute_parser_base > make_hid_header_parser(Attribute St::*attribute, attrib_modifyer mod=nullptr)
A utility function to create HID metadata header parser.
md_sr300_attribute_parser(Attribute S::*attribute_name, unsigned long long offset, attrib_modifyer mod)
rs2_frame_metadata_value
Per-Frame-Metadata is the set of read-only properties that might be exposed for each individual frame...
bool supports(const frame &frm) const override
unsigned long long last_frame_number
std::string to_string(T value)