Skip to content

Commit

Permalink
remove actual_fps_calculator in favor of frame::calc_actual_fps
Browse files Browse the repository at this point in the history
  • Loading branch information
maloel committed Oct 26, 2023
1 parent 337eba1 commit 96bcbaa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 29 deletions.
21 changes: 21 additions & 0 deletions src/frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,27 @@ unsigned long long frame::get_frame_number() const
return additional_data.frame_number;
}

double frame::calc_actual_fps() const
{
// 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
auto num_of_frames
= additional_data.frame_number ? additional_data.frame_number - additional_data.last_frame_number : 0;

if( num_of_frames == 0 )
{
LOG_INFO( "Frame counter reset" );
}
else
{
auto diff = ( additional_data.timestamp - additional_data.last_timestamp ) / (double)num_of_frames;
if( diff > 0 )
return std::max( 1000. / diff, 1. );
}

return get_stream()->get_framerate();
}

rs2_time_t frame::get_frame_system_time() const
{
return additional_data.system_time;
Expand Down
2 changes: 2 additions & 0 deletions src/frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class LRS_EXTENSION_API frame : public frame_interface
additional_data.timestamp_domain = timestamp_domain;
}

double calc_actual_fps() const;

rs2_time_t get_frame_system_time() const override;

std::shared_ptr< stream_profile_interface > get_stream() const override { return stream; }
Expand Down
30 changes: 1 addition & 29 deletions src/metadata-parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,40 +342,12 @@ namespace librealsense
};


class actual_fps_calculator
{
public:
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
auto num_of_frames = frm.additional_data.frame_number
? frm.additional_data.frame_number - frm.additional_data.last_frame_number
: 0;

if (num_of_frames == 0)
{
LOG_INFO("Frame counter reset");
}
else
{
auto diff
= ( frm.additional_data.timestamp - frm.additional_data.last_timestamp ) / (double)num_of_frames;
if( diff > 0 )
return std::max( 1000. / diff, 1. );
}

return frm.get_stream()->get_framerate();
}
};


class ds_md_attribute_actual_fps : public md_attribute_parser_base
{
public:
rs2_metadata_type get( const librealsense::frame & frm ) const override
{
return rs2_metadata_type( actual_fps_calculator::get_fps( frm ) * 1000 );
return rs2_metadata_type( frm.calc_actual_fps() * 1000 );
}

bool supports(const librealsense::frame & frm) const override
Expand Down

0 comments on commit 96bcbaa

Please sign in to comment.