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"
35 #include "user_property.h"
36 #include <libcxml/cxml.h>
37 #include <boost/filesystem.hpp>
38 #include <boost/signals2.hpp>
39 #include <boost/thread/mutex.hpp>
57 static int const PATH;
58 static int const POSITION;
59 static int const LENGTH;
60 static int const TRIM_START;
61 static int const TRIM_END;
62 static int const VIDEO_FRAME_RATE;
67 * @brief A piece of content represented by one or more files on disk.
69 class Content : public std::enable_shared_from_this<Content>, public Signaller
73 Content (dcpomatic::DCPTime);
74 Content (boost::filesystem::path);
75 Content (cxml::ConstNodePtr);
76 Content (std::vector<std::shared_ptr<Content>>);
77 virtual ~Content () {}
79 Content (Content const&) = delete;
80 Content& operator= (Content const&) = delete;
82 /** Examine the content to establish digest, frame rates and any other
84 * @param job Job to use to report progress, or 0.
86 virtual void examine (std::shared_ptr<const Film> film, std::shared_ptr<Job> job);
88 virtual void take_settings_from (std::shared_ptr<const Content> c);
90 /** @return Quick one-line summary of the content, as will be presented in the
93 virtual std::string summary () const = 0;
95 /** @return Technical details of this content; these are written to logs to
96 * help with debugging.
98 virtual std::string technical_summary () const;
100 virtual void as_xml (xmlpp::Node *, bool with_paths) const;
101 virtual dcpomatic::DCPTime full_length (std::shared_ptr<const Film>) const = 0;
102 virtual dcpomatic::DCPTime approximate_length () const = 0;
103 virtual std::string identifier () const;
104 /** @return points at which to split this content when
105 * REELTYPE_BY_VIDEO_CONTENT is in use.
107 virtual std::list<dcpomatic::DCPTime> reel_split_points (std::shared_ptr<const Film>) const;
109 std::shared_ptr<Content> clone () const;
111 void set_paths (std::vector<boost::filesystem::path> paths);
113 std::string path_summary () const;
115 std::vector<boost::filesystem::path> paths () const {
116 boost::mutex::scoped_lock lm (_mutex);
120 size_t number_of_paths () const {
121 boost::mutex::scoped_lock lm (_mutex);
122 return _paths.size ();
125 boost::filesystem::path path (size_t i) const {
126 boost::mutex::scoped_lock lm (_mutex);
130 std::time_t last_write_time (size_t i) const {
131 boost::mutex::scoped_lock lm (_mutex);
132 return _last_write_times[i];
135 bool paths_valid () const;
137 /** @return Digest of the content's file(s). Note: this is
138 * not a complete MD5-or-whatever hash, but a sort of poor
139 * man's version (see comments in examine()).
141 std::string digest () const {
142 boost::mutex::scoped_lock lm (_mutex);
146 void set_position (std::shared_ptr<const Film> film, dcpomatic::DCPTime, bool force_emit = false);
148 /** dcpomatic::DCPTime that this content starts; i.e. the time that the first
149 * bit of the content (trimmed or not) will happen.
151 dcpomatic::DCPTime position () const {
152 boost::mutex::scoped_lock lm (_mutex);
156 void set_trim_start(std::shared_ptr<const Film> film, dcpomatic::ContentTime);
158 dcpomatic::ContentTime trim_start () const {
159 boost::mutex::scoped_lock lm (_mutex);
163 void set_trim_end (dcpomatic::ContentTime);
165 dcpomatic::ContentTime trim_end () const {
166 boost::mutex::scoped_lock lm (_mutex);
170 /** @return Time immediately after the last thing in this content */
171 dcpomatic::DCPTime end (std::shared_ptr<const Film> film) const {
172 return position() + length_after_trim(film);
175 dcpomatic::DCPTime length_after_trim (std::shared_ptr<const Film> film) const;
177 boost::optional<double> video_frame_rate () const {
178 boost::mutex::scoped_lock lm (_mutex);
179 return _video_frame_rate;
182 void set_video_frame_rate(std::shared_ptr<const Film> film, double r);
183 void unset_video_frame_rate ();
185 double active_video_frame_rate (std::shared_ptr<const Film> film) const;
187 void set_change_signals_frequent (bool f) {
188 _change_signals_frequent = f;
191 std::list<UserProperty> user_properties (std::shared_ptr<const Film> film) const;
193 std::string calculate_digest () const;
195 virtual bool can_be_played () const {
199 /* ChangeType::PENDING and ChangeType::CANCELLED may be emitted from any thread; ChangeType::DONE always from GUI thread */
200 boost::signals2::signal<void (ChangeType, std::weak_ptr<Content>, int, bool)> Change;
202 std::shared_ptr<VideoContent> video;
203 std::shared_ptr<AudioContent> audio;
204 std::list<std::shared_ptr<TextContent>> text;
205 std::shared_ptr<AtmosContent> atmos;
207 std::shared_ptr<TextContent> only_text () const;
208 std::shared_ptr<TextContent> text_of_original_type (TextType type) const;
210 /** @return true if this content has changed since it was last examined */
211 bool changed () const;
215 virtual void add_properties (std::shared_ptr<const Film> film, std::list<UserProperty> &) const;
217 /** _mutex which should be used to protect accesses, as examine
218 * jobs can update content state in threads other than the main one.
220 mutable boost::mutex _mutex;
222 void add_path (boost::filesystem::path p);
225 friend struct ffmpeg_pts_offset_test;
226 friend struct best_dcp_frame_rate_test_single;
227 friend struct best_dcp_frame_rate_test_double;
228 friend struct audio_sampling_rate_test;
229 friend struct subtitle_font_id_change_test2;
230 template<class, class> friend class ChangeSignaller;
232 void signal_change (ChangeType, int);
234 /** Paths of our data files */
235 std::vector<boost::filesystem::path> _paths;
236 std::vector<std::time_t> _last_write_times;
239 dcpomatic::DCPTime _position;
240 dcpomatic::ContentTime _trim_start;
241 dcpomatic::ContentTime _trim_end;
242 /** The video frame rate that this content is or was prepared to be used with,
243 * or empty if the effective rate of this content should be dictated by something
244 * else (either some video happening at the same time, or the rate of the DCP).
246 boost::optional<double> _video_frame_rate;
247 bool _change_signals_frequent = false;
251 typedef ChangeSignaller<Content, int> ContentChangeSignaller;