ChangeLog.
[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 "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 FilmState;
29 class EncodeOptions;
30 class ServerDescription;
31 class Scaler;
32 class Image;
33 class Log;
34 class Subtitle;
35
36 /** @class EncodedData
37  *  @brief Container for J2K-encoded data.
38  */
39 class EncodedData
40 {
41 public:
42         /** @param d Data (will not be freed by this class, but may be by subclasses)
43          *  @param s libdcp::Size of data, in bytes.
44          */
45         EncodedData (uint8_t* d, int s)
46                 : _data (d)
47                 , _size (s)
48         {}
49
50         virtual ~EncodedData () {}
51
52         void send (boost::shared_ptr<Socket> socket);
53         void write (boost::shared_ptr<const EncodeOptions>, SourceFrame);
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 not be freed by this class)
79          *  @param s libdcp::Size of data, in bytes.
80          */
81         LocallyEncodedData (uint8_t* d, int s)
82                 : EncodedData (d, s)
83         {}
84 };
85
86 /** @class RemotelyEncodedData
87  *  @brief EncodedData that is being read from a remote server;
88  *  this class allocates and manages memory for the data.
89  */
90 class RemotelyEncodedData : public EncodedData
91 {
92 public:
93         RemotelyEncodedData (int s);
94         ~RemotelyEncodedData ();
95 };
96
97 /** @class DCPVideoFrame
98  *  @brief A single frame of video destined for a DCP.
99  *
100  *  Given an Image and some settings, this class knows how to encode
101  *  the image to J2K either on the local host or on a remote server.
102  *
103  *  Objects of this class are used for the queue that we keep
104  *  of images that require encoding.
105  */
106 class DCPVideoFrame
107 {
108 public:
109         DCPVideoFrame (
110                 boost::shared_ptr<const Image>, boost::shared_ptr<Subtitle>, libdcp::Size,
111                 int, int, float, Scaler const *, SourceFrame, float, std::string, int, int, Log *
112                 );
113         
114         virtual ~DCPVideoFrame ();
115
116         boost::shared_ptr<EncodedData> encode_locally ();
117         boost::shared_ptr<EncodedData> encode_remotely (ServerDescription const *);
118
119         SourceFrame frame () const {
120                 return _frame;
121         }
122         
123 private:
124         void create_openjpeg_container ();
125
126         boost::shared_ptr<const Image> _input; ///< the input image
127         boost::shared_ptr<Subtitle> _subtitle; ///< any subtitle that should be on the image
128         libdcp::Size _out_size;                  ///< the required size of the output, in pixels
129         int _padding;
130         int _subtitle_offset;
131         float _subtitle_scale;
132         Scaler const * _scaler;          ///< scaler to use
133         SourceFrame _frame;              ///< frame index within the Film's source
134         int _frames_per_second;          ///< Frames per second that we will use for the DCP (rounded)
135         std::string _post_process;       ///< FFmpeg post-processing string to use
136         int _colour_lut;                 ///< Colour look-up table to use
137         int _j2k_bandwidth;              ///< J2K bandwidth to use
138
139         Log* _log; ///< log
140
141         opj_image_cmptparm_t _cmptparm[3]; ///< libopenjpeg's opj_image_cmptparm_t
142         opj_image* _image;                 ///< libopenjpeg's image container 
143         opj_cparameters_t* _parameters;    ///< libopenjpeg's parameters
144         opj_cinfo_t* _cinfo;               ///< libopenjpeg's opj_cinfo_t
145         opj_cio_t* _cio;                   ///< libopenjpeg's opj_cio_t
146 };