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