Improve ratings dialog to allow only valid values (#2199).
[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.h"
29 #include "dcp_text_track.h"
30 #include "dcpomatic_assert.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 DCP, public VideoExaminer, public AudioExaminer
40 {
41 public:
42         explicit DCPExaminer (std::shared_ptr<const DCPContent>, bool tolerant);
43
44         bool has_video () const {
45                 return _has_video;
46         }
47
48         boost::optional<double> video_frame_rate () const {
49                 return _video_frame_rate;
50         }
51
52         dcp::Size video_size () const {
53                 DCPOMATIC_ASSERT (_has_video);
54                 DCPOMATIC_ASSERT (_video_size);
55                 return *_video_size;
56         }
57
58         Frame video_length () const {
59                 return _video_length;
60         }
61
62         bool yuv () const {
63                 return false;
64         }
65
66         VideoRange range () const {
67                 return VideoRange::FULL;
68         }
69
70         PixelQuanta pixel_quanta () const {
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 {
87                 return _has_audio;
88         }
89
90         int audio_channels () const {
91                 return _audio_channels.get_value_or (0);
92         }
93
94         Frame audio_length () const {
95                 return _audio_length;
96         }
97
98         int audio_frame_rate () const {
99                 return _audio_frame_rate.get_value_or (48000);
100         }
101
102         boost::optional<dcp::LanguageTag> audio_language () const {
103                 return _audio_language;
104         }
105
106         /** @param type TEXT_OPEN_SUBTITLE or TEXT_CLOSED_CAPTION.
107          *  @return Number of assets of this type in this DCP.
108          */
109         int text_count (TextType type) const {
110                 return _text_count[static_cast<int>(type)];
111         }
112
113         boost::optional<dcp::LanguageTag> open_subtitle_language () const {
114                 return _open_subtitle_language;
115         }
116
117         DCPTextTrack dcp_text_track (int i) const {
118                 DCPOMATIC_ASSERT (i >= 0 && i < static_cast<int>(_dcp_text_tracks.size()));
119                 return _dcp_text_tracks[i];
120         }
121
122         bool kdm_valid () const {
123                 return _kdm_valid;
124         }
125
126         boost::optional<dcp::Standard> standard () const {
127                 return _standard;
128         }
129
130         bool three_d () const {
131                 return _three_d;
132         }
133
134         dcp::ContentKind content_kind () const {
135                 return _content_kind;
136         }
137
138         std::string cpl () const {
139                 return _cpl;
140         }
141
142         std::list<int64_t> reel_lengths () const {
143                 return _reel_lengths;
144         }
145
146         std::map<dcp::Marker, dcp::Time> markers () const {
147                 return _markers;
148         }
149
150         std::vector<dcp::Rating> ratings () const {
151                 return _ratings;
152         }
153
154         std::vector<std::string> content_versions () const {
155                 return _content_versions;
156         }
157
158         bool has_atmos () const {
159                 return _has_atmos;
160         }
161
162         Frame atmos_length () const {
163                 return _atmos_length;
164         }
165
166         dcp::Fraction atmos_edit_rate () const {
167                 return _atmos_edit_rate;
168         }
169
170 private:
171         boost::optional<double> _video_frame_rate;
172         boost::optional<dcp::Size> _video_size;
173         Frame _video_length = 0;
174         boost::optional<int> _audio_channels;
175         boost::optional<int> _audio_frame_rate;
176         Frame _audio_length = 0;
177         std::string _name;
178         /** true if this DCP has video content (but false if it has unresolved references to video content) */
179         bool _has_video = false;
180         /** true if this DCP has audio content (but false if it has unresolved references to audio content) */
181         bool _has_audio = false;
182         boost::optional<dcp::LanguageTag> _audio_language;
183         /** number of different assets of each type (OCAP/CCAP) */
184         int _text_count[static_cast<int>(TextType::COUNT)];
185         boost::optional<dcp::LanguageTag> _open_subtitle_language;
186         /** the DCPTextTracks for each of our CCAPs */
187         std::vector<DCPTextTrack> _dcp_text_tracks;
188         bool _encrypted = false;
189         bool _needs_assets = false;
190         bool _kdm_valid = false;
191         boost::optional<dcp::Standard> _standard;
192         bool _three_d = false;
193         dcp::ContentKind _content_kind;
194         std::string _cpl;
195         std::list<int64_t> _reel_lengths;
196         std::map<dcp::Marker, dcp::Time> _markers;
197         std::vector<dcp::Rating> _ratings;
198         std::vector<std::string> _content_versions;
199         bool _has_atmos = false;
200         Frame _atmos_length = 0;
201         dcp::Fraction _atmos_edit_rate;
202 };