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"
34 class MonoPictureFrame;
35 class StereoPictureFrame;
37 /** @brief An asset made up of JPEG2000 files */
38 class PictureAsset : public MXFAsset
41 /** Construct a PictureAsset.
42 * This class will not write anything to disk in this constructor, but subclasses may.
44 * @param directory Directory where MXF file is.
45 * @param mxf_name Name of MXF file.
47 PictureAsset (std::string directory, std::string mxf_name);
49 /** Construct a PictureAsset.
50 * This class will not write anything to disk in this constructor, but subclasses may.
52 * @param directory Directory where MXF file is.
53 * @param mxf_name Name of MXF file.
54 * @param progress Signal to use to inform of progres, or 0.
55 * @param fps Video Frames per second.
56 * @param intrinsic_duration Duration of all the frames in the asset.
57 * @param size Size of video frame images in pixels.
59 PictureAsset (std::string directory, std::string mxf_name, boost::signals2::signal<void (float)>* progress, int fps, int intrinsic_duration, Size size);
61 /** Write details of this asset to a CPL stream.
64 void write_to_cpl (std::ostream& s) const;
66 bool equals (boost::shared_ptr<const Asset> other, EqualityOptions opt, std::list<std::string>& notes) const;
74 bool frame_buffer_equals (
75 int frame, EqualityOptions opt, std::list<std::string>& notes,
76 uint8_t const * data_A, unsigned int size_A, uint8_t const * data_B, unsigned int size_B
79 /** picture size in pixels */
83 class MonoPictureAsset;
87 FrameInfo (uint64_t o, uint64_t l, std::string h)
93 FrameInfo (std::istream& s);
95 void write (std::ostream& s);
102 /** A helper class for writing to MonoPictureAssets progressively (i.e. writing frame-by-frame,
103 * rather than giving libdcp all the frames in one go).
105 * Objects of this class can only be created with MonoPictureAsset::start_write().
107 * Frames can be written to the MonoPictureAsset by calling write() with a JPEG2000 image
108 * (a verbatim .j2 file). finalize() must be called after the last frame has been written.
109 * The action of finalize() can't be done in MonoPictureAssetWriter's destructor as it may
110 * throw an exception.
112 class MonoPictureAssetWriter
115 ~MonoPictureAssetWriter ();
117 FrameInfo write (uint8_t* data, int size);
121 friend class MonoPictureAsset;
123 MonoPictureAssetWriter (MonoPictureAsset *);
125 /* no copy construction */
126 MonoPictureAssetWriter (MonoPictureAssetWriter const &);
127 MonoPictureAssetWriter& operator= (MonoPictureAssetWriter const &);
129 /* do this with an opaque pointer so we don't have to include
134 boost::shared_ptr<ASDCPState> _state;
136 MonoPictureAsset* _asset;
137 /** Number of picture frames written to the asset so far */
139 /** true if finalize() has been called */
143 /** A 2D (monoscopic) picture asset */
144 class MonoPictureAsset : public PictureAsset
147 /** Construct a MonoPictureAsset, generating the MXF from the JPEG2000 files.
148 * This may take some time; progress is indicated by emission of the Progress signal.
150 * @param files Pathnames of JPEG2000 files, in frame order.
151 * @param directory Directory in which to create MXF file.
152 * @param mxf_name Name of MXF file to create.
153 * @param progress Signal to inform of progress.
154 * @param fps Video frames per second.
155 * @param intrinsic_duration Length of the whole asset in frames.
156 * @param size Size of images in pixels.
159 std::vector<std::string> const & files,
160 std::string directory,
161 std::string mxf_name,
162 boost::signals2::signal<void (float)>* progress,
164 int intrinsic_duration,
168 /** Construct a MonoPictureAsset, generating the MXF from the JPEG2000 files.
169 * This may take some time; progress is indicated by emission of the Progress signal.
171 * @param get_path Functor which returns a JPEG2000 file path for a given frame (frames counted from 0).
172 * @param directory Directory in which to create MXF file.
173 * @param mxf_name Name of MXF file to create.
174 * @param progress Signal to inform of progress.
175 * @param fps Video frames per second.
176 * @param intrinsic_duration Length of the whole asset in frames.
177 * @param size Size of images in pixels.
180 boost::function<std::string (int)> get_path,
181 std::string directory,
182 std::string mxf_name,
183 boost::signals2::signal<void (float)>* progress,
185 int intrinsic_duration,
189 /** Construct a MonoPictureAsset, reading the MXF from disk.
190 * @param directory Directory that the MXF is in.
191 * @param mxf_name The filename of the MXF within `directory'.
193 MonoPictureAsset (std::string directory, std::string mxf_name);
195 /** Construct a MonoPictureAsset for progressive writing using
196 * start_write() and a MonoPictureAssetWriter.
198 * @param directory Directory to put the MXF in.
199 * @param mxf_name Filename of the MXF within this directory.
200 * @param fps Video frames per second.
201 * @param size Size in pixels that the picture frames will be.
203 MonoPictureAsset (std::string directory, std::string mxf_name, int fps, Size size);
205 /** Start a progressive write to a MonoPictureAsset */
206 boost::shared_ptr<MonoPictureAssetWriter> start_write ();
208 boost::shared_ptr<const MonoPictureFrame> get_frame (int n) const;
209 bool equals (boost::shared_ptr<const Asset> other, EqualityOptions opt, std::list<std::string>& notes) const;
212 std::string path_from_list (int f, std::vector<std::string> const & files) const;
213 void construct (boost::function<std::string (int)>);
216 /** A 3D (stereoscopic) picture asset */
217 class StereoPictureAsset : public PictureAsset
220 StereoPictureAsset (std::string directory, std::string mxf_name, int fps, int intrinsic_duration);
222 boost::shared_ptr<const StereoPictureFrame> get_frame (int n) const;
223 bool equals (boost::shared_ptr<const Asset> other, EqualityOptions opt, std::list<std::string>& notes) const;