2 Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
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.
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.
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/>.
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
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.
35 #ifndef LIBDCP_SMPTE_SUBTITLE_ASSET_H
36 #define LIBDCP_SMPTE_SUBTITLE_ASSET_H
39 /** @file src/smpte_subtitle_asset.h
40 * @brief SMPTESubtitleAsset class
44 #include "crypto_context.h"
45 #include "language_tag.h"
46 #include "local_time.h"
48 #include "subtitle_asset.h"
49 #include "subtitle_standard.h"
50 #include <boost/filesystem.hpp>
60 struct verify_invalid_language1;
61 struct verify_invalid_language2;
62 struct write_subtitles_in_vertical_order_with_top_alignment;
63 struct write_subtitles_in_vertical_order_with_bottom_alignment;
69 class SMPTELoadFontNode;
72 /** @class SMPTESubtitleAsset
73 * @brief A set of subtitles to be read and/or written in the SMPTE format
75 class SMPTESubtitleAsset : public SubtitleAsset, public MXF
78 explicit SMPTESubtitleAsset(SubtitleStandard standard = SubtitleStandard::SMPTE_2014);
80 /** Construct a SMPTESubtitleAsset by reading an MXF or XML file
81 * @param file Filename
83 explicit SMPTESubtitleAsset (boost::filesystem::path file);
86 std::shared_ptr<const Asset>,
87 EqualityOptions const&,
91 std::vector<std::shared_ptr<LoadFontNode>> load_font_nodes () const override;
93 std::string xml_as_string () const override;
95 /** Write this content to a MXF file */
96 void write (boost::filesystem::path path) const override;
98 void add (std::shared_ptr<Subtitle>) override;
99 void add_font (std::string id, dcp::ArrayData data) override;
100 void set_key (Key key) override;
102 void set_content_title_text (std::string t) {
103 _content_title_text = t;
106 void set_language (dcp::LanguageTag l) {
107 _language = l.to_string();
110 void set_issue_date (LocalTime t) {
114 void set_reel_number (int r) {
118 void set_edit_rate (Fraction e) {
122 void set_time_code_rate (int t) {
126 void set_start_time (Time t) {
130 void set_intrinsic_duration (int64_t d) {
131 _intrinsic_duration = d;
134 int64_t intrinsic_duration () const {
135 return _intrinsic_duration;
138 /** @return title of the film that these subtitles are for,
139 * to be presented to the user
141 std::string content_title_text () const {
142 return _content_title_text;
145 /** @return Language, if one was set. This should be a xs:language, but
146 * it might not be if a non-compliant DCP was read in.
148 boost::optional<std::string> language () const {
152 /** @return annotation text, to be presented to the user */
153 boost::optional<std::string> annotation_text () const {
154 return _annotation_text;
157 /** @return file issue time and date */
158 LocalTime issue_date () const {
162 boost::optional<int> reel_number () const {
166 Fraction edit_rate () const {
170 /** @return subdivision of 1 second that is used for subtitle times;
171 * e.g. a time_code_rate of 250 means that a subtitle time of 0:0:0:001
174 int time_code_rate () const override {
175 return _time_code_rate;
178 boost::optional<Time> start_time () const {
182 /** @return ID from XML's <Id> tag, or the <Id> that will be used when writing the XML,
183 * or boost::none if this content is encrypted and no key is available.
185 boost::optional<std::string> xml_id () const {
189 /** @return ResourceID read from any MXF that was read */
190 boost::optional<std::string> resource_id () const {
194 SubtitleStandard subtitle_standard() const override {
195 return _subtitle_standard;
198 static bool valid_mxf (boost::filesystem::path);
199 static std::string static_pkl_type (Standard) {
200 return "application/mxf";
205 std::string pkl_type (Standard s) const override {
206 return static_pkl_type (s);
210 friend struct ::write_smpte_subtitle_test;
211 friend struct ::write_smpte_subtitle_test2;
212 friend struct ::verify_invalid_language1;
213 friend struct ::verify_invalid_language2;
214 friend struct ::write_subtitles_in_vertical_order_with_top_alignment;
215 friend struct ::write_subtitles_in_vertical_order_with_bottom_alignment;
217 void read_fonts (std::shared_ptr<ASDCP::TimedText::MXFReader>);
218 void parse_xml (std::shared_ptr<cxml::Document> xml);
219 void read_mxf_descriptor (std::shared_ptr<ASDCP::TimedText::MXFReader> reader);
220 void read_mxf_resources (std::shared_ptr<ASDCP::TimedText::MXFReader> reader, std::shared_ptr<DecryptionContext> dec);
221 std::string schema_namespace() const;
223 /** The total length of this content in video frames. The amount of
224 * content presented may be less than this.
226 int64_t _intrinsic_duration = 0;
227 /** <ContentTitleText> from the asset */
228 std::string _content_title_text;
229 /** This is stored and returned as a string so that we can tolerate non-RFC-5646 strings,
230 * but must be set as a dcp::LanguageTag to try to ensure that we create compliant output.
232 boost::optional<std::string> _language;
233 boost::optional<std::string> _annotation_text;
234 LocalTime _issue_date;
235 boost::optional<int> _reel_number;
237 int _time_code_rate = 0;
238 boost::optional<Time> _start_time;
239 /** There are two SMPTE standards describing subtitles, 428-7:2010 and 428-7:2014, and they
240 * have different interpretations of what Vposition means. Though libdcp does not need to
241 * know the difference, this variable stores the standard from the namespace that this asset was
242 * written with (or will be written with).
244 SubtitleStandard _subtitle_standard;
246 std::vector<std::shared_ptr<SMPTELoadFontNode>> _load_font_nodes;
247 /** UUID for the XML inside the MXF, which should be the same as the ResourceID in the MXF (our _resource_id)
248 * but different to the AssetUUID in the MXF (our _id) according to SMPTE Bv2.1 and Doremi's 2.8.18 release notes.
249 * May be boost::none if this object has been made from an encrypted object without a key.
251 boost::optional<std::string> _xml_id;
253 /** ResourceID read from the MXF, if there was one */
254 boost::optional<std::string> _resource_id;