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 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 bool content_is_dvd () const;
87 std::string thumb_file (int) const;
88 std::string thumb_base (int) const;
89 int thumb_frame (int) const;
91 int target_sample_rate () const;
93 void write_metadata () const;
94 void read_metadata ();
96 Size cropped_size (Size) const;
97 int dcp_length () const;
98 std::string dci_name () const;
100 std::string dcp_name () const;
102 boost::shared_ptr<FilmState> state_copy () const;
104 bool dirty () const {
108 int audio_channels () const;
145 std::string directory () const {
149 std::string name () const {
153 bool use_dci_name () const {
154 return _use_dci_name;
157 std::string content () const {
161 DCPContentType const * dcp_content_type () const {
162 return _dcp_content_type;
165 Format const * format () const {
173 std::vector<Filter const *> filters () const {
177 Scaler const * scaler () const {
181 int dcp_frames () const {
185 TrimAction dcp_trim_action () const {
186 return _dcp_trim_action;
189 bool dcp_ab () const {
193 int audio_stream_index () const {
194 return _audio_stream;
197 AudioStream audio_stream () const {
198 assert (_audio_stream < int (_audio_streams.size()));
199 return _audio_streams[_audio_stream];
202 float audio_gain () const {
206 int audio_delay () const {
210 int still_duration () const {
211 return _still_duration;
214 int subtitle_stream_index () const {
215 return _subtitle_stream;
218 SubtitleStream subtitle_stream () const {
219 assert (_subtitle_stream < int (_subtitle_streams.size()));
220 return _subtitle_streams[_subtitle_stream];
223 bool with_subtitles () const {
224 return _with_subtitles;
227 int subtitle_offset () const {
228 return _subtitle_offset;
231 float subtitle_scale () const {
232 return _subtitle_scale;
235 std::string audio_language () const {
236 return _audio_language;
239 std::string subtitle_language () const {
240 return _subtitle_language;
243 std::string territory () const {
247 std::string rating () const {
251 std::string studio () const {
255 std::string facility () const {
259 std::string package_type () const {
260 return _package_type;
263 std::vector<int> thumbs () const {
271 int length () const {
275 int audio_sample_rate () const {
276 return _audio_sample_rate;
279 std::string content_digest () const {
280 return _content_digest;
283 bool has_subtitles () const {
284 return _has_subtitles;
287 std::vector<AudioStream> audio_streams () const {
288 return _audio_streams;
291 std::vector<SubtitleStream> subtitle_streams () const {
292 return _subtitle_streams;
295 float frames_per_second () const {
296 return _frames_per_second;
302 void set_directory (std::string);
303 void set_name (std::string);
304 void set_use_dci_name (bool);
305 virtual void set_content (std::string);
306 void set_dcp_content_type (DCPContentType const *);
307 void set_format (Format const *);
308 void set_crop (Crop);
309 void set_left_crop (int);
310 void set_right_crop (int);
311 void set_top_crop (int);
312 void set_bottom_crop (int);
313 void set_filters (std::vector<Filter const *>);
314 void set_scaler (Scaler const *);
315 void set_dcp_frames (int);
316 void set_dcp_trim_action (TrimAction);
317 void set_dcp_ab (bool);
318 void set_audio_stream (int);
319 void set_audio_gain (float);
320 void set_audio_delay (int);
321 void set_still_duration (int);
322 void set_subtitle_stream (int);
323 void set_with_subtitles (bool);
324 void set_subtitle_offset (int);
325 void set_subtitle_scale (float);
326 void set_audio_language (std::string);
327 void set_subtitle_language (std::string);
328 void set_territory (std::string);
329 void set_rating (std::string);
330 void set_studio (std::string);
331 void set_facility (std::string);
332 void set_package_type (std::string);
333 void set_thumbs (std::vector<int>);
334 void set_size (Size);
335 void set_length (int);
336 void set_audio_channels (int);
337 void set_audio_sample_rate (int);
338 void set_content_digest (std::string);
339 void set_has_subtitles (bool);
340 void set_audio_streams (std::vector<AudioStream>);
341 void set_subtitle_streams (std::vector<SubtitleStream>);
342 void set_frames_per_second (float);
344 /** Emitted when some property has changed */
345 mutable sigc::signal1<void, Property> Changed;
349 std::string thumb_file_for_frame (int) const;
350 std::string thumb_base_for_frame (int) const;
351 void signal_changed (Property);
353 /** Complete path to directory containing the film metadata;
354 * must not be relative.
356 std::string _directory;
357 /** Name for DVD-o-matic */
359 /** True if a auto-generated DCI-compliant name should be used for our DCP */
361 /** File or directory containing content; may be relative to our directory
362 * or an absolute path.
364 std::string _content;
365 /** The type of content that this Film represents (feature, trailer etc.) */
366 DCPContentType const * _dcp_content_type;
367 /** The format to present this Film in (flat, scope, etc.) */
368 Format const * _format;
369 /** The crop to apply to the source */
371 /** Video filters that should be used when generating DCPs */
372 std::vector<Filter const *> _filters;
373 /** Scaler algorithm to use */
374 Scaler const * _scaler;
375 /** Number of frames to put in the DCP, or 0 for all */
377 /** What to do with audio when trimming DCPs */
378 TrimAction _dcp_trim_action;
379 /** true to create an A/B comparison DCP, where the left half of the image
380 is the video without any filters or post-processing, and the right half
381 has the specified filters and post-processing.
384 /** An index into our _audio_streams vector for the stream to use for audio, or -1 if there is none */
386 /** Gain to apply to audio in dB */
388 /** Delay to apply to audio (positive moves audio later) in milliseconds */
390 /** Duration to make still-sourced films (in seconds) */
392 /** An index into our _subtitle_streams vector for the stream to use for subtitles, or -1 if there is none */
393 int _subtitle_stream;
394 /** True if subtitles should be shown for this film */
395 bool _with_subtitles;
396 /** y offset for placing subtitles, in source pixels; +ve is further down
397 the frame, -ve is further up.
399 int _subtitle_offset;
400 /** scale factor to apply to subtitles */
401 float _subtitle_scale;
403 /* DCI naming stuff */
404 std::string _audio_language;
405 std::string _subtitle_language;
406 std::string _territory;
409 std::string _facility;
410 std::string _package_type;
412 /* Data which are cached to speed things up */
414 /** Vector of frame indices for each of our `thumbnails' */
415 std::vector<int> _thumbs;
416 /** Size, in pixels, of the source (ignoring cropping) */
418 /** Length of the source in frames */
420 /** Sample rate of the source audio, in Hz */
421 int _audio_sample_rate;
422 /** MD5 digest of our content file */
423 std::string _content_digest;
424 /** true if the source has subtitles */
426 /** the audio streams that the source has */
427 std::vector<AudioStream> _audio_streams;
428 /** the subtitle streams that the source has */
429 std::vector<SubtitleStream> _subtitle_streams;
430 /** Frames per second of the source */
431 float _frames_per_second;
435 friend class paths_test;