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 with sound.
52 * A representation of a piece of video (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;
99 int audio_channels () const;
101 void set_dci_date_today ();
108 TRUST_CONTENT_HEADER,
118 CONTENT_AUDIO_STREAM,
133 CONTENT_AUDIO_STREAMS,
141 std::string directory () const {
142 boost::mutex::scoped_lock lm (_directory_mutex);
146 std::string name () const {
147 boost::mutex::scoped_lock lm (_state_mutex);
151 bool use_dci_name () const {
152 boost::mutex::scoped_lock lm (_state_mutex);
153 return _use_dci_name;
156 std::string content () const {
157 boost::mutex::scoped_lock lm (_state_mutex);
161 bool trust_content_header () const {
162 boost::mutex::scoped_lock lm (_state_mutex);
163 return _trust_content_header;
166 DCPContentType const * dcp_content_type () const {
167 boost::mutex::scoped_lock lm (_state_mutex);
168 return _dcp_content_type;
171 Format const * format () const {
172 boost::mutex::scoped_lock lm (_state_mutex);
177 boost::mutex::scoped_lock lm (_state_mutex);
181 std::vector<Filter const *> filters () const {
182 boost::mutex::scoped_lock lm (_state_mutex);
186 Scaler const * scaler () const {
187 boost::mutex::scoped_lock lm (_state_mutex);
191 SourceFrame dcp_trim_start () const {
192 boost::mutex::scoped_lock lm (_state_mutex);
193 return _dcp_trim_start;
196 SourceFrame dcp_trim_end () const {
197 boost::mutex::scoped_lock lm (_state_mutex);
198 return _dcp_trim_end;
201 boost::optional<uint64_t> reel_size () const {
202 boost::mutex::scoped_lock lm (_state_mutex);
206 bool dcp_ab () const {
207 boost::mutex::scoped_lock lm (_state_mutex);
211 boost::shared_ptr<AudioStream> content_audio_stream () const {
212 boost::mutex::scoped_lock lm (_state_mutex);
213 return _content_audio_stream;
216 std::vector<std::string> external_audio () const {
217 boost::mutex::scoped_lock lm (_state_mutex);
218 return _external_audio;
221 bool use_content_audio () const {
222 boost::mutex::scoped_lock lm (_state_mutex);
223 return _use_content_audio;
226 float audio_gain () const {
227 boost::mutex::scoped_lock lm (_state_mutex);
231 int audio_delay () const {
232 boost::mutex::scoped_lock lm (_state_mutex);
236 int still_duration () const {
237 boost::mutex::scoped_lock lm (_state_mutex);
238 return _still_duration;
241 boost::shared_ptr<SubtitleStream> subtitle_stream () const {
242 boost::mutex::scoped_lock lm (_state_mutex);
243 return _subtitle_stream;
246 bool with_subtitles () const {
247 boost::mutex::scoped_lock lm (_state_mutex);
248 return _with_subtitles;
251 int subtitle_offset () const {
252 boost::mutex::scoped_lock lm (_state_mutex);
253 return _subtitle_offset;
256 float subtitle_scale () const {
257 boost::mutex::scoped_lock lm (_state_mutex);
258 return _subtitle_scale;
261 /** @return index of colour LUT to use when converting RGB to XYZ.
265 int colour_lut () const {
266 boost::mutex::scoped_lock lm (_state_mutex);
270 /** @return bandwidth for J2K files in bits per second */
271 int j2k_bandwidth () const {
272 boost::mutex::scoped_lock lm (_state_mutex);
273 return _j2k_bandwidth;
276 std::string audio_language () const {
277 boost::mutex::scoped_lock lm (_state_mutex);
278 return _audio_language;
281 std::string subtitle_language () const {
282 boost::mutex::scoped_lock lm (_state_mutex);
283 return _subtitle_language;
286 std::string territory () const {
287 boost::mutex::scoped_lock lm (_state_mutex);
291 std::string rating () const {
292 boost::mutex::scoped_lock lm (_state_mutex);
296 std::string studio () const {
297 boost::mutex::scoped_lock lm (_state_mutex);
301 std::string facility () const {
302 boost::mutex::scoped_lock lm (_state_mutex);
306 std::string package_type () const {
307 boost::mutex::scoped_lock lm (_state_mutex);
308 return _package_type;
312 boost::mutex::scoped_lock lm (_state_mutex);
316 boost::optional<SourceFrame> length () const {
317 boost::mutex::scoped_lock lm (_state_mutex);
321 std::string content_digest () const {
322 boost::mutex::scoped_lock lm (_state_mutex);
323 return _content_digest;
326 std::vector<boost::shared_ptr<AudioStream> > content_audio_streams () const {
327 boost::mutex::scoped_lock lm (_state_mutex);
328 return _content_audio_streams;
331 std::vector<boost::shared_ptr<SubtitleStream> > subtitle_streams () const {
332 boost::mutex::scoped_lock lm (_state_mutex);
333 return _subtitle_streams;
336 float frames_per_second () const {
337 boost::mutex::scoped_lock lm (_state_mutex);
338 if (content_type() == STILL) {
342 return _frames_per_second;
345 boost::shared_ptr<AudioStream> audio_stream () const;
350 void set_directory (std::string);
351 void set_name (std::string);
352 void set_use_dci_name (bool);
353 void set_content (std::string);
354 void set_trust_content_header (bool);
355 void set_dcp_content_type (DCPContentType const *);
356 void set_format (Format const *);
357 void set_crop (Crop);
358 void set_left_crop (int);
359 void set_right_crop (int);
360 void set_top_crop (int);
361 void set_bottom_crop (int);
362 void set_filters (std::vector<Filter const *>);
363 void set_scaler (Scaler const *);
364 void set_dcp_trim_start (int);
365 void set_dcp_trim_end (int);
366 void set_reel_size (uint64_t);
367 void unset_reel_size ();
368 void set_dcp_ab (bool);
369 void set_content_audio_stream (boost::shared_ptr<AudioStream>);
370 void set_external_audio (std::vector<std::string>);
371 void set_use_content_audio (bool);
372 void set_audio_gain (float);
373 void set_audio_delay (int);
374 void set_still_duration (int);
375 void set_subtitle_stream (boost::shared_ptr<SubtitleStream>);
376 void set_with_subtitles (bool);
377 void set_subtitle_offset (int);
378 void set_subtitle_scale (float);
379 void set_colour_lut (int);
380 void set_j2k_bandwidth (int);
381 void set_audio_language (std::string);
382 void set_subtitle_language (std::string);
383 void set_territory (std::string);
384 void set_rating (std::string);
385 void set_studio (std::string);
386 void set_facility (std::string);
387 void set_package_type (std::string);
388 void set_size (Size);
389 void set_length (SourceFrame);
390 void unset_length ();
391 void set_content_digest (std::string);
392 void set_content_audio_streams (std::vector<boost::shared_ptr<AudioStream> >);
393 void set_subtitle_streams (std::vector<boost::shared_ptr<SubtitleStream> >);
394 void set_frames_per_second (float);
396 /** Emitted when some property has changed */
397 mutable boost::signals2::signal<void (Property)> Changed;
399 /** Current version number of the state file */
400 static int const state_version;
404 /** Log to write to */
407 /** Any running ExamineContentJob, or 0 */
408 boost::shared_ptr<ExamineContentJob> _examine_content_job;
410 /** The date that we should use in a DCI name */
411 boost::gregorian::date _dci_date;
413 void signal_changed (Property);
414 void examine_content_finished ();
416 /** Complete path to directory containing the film metadata;
417 * must not be relative.
419 std::string _directory;
420 /** Mutex for _directory */
421 mutable boost::mutex _directory_mutex;
423 /** Name for DVD-o-matic */
425 /** True if a auto-generated DCI-compliant name should be used for our DCP */
427 /** File or directory containing content; may be relative to our directory
428 * or an absolute path.
430 std::string _content;
431 bool _trust_content_header;
432 /** The type of content that this Film represents (feature, trailer etc.) */
433 DCPContentType const * _dcp_content_type;
434 /** The format to present this Film in (flat, scope, etc.) */
435 Format const * _format;
436 /** The crop to apply to the source */
438 /** Video filters that should be used when generating DCPs */
439 std::vector<Filter const *> _filters;
440 /** Scaler algorithm to use */
441 Scaler const * _scaler;
442 /** Frames to trim off the start of the DCP */
444 /** Frames to trim off the end of the DCP */
446 /** Approximate target reel size in bytes; if not set, use a single reel */
447 boost::optional<uint64_t> _reel_size;
448 /** true to create an A/B comparison DCP, where the left half of the image
449 is the video without any filters or post-processing, and the right half
450 has the specified filters and post-processing.
453 /** The audio stream to use from our content */
454 boost::shared_ptr<AudioStream> _content_audio_stream;
455 /** List of filenames of external audio files, in channel order
456 (L, R, C, Lfe, Ls, Rs)
458 std::vector<std::string> _external_audio;
459 /** true to use audio from our content file; false to use external audio */
460 bool _use_content_audio;
461 /** Gain to apply to audio in dB */
463 /** Delay to apply to audio (positive moves audio later) in milliseconds */
465 /** Duration to make still-sourced films (in seconds) */
467 boost::shared_ptr<SubtitleStream> _subtitle_stream;
468 /** True if subtitles should be shown for this film */
469 bool _with_subtitles;
470 /** y offset for placing subtitles, in source pixels; +ve is further down
471 the frame, -ve is further up.
473 int _subtitle_offset;
474 /** scale factor to apply to subtitles */
475 float _subtitle_scale;
476 /** index of colour LUT to use when converting RGB to XYZ
477 * (see colour_lut ())
480 /** bandwidth for J2K files in bits per second */
483 /* DCI naming stuff */
484 std::string _audio_language;
485 std::string _subtitle_language;
486 std::string _territory;
489 std::string _facility;
490 std::string _package_type;
492 /* Data which are cached to speed things up */
494 /** Size, in pixels, of the source (ignoring cropping) */
496 /** The length of the source, in video frames (as far as we know) */
497 boost::optional<SourceFrame> _length;
498 /** MD5 digest of our content file */
499 std::string _content_digest;
500 /** The audio streams in our content */
501 std::vector<boost::shared_ptr<AudioStream> > _content_audio_streams;
502 /** A stream to represent possible external audio (will always exist) */
503 boost::shared_ptr<AudioStream> _external_audio_stream;
504 /** the subtitle streams that we can use */
505 std::vector<boost::shared_ptr<SubtitleStream> > _subtitle_streams;
506 /** Frames per second of the source */
507 float _frames_per_second;
509 /** true if our state has changed since we last saved it */
512 /** Mutex for all state except _directory */
513 mutable boost::mutex _state_mutex;
515 friend class paths_test;