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;
49 * @brief A representation of a video with sound.
51 * A representation of a piece of video (with sound), including naming,
52 * the source content file, and how it should be presented in a DCP.
54 class Film : public boost::enable_shared_from_this<Film>
57 Film (std::string d, bool must_exist = true);
61 std::string j2k_dir () const;
62 std::vector<std::string> audio_files () const;
63 std::pair<Position, std::string> thumb_subtitle (int) const;
65 void examine_content ();
66 void send_dcp_to_tms ();
67 void copy_from_dvd ();
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 ();
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 int audio_stream_index () const {
206 boost::mutex::scoped_lock lm (_state_mutex);
207 return _audio_stream;
210 AudioStream audio_stream () const {
211 boost::mutex::scoped_lock lm (_state_mutex);
212 assert (_audio_stream < int (_audio_streams.size()));
213 return _audio_streams[_audio_stream];
216 float audio_gain () const {
217 boost::mutex::scoped_lock lm (_state_mutex);
221 int audio_delay () const {
222 boost::mutex::scoped_lock lm (_state_mutex);
226 int still_duration () const {
227 boost::mutex::scoped_lock lm (_state_mutex);
228 return _still_duration;
231 int subtitle_stream_index () const {
232 boost::mutex::scoped_lock lm (_state_mutex);
233 return _subtitle_stream;
236 SubtitleStream subtitle_stream () const {
237 boost::mutex::scoped_lock lm (_state_mutex);
238 assert (_subtitle_stream < int (_subtitle_streams.size()));
239 return _subtitle_streams[_subtitle_stream];
242 bool with_subtitles () const {
243 boost::mutex::scoped_lock lm (_state_mutex);
244 return _with_subtitles;
247 int subtitle_offset () const {
248 boost::mutex::scoped_lock lm (_state_mutex);
249 return _subtitle_offset;
252 float subtitle_scale () const {
253 boost::mutex::scoped_lock lm (_state_mutex);
254 return _subtitle_scale;
257 std::string audio_language () const {
258 boost::mutex::scoped_lock lm (_state_mutex);
259 return _audio_language;
262 std::string subtitle_language () const {
263 boost::mutex::scoped_lock lm (_state_mutex);
264 return _subtitle_language;
267 std::string territory () const {
268 boost::mutex::scoped_lock lm (_state_mutex);
272 std::string rating () const {
273 boost::mutex::scoped_lock lm (_state_mutex);
277 std::string studio () const {
278 boost::mutex::scoped_lock lm (_state_mutex);
282 std::string facility () const {
283 boost::mutex::scoped_lock lm (_state_mutex);
287 std::string package_type () const {
288 boost::mutex::scoped_lock lm (_state_mutex);
289 return _package_type;
292 std::vector<SourceFrame> thumbs () const {
293 boost::mutex::scoped_lock lm (_state_mutex);
298 boost::mutex::scoped_lock lm (_state_mutex);
302 boost::optional<SourceFrame> length () const {
303 boost::mutex::scoped_lock lm (_state_mutex);
307 int audio_sample_rate () const {
308 boost::mutex::scoped_lock lm (_state_mutex);
309 return _audio_sample_rate;
312 std::string content_digest () const {
313 boost::mutex::scoped_lock lm (_state_mutex);
314 return _content_digest;
317 bool has_subtitles () const {
318 boost::mutex::scoped_lock lm (_state_mutex);
319 return _has_subtitles;
322 std::vector<AudioStream> audio_streams () const {
323 boost::mutex::scoped_lock lm (_state_mutex);
324 return _audio_streams;
327 std::vector<SubtitleStream> subtitle_streams () const {
328 boost::mutex::scoped_lock lm (_state_mutex);
329 return _subtitle_streams;
332 float frames_per_second () const {
333 boost::mutex::scoped_lock lm (_state_mutex);
334 return _frames_per_second;
340 void set_directory (std::string);
341 void set_name (std::string);
342 void set_use_dci_name (bool);
343 virtual void set_content (std::string);
344 void set_dcp_content_type (DCPContentType const *);
345 void set_format (Format const *);
346 void set_crop (Crop);
347 void set_left_crop (int);
348 void set_right_crop (int);
349 void set_top_crop (int);
350 void set_bottom_crop (int);
351 void set_filters (std::vector<Filter const *>);
352 void set_scaler (Scaler const *);
353 void set_dcp_trim_start (int);
354 void set_dcp_trim_end (int);
355 void set_dcp_ab (bool);
356 void set_audio_stream (int);
357 void set_audio_gain (float);
358 void set_audio_delay (int);
359 void set_still_duration (int);
360 void set_subtitle_stream (int);
361 void set_with_subtitles (bool);
362 void set_subtitle_offset (int);
363 void set_subtitle_scale (float);
364 void set_audio_language (std::string);
365 void set_subtitle_language (std::string);
366 void set_territory (std::string);
367 void set_rating (std::string);
368 void set_studio (std::string);
369 void set_facility (std::string);
370 void set_package_type (std::string);
371 void set_thumbs (std::vector<SourceFrame>);
372 void set_size (Size);
373 void set_length (SourceFrame);
374 void unset_length ();
375 void set_audio_sample_rate (int);
376 void set_content_digest (std::string);
377 void set_has_subtitles (bool);
378 void set_audio_streams (std::vector<AudioStream>);
379 void set_subtitle_streams (std::vector<SubtitleStream>);
380 void set_frames_per_second (float);
382 /** Emitted when some property has changed */
383 mutable boost::signals2::signal<void (Property)> Changed;
387 /** Log to write to */
390 /** Any running ExamineContentJob, or 0 */
391 boost::shared_ptr<ExamineContentJob> _examine_content_job;
393 boost::gregorian::date _dci_date;
395 std::string thumb_file_for_frame (SourceFrame) const;
396 std::string thumb_base_for_frame (SourceFrame) const;
397 void signal_changed (Property);
398 void examine_content_finished ();
400 /** Complete path to directory containing the film metadata;
401 * must not be relative.
403 std::string _directory;
404 /** Mutex for _directory */
405 mutable boost::mutex _directory_mutex;
407 /** Name for DVD-o-matic */
409 /** True if a auto-generated DCI-compliant name should be used for our DCP */
411 /** File or directory containing content; may be relative to our directory
412 * or an absolute path.
414 std::string _content;
415 /** The type of content that this Film represents (feature, trailer etc.) */
416 DCPContentType const * _dcp_content_type;
417 /** The format to present this Film in (flat, scope, etc.) */
418 Format const * _format;
419 /** The crop to apply to the source */
421 /** Video filters that should be used when generating DCPs */
422 std::vector<Filter const *> _filters;
423 /** Scaler algorithm to use */
424 Scaler const * _scaler;
425 SourceFrame _dcp_trim_start;
426 SourceFrame _dcp_trim_end;
427 /** true to create an A/B comparison DCP, where the left half of the image
428 is the video without any filters or post-processing, and the right half
429 has the specified filters and post-processing.
432 /** An index into our _audio_streams vector for the stream to use for audio, or -1 if there is none */
434 /** Gain to apply to audio in dB */
436 /** Delay to apply to audio (positive moves audio later) in milliseconds */
438 /** Duration to make still-sourced films (in seconds) */
440 /** An index into our _subtitle_streams vector for the stream to use for subtitles, or -1 if there is none */
441 int _subtitle_stream;
442 /** True if subtitles should be shown for this film */
443 bool _with_subtitles;
444 /** y offset for placing subtitles, in source pixels; +ve is further down
445 the frame, -ve is further up.
447 int _subtitle_offset;
448 /** scale factor to apply to subtitles */
449 float _subtitle_scale;
451 /* DCI naming stuff */
452 std::string _audio_language;
453 std::string _subtitle_language;
454 std::string _territory;
457 std::string _facility;
458 std::string _package_type;
460 /* Data which are cached to speed things up */
462 /** Vector of frame indices for each of our `thumbnails' */
463 std::vector<SourceFrame> _thumbs;
464 /** Size, in pixels, of the source (ignoring cropping) */
466 /** Actual length of the source (in video frames) from examining it */
467 boost::optional<SourceFrame> _length;
468 /** Sample rate of the source audio, in Hz */
469 int _audio_sample_rate;
470 /** MD5 digest of our content file */
471 std::string _content_digest;
472 /** true if the source has subtitles */
474 /** the audio streams that the source has */
475 std::vector<AudioStream> _audio_streams;
476 /** the subtitle streams that the source has */
477 std::vector<SubtitleStream> _subtitle_streams;
478 /** Frames per second of the source */
479 float _frames_per_second;
483 /** Mutex for all state except _directory */
484 mutable boost::mutex _state_mutex;
486 friend class paths_test;