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"
41 #include "dci_metadata.h"
47 class ExamineContentJob;
48 class AnalyseAudioJob;
49 class ExternalAudioStream;
52 * @brief A representation of a video, maybe with sound.
54 * A representation of a piece of video (maybe with sound), including naming,
55 * the source content file, and how it should be presented in a DCP.
57 class Film : public boost::enable_shared_from_this<Film>
60 Film (std::string d, bool must_exist = true);
64 std::string info_dir () const;
65 std::string j2c_path (int f, bool t) const;
66 std::string info_path (int f) const;
67 std::string internal_video_mxf_dir () const;
68 std::string internal_video_mxf_filename () const;
69 std::string audio_analysis_path () const;
71 std::string dcp_video_mxf_filename () const;
72 std::string dcp_audio_mxf_filename () const;
74 void examine_content ();
75 void analyse_audio ();
76 void send_dcp_to_tms ();
81 * It is safe to call this from any thread.
83 boost::shared_ptr<Log> log () const {
87 int encoded_frames () const;
89 std::string file (std::string f) const;
90 std::string dir (std::string d) const;
92 std::string content_path () const;
93 ContentType content_type () const;
95 int target_audio_sample_rate () const;
97 void write_metadata () const;
98 void read_metadata ();
100 libdcp::Size cropped_size (libdcp::Size) const;
101 std::string dci_name (bool if_created_now) const;
102 std::string dcp_name (bool if_created_now = false) const;
104 /** @return true if our state has changed since we last saved it */
105 bool dirty () const {
109 int audio_channels () const;
111 void set_dci_date_today ();
113 bool have_dcp () const;
120 /** Identifiers for the parts of our state;
121 used for signalling changes.
128 TRUST_CONTENT_HEADER,
138 CONTENT_AUDIO_STREAM,
153 CONTENT_AUDIO_STREAMS,
162 std::string directory () const {
163 boost::mutex::scoped_lock lm (_directory_mutex);
167 std::string name () const {
168 boost::mutex::scoped_lock lm (_state_mutex);
172 bool use_dci_name () const {
173 boost::mutex::scoped_lock lm (_state_mutex);
174 return _use_dci_name;
177 std::string content () const {
178 boost::mutex::scoped_lock lm (_state_mutex);
182 bool trust_content_header () const {
183 boost::mutex::scoped_lock lm (_state_mutex);
184 return _trust_content_header;
187 DCPContentType const * dcp_content_type () const {
188 boost::mutex::scoped_lock lm (_state_mutex);
189 return _dcp_content_type;
192 Format const * format () const {
193 boost::mutex::scoped_lock lm (_state_mutex);
198 boost::mutex::scoped_lock lm (_state_mutex);
202 std::vector<Filter const *> filters () const {
203 boost::mutex::scoped_lock lm (_state_mutex);
207 Scaler const * scaler () const {
208 boost::mutex::scoped_lock lm (_state_mutex);
212 int trim_start () const {
213 boost::mutex::scoped_lock lm (_state_mutex);
217 int trim_end () const {
218 boost::mutex::scoped_lock lm (_state_mutex);
222 TrimType trim_type () const {
223 boost::mutex::scoped_lock lm (_state_mutex);
227 bool dcp_ab () const {
228 boost::mutex::scoped_lock lm (_state_mutex);
232 boost::shared_ptr<AudioStream> content_audio_stream () const {
233 boost::mutex::scoped_lock lm (_state_mutex);
234 return _content_audio_stream;
237 std::vector<std::string> external_audio () const {
238 boost::mutex::scoped_lock lm (_state_mutex);
239 return _external_audio;
242 bool use_content_audio () const {
243 boost::mutex::scoped_lock lm (_state_mutex);
244 return _use_content_audio;
247 float audio_gain () const {
248 boost::mutex::scoped_lock lm (_state_mutex);
252 int audio_delay () const {
253 boost::mutex::scoped_lock lm (_state_mutex);
257 int still_duration () const {
258 boost::mutex::scoped_lock lm (_state_mutex);
259 return _still_duration;
262 int still_duration_in_frames () const;
264 boost::shared_ptr<SubtitleStream> subtitle_stream () const {
265 boost::mutex::scoped_lock lm (_state_mutex);
266 return _subtitle_stream;
269 bool with_subtitles () const {
270 boost::mutex::scoped_lock lm (_state_mutex);
271 return _with_subtitles;
274 int subtitle_offset () const {
275 boost::mutex::scoped_lock lm (_state_mutex);
276 return _subtitle_offset;
279 float subtitle_scale () const {
280 boost::mutex::scoped_lock lm (_state_mutex);
281 return _subtitle_scale;
284 int colour_lut () const {
285 boost::mutex::scoped_lock lm (_state_mutex);
289 int j2k_bandwidth () const {
290 boost::mutex::scoped_lock lm (_state_mutex);
291 return _j2k_bandwidth;
294 DCIMetadata dci_metadata () const {
295 boost::mutex::scoped_lock lm (_state_mutex);
296 return _dci_metadata;
299 int dcp_frame_rate () const {
300 boost::mutex::scoped_lock lm (_state_mutex);
301 return _dcp_frame_rate;
304 libdcp::Size size () const {
305 boost::mutex::scoped_lock lm (_state_mutex);
309 boost::optional<SourceFrame> length () const {
310 boost::mutex::scoped_lock lm (_state_mutex);
314 std::string content_digest () const {
315 boost::mutex::scoped_lock lm (_state_mutex);
316 return _content_digest;
319 std::vector<boost::shared_ptr<AudioStream> > content_audio_streams () const {
320 boost::mutex::scoped_lock lm (_state_mutex);
321 return _content_audio_streams;
324 std::vector<boost::shared_ptr<SubtitleStream> > subtitle_streams () const {
325 boost::mutex::scoped_lock lm (_state_mutex);
326 return _subtitle_streams;
329 float source_frame_rate () const {
330 boost::mutex::scoped_lock lm (_state_mutex);
331 if (content_type() == STILL) {
335 return _source_frame_rate;
338 boost::shared_ptr<AudioStream> audio_stream () const;
339 bool has_audio () const;
343 void set_directory (std::string);
344 void set_name (std::string);
345 void set_use_dci_name (bool);
346 void set_content (std::string);
347 void set_trust_content_header (bool);
348 void set_dcp_content_type (DCPContentType const *);
349 void set_format (Format const *);
350 void set_crop (Crop);
351 void set_left_crop (int);
352 void set_right_crop (int);
353 void set_top_crop (int);
354 void set_bottom_crop (int);
355 void set_filters (std::vector<Filter const *>);
356 void set_scaler (Scaler const *);
357 void set_trim_start (int);
358 void set_trim_end (int);
359 void set_trim_type (TrimType);
360 void set_dcp_ab (bool);
361 void set_content_audio_stream (boost::shared_ptr<AudioStream>);
362 void set_external_audio (std::vector<std::string>);
363 void set_use_content_audio (bool);
364 void set_audio_gain (float);
365 void set_audio_delay (int);
366 void set_still_duration (int);
367 void set_subtitle_stream (boost::shared_ptr<SubtitleStream>);
368 void set_with_subtitles (bool);
369 void set_subtitle_offset (int);
370 void set_subtitle_scale (float);
371 void set_colour_lut (int);
372 void set_j2k_bandwidth (int);
373 void set_dci_metadata (DCIMetadata);
374 void set_dcp_frame_rate (int);
375 void set_size (libdcp::Size);
376 void set_length (SourceFrame);
377 void unset_length ();
378 void set_content_digest (std::string);
379 void set_content_audio_streams (std::vector<boost::shared_ptr<AudioStream> >);
380 void set_subtitle_streams (std::vector<boost::shared_ptr<SubtitleStream> >);
381 void set_source_frame_rate (float);
383 /** Emitted when some property has changed */
384 mutable boost::signals2::signal<void (Property)> Changed;
386 boost::signals2::signal<void ()> AudioAnalysisSucceeded;
388 /** Current version number of the state file */
389 static int const state_version;
393 /** Log to write to */
394 boost::shared_ptr<Log> _log;
396 /** Any running ExamineContentJob, or 0 */
397 boost::shared_ptr<ExamineContentJob> _examine_content_job;
398 /** Any running AnalyseAudioJob, or 0 */
399 boost::shared_ptr<AnalyseAudioJob> _analyse_audio_job;
401 void signal_changed (Property);
402 void examine_content_finished ();
403 void analyse_audio_finished ();
404 std::string video_state_identifier () const;
405 std::string filename_safe_name () const;
407 /** Complete path to directory containing the film metadata;
408 * must not be relative.
410 std::string _directory;
411 /** Mutex for _directory */
412 mutable boost::mutex _directory_mutex;
414 /** Name for DVD-o-matic */
416 /** True if a auto-generated DCI-compliant name should be used for our DCP */
418 /** File or directory containing content; may be relative to our directory
419 * or an absolute path.
421 std::string _content;
422 /** If this is true, we will believe the length specified by the content
423 * file's header; if false, we will run through the whole content file
424 * the first time we see it in order to obtain the length.
426 bool _trust_content_header;
427 /** The type of content that this Film represents (feature, trailer etc.) */
428 DCPContentType const * _dcp_content_type;
429 /** The format to present this Film in (flat, scope, etc.) */
430 Format const * _format;
431 /** The crop to apply to the source */
433 /** Video filters that should be used when generating DCPs */
434 std::vector<Filter const *> _filters;
435 /** Scaler algorithm to use */
436 Scaler const * _scaler;
437 /** Frames to trim off the start of the DCP */
439 /** Frames to trim off the end of the DCP */
442 /** true to create an A/B comparison DCP, where the left half of the image
443 is the video without any filters or post-processing, and the right half
444 has the specified filters and post-processing.
447 /** The audio stream to use from our content */
448 boost::shared_ptr<AudioStream> _content_audio_stream;
449 /** List of filenames of external audio files, in channel order
450 (L, R, C, Lfe, Ls, Rs)
452 std::vector<std::string> _external_audio;
453 /** true to use audio from our content file; false to use external audio */
454 bool _use_content_audio;
455 /** Gain to apply to audio in dB */
457 /** Delay to apply to audio (positive moves audio later) in milliseconds */
459 /** Duration to make still-sourced films (in seconds) */
461 boost::shared_ptr<SubtitleStream> _subtitle_stream;
462 /** True if subtitles should be shown for this film */
463 bool _with_subtitles;
464 /** y offset for placing subtitles, in source pixels; +ve is further down
465 the frame, -ve is further up.
467 int _subtitle_offset;
468 /** scale factor to apply to subtitles */
469 float _subtitle_scale;
470 /** index of colour LUT to use when converting RGB to XYZ.
475 /** bandwidth for J2K files in bits per second */
478 /** DCI naming stuff */
479 DCIMetadata _dci_metadata;
480 /** The date that we should use in a DCI name */
481 boost::gregorian::date _dci_date;
482 /** Frames per second to run our DCP at */
485 /* Data which are cached to speed things up */
487 /** Size, in pixels, of the source (ignoring cropping) */
489 /** The length of the source, in video frames (as far as we know) */
490 boost::optional<SourceFrame> _length;
491 /** MD5 digest of our content file */
492 std::string _content_digest;
493 /** The audio streams in our content */
494 std::vector<boost::shared_ptr<AudioStream> > _content_audio_streams;
495 /** A stream to represent possible external audio (will always exist) */
496 boost::shared_ptr<AudioStream> _sndfile_stream;
497 /** the subtitle streams that we can use */
498 std::vector<boost::shared_ptr<SubtitleStream> > _subtitle_streams;
499 /** Frames per second of the source */
500 float _source_frame_rate;
502 /** true if our state has changed since we last saved it */
505 /** Mutex for all state except _directory */
506 mutable boost::mutex _state_mutex;
508 friend class paths_test;
509 friend class film_metadata_test;