Extract J2K frame encoder classes for CPU and remote.
[dcpomatic.git] / src / lib / cpu_j2k_frame_encoder.cc
1 /*
2     Copyright (C) 2022 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21
22 #include "cpu_j2k_frame_encoder.h"
23 #include "cross.h"
24 #include "dcp_video.h"
25 #include "dcpomatic_log.h"
26
27 #include "i18n.h"
28
29
30 using std::shared_ptr;
31 using boost::optional;
32 using dcp::ArrayData;
33
34
35 optional<ArrayData>
36 CPUJ2KFrameEncoder::encode (DCPVideo const& vf)
37 {
38         optional<ArrayData> encoded;
39
40         try {
41                 LOG_TIMING("start-local-encode thread=%1 frame=%2", thread_id(), vf.index());
42                 encoded = vf.encode_locally();
43                 LOG_TIMING("finish-local-encode thread=%1 frame=%2", thread_id(), vf.index());
44         } catch (std::exception& e) {
45                 /* This is very bad, so don't cope with it, just pass it on */
46                 LOG_ERROR(N_("Local encode failed (%1)"), e.what());
47                 throw;
48         }
49
50         return encoded;
51 }
52
53
54 void
55 CPUJ2KFrameEncoder::log_thread_start ()
56 {
57         LOG_TIMING("start-encoder-thread thread=%1 server=localhost", thread_id());
58 }
59