Add OpenSSL licence exception.
[libdcp.git] / src / smpte_subtitle_asset.h
1 /*
2     Copyright (C) 2012-2015 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 /** @file  src/smpte_subtitle_asset.h
35  *  @brief SMPTESubtitleAsset class.
36  */
37
38 #include "subtitle_asset.h"
39 #include "local_time.h"
40 #include "mxf.h"
41 #include <boost/filesystem.hpp>
42
43 namespace ASDCP {
44         namespace TimedText {
45                 class MXFReader;
46         }
47 }
48
49 namespace dcp {
50
51 class SMPTELoadFontNode;
52
53 /** @class SMPTESubtitleAsset
54  *  @brief A set of subtitles to be read and/or written in the SMPTE format.
55  */
56 class SMPTESubtitleAsset : public SubtitleAsset, public MXF
57 {
58 public:
59         SMPTESubtitleAsset ();
60
61         /** @param file File name
62          */
63         explicit SMPTESubtitleAsset (boost::filesystem::path file);
64
65         bool equals (
66                 boost::shared_ptr<const Asset>,
67                 EqualityOptions,
68                 NoteHandler note
69                 ) const;
70
71         std::list<boost::shared_ptr<LoadFontNode> > load_font_nodes () const;
72
73         std::string xml_as_string () const;
74         void write (boost::filesystem::path path) const;
75         void add (SubtitleString);
76         void add_font (std::string id, boost::filesystem::path file);
77
78         void set_content_title_text (std::string t) {
79                 _content_title_text = t;
80         }
81
82         void set_language (std::string l) {
83                 _language = l;
84         }
85
86         void set_issue_date (LocalTime t) {
87                 _issue_date = t;
88         }
89
90         void set_reel_number (int r) {
91                 _reel_number = r;
92         }
93
94         void set_edit_rate (Fraction e) {
95                 _edit_rate = e;
96         }
97
98         void set_time_code_rate (int t) {
99                 _time_code_rate = t;
100         }
101
102         void set_start_time (Time t) {
103                 _start_time = t;
104         }
105
106         void set_intrinsic_duration (int64_t d) {
107                 _intrinsic_duration = d;
108         }
109
110         /** @return title of the film that these subtitles are for,
111          *  to be presented to the user.
112          */
113         std::string content_title_text () const {
114                 return _content_title_text;
115         }
116
117         /** @return language as a xs:language, if one was specified */
118         boost::optional<std::string> language () const {
119                 return _language;
120         }
121
122         /** @return annotation text, to be presented to the user */
123         boost::optional<std::string> annotation_text () const {
124                 return _annotation_text;
125         }
126
127         /** @return file creation time and date */
128         LocalTime issue_date () const {
129                 return _issue_date;
130         }
131
132         boost::optional<int> reel_number () const {
133                 return _reel_number;
134         }
135
136         Fraction edit_rate () const {
137                 return _edit_rate;
138         }
139
140         /** @return subdivision of 1 second that is used for subtitle times;
141          *  e.g. a time_code_rate of 250 means that a subtitle time of 0:0:0:001
142          *  represents 4ms.
143          */
144         int time_code_rate () const {
145                 return _time_code_rate;
146         }
147
148         boost::optional<Time> start_time () const {
149                 return _start_time;
150         }
151
152         static bool valid_mxf (boost::filesystem::path);
153
154 protected:
155
156         std::string pkl_type (Standard) const {
157                 return "application/mxf";
158         }
159
160 private:
161         void read_fonts (boost::shared_ptr<ASDCP::TimedText::MXFReader>);
162
163         /** The total length of this content in video frames.  The amount of
164          *  content presented may be less than this.
165          */
166         int64_t _intrinsic_duration;
167         std::string _content_title_text;
168         boost::optional<std::string> _language;
169         boost::optional<std::string> _annotation_text;
170         LocalTime _issue_date;
171         boost::optional<int> _reel_number;
172         Fraction _edit_rate;
173         int _time_code_rate;
174         boost::optional<Time> _start_time;
175
176         std::list<boost::shared_ptr<SMPTELoadFontNode> > _load_font_nodes;
177 };
178
179 }