Abort encode if Grok encoder threads are failing (#2899)
authorCarl Hetherington <cth@carlh.net>
Thu, 28 Nov 2024 17:50:21 +0000 (18:50 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 29 Nov 2024 22:31:41 +0000 (23:31 +0100)
src/lib/j2k_encoder.cc
src/lib/j2k_encoder.h

index 0b50bcd5abcfc76ac2848a2481977cec6adf13b6..15046b51d2c0bc192a126876b8cf39a9906aabad 100644 (file)
@@ -93,6 +93,9 @@ grk_plugin::IMessengerLogger* getMessengerLogger(void)
  */
 J2KEncoder::J2KEncoder(shared_ptr<const Film> film, Writer& writer)
        : VideoEncoder(film, writer)
+#ifdef DCPOMATIC_GROK
+       , _give_up(false)
+#endif
 {
 #ifdef DCPOMATIC_GROK
        auto grok = Config::instance()->grok().get_value_or({});
@@ -271,6 +274,12 @@ J2KEncoder::frame_done ()
 void
 J2KEncoder::encode (shared_ptr<PlayerVideo> pv, DCPTime time)
 {
+#ifdef DCPOMATIC_GROK
+       if (_give_up) {
+               throw EncodeError(_("GPU acceleration is enabled but the grok decoder is not working.  Please check your configuration and license, and ensure that you are connected to the internet."));
+       }
+#endif
+
        VideoEncoder::encode(pv, time);
 
        _waker.nudge ();
@@ -463,9 +472,23 @@ J2KEncoder::pop()
 void
 J2KEncoder::retry(DCPVideo video)
 {
-       boost::mutex::scoped_lock lock(_queue_mutex);
-       _queue.push_front(video);
-       _empty_condition.notify_all();
+#ifdef DCPOMATIC_GROK
+       {
+               boost::mutex::scoped_lock lock(_threads_mutex);
+               auto is_grok_thread_with_errors = [](shared_ptr<const J2KEncoderThread> thread) {
+                       auto grok = dynamic_pointer_cast<const GrokJ2KEncoderThread>(thread);
+                       return grok && grok->errors();
+               };
+
+               _give_up = std::any_of(_threads.begin(), _threads.end(), is_grok_thread_with_errors);
+       }
+#endif
+
+       {
+               boost::mutex::scoped_lock lock(_queue_mutex);
+               _queue.push_front(video);
+               _empty_condition.notify_all();
+       }
 }
 
 
index 7536cbc3abb86ed38d5e4e77b0dc230b87b93c02..5c8ad030d53ff5a69e06ad9974f567d4f86f79cc 100644 (file)
@@ -120,6 +120,7 @@ private:
 #ifdef DCPOMATIC_GROK
        grk_plugin::DcpomaticContext* _dcpomatic_context = nullptr;
        grk_plugin::GrokContext *_context = nullptr;
+       std::atomic<bool> _give_up;
 #endif
 
        bool _ending = false;