Use a HMAC context to write HMAC stuff to encrypted MXFs.
[libdcp.git] / src / smpte_subtitle_asset.h
1 /*
2     Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /** @file  src/smpte_subtitle_asset.h
21  *  @brief SMPTESubtitleAsset class.
22  */
23
24 #include "subtitle_asset.h"
25 #include "local_time.h"
26 #include "mxf.h"
27 #include <boost/filesystem.hpp>
28
29 namespace ASDCP {
30         namespace TimedText {
31                 class MXFReader;
32         }
33 }
34
35 namespace dcp {
36
37 class SMPTELoadFontNode;
38
39 /** @class SMPTESubtitleAsset
40  *  @brief A set of subtitles to be read and/or written in the SMPTE format.
41  */
42 class SMPTESubtitleAsset : public SubtitleAsset, public MXF
43 {
44 public:
45         SMPTESubtitleAsset ();
46
47         /** @param file File name
48          */
49         SMPTESubtitleAsset (boost::filesystem::path file);
50
51         bool equals (
52                 boost::shared_ptr<const Asset>,
53                 EqualityOptions,
54                 NoteHandler note
55                 ) const;
56
57         std::list<boost::shared_ptr<LoadFontNode> > load_font_nodes () const;
58
59         std::string xml_as_string () const;
60         void write (boost::filesystem::path path) const;
61         void add (SubtitleString);
62         void add_font (std::string id, boost::filesystem::path file);
63
64         void set_content_title_text (std::string t) {
65                 _content_title_text = t;
66         }
67
68         void set_language (std::string l) {
69                 _language = l;
70         }
71
72         void set_reel_number (int r) {
73                 _reel_number = r;
74         }
75
76         void set_edit_rate (Fraction e) {
77                 _edit_rate = e;
78         }
79
80         void set_time_code_rate (int t) {
81                 _time_code_rate = t;
82         }
83
84         void set_start_time (Time t) {
85                 _start_time = t;
86         }
87
88         void set_intrinsic_duration (int64_t d) {
89                 _intrinsic_duration = d;
90         }
91
92         /** @return title of the film that these subtitles are for,
93          *  to be presented to the user.
94          */
95         std::string content_title_text () const {
96                 return _content_title_text;
97         }
98
99         /** @return language as a xs:language, if one was specified */
100         boost::optional<std::string> language () const {
101                 return _language;
102         }
103
104         /** @return annotation text, to be presented to the user */
105         boost::optional<std::string> annotation_text () const {
106                 return _annotation_text;
107         }
108
109         /** @return file creation time and date */
110         LocalTime issue_date () const {
111                 return _issue_date;
112         }
113
114         boost::optional<int> reel_number () const {
115                 return _reel_number;
116         }
117
118         Fraction edit_rate () const {
119                 return _edit_rate;
120         }
121
122         /** @return subdivision of 1 second that is used for subtitle times;
123          *  e.g. a time_code_rate of 250 means that a subtitle time of 0:0:0:001
124          *  represents 4ms.
125          */
126         int time_code_rate () const {
127                 return _time_code_rate;
128         }
129
130         boost::optional<Time> start_time () const {
131                 return _start_time;
132         }
133
134         static bool valid_mxf (boost::filesystem::path);
135
136 protected:
137
138         std::string pkl_type (Standard) const {
139                 return "application/mxf";
140         }
141
142 private:
143         void read_fonts (boost::shared_ptr<ASDCP::TimedText::MXFReader>);
144
145         /** The total length of this content in video frames.  The amount of
146          *  content presented may be less than this.
147          */
148         int64_t _intrinsic_duration;
149         std::string _content_title_text;
150         boost::optional<std::string> _language;
151         boost::optional<std::string> _annotation_text;
152         LocalTime _issue_date;
153         boost::optional<int> _reel_number;
154         Fraction _edit_rate;
155         int _time_code_rate;
156         boost::optional<Time> _start_time;
157
158         std::list<boost::shared_ptr<SMPTELoadFontNode> > _load_font_nodes;
159 };
160
161 }