libdcp
smpte_text_asset.h
Go to the documentation of this file.
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 #ifndef LIBDCP_SMPTE_TEXT_ASSET_H
36 #define LIBDCP_SMPTE_TEXT_ASSET_H
37 
38 
44 #include "crypto_context.h"
45 #include "language_tag.h"
46 #include "local_time.h"
47 #include "mxf.h"
48 #include "text_asset.h"
49 #include "subtitle_standard.h"
50 #include <boost/filesystem.hpp>
51 
52 
53 namespace ASDCP {
54  namespace TimedText {
55  class MXFReader;
56  }
57 }
58 
59 
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;
64 
65 
66 namespace dcp {
67 
68 
69 class SMPTELoadFontNode;
70 
71 
75 class SMPTETextAsset : public TextAsset, public MXF
76 {
77 public:
78  explicit SMPTETextAsset(SubtitleStandard standard = SubtitleStandard::SMPTE_2014);
79 
83  explicit SMPTETextAsset(boost::filesystem::path file);
84 
85  bool equals (
86  std::shared_ptr<const Asset>,
87  EqualityOptions const&,
88  NoteHandler note
89  ) const override;
90 
91  std::vector<std::shared_ptr<LoadFontNode>> load_font_nodes () const override;
92 
93  std::string xml_as_string () const override;
94 
96  void write (boost::filesystem::path path) const override;
97 
98  void add(std::shared_ptr<Text>) override;
99  void add_font (std::string id, dcp::ArrayData data) override;
100  void set_key (Key key) override;
101 
102  void set_content_title_text (std::string t) {
104  }
105 
106  void set_language (dcp::LanguageTag l) {
107  _language = l.to_string();
108  }
109 
110  void set_issue_date (LocalTime t) {
111  _issue_date = t;
112  }
113 
114  void set_reel_number (int r) {
115  _reel_number = r;
116  }
117 
118  void set_edit_rate (Fraction e) {
119  _edit_rate = e;
120  }
121 
122  void set_time_code_rate (int t) {
123  _time_code_rate = t;
124  }
125 
126  void set_start_time (Time t) {
127  _start_time = t;
128  }
129 
130  void set_intrinsic_duration (int64_t d) {
132  }
133 
134  int64_t intrinsic_duration () const {
135  return _intrinsic_duration;
136  }
137 
141  std::string content_title_text () const {
142  return _content_title_text;
143  }
144 
148  boost::optional<std::string> language () const {
149  return _language;
150  }
151 
153  boost::optional<std::string> annotation_text () const {
154  return _annotation_text;
155  }
156 
159  return _issue_date;
160  }
161 
162  boost::optional<int> reel_number () const {
163  return _reel_number;
164  }
165 
166  Fraction edit_rate () const {
167  return _edit_rate;
168  }
169 
174  int time_code_rate () const override {
175  return _time_code_rate;
176  }
177 
178  boost::optional<Time> start_time () const {
179  return _start_time;
180  }
181 
185  boost::optional<std::string> xml_id () const {
186  return _xml_id;
187  }
188 
190  boost::optional<std::string> resource_id () const {
191  return _resource_id;
192  }
193 
194  SubtitleStandard subtitle_standard() const override {
195  return _subtitle_standard;
196  }
197 
198  static bool valid_mxf (boost::filesystem::path);
199  static std::string static_pkl_type (Standard) {
200  return "application/mxf";
201  }
202 
203 protected:
204 
205  std::string pkl_type (Standard s) const override {
206  return static_pkl_type (s);
207  }
208 
209 private:
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;
216 
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;
222 
226  int64_t _intrinsic_duration = 0;
228  std::string _content_title_text;
232  boost::optional<std::string> _language;
233  boost::optional<std::string> _annotation_text;
234  LocalTime _issue_date;
235  boost::optional<int> _reel_number;
236  Fraction _edit_rate;
237  int _time_code_rate = 0;
238  boost::optional<Time> _start_time;
244  SubtitleStandard _subtitle_standard;
245 
246  std::vector<std::shared_ptr<SMPTELoadFontNode>> _load_font_nodes;
251  boost::optional<std::string> _xml_id;
252 
254  boost::optional<std::string> _resource_id;
255 };
256 
257 
258 }
259 
260 
261 #endif
Class to hold an arbitrary block of data.
Definition: array_data.h:55
boost::optional< boost::filesystem::path > file() const
Definition: asset.h:100
A class to describe what "equality" means for a particular test.
A fraction (i.e. a thing with an integer numerator and an integer denominator).
Definition: types.h:168
A key for decrypting/encrypting assets.
Definition: key.h:59
A representation of a local time (down to the second), including its offset from GMT (equivalent to x...
Definition: local_time.h:68
Parent for classes which represent MXF files.
Definition: mxf.h:74
boost::optional< Key > key() const
Definition: mxf.h:104
A set of subtitles/captions to be read and/or written in the SMPTE format.
boost::optional< std::string > _language
std::string _content_title_text
std::string pkl_type(Standard s) const override
boost::optional< std::string > language() const
boost::optional< std::string > xml_id() const
SubtitleStandard _subtitle_standard
LocalTime issue_date() const
boost::optional< std::string > _xml_id
boost::optional< std::string > annotation_text() const
int time_code_rate() const override
boost::optional< std::string > resource_id() const
void write(boost::filesystem::path path) const override
void set_key(Key key) override
boost::optional< std::string > _resource_id
std::string content_title_text() const
A parent for classes representing a file containing subtitles or captions.
Definition: text_asset.h:97
A representation of time within a DCP.
Definition: dcp_time.h:73
LanguageTag class.
LocalTime class.
MXF class.
Namespace for everything in libdcp.
Definition: array_data.h:50
TextAsset class.