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