[cscore] Sink: add ability to get most recent frame instead of waiting (#7572)

This allows more control over frame dropping.
This commit is contained in:
Matt
2024-12-28 23:44:48 -05:00
committed by GitHub
parent 85507a6c65
commit a27df8ec24
7 changed files with 117 additions and 6 deletions

View File

@@ -84,12 +84,17 @@ Frame SourceImpl::GetNextFrame() {
return m_frame;
}
Frame SourceImpl::GetNextFrame(double timeout) {
Frame SourceImpl::GetNextFrame(double timeout, Frame::Time lastFrameTime) {
std::unique_lock lock{m_frameMutex};
auto oldTime = m_frame.GetTime();
if (lastFrameTime == 0) {
lastFrameTime = m_frame.GetTime();
}
// Wait unitl m_frame has a timestamp other than lastFrameTime
if (!m_frameCv.wait_for(
lock, std::chrono::milliseconds(static_cast<int>(timeout * 1000)),
[=, this] { return m_frame.GetTime() != oldTime; })) {
[=, this] { return m_frame.GetTime() != lastFrameTime; })) {
m_frame = Frame{*this, "timed out getting frame", wpi::Now()};
}
return m_frame;