libdcp
smpte_subtitle_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_SUBTITLE_ASSET_H
36 #define LIBDCP_SMPTE_SUBTITLE_ASSET_H
37 
38 
44 #include "subtitle_asset.h"
45 #include "language_tag.h"
46 #include "local_time.h"
47 #include "mxf.h"
48 #include "crypto_context.h"
49 #include <boost/filesystem.hpp>
50 
51 
52 namespace ASDCP {
53  namespace TimedText {
54  class MXFReader;
55  }
56 }
57 
58 
59 struct verify_invalid_language1;
60 struct verify_invalid_language2;
61 struct write_subtitles_in_vertical_order_with_top_alignment;
62 struct write_subtitles_in_vertical_order_with_bottom_alignment;
63 
64 
65 namespace dcp {
66 
67 
68 class SMPTELoadFontNode;
69 
70 
74 class SMPTESubtitleAsset : public SubtitleAsset, public MXF
75 {
76 public:
78 
82  explicit SMPTESubtitleAsset (boost::filesystem::path file);
83 
84  bool equals (
85  std::shared_ptr<const Asset>,
87  NoteHandler note
88  ) const override;
89 
90  std::vector<std::shared_ptr<LoadFontNode>> load_font_nodes () const override;
91 
92  std::string xml_as_string () const override;
93 
95  void write (boost::filesystem::path path) const override;
96 
97  void add (std::shared_ptr<Subtitle>) override;
98  void add_font (std::string id, dcp::ArrayData data) override;
99  void set_key (Key key) override;
100 
101  void set_content_title_text (std::string t) {
103  }
104 
105  void set_language (dcp::LanguageTag l) {
106  _language = l.to_string();
107  }
108 
109  void set_issue_date (LocalTime t) {
110  _issue_date = t;
111  }
112 
113  void set_reel_number (int r) {
114  _reel_number = r;
115  }
116 
117  void set_edit_rate (Fraction e) {
118  _edit_rate = e;
119  }
120 
121  void set_time_code_rate (int t) {
122  _time_code_rate = t;
123  }
124 
125  void set_start_time (Time t) {
126  _start_time = t;
127  }
128 
129  void set_intrinsic_duration (int64_t d) {
131  }
132 
133  int64_t intrinsic_duration () const {
134  return _intrinsic_duration;
135  }
136 
140  std::string content_title_text () const {
141  return _content_title_text;
142  }
143 
147  boost::optional<std::string> language () const {
148  return _language;
149  }
150 
152  boost::optional<std::string> annotation_text () const {
153  return _annotation_text;
154  }
155 
158  return _issue_date;
159  }
160 
161  boost::optional<int> reel_number () const {
162  return _reel_number;
163  }
164 
165  Fraction edit_rate () const {
166  return _edit_rate;
167  }
168 
173  int time_code_rate () const override {
174  return _time_code_rate;
175  }
176 
177  boost::optional<Time> start_time () const {
178  return _start_time;
179  }
180 
184  boost::optional<std::string> xml_id () const {
185  return _xml_id;
186  }
187 
189  boost::optional<std::string> resource_id () const {
190  return _resource_id;
191  }
192 
193  static bool valid_mxf (boost::filesystem::path);
194  static std::string static_pkl_type (Standard) {
195  return "application/mxf";
196  }
197 
198 protected:
199 
200  std::string pkl_type (Standard s) const override {
201  return static_pkl_type (s);
202  }
203 
204 private:
205  friend struct ::write_smpte_subtitle_test;
206  friend struct ::write_smpte_subtitle_test2;
207  friend struct ::verify_invalid_language1;
208  friend struct ::verify_invalid_language2;
209  friend struct ::write_subtitles_in_vertical_order_with_top_alignment;
210  friend struct ::write_subtitles_in_vertical_order_with_bottom_alignment;
211 
212  void read_fonts (std::shared_ptr<ASDCP::TimedText::MXFReader>);
213  void parse_xml (std::shared_ptr<cxml::Document> xml);
214  void read_mxf_descriptor (std::shared_ptr<ASDCP::TimedText::MXFReader> reader);
215  void read_mxf_resources (std::shared_ptr<ASDCP::TimedText::MXFReader> reader, std::shared_ptr<DecryptionContext> dec);
216 
220  int64_t _intrinsic_duration = 0;
222  std::string _content_title_text;
226  boost::optional<std::string> _language;
227  boost::optional<std::string> _annotation_text;
228  LocalTime _issue_date;
229  boost::optional<int> _reel_number;
230  Fraction _edit_rate;
231  int _time_code_rate = 0;
232  boost::optional<Time> _start_time;
233 
234  std::vector<std::shared_ptr<SMPTELoadFontNode>> _load_font_nodes;
239  boost::optional<std::string> _xml_id;
240 
242  boost::optional<std::string> _resource_id;
243 };
244 
245 
246 }
247 
248 
249 #endif
Class to hold an arbitrary block of data.
Definition: array_data.h:55
boost::optional< boost::filesystem::path > file() const
Definition: asset.h:97
A fraction (i.e. a thing with an integer numerator and an integer denominator).
Definition: types.h:214
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:64
Parent for classes which represent MXF files.
Definition: mxf.h:74
boost::optional< Key > key() const
Definition: mxf.h:104
A set of subtitles to be read and/or written in the SMPTE format.
boost::optional< std::string > annotation_text() const
boost::optional< std::string > xml_id() const
std::string pkl_type(Standard s) const override
int time_code_rate() const override
boost::optional< std::string > resource_id() const
std::string content_title_text() const
void write(boost::filesystem::path path) const override
void set_key(Key key) override
boost::optional< std::string > _xml_id
boost::optional< std::string > language() const
boost::optional< std::string > _language
boost::optional< std::string > _resource_id
A parent for classes representing a file containing subtitles.
A representation of time within a DCP.
Definition: dcp_time.h:73
LocalTime class.
MXF class.
Namespace for everything in libdcp.
Definition: array_data.h:50
A class to describe what "equality" means for a particular test.
Definition: types.h:249
SubtitleAsset class.