Skip to content

Commit

Permalink
change syncer behavior to release earlier frames if better sync can b…
Browse files Browse the repository at this point in the history
…e made
  • Loading branch information
maloel committed Nov 2, 2023
1 parent 0c6ef6f commit 1290a18
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
63 changes: 62 additions & 1 deletion src/sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ namespace librealsense
[]( frame_holder const & fh )
{
// If queues are overrun, we'll get here
LOG_DEBUG( "DROPPED frame " << fh );
LOG_ERROR( "DROPPED frame " << fh );
} )
{
}
Expand Down Expand Up @@ -415,6 +415,56 @@ namespace librealsense
continue;
}

// If all the synced frames have newer frames, and the newer frames also match the missing
// stream, then it won't make sense to hold them...
//
// E.g.:
// Depth@50 <- this is curr_sync (fps=100)
// Depth@60
// And we're waiting on Color@100 (fps=10).
// Both D@50 and D@60 will match C@100.
// We want to release D@50 because D@60 is available and can be synced instead...
//
// This goes against "the synced frames should be the earliest possible!"?
//
if( ! is_smaller_than( i, *curr_sync ) )
{
bool have_more_frames = true;
for( auto index : synced_frames )
{
librealsense::matcher * m = frames_arrived_matchers[index];
if( ! _frames_queue[m].q.peek(
[&]( frame_holder & fh )
{
if( is_smaller_than( i, fh ) )
{
LOG_IF_ENABLE( "... x " << fh << " is after next-expected", env );
have_more_frames = false;
}
else if( skip_missing_stream( fh, i, last_arrived, env ) )
{
LOG_IF_ENABLE( "... x " << fh << " cannot be synced", env );
have_more_frames = false;
}
else
{
LOG_IF_ENABLE( "... " << fh << " is a better sync", env );
}
},
1 ) ) // We looked at index 0, do the peek for the next index
{
have_more_frames = false;
}
if( ! have_more_frames )
break;
}
if( have_more_frames )
{
LOG_IF_ENABLE( "... not waiting because of above", env );
continue;
}
}

LOG_IF_ENABLE( "... waiting for it", env );
release_synced_frames = false;
}
Expand Down Expand Up @@ -479,6 +529,11 @@ namespace librealsense
{
return a->get_frame_number() < b->get_frame_number();
}
bool frame_number_composite_matcher::is_smaller_than( matcher * missing, frame_holder & a )
{
auto const & next_expected = _next_expected.at( missing );
return next_expected.value < a->get_frame_number();
}
void frame_number_composite_matcher::clean_inactive_streams(frame_holder& f)
{
std::vector<stream_id> inactive_matchers;
Expand Down Expand Up @@ -570,6 +625,12 @@ namespace librealsense
return ts.first < ts.second;
}

bool timestamp_composite_matcher::is_smaller_than( matcher * missing, frame_holder & a )
{
auto const & next_expected = _next_expected.at( missing );
return next_expected.value < a->get_frame_timestamp();
}

void timestamp_composite_matcher::update_last_arrived(frame_holder& f, matcher* m)
{
auto const now = time_service::get_time();
Expand Down
6 changes: 5 additions & 1 deletion src/sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ namespace librealsense

virtual bool are_equivalent(frame_holder& a, frame_holder& b) = 0;
virtual bool is_smaller_than(frame_holder& a, frame_holder& b) = 0;
virtual bool is_smaller_than( matcher * missing, frame_holder & ) = 0;
virtual bool skip_missing_stream( frame_interface const * waiting_to_be_released,
matcher * missing,
frame_header const & last_arrived,
Expand Down Expand Up @@ -139,7 +140,8 @@ namespace librealsense

void sync(frame_holder f, const syncronization_environment& env) override;
virtual bool are_equivalent(frame_holder& a, frame_holder& b) override { return false; }
virtual bool is_smaller_than(frame_holder& a, frame_holder& b) override { return false; }
virtual bool is_smaller_than( frame_holder & a, frame_holder & b ) override { return false; }
virtual bool is_smaller_than( matcher * missing, frame_holder & a ) override { return false; }
virtual bool skip_missing_stream( frame_interface const * waiting_to_be_released,
matcher * missing,
frame_header const & last_arrived,
Expand All @@ -165,6 +167,7 @@ namespace librealsense
virtual void update_last_arrived(frame_holder& f, matcher* m) override;
bool are_equivalent(frame_holder& a, frame_holder& b) override;
bool is_smaller_than(frame_holder& a, frame_holder& b) override;
bool is_smaller_than( matcher * missing, frame_holder & a ) override;
bool skip_missing_stream( frame_interface const * waiting_to_be_released,
matcher * missing,
frame_header const & last_arrived,
Expand All @@ -183,6 +186,7 @@ namespace librealsense
timestamp_composite_matcher( std::vector< std::shared_ptr< matcher > > const & matchers );
bool are_equivalent(frame_holder& a, frame_holder& b) override;
bool is_smaller_than(frame_holder& a, frame_holder& b) override;
bool is_smaller_than( matcher * missing, frame_holder & ) override;
virtual void update_last_arrived(frame_holder& f, matcher* m) override;
void clean_inactive_streams(frame_holder& f) override;
bool skip_missing_stream( frame_interface const * waiting_to_be_released,
Expand Down

0 comments on commit 1290a18

Please sign in to comment.