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