]> git.sesse.net Git - nageru/blob - pbo_frame_allocator.h
Remove an obsolete comment, now that we have proper latency control.
[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(bmusb::PixelFormat pixel_format,
21                           size_t frame_size,
22                           GLuint width, GLuint height,
23                           size_t num_queued_frames = 16,
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;
30
31         struct Userdata {
32                 GLuint pbo;
33
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
37                 // freely at runtime.
38                 bmusb::PixelFormat pixel_format;
39
40                 // The second set is only used for the second field of interlaced inputs.
41                 GLuint tex_y[2], tex_cbcr[2];  // For PixelFormat_8BitYCbCr.
42                 GLuint tex_v210[2], tex_444[2];  // For PixelFormat_10BitYCbCr.
43                 GLuint tex_rgba[2];  // For PixelFormat_8BitBGRA.
44                 GLuint last_width[2], last_height[2];
45                 GLuint last_v210_width[2];  // PixelFormat_10BitYCbCr.
46                 bool last_interlaced, last_has_signal, last_is_connected;
47                 unsigned last_frame_rate_nom, last_frame_rate_den;
48         };
49
50 private:
51         bmusb::PixelFormat pixel_format;
52         std::mutex freelist_mutex;
53         std::queue<Frame> freelist;
54         GLenum buffer;
55         std::unique_ptr<Userdata[]> userdata;
56 };
57
58 #endif  // !defined(_PBO_FRAME_ALLOCATOR)