2 Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
22 /** @file src/lib/content.h
23 * @brief Content class.
27 #ifndef DCPOMATIC_CONTENT_H
28 #define DCPOMATIC_CONTENT_H
31 #include "change_signaller.h"
32 #include "dcpomatic_time.h"
33 #include "signaller.h"
34 #include "user_property.h"
35 #include "text_type.h"
36 #include <libcxml/cxml.h>
37 #include <boost/filesystem.hpp>
38 #include <boost/signals2.hpp>
39 #include <boost/thread/mutex.hpp>
60 static int const PATH;
61 static int const POSITION;
62 static int const LENGTH;
63 static int const TRIM_START;
64 static int const TRIM_END;
65 static int const VIDEO_FRAME_RATE;
70 * @brief A piece of content represented by one or more files on disk.
72 class Content : public std::enable_shared_from_this<Content>, public Signaller
76 Content (dcpomatic::DCPTime);
77 Content (boost::filesystem::path);
78 Content (cxml::ConstNodePtr);
79 Content (std::vector<std::shared_ptr<Content>>);
80 virtual ~Content () {}
82 Content (Content const&) = delete;
83 Content& operator= (Content const&) = delete;
85 /** Examine the content to establish digest, frame rates and any other
87 * @param job Job to use to report progress, or 0.
89 virtual void examine (std::shared_ptr<const Film> film, std::shared_ptr<Job> job);
91 virtual void take_settings_from (std::shared_ptr<const Content> c);
93 /** @return Quick one-line summary of the content, as will be presented in the
96 virtual std::string summary () const = 0;
98 /** @return Technical details of this content; these are written to logs to
99 * help with debugging.
101 virtual std::string technical_summary () const;
103 virtual void as_xml (xmlpp::Node *, bool with_paths) const;
104 virtual dcpomatic::DCPTime full_length (std::shared_ptr<const Film>) const = 0;
105 virtual dcpomatic::DCPTime approximate_length () const = 0;
106 virtual std::string identifier () const;
107 /** @return points at which to split this content when
108 * REELTYPE_BY_VIDEO_CONTENT is in use.
110 virtual std::list<dcpomatic::DCPTime> reel_split_points (std::shared_ptr<const Film>) const;
112 std::shared_ptr<Content> clone () const;
114 void set_paths (std::vector<boost::filesystem::path> paths);
116 std::string path_summary () const;
118 std::vector<boost::filesystem::path> paths () const {
119 boost::mutex::scoped_lock lm (_mutex);
123 size_t number_of_paths () const {
124 boost::mutex::scoped_lock lm (_mutex);
125 return _paths.size ();
128 boost::filesystem::path path (size_t i) const {
129 boost::mutex::scoped_lock lm (_mutex);
133 std::time_t last_write_time (size_t i) const {
134 boost::mutex::scoped_lock lm (_mutex);
135 return _last_write_times[i];
138 bool paths_valid () const;
140 /** @return Digest of the content's file(s). Note: this is
141 * not a complete MD5-or-whatever hash, but a sort of poor
142 * man's version (see comments in examine()).
144 std::string digest () const {
145 boost::mutex::scoped_lock lm (_mutex);
149 void set_position (std::shared_ptr<const Film> film, dcpomatic::DCPTime, bool force_emit = false);
151 /** dcpomatic::DCPTime that this content starts; i.e. the time that the first
152 * bit of the content (trimmed or not) will happen.
154 dcpomatic::DCPTime position () const {
155 boost::mutex::scoped_lock lm (_mutex);
159 void set_trim_start(std::shared_ptr<const Film> film, dcpomatic::ContentTime);
161 dcpomatic::ContentTime trim_start () const {
162 boost::mutex::scoped_lock lm (_mutex);
166 void set_trim_end (dcpomatic::ContentTime);
168 dcpomatic::ContentTime trim_end () const {
169 boost::mutex::scoped_lock lm (_mutex);
173 /** @return Time immediately after the last thing in this content */
174 dcpomatic::DCPTime end (std::shared_ptr<const Film> film) const {
175 return position() + length_after_trim(film);
178 dcpomatic::DCPTimePeriod period(std::shared_ptr<const Film> film) const {
179 return { position(), end(film) };
182 dcpomatic::DCPTime length_after_trim (std::shared_ptr<const Film> film) const;
184 boost::optional<double> video_frame_rate () const {
185 boost::mutex::scoped_lock lm (_mutex);
186 return _video_frame_rate;
189 void set_video_frame_rate(std::shared_ptr<const Film> film, double r);
190 void unset_video_frame_rate ();
192 double active_video_frame_rate (std::shared_ptr<const Film> film) const;
194 void set_change_signals_frequent (bool f) {
195 _change_signals_frequent = f;
198 std::list<UserProperty> user_properties (std::shared_ptr<const Film> film) const;
200 std::string calculate_digest () const;
202 virtual bool can_be_played () const {
206 /* ChangeType::PENDING and ChangeType::CANCELLED may be emitted from any thread; ChangeType::DONE always from GUI thread */
207 boost::signals2::signal<void (ChangeType, std::weak_ptr<Content>, int, bool)> Change;
209 std::shared_ptr<VideoContent> video;
210 std::shared_ptr<AudioContent> audio;
211 std::vector<std::shared_ptr<TextContent>> text;
212 std::shared_ptr<AtmosContent> atmos;
214 std::shared_ptr<TextContent> only_text () const;
215 std::shared_ptr<TextContent> text_of_original_type (TextType type) const;
217 /** @return true if this content has changed since it was last examined */
218 bool changed () const;
222 virtual void add_properties (std::shared_ptr<const Film> film, std::list<UserProperty> &) const;
224 /** _mutex which should be used to protect accesses, as examine
225 * jobs can update content state in threads other than the main one.
227 mutable boost::mutex _mutex;
229 void add_path (boost::filesystem::path p);
232 friend struct ffmpeg_pts_offset_test;
233 friend struct best_dcp_frame_rate_test_single;
234 friend struct best_dcp_frame_rate_test_double;
235 friend struct audio_sampling_rate_test;
236 friend struct subtitle_font_id_change_test2;
237 template<class, class> friend class ChangeSignaller;
239 void signal_change (ChangeType, int);
241 /** Paths of our data files */
242 std::vector<boost::filesystem::path> _paths;
243 std::vector<std::time_t> _last_write_times;
246 dcpomatic::DCPTime _position;
247 dcpomatic::ContentTime _trim_start;
248 dcpomatic::ContentTime _trim_end;
249 /** The video frame rate that this content is or was prepared to be used with,
250 * or empty if the effective rate of this content should be dictated by something
251 * else (either some video happening at the same time, or the rate of the DCP).
253 boost::optional<double> _video_frame_rate;
254 bool _change_signals_frequent = false;
258 typedef ChangeSignaller<Content, int> ContentChangeSignaller;