]> git.sesse.net Git - nageru/commitdiff
Fix MJPEG white balance information when VA-API is in use.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 4 Mar 2020 18:53:49 +0000 (19:53 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 4 Mar 2020 18:53:49 +0000 (19:53 +0100)
The JPEG headers were cached (per resolution) and never invalidated,
causing wrong/outdated information to be sent.

I can't really remember why I wanted to cache these, but I suppose
I had a reason, so I'm a bit reluctant to just kill the cache.
Hopefully, the white balance won't change often enough, and these
objects are so small, that we won't need invalidation; we can just
let it grow until program exit.

nageru/mjpeg_encoder.cpp
nageru/mjpeg_encoder.h

index 19ffd58719aa151c01144d850cc987799cd175ed..4cc929b88d5083f0fb30b80a9b199c256cf8abe1 100644 (file)
@@ -660,11 +660,11 @@ vector<uint8_t> MJPEGEncoder::get_jpeg_header(unsigned width, unsigned height, c
        return dest.dest;
 }
 
-MJPEGEncoder::VAData MJPEGEncoder::get_va_data_for_resolution(unsigned width, unsigned height, const RGBTriplet &white_balance)
+MJPEGEncoder::VAData MJPEGEncoder::get_va_data_for_parameters(unsigned width, unsigned height, const RGBTriplet &white_balance)
 {
-       pair<unsigned, unsigned> key(width, height);
-       if (va_data_for_resolution.count(key)) {
-               return va_data_for_resolution[key];
+       VAKey key{width, height, white_balance};
+       if (va_data_for_parameters.count(key)) {
+               return va_data_for_parameters[key];
        }
 
        // Use libjpeg to generate a header and set sane defaults for e.g.
@@ -765,7 +765,7 @@ MJPEGEncoder::VAData MJPEGEncoder::get_va_data_for_resolution(unsigned width, un
        ret.q = q;
        ret.huff = huff;
        ret.parms = parms;
-       va_data_for_resolution[key] = ret;
+       va_data_for_parameters[key] = ret;
        return ret;
 }
 
@@ -786,7 +786,7 @@ void MJPEGEncoder::encode_jpeg_va(QueuedFrame &&qf)
                release = ReleaseVAResources(this, resources);
        }
 
-       VAData va_data = get_va_data_for_resolution(width, height, qf.white_balance);
+       VAData va_data = get_va_data_for_parameters(width, height, qf.white_balance);
        va_data.pic_param.coded_buf = resources.data_buffer;
 
        VABufferID pic_param_buffer;
index eff361ea4e4cb1ebada2236daef46321e690a942..87bf3b5836509429b67195733d567c77ae0550e4 100644 (file)
@@ -154,6 +154,22 @@ private:
        std::unique_ptr<VADisplayWithCleanup> va_dpy;
        VAConfigID config_id;
 
+       struct VAKey {
+               unsigned width, height;
+               movit::RGBTriplet white_balance;
+
+               bool operator< (const VAKey &other) const {
+                       if (width != other.width)
+                               return width < other.width;
+                       if (height != other.height)
+                               return height < other.height;
+                       if (white_balance.r != other.white_balance.r)
+                               return white_balance.r < other.white_balance.r;
+                       if (white_balance.g != other.white_balance.g)
+                               return white_balance.g < other.white_balance.g;
+                       return white_balance.b < other.white_balance.b;
+               }
+       };
        struct VAData {
                std::vector<uint8_t> jpeg_header;
                VAEncPictureParameterBufferJPEG pic_param;
@@ -161,8 +177,8 @@ private:
                VAHuffmanTableBufferJPEGBaseline huff;
                VAEncSliceParameterBufferJPEG parms;
        };
-       std::map<std::pair<unsigned, unsigned>, VAData> va_data_for_resolution;
-       VAData get_va_data_for_resolution(unsigned width, unsigned height, const movit::RGBTriplet &white_balance);
+       std::map<VAKey, VAData> va_data_for_parameters;
+       VAData get_va_data_for_parameters(unsigned width, unsigned height, const movit::RGBTriplet &white_balance);
 
        std::list<VAResources> va_resources_freelist;
        std::mutex va_resources_mutex;