Skip to content

Commit

Permalink
remove exposure & discrete value handling in actual FPS calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
maloel committed Oct 26, 2023
1 parent 6e92eb5 commit 337eba1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 57 deletions.
3 changes: 1 addition & 2 deletions src/ds/ds-color-common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ namespace librealsense
void ds_color_common::register_metadata()
{
_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<ds_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_ACTUAL_FPS, std::make_shared<ds_md_attribute_actual_fps>());

// attributes of md_capture_timing
auto md_prop_offset = offsetof(metadata_raw, mode) +
Expand Down
58 changes: 3 additions & 55 deletions src/metadata-parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ namespace librealsense
class actual_fps_calculator
{
public:
double get_fps(const librealsense::frame & frm)
static double get_fps( const librealsense::frame & frm )
{
// A computation involving unsigned operands can never overflow (ISO/IEC 9899:1999 (E) \A76.2.5/9)
// In case of frame counter reset fallback use fps from the stream configuration
Expand Down Expand Up @@ -373,67 +373,15 @@ namespace librealsense
class ds_md_attribute_actual_fps : public md_attribute_parser_base
{
public:
ds_md_attribute_actual_fps(bool discrete = true, attrib_modifyer exposure_mod = [](const rs2_metadata_type& param) {return param; })
: _fps_values{ 6, 15, 30, 60, 90 } , _exposure_modifyer(exposure_mod), _discrete(discrete)
{}

rs2_metadata_type get(const librealsense::frame & frm) const override
rs2_metadata_type get( const librealsense::frame & frm ) const override
{
if (frm.supports_frame_metadata(RS2_FRAME_METADATA_ACTUAL_EXPOSURE))
{
if (frm.get_stream()->get_format() == RS2_FORMAT_Y16 &&
frm.get_stream()->get_stream_type() == RS2_STREAM_INFRARED) //calibration mode
{
if (std::find(_fps_values.begin(), _fps_values.end(), 25) == _fps_values.end())
{
_fps_values.push_back(25);
std::sort(_fps_values.begin(), _fps_values.end());
}

}

auto exp = frm.get_frame_metadata(RS2_FRAME_METADATA_ACTUAL_EXPOSURE);

auto exp_in_micro = _exposure_modifyer(exp);
if (exp_in_micro > 0)
{
auto fps = 1000000. / exp_in_micro;

if (_discrete)
{
if (fps >= _fps_values.back())
{
fps = static_cast<double>(_fps_values.back());
}
else
{
for (size_t i = 0; i < _fps_values.size() - 1; i++)
{
if (fps < _fps_values[i + 1])
{
fps = static_cast<double>(_fps_values[i]);
break;
}
}
}
}
return rs2_metadata_type( std::min( fps, (double)frm.get_stream()->get_framerate() ) * 1000 );
}
}

return rs2_metadata_type( _fps_calculator.get_fps( frm ) * 1000 );
return rs2_metadata_type( actual_fps_calculator::get_fps( frm ) * 1000 );
}

bool supports(const librealsense::frame & frm) const override
{
return true;
}

private:
mutable actual_fps_calculator _fps_calculator;
mutable std::vector<uint32_t> _fps_values;
attrib_modifyer _exposure_modifyer;
bool _discrete;
};

/**\brief A helper function to create a specialized parser for RS4xx sensor timestamp*/
Expand Down

0 comments on commit 337eba1

Please sign in to comment.