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;
64 std::pair<Position, std::string> thumb_subtitle (int) 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 bool content_is_dvd () const;
88 std::string thumb_file (int) const;
89 std::string thumb_base (int) const;
90 SourceFrame thumb_frame (int) const;
92 int target_audio_sample_rate () const;
94 void write_metadata () const;
95 void read_metadata ();
97 Size cropped_size (Size) const;
98 boost::optional<SourceFrame> dcp_length () const;
99 std::string dci_name () const;
100 std::string dcp_name () const;
102 bool dirty () const {
106 int audio_channels () const;
108 void set_dci_date_today ();
123 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 DCPContentType const * dcp_content_type () const {
166 boost::mutex::scoped_lock lm (_state_mutex);
167 return _dcp_content_type;
170 Format const * format () const {
171 boost::mutex::scoped_lock lm (_state_mutex);
176 boost::mutex::scoped_lock lm (_state_mutex);
180 std::vector<Filter const *> filters () const {
181 boost::mutex::scoped_lock lm (_state_mutex);
185 Scaler const * scaler () const {
186 boost::mutex::scoped_lock lm (_state_mutex);
190 SourceFrame dcp_trim_start () const {
191 boost::mutex::scoped_lock lm (_state_mutex);
192 return _dcp_trim_start;
195 SourceFrame dcp_trim_end () const {
196 boost::mutex::scoped_lock lm (_state_mutex);
197 return _dcp_trim_end;
200 bool dcp_ab () const {
201 boost::mutex::scoped_lock lm (_state_mutex);
205 boost::shared_ptr<AudioStream> content_audio_stream () const {
206 boost::mutex::scoped_lock lm (_state_mutex);
207 return _content_audio_stream;
210 std::vector<std::string> external_audio () const {
211 boost::mutex::scoped_lock lm (_state_mutex);
212 return _external_audio;
215 bool use_content_audio () const {
216 boost::mutex::scoped_lock lm (_state_mutex);
217 return _use_content_audio;
220 float audio_gain () const {
221 boost::mutex::scoped_lock lm (_state_mutex);
225 int audio_delay () const {
226 boost::mutex::scoped_lock lm (_state_mutex);
230 int still_duration () const {
231 boost::mutex::scoped_lock lm (_state_mutex);
232 return _still_duration;
235 boost::shared_ptr<SubtitleStream> subtitle_stream () const {
236 boost::mutex::scoped_lock lm (_state_mutex);
237 return _subtitle_stream;
240 bool with_subtitles () const {
241 boost::mutex::scoped_lock lm (_state_mutex);
242 return _with_subtitles;
245 int subtitle_offset () const {
246 boost::mutex::scoped_lock lm (_state_mutex);
247 return _subtitle_offset;
250 float subtitle_scale () const {
251 boost::mutex::scoped_lock lm (_state_mutex);
252 return _subtitle_scale;
255 std::string audio_language () const {
256 boost::mutex::scoped_lock lm (_state_mutex);
257 return _audio_language;
260 std::string subtitle_language () const {
261 boost::mutex::scoped_lock lm (_state_mutex);
262 return _subtitle_language;
265 std::string territory () const {
266 boost::mutex::scoped_lock lm (_state_mutex);
270 std::string rating () const {
271 boost::mutex::scoped_lock lm (_state_mutex);
275 std::string studio () const {
276 boost::mutex::scoped_lock lm (_state_mutex);
280 std::string facility () const {
281 boost::mutex::scoped_lock lm (_state_mutex);
285 std::string package_type () const {
286 boost::mutex::scoped_lock lm (_state_mutex);
287 return _package_type;
290 std::vector<SourceFrame> thumbs () const {
291 boost::mutex::scoped_lock lm (_state_mutex);
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 frames_per_second () const {
321 boost::mutex::scoped_lock lm (_state_mutex);
322 return _frames_per_second;
325 boost::shared_ptr<AudioStream> audio_stream () const;
330 void set_directory (std::string);
331 void set_name (std::string);
332 void set_use_dci_name (bool);
333 virtual void set_content (std::string);
334 void set_dcp_content_type (DCPContentType const *);
335 void set_format (Format const *);
336 void set_crop (Crop);
337 void set_left_crop (int);
338 void set_right_crop (int);
339 void set_top_crop (int);
340 void set_bottom_crop (int);
341 void set_filters (std::vector<Filter const *>);
342 void set_scaler (Scaler const *);
343 void set_dcp_trim_start (int);
344 void set_dcp_trim_end (int);
345 void set_dcp_ab (bool);
346 void set_content_audio_stream (boost::shared_ptr<AudioStream>);
347 void set_external_audio (std::vector<std::string>);
348 void set_use_content_audio (bool);
349 void set_audio_gain (float);
350 void set_audio_delay (int);
351 void set_still_duration (int);
352 void set_subtitle_stream (boost::shared_ptr<SubtitleStream>);
353 void set_with_subtitles (bool);
354 void set_subtitle_offset (int);
355 void set_subtitle_scale (float);
356 void set_audio_language (std::string);
357 void set_subtitle_language (std::string);
358 void set_territory (std::string);
359 void set_rating (std::string);
360 void set_studio (std::string);
361 void set_facility (std::string);
362 void set_package_type (std::string);
363 void set_thumbs (std::vector<SourceFrame>);
364 void set_size (Size);
365 void set_length (SourceFrame);
366 void unset_length ();
367 void set_content_digest (std::string);
368 void set_content_audio_streams (std::vector<boost::shared_ptr<AudioStream> >);
369 void set_subtitle_streams (std::vector<boost::shared_ptr<SubtitleStream> >);
370 void set_frames_per_second (float);
372 /** Emitted when some property has changed */
373 mutable boost::signals2::signal<void (Property)> Changed;
375 /** Current version number of the state file */
376 static int const state_version;
380 /** Log to write to */
383 /** Any running ExamineContentJob, or 0 */
384 boost::shared_ptr<ExamineContentJob> _examine_content_job;
386 /** The date that we should use in a DCI name */
387 boost::gregorian::date _dci_date;
389 std::string thumb_file_for_frame (SourceFrame) const;
390 std::string thumb_base_for_frame (SourceFrame) const;
391 void signal_changed (Property);
392 void examine_content_finished ();
394 /** Complete path to directory containing the film metadata;
395 * must not be relative.
397 std::string _directory;
398 /** Mutex for _directory */
399 mutable boost::mutex _directory_mutex;
401 /** Name for DVD-o-matic */
403 /** True if a auto-generated DCI-compliant name should be used for our DCP */
405 /** File or directory containing content; may be relative to our directory
406 * or an absolute path.
408 std::string _content;
409 /** The type of content that this Film represents (feature, trailer etc.) */
410 DCPContentType const * _dcp_content_type;
411 /** The format to present this Film in (flat, scope, etc.) */
412 Format const * _format;
413 /** The crop to apply to the source */
415 /** Video filters that should be used when generating DCPs */
416 std::vector<Filter const *> _filters;
417 /** Scaler algorithm to use */
418 Scaler const * _scaler;
419 /** Frames to trim off the start of the source */
420 SourceFrame _dcp_trim_start;
421 /** Frames to trim off the end of the source */
422 SourceFrame _dcp_trim_end;
423 /** true to create an A/B comparison DCP, where the left half of the image
424 is the video without any filters or post-processing, and the right half
425 has the specified filters and post-processing.
428 /** The audio stream to use from our content */
429 boost::shared_ptr<AudioStream> _content_audio_stream;
430 /** List of filenames of external audio files, in channel order
431 (L, R, C, Lfe, Ls, Rs)
433 std::vector<std::string> _external_audio;
434 /** true to use audio from our content file; false to use external audio */
435 bool _use_content_audio;
436 /** Gain to apply to audio in dB */
438 /** Delay to apply to audio (positive moves audio later) in milliseconds */
440 /** Duration to make still-sourced films (in seconds) */
442 boost::shared_ptr<SubtitleStream> _subtitle_stream;
443 /** True if subtitles should be shown for this film */
444 bool _with_subtitles;
445 /** y offset for placing subtitles, in source pixels; +ve is further down
446 the frame, -ve is further up.
448 int _subtitle_offset;
449 /** scale factor to apply to subtitles */
450 float _subtitle_scale;
452 /* DCI naming stuff */
453 std::string _audio_language;
454 std::string _subtitle_language;
455 std::string _territory;
458 std::string _facility;
459 std::string _package_type;
461 /* Data which are cached to speed things up */
463 /** Vector of frame indices for each of our `thumbnails' */
464 std::vector<SourceFrame> _thumbs;
465 /** Size, in pixels, of the source (ignoring cropping) */
467 /** Actual length of the source (in video frames) from examining it */
468 boost::optional<SourceFrame> _length;
469 /** MD5 digest of our content file */
470 std::string _content_digest;
471 /** The audio streams in our content */
472 std::vector<boost::shared_ptr<AudioStream> > _content_audio_streams;
473 /** A stream to represent possible external audio (will always exist) */
474 boost::shared_ptr<AudioStream> _external_audio_stream;
475 /** the subtitle streams that we can use */
476 std::vector<boost::shared_ptr<SubtitleStream> > _subtitle_streams;
477 /** Frames per second of the source */
478 float _frames_per_second;
480 /** true if our state has changed since we last saved it */
483 /** Mutex for all state except _directory */
484 mutable boost::mutex _state_mutex;
486 friend class paths_test;