1 #ifndef _PBO_FRAME_ALLOCATOR
2 #define _PBO_FRAME_ALLOCATOR 1
11 #include <movit/ycbcr.h>
13 #include "bmusb/bmusb.h"
15 // An allocator that allocates straight into OpenGL pinned memory.
16 // Meant for video frames only. We use a queue rather than a stack,
17 // since we want to maximize pipelineability.
18 class PBOFrameAllocator : public bmusb::FrameAllocator {
20 // Note: You need to have an OpenGL context when calling
22 PBOFrameAllocator(bmusb::PixelFormat pixel_format,
24 GLuint width, GLuint height,
25 size_t num_queued_frames = 16,
26 GLenum buffer = GL_PIXEL_UNPACK_BUFFER_ARB,
27 GLenum permissions = GL_MAP_WRITE_BIT,
28 GLenum map_bits = GL_MAP_FLUSH_EXPLICIT_BIT);
29 ~PBOFrameAllocator() override;
30 Frame alloc_frame() override;
31 void release_frame(Frame frame) override;
36 // NOTE: These frames typically go into LiveInputWrapper, which is
37 // configured to accept one type of frame only. In other words,
38 // the existence of a format field doesn't mean you can set it
40 bmusb::PixelFormat pixel_format;
42 // Used only for PixelFormat_8BitYCbCrPlanar.
43 movit::YCbCrFormat ycbcr_format;
45 // The second set is only used for the second field of interlaced inputs.
46 GLuint tex_y[2], tex_cbcr[2]; // For PixelFormat_8BitYCbCr.
47 GLuint tex_cb[2], tex_cr[2]; // For PixelFormat_8BitYCbCrPlanar (which also uses tex_y).
48 GLuint tex_v210[2], tex_444[2]; // For PixelFormat_10BitYCbCr.
49 GLuint tex_rgba[2]; // For PixelFormat_8BitBGRA.
50 GLuint last_width[2], last_height[2];
51 GLuint last_cbcr_width[2], last_cbcr_height[2];
52 GLuint last_v210_width[2]; // PixelFormat_10BitYCbCr.
53 bool last_interlaced, last_has_signal, last_is_connected;
54 unsigned last_frame_rate_nom, last_frame_rate_den;
58 void init_frame(size_t frame_idx, size_t frame_size, GLuint width, GLuint height, GLenum permissions, GLenum map_bits);
59 void destroy_frame(Frame *frame);
61 bmusb::PixelFormat pixel_format;
62 std::mutex freelist_mutex;
63 std::queue<Frame> freelist;
65 std::unique_ptr<Userdata[]> userdata;
68 #endif // !defined(_PBO_FRAME_ALLOCATOR)