summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2024-11-28 18:50:21 +0100
committerCarl Hetherington <cth@carlh.net>2024-11-29 23:31:41 +0100
commit92eab12404eca23db0a96ad7574d8d500f3d0f8a (patch)
treed228554891cda105e85b4955f43f9bcbd3d68b5d
parente995209353552a97676a11fee03f245564df41ba (diff)
Abort encode if Grok encoder threads are failing (#2899)
-rw-r--r--src/lib/j2k_encoder.cc29
-rw-r--r--src/lib/j2k_encoder.h1
2 files changed, 27 insertions, 3 deletions
diff --git a/src/lib/j2k_encoder.cc b/src/lib/j2k_encoder.cc
index 0b50bcd5a..15046b51d 100644
--- a/src/lib/j2k_encoder.cc
+++ b/src/lib/j2k_encoder.cc
@@ -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();
+ }
}
diff --git a/src/lib/j2k_encoder.h b/src/lib/j2k_encoder.h
index 7536cbc3a..5c8ad030d 100644
--- a/src/lib/j2k_encoder.h
+++ b/src/lib/j2k_encoder.h
@@ -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;