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"
46 class ExamineContentJob;
47 class ExternalAudioStream;
50 * @brief A representation of a video, maybe with sound.
52 * A representation of a piece of video (maybe with sound), including naming,
53 * the source content file, and how it should be presented in a DCP.
55 class Film : public boost::enable_shared_from_this<Film>
58 Film (std::string d, bool must_exist = true);
62 std::string j2k_dir () const;
63 std::vector<std::string> audio_files () const;
65 void examine_content ();
66 void send_dcp_to_tms ();
71 * It is safe to call this from any thread.
77 int encoded_frames () const;
79 std::string file (std::string f) const;
80 std::string dir (std::string d) const;
82 std::string content_path () const;
83 ContentType content_type () const;
85 int target_audio_sample_rate () const;
87 void write_metadata () const;
88 void read_metadata ();
90 Size cropped_size (Size) const;
91 boost::optional<int> dcp_length () const;
92 std::string dci_name () const;
93 std::string dcp_name () const;
95 /** @return true if our state has changed since we last saved it */
100 int audio_channels () const;
102 void set_dci_date_today ();
104 /** Identifiers for the parts of our state;
105 used for signalling changes.
112 TRUST_CONTENT_HEADER,
122 CONTENT_AUDIO_STREAM,
137 CONTENT_AUDIO_STREAMS,
145 std::string directory () const {
146 boost::mutex::scoped_lock lm (_directory_mutex);
150 std::string name () const {
151 boost::mutex::scoped_lock lm (_state_mutex);
155 bool use_dci_name () const {
156 boost::mutex::scoped_lock lm (_state_mutex);
157 return _use_dci_name;
160 std::string content () const {
161 boost::mutex::scoped_lock lm (_state_mutex);
165 bool trust_content_header () const {
166 boost::mutex::scoped_lock lm (_state_mutex);
167 return _trust_content_header;
170 DCPContentType const * dcp_content_type () const {
171 boost::mutex::scoped_lock lm (_state_mutex);
172 return _dcp_content_type;
175 Format const * format () const {
176 boost::mutex::scoped_lock lm (_state_mutex);
181 boost::mutex::scoped_lock lm (_state_mutex);
185 std::vector<Filter const *> filters () const {
186 boost::mutex::scoped_lock lm (_state_mutex);
190 Scaler const * scaler () const {
191 boost::mutex::scoped_lock lm (_state_mutex);
195 SourceFrame dcp_trim_start () const {
196 boost::mutex::scoped_lock lm (_state_mutex);
197 return _dcp_trim_start;
200 SourceFrame dcp_trim_end () const {
201 boost::mutex::scoped_lock lm (_state_mutex);
202 return _dcp_trim_end;
205 boost::optional<uint64_t> reel_size () const {
206 boost::mutex::scoped_lock lm (_state_mutex);
210 bool dcp_ab () const {
211 boost::mutex::scoped_lock lm (_state_mutex);
215 boost::shared_ptr<AudioStream> content_audio_stream () const {
216 boost::mutex::scoped_lock lm (_state_mutex);
217 return _content_audio_stream;
220 std::vector<std::string> external_audio () const {
221 boost::mutex::scoped_lock lm (_state_mutex);
222 return _external_audio;
225 bool use_content_audio () const {
226 boost::mutex::scoped_lock lm (_state_mutex);
227 return _use_content_audio;
230 float audio_gain () const {
231 boost::mutex::scoped_lock lm (_state_mutex);
235 int audio_delay () const {
236 boost::mutex::scoped_lock lm (_state_mutex);
240 int still_duration () const {
241 boost::mutex::scoped_lock lm (_state_mutex);
242 return _still_duration;
245 boost::shared_ptr<SubtitleStream> subtitle_stream () const {
246 boost::mutex::scoped_lock lm (_state_mutex);
247 return _subtitle_stream;
250 bool with_subtitles () const {
251 boost::mutex::scoped_lock lm (_state_mutex);
252 return _with_subtitles;
255 int subtitle_offset () const {
256 boost::mutex::scoped_lock lm (_state_mutex);
257 return _subtitle_offset;
260 float subtitle_scale () const {
261 boost::mutex::scoped_lock lm (_state_mutex);
262 return _subtitle_scale;
265 int colour_lut () const {
266 boost::mutex::scoped_lock lm (_state_mutex);
270 int j2k_bandwidth () const {
271 boost::mutex::scoped_lock lm (_state_mutex);
272 return _j2k_bandwidth;
275 std::string audio_language () const {
276 boost::mutex::scoped_lock lm (_state_mutex);
277 return _audio_language;
280 std::string subtitle_language () const {
281 boost::mutex::scoped_lock lm (_state_mutex);
282 return _subtitle_language;
285 std::string territory () const {
286 boost::mutex::scoped_lock lm (_state_mutex);
290 std::string rating () const {
291 boost::mutex::scoped_lock lm (_state_mutex);
295 std::string studio () const {
296 boost::mutex::scoped_lock lm (_state_mutex);
300 std::string facility () const {
301 boost::mutex::scoped_lock lm (_state_mutex);
305 std::string package_type () const {
306 boost::mutex::scoped_lock lm (_state_mutex);
307 return _package_type;
311 boost::mutex::scoped_lock lm (_state_mutex);
315 boost::optional<SourceFrame> length () const {
316 boost::mutex::scoped_lock lm (_state_mutex);
320 std::string content_digest () const {
321 boost::mutex::scoped_lock lm (_state_mutex);
322 return _content_digest;
325 std::vector<boost::shared_ptr<AudioStream> > content_audio_streams () const {
326 boost::mutex::scoped_lock lm (_state_mutex);
327 return _content_audio_streams;
330 std::vector<boost::shared_ptr<SubtitleStream> > subtitle_streams () const {
331 boost::mutex::scoped_lock lm (_state_mutex);
332 return _subtitle_streams;
335 float frames_per_second () const {
336 boost::mutex::scoped_lock lm (_state_mutex);
337 if (content_type() == STILL) {
341 return _frames_per_second;
344 boost::shared_ptr<AudioStream> audio_stream () const;
349 void set_directory (std::string);
350 void set_name (std::string);
351 void set_use_dci_name (bool);
352 void set_content (std::string);
353 void set_trust_content_header (bool);
354 void set_dcp_content_type (DCPContentType const *);
355 void set_format (Format const *);
356 void set_crop (Crop);
357 void set_left_crop (int);
358 void set_right_crop (int);
359 void set_top_crop (int);
360 void set_bottom_crop (int);
361 void set_filters (std::vector<Filter const *>);
362 void set_scaler (Scaler const *);
363 void set_dcp_trim_start (int);
364 void set_dcp_trim_end (int);
365 void set_reel_size (uint64_t);
366 void unset_reel_size ();
367 void set_dcp_ab (bool);
368 void set_content_audio_stream (boost::shared_ptr<AudioStream>);
369 void set_external_audio (std::vector<std::string>);
370 void set_use_content_audio (bool);
371 void set_audio_gain (float);
372 void set_audio_delay (int);
373 void set_still_duration (int);
374 void set_subtitle_stream (boost::shared_ptr<SubtitleStream>);
375 void set_with_subtitles (bool);
376 void set_subtitle_offset (int);
377 void set_subtitle_scale (float);
378 void set_colour_lut (int);
379 void set_j2k_bandwidth (int);
380 void set_audio_language (std::string);
381 void set_subtitle_language (std::string);
382 void set_territory (std::string);
383 void set_rating (std::string);
384 void set_studio (std::string);
385 void set_facility (std::string);
386 void set_package_type (std::string);
387 void set_size (Size);
388 void set_length (SourceFrame);
389 void unset_length ();
390 void set_content_digest (std::string);
391 void set_content_audio_streams (std::vector<boost::shared_ptr<AudioStream> >);
392 void set_subtitle_streams (std::vector<boost::shared_ptr<SubtitleStream> >);
393 void set_frames_per_second (float);
395 /** Emitted when some property has changed */
396 mutable boost::signals2::signal<void (Property)> Changed;
398 /** Current version number of the state file */
399 static int const state_version;
403 /** Log to write to */
406 /** Any running ExamineContentJob, or 0 */
407 boost::shared_ptr<ExamineContentJob> _examine_content_job;
409 /** The date that we should use in a DCI name */
410 boost::gregorian::date _dci_date;
412 void signal_changed (Property);
413 void examine_content_finished ();
415 /** Complete path to directory containing the film metadata;
416 * must not be relative.
418 std::string _directory;
419 /** Mutex for _directory */
420 mutable boost::mutex _directory_mutex;
422 /** Name for DVD-o-matic */
424 /** True if a auto-generated DCI-compliant name should be used for our DCP */
426 /** File or directory containing content; may be relative to our directory
427 * or an absolute path.
429 std::string _content;
430 /** If this is true, we will believe the length specified by the content
431 * file's header; if false, we will run through the whole content file
432 * the first time we see it in order to obtain the length.
434 bool _trust_content_header;
435 /** The type of content that this Film represents (feature, trailer etc.) */
436 DCPContentType const * _dcp_content_type;
437 /** The format to present this Film in (flat, scope, etc.) */
438 Format const * _format;
439 /** The crop to apply to the source */
441 /** Video filters that should be used when generating DCPs */
442 std::vector<Filter const *> _filters;
443 /** Scaler algorithm to use */
444 Scaler const * _scaler;
445 /** Frames to trim off the start of the DCP */
447 /** Frames to trim off the end of the DCP */
449 /** Approximate target reel size in bytes; if not set, use a single reel */
450 boost::optional<uint64_t> _reel_size;
451 /** true to create an A/B comparison DCP, where the left half of the image
452 is the video without any filters or post-processing, and the right half
453 has the specified filters and post-processing.
456 /** The audio stream to use from our content */
457 boost::shared_ptr<AudioStream> _content_audio_stream;
458 /** List of filenames of external audio files, in channel order
459 (L, R, C, Lfe, Ls, Rs)
461 std::vector<std::string> _external_audio;
462 /** true to use audio from our content file; false to use external audio */
463 bool _use_content_audio;
464 /** Gain to apply to audio in dB */
466 /** Delay to apply to audio (positive moves audio later) in milliseconds */
468 /** Duration to make still-sourced films (in seconds) */
470 boost::shared_ptr<SubtitleStream> _subtitle_stream;
471 /** True if subtitles should be shown for this film */
472 bool _with_subtitles;
473 /** y offset for placing subtitles, in source pixels; +ve is further down
474 the frame, -ve is further up.
476 int _subtitle_offset;
477 /** scale factor to apply to subtitles */
478 float _subtitle_scale;
479 /** index of colour LUT to use when converting RGB to XYZ.
484 /** bandwidth for J2K files in bits per second */
487 /* DCI naming stuff */
488 std::string _audio_language;
489 std::string _subtitle_language;
490 std::string _territory;
493 std::string _facility;
494 std::string _package_type;
496 /* Data which are cached to speed things up */
498 /** Size, in pixels, of the source (ignoring cropping) */
500 /** The length of the source, in video frames (as far as we know) */
501 boost::optional<SourceFrame> _length;
502 /** MD5 digest of our content file */
503 std::string _content_digest;
504 /** The audio streams in our content */
505 std::vector<boost::shared_ptr<AudioStream> > _content_audio_streams;
506 /** A stream to represent possible external audio (will always exist) */
507 boost::shared_ptr<AudioStream> _external_audio_stream;
508 /** the subtitle streams that we can use */
509 std::vector<boost::shared_ptr<SubtitleStream> > _subtitle_streams;
510 /** Frames per second of the source */
511 float _frames_per_second;
513 /** true if our state has changed since we last saved it */
516 /** Mutex for all state except _directory */
517 mutable boost::mutex _state_mutex;
519 friend class paths_test;