A few comment fixes.
[libdcp.git] / src / picture_asset.h
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef LIBDCP_PICTURE_ASSET_H
21 #define LIBDCP_PICTURE_ASSET_H
22
23 /** @file  src/picture_asset.h
24  *  @brief An asset made up of JPEG2000 data
25  */
26
27 #include <openjpeg.h>
28 #include "mxf_asset.h"
29 #include "util.h"
30 #include "metadata.h"
31
32 namespace libdcp
33 {
34
35 class MonoPictureFrame; 
36 class StereoPictureFrame;
37 class PictureAssetWriter;
38
39 /** @brief An asset made up of JPEG2000 data */
40 class PictureAsset : public MXFAsset
41 {
42 public:
43         /** Construct a PictureAsset.
44          *  This class will not write anything to disk in this constructor, but subclasses may.
45          *  
46          *  @param directory Directory where MXF file is.
47          *  @param mxf_name Name of MXF file.
48          */
49         PictureAsset (std::string directory, std::string mxf_name);
50
51         /** Construct a PictureAsset.
52          *  This class will not write anything to disk in this constructor, but subclasses may.
53          *
54          *  @param directory Directory where MXF file is.
55          *  @param mxf_name Name of MXF file.
56          *  @param progress Signal to use to inform of progres, or 0.
57          *  @param fps Video frames per second.
58          *  @param intrinsic_duration Total number of frames in the asset.
59          *  @param size Size of video frame images in pixels.
60          */
61         PictureAsset (
62                 std::string directory,
63                 std::string mxf_name,
64                 boost::signals2::signal<void (float)>* progress,
65                 int fps,
66                 int intrinsic_duration,
67                 bool encrypted,
68                 Size
69                 );
70
71         /** Start a progressive write to this asset.
72          *  @param overwrite true to overwrite an existing MXF file; in this mode, writing can be resumed to a partially-written MXF; false if the
73          *  MXF file does not exist.
74          *  @param metadata MXF metadata to use.
75          */
76         virtual boost::shared_ptr<PictureAssetWriter> start_write (bool overwrite, MXFMetadata const & metadata = MXFMetadata ()) = 0;
77         
78         bool equals (boost::shared_ptr<const Asset> other, EqualityOptions opt, boost::function<void (NoteType, std::string)> note) const;
79
80         Size size () const {
81                 return _size;
82         }
83
84         void write_to_cpl (xmlpp::Node *) const;
85
86 protected:      
87
88         bool frame_buffer_equals (
89                 int frame, EqualityOptions opt, boost::function<void (NoteType, std::string)> note,
90                 uint8_t const * data_A, unsigned int size_A, uint8_t const * data_B, unsigned int size_B
91                 ) const;
92
93         /** picture size in pixels */
94         Size _size;
95
96 private:
97         std::string key_type () const;
98         std::string cpl_node_name () const = 0;
99         virtual int edit_rate_factor () const = 0;
100 };
101
102 /** A 2D (monoscopic) picture asset */
103 class MonoPictureAsset : public PictureAsset
104 {
105 public:
106         /** Construct a MonoPictureAsset, generating the MXF from the JPEG2000 files.
107          *  This may take some time; progress is indicated by emission of the Progress signal.
108          *
109          *  @param files Pathnames of JPEG2000 files, in frame order.
110          *  @param directory Directory in which to create MXF file.
111          *  @param mxf_name Name of MXF file to create.
112          *  @param progress Signal to inform of progress.
113          *  @param fps Video frames per second.
114          *  @param intrinsic_duration Total number of frames in the asset.
115          *  @param size Size of images in pixels.
116          *  @param encrypted true if asset should be encrypted.
117          */
118         MonoPictureAsset (
119                 std::vector<std::string> const & files,
120                 std::string directory,
121                 std::string mxf_name,
122                 boost::signals2::signal<void (float)>* progress,
123                 int fps,
124                 int intrinsic_duration,
125                 bool encrypted,
126                 Size size,
127                 MXFMetadata const & metadata = MXFMetadata ()
128                 );
129
130         /** Construct a MonoPictureAsset, generating the MXF from the JPEG2000 files.
131          *  This may take some time; progress is indicated by emission of the Progress signal.
132          *
133          *  @param get_path Functor which returns a JPEG2000 file path for a given frame (frames counted from 0).
134          *  @param directory Directory in which to create MXF file.
135          *  @param mxf_name Name of MXF file to create.
136          *  @param progress Signal to inform of progress.
137          *  @param fps Video frames per second.
138          *  @param intrinsic_duration Total number of frames in the asset.
139          *  @param size Size of images in pixels.
140          *  @param encrypted true if asset should be encrypted.
141          */
142         MonoPictureAsset (
143                 boost::function<std::string (int)> get_path,
144                 std::string directory,
145                 std::string mxf_name,
146                 boost::signals2::signal<void (float)>* progress,
147                 int fps,
148                 int intrinsic_duration,
149                 bool encrypted,
150                 Size size,
151                 MXFMetadata const & metadata = MXFMetadata ()
152                 );
153
154         /** Construct a MonoPictureAsset, reading the MXF from disk.
155          *  @param directory Directory that the MXF is in.
156          *  @param mxf_name The filename of the MXF within `directory'.
157          */
158         MonoPictureAsset (std::string directory, std::string mxf_name);
159
160         /** Construct a MonoPictureAsset for progressive writing using
161          *  start_write() and a MonoPictureAssetWriter.
162          *
163          *  @param directory Directory to put the MXF in.
164          *  @param mxf_name Filename of the MXF within this directory.
165          *  @param fps Video frames per second.
166          *  @param size Size in pixels that the picture frames will be.
167          */
168         MonoPictureAsset (std::string directory, std::string mxf_name, int fps, Size size);
169
170         /** Start a progressive write to a MonoPictureAsset */
171         boost::shared_ptr<PictureAssetWriter> start_write (bool, MXFMetadata const & metadata = MXFMetadata ());
172
173         boost::shared_ptr<const MonoPictureFrame> get_frame (int n) const;
174         bool equals (boost::shared_ptr<const Asset> other, EqualityOptions opt, boost::function<void (NoteType, std::string)> note) const;
175
176 private:
177         std::string path_from_list (int f, std::vector<std::string> const & files) const;
178         void construct (boost::function<std::string (int)>, MXFMetadata const &);
179         std::string cpl_node_name () const;
180         int edit_rate_factor () const;
181 };
182
183 /** A 3D (stereoscopic) picture asset */        
184 class StereoPictureAsset : public PictureAsset
185 {
186 public:
187         StereoPictureAsset (std::string directory, std::string mxf_name, int fps, int intrinsic_duration);
188
189         /** Construct a StereoPictureAsset for progressive writing using
190          *  start_write() and a StereoPictureAssetWriter.
191          *
192          *  @param directory Directory to put the MXF in.
193          *  @param mxf_name Filename of the MXF within this directory.
194          *  @param fps Video frames per second.
195          *  @param size Size in pixels that the picture frames will be.
196          */
197         StereoPictureAsset (std::string directory, std::string mxf_name, int fps, Size size);
198
199         /** Start a progressive write to a StereoPictureAsset */
200         boost::shared_ptr<PictureAssetWriter> start_write (bool, MXFMetadata const & metadata = MXFMetadata ());
201
202         boost::shared_ptr<const StereoPictureFrame> get_frame (int n) const;
203         bool equals (boost::shared_ptr<const Asset> other, EqualityOptions opt, boost::function<void (NoteType, std::string)> note) const;
204
205 private:
206         std::string cpl_node_name () const;
207         int edit_rate_factor () const;
208 };
209         
210
211 }
212
213 #endif