]> git.sesse.net Git - nageru/blobdiff - nageru/pbo_frame_allocator.cpp
Move texture uploading out of a lambda.
[nageru] / nageru / pbo_frame_allocator.cpp
index f9b4601ec3653da0e23fd349a54ad2475291d085..d7cd818d15d614ba96d1d049e9bb36afbdc01e36 100644 (file)
@@ -10,7 +10,7 @@
 #include "flags.h"
 #include "mjpeg_encoder.h"
 #include "v210_converter.h"
-#include "va_display_with_cleanup.h"
+#include "shared/va_display.h"
 
 using namespace std;
 
@@ -264,6 +264,14 @@ void PBOFrameAllocator::destroy_frame(Frame *frame)
        default:
                assert(false);
        }
+
+       if (ud->generation != generation) {
+               auto it = lingering_generations.find(ud->generation);
+               assert(it != lingering_generations.end());
+               if (--it->second.num_frames_left == 0) {
+                       lingering_generations.erase(it);  // Deallocates the userdata block.
+               }
+       }
 }
 //static int sumsum = 0;
 
@@ -320,7 +328,7 @@ bmusb::FrameAllocator::Frame PBOFrameAllocator::create_frame(size_t width, size_
            mjpeg_encoder->should_encode_mjpeg_for_card(card_index)) {
                if (mjpeg_encoder->using_vaapi()) {
                        VADisplay va_dpy = mjpeg_encoder->va_dpy->va_dpy;
-                       MJPEGEncoder::VAResources resources = mjpeg_encoder->get_va_resources(width, height);
+                       MJPEGEncoder::VAResources resources = mjpeg_encoder->get_va_resources(width, height, VA_FOURCC_UYVY);  // Only used by DeckLinkCapture, so always 4:2:2.
                        MJPEGEncoder::ReleaseVAResources release(mjpeg_encoder, resources);
 
                        if (resources.image.pitches[0] == stride) {
@@ -429,6 +437,16 @@ void PBOFrameAllocator::reconfigure(bmusb::PixelFormat pixel_format,
                return;
        }
 
+       lock_guard<mutex> lock(freelist_mutex);
+       lingering_generations[generation] = LingeringGeneration{ move(userdata), this->num_queued_frames };
+       ++generation;
+
+       while (!freelist.empty()) {
+               Frame frame = freelist.front();
+               freelist.pop();
+               destroy_frame(&frame);
+       }
+
        this->pixel_format = pixel_format;
        this->frame_size = frame_size;
        this->width = width;
@@ -440,13 +458,7 @@ void PBOFrameAllocator::reconfigure(bmusb::PixelFormat pixel_format,
        this->permissions = permissions;
        this->map_bits = map_bits;
 
-       lock_guard<mutex> lock(freelist_mutex);
-       while (!freelist.empty()) {
-               Frame frame = freelist.front();
-               freelist.pop();
-               destroy_frame(&frame);
-       }
-       ++generation;
+       userdata.reset(new Userdata[num_queued_frames]);
        for (size_t i = 0; i < num_queued_frames; ++i) {
                init_frame(i, frame_size, width, height, permissions, map_bits, generation);
        }