1 #ifndef _PBO_FRAME_ALLOCATOR
2 #define _PBO_FRAME_ALLOCATOR 1
11 #include "bmusb/bmusb.h"
13 // An allocator that allocates straight into OpenGL pinned memory.
14 // Meant for video frames only. We use a queue rather than a stack,
15 // since we want to maximize pipelineability.
16 class PBOFrameAllocator : public bmusb::FrameAllocator {
18 // Note: You need to have an OpenGL context when calling
20 PBOFrameAllocator(bmusb::PixelFormat pixel_format,
22 GLuint width, GLuint height,
23 size_t num_queued_frames = 16, // FIXME: should be 6
24 GLenum buffer = GL_PIXEL_UNPACK_BUFFER_ARB,
25 GLenum permissions = GL_MAP_WRITE_BIT,
26 GLenum map_bits = GL_MAP_FLUSH_EXPLICIT_BIT);
27 ~PBOFrameAllocator() override;
28 Frame alloc_frame() override;
29 void release_frame(Frame frame) override;
34 // NOTE: These frames typically go into LiveInputWrapper, which is
35 // configured to accept one type of frame only. In other words,
36 // the existence of a format field doesn't mean you can set it
38 bmusb::PixelFormat pixel_format;
40 // The second set is only used for the second field of interlaced inputs.
41 GLuint tex_y[2], tex_cbcr[2]; // For FRAME_FORMAT_YCBCR_8BIT.
42 GLuint tex_v210[2], tex_444[2]; // For FRAME_FORMAT_YCBCR_10BIT.
43 GLuint tex_rgba[2]; // For FRAME_FORMAT_RGBA_8BIT.
44 GLuint last_width[2], last_height[2];
45 GLuint last_v210_width[2]; // FRAME_FORMAT_YCBCR_10BIT.
46 bool last_interlaced, last_has_signal, last_is_connected;
47 unsigned last_frame_rate_nom, last_frame_rate_den;
51 bmusb::PixelFormat pixel_format;
52 std::mutex freelist_mutex;
53 std::queue<Frame> freelist;
55 std::unique_ptr<Userdata[]> userdata;
58 #endif // !defined(_PBO_FRAME_ALLOCATOR)