2 Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * @brief A representation of a piece of video (with sound), including naming,
22 * the source content file, and how it should be presented in a DCP.
25 #ifndef DVDOMATIC_FILM_H
26 #define DVDOMATIC_FILM_H
31 #include <boost/thread/mutex.hpp>
32 #include <boost/thread.hpp>
33 #include <boost/signals2.hpp>
34 #include <boost/enable_shared_from_this.hpp>
36 #include <libavcodec/avcodec.h>
38 #include "dcp_content_type.h"
40 #include "dci_metadata.h"
46 class ExamineContentJob;
47 class AnalyseAudioJob;
48 class ExternalAudioStream;
53 * @brief A representation of a video, maybe with sound.
55 * A representation of a piece of video (maybe with sound), including naming,
56 * the source content file, and how it should be presented in a DCP.
58 class Film : public boost::enable_shared_from_this<Film>
61 Film (std::string d, bool must_exist = true);
65 std::string info_dir () const;
66 std::string j2c_path (int f, bool t) const;
67 std::string info_path (int f) const;
68 std::string video_mxf_dir () const;
69 std::string video_mxf_filename () const;
70 std::string audio_analysis_path () const;
72 void examine_content (boost::shared_ptr<Content>);
73 void analyse_audio ();
74 void send_dcp_to_tms ();
79 * It is safe to call this from any thread.
81 boost::shared_ptr<Log> log () const {
85 int encoded_frames () const;
87 std::string file (std::string f) const;
88 std::string dir (std::string d) const;
90 int target_audio_sample_rate () const;
92 void write_metadata () const;
93 void read_metadata ();
95 libdcp::Size cropped_size (libdcp::Size) const;
96 std::string dci_name (bool if_created_now) const;
97 std::string dcp_name (bool if_created_now = false) const;
99 /** @return true if our state has changed since we last saved it */
100 bool dirty () const {
104 void set_dci_date_today ();
106 bool have_dcp () const;
108 boost::shared_ptr<Playlist> playlist () const;
110 /** Identifiers for the parts of our state;
111 used for signalling changes.
117 TRUST_CONTENT_HEADERS,
143 std::string directory () const {
144 boost::mutex::scoped_lock lm (_directory_mutex);
148 std::string name () const {
149 boost::mutex::scoped_lock lm (_state_mutex);
153 bool use_dci_name () const {
154 boost::mutex::scoped_lock lm (_state_mutex);
155 return _use_dci_name;
158 bool trust_content_headers () const {
159 boost::mutex::scoped_lock lm (_state_mutex);
160 return _trust_content_headers;
163 std::list<boost::shared_ptr<Content> > content () const {
164 boost::mutex::scoped_lock lm (_state_mutex);
168 DCPContentType const * dcp_content_type () const {
169 boost::mutex::scoped_lock lm (_state_mutex);
170 return _dcp_content_type;
173 Format const * format () const {
174 boost::mutex::scoped_lock lm (_state_mutex);
179 boost::mutex::scoped_lock lm (_state_mutex);
183 std::vector<Filter const *> filters () const {
184 boost::mutex::scoped_lock lm (_state_mutex);
188 Scaler const * scaler () const {
189 boost::mutex::scoped_lock lm (_state_mutex);
193 int trim_start () const {
194 boost::mutex::scoped_lock lm (_state_mutex);
198 int trim_end () const {
199 boost::mutex::scoped_lock lm (_state_mutex);
204 boost::mutex::scoped_lock lm (_state_mutex);
208 float audio_gain () const {
209 boost::mutex::scoped_lock lm (_state_mutex);
213 int audio_delay () const {
214 boost::mutex::scoped_lock lm (_state_mutex);
218 bool with_subtitles () const {
219 boost::mutex::scoped_lock lm (_state_mutex);
220 return _with_subtitles;
223 int subtitle_offset () const {
224 boost::mutex::scoped_lock lm (_state_mutex);
225 return _subtitle_offset;
228 float subtitle_scale () const {
229 boost::mutex::scoped_lock lm (_state_mutex);
230 return _subtitle_scale;
233 int colour_lut () const {
234 boost::mutex::scoped_lock lm (_state_mutex);
238 int j2k_bandwidth () const {
239 boost::mutex::scoped_lock lm (_state_mutex);
240 return _j2k_bandwidth;
243 DCIMetadata dci_metadata () const {
244 boost::mutex::scoped_lock lm (_state_mutex);
245 return _dci_metadata;
248 int dcp_frame_rate () const {
249 boost::mutex::scoped_lock lm (_state_mutex);
250 return _dcp_frame_rate;
255 void set_directory (std::string);
256 void set_name (std::string);
257 void set_use_dci_name (bool);
258 void set_trust_content_headers (bool);
259 void add_content (boost::shared_ptr<Content>);
260 void set_dcp_content_type (DCPContentType const *);
261 void set_format (Format const *);
262 void set_crop (Crop);
263 void set_left_crop (int);
264 void set_right_crop (int);
265 void set_top_crop (int);
266 void set_bottom_crop (int);
267 void set_filters (std::vector<Filter const *>);
268 void set_scaler (Scaler const *);
269 void set_trim_start (int);
270 void set_trim_end (int);
272 void set_audio_gain (float);
273 void set_audio_delay (int);
274 void set_still_duration (int);
275 void set_with_subtitles (bool);
276 void set_subtitle_offset (int);
277 void set_subtitle_scale (float);
278 void set_colour_lut (int);
279 void set_j2k_bandwidth (int);
280 void set_dci_metadata (DCIMetadata);
281 void set_dcp_frame_rate (int);
283 /** Emitted when some property has changed */
284 mutable boost::signals2::signal<void (Property)> Changed;
286 boost::signals2::signal<void ()> AudioAnalysisSucceeded;
288 /** Current version number of the state file */
289 static int const state_version;
293 /** Log to write to */
294 boost::shared_ptr<Log> _log;
296 /** Any running AnalyseAudioJob, or 0 */
297 boost::shared_ptr<AnalyseAudioJob> _analyse_audio_job;
299 void signal_changed (Property);
300 void examine_content_finished ();
301 void analyse_audio_finished ();
302 std::string video_state_identifier () const;
304 /** Complete path to directory containing the film metadata;
305 * must not be relative.
307 std::string _directory;
308 /** Mutex for _directory */
309 mutable boost::mutex _directory_mutex;
311 /** Name for DVD-o-matic */
313 /** True if a auto-generated DCI-compliant name should be used for our DCP */
315 typedef std::list<boost::shared_ptr<Content> > ContentList;
316 ContentList _content;
317 bool _trust_content_headers;
318 /** The type of content that this Film represents (feature, trailer etc.) */
319 DCPContentType const * _dcp_content_type;
320 /** The format to present this Film in (flat, scope, etc.) */
321 Format const * _format;
322 /** The crop to apply to the source */
324 /** Video filters that should be used when generating DCPs */
325 std::vector<Filter const *> _filters;
326 /** Scaler algorithm to use */
327 Scaler const * _scaler;
328 /** Frames to trim off the start of the DCP */
330 /** Frames to trim off the end of the DCP */
332 /** true to create an A/B comparison DCP, where the left half of the image
333 is the video without any filters or post-processing, and the right half
334 has the specified filters and post-processing.
337 /** Gain to apply to audio in dB */
339 /** Delay to apply to audio (positive moves audio later) in milliseconds */
341 /** True if subtitles should be shown for this film */
342 bool _with_subtitles;
343 /** y offset for placing subtitles, in source pixels; +ve is further down
344 the frame, -ve is further up.
346 int _subtitle_offset;
347 /** scale factor to apply to subtitles */
348 float _subtitle_scale;
349 /** index of colour LUT to use when converting RGB to XYZ.
354 /** bandwidth for J2K files in bits per second */
357 /** DCI naming stuff */
358 DCIMetadata _dci_metadata;
359 /** The date that we should use in a DCI name */
360 boost::gregorian::date _dci_date;
361 /** Frames per second to run our DCP at */
364 /** true if our state has changed since we last saved it */
367 /** Mutex for all state except _directory */
368 mutable boost::mutex _state_mutex;
370 friend class paths_test;
371 friend class film_metadata_test;