]> git.sesse.net Git - nageru/blobdiff - ref_counted_frame.h
Fix an issue where the mixer lagging too much behind CEF would cause us to display...
[nageru] / ref_counted_frame.h
index 5912ce8187c7fc90ab02d2e5d4c5d3c0e4b0e2be..cb055f9e3a62ea49bf8d8a963d2aa8b07ea87ef5 100644 (file)
@@ -7,18 +7,47 @@
 // Note that the important point isn't really the pointer to the Frame itself,
 // it's the resources it's representing that need to go back to the allocator.
 
-#include "bmusb.h"
+#include <memory>
 
-void release_refcounted_frame(FrameAllocator::Frame *frame);
+#include "bmusb/bmusb.h"
 
-typedef std::shared_ptr<FrameAllocator::Frame> RefCountedFrameBase;
+void release_refcounted_frame(bmusb::FrameAllocator::Frame *frame);
+
+typedef std::shared_ptr<bmusb::FrameAllocator::Frame> RefCountedFrameBase;
 
 class RefCountedFrame : public RefCountedFrameBase {
 public:
        RefCountedFrame() {}
 
-       RefCountedFrame(const FrameAllocator::Frame &frame)
-               : RefCountedFrameBase(new FrameAllocator::Frame(frame), release_refcounted_frame) {}
+       RefCountedFrame(const bmusb::FrameAllocator::Frame &frame)
+               : RefCountedFrameBase(new bmusb::FrameAllocator::Frame(frame), release_refcounted_frame) {}
+};
+
+// Similar to RefCountedFrame, but as unique_ptr instead of shared_ptr.
+
+struct Unique_frame_deleter {
+       void operator() (bmusb::FrameAllocator::Frame *frame) const {
+               release_refcounted_frame(frame);
+       }
+};
+
+typedef std::unique_ptr<bmusb::FrameAllocator::Frame, Unique_frame_deleter>
+       UniqueFrameBase;
+
+class UniqueFrame : public UniqueFrameBase {
+public:
+       UniqueFrame() {}
+
+       UniqueFrame(const bmusb::FrameAllocator::Frame &frame)
+               : UniqueFrameBase(new bmusb::FrameAllocator::Frame(frame)) {}
+
+       bmusb::FrameAllocator::Frame get_and_release()
+       {
+               bmusb::FrameAllocator::Frame *ptr = release();
+               bmusb::FrameAllocator::Frame frame = *ptr;
+               delete ptr;
+               return frame;
+       }
 };
 
 #endif  // !defined(_REF_COUNTED_FRAME_H)