Merge.
[dcpomatic.git] / src / lib / dcp_video_frame.h
1 /*
2     Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
3     Taken from code Copyright (C) 2010-2011 Terrence Meiczinger
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20
21 #include <openjpeg.h>
22 #include <libdcp/picture_asset.h>
23 #include <libdcp/picture_asset_writer.h>
24 #include "util.h"
25
26 /** @file  src/dcp_video_frame.h
27  *  @brief A single frame of video destined for a DCP.
28  */
29
30 class Film;
31 class ServerDescription;
32 class Scaler;
33 class Image;
34 class Log;
35 class Subtitle;
36 class PlayerVideoFrame;
37
38 /** @class EncodedData
39  *  @brief Container for J2K-encoded data.
40  */
41 class EncodedData : public boost::noncopyable
42 {
43 public:
44         /** @param s Size of data, in bytes */
45         EncodedData (int s);
46
47         EncodedData (boost::filesystem::path);
48
49         virtual ~EncodedData ();
50
51         void send (boost::shared_ptr<Socket> socket);
52         void write (boost::shared_ptr<const Film>, int, Eyes) const;
53         void write_info (boost::shared_ptr<const Film>, int, Eyes, libdcp::FrameInfo) const;
54
55         /** @return data */
56         uint8_t* data () const {
57                 return _data;
58         }
59
60         /** @return data size, in bytes */
61         int size () const {
62                 return _size;
63         }
64
65 protected:
66         uint8_t* _data; ///< data
67         int _size;      ///< data size in bytes
68 };
69
70 /** @class LocallyEncodedData
71  *  @brief EncodedData that was encoded locally; this class
72  *  just keeps a pointer to the data, but does no memory
73  *  management.
74  */
75 class LocallyEncodedData : public EncodedData
76 {
77 public:
78         /** @param d Data (which will be copied by this class)
79          *  @param s Size of data, in bytes.
80          */
81         LocallyEncodedData (uint8_t* d, int s);
82 };
83
84 /** @class RemotelyEncodedData
85  *  @brief EncodedData that is being read from a remote server;
86  *  this class allocates and manages memory for the data.
87  */
88 class RemotelyEncodedData : public EncodedData
89 {
90 public:
91         RemotelyEncodedData (int s);
92 };
93
94 /** @class DCPVideoFrame
95  *  @brief A single frame of video destined for a DCP.
96  *
97  *  Given an Image and some settings, this class knows how to encode
98  *  the image to J2K either on the local host or on a remote server.
99  *
100  *  Objects of this class are used for the queue that we keep
101  *  of images that require encoding.
102  */
103 class DCPVideoFrame : public boost::noncopyable
104 {
105 public:
106         DCPVideoFrame (boost::shared_ptr<const PlayerVideoFrame>, int, int, int, Resolution, boost::shared_ptr<Log>);
107         DCPVideoFrame (boost::shared_ptr<const PlayerVideoFrame>, boost::shared_ptr<const cxml::Node>, boost::shared_ptr<Log>);
108
109         boost::shared_ptr<EncodedData> encode_locally ();
110         boost::shared_ptr<EncodedData> encode_remotely (ServerDescription);
111
112         int index () const {
113                 return _index;
114         }
115
116         Eyes eyes () const;
117         
118 private:
119
120         void add_metadata (xmlpp::Element *) const;
121         
122         boost::shared_ptr<const PlayerVideoFrame> _frame;
123         int _index;                      ///< frame index within the DCP's intrinsic duration
124         int _frames_per_second;          ///< Frames per second that we will use for the DCP
125         int _j2k_bandwidth;              ///< J2K bandwidth to use
126         Resolution _resolution;          ///< Resolution (2K or 4K)
127
128         boost::shared_ptr<Log> _log; ///< log
129 };