37 lines
1002 B
C++
37 lines
1002 B
C++
#include "frame_ring_buffer.h"
|
|
|
|
namespace rk3588 {
|
|
|
|
FrameRingBuffer::FrameRingBuffer(int pre_event_sec, int fps_hint)
|
|
: pre_event_sec_(pre_event_sec), fps_hint_(fps_hint > 0 ? fps_hint : 25) {
|
|
max_frames_ = static_cast<size_t>(pre_event_sec_ * fps_hint_);
|
|
if (max_frames_ < 10) max_frames_ = 10;
|
|
}
|
|
|
|
void FrameRingBuffer::Push(std::shared_ptr<Frame> frame) {
|
|
if (!frame) return;
|
|
|
|
std::lock_guard<std::mutex> lock(mutex_);
|
|
buffer_.push_back(frame);
|
|
while (buffer_.size() > max_frames_) {
|
|
buffer_.pop_front();
|
|
}
|
|
}
|
|
|
|
std::vector<std::shared_ptr<Frame>> FrameRingBuffer::GetPreEventFrames() const {
|
|
std::lock_guard<std::mutex> lock(mutex_);
|
|
return std::vector<std::shared_ptr<Frame>>(buffer_.begin(), buffer_.end());
|
|
}
|
|
|
|
void FrameRingBuffer::Clear() {
|
|
std::lock_guard<std::mutex> lock(mutex_);
|
|
buffer_.clear();
|
|
}
|
|
|
|
size_t FrameRingBuffer::Size() const {
|
|
std::lock_guard<std::mutex> lock(mutex_);
|
|
return buffer_.size();
|
|
}
|
|
|
|
} // namespace rk3588
|