Clean up grok's presence in the config file and make sure it's optional.
[dcpomatic.git] / src / lib / grok_j2k_encoder_thread.cc
1 #include "config.h"
2 #include "cross.h"
3 #include "dcpomatic_log.h"
4 #include "dcp_video.h"
5 #include "grok/context.h"
6 #include "grok_j2k_encoder_thread.h"
7 #include "j2k_encoder.h"
8 #include "scope_guard.h"
9 #include "util.h"
10
11 #include "i18n.h"
12
13
14 using std::make_shared;
15 using std::shared_ptr;
16
17
18 GrokJ2KEncoderThread::GrokJ2KEncoderThread(J2KEncoder& encoder, grk_plugin::GrokContext* context)
19         : J2KEncoderThread(encoder)
20         , _context(context)
21 {
22
23 }
24
25
26 void
27 GrokJ2KEncoderThread::run()
28 try
29 {
30         while (true)
31         {
32                 LOG_TIMING("encoder-sleep thread=%1", thread_id());
33                 auto frame = _encoder.pop();
34
35                 ScopeGuard frame_guard([this, &frame]() {
36                         LOG_ERROR("Failed to schedule encode of %1 using grok", frame.index());
37                         _encoder.retry(frame);
38                 });
39
40                 LOG_TIMING("encoder-pop thread=%1 frame=%2 eyes=%3", thread_id(), frame.index(), static_cast<int>(frame.eyes()));
41
42                 auto grok = Config::instance()->grok().get_value_or({});
43
44                 if (_context->launch(frame, grok.selected) && _context->scheduleCompress(frame)) {
45                         frame_guard.cancel();
46                 }
47         }
48 } catch (boost::thread_interrupted& e) {
49 } catch (...) {
50         store_current();
51 }