]> git.sesse.net Git - nageru/blob - pbo_frame_allocator.h
Let settings follow buses when editing the mapping.
[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 bmusb::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
32                 // The second set is only used for the second field of interlaced inputs.
33                 GLuint tex_y[2], tex_cbcr[2];
34                 GLuint last_width[2], last_height[2];
35                 bool last_interlaced, last_has_signal, last_is_connected;
36                 unsigned last_frame_rate_nom, last_frame_rate_den;
37         };
38
39 private:
40         std::mutex freelist_mutex;
41         std::queue<Frame> freelist;
42         GLenum buffer;
43         std::unique_ptr<Userdata[]> userdata;
44 };
45
46 #endif  // !defined(_PBO_FRAME_ALLOCATOR)