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 /** @file src/smpte_subtitle_asset.h
36 * @brief SMPTESubtitleAsset class
40 #include "subtitle_asset.h"
41 #include "language_tag.h"
42 #include "local_time.h"
44 #include "crypto_context.h"
45 #include <boost/filesystem.hpp>
55 struct verify_invalid_language1;
56 struct verify_invalid_language2;
62 class SMPTELoadFontNode;
65 /** @class SMPTESubtitleAsset
66 * @brief A set of subtitles to be read and/or written in the SMPTE format
68 class SMPTESubtitleAsset : public SubtitleAsset, public MXF
71 SMPTESubtitleAsset ();
73 /** Construct a SMPTESubtitleAsset by reading an MXF or XML file
74 * @param file Filename
76 explicit SMPTESubtitleAsset (boost::filesystem::path file);
79 std::shared_ptr<const Asset>,
84 std::vector<std::shared_ptr<LoadFontNode>> load_font_nodes () const;
86 std::string xml_as_string () const;
88 /** Write this content to a MXF file */
89 void write (boost::filesystem::path path) const;
91 void add (std::shared_ptr<Subtitle>);
92 void add_font (std::string id, dcp::ArrayData data);
93 void set_key (Key key);
95 void set_content_title_text (std::string t) {
96 _content_title_text = t;
99 void set_language (dcp::LanguageTag l) {
100 _language = l.to_string();
103 void set_issue_date (LocalTime t) {
107 void set_reel_number (int r) {
111 void set_edit_rate (Fraction e) {
115 void set_time_code_rate (int t) {
119 void set_start_time (Time t) {
123 void set_intrinsic_duration (int64_t d) {
124 _intrinsic_duration = d;
127 int64_t intrinsic_duration () const {
128 return _intrinsic_duration;
131 /** @return title of the film that these subtitles are for,
132 * to be presented to the user
134 std::string content_title_text () const {
135 return _content_title_text;
138 /** @return Language, if one was set. This should be a xs:language, but
139 * it might not be if a non-compliant DCP was read in.
141 boost::optional<std::string> language () const {
145 /** @return annotation text, to be presented to the user */
146 boost::optional<std::string> annotation_text () const {
147 return _annotation_text;
150 /** @return file issue time and date */
151 LocalTime issue_date () const {
155 boost::optional<int> reel_number () const {
159 Fraction edit_rate () const {
163 /** @return subdivision of 1 second that is used for subtitle times;
164 * e.g. a time_code_rate of 250 means that a subtitle time of 0:0:0:001
167 int time_code_rate () const {
168 return _time_code_rate;
171 boost::optional<Time> start_time () const {
175 std::string xml_id () const {
179 /** @return ResourceID read from the MXF, if there was one */
180 boost::optional<std::string> resource_id () const {
184 static bool valid_mxf (boost::filesystem::path);
185 static std::string static_pkl_type (Standard) {
186 return "application/mxf";
191 std::string pkl_type (Standard s) const {
192 return static_pkl_type (s);
196 friend struct ::write_smpte_subtitle_test;
197 friend struct ::write_smpte_subtitle_test2;
198 friend struct ::verify_invalid_language1;
199 friend struct ::verify_invalid_language2;
201 void read_fonts (std::shared_ptr<ASDCP::TimedText::MXFReader>);
202 void parse_xml (std::shared_ptr<cxml::Document> xml);
203 void read_mxf_descriptor (std::shared_ptr<ASDCP::TimedText::MXFReader> reader, std::shared_ptr<DecryptionContext> dec);
205 /** The total length of this content in video frames. The amount of
206 * content presented may be less than this.
208 int64_t _intrinsic_duration = 0;
209 /** <ContentTitleText> from the asset */
210 std::string _content_title_text;
211 /** This is stored and returned as a string so that we can tolerate non-RFC-5646 strings,
212 * but must be set as a dcp::LanguageTag to try to ensure that we create compliant output.
214 boost::optional<std::string> _language;
215 boost::optional<std::string> _annotation_text;
216 LocalTime _issue_date;
217 boost::optional<int> _reel_number;
219 int _time_code_rate = 0;
220 boost::optional<Time> _start_time;
222 std::vector<std::shared_ptr<SMPTELoadFontNode>> _load_font_nodes;
223 /** UUID for the XML inside the MXF, which should be the same as the ResourceID in the MXF (our _resource_id)
224 * but different to the AssetUUID in the MXF (our _id) according to SMPTE Bv2.1 and Doremi's 2.8.18 release notes.
228 /** ResourceID read from the MXF, if there was one */
229 boost::optional<std::string> _resource_id;