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>
35 #include <boost/date_time/posix_time/posix_time.hpp>
37 #include <libavcodec/avcodec.h>
39 #include "dcp_content_type.h"
47 class ExamineContentJob;
48 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 j2k_dir () const;
66 void examine_content ();
67 void send_dcp_to_tms ();
72 * It is safe to call this from any thread.
78 int encoded_frames () const;
80 std::string file (std::string f) const;
81 std::string dir (std::string d) const;
83 std::string content_path () const;
84 ContentType content_type () const;
86 int target_audio_sample_rate () const;
88 void write_metadata () const;
89 void read_metadata ();
91 Size cropped_size (Size) const;
92 boost::optional<int> dcp_length () const;
93 std::string dci_name () const;
94 std::string dcp_name () const;
96 /** @return true if our state has changed since we last saved it */
101 int audio_channels () const;
103 void set_dci_date_today ();
106 std::list<boost::shared_ptr<Screen> >,
107 boost::posix_time::ptime from,
108 boost::posix_time::ptime until,
109 std::string directory
112 /** Identifiers for the parts of our state;
113 used for signalling changes.
120 TRUST_CONTENT_HEADER,
130 CONTENT_AUDIO_STREAM,
146 CONTENT_AUDIO_STREAMS,
154 std::string directory () const {
155 boost::mutex::scoped_lock lm (_directory_mutex);
159 std::string name () const {
160 boost::mutex::scoped_lock lm (_state_mutex);
164 bool use_dci_name () const {
165 boost::mutex::scoped_lock lm (_state_mutex);
166 return _use_dci_name;
169 std::string content () const {
170 boost::mutex::scoped_lock lm (_state_mutex);
174 bool trust_content_header () const {
175 boost::mutex::scoped_lock lm (_state_mutex);
176 return _trust_content_header;
179 DCPContentType const * dcp_content_type () const {
180 boost::mutex::scoped_lock lm (_state_mutex);
181 return _dcp_content_type;
184 Format const * format () const {
185 boost::mutex::scoped_lock lm (_state_mutex);
190 boost::mutex::scoped_lock lm (_state_mutex);
194 std::vector<Filter const *> filters () const {
195 boost::mutex::scoped_lock lm (_state_mutex);
199 Scaler const * scaler () const {
200 boost::mutex::scoped_lock lm (_state_mutex);
204 SourceFrame dcp_trim_start () const {
205 boost::mutex::scoped_lock lm (_state_mutex);
206 return _dcp_trim_start;
209 SourceFrame dcp_trim_end () const {
210 boost::mutex::scoped_lock lm (_state_mutex);
211 return _dcp_trim_end;
214 boost::optional<uint64_t> reel_size () const {
215 boost::mutex::scoped_lock lm (_state_mutex);
219 bool dcp_ab () const {
220 boost::mutex::scoped_lock lm (_state_mutex);
224 boost::shared_ptr<AudioStream> content_audio_stream () const {
225 boost::mutex::scoped_lock lm (_state_mutex);
226 return _content_audio_stream;
229 std::vector<std::string> external_audio () const {
230 boost::mutex::scoped_lock lm (_state_mutex);
231 return _external_audio;
234 bool use_content_audio () const {
235 boost::mutex::scoped_lock lm (_state_mutex);
236 return _use_content_audio;
239 float audio_gain () const {
240 boost::mutex::scoped_lock lm (_state_mutex);
244 int audio_delay () const {
245 boost::mutex::scoped_lock lm (_state_mutex);
249 int still_duration () const {
250 boost::mutex::scoped_lock lm (_state_mutex);
251 return _still_duration;
254 boost::shared_ptr<SubtitleStream> subtitle_stream () const {
255 boost::mutex::scoped_lock lm (_state_mutex);
256 return _subtitle_stream;
259 bool with_subtitles () const {
260 boost::mutex::scoped_lock lm (_state_mutex);
261 return _with_subtitles;
264 int subtitle_offset () const {
265 boost::mutex::scoped_lock lm (_state_mutex);
266 return _subtitle_offset;
269 float subtitle_scale () const {
270 boost::mutex::scoped_lock lm (_state_mutex);
271 return _subtitle_scale;
274 bool encrypted () const {
275 boost::mutex::scoped_lock lm (_state_mutex);
279 int colour_lut () const {
280 boost::mutex::scoped_lock lm (_state_mutex);
284 int j2k_bandwidth () const {
285 boost::mutex::scoped_lock lm (_state_mutex);
286 return _j2k_bandwidth;
289 std::string audio_language () const {
290 boost::mutex::scoped_lock lm (_state_mutex);
291 return _audio_language;
294 std::string subtitle_language () const {
295 boost::mutex::scoped_lock lm (_state_mutex);
296 return _subtitle_language;
299 std::string territory () const {
300 boost::mutex::scoped_lock lm (_state_mutex);
304 std::string rating () const {
305 boost::mutex::scoped_lock lm (_state_mutex);
309 std::string studio () const {
310 boost::mutex::scoped_lock lm (_state_mutex);
314 std::string facility () const {
315 boost::mutex::scoped_lock lm (_state_mutex);
319 std::string package_type () const {
320 boost::mutex::scoped_lock lm (_state_mutex);
321 return _package_type;
325 boost::mutex::scoped_lock lm (_state_mutex);
329 boost::optional<SourceFrame> length () const {
330 boost::mutex::scoped_lock lm (_state_mutex);
334 std::string content_digest () const {
335 boost::mutex::scoped_lock lm (_state_mutex);
336 return _content_digest;
339 std::vector<boost::shared_ptr<AudioStream> > content_audio_streams () const {
340 boost::mutex::scoped_lock lm (_state_mutex);
341 return _content_audio_streams;
344 std::vector<boost::shared_ptr<SubtitleStream> > subtitle_streams () const {
345 boost::mutex::scoped_lock lm (_state_mutex);
346 return _subtitle_streams;
349 float frames_per_second () const {
350 boost::mutex::scoped_lock lm (_state_mutex);
351 if (content_type() == STILL) {
355 return _frames_per_second;
358 boost::shared_ptr<AudioStream> audio_stream () const;
363 void set_directory (std::string);
364 void set_name (std::string);
365 void set_use_dci_name (bool);
366 void set_content (std::string);
367 void set_trust_content_header (bool);
368 void set_dcp_content_type (DCPContentType const *);
369 void set_format (Format const *);
370 void set_crop (Crop);
371 void set_left_crop (int);
372 void set_right_crop (int);
373 void set_top_crop (int);
374 void set_bottom_crop (int);
375 void set_filters (std::vector<Filter const *>);
376 void set_scaler (Scaler const *);
377 void set_dcp_trim_start (int);
378 void set_dcp_trim_end (int);
379 void set_reel_size (uint64_t);
380 void unset_reel_size ();
381 void set_dcp_ab (bool);
382 void set_content_audio_stream (boost::shared_ptr<AudioStream>);
383 void set_external_audio (std::vector<std::string>);
384 void set_use_content_audio (bool);
385 void set_audio_gain (float);
386 void set_audio_delay (int);
387 void set_still_duration (int);
388 void set_subtitle_stream (boost::shared_ptr<SubtitleStream>);
389 void set_with_subtitles (bool);
390 void set_subtitle_offset (int);
391 void set_subtitle_scale (float);
392 void set_encrypted (bool);
393 void set_colour_lut (int);
394 void set_j2k_bandwidth (int);
395 void set_audio_language (std::string);
396 void set_subtitle_language (std::string);
397 void set_territory (std::string);
398 void set_rating (std::string);
399 void set_studio (std::string);
400 void set_facility (std::string);
401 void set_package_type (std::string);
402 void set_size (Size);
403 void set_length (SourceFrame);
404 void unset_length ();
405 void set_content_digest (std::string);
406 void set_content_audio_streams (std::vector<boost::shared_ptr<AudioStream> >);
407 void set_subtitle_streams (std::vector<boost::shared_ptr<SubtitleStream> >);
408 void set_frames_per_second (float);
410 /** Emitted when some property has changed */
411 mutable boost::signals2::signal<void (Property)> Changed;
413 /** Current version number of the state file */
414 static int const state_version;
418 /** Log to write to */
421 /** Any running ExamineContentJob, or 0 */
422 boost::shared_ptr<ExamineContentJob> _examine_content_job;
424 /** The date that we should use in a DCI name */
425 boost::gregorian::date _dci_date;
427 void signal_changed (Property);
428 void examine_content_finished ();
430 /** Complete path to directory containing the film metadata;
431 * must not be relative.
433 std::string _directory;
434 /** Mutex for _directory */
435 mutable boost::mutex _directory_mutex;
437 /** Name for DVD-o-matic */
439 /** True if a auto-generated DCI-compliant name should be used for our DCP */
441 /** File or directory containing content; may be relative to our directory
442 * or an absolute path.
444 std::string _content;
445 /** If this is true, we will believe the length specified by the content
446 * file's header; if false, we will run through the whole content file
447 * the first time we see it in order to obtain the length.
449 bool _trust_content_header;
450 /** The type of content that this Film represents (feature, trailer etc.) */
451 DCPContentType const * _dcp_content_type;
452 /** The format to present this Film in (flat, scope, etc.) */
453 Format const * _format;
454 /** The crop to apply to the source */
456 /** Video filters that should be used when generating DCPs */
457 std::vector<Filter const *> _filters;
458 /** Scaler algorithm to use */
459 Scaler const * _scaler;
460 /** Frames to trim off the start of the DCP */
462 /** Frames to trim off the end of the DCP */
464 /** Approximate target reel size in bytes; if not set, use a single reel */
465 boost::optional<uint64_t> _reel_size;
466 /** true to create an A/B comparison DCP, where the left half of the image
467 is the video without any filters or post-processing, and the right half
468 has the specified filters and post-processing.
471 /** The audio stream to use from our content */
472 boost::shared_ptr<AudioStream> _content_audio_stream;
473 /** List of filenames of external audio files, in channel order
474 (L, R, C, Lfe, Ls, Rs)
476 std::vector<std::string> _external_audio;
477 /** true to use audio from our content file; false to use external audio */
478 bool _use_content_audio;
479 /** Gain to apply to audio in dB */
481 /** Delay to apply to audio (positive moves audio later) in milliseconds */
483 /** Duration to make still-sourced films (in seconds) */
485 boost::shared_ptr<SubtitleStream> _subtitle_stream;
486 /** True if subtitles should be shown for this film */
487 bool _with_subtitles;
488 /** y offset for placing subtitles, in source pixels; +ve is further down
489 the frame, -ve is further up.
491 int _subtitle_offset;
492 /** scale factor to apply to subtitles */
493 float _subtitle_scale;
496 /** index of colour LUT to use when converting RGB to XYZ.
501 /** bandwidth for J2K files in bits per second */
504 /* DCI naming stuff */
505 std::string _audio_language;
506 std::string _subtitle_language;
507 std::string _territory;
510 std::string _facility;
511 std::string _package_type;
513 /* Data which are cached to speed things up */
515 /** Size, in pixels, of the source (ignoring cropping) */
517 /** The length of the source, in video frames (as far as we know) */
518 boost::optional<SourceFrame> _length;
519 /** MD5 digest of our content file */
520 std::string _content_digest;
521 /** The audio streams in our content */
522 std::vector<boost::shared_ptr<AudioStream> > _content_audio_streams;
523 /** A stream to represent possible external audio (will always exist) */
524 boost::shared_ptr<AudioStream> _external_audio_stream;
525 /** the subtitle streams that we can use */
526 std::vector<boost::shared_ptr<SubtitleStream> > _subtitle_streams;
527 /** Frames per second of the source */
528 float _frames_per_second;
530 /** true if our state has changed since we last saved it */
533 /** Mutex for all state except _directory */
534 mutable boost::mutex _state_mutex;
536 friend class paths_test;