]> git.sesse.net Git - nageru/blob - pbo_frame_allocator.h
Various Makefile tweaks (mostly related to cleaning moc files).
[nageru] / pbo_frame_allocator.h
1 #ifndef _PBO_FRAME_ALLOCATOR 
2 #define _PBO_FRAME_ALLOCATOR 1
3
4 #include <epoxy/gl.h>
5 #include <stdbool.h>
6 #include <stddef.h>
7 #include <memory>
8 #include <mutex>
9 #include <queue>
10
11 #include "bmusb/bmusb.h"
12
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 {
17 public:
18         // Note: You need to have an OpenGL context when calling
19         // the constructor.
20         PBOFrameAllocator(size_t frame_size,
21                           GLuint width, GLuint height,
22                           size_t num_queued_frames = 16,  // FIXME: should be 6
23                           GLenum buffer = GL_PIXEL_UNPACK_BUFFER_ARB,
24                           GLenum permissions = GL_MAP_WRITE_BIT,
25                           GLenum map_bits = GL_MAP_FLUSH_EXPLICIT_BIT);
26         ~PBOFrameAllocator() override;
27         Frame alloc_frame() override;
28         void release_frame(Frame frame) override;
29
30         struct Userdata {
31                 GLuint pbo;
32
33                 // The second set is only used for the second field of interlaced inputs.
34                 GLuint tex_y[2], tex_cbcr[2];
35                 GLuint last_width[2], last_height[2];
36                 bool last_interlaced, last_has_signal, last_is_connected;
37                 unsigned last_frame_rate_nom, last_frame_rate_den;
38         };
39
40 private:
41         std::mutex freelist_mutex;
42         std::queue<Frame> freelist;
43         GLenum buffer;
44         std::unique_ptr<Userdata[]> userdata;
45 };
46
47 #endif  // !defined(_PBO_FRAME_ALLOCATOR)