]> git.sesse.net Git - nageru/blob - pbo_frame_allocator.h
Open up for inputs that are different from the native resolution. No deinterlacing...
[nageru] / pbo_frame_allocator.h
1 #ifndef _PBO_FRAME_ALLOCATOR 
2 #define _PBO_FRAME_ALLOCATOR 1
3
4 #include <epoxy/gl.h>
5 #include <stddef.h>
6 #include <memory>
7 #include <mutex>
8 #include <queue>
9
10 #include "bmusb/bmusb.h"
11
12 // An allocator that allocates straight into OpenGL pinned memory.
13 // Meant for video frames only. We use a queue rather than a stack,
14 // since we want to maximize pipelineability.
15 class PBOFrameAllocator : public FrameAllocator {
16 public:
17         // Note: You need to have an OpenGL context when calling
18         // the constructor.
19         PBOFrameAllocator(size_t frame_size,
20                           GLuint width, GLuint height,
21                           size_t num_queued_frames = 16,  // FIXME: should be 6
22                           GLenum buffer = GL_PIXEL_UNPACK_BUFFER_ARB,
23                           GLenum permissions = GL_MAP_WRITE_BIT,
24                           GLenum map_bits = GL_MAP_FLUSH_EXPLICIT_BIT);
25         ~PBOFrameAllocator() override;
26         Frame alloc_frame() override;
27         void release_frame(Frame frame) override;
28
29         struct Userdata {
30                 GLuint pbo;
31                 GLuint tex_y, tex_cbcr;
32                 GLuint last_width, last_height;
33         };
34
35 private:
36         size_t frame_size;
37
38         std::mutex freelist_mutex;
39         std::queue<Frame> freelist;
40         GLenum buffer;
41         std::unique_ptr<Userdata[]> userdata;
42 };
43
44 #endif  // !defined(_PBO_FRAME_ALLOCATOR)