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<SourceFrame> 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,
117 CONTENT_AUDIO_STREAM,
130 CONTENT_AUDIO_STREAMS,
138 std::string directory () const {
139 boost::mutex::scoped_lock lm (_directory_mutex);
143 std::string name () const {
144 boost::mutex::scoped_lock lm (_state_mutex);
148 bool use_dci_name () const {
149 boost::mutex::scoped_lock lm (_state_mutex);
150 return _use_dci_name;
153 std::string content () const {
154 boost::mutex::scoped_lock lm (_state_mutex);
158 bool trust_content_header () const {
159 boost::mutex::scoped_lock lm (_state_mutex);
160 return _trust_content_header;
163 DCPContentType const * dcp_content_type () const {
164 boost::mutex::scoped_lock lm (_state_mutex);
165 return _dcp_content_type;
168 Format const * format () const {
169 boost::mutex::scoped_lock lm (_state_mutex);
174 boost::mutex::scoped_lock lm (_state_mutex);
178 std::vector<Filter const *> filters () const {
179 boost::mutex::scoped_lock lm (_state_mutex);
183 Scaler const * scaler () const {
184 boost::mutex::scoped_lock lm (_state_mutex);
188 SourceFrame dcp_trim_start () const {
189 boost::mutex::scoped_lock lm (_state_mutex);
190 return _dcp_trim_start;
193 SourceFrame dcp_trim_end () const {
194 boost::mutex::scoped_lock lm (_state_mutex);
195 return _dcp_trim_end;
198 bool dcp_ab () const {
199 boost::mutex::scoped_lock lm (_state_mutex);
203 boost::shared_ptr<AudioStream> content_audio_stream () const {
204 boost::mutex::scoped_lock lm (_state_mutex);
205 return _content_audio_stream;
208 std::vector<std::string> external_audio () const {
209 boost::mutex::scoped_lock lm (_state_mutex);
210 return _external_audio;
213 bool use_content_audio () const {
214 boost::mutex::scoped_lock lm (_state_mutex);
215 return _use_content_audio;
218 float audio_gain () const {
219 boost::mutex::scoped_lock lm (_state_mutex);
223 int audio_delay () const {
224 boost::mutex::scoped_lock lm (_state_mutex);
228 int still_duration () const {
229 boost::mutex::scoped_lock lm (_state_mutex);
230 return _still_duration;
233 boost::shared_ptr<SubtitleStream> subtitle_stream () const {
234 boost::mutex::scoped_lock lm (_state_mutex);
235 return _subtitle_stream;
238 bool with_subtitles () const {
239 boost::mutex::scoped_lock lm (_state_mutex);
240 return _with_subtitles;
243 int subtitle_offset () const {
244 boost::mutex::scoped_lock lm (_state_mutex);
245 return _subtitle_offset;
248 float subtitle_scale () const {
249 boost::mutex::scoped_lock lm (_state_mutex);
250 return _subtitle_scale;
253 std::string audio_language () const {
254 boost::mutex::scoped_lock lm (_state_mutex);
255 return _audio_language;
258 std::string subtitle_language () const {
259 boost::mutex::scoped_lock lm (_state_mutex);
260 return _subtitle_language;
263 std::string territory () const {
264 boost::mutex::scoped_lock lm (_state_mutex);
268 std::string rating () const {
269 boost::mutex::scoped_lock lm (_state_mutex);
273 std::string studio () const {
274 boost::mutex::scoped_lock lm (_state_mutex);
278 std::string facility () const {
279 boost::mutex::scoped_lock lm (_state_mutex);
283 std::string package_type () const {
284 boost::mutex::scoped_lock lm (_state_mutex);
285 return _package_type;
289 boost::mutex::scoped_lock lm (_state_mutex);
293 boost::optional<SourceFrame> length () const {
294 boost::mutex::scoped_lock lm (_state_mutex);
298 std::string content_digest () const {
299 boost::mutex::scoped_lock lm (_state_mutex);
300 return _content_digest;
303 std::vector<boost::shared_ptr<AudioStream> > content_audio_streams () const {
304 boost::mutex::scoped_lock lm (_state_mutex);
305 return _content_audio_streams;
308 std::vector<boost::shared_ptr<SubtitleStream> > subtitle_streams () const {
309 boost::mutex::scoped_lock lm (_state_mutex);
310 return _subtitle_streams;
313 float frames_per_second () const {
314 boost::mutex::scoped_lock lm (_state_mutex);
315 return _frames_per_second;
318 boost::shared_ptr<AudioStream> audio_stream () const;
323 void set_directory (std::string);
324 void set_name (std::string);
325 void set_use_dci_name (bool);
326 void set_content (std::string);
327 void set_trust_content_header (bool);
328 void set_dcp_content_type (DCPContentType const *);
329 void set_format (Format const *);
330 void set_crop (Crop);
331 void set_left_crop (int);
332 void set_right_crop (int);
333 void set_top_crop (int);
334 void set_bottom_crop (int);
335 void set_filters (std::vector<Filter const *>);
336 void set_scaler (Scaler const *);
337 void set_dcp_trim_start (int);
338 void set_dcp_trim_end (int);
339 void set_dcp_ab (bool);
340 void set_content_audio_stream (boost::shared_ptr<AudioStream>);
341 void set_external_audio (std::vector<std::string>);
342 void set_use_content_audio (bool);
343 void set_audio_gain (float);
344 void set_audio_delay (int);
345 void set_still_duration (int);
346 void set_subtitle_stream (boost::shared_ptr<SubtitleStream>);
347 void set_with_subtitles (bool);
348 void set_subtitle_offset (int);
349 void set_subtitle_scale (float);
350 void set_audio_language (std::string);
351 void set_subtitle_language (std::string);
352 void set_territory (std::string);
353 void set_rating (std::string);
354 void set_studio (std::string);
355 void set_facility (std::string);
356 void set_package_type (std::string);
357 void set_size (Size);
358 void set_length (SourceFrame);
359 void unset_length ();
360 void set_content_digest (std::string);
361 void set_content_audio_streams (std::vector<boost::shared_ptr<AudioStream> >);
362 void set_subtitle_streams (std::vector<boost::shared_ptr<SubtitleStream> >);
363 void set_frames_per_second (float);
365 /** Emitted when some property has changed */
366 mutable boost::signals2::signal<void (Property)> Changed;
368 /** Current version number of the state file */
369 static int const state_version;
373 /** Log to write to */
376 /** Any running ExamineContentJob, or 0 */
377 boost::shared_ptr<ExamineContentJob> _examine_content_job;
379 /** The date that we should use in a DCI name */
380 boost::gregorian::date _dci_date;
382 void signal_changed (Property);
383 void examine_content_finished ();
385 /** Complete path to directory containing the film metadata;
386 * must not be relative.
388 std::string _directory;
389 /** Mutex for _directory */
390 mutable boost::mutex _directory_mutex;
392 /** Name for DVD-o-matic */
394 /** True if a auto-generated DCI-compliant name should be used for our DCP */
396 /** File or directory containing content; may be relative to our directory
397 * or an absolute path.
399 std::string _content;
400 bool _trust_content_header;
401 /** The type of content that this Film represents (feature, trailer etc.) */
402 DCPContentType const * _dcp_content_type;
403 /** The format to present this Film in (flat, scope, etc.) */
404 Format const * _format;
405 /** The crop to apply to the source */
407 /** Video filters that should be used when generating DCPs */
408 std::vector<Filter const *> _filters;
409 /** Scaler algorithm to use */
410 Scaler const * _scaler;
411 /** Frames to trim off the start of the source */
412 SourceFrame _dcp_trim_start;
413 /** Frames to trim off the end of the source */
414 SourceFrame _dcp_trim_end;
415 /** true to create an A/B comparison DCP, where the left half of the image
416 is the video without any filters or post-processing, and the right half
417 has the specified filters and post-processing.
420 /** The audio stream to use from our content */
421 boost::shared_ptr<AudioStream> _content_audio_stream;
422 /** List of filenames of external audio files, in channel order
423 (L, R, C, Lfe, Ls, Rs)
425 std::vector<std::string> _external_audio;
426 /** true to use audio from our content file; false to use external audio */
427 bool _use_content_audio;
428 /** Gain to apply to audio in dB */
430 /** Delay to apply to audio (positive moves audio later) in milliseconds */
432 /** Duration to make still-sourced films (in seconds) */
434 boost::shared_ptr<SubtitleStream> _subtitle_stream;
435 /** True if subtitles should be shown for this film */
436 bool _with_subtitles;
437 /** y offset for placing subtitles, in source pixels; +ve is further down
438 the frame, -ve is further up.
440 int _subtitle_offset;
441 /** scale factor to apply to subtitles */
442 float _subtitle_scale;
444 /* DCI naming stuff */
445 std::string _audio_language;
446 std::string _subtitle_language;
447 std::string _territory;
450 std::string _facility;
451 std::string _package_type;
453 /* Data which are cached to speed things up */
455 /** Size, in pixels, of the source (ignoring cropping) */
457 /** Actual length of the source (in video frames) from examining it */
458 boost::optional<SourceFrame> _length;
459 /** MD5 digest of our content file */
460 std::string _content_digest;
461 /** The audio streams in our content */
462 std::vector<boost::shared_ptr<AudioStream> > _content_audio_streams;
463 /** A stream to represent possible external audio (will always exist) */
464 boost::shared_ptr<AudioStream> _external_audio_stream;
465 /** the subtitle streams that we can use */
466 std::vector<boost::shared_ptr<SubtitleStream> > _subtitle_streams;
467 /** Frames per second of the source */
468 float _frames_per_second;
470 /** true if our state has changed since we last saved it */
473 /** Mutex for all state except _directory */
474 mutable boost::mutex _state_mutex;
476 friend class paths_test;