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>
34 #include <libavcodec/avcodec.h>
36 #include "dcp_content_type.h"
39 #include "trim_action.h"
45 class ExamineContentJob;
48 * @brief A representation of a video with sound.
50 * A representation of a piece of video (with sound), including naming,
51 * the source content file, and how it should be presented in a DCP.
53 class Film : public boost::enable_shared_from_this<Film>
56 Film (std::string d, bool must_exist = true);
60 std::string j2k_dir () const;
61 std::vector<std::string> audio_files () const;
62 std::pair<Position, std::string> thumb_subtitle (int) const;
64 void copy_from_dvd_post_gui ();
65 void examine_content ();
66 void examine_content_post_gui ();
67 void send_dcp_to_tms ();
68 void copy_from_dvd ();
73 * It is safe to call this from any thread.
79 int encoded_frames () const;
81 std::string file (std::string f) const;
82 std::string dir (std::string d) const;
84 std::string content_path () const;
85 ContentType content_type () const;
87 bool content_is_dvd () const;
89 std::string thumb_file (int) const;
90 std::string thumb_base (int) const;
91 int thumb_frame (int) const;
93 int target_audio_sample_rate () const;
95 void write_metadata () const;
96 void read_metadata ();
98 Size cropped_size (Size) const;
99 int dcp_length () const;
100 std::string dci_name () const;
101 std::string dcp_name () const;
103 bool dirty () const {
107 int audio_channels () const;
144 std::string directory () const {
145 boost::mutex::scoped_lock lm (_state_mutex);
149 std::string name () const {
150 boost::mutex::scoped_lock lm (_state_mutex);
154 bool use_dci_name () const {
155 boost::mutex::scoped_lock lm (_state_mutex);
156 return _use_dci_name;
159 std::string content () const {
160 boost::mutex::scoped_lock lm (_state_mutex);
164 DCPContentType const * dcp_content_type () const {
165 boost::mutex::scoped_lock lm (_state_mutex);
166 return _dcp_content_type;
169 Format const * format () const {
170 boost::mutex::scoped_lock lm (_state_mutex);
175 boost::mutex::scoped_lock lm (_state_mutex);
179 std::vector<Filter const *> filters () const {
180 boost::mutex::scoped_lock lm (_state_mutex);
184 Scaler const * scaler () const {
185 boost::mutex::scoped_lock lm (_state_mutex);
189 int dcp_frames () const {
190 boost::mutex::scoped_lock lm (_state_mutex);
194 TrimAction dcp_trim_action () const {
195 boost::mutex::scoped_lock lm (_state_mutex);
196 return _dcp_trim_action;
199 bool dcp_ab () const {
200 boost::mutex::scoped_lock lm (_state_mutex);
204 int audio_stream_index () const {
205 boost::mutex::scoped_lock lm (_state_mutex);
206 return _audio_stream;
209 AudioStream audio_stream () const {
210 boost::mutex::scoped_lock lm (_state_mutex);
211 assert (_audio_stream < int (_audio_streams.size()));
212 return _audio_streams[_audio_stream];
215 float audio_gain () const {
216 boost::mutex::scoped_lock lm (_state_mutex);
220 int audio_delay () const {
221 boost::mutex::scoped_lock lm (_state_mutex);
225 int still_duration () const {
226 boost::mutex::scoped_lock lm (_state_mutex);
227 return _still_duration;
230 int subtitle_stream_index () const {
231 boost::mutex::scoped_lock lm (_state_mutex);
232 return _subtitle_stream;
235 SubtitleStream subtitle_stream () const {
236 boost::mutex::scoped_lock lm (_state_mutex);
237 assert (_subtitle_stream < int (_subtitle_streams.size()));
238 return _subtitle_streams[_subtitle_stream];
241 bool with_subtitles () const {
242 boost::mutex::scoped_lock lm (_state_mutex);
243 return _with_subtitles;
246 int subtitle_offset () const {
247 boost::mutex::scoped_lock lm (_state_mutex);
248 return _subtitle_offset;
251 float subtitle_scale () const {
252 boost::mutex::scoped_lock lm (_state_mutex);
253 return _subtitle_scale;
256 std::string audio_language () const {
257 boost::mutex::scoped_lock lm (_state_mutex);
258 return _audio_language;
261 std::string subtitle_language () const {
262 boost::mutex::scoped_lock lm (_state_mutex);
263 return _subtitle_language;
266 std::string territory () const {
267 boost::mutex::scoped_lock lm (_state_mutex);
271 std::string rating () const {
272 boost::mutex::scoped_lock lm (_state_mutex);
276 std::string studio () const {
277 boost::mutex::scoped_lock lm (_state_mutex);
281 std::string facility () const {
282 boost::mutex::scoped_lock lm (_state_mutex);
286 std::string package_type () const {
287 boost::mutex::scoped_lock lm (_state_mutex);
288 return _package_type;
291 std::vector<int> thumbs () const {
292 boost::mutex::scoped_lock lm (_state_mutex);
297 boost::mutex::scoped_lock lm (_state_mutex);
301 int length () const {
302 boost::mutex::scoped_lock lm (_state_mutex);
306 int audio_sample_rate () const {
307 boost::mutex::scoped_lock lm (_state_mutex);
308 return _audio_sample_rate;
311 std::string content_digest () const {
312 boost::mutex::scoped_lock lm (_state_mutex);
313 return _content_digest;
316 bool has_subtitles () const {
317 boost::mutex::scoped_lock lm (_state_mutex);
318 return _has_subtitles;
321 std::vector<AudioStream> audio_streams () const {
322 boost::mutex::scoped_lock lm (_state_mutex);
323 return _audio_streams;
326 std::vector<SubtitleStream> subtitle_streams () const {
327 boost::mutex::scoped_lock lm (_state_mutex);
328 return _subtitle_streams;
331 float frames_per_second () const {
332 boost::mutex::scoped_lock lm (_state_mutex);
333 return _frames_per_second;
339 void set_directory (std::string);
340 void set_name (std::string);
341 void set_use_dci_name (bool);
342 virtual void set_content (std::string);
343 void set_dcp_content_type (DCPContentType const *);
344 void set_format (Format const *);
345 void set_crop (Crop);
346 void set_left_crop (int);
347 void set_right_crop (int);
348 void set_top_crop (int);
349 void set_bottom_crop (int);
350 void set_filters (std::vector<Filter const *>);
351 void set_scaler (Scaler const *);
352 void set_dcp_frames (int);
353 void set_dcp_trim_action (TrimAction);
354 void set_dcp_ab (bool);
355 void set_audio_stream (int);
356 void set_audio_gain (float);
357 void set_audio_delay (int);
358 void set_still_duration (int);
359 void set_subtitle_stream (int);
360 void set_with_subtitles (bool);
361 void set_subtitle_offset (int);
362 void set_subtitle_scale (float);
363 void set_audio_language (std::string);
364 void set_subtitle_language (std::string);
365 void set_territory (std::string);
366 void set_rating (std::string);
367 void set_studio (std::string);
368 void set_facility (std::string);
369 void set_package_type (std::string);
370 void set_thumbs (std::vector<int>);
371 void set_size (Size);
372 void set_length (int);
373 void set_audio_sample_rate (int);
374 void set_content_digest (std::string);
375 void set_has_subtitles (bool);
376 void set_audio_streams (std::vector<AudioStream>);
377 void set_subtitle_streams (std::vector<SubtitleStream>);
378 void set_frames_per_second (float);
380 /** Emitted when some property has changed */
381 mutable sigc::signal1<void, Property> Changed;
385 /** Log to write to */
388 /** Any running ExamineContentJob, or 0 */
389 boost::shared_ptr<ExamineContentJob> _examine_content_job;
391 std::string thumb_file_for_frame (int) const;
392 std::string thumb_base_for_frame (int) const;
393 void signal_changed (Property);
394 std::string file_locked (std::string) const;
396 /** Complete path to directory containing the film metadata;
397 * must not be relative.
399 std::string _directory;
400 /** Name for DVD-o-matic */
402 /** True if a auto-generated DCI-compliant name should be used for our DCP */
404 /** File or directory containing content; may be relative to our directory
405 * or an absolute path.
407 std::string _content;
408 /** The type of content that this Film represents (feature, trailer etc.) */
409 DCPContentType const * _dcp_content_type;
410 /** The format to present this Film in (flat, scope, etc.) */
411 Format const * _format;
412 /** The crop to apply to the source */
414 /** Video filters that should be used when generating DCPs */
415 std::vector<Filter const *> _filters;
416 /** Scaler algorithm to use */
417 Scaler const * _scaler;
418 /** Number of frames to put in the DCP, or 0 for all */
420 /** What to do with audio when trimming DCPs */
421 TrimAction _dcp_trim_action;
422 /** true to create an A/B comparison DCP, where the left half of the image
423 is the video without any filters or post-processing, and the right half
424 has the specified filters and post-processing.
427 /** An index into our _audio_streams vector for the stream to use for audio, or -1 if there is none */
429 /** Gain to apply to audio in dB */
431 /** Delay to apply to audio (positive moves audio later) in milliseconds */
433 /** Duration to make still-sourced films (in seconds) */
435 /** An index into our _subtitle_streams vector for the stream to use for subtitles, or -1 if there is none */
436 int _subtitle_stream;
437 /** True if subtitles should be shown for this film */
438 bool _with_subtitles;
439 /** y offset for placing subtitles, in source pixels; +ve is further down
440 the frame, -ve is further up.
442 int _subtitle_offset;
443 /** scale factor to apply to subtitles */
444 float _subtitle_scale;
446 /* DCI naming stuff */
447 std::string _audio_language;
448 std::string _subtitle_language;
449 std::string _territory;
452 std::string _facility;
453 std::string _package_type;
455 /* Data which are cached to speed things up */
457 /** Vector of frame indices for each of our `thumbnails' */
458 std::vector<int> _thumbs;
459 /** Size, in pixels, of the source (ignoring cropping) */
461 /** Length of the source in frames */
463 /** Sample rate of the source audio, in Hz */
464 int _audio_sample_rate;
465 /** MD5 digest of our content file */
466 std::string _content_digest;
467 /** true if the source has subtitles */
469 /** the audio streams that the source has */
470 std::vector<AudioStream> _audio_streams;
471 /** the subtitle streams that the source has */
472 std::vector<SubtitleStream> _subtitle_streams;
473 /** Frames per second of the source */
474 float _frames_per_second;
478 mutable boost::mutex _state_mutex;
480 friend class paths_test;