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.
20 /** @file src/film_state.h
21 * @brief The state of a Film. This is separate from Film so that
22 * state can easily be copied and kept around for reference
23 * by long-running jobs. This avoids the jobs getting confused
24 * by the user changing Film settings during their run.
27 #ifndef DVDOMATIC_FILM_STATE_H
28 #define DVDOMATIC_FILM_STATE_H
30 #include <sigc++/signal.h>
32 #include <libavcodec/avcodec.h>
33 #include <libswscale/swscale.h>
37 #include "trim_action.h"
45 * @brief The state of a Film.
47 * This is separate from Film so that state can easily be copied and
48 * kept around for reference by long-running jobs. This avoids the
49 * jobs getting confused by the user changing Film settings during
57 : _use_dci_name (false)
58 , _dcp_content_type (0)
60 , _scaler (Scaler::from_id ("bicubic"))
62 , _dcp_trim_action (CUT)
67 , _still_duration (10)
68 , _subtitle_stream (-1)
69 , _with_subtitles (false)
70 , _subtitle_offset (0)
73 , _audio_sample_rate (0)
74 , _has_subtitles (false)
75 , _frames_per_second (0)
79 FilmState (FilmState const & o)
80 : _directory (o._directory)
82 , _use_dci_name (o._use_dci_name)
83 , _content (o._content)
84 , _dcp_content_type (o._dcp_content_type)
87 , _filters (o._filters)
89 , _dcp_frames (o._dcp_frames)
90 , _dcp_trim_action (o._dcp_trim_action)
92 , _audio_stream (o._audio_stream)
93 , _audio_gain (o._audio_gain)
94 , _audio_delay (o._audio_delay)
95 , _still_duration (o._still_duration)
96 , _subtitle_stream (o._subtitle_stream)
97 , _with_subtitles (o._with_subtitles)
98 , _subtitle_offset (o._subtitle_offset)
99 , _subtitle_scale (o._subtitle_scale)
100 , _audio_language (o._audio_language)
101 , _subtitle_language (o._subtitle_language)
102 , _territory (o._territory)
103 , _rating (o._rating)
104 , _studio (o._studio)
105 , _facility (o._facility)
106 , _package_type (o._package_type)
107 , _thumbs (o._thumbs)
109 , _length (o._length)
110 , _audio_sample_rate (o._audio_sample_rate)
111 , _content_digest (o._content_digest)
112 , _has_subtitles (o._has_subtitles)
113 , _audio_streams (o._audio_streams)
114 , _subtitle_streams (o._subtitle_streams)
115 , _frames_per_second (o._frames_per_second)
119 virtual ~FilmState () {}
121 std::string file (std::string f) const;
122 std::string dir (std::string d) const;
124 std::string content_path () const;
125 ContentType content_type () const;
127 bool content_is_dvd () const;
129 std::string thumb_file (int) const;
130 std::string thumb_base (int) const;
131 int thumb_frame (int) const;
133 int target_sample_rate () const;
135 void write_metadata () const;
136 void read_metadata ();
138 Size cropped_size (Size) const;
139 int dcp_length () const;
140 std::string dci_name () const;
142 std::string dcp_name () const;
144 boost::shared_ptr<FilmState> state_copy () const;
146 bool dirty () const {
150 int audio_channels () const;
187 std::string directory () const {
191 std::string name () const {
195 bool use_dci_name () const {
196 return _use_dci_name;
199 std::string content () const {
203 DCPContentType const * dcp_content_type () const {
204 return _dcp_content_type;
207 Format const * format () const {
215 std::vector<Filter const *> filters () const {
219 Scaler const * scaler () const {
223 int dcp_frames () const {
227 TrimAction dcp_trim_action () const {
228 return _dcp_trim_action;
231 bool dcp_ab () const {
235 int audio_stream_index () const {
236 return _audio_stream;
239 AudioStream audio_stream () const {
240 assert (_audio_stream < int (_audio_streams.size()));
241 return _audio_streams[_audio_stream];
244 float audio_gain () const {
248 int audio_delay () const {
252 int still_duration () const {
253 return _still_duration;
256 int subtitle_stream_index () const {
257 return _subtitle_stream;
260 SubtitleStream subtitle_stream () const {
261 assert (_subtitle_stream < int (_subtitle_streams.size()));
262 return _subtitle_streams[_subtitle_stream];
265 bool with_subtitles () const {
266 return _with_subtitles;
269 int subtitle_offset () const {
270 return _subtitle_offset;
273 float subtitle_scale () const {
274 return _subtitle_scale;
277 std::string audio_language () const {
278 return _audio_language;
281 std::string subtitle_language () const {
282 return _subtitle_language;
285 std::string territory () const {
289 std::string rating () const {
293 std::string studio () const {
297 std::string facility () const {
301 std::string package_type () const {
302 return _package_type;
305 std::vector<int> thumbs () const {
313 int length () const {
317 int audio_sample_rate () const {
318 return _audio_sample_rate;
321 std::string content_digest () const {
322 return _content_digest;
325 bool has_subtitles () const {
326 return _has_subtitles;
329 std::vector<AudioStream> audio_streams () const {
330 return _audio_streams;
333 std::vector<SubtitleStream> subtitle_streams () const {
334 return _subtitle_streams;
337 float frames_per_second () const {
338 return _frames_per_second;
344 void set_directory (std::string);
345 void set_name (std::string);
346 void set_use_dci_name (bool);
347 virtual void set_content (std::string);
348 void set_dcp_content_type (DCPContentType const *);
349 void set_format (Format const *);
350 void set_crop (Crop);
351 void set_left_crop (int);
352 void set_right_crop (int);
353 void set_top_crop (int);
354 void set_bottom_crop (int);
355 void set_filters (std::vector<Filter const *>);
356 void set_scaler (Scaler const *);
357 void set_dcp_frames (int);
358 void set_dcp_trim_action (TrimAction);
359 void set_dcp_ab (bool);
360 void set_audio_stream (int);
361 void set_audio_gain (float);
362 void set_audio_delay (int);
363 void set_still_duration (int);
364 void set_subtitle_stream (int);
365 void set_with_subtitles (bool);
366 void set_subtitle_offset (int);
367 void set_subtitle_scale (float);
368 void set_audio_language (std::string);
369 void set_subtitle_language (std::string);
370 void set_territory (std::string);
371 void set_rating (std::string);
372 void set_studio (std::string);
373 void set_facility (std::string);
374 void set_package_type (std::string);
375 void set_thumbs (std::vector<int>);
376 void set_size (Size);
377 void set_length (int);
378 void set_audio_channels (int);
379 void set_audio_sample_rate (int);
380 void set_content_digest (std::string);
381 void set_has_subtitles (bool);
382 void set_audio_streams (std::vector<AudioStream>);
383 void set_subtitle_streams (std::vector<SubtitleStream>);
384 void set_frames_per_second (float);
386 /** Emitted when some property has changed */
387 mutable sigc::signal1<void, Property> Changed;
391 std::string thumb_file_for_frame (int) const;
392 std::string thumb_base_for_frame (int) const;
393 void signal_changed (Property);
395 /** Complete path to directory containing the film metadata;
396 * must not be relative.
398 std::string _directory;
399 /** Name for DVD-o-matic */
401 /** True if a auto-generated DCI-compliant name should be used for our DCP */
403 /** File or directory containing content; may be relative to our directory
404 * or an absolute path.
406 std::string _content;
407 /** The type of content that this Film represents (feature, trailer etc.) */
408 DCPContentType const * _dcp_content_type;
409 /** The format to present this Film in (flat, scope, etc.) */
410 Format const * _format;
411 /** The crop to apply to the source */
413 /** Video filters that should be used when generating DCPs */
414 std::vector<Filter const *> _filters;
415 /** Scaler algorithm to use */
416 Scaler const * _scaler;
417 /** Number of frames to put in the DCP, or 0 for all */
419 /** What to do with audio when trimming DCPs */
420 TrimAction _dcp_trim_action;
421 /** true to create an A/B comparison DCP, where the left half of the image
422 is the video without any filters or post-processing, and the right half
423 has the specified filters and post-processing.
426 /** An index into our _audio_streams vector for the stream to use for audio, or -1 if there is none */
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 /** An index into our _subtitle_streams vector for the stream to use for subtitles, or -1 if there is none */
435 int _subtitle_stream;
436 /** True if subtitles should be shown for this film */
437 bool _with_subtitles;
438 /** y offset for placing subtitles, in source pixels; +ve is further down
439 the frame, -ve is further up.
441 int _subtitle_offset;
442 /** scale factor to apply to subtitles */
443 float _subtitle_scale;
445 /* DCI naming stuff */
446 std::string _audio_language;
447 std::string _subtitle_language;
448 std::string _territory;
451 std::string _facility;
452 std::string _package_type;
454 /* Data which are cached to speed things up */
456 /** Vector of frame indices for each of our `thumbnails' */
457 std::vector<int> _thumbs;
458 /** Size, in pixels, of the source (ignoring cropping) */
460 /** Length of the source in frames */
462 /** Sample rate of the source audio, in Hz */
463 int _audio_sample_rate;
464 /** MD5 digest of our content file */
465 std::string _content_digest;
466 /** true if the source has subtitles */
468 /** the audio streams that the source has */
469 std::vector<AudioStream> _audio_streams;
470 /** the subtitle streams that the source has */
471 std::vector<SubtitleStream> _subtitle_streams;
472 /** Frames per second of the source */
473 float _frames_per_second;
477 friend class paths_test;