X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nageru%2Fpbo_frame_allocator.h;h=cff50aa6310036fe320f2f2021c9b445ec7e7a75;hb=HEAD;hp=0080dd0e97fe3ce729d37aa960895d04ffedc12e;hpb=6cf87ad853439f8565c575fb29dc539a15fdba87;p=nageru diff --git a/nageru/pbo_frame_allocator.h b/nageru/pbo_frame_allocator.h index 0080dd0..772d05e 100644 --- a/nageru/pbo_frame_allocator.h +++ b/nageru/pbo_frame_allocator.h @@ -4,14 +4,19 @@ #include #include #include +#include +#include #include #include +#include #include +#include #include #include "bmusb/bmusb.h" #include "mjpeg_encoder.h" +#include "shared/va_resource_pool.h" class MJPEGEncoder; @@ -36,6 +41,17 @@ public: Frame create_frame(size_t width, size_t height, size_t stride) override; void release_frame(Frame frame) override; + // NOTE: Does not check the buffer types; they are just assumed to be compatible. + void reconfigure(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); + struct Userdata { GLuint pbo; @@ -78,12 +94,14 @@ public: // 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; + VAResourcePool::VAResources va_resources; + ReleaseVAResources va_resources_release; + + int generation; }; private: - void init_frame(size_t frame_idx, size_t frame_size, GLuint width, GLuint height, GLenum permissions, GLenum map_bits); + static void init_frame(Frame &frame, Userdata *ud, PBOFrameAllocator *owner, bmusb::PixelFormat pixel_format, size_t frame_size, GLuint width, GLuint height, GLenum permissions, GLenum map_bits, GLenum buffer, int generation); void destroy_frame(Frame *frame); unsigned card_index; @@ -93,6 +111,20 @@ private: std::queue freelist; GLenum buffer; std::unique_ptr userdata; + + // Used only for reconfigure(), to check whether we can do without. + size_t frame_size; + size_t num_queued_frames; + GLuint width, height; + GLenum permissions; + GLenum map_bits; + int generation = 0; // Under freelist_mutex. + + struct LingeringGeneration { + std::unique_ptr userdata; + size_t num_frames_left; + }; + std::map lingering_generations; }; #endif // !defined(_PBO_FRAME_ALLOCATOR)