Move encode_{locally,remotely} into the frame encoder classes.
[dcpomatic.git] / src / lib / dcp_video.cc
1 /*
2     Copyright (C) 2012-2021 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 /** @file  src/dcp_video_frame.cc
23  *  @brief A single frame of video destined for a DCP.
24  *
25  *  Given an Image and some settings, this class knows how to encode
26  *  the image to J2K either on the local host or on a remote server.
27  *
28  *  Objects of this class are used for the queue that we keep
29  *  of images that require encoding.
30  */
31
32
33 #include "cross.h"
34 #include "dcp_video.h"
35 #include "player_video.h"
36 #include <libcxml/cxml.h>
37
38 #include "i18n.h"
39
40
41 using std::cout;
42 using std::make_shared;
43 using std::shared_ptr;
44 using std::string;
45
46
47 #define DCI_COEFFICENT (48.0 / 52.37)
48
49
50 /** Construct a DCP video frame.
51  *  @param frame Input frame.
52  *  @param index Index of the frame within the DCP.
53  *  @param bw J2K bandwidth to use (see Config::j2k_bandwidth ())
54  */
55 DCPVideo::DCPVideo (
56         shared_ptr<const PlayerVideo> frame, int index, int dcp_fps, int bw, Resolution r
57         )
58         : _frame (frame)
59         , _index (index)
60         , _frames_per_second (dcp_fps)
61         , _j2k_bandwidth (bw)
62         , _resolution (r)
63 {
64
65 }
66
67 DCPVideo::DCPVideo (shared_ptr<const PlayerVideo> frame, shared_ptr<const cxml::Node> node)
68         : _frame (frame)
69 {
70         _index = node->number_child<int> ("Index");
71         _frames_per_second = node->number_child<int> ("FramesPerSecond");
72         _j2k_bandwidth = node->number_child<int> ("J2KBandwidth");
73         _resolution = Resolution (node->optional_number_child<int>("Resolution").get_value_or(static_cast<int>(Resolution::TWO_K)));
74 }
75
76
77 Eyes
78 DCPVideo::eyes () const
79 {
80         return _frame->eyes ();
81 }
82
83 /** @return true if this DCPVideo is definitely the same as another;
84  *  (apart from the frame index), false if it is probably not.
85  */
86 bool
87 DCPVideo::same (shared_ptr<const DCPVideo> other) const
88 {
89         if (_frames_per_second != other->_frames_per_second ||
90             _j2k_bandwidth != other->_j2k_bandwidth ||
91             _resolution != other->_resolution) {
92                 return false;
93         }
94
95         return _frame->same (other->_frame);
96 }