d5256619d6a9c43e305b29fc62c7a1967dc6e9ce
[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                         _encoder.retry(frame);
37                 });
38
39                 LOG_TIMING("encoder-pop thread=%1 frame=%2 eyes=%3", thread_id(), frame.index(), static_cast<int>(frame.eyes()));
40
41                 if (_context->launch(frame, Config::instance()->selected_gpu()) && _context->scheduleCompress(frame)) {
42                         frame_guard.cancel();
43                 }
44         }
45 } catch (boost::thread_interrupted& e) {
46 } catch (...) {
47         store_current();
48 }