Skip to content

Commit

Permalink
Merge pull request #300 from odin-detector/299_live_view_rate_calc
Browse files Browse the repository at this point in the history
Fix elapsed time calculation in live view rate settiing.

Fixes #299
  • Loading branch information
timcnicholls authored Jun 14, 2022
2 parents 4236024 + c3ed32f commit 638e8ad
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
4 changes: 3 additions & 1 deletion frameProcessor/include/LiveViewPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ class LiveViewPlugin : public FrameProcessorPlugin{


/**time between frames in milliseconds, calculated from the per_second config*/
int32_t time_between_frames_;
//int32_t time_between_frames_;
boost::posix_time::time_duration time_between_frames_;

/**time the last frame was shown*/
boost::posix_time::ptime time_last_frame_;

Expand Down
33 changes: 24 additions & 9 deletions frameProcessor/src/LiveViewPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,36 @@ void LiveViewPlugin::process_frame(boost::shared_ptr<Frame> frame)
}
}
}

// If the frame is tagged or the tag filter is inactive, test if the rate and frequency
// conditions are set to pass the frame to clients
if (!tag_filter_active || is_tagged)
{
boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time();
int32_t elapsed_time = (now - time_last_frame_).total_milliseconds();
bool pass_frame = false;

if (per_second_ != 0 && elapsed_time > time_between_frames_) //time between frames too large, showing frame no matter what the frame number is
// If the per-second rate setting is active, check time since last live view frame sent
if (per_second_ != 0)
{
LOG4CXX_TRACE(logger_, "Elapsed time " << elapsed_time << " > " << time_between_frames_);
pass_live_frame(frame);
boost::posix_time::time_duration elapsed = (boost::posix_time::microsec_clock::local_time() - time_last_frame_);
if (elapsed > time_between_frames_)
{
LOG4CXX_TRACE(logger_, "Frame " << frame->get_frame_number() << " elapsed time " << elapsed << " > " << time_between_frames_);
pass_frame = true;
}
}
else if (frame_freq_ != 0 && frame_count_ % frame_freq_ == 0)

// If the frame frequency setting is active, check if this frame should be sent
if (frame_freq_ != 0 && frame_count_ % frame_freq_ == 0)
{
LOG4CXX_TRACE(logger_, "LiveViewPlugin Frame " << frame->get_frame_number() << " to be displayed.");
LOG4CXX_TRACE(logger_, "Frame " << frame->get_frame_number() << " count matches frequency " << frame_freq_);
pass_frame = true;
}

// Pass the frame to live view clients if one of the conditions above has been met
if (pass_frame) {
pass_live_frame(frame);
}

//Count all frames that match the dataset(s) and tag(s)
frame_count_ ++;
}
Expand All @@ -115,7 +130,7 @@ void LiveViewPlugin::process_frame(boost::shared_ptr<Frame> frame)
{
LOG4CXX_WARN(logger_, "Socket is unbound. Check if address " << image_view_socket_addr_ << " is in use.");
}

LOG4CXX_TRACE(logger_, "Pushing Data Frame" );
this->push(frame);
}
Expand Down Expand Up @@ -329,7 +344,7 @@ void LiveViewPlugin::set_per_second_config(int32_t value)
else
{
LOG4CXX_INFO(logger_, "Displaying " << per_second_ << " frames per second");
time_between_frames_ = 1000 / per_second_;
time_between_frames_ = boost::posix_time::milliseconds(1000 / per_second_);
}
}
/**
Expand Down

0 comments on commit 638e8ad

Please sign in to comment.