Merge master.
[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 <dcp/picture_mxf_writer.h>
22 #include "util.h"
23
24 /** @file  src/dcp_video_frame.h
25  *  @brief A single frame of video destined for a DCP.
26  */
27
28 class Film;
29 class ServerDescription;
30 class Scaler;
31 class Image;
32 class Log;
33 class Subtitle;
34 class PlayerVideoFrame;
35
36 /** @class EncodedData
37  *  @brief Container for J2K-encoded data.
38  */
39 class EncodedData : public boost::noncopyable
40 {
41 public:
42         /** @param s Size of data, in bytes */
43         EncodedData (int s);
44
45         EncodedData (boost::filesystem::path);
46
47         virtual ~EncodedData ();
48
49         void send (boost::shared_ptr<Socket> socket);
50         void write (boost::shared_ptr<const Film>, int, Eyes) const;
51         void write_info (boost::shared_ptr<const Film>, int, Eyes, dcp::FrameInfo) const;
52
53         /** @return data */
54         uint8_t* data () const {
55                 return _data;
56         }
57
58         /** @return data size, in bytes */
59         int size () const {
60                 return _size;
61         }
62
63 protected:
64         uint8_t* _data; ///< data
65         int _size;      ///< data size in bytes
66 };
67
68 /** @class LocallyEncodedData
69  *  @brief EncodedData that was encoded locally; this class
70  *  just keeps a pointer to the data, but does no memory
71  *  management.
72  */
73 class LocallyEncodedData : public EncodedData
74 {
75 public:
76         /** @param d Data (which will be copied by this class)
77          *  @param s Size of data, in bytes.
78          */
79         LocallyEncodedData (uint8_t* d, int s);
80 };
81
82 /** @class RemotelyEncodedData
83  *  @brief EncodedData that is being read from a remote server;
84  *  this class allocates and manages memory for the data.
85  */
86 class RemotelyEncodedData : public EncodedData
87 {
88 public:
89         RemotelyEncodedData (int s);
90 };
91
92 /** @class DCPVideoFrame
93  *  @brief A single frame of video destined for a DCP.
94  *
95  *  Given an Image and some settings, this class knows how to encode
96  *  the image to J2K either on the local host or on a remote server.
97  *
98  *  Objects of this class are used for the queue that we keep
99  *  of images that require encoding.
100  */
101 class DCPVideoFrame : public boost::noncopyable
102 {
103 public:
104         DCPVideoFrame (boost::shared_ptr<const PlayerVideoFrame>, int, int, int, Resolution, boost::shared_ptr<Log>);
105         DCPVideoFrame (boost::shared_ptr<const PlayerVideoFrame>, cxml::ConstNodePtr, boost::shared_ptr<Log>);
106
107         boost::shared_ptr<EncodedData> encode_locally ();
108         boost::shared_ptr<EncodedData> encode_remotely (ServerDescription);
109
110         int index () const {
111                 return _index;
112         }
113
114         Eyes eyes () const;
115         
116 private:
117
118         void add_metadata (xmlpp::Element *) const;
119         
120         boost::shared_ptr<const PlayerVideoFrame> _frame;
121         int _index;                      ///< frame index within the DCP's intrinsic duration
122         int _frames_per_second;          ///< Frames per second that we will use for the DCP
123         int _j2k_bandwidth;              ///< J2K bandwidth to use
124         Resolution _resolution;          ///< Resolution (2K or 4K)
125
126         boost::shared_ptr<Log> _log; ///< log
127 };