#pragma once #include "./frame_stream2.hpp" #include #include // threadsafe queue frame stream // protected by a simple mutex lock // prefer lockless queue implementations, when available template struct LockedFrameStream2 : public FrameStream2I { std::mutex _lock; std::deque _frames; ~LockedFrameStream2(void) {} int32_t size(void) { return -1; } std::optional pop(void) { std::lock_guard lg{_lock}; if (_frames.empty()) { return std::nullopt; } FrameType new_frame = std::move(_frames.front()); _frames.pop_front(); return std::move(new_frame); } bool push(const FrameType& value) { std::lock_guard lg{_lock}; if (_frames.size() > 1024) { return false; // hard limit } _frames.push_back(value); return true; } };