]> git.sesse.net Git - nageru/blobdiff - nageru/pbo_frame_allocator.h
Heed the Exif white point when playing back (MJPEG) video.
[nageru] / nageru / pbo_frame_allocator.h
index ab51f6bc108839297363dd0ede80860dacfb4481..0080dd0e97fe3ce729d37aa960895d04ffedc12e 100644 (file)
@@ -11,6 +11,9 @@
 #include <movit/ycbcr.h>
 
 #include "bmusb/bmusb.h"
+#include "mjpeg_encoder.h"
+
+class MJPEGEncoder;
 
 // An allocator that allocates straight into OpenGL pinned memory.
 // Meant for video frames only. We use a queue rather than a stack,
@@ -22,12 +25,15 @@ public:
        PBOFrameAllocator(bmusb::PixelFormat pixel_format,
                          size_t frame_size,
                          GLuint width, GLuint height,
+                         unsigned card_index,
+                         MJPEGEncoder *mjpeg_encoder = nullptr,
                          size_t num_queued_frames = 16,
                          GLenum buffer = GL_PIXEL_UNPACK_BUFFER_ARB,
                          GLenum permissions = GL_MAP_WRITE_BIT,
                          GLenum map_bits = GL_MAP_FLUSH_EXPLICIT_BIT);
        ~PBOFrameAllocator() override;
        Frame alloc_frame() override;
+       Frame create_frame(size_t width, size_t height, size_t stride) override;
        void release_frame(Frame frame) override;
 
        struct Userdata {
@@ -54,12 +60,34 @@ public:
                unsigned last_frame_rate_nom, last_frame_rate_den;
                bool has_last_subtitle = false;
                std::string last_subtitle;
+               movit::RGBTriplet white_balance{1.0f, 1.0f, 1.0f};
+
+               // These are the source of the “data_copy” member in Frame,
+               // used for MJPEG encoding. There are three possibilities:
+               //
+               //  - MJPEG encoding is not active (at all, or for this specific
+               //    card). Then data_copy is nullptr, and what's in here
+               //    does not matter at all.
+               //  - We can encode directly into VA-API buffers (ie., VA-API
+               //    is active, and nothing strange happened wrt. strides);
+               //    then va_resources, va_resources_release and va_image
+               //    are fetched from MJPEGEncoder at create_frame() and released
+               //    back when the frame is uploaded (or would have been).
+               //    In this case, data_copy points into the mapped VAImage.
+               //  - If not, data_copy points to data_copy_malloc, and is copied
+               //    from there into VA-API buffers (by MJPEGEncoder) if needed.
+               enum { FROM_MALLOC, FROM_VA_API } data_copy_current_src;
+               uint8_t *data_copy_malloc;
+               MJPEGEncoder::VAResources va_resources;
+               MJPEGEncoder::ReleaseVAResources va_resources_release;
        };
 
 private:
        void init_frame(size_t frame_idx, size_t frame_size, GLuint width, GLuint height, GLenum permissions, GLenum map_bits);
        void destroy_frame(Frame *frame);
 
+       unsigned card_index;
+       MJPEGEncoder *mjpeg_encoder;
        bmusb::PixelFormat pixel_format;
        std::mutex freelist_mutex;
        std::queue<Frame> freelist;