Cope with loading a film containing a missing DCP which itself contains subtitles.
[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         dcp::Size video_size () const override {
52                 DCPOMATIC_ASSERT (_has_video);
53                 DCPOMATIC_ASSERT (_video_size);
54                 return *_video_size;
55         }
56
57         Frame video_length () const override {
58                 return _video_length;
59         }
60
61         bool yuv () const override {
62                 return false;
63         }
64
65         VideoRange range () const override {
66                 return VideoRange::FULL;
67         }
68
69         PixelQuanta pixel_quanta () const override {
70                 return {};
71         }
72
73         std::string name () const {
74                 return _name;
75         }
76
77         bool encrypted () const {
78                 return _encrypted;
79         }
80
81         bool needs_assets () const {
82                 return _needs_assets;
83         }
84
85         bool has_audio () const override {
86                 return _has_audio;
87         }
88
89         int audio_channels () const override {
90                 return _audio_channels.get_value_or (0);
91         }
92
93         int active_audio_channels() const {
94                 return _active_audio_channels.get_value_or(0);
95         }
96
97         Frame audio_length () const override {
98                 return _audio_length;
99         }
100
101         int audio_frame_rate () const override {
102                 return _audio_frame_rate.get_value_or (48000);
103         }
104
105         boost::optional<dcp::LanguageTag> audio_language () const {
106                 return _audio_language;
107         }
108
109         /** @param type TEXT_OPEN_SUBTITLE or TEXT_CLOSED_CAPTION.
110          *  @return the number of "streams" of this type in the DCP.
111          *  Reels do not affect the return value of this method: if a DCP
112          *  has any subtitles, type=TEXT_OPEN_SUBTITLE will return 1.
113          */
114         int text_count (TextType type) const {
115                 return _text_count[type];
116         }
117
118         boost::optional<dcp::LanguageTag> open_subtitle_language () const {
119                 return _open_subtitle_language;
120         }
121
122         DCPTextTrack dcp_text_track (int i) const {
123                 DCPOMATIC_ASSERT (i >= 0 && i < static_cast<int>(_dcp_text_tracks.size()));
124                 return _dcp_text_tracks[i];
125         }
126
127         bool kdm_valid () const {
128                 return _kdm_valid;
129         }
130
131         boost::optional<dcp::Standard> standard () const {
132                 return _standard;
133         }
134
135         bool three_d () const {
136                 return _three_d;
137         }
138
139         dcp::ContentKind content_kind () const {
140                 DCPOMATIC_ASSERT(_content_kind);
141                 return *_content_kind;
142         }
143
144         std::string cpl () const {
145                 return _cpl;
146         }
147
148         std::list<int64_t> reel_lengths () const {
149                 return _reel_lengths;
150         }
151
152         std::map<dcp::Marker, dcp::Time> markers () const {
153                 return _markers;
154         }
155
156         std::vector<dcp::Rating> ratings () const {
157                 return _ratings;
158         }
159
160         std::vector<std::string> content_versions () const {
161                 return _content_versions;
162         }
163
164         bool has_atmos () const {
165                 return _has_atmos;
166         }
167
168         Frame atmos_length () const {
169                 return _atmos_length;
170         }
171
172         dcp::Fraction atmos_edit_rate () const {
173                 return _atmos_edit_rate;
174         }
175
176         void add_fonts(std::shared_ptr<TextContent> content);
177
178 private:
179         boost::optional<double> _video_frame_rate;
180         boost::optional<dcp::Size> _video_size;
181         Frame _video_length = 0;
182         boost::optional<int> _audio_channels;
183         boost::optional<int> _active_audio_channels;
184         boost::optional<int> _audio_frame_rate;
185         Frame _audio_length = 0;
186         std::string _name;
187         /** true if this DCP has video content (but false if it has unresolved references to video content) */
188         bool _has_video = false;
189         /** true if this DCP has audio content (but false if it has unresolved references to audio content) */
190         bool _has_audio = false;
191         boost::optional<dcp::LanguageTag> _audio_language;
192         /** number of different assets of each type (OCAP/CCAP) */
193         EnumIndexedVector<int, TextType> _text_count;
194         boost::optional<dcp::LanguageTag> _open_subtitle_language;
195         /** the DCPTextTracks for each of our CCAPs */
196         std::vector<DCPTextTrack> _dcp_text_tracks;
197         bool _encrypted = false;
198         bool _needs_assets = false;
199         bool _kdm_valid = false;
200         boost::optional<dcp::Standard> _standard;
201         bool _three_d = false;
202         boost::optional<dcp::ContentKind> _content_kind;
203         std::string _cpl;
204         std::list<int64_t> _reel_lengths;
205         std::map<dcp::Marker, dcp::Time> _markers;
206         std::vector<dcp::Rating> _ratings;
207         std::vector<std::string> _content_versions;
208         bool _has_atmos = false;
209         Frame _atmos_length = 0;
210         dcp::Fraction _atmos_edit_rate;
211
212         struct Font
213         {
214                 Font(int reel_index_, std::string asset_id_, std::shared_ptr<dcpomatic::Font> font_)
215                         : reel_index(reel_index_)
216                         , asset_id(asset_id_)
217                         , font(font_)
218                 {}
219
220                 int reel_index;
221                 std::string asset_id;
222                 std::shared_ptr<dcpomatic::Font> font;
223         };
224
225         std::vector<Font> _fonts;
226 };