Supporters update.
[dcpomatic.git] / src / lib / dcp_examiner.h
1 /*
2     Copyright (C) 2014-2020 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic 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     DCP-o-matic 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 DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21
22 /** @file  src/lib/dcp_examiner.h
23  *  @brief DCPExaminer class.
24  */
25
26
27 #include "audio_examiner.h"
28 #include "dcp_text_track.h"
29 #include "dcpomatic_assert.h"
30 #include "video_examiner.h"
31 #include <dcp/dcp_time.h>
32 #include <dcp/rating.h>
33
34
35 class DCPContent;
36
37
38 class DCPExaminer : public VideoExaminer, public AudioExaminer
39 {
40 public:
41         DCPExaminer(std::shared_ptr<const DCPContent>, bool tolerant);
42
43         bool has_video () const override {
44                 return _has_video;
45         }
46
47         boost::optional<double> video_frame_rate () const override {
48                 return _video_frame_rate;
49         }
50
51         boost::optional<dcp::Size> video_size() const override {
52                 return _video_size;
53         }
54
55         Frame video_length () const override {
56                 return _video_length;
57         }
58
59         bool yuv () const override {
60                 return false;
61         }
62
63         VideoRange range () const override {
64                 return VideoRange::FULL;
65         }
66
67         PixelQuanta pixel_quanta () const override {
68                 return {};
69         }
70
71         std::string name () const {
72                 return _name;
73         }
74
75         bool encrypted () const {
76                 return _encrypted;
77         }
78
79         bool needs_assets () const {
80                 return _needs_assets;
81         }
82
83         bool has_audio () const override {
84                 return _has_audio;
85         }
86
87         int audio_channels () const override {
88                 return _audio_channels.get_value_or (0);
89         }
90
91         int active_audio_channels() const {
92                 return _active_audio_channels.get_value_or(0);
93         }
94
95         Frame audio_length () const override {
96                 return _audio_length;
97         }
98
99         int audio_frame_rate () const override {
100                 return _audio_frame_rate.get_value_or (48000);
101         }
102
103         boost::optional<dcp::LanguageTag> audio_language () const {
104                 return _audio_language;
105         }
106
107         /** @param type TEXT_OPEN_SUBTITLE or TEXT_CLOSED_CAPTION.
108          *  @return the number of "streams" of this type in the DCP.
109          *  Reels do not affect the return value of this method: if a DCP
110          *  has any subtitles, type=TEXT_OPEN_SUBTITLE will return 1.
111          */
112         int text_count (TextType type) const {
113                 return _text_count[type];
114         }
115
116         boost::optional<dcp::LanguageTag> open_subtitle_language () const {
117                 return _open_subtitle_language;
118         }
119
120         DCPTextTrack dcp_text_track (int i) const {
121                 DCPOMATIC_ASSERT (i >= 0 && i < static_cast<int>(_dcp_text_tracks.size()));
122                 return _dcp_text_tracks[i];
123         }
124
125         bool kdm_valid () const {
126                 return _kdm_valid;
127         }
128
129         boost::optional<dcp::Standard> standard () const {
130                 return _standard;
131         }
132
133         bool three_d () const {
134                 return _three_d;
135         }
136
137         dcp::ContentKind content_kind () const {
138                 DCPOMATIC_ASSERT(_content_kind);
139                 return *_content_kind;
140         }
141
142         std::string cpl () const {
143                 return _cpl;
144         }
145
146         std::list<int64_t> reel_lengths () const {
147                 return _reel_lengths;
148         }
149
150         std::map<dcp::Marker, dcp::Time> markers () const {
151                 return _markers;
152         }
153
154         std::vector<dcp::Rating> ratings () const {
155                 return _ratings;
156         }
157
158         std::vector<std::string> content_versions () const {
159                 return _content_versions;
160         }
161
162         bool has_atmos () const {
163                 return _has_atmos;
164         }
165
166         Frame atmos_length () const {
167                 return _atmos_length;
168         }
169
170         dcp::Fraction atmos_edit_rate () const {
171                 return _atmos_edit_rate;
172         }
173
174         void add_fonts(std::shared_ptr<TextContent> content);
175
176 private:
177         boost::optional<double> _video_frame_rate;
178         boost::optional<dcp::Size> _video_size;
179         Frame _video_length = 0;
180         boost::optional<int> _audio_channels;
181         boost::optional<int> _active_audio_channels;
182         boost::optional<int> _audio_frame_rate;
183         Frame _audio_length = 0;
184         std::string _name;
185         /** true if this DCP has video content (but false if it has unresolved references to video content) */
186         bool _has_video = false;
187         /** true if this DCP has audio content (but false if it has unresolved references to audio content) */
188         bool _has_audio = false;
189         boost::optional<dcp::LanguageTag> _audio_language;
190         /** number of different assets of each type (OCAP/CCAP) */
191         EnumIndexedVector<int, TextType> _text_count;
192         boost::optional<dcp::LanguageTag> _open_subtitle_language;
193         /** the DCPTextTracks for each of our CCAPs */
194         std::vector<DCPTextTrack> _dcp_text_tracks;
195         bool _encrypted = false;
196         bool _needs_assets = false;
197         bool _kdm_valid = false;
198         boost::optional<dcp::Standard> _standard;
199         bool _three_d = false;
200         boost::optional<dcp::ContentKind> _content_kind;
201         std::string _cpl;
202         std::list<int64_t> _reel_lengths;
203         std::map<dcp::Marker, dcp::Time> _markers;
204         std::vector<dcp::Rating> _ratings;
205         std::vector<std::string> _content_versions;
206         bool _has_atmos = false;
207         Frame _atmos_length = 0;
208         dcp::Fraction _atmos_edit_rate;
209
210         struct Font
211         {
212                 Font(int reel_index_, std::string asset_id_, std::shared_ptr<dcpomatic::Font> font_)
213                         : reel_index(reel_index_)
214                         , asset_id(asset_id_)
215                         , font(font_)
216                 {}
217
218                 int reel_index;
219                 std::string asset_id;
220                 std::shared_ptr<dcpomatic::Font> font;
221         };
222
223         std::vector<Font> _fonts;
224 };