Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minimize frame skip so FPS will be calculated ASAP #13658

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions common/rendering.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ namespace rs2
fps_calc()
: _counter(0),
_delta(0),
_last_timestamp(0),
_num_of_frames(0)
_last_timestamp(0.0),
_num_of_frames(0),
_skip_frames(0),//initialiy set to zero in order to minimize the time where _delta and _num_of_frames are uninitialized and the display on screen will be NA.
_last_frame_counter(0)
{}

fps_calc(const fps_calc& other)
Expand All @@ -75,10 +77,11 @@ namespace rs2
std::lock_guard<std::mutex> lock(_mtx);
if (++_counter >= _skip_frames)
{
if (_last_timestamp != 0)
if (_last_timestamp > std::numeric_limits<double>::epsilon() && frame_counter > _last_frame_counter)
Nir-Az marked this conversation as resolved.
Show resolved Hide resolved
{
_delta = timestamp - _last_timestamp;
_num_of_frames = frame_counter - _last_frame_counter;
_skip_frames = _skip_frames_default;// now that _delta and _num_of_frames are initialized we can recover to default value.
}

_last_frame_counter = frame_counter;
Expand All @@ -90,15 +93,16 @@ namespace rs2
double get_fps() const
{
std::lock_guard<std::mutex> lock(_mtx);
if (_delta == 0)
if (_delta < std::numeric_limits<double>::epsilon())
return 0;

return (static_cast<double>(_numerator) * _num_of_frames) / _delta;
}

private:
static const int _numerator = 1000;
static const int _skip_frames = 5;
static const int _skip_frames_default = 5;
int _skip_frames;
Nir-Az marked this conversation as resolved.
Show resolved Hide resolved
int _counter;
double _delta;
double _last_timestamp;
Expand Down
7 changes: 5 additions & 2 deletions common/stream-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -847,11 +847,14 @@ namespace rs2
stream_details.push_back(
{ "Pixel Format", rsutils::string::from() << rs2_format_to_string( profile.format() ), "" } );

double fps_tmp = fps.get_fps();
Nir-Az marked this conversation as resolved.
Show resolved Hide resolved
std::string fps_value = (fps_tmp > 0) ? (rsutils::string::from() << std::setprecision(2) << std::fixed << fps_tmp).str() : std::string("--");

stream_details.push_back(
{ "Hardware FPS",
rsutils::string::from() << std::setprecision( 2 ) << std::fixed << fps.get_fps(),
fps_value,
"Hardware FPS captures the number of frames per second produced by the device.\n"
"It is possible and likely that not all of these frames will make it to the application." } );
"It is possible and likely that not all of these frames will make it to the application." });

stream_details.push_back(
{ "Viewer FPS",
Expand Down
Loading