Add a test corpus for XML.
[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 class Reel;
46
47 /** @class DCP dcp.h libdcp/dcp.h
48  *  @brief A class to create or read a DCP.
49  */
50         
51 class DCP
52 {
53 public:
54         /** Construct a DCP.
55          *
56          *  This is for making a new DCP that you are going to add assets to.
57          *
58          *  @param directory Directory to write files to.
59          *  @param name Name.
60          *  @param content_kind Content kind.
61          *  @param fps Frames per second.
62          *  @param length Length in frames.
63          */
64         DCP (std::string directory, std::string name, ContentKind content_kind, int fps, int length);
65
66         /** Construct a DCP object for an existing DCP.
67          *
68          *  The DCP's XML metadata will be examined, and you can then look at the contents
69          *  of the DCP.
70          *
71          *  @param directory Existing DCP's directory.
72          *  @param read_mxfs true to read MXF files; setting to false can be useful for testing, but
73          *  normally it should be set to true.
74          */
75         DCP (std::string directory, bool read_mxfs = true);
76
77         void add_reel (boost::shared_ptr<const Reel> reel);
78
79         /** Write the required XML files to the directory that was
80          *  passed into the constructor.
81          */
82         void write_xml () const;
83
84         /** @return the DCP's name, as will be presented on projector
85          *  media servers and theatre management systems.
86          */
87         std::string name () const {
88                 return _name;
89         }
90
91         /** @return the type of the content, used by media servers
92          *  to categorise things (e.g. feature, trailer, etc.)
93          */
94         ContentKind content_kind () const {
95                 return _content_kind;
96         }
97
98         /** @return the number of frames per second */
99         int frames_per_second () const {
100                 return _fps;
101         }
102
103         /** @return the length in frames */
104         int length () const {
105                 return _length;
106         }
107
108         std::list<boost::shared_ptr<const Reel> > reels () const {
109                 return _reels;
110         }
111
112         /** Compare this DCP with another, according to various options.
113          *  @param other DCP to compare this one to.
114          *  @param options Options to define just what "equality" means.
115          *  @return An empty list if the DCPs are equal; otherwise a list of messages
116          *  which explain the ways in which they differ.
117          */
118         std::list<std::string> equals (DCP const & other, EqualityOptions options) const;
119
120         /** Emitted with a parameter between 0 and 1 to indicate progress
121          *  for long jobs.
122          */
123         sigc::signal1<void, float> Progress;
124
125 private:
126
127         /** Write the CPL file.
128          *  @param cpl_uuid UUID to use.
129          *  @return CPL pathname.
130          */
131         std::string write_cpl (std::string cpl_uuid) const;
132
133         /** Write the PKL file.
134          *  @param pkl_uuid UUID to use.
135          *  @param cpl_uuid UUID of the CPL file.
136          *  @param cpl_digest SHA digest of the CPL file.
137          *  @param cpl_length Length of the CPL file in bytes.
138          */
139         std::string write_pkl (std::string pkl_uuid, std::string cpl_uuid, std::string cpl_digest, int cpl_length) const;
140         
141         /** Write the VOLINDEX file */
142         void write_volindex () const;
143
144         /** Write the ASSETMAP file.
145          *  @param cpl_uuid UUID of our CPL.
146          *  @param cpl_length Length of our CPL in bytes.
147          *  @param pkl_uuid UUID of our PKL.
148          *  @param pkl_length Length of our PKL in bytes.
149          */
150         void write_assetmap (std::string cpl_uuid, int cpl_length, std::string pkl_uuid, int pkl_length) const;
151
152         struct Files {
153                 std::string cpl;
154                 std::string pkl;
155                 std::string asset_map;
156                 std::list<std::string> subtitles;
157         };
158
159         void scan (Files& files, std::string directory) const;
160
161         /** the directory that we are writing to */
162         std::string _directory;
163         /** the name of the DCP */
164         std::string _name;
165         /** the content kind of the DCP */
166         ContentKind _content_kind;
167         /** frames per second */
168         int _fps;
169         /** length in frames */
170         int _length;
171         /** reels */
172         std::list<boost::shared_ptr<const Reel> > _reels;
173 };
174
175 }
176
177 #endif