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.
28 #include <boost/filesystem.hpp>
29 #include <boost/algorithm/string.hpp>
30 #include <boost/lexical_cast.hpp>
31 #include <boost/date_time.hpp>
34 #include "imagemagick_encoder.h"
37 #include "transcoder.h"
39 #include "job_manager.h"
40 #include "ab_transcode_job.h"
41 #include "transcode_job.h"
42 #include "scp_dcp_job.h"
43 #include "copy_from_dvd_job.h"
44 #include "make_dcp_job.h"
47 #include "exceptions.h"
48 #include "examine_content_job.h"
50 #include "decoder_factory.h"
52 #include "check_hashes_job.h"
54 #include "ui_signaller.h"
57 using std::stringstream;
67 using boost::shared_ptr;
68 using boost::lexical_cast;
69 using boost::to_upper_copy;
70 using boost::ends_with;
71 using boost::starts_with;
72 using boost::optional;
74 int const Film::state_version = 1;
76 /** Construct a Film object in a given directory, reading any metadata
77 * file that exists in that directory. An exception will be thrown if
78 * must_exist is true and the specified directory does not exist.
80 * @param d Film directory.
81 * @param must_exist true to throw an exception if does not exist.
84 Film::Film (string d, bool must_exist)
85 : _use_dci_name (true)
86 , _dcp_content_type (0)
88 , _scaler (Scaler::from_id ("bicubic"))
92 , _use_content_audio (true)
95 , _still_duration (10)
96 , _with_subtitles (false)
97 , _subtitle_offset (0)
99 , _frames_per_second (0)
102 /* Make state.directory a complete path without ..s (where possible)
103 (Code swiped from Adam Bowen on stackoverflow)
106 boost::filesystem::path p (boost::filesystem::system_complete (d));
107 boost::filesystem::path result;
108 for (boost::filesystem::path::iterator i = p.begin(); i != p.end(); ++i) {
110 if (boost::filesystem::is_symlink (result) || result.filename() == "..") {
113 result = result.parent_path ();
115 } else if (*i != ".") {
120 set_directory (result.string ());
122 if (!boost::filesystem::exists (directory())) {
124 throw OpenFileError (directory());
126 boost::filesystem::create_directory (directory());
132 _log = new FileLog (file ("log"));
133 set_dci_date_today ();
136 Film::Film (Film const & o)
138 , _directory (o._directory)
140 , _use_dci_name (o._use_dci_name)
141 , _content (o._content)
142 , _dcp_content_type (o._dcp_content_type)
143 , _format (o._format)
145 , _filters (o._filters)
146 , _scaler (o._scaler)
147 , _dcp_trim_start (o._dcp_trim_start)
148 , _dcp_trim_end (o._dcp_trim_end)
149 , _dcp_ab (o._dcp_ab)
150 , _use_content_audio (o._use_content_audio)
151 , _audio_stream (o._audio_stream)
152 , _external_audio (o._external_audio)
153 , _audio_gain (o._audio_gain)
154 , _audio_delay (o._audio_delay)
155 , _still_duration (o._still_duration)
156 , _subtitle_stream (o._subtitle_stream)
157 , _with_subtitles (o._with_subtitles)
158 , _subtitle_offset (o._subtitle_offset)
159 , _subtitle_scale (o._subtitle_scale)
160 , _audio_language (o._audio_language)
161 , _subtitle_language (o._subtitle_language)
162 , _territory (o._territory)
163 , _rating (o._rating)
164 , _studio (o._studio)
165 , _facility (o._facility)
166 , _package_type (o._package_type)
167 , _thumbs (o._thumbs)
169 , _length (o._length)
170 , _content_digest (o._content_digest)
171 , _audio_streams (o._audio_streams)
172 , _subtitle_streams (o._subtitle_streams)
173 , _frames_per_second (o._frames_per_second)
184 /** @return The path to the directory to write JPEG2000 files to */
186 Film::j2k_dir () const
190 boost::filesystem::path p;
195 pair<string, string> f = Filter::ffmpeg_strings (filters());
197 /* Write stuff to specify the filter / post-processing settings that are in use,
198 so that we don't get confused about J2K files generated using different
203 << "_" << content_digest()
204 << "_" << crop().left << "_" << crop().right << "_" << crop().top << "_" << crop().bottom
205 << "_" << f.first << "_" << f.second
206 << "_" << scaler()->id();
210 /* Similarly for the A/B case */
213 pair<string, string> fa = Filter::ffmpeg_strings (Config::instance()->reference_filters());
214 s << "ab_" << Config::instance()->reference_scaler()->id() << "_" << fa.first << "_" << fa.second;
218 return dir (p.string());
221 /** Add suitable Jobs to the JobManager to create a DCP for this Film.
222 * @param true to transcode, false to use the WAV and J2K files that are already there.
225 Film::make_dcp (bool transcode)
227 set_dci_date_today ();
229 if (dcp_name().find ("/") != string::npos) {
230 throw BadSettingError ("name", "cannot contain slashes");
233 log()->log (String::compose ("DVD-o-matic %1 git %2 using %3", dvdomatic_version, dvdomatic_git_commit, dependency_version_summary()));
237 gethostname (buffer, sizeof (buffer));
238 log()->log (String::compose ("Starting to make DCP on %1", buffer));
242 throw MissingSettingError ("format");
245 if (content().empty ()) {
246 throw MissingSettingError ("content");
249 if (dcp_content_type() == 0) {
250 throw MissingSettingError ("content type");
253 if (name().empty()) {
254 throw MissingSettingError ("name");
257 shared_ptr<Options> o (new Options (j2k_dir(), ".j2c", dir ("wavs")));
258 o->out_size = format()->dcp_size ();
259 o->padding = format()->dcp_padding (shared_from_this ());
260 o->ratio = format()->ratio_as_float (shared_from_this ());
262 o->video_decode_range = make_pair (dcp_trim_start(), dcp_trim_start() + dcp_length().get());
263 if (audio_stream()) {
264 o->audio_decode_range = make_pair (
265 video_frames_to_audio_frames (o->video_decode_range.get().first, audio_stream().get().sample_rate(), frames_per_second()),
266 video_frames_to_audio_frames (o->video_decode_range.get().second, audio_stream().get().sample_rate(), frames_per_second())
271 o->decode_subtitles = with_subtitles ();
272 o->decode_video_skip = dcp_frame_rate (frames_per_second()).skip;
278 r = JobManager::instance()->add (shared_ptr<Job> (new ABTranscodeJob (shared_from_this(), o, shared_ptr<Job> ())));
280 r = JobManager::instance()->add (shared_ptr<Job> (new TranscodeJob (shared_from_this(), o, shared_ptr<Job> ())));
284 r = JobManager::instance()->add (shared_ptr<Job> (new CheckHashesJob (shared_from_this(), o, r)));
285 JobManager::instance()->add (shared_ptr<Job> (new MakeDCPJob (shared_from_this(), o, r)));
288 /** Start a job to examine our content file */
290 Film::examine_content ()
292 if (_examine_content_job) {
296 set_thumbs (vector<SourceFrame> ());
297 boost::filesystem::remove_all (dir ("thumbs"));
299 /* This call will recreate the directory */
302 _examine_content_job.reset (new ExamineContentJob (shared_from_this(), shared_ptr<Job> ()));
303 _examine_content_job->Finished.connect (bind (&Film::examine_content_finished, this));
304 JobManager::instance()->add (_examine_content_job);
308 Film::examine_content_finished ()
310 _examine_content_job.reset ();
313 /** @return full paths to any audio files that this Film has */
315 Film::audio_files () const
318 for (boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (dir("wavs")); i != boost::filesystem::directory_iterator(); ++i) {
319 f.push_back (i->path().string ());
325 /** Start a job to send our DCP to the configured TMS */
327 Film::send_dcp_to_tms ()
329 shared_ptr<Job> j (new SCPDCPJob (shared_from_this(), shared_ptr<Job> ()));
330 JobManager::instance()->add (j);
334 Film::copy_from_dvd ()
336 shared_ptr<Job> j (new CopyFromDVDJob (shared_from_this(), shared_ptr<Job> ()));
337 JobManager::instance()->add (j);
340 /** Count the number of frames that have been encoded for this film.
341 * @return frame count.
344 Film::encoded_frames () const
351 for (boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (j2k_dir ()); i != boost::filesystem::directory_iterator(); ++i) {
353 boost::this_thread::interruption_point ();
359 /** Return the filename of a subtitle image if one exists for a given thumb index.
360 * @param Thumbnail index.
361 * @return Position of the image within the source frame, and the image filename, if one exists.
362 * Otherwise the filename will be empty.
364 pair<Position, string>
365 Film::thumb_subtitle (int n) const
367 string sub_file = thumb_base(n) + ".sub";
368 if (!boost::filesystem::exists (sub_file)) {
369 return pair<Position, string> ();
372 pair<Position, string> sub;
374 ifstream f (sub_file.c_str ());
375 multimap<string, string> kv = read_key_value (f);
376 for (map<string, string>::const_iterator i = kv.begin(); i != kv.end(); ++i) {
377 if (i->first == "x") {
378 sub.first.x = lexical_cast<int> (i->second);
379 } else if (i->first == "y") {
380 sub.first.y = lexical_cast<int> (i->second);
381 sub.second = String::compose ("%1.sub.png", thumb_base(n));
388 /** Write state to our `metadata' file */
390 Film::write_metadata () const
392 boost::mutex::scoped_lock lm (_state_mutex);
394 boost::filesystem::create_directories (directory());
396 string const m = file ("metadata");
397 ofstream f (m.c_str ());
399 throw CreateFileError (m);
402 f << "version " << state_version << "\n";
405 f << "name " << _name << "\n";
406 f << "use_dci_name " << _use_dci_name << "\n";
407 f << "content " << _content << "\n";
408 if (_dcp_content_type) {
409 f << "dcp_content_type " << _dcp_content_type->pretty_name () << "\n";
412 f << "format " << _format->as_metadata () << "\n";
414 f << "left_crop " << _crop.left << "\n";
415 f << "right_crop " << _crop.right << "\n";
416 f << "top_crop " << _crop.top << "\n";
417 f << "bottom_crop " << _crop.bottom << "\n";
418 for (vector<Filter const *>::const_iterator i = _filters.begin(); i != _filters.end(); ++i) {
419 f << "filter " << (*i)->id () << "\n";
421 f << "scaler " << _scaler->id () << "\n";
422 f << "dcp_trim_start " << _dcp_trim_start << "\n";
423 f << "dcp_trim_end " << _dcp_trim_end << "\n";
424 f << "dcp_ab " << (_dcp_ab ? "1" : "0") << "\n";
425 f << "use_content_audio " << (_use_content_audio ? "1" : "0") << "\n";
427 f << "selected_audio_stream " << _audio_stream.get().to_string() << "\n";
429 for (vector<string>::const_iterator i = _external_audio.begin(); i != _external_audio.end(); ++i) {
430 f << "external_audio " << *i << "\n";
432 f << "audio_gain " << _audio_gain << "\n";
433 f << "audio_delay " << _audio_delay << "\n";
434 f << "still_duration " << _still_duration << "\n";
435 if (_subtitle_stream) {
436 f << "selected_subtitle_stream " << _subtitle_stream.get().to_string() << "\n";
438 f << "with_subtitles " << _with_subtitles << "\n";
439 f << "subtitle_offset " << _subtitle_offset << "\n";
440 f << "subtitle_scale " << _subtitle_scale << "\n";
441 f << "audio_language " << _audio_language << "\n";
442 f << "subtitle_language " << _subtitle_language << "\n";
443 f << "territory " << _territory << "\n";
444 f << "rating " << _rating << "\n";
445 f << "studio " << _studio << "\n";
446 f << "facility " << _facility << "\n";
447 f << "package_type " << _package_type << "\n";
449 /* Cached stuff; this is information about our content; we could
450 look it up each time, but that's slow.
452 for (vector<SourceFrame>::const_iterator i = _thumbs.begin(); i != _thumbs.end(); ++i) {
453 f << "thumb " << *i << "\n";
455 f << "width " << _size.width << "\n";
456 f << "height " << _size.height << "\n";
457 f << "length " << _length.get_value_or(0) << "\n";
458 f << "content_digest " << _content_digest << "\n";
460 for (vector<AudioStream>::const_iterator i = _audio_streams.begin(); i != _audio_streams.end(); ++i) {
461 f << "audio_stream " << i->to_string () << "\n";
464 for (vector<SubtitleStream>::const_iterator i = _subtitle_streams.begin(); i != _subtitle_streams.end(); ++i) {
465 f << "subtitle_stream " << i->to_string () << "\n";
468 f << "frames_per_second " << _frames_per_second << "\n";
473 /** Read state from our metadata file */
475 Film::read_metadata ()
477 boost::mutex::scoped_lock lm (_state_mutex);
479 _external_audio.clear ();
481 _audio_streams.clear ();
482 _subtitle_streams.clear ();
484 boost::optional<int> version;
486 /* Backward compatibility things */
487 boost::optional<int> audio_sample_rate;
488 boost::optional<int> audio_stream_index;
489 boost::optional<int> subtitle_stream_index;
491 ifstream f (file ("metadata").c_str());
492 multimap<string, string> kv = read_key_value (f);
493 for (multimap<string, string>::const_iterator i = kv.begin(); i != kv.end(); ++i) {
494 string const k = i->first;
495 string const v = i->second;
497 if (k == "version") {
498 version = atoi (v.c_str());
499 } else if (k == "audio_sample_rate") {
500 audio_sample_rate = atoi (v.c_str());
503 /* User-specified stuff */
506 } else if (k == "use_dci_name") {
507 _use_dci_name = (v == "1");
508 } else if (k == "content") {
510 } else if (k == "dcp_content_type") {
511 _dcp_content_type = DCPContentType::from_pretty_name (v);
512 } else if (k == "format") {
513 _format = Format::from_metadata (v);
514 } else if (k == "left_crop") {
515 _crop.left = atoi (v.c_str ());
516 } else if (k == "right_crop") {
517 _crop.right = atoi (v.c_str ());
518 } else if (k == "top_crop") {
519 _crop.top = atoi (v.c_str ());
520 } else if (k == "bottom_crop") {
521 _crop.bottom = atoi (v.c_str ());
522 } else if (k == "filter") {
523 _filters.push_back (Filter::from_id (v));
524 } else if (k == "scaler") {
525 _scaler = Scaler::from_id (v);
526 } else if (k == "dcp_trim_start") {
527 _dcp_trim_start = atoi (v.c_str ());
528 } else if (k == "dcp_trim_end") {
529 _dcp_trim_end = atoi (v.c_str ());
530 } else if (k == "dcp_ab") {
531 _dcp_ab = (v == "1");
532 } else if (k == "use_content_audio") {
533 _use_content_audio = (v == "1");
534 } else if (k == "selected_audio_stream") {
536 audio_stream_index = atoi (v.c_str ());
538 _audio_stream = AudioStream (v, version);
540 } else if (k == "external_audio") {
541 _external_audio.push_back (v);
542 } else if (k == "audio_gain") {
543 _audio_gain = atof (v.c_str ());
544 } else if (k == "audio_delay") {
545 _audio_delay = atoi (v.c_str ());
546 } else if (k == "still_duration") {
547 _still_duration = atoi (v.c_str ());
548 } else if (k == "selected_subtitle_stream") {
550 subtitle_stream_index = atoi (v.c_str ());
552 _subtitle_stream = SubtitleStream (v);
554 } else if (k == "with_subtitles") {
555 _with_subtitles = (v == "1");
556 } else if (k == "subtitle_offset") {
557 _subtitle_offset = atoi (v.c_str ());
558 } else if (k == "subtitle_scale") {
559 _subtitle_scale = atof (v.c_str ());
560 } else if (k == "audio_language") {
562 } else if (k == "subtitle_language") {
563 _subtitle_language = v;
564 } else if (k == "territory") {
566 } else if (k == "rating") {
568 } else if (k == "studio") {
570 } else if (k == "facility") {
572 } else if (k == "package_type") {
578 int const n = atoi (v.c_str ());
579 /* Only add it to the list if it still exists */
580 if (boost::filesystem::exists (thumb_file_for_frame (n))) {
581 _thumbs.push_back (n);
583 } else if (k == "width") {
584 _size.width = atoi (v.c_str ());
585 } else if (k == "height") {
586 _size.height = atoi (v.c_str ());
587 } else if (k == "length") {
588 int const vv = atoi (v.c_str ());
592 } else if (k == "content_digest") {
594 } else if (k == "audio_stream") {
595 _audio_streams.push_back (AudioStream (v, version));
596 } else if (k == "subtitle_stream") {
597 _subtitle_streams.push_back (SubtitleStream (v));
598 } else if (k == "frames_per_second") {
599 _frames_per_second = atof (v.c_str ());
604 if (audio_sample_rate) {
605 /* version < 1 didn't specify sample rate in the audio streams, so fill it in here */
606 for (vector<AudioStream>::iterator i = _audio_streams.begin(); i != _audio_streams.end(); ++i) {
607 i->set_sample_rate (audio_sample_rate.get());
611 /* also the selected stream was specified as an index */
612 if (audio_stream_index && audio_stream_index.get() >= 0 && audio_stream_index.get() < (int) _audio_streams.size()) {
613 _audio_stream = _audio_streams[audio_stream_index.get()];
616 /* similarly the subtitle */
617 if (subtitle_stream_index && subtitle_stream_index.get() >= 0 && subtitle_stream_index.get() < (int) _subtitle_streams.size()) {
618 _subtitle_stream = _subtitle_streams[subtitle_stream_index.get()];
625 /** @param n A thumb index.
626 * @return The path to the thumb's image file.
629 Film::thumb_file (int n) const
631 return thumb_file_for_frame (thumb_frame (n));
634 /** @param n A frame index within the Film's source.
635 * @return The path to the thumb's image file for this frame;
636 * we assume that it exists.
639 Film::thumb_file_for_frame (SourceFrame n) const
641 return thumb_base_for_frame(n) + ".png";
644 /** @param n Thumb index.
645 * Must not be called with the _state_mutex locked.
648 Film::thumb_base (int n) const
650 return thumb_base_for_frame (thumb_frame (n));
654 Film::thumb_base_for_frame (SourceFrame n) const
658 s << setfill('0') << n;
660 boost::filesystem::path p;
667 /** @param n A thumb index.
668 * @return The frame within the Film's source that it is for.
670 * Must not be called with the _state_mutex locked.
673 Film::thumb_frame (int n) const
675 boost::mutex::scoped_lock lm (_state_mutex);
676 assert (n < int (_thumbs.size ()));
681 Film::cropped_size (Size s) const
683 boost::mutex::scoped_lock lm (_state_mutex);
684 s.width -= _crop.left + _crop.right;
685 s.height -= _crop.top + _crop.bottom;
689 /** Given a directory name, return its full path within the Film's directory.
690 * The directory (and its parents) will be created if they do not exist.
693 Film::dir (string d) const
695 boost::mutex::scoped_lock lm (_directory_mutex);
696 boost::filesystem::path p;
699 boost::filesystem::create_directories (p);
703 /** Given a file or directory name, return its full path within the Film's directory.
704 * _directory_mutex must not be locked on entry.
707 Film::file (string f) const
709 boost::mutex::scoped_lock lm (_directory_mutex);
710 boost::filesystem::path p;
716 /** @return full path of the content (actual video) file
720 Film::content_path () const
722 boost::mutex::scoped_lock lm (_state_mutex);
723 if (boost::filesystem::path(_content).has_root_directory ()) {
727 return file (_content);
731 Film::content_type () const
733 if (boost::filesystem::is_directory (_content)) {
734 /* Directory of images, we assume */
738 if (still_image_file (_content)) {
745 /** @return The sampling rate that we will resample the audio to */
747 Film::target_audio_sample_rate () const
749 /* Resample to a DCI-approved sample rate */
750 double t = dcp_audio_sample_rate (audio_stream().get().sample_rate());
752 DCPFrameRate dfr = dcp_frame_rate (frames_per_second ());
754 /* Compensate for the fact that video will be rounded to the
755 nearest integer number of frames per second.
758 t *= _frames_per_second * dfr.skip / dfr.frames_per_second;
764 boost::optional<SourceFrame>
765 Film::dcp_length () const
768 return boost::optional<SourceFrame> ();
771 return length().get() - dcp_trim_start() - dcp_trim_end();
774 /** @return a DCI-compliant name for a DCP of this film */
776 Film::dci_name () const
780 string fixed_name = to_upper_copy (name());
781 for (size_t i = 0; i < fixed_name.length(); ++i) {
782 if (fixed_name[i] == ' ') {
787 /* Spec is that the name part should be maximum 14 characters, as I understand it */
788 if (fixed_name.length() > 14) {
789 fixed_name = fixed_name.substr (0, 14);
792 d << fixed_name << "_";
794 if (dcp_content_type()) {
795 d << dcp_content_type()->dci_name() << "_";
799 d << format()->dci_name() << "_";
802 if (!audio_language().empty ()) {
803 d << audio_language();
804 if (!subtitle_language().empty() && with_subtitles()) {
805 d << "-" << subtitle_language();
813 if (!territory().empty ()) {
815 if (!rating().empty ()) {
816 d << "-" << rating();
821 switch (audio_channels()) {
838 if (!studio().empty ()) {
839 d << studio() << "_";
842 d << boost::gregorian::to_iso_string (_dci_date) << "_";
844 if (!facility().empty ()) {
845 d << facility() << "_";
848 if (!package_type().empty ()) {
855 /** @return name to give the DCP */
857 Film::dcp_name () const
859 if (use_dci_name()) {
868 Film::set_directory (string d)
870 boost::mutex::scoped_lock lm (_state_mutex);
876 Film::set_name (string n)
879 boost::mutex::scoped_lock lm (_state_mutex);
882 signal_changed (NAME);
886 Film::set_use_dci_name (bool u)
889 boost::mutex::scoped_lock lm (_state_mutex);
892 signal_changed (USE_DCI_NAME);
896 Film::set_content (string c)
898 string check = directory ();
900 #if BOOST_FILESYSTEM_VERSION == 3
901 boost::filesystem::path slash ("/");
902 string platform_slash = slash.make_preferred().string ();
904 #ifdef DVDOMATIC_WINDOWS
905 string platform_slash = "\\";
907 string platform_slash = "/";
911 if (!ends_with (check, platform_slash)) {
912 check += platform_slash;
915 if (boost::filesystem::path(c).has_root_directory () && starts_with (c, check)) {
916 c = c.substr (_directory.length() + 1);
922 boost::mutex::scoped_lock lm (_state_mutex);
927 old_content = _content;
931 _audio_stream = optional<AudioStream> ();
932 _subtitle_stream = optional<SubtitleStream> ();
934 /* Create a temporary decoder so that we can get information
939 shared_ptr<Options> o (new Options ("", "", ""));
940 o->out_size = Size (1024, 1024);
942 shared_ptr<Decoder> d = decoder_factory (shared_from_this(), o, 0);
944 set_size (d->native_size ());
945 set_frames_per_second (d->frames_per_second ());
946 set_audio_streams (d->audio_streams ());
947 set_subtitle_streams (d->subtitle_streams ());
949 /* Start off with the first audio and subtitle streams */
950 if (!d->audio_streams().empty()) {
951 set_audio_stream (d->audio_streams().front());
954 if (!d->subtitle_streams().empty()) {
955 set_subtitle_stream (d->subtitle_streams().front());
959 boost::mutex::scoped_lock lm (_state_mutex);
963 signal_changed (CONTENT);
965 set_content_digest (md5_digest (content_path ()));
971 boost::mutex::scoped_lock lm (_state_mutex);
972 _content = old_content;
979 Film::set_dcp_content_type (DCPContentType const * t)
982 boost::mutex::scoped_lock lm (_state_mutex);
983 _dcp_content_type = t;
985 signal_changed (DCP_CONTENT_TYPE);
989 Film::set_format (Format const * f)
992 boost::mutex::scoped_lock lm (_state_mutex);
995 signal_changed (FORMAT);
999 Film::set_crop (Crop c)
1002 boost::mutex::scoped_lock lm (_state_mutex);
1005 signal_changed (CROP);
1009 Film::set_left_crop (int c)
1012 boost::mutex::scoped_lock lm (_state_mutex);
1014 if (_crop.left == c) {
1020 signal_changed (CROP);
1024 Film::set_right_crop (int c)
1027 boost::mutex::scoped_lock lm (_state_mutex);
1028 if (_crop.right == c) {
1034 signal_changed (CROP);
1038 Film::set_top_crop (int c)
1041 boost::mutex::scoped_lock lm (_state_mutex);
1042 if (_crop.top == c) {
1048 signal_changed (CROP);
1052 Film::set_bottom_crop (int c)
1055 boost::mutex::scoped_lock lm (_state_mutex);
1056 if (_crop.bottom == c) {
1062 signal_changed (CROP);
1066 Film::set_filters (vector<Filter const *> f)
1069 boost::mutex::scoped_lock lm (_state_mutex);
1072 signal_changed (FILTERS);
1076 Film::set_scaler (Scaler const * s)
1079 boost::mutex::scoped_lock lm (_state_mutex);
1082 signal_changed (SCALER);
1086 Film::set_dcp_trim_start (int t)
1089 boost::mutex::scoped_lock lm (_state_mutex);
1090 _dcp_trim_start = t;
1092 signal_changed (DCP_TRIM_START);
1096 Film::set_dcp_trim_end (int t)
1099 boost::mutex::scoped_lock lm (_state_mutex);
1102 signal_changed (DCP_TRIM_END);
1106 Film::set_dcp_ab (bool a)
1109 boost::mutex::scoped_lock lm (_state_mutex);
1112 signal_changed (DCP_AB);
1116 Film::set_use_content_audio (bool s)
1119 boost::mutex::scoped_lock lm (_state_mutex);
1120 _use_content_audio = s;
1122 signal_changed (USE_CONTENT_AUDIO);
1126 Film::set_audio_stream (optional<AudioStream> s)
1129 boost::mutex::scoped_lock lm (_state_mutex);
1132 signal_changed (AUDIO_STREAM);
1136 Film::set_external_audio (vector<string> a)
1139 boost::mutex::scoped_lock lm (_state_mutex);
1140 _external_audio = a;
1142 signal_changed (EXTERNAL_AUDIO);
1146 Film::set_audio_gain (float g)
1149 boost::mutex::scoped_lock lm (_state_mutex);
1152 signal_changed (AUDIO_GAIN);
1156 Film::set_audio_delay (int d)
1159 boost::mutex::scoped_lock lm (_state_mutex);
1162 signal_changed (AUDIO_DELAY);
1166 Film::set_still_duration (int d)
1169 boost::mutex::scoped_lock lm (_state_mutex);
1170 _still_duration = d;
1172 signal_changed (STILL_DURATION);
1176 Film::set_subtitle_stream (optional<SubtitleStream> s)
1179 boost::mutex::scoped_lock lm (_state_mutex);
1180 _subtitle_stream = s;
1182 signal_changed (SUBTITLE_STREAM);
1186 Film::set_with_subtitles (bool w)
1189 boost::mutex::scoped_lock lm (_state_mutex);
1190 _with_subtitles = w;
1192 signal_changed (WITH_SUBTITLES);
1196 Film::set_subtitle_offset (int o)
1199 boost::mutex::scoped_lock lm (_state_mutex);
1200 _subtitle_offset = o;
1202 signal_changed (SUBTITLE_OFFSET);
1206 Film::set_subtitle_scale (float s)
1209 boost::mutex::scoped_lock lm (_state_mutex);
1210 _subtitle_scale = s;
1212 signal_changed (SUBTITLE_SCALE);
1216 Film::set_audio_language (string l)
1219 boost::mutex::scoped_lock lm (_state_mutex);
1220 _audio_language = l;
1222 signal_changed (DCI_METADATA);
1226 Film::set_subtitle_language (string l)
1229 boost::mutex::scoped_lock lm (_state_mutex);
1230 _subtitle_language = l;
1232 signal_changed (DCI_METADATA);
1236 Film::set_territory (string t)
1239 boost::mutex::scoped_lock lm (_state_mutex);
1242 signal_changed (DCI_METADATA);
1246 Film::set_rating (string r)
1249 boost::mutex::scoped_lock lm (_state_mutex);
1252 signal_changed (DCI_METADATA);
1256 Film::set_studio (string s)
1259 boost::mutex::scoped_lock lm (_state_mutex);
1262 signal_changed (DCI_METADATA);
1266 Film::set_facility (string f)
1269 boost::mutex::scoped_lock lm (_state_mutex);
1272 signal_changed (DCI_METADATA);
1276 Film::set_package_type (string p)
1279 boost::mutex::scoped_lock lm (_state_mutex);
1282 signal_changed (DCI_METADATA);
1286 Film::set_thumbs (vector<SourceFrame> t)
1289 boost::mutex::scoped_lock lm (_state_mutex);
1292 signal_changed (THUMBS);
1296 Film::set_size (Size s)
1299 boost::mutex::scoped_lock lm (_state_mutex);
1302 signal_changed (SIZE);
1306 Film::set_length (SourceFrame l)
1309 boost::mutex::scoped_lock lm (_state_mutex);
1312 signal_changed (LENGTH);
1316 Film::unset_length ()
1319 boost::mutex::scoped_lock lm (_state_mutex);
1320 _length = boost::none;
1322 signal_changed (LENGTH);
1326 Film::set_content_digest (string d)
1329 boost::mutex::scoped_lock lm (_state_mutex);
1330 _content_digest = d;
1336 Film::set_audio_streams (vector<AudioStream> s)
1339 boost::mutex::scoped_lock lm (_state_mutex);
1346 Film::set_subtitle_streams (vector<SubtitleStream> s)
1349 boost::mutex::scoped_lock lm (_state_mutex);
1350 _subtitle_streams = s;
1356 Film::set_frames_per_second (float f)
1359 boost::mutex::scoped_lock lm (_state_mutex);
1360 _frames_per_second = f;
1362 signal_changed (FRAMES_PER_SECOND);
1366 Film::signal_changed (Property p)
1369 boost::mutex::scoped_lock lm (_state_mutex);
1374 ui_signaller->emit (boost::bind (boost::ref (Changed), p));
1379 Film::audio_channels () const
1381 boost::mutex::scoped_lock lm (_state_mutex);
1383 if (_use_content_audio) {
1384 if (_audio_stream) {
1385 return _audio_stream.get().channels ();
1388 int last_filled = -1;
1389 for (size_t i = 0; i < _external_audio.size(); ++i) {
1390 if (!_external_audio[i].empty()) {
1395 return last_filled + 1;
1402 Film::set_dci_date_today ()
1404 _dci_date = boost::gregorian::day_clock::local_day ();