924a9f4f5ea7444536487749ecb6138ed9906a47
[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
44 /** @class DCP dcp.h libdcp/dcp.h
45  *  @brief A class to create or read a DCP.
46  */
47         
48 class DCP
49 {
50 public:
51         /** Construct a DCP.
52          *  @param directory Directory to write files to.
53          *  @param name Name.
54          *  @param content_kind Content kind.
55          *  @param fps Frames per second.
56          *  @param length Length in frames.
57          */
58         DCP (std::string directory, std::string name, ContentKind content_kind, int fps, int length);
59
60         DCP (std::string directory);
61
62         /** Add a sound asset.
63          *  @param files Pathnames of WAV files to use in the order Left, Right,
64          *  Centre, Lfe (sub), Left surround, Right surround; not all files need
65          *  to be present.
66          */
67         void add_sound_asset (std::vector<std::string> const & files);
68
69         /** Add a sound asset.
70          *  @param get_path Functor to get the path to the WAV for a given channel.
71          *  @param channels Number of channels.
72          */
73         void add_sound_asset (sigc::slot<std::string, Channel> get_path, int channels);
74
75         /** Add a picture asset.
76          *  @param files Pathnames of JPEG2000 files, in frame order.
77          *  @param width Width of images in pixels.
78          *  @param height Height of images in pixels.
79          */
80         void add_picture_asset (std::vector<std::string> const & files, int width, int height);
81
82         /** Add a picture asset.
83          *  @param get_path Functor to get path to the JPEG2000 for a given frame.
84          *  @param width Width of images in pixels.
85          *  @param height Height of images in pixels.
86          */
87         void add_picture_asset (sigc::slot<std::string, int> get_path, int width, int height);
88
89         /** Write the required XML files to the directory that was
90          *  passed into the constructor.
91          */
92         void write_xml () const;
93
94         std::string name () const {
95                 return _name;
96         }
97
98         ContentKind content_kind () const {
99                 return _content_kind;
100         }
101
102         int frames_per_second () const {
103                 return _fps;
104         }
105
106         int length () const {
107                 return _length;
108         }
109
110         boost::shared_ptr<const PictureAsset> picture_asset () const;
111
112         std::list<std::string> equals (DCP const & other, EqualityOptions options) const;
113
114         /** Emitted with a parameter between 0 and 1 to indicate progress
115          *  for long jobs.
116          */
117         sigc::signal1<void, float> Progress;
118
119 private:
120
121         /** Write the CPL file.
122          *  @param cpl_uuid UUID to use.
123          *  @return CPL pathname.
124          */
125         std::string write_cpl (std::string cpl_uuid) const;
126
127         /** Write the PKL file.
128          *  @param pkl_uuid UUID to use.
129          *  @param cpl_uuid UUID of the CPL file.
130          *  @param cpl_digest SHA digest of the CPL file.
131          *  @param cpl_length Length of the CPL file in bytes.
132          */
133         std::string write_pkl (std::string pkl_uuid, std::string cpl_uuid, std::string cpl_digest, int cpl_length) const;
134         
135         /** Write the VOLINDEX file */
136         void write_volindex () const;
137
138         /** Write the ASSETMAP file.
139          *  @param cpl_uuid UUID of our CPL.
140          *  @param cpl_length Length of our CPL in bytes.
141          *  @param pkl_uuid UUID of our PKL.
142          *  @param pkl_length Length of our PKL in bytes.
143          */
144         void write_assetmap (std::string cpl_uuid, int cpl_length, std::string pkl_uuid, int pkl_length) const;
145
146         /** the directory that we are writing to */
147         std::string _directory;
148         /** the name of the DCP */
149         std::string _name;
150         /** the content kind of the DCP */
151         ContentKind _content_kind;
152         /** frames per second */
153         int _fps;
154         /** length in frames */
155         int _length;
156         /** assets */
157         std::list<boost::shared_ptr<Asset> > _assets;
158 };
159
160 }
161
162 #endif