2 Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
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.
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.
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.
20 #ifndef LIBDCP_PICTURE_ASSET_H
21 #define LIBDCP_PICTURE_ASSET_H
23 /** @file src/picture_asset.h
24 * @brief An asset made up of JPEG2000 files
28 #include "mxf_asset.h"
35 class MonoPictureFrame;
36 class StereoPictureFrame;
38 /** @brief An asset made up of JPEG2000 files */
39 class PictureAsset : public MXFAsset
42 /** Construct a PictureAsset.
43 * This class will not write anything to disk in this constructor, but subclasses may.
45 * @param directory Directory where MXF file is.
46 * @param mxf_name Name of MXF file.
48 PictureAsset (std::string directory, std::string mxf_name);
50 /** Construct a PictureAsset.
51 * This class will not write anything to disk in this constructor, but subclasses may.
53 * @param directory Directory where MXF file is.
54 * @param mxf_name Name of MXF file.
55 * @param progress Signal to use to inform of progres, or 0.
56 * @param fps Video Frames per second.
57 * @param intrinsic_duration Duration of all the frames in the asset.
58 * @param size Size of video frame images in pixels.
60 PictureAsset (std::string directory, std::string mxf_name, boost::signals2::signal<void (float)>* progress, int fps, int intrinsic_duration, bool encrypted, Size);
62 /** Write details of this asset to a CPL XML node.
65 void write_to_cpl (xmlpp::Node* node) const;
67 bool equals (boost::shared_ptr<const Asset> other, EqualityOptions opt, boost::function<void (NoteType, std::string)> note) const;
75 std::string key_type () const;
77 bool frame_buffer_equals (
78 int frame, EqualityOptions opt, boost::function<void (NoteType, std::string)> note,
79 uint8_t const * data_A, unsigned int size_A, uint8_t const * data_B, unsigned int size_B
82 /** picture size in pixels */
86 class MonoPictureAsset;
90 FrameInfo (uint64_t o, uint64_t s, std::string h)
96 FrameInfo (std::istream& s);
98 void write (std::ostream& s);
105 /** A helper class for writing to MonoPictureAssets progressively (i.e. writing frame-by-frame,
106 * rather than giving libdcp all the frames in one go).
108 * Objects of this class can only be created with MonoPictureAsset::start_write().
110 * Frames can be written to the MonoPictureAsset by calling write() with a JPEG2000 image
111 * (a verbatim .j2 file). finalize() must be called after the last frame has been written.
112 * The action of finalize() can't be done in MonoPictureAssetWriter's destructor as it may
113 * throw an exception.
115 class MonoPictureAssetWriter
118 FrameInfo write (uint8_t* data, int size);
119 void fake_write (int size);
123 friend class MonoPictureAsset;
125 MonoPictureAssetWriter (MonoPictureAsset *, bool, MXFMetadata const &);
126 void start (uint8_t *, int);
128 /* no copy construction */
129 MonoPictureAssetWriter (MonoPictureAssetWriter const &);
130 MonoPictureAssetWriter& operator= (MonoPictureAssetWriter const &);
132 /* do this with an opaque pointer so we don't have to include
137 boost::shared_ptr<ASDCPState> _state;
139 MonoPictureAsset* _asset;
140 /** Number of picture frames written to the asset so far */
143 /** true if finalize() has been called */
146 MXFMetadata _metadata;
149 /** A 2D (monoscopic) picture asset */
150 class MonoPictureAsset : public PictureAsset
153 /** Construct a MonoPictureAsset, generating the MXF from the JPEG2000 files.
154 * This may take some time; progress is indicated by emission of the Progress signal.
156 * @param files Pathnames of JPEG2000 files, in frame order.
157 * @param directory Directory in which to create MXF file.
158 * @param mxf_name Name of MXF file to create.
159 * @param progress Signal to inform of progress.
160 * @param fps Video frames per second.
161 * @param intrinsic_duration Length of the whole asset in frames.
162 * @param size Size of images in pixels.
163 * @param encrypted true if asset should be encrypted.
166 std::vector<std::string> const & files,
167 std::string directory,
168 std::string mxf_name,
169 boost::signals2::signal<void (float)>* progress,
171 int intrinsic_duration,
174 MXFMetadata const & metadata = MXFMetadata ()
177 /** Construct a MonoPictureAsset, generating the MXF from the JPEG2000 files.
178 * This may take some time; progress is indicated by emission of the Progress signal.
180 * @param get_path Functor which returns a JPEG2000 file path for a given frame (frames counted from 0).
181 * @param directory Directory in which to create MXF file.
182 * @param mxf_name Name of MXF file to create.
183 * @param progress Signal to inform of progress.
184 * @param fps Video frames per second.
185 * @param intrinsic_duration Length of the whole asset in frames.
186 * @param size Size of images in pixels.
187 * @param encrypted true if asset should be encrypted.
190 boost::function<std::string (int)> get_path,
191 std::string directory,
192 std::string mxf_name,
193 boost::signals2::signal<void (float)>* progress,
195 int intrinsic_duration,
198 MXFMetadata const & metadata = MXFMetadata ()
201 /** Construct a MonoPictureAsset, reading the MXF from disk.
202 * @param directory Directory that the MXF is in.
203 * @param mxf_name The filename of the MXF within `directory'.
205 MonoPictureAsset (std::string directory, std::string mxf_name);
207 /** Construct a MonoPictureAsset for progressive writing using
208 * start_write() and a MonoPictureAssetWriter.
210 * @param directory Directory to put the MXF in.
211 * @param mxf_name Filename of the MXF within this directory.
212 * @param fps Video frames per second.
213 * @param size Size in pixels that the picture frames will be.
215 MonoPictureAsset (std::string directory, std::string mxf_name, int fps, Size size);
217 /** Start a progressive write to a MonoPictureAsset */
218 boost::shared_ptr<MonoPictureAssetWriter> start_write (bool, MXFMetadata const & metadata = MXFMetadata ());
220 boost::shared_ptr<const MonoPictureFrame> get_frame (int n) const;
221 bool equals (boost::shared_ptr<const Asset> other, EqualityOptions opt, boost::function<void (NoteType, std::string)> note) const;
224 std::string path_from_list (int f, std::vector<std::string> const & files) const;
225 void construct (boost::function<std::string (int)>, MXFMetadata const &);
228 /** A 3D (stereoscopic) picture asset */
229 class StereoPictureAsset : public PictureAsset
232 StereoPictureAsset (std::string directory, std::string mxf_name, int fps, int intrinsic_duration);
234 boost::shared_ptr<const StereoPictureFrame> get_frame (int n) const;
235 bool equals (boost::shared_ptr<const Asset> other, EqualityOptions opt, boost::function<void (NoteType, std::string)> note) const;