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 video_mxf_dir () const;
68 std::string video_mxf_filename () const;
69 std::string audio_analysis_path () const;
71 void examine_content ();
72 void analyse_audio ();
73 void send_dcp_to_tms ();
78 * It is safe to call this from any thread.
84 int encoded_frames () const;
86 std::string file (std::string f) const;
87 std::string dir (std::string d) const;
89 std::string content_path () const;
90 ContentType content_type () const;
92 int target_audio_sample_rate () const;
94 void write_metadata () const;
95 void read_metadata ();
97 libdcp::Size cropped_size (libdcp::Size) const;
98 std::string dci_name (bool if_created_now) const;
99 std::string dcp_name (bool if_created_now = false) const;
101 boost::optional<int> dcp_intrinsic_duration () const {
102 return _dcp_intrinsic_duration;
105 /** @return true if our state has changed since we last saved it */
106 bool dirty () const {
110 int audio_channels () const;
112 void set_dci_date_today ();
114 bool have_dcp () const;
116 /** Identifiers for the parts of our state;
117 used for signalling changes.
124 TRUST_CONTENT_HEADER,
133 CONTENT_AUDIO_STREAM,
148 DCP_INTRINSIC_DURATION,
149 CONTENT_AUDIO_STREAMS,
158 std::string directory () const {
159 boost::mutex::scoped_lock lm (_directory_mutex);
163 std::string name () const {
164 boost::mutex::scoped_lock lm (_state_mutex);
168 bool use_dci_name () const {
169 boost::mutex::scoped_lock lm (_state_mutex);
170 return _use_dci_name;
173 std::string content () const {
174 boost::mutex::scoped_lock lm (_state_mutex);
178 bool trust_content_header () const {
179 boost::mutex::scoped_lock lm (_state_mutex);
180 return _trust_content_header;
183 DCPContentType const * dcp_content_type () const {
184 boost::mutex::scoped_lock lm (_state_mutex);
185 return _dcp_content_type;
188 Format const * format () const {
189 boost::mutex::scoped_lock lm (_state_mutex);
194 boost::mutex::scoped_lock lm (_state_mutex);
198 std::vector<Filter const *> filters () const {
199 boost::mutex::scoped_lock lm (_state_mutex);
203 Scaler const * scaler () const {
204 boost::mutex::scoped_lock lm (_state_mutex);
208 int trim_start () const {
209 boost::mutex::scoped_lock lm (_state_mutex);
213 int trim_end () const {
214 boost::mutex::scoped_lock lm (_state_mutex);
218 bool dcp_ab () const {
219 boost::mutex::scoped_lock lm (_state_mutex);
223 boost::shared_ptr<AudioStream> content_audio_stream () const {
224 boost::mutex::scoped_lock lm (_state_mutex);
225 return _content_audio_stream;
228 std::vector<std::string> external_audio () const {
229 boost::mutex::scoped_lock lm (_state_mutex);
230 return _external_audio;
233 bool use_content_audio () const {
234 boost::mutex::scoped_lock lm (_state_mutex);
235 return _use_content_audio;
238 float audio_gain () const {
239 boost::mutex::scoped_lock lm (_state_mutex);
243 int audio_delay () const {
244 boost::mutex::scoped_lock lm (_state_mutex);
248 int still_duration () const {
249 boost::mutex::scoped_lock lm (_state_mutex);
250 return _still_duration;
253 int still_duration_in_frames () const;
255 boost::shared_ptr<SubtitleStream> subtitle_stream () const {
256 boost::mutex::scoped_lock lm (_state_mutex);
257 return _subtitle_stream;
260 bool with_subtitles () const {
261 boost::mutex::scoped_lock lm (_state_mutex);
262 return _with_subtitles;
265 int subtitle_offset () const {
266 boost::mutex::scoped_lock lm (_state_mutex);
267 return _subtitle_offset;
270 float subtitle_scale () const {
271 boost::mutex::scoped_lock lm (_state_mutex);
272 return _subtitle_scale;
275 int colour_lut () const {
276 boost::mutex::scoped_lock lm (_state_mutex);
280 int j2k_bandwidth () const {
281 boost::mutex::scoped_lock lm (_state_mutex);
282 return _j2k_bandwidth;
285 DCIMetadata dci_metadata () const {
286 boost::mutex::scoped_lock lm (_state_mutex);
287 return _dci_metadata;
290 int dcp_frame_rate () const {
291 boost::mutex::scoped_lock lm (_state_mutex);
292 return _dcp_frame_rate;
295 libdcp::Size size () const {
296 boost::mutex::scoped_lock lm (_state_mutex);
300 boost::optional<SourceFrame> length () const {
301 boost::mutex::scoped_lock lm (_state_mutex);
305 std::string content_digest () const {
306 boost::mutex::scoped_lock lm (_state_mutex);
307 return _content_digest;
310 std::vector<boost::shared_ptr<AudioStream> > content_audio_streams () const {
311 boost::mutex::scoped_lock lm (_state_mutex);
312 return _content_audio_streams;
315 std::vector<boost::shared_ptr<SubtitleStream> > subtitle_streams () const {
316 boost::mutex::scoped_lock lm (_state_mutex);
317 return _subtitle_streams;
320 float source_frame_rate () const {
321 boost::mutex::scoped_lock lm (_state_mutex);
322 if (content_type() == STILL) {
326 return _source_frame_rate;
329 boost::shared_ptr<AudioStream> audio_stream () const;
334 void set_directory (std::string);
335 void set_name (std::string);
336 void set_use_dci_name (bool);
337 void set_content (std::string);
338 void set_trust_content_header (bool);
339 void set_dcp_content_type (DCPContentType const *);
340 void set_format (Format const *);
341 void set_crop (Crop);
342 void set_left_crop (int);
343 void set_right_crop (int);
344 void set_top_crop (int);
345 void set_bottom_crop (int);
346 void set_filters (std::vector<Filter const *>);
347 void set_scaler (Scaler const *);
348 void set_trim_start (int);
349 void set_trim_end (int);
350 void set_dcp_ab (bool);
351 void set_content_audio_stream (boost::shared_ptr<AudioStream>);
352 void set_external_audio (std::vector<std::string>);
353 void set_use_content_audio (bool);
354 void set_audio_gain (float);
355 void set_audio_delay (int);
356 void set_still_duration (int);
357 void set_subtitle_stream (boost::shared_ptr<SubtitleStream>);
358 void set_with_subtitles (bool);
359 void set_subtitle_offset (int);
360 void set_subtitle_scale (float);
361 void set_colour_lut (int);
362 void set_j2k_bandwidth (int);
363 void set_dci_metadata (DCIMetadata);
364 void set_dcp_frame_rate (int);
365 void set_size (libdcp::Size);
366 void set_length (SourceFrame);
367 void unset_length ();
368 void set_dcp_intrinsic_duration (int);
369 void set_content_digest (std::string);
370 void set_content_audio_streams (std::vector<boost::shared_ptr<AudioStream> >);
371 void set_subtitle_streams (std::vector<boost::shared_ptr<SubtitleStream> >);
372 void set_source_frame_rate (float);
374 /** Emitted when some property has changed */
375 mutable boost::signals2::signal<void (Property)> Changed;
377 boost::signals2::signal<void ()> AudioAnalysisFinished;
379 /** Current version number of the state file */
380 static int const state_version;
384 /** Log to write to */
387 /** Any running ExamineContentJob, or 0 */
388 boost::shared_ptr<ExamineContentJob> _examine_content_job;
389 /** Any running AnalyseAudioJob, or 0 */
390 boost::shared_ptr<AnalyseAudioJob> _analyse_audio_job;
392 void signal_changed (Property);
393 void examine_content_finished ();
394 void analyse_audio_finished ();
395 std::string video_state_identifier () const;
397 /** Complete path to directory containing the film metadata;
398 * must not be relative.
400 std::string _directory;
401 /** Mutex for _directory */
402 mutable boost::mutex _directory_mutex;
404 /** Name for DVD-o-matic */
406 /** True if a auto-generated DCI-compliant name should be used for our DCP */
408 /** File or directory containing content; may be relative to our directory
409 * or an absolute path.
411 std::string _content;
412 /** If this is true, we will believe the length specified by the content
413 * file's header; if false, we will run through the whole content file
414 * the first time we see it in order to obtain the length.
416 bool _trust_content_header;
417 /** The type of content that this Film represents (feature, trailer etc.) */
418 DCPContentType const * _dcp_content_type;
419 /** The format to present this Film in (flat, scope, etc.) */
420 Format const * _format;
421 /** The crop to apply to the source */
423 /** Video filters that should be used when generating DCPs */
424 std::vector<Filter const *> _filters;
425 /** Scaler algorithm to use */
426 Scaler const * _scaler;
427 /** Frames to trim off the start of the DCP */
429 /** Frames to trim off the end of the DCP */
431 /** true to create an A/B comparison DCP, where the left half of the image
432 is the video without any filters or post-processing, and the right half
433 has the specified filters and post-processing.
436 /** The audio stream to use from our content */
437 boost::shared_ptr<AudioStream> _content_audio_stream;
438 /** List of filenames of external audio files, in channel order
439 (L, R, C, Lfe, Ls, Rs)
441 std::vector<std::string> _external_audio;
442 /** true to use audio from our content file; false to use external audio */
443 bool _use_content_audio;
444 /** Gain to apply to audio in dB */
446 /** Delay to apply to audio (positive moves audio later) in milliseconds */
448 /** Duration to make still-sourced films (in seconds) */
450 boost::shared_ptr<SubtitleStream> _subtitle_stream;
451 /** True if subtitles should be shown for this film */
452 bool _with_subtitles;
453 /** y offset for placing subtitles, in source pixels; +ve is further down
454 the frame, -ve is further up.
456 int _subtitle_offset;
457 /** scale factor to apply to subtitles */
458 float _subtitle_scale;
459 /** index of colour LUT to use when converting RGB to XYZ.
464 /** bandwidth for J2K files in bits per second */
467 /** DCI naming stuff */
468 DCIMetadata _dci_metadata;
469 /** The date that we should use in a DCI name */
470 boost::gregorian::date _dci_date;
471 /** Frames per second to run our DCP at */
474 /* Data which are cached to speed things up */
476 /** Size, in pixels, of the source (ignoring cropping) */
478 /** The length of the source, in video frames (as far as we know) */
479 boost::optional<SourceFrame> _length;
480 boost::optional<int> _dcp_intrinsic_duration;
481 /** MD5 digest of our content file */
482 std::string _content_digest;
483 /** The audio streams in our content */
484 std::vector<boost::shared_ptr<AudioStream> > _content_audio_streams;
485 /** A stream to represent possible external audio (will always exist) */
486 boost::shared_ptr<AudioStream> _external_audio_stream;
487 /** the subtitle streams that we can use */
488 std::vector<boost::shared_ptr<SubtitleStream> > _subtitle_streams;
489 /** Frames per second of the source */
490 float _source_frame_rate;
492 /** true if our state has changed since we last saved it */
495 /** Mutex for all state except _directory */
496 mutable boost::mutex _state_mutex;
498 friend class paths_test;
499 friend class film_metadata_test;