Some comments.
[libdcp.git] / src / dcp.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 /** @file  src/dcp.h
21  *  @brief A class to create a DCP.
22  */
23
24 #ifndef LIBDCP_DCP_H
25 #define LIBDCP_DCP_H
26
27 #include <string>
28 #include <vector>
29 #include <boost/shared_ptr.hpp>
30 #include <sigc++/sigc++.h>
31 #include "types.h"
32
33 namespace xmlpp {
34         class Node;
35 }
36
37 /** @brief Namespace for everything in libdcp */
38 namespace libdcp
39 {
40
41 class Asset;    
42 class PictureAsset;
43 class SoundAsset;
44 class SubtitleAsset;
45
46 /** @class DCP dcp.h libdcp/dcp.h
47  *  @brief A class to create or read a DCP.
48  */
49         
50 class DCP
51 {
52 public:
53         /** Construct a DCP.
54          *
55          *  This is for making a new DCP that you are going to add assets to.
56          *
57          *  @param directory Directory to write files to.
58          *  @param name Name.
59          *  @param content_kind Content kind.
60          *  @param fps Frames per second.
61          *  @param length Length in frames.
62          */
63         DCP (std::string directory, std::string name, ContentKind content_kind, int fps, int length);
64
65         /** Construct a DCP object for an existing DCP.
66          *
67          *  The DCP's XML metadata will be examined, and you can then look at the contents
68          *  of the DCP.
69          *
70          *  @param directory Existing DCP's directory.
71          */
72         DCP (std::string directory);
73
74         /** Add a sound asset.
75          *  @param files Pathnames of WAV files to use in the order Left, Right,
76          *  Centre, Lfe (sub), Left surround, Right surround; not all files need
77          *  to be present.
78          */
79         void add_sound_asset (std::vector<std::string> const & files);
80
81         /** Add a sound asset.
82          *  @param get_path Functor to get the path to the WAV for a given channel.
83          *  @param channels Number of channels.
84          */
85         void add_sound_asset (sigc::slot<std::string, Channel> get_path, int channels);
86
87         /** Add a picture asset.
88          *  @param files Pathnames of JPEG2000 files, in frame order.
89          *  @param width Width of images in pixels.
90          *  @param height Height of images in pixels.
91          */
92         void add_picture_asset (std::vector<std::string> const & files, int width, int height);
93
94         /** Add a picture asset.
95          *  @param get_path Functor to get path to the JPEG2000 for a given frame.
96          *  @param width Width of images in pixels.
97          *  @param height Height of images in pixels.
98          */
99         void add_picture_asset (sigc::slot<std::string, int> get_path, int width, int height);
100
101         /** Write the required XML files to the directory that was
102          *  passed into the constructor.
103          */
104         void write_xml () const;
105
106         /** @return the DCP's name, as will be presented on projector
107          *  media servers and theatre management systems.
108          */
109         std::string name () const {
110                 return _name;
111         }
112
113         /** @return the type of the content, used by media servers
114          *  to categorise things (e.g. feature, trailer, etc.)
115          */
116         ContentKind content_kind () const {
117                 return _content_kind;
118         }
119
120         /** @return the number of frames per second */
121         int frames_per_second () const {
122                 return _fps;
123         }
124
125         /** @return the length in frames */
126         int length () const {
127                 return _length;
128         }
129
130         /** @return the main picture asset, if one exists, otherwise 0 */
131         boost::shared_ptr<const PictureAsset> picture_asset () const;
132         /** @return the main sound asset, if one exists, otherwise 0 */
133         boost::shared_ptr<const SoundAsset> sound_asset () const;
134         /** @return the main subtitle asset, if one exists, otherwise 0 */
135         boost::shared_ptr<const SubtitleAsset> subtitle_asset () const;
136
137         /** Compare this DCP with another, according to various options.
138          *  @param other DCP to compare this one to.
139          *  @param options Options to define just what "equality" means.
140          *  @return An empty list if the DCPs are equal; otherwise a list of messages
141          *  which explain the ways in which they differ.
142          */
143         std::list<std::string> equals (DCP const & other, EqualityOptions options) const;
144
145         /** Emitted with a parameter between 0 and 1 to indicate progress
146          *  for long jobs.
147          */
148         sigc::signal1<void, float> Progress;
149
150 private:
151
152         /** Write the CPL file.
153          *  @param cpl_uuid UUID to use.
154          *  @return CPL pathname.
155          */
156         std::string write_cpl (std::string cpl_uuid) const;
157
158         /** Write the PKL file.
159          *  @param pkl_uuid UUID to use.
160          *  @param cpl_uuid UUID of the CPL file.
161          *  @param cpl_digest SHA digest of the CPL file.
162          *  @param cpl_length Length of the CPL file in bytes.
163          */
164         std::string write_pkl (std::string pkl_uuid, std::string cpl_uuid, std::string cpl_digest, int cpl_length) const;
165         
166         /** Write the VOLINDEX file */
167         void write_volindex () const;
168
169         /** Write the ASSETMAP file.
170          *  @param cpl_uuid UUID of our CPL.
171          *  @param cpl_length Length of our CPL in bytes.
172          *  @param pkl_uuid UUID of our PKL.
173          *  @param pkl_length Length of our PKL in bytes.
174          */
175         void write_assetmap (std::string cpl_uuid, int cpl_length, std::string pkl_uuid, int pkl_length) const;
176
177         struct Files {
178                 std::string cpl;
179                 std::string pkl;
180                 std::string asset_map;
181                 std::list<std::string> subtitles;
182         };
183
184         void scan (Files& files, std::string directory) const;
185
186         /** the directory that we are writing to */
187         std::string _directory;
188         /** the name of the DCP */
189         std::string _name;
190         /** the content kind of the DCP */
191         ContentKind _content_kind;
192         /** frames per second */
193         int _fps;
194         /** length in frames */
195         int _length;
196         /** assets */
197         std::list<boost::shared_ptr<Asset> > _assets;
198 };
199
200 }
201
202 #endif