Fix hang when trying to assure minimum bitrate.
authorCarl Hetherington <cth@carlh.net>
Mon, 1 Feb 2021 09:02:56 +0000 (10:02 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 1 Feb 2021 09:02:56 +0000 (10:02 +0100)
src/lib/dcp_video.cc

index cb151772700a62e661ea4dcb1f50adabf67527bb..7b529c45a205df6d52bb8bec964819271ab76ede 100644 (file)
@@ -128,6 +128,7 @@ DCPVideo::encode_locally ()
        int constexpr minimum_size = 65536;
 
        auto xyz = convert_to_xyz (_frame, boost::bind(&Log::dcp_log, dcpomatic_log.get(), _1, _2));
+       int noise_amount = 2;
        while (true) {
                enc = dcp::compress_j2k (
                        xyz,
@@ -153,10 +154,14 @@ DCPVideo::encode_locally ()
                for (auto c = 0; c < 3; ++c) {
                        auto p = xyz->data(c);
                        for (auto i = 0; i < pixels; ++i) {
-                               *p = std::min(4095, std::max(0, *p + rand() % 2));
+                               *p = std::min(4095, std::max(0, *p + rand() % noise_amount));
                                ++p;
                        }
                }
+
+               ++noise_amount;
+               /* Something's gone badly wrong if this much noise doesn't help */
+               DCP_ASSERT (noise_amount < 16);
        }
 
        switch (_frame->eyes()) {