Skip to content

Commit

Permalink
More robust fps estimation.
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanFabian committed Jul 30, 2021
1 parent 7da46ce commit d9e04ab
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/qml_ros_plugin/helpers/rolling_average.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class RollingAverage
void add( const T &value )
{
if (count_values_ == COUNT) sum_ -= values_[index_];
else ++count_values_;
values_[index_] = value;
sum_ += value;
if ( ++index_ == COUNT ) index_ = 0;
if (count_values_ != COUNT) ++count_values_;
}

T value() const { return count_values_ == 0 ? 0 : sum_ / count_values_; }
Expand Down
6 changes: 3 additions & 3 deletions src/image_transport_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,13 @@ Q_OBJECT
network_latency_average_.add( network_latency );
int processing_latency = static_cast<int>((ros::Time::now() - received).toSec() * 1000);
processing_latency_average_.add( processing_latency );
if ( base_interval > 0 ) framerate_average_.add( 1000.0 / base_interval );
image_interval_average_.add(base_interval);
for ( const auto &sub : subscribers )
{
if ( sub == nullptr || !sub->callback ) continue;
sub->network_latency = network_latency_average_;
sub->processing_latency = processing_latency_average_;
sub->framerate_ = std::round(framerate_average_ * 10) / 10;
sub->framerate_ = std::round(1000.0 / image_interval_average_ * 10) / 10;
sub->callback( frame );
}
}
Expand Down Expand Up @@ -338,7 +338,7 @@ Q_OBJECT
std::vector<ImageTransportSubscriptionHandle *> subscriptions_;
std::vector<std::weak_ptr<ImageTransportSubscriptionHandle>> subscription_handles_;
QList<QVideoFrame::PixelFormat> supported_formats_;
RollingAverage<double, 10> framerate_average_;
RollingAverage<int, 10> image_interval_average_;
RollingAverage<int, 10> network_latency_average_;
RollingAverage<int, 10> processing_latency_average_;
ros::Time last_received_stamp_;
Expand Down

0 comments on commit d9e04ab

Please sign in to comment.