Tidying.
[libdcp.git] / src / smpte_subtitle_asset.h
1 /*
2     Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of libdcp.
5
6     libdcp is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     libdcp is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with libdcp.  If not, see <http://www.gnu.org/licenses/>.
18
19     In addition, as a special exception, the copyright holders give
20     permission to link the code of portions of this program with the
21     OpenSSL library under certain conditions as described in each
22     individual source file, and distribute linked combinations
23     including the two.
24
25     You must obey the GNU General Public License in all respects
26     for all of the code used other than OpenSSL.  If you modify
27     file(s) with this exception, you may extend this exception to your
28     version of the file(s), but you are not obligated to do so.  If you
29     do not wish to do so, delete this exception statement from your
30     version.  If you delete this exception statement from all source
31     files in the program, then also delete it here.
32 */
33
34
35 /** @file  src/smpte_subtitle_asset.h
36  *  @brief SMPTESubtitleAsset class
37  */
38
39
40 #include "subtitle_asset.h"
41 #include "language_tag.h"
42 #include "local_time.h"
43 #include "mxf.h"
44 #include "crypto_context.h"
45 #include <boost/filesystem.hpp>
46
47
48 namespace ASDCP {
49         namespace TimedText {
50                 class MXFReader;
51         }
52 }
53
54
55 struct verify_invalid_language1;
56 struct verify_invalid_language2;
57
58
59 namespace dcp {
60
61
62 class SMPTELoadFontNode;
63
64
65 /** @class SMPTESubtitleAsset
66  *  @brief A set of subtitles to be read and/or written in the SMPTE format
67  */
68 class SMPTESubtitleAsset : public SubtitleAsset, public MXF
69 {
70 public:
71         SMPTESubtitleAsset ();
72
73         /** Construct a SMPTESubtitleAsset by reading an MXF or XML file
74          *  @param file Filename
75          */
76         explicit SMPTESubtitleAsset (boost::filesystem::path file);
77
78         bool equals (
79                 std::shared_ptr<const Asset>,
80                 EqualityOptions,
81                 NoteHandler note
82                 ) const;
83
84         std::vector<std::shared_ptr<LoadFontNode>> load_font_nodes () const;
85
86         std::string xml_as_string () const;
87
88         /** Write this content to a MXF file */
89         void write (boost::filesystem::path path) const;
90
91         void add (std::shared_ptr<Subtitle>);
92         void add_font (std::string id, dcp::ArrayData data);
93         void set_key (Key key);
94
95         void set_content_title_text (std::string t) {
96                 _content_title_text = t;
97         }
98
99         void set_language (dcp::LanguageTag l) {
100                 _language = l.to_string();
101         }
102
103         void set_issue_date (LocalTime t) {
104                 _issue_date = t;
105         }
106
107         void set_reel_number (int r) {
108                 _reel_number = r;
109         }
110
111         void set_edit_rate (Fraction e) {
112                 _edit_rate = e;
113         }
114
115         void set_time_code_rate (int t) {
116                 _time_code_rate = t;
117         }
118
119         void set_start_time (Time t) {
120                 _start_time = t;
121         }
122
123         void set_intrinsic_duration (int64_t d) {
124                 _intrinsic_duration = d;
125         }
126
127         /** @return title of the film that these subtitles are for,
128          *  to be presented to the user
129          */
130         std::string content_title_text () const {
131                 return _content_title_text;
132         }
133
134         /** @return Language, if one was set.  This should be a xs:language, but
135          *  it might not be if a non-compliant DCP was read in.
136          */
137         boost::optional<std::string> language () const {
138                 return _language;
139         }
140
141         /** @return annotation text, to be presented to the user */
142         boost::optional<std::string> annotation_text () const {
143                 return _annotation_text;
144         }
145
146         /** @return file issue time and date */
147         LocalTime issue_date () const {
148                 return _issue_date;
149         }
150
151         boost::optional<int> reel_number () const {
152                 return _reel_number;
153         }
154
155         Fraction edit_rate () const {
156                 return _edit_rate;
157         }
158
159         /** @return subdivision of 1 second that is used for subtitle times;
160          *  e.g. a time_code_rate of 250 means that a subtitle time of 0:0:0:001
161          *  represents 4ms.
162          */
163         int time_code_rate () const {
164                 return _time_code_rate;
165         }
166
167         boost::optional<Time> start_time () const {
168                 return _start_time;
169         }
170
171         std::string xml_id () const {
172                 return _xml_id;
173         }
174
175         static bool valid_mxf (boost::filesystem::path);
176         static std::string static_pkl_type (Standard) {
177                 return "application/mxf";
178         }
179
180 protected:
181
182         std::string pkl_type (Standard s) const {
183                 return static_pkl_type (s);
184         }
185
186 private:
187         friend struct ::write_smpte_subtitle_test;
188         friend struct ::write_smpte_subtitle_test2;
189         friend struct ::verify_invalid_language1;
190         friend struct ::verify_invalid_language2;
191
192         void read_fonts (std::shared_ptr<ASDCP::TimedText::MXFReader>);
193         void parse_xml (std::shared_ptr<cxml::Document> xml);
194         void read_mxf_descriptor (std::shared_ptr<ASDCP::TimedText::MXFReader> reader, std::shared_ptr<DecryptionContext> dec);
195
196         /** The total length of this content in video frames.  The amount of
197          *  content presented may be less than this.
198          */
199         int64_t _intrinsic_duration = 0;
200         /** <ContentTitleText> from the asset */
201         std::string _content_title_text;
202         /** This is stored and returned as a string so that we can tolerate non-RFC-5646 strings,
203          *  but must be set as a dcp::LanguageTag to try to ensure that we create compliant output.
204          */
205         boost::optional<std::string> _language;
206         boost::optional<std::string> _annotation_text;
207         LocalTime _issue_date;
208         boost::optional<int> _reel_number;
209         Fraction _edit_rate;
210         int _time_code_rate = 0;
211         boost::optional<Time> _start_time;
212
213         std::vector<std::shared_ptr<SMPTELoadFontNode>> _load_font_nodes;
214         /** UUID for the XML inside the MXF, which should be different to the ID of the MXF according to
215          *  Doremi's 2.8.18 release notes.
216          */
217         std::string _xml_id;
218 };
219
220
221 }