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>
36 #include "transcoder.h"
38 #include "job_manager.h"
39 #include "ab_transcode_job.h"
40 #include "transcode_job.h"
41 #include "scp_dcp_job.h"
44 #include "exceptions.h"
45 #include "examine_content_job.h"
47 #include "decoder_factory.h"
50 #include "ui_signaller.h"
51 #include "video_decoder.h"
52 #include "audio_decoder.h"
53 #include "external_audio_decoder.h"
56 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;
75 int const Film::state_version = 2;
77 /** Construct a Film object in a given directory, reading any metadata
78 * file that exists in that directory. An exception will be thrown if
79 * must_exist is true and the specified directory does not exist.
81 * @param d Film directory.
82 * @param must_exist true to throw an exception if does not exist.
85 Film::Film (string d, bool must_exist)
86 : _use_dci_name (true)
87 , _trust_content_header (true)
88 , _dcp_content_type (0)
90 , _scaler (Scaler::from_id ("bicubic"))
94 , _use_content_audio (true)
97 , _still_duration (10)
98 , _with_subtitles (false)
99 , _subtitle_offset (0)
100 , _subtitle_scale (1)
102 , _j2k_bandwidth (200000000)
103 , _frames_per_second (0)
106 /* Make state.directory a complete path without ..s (where possible)
107 (Code swiped from Adam Bowen on stackoverflow)
110 boost::filesystem::path p (boost::filesystem::system_complete (d));
111 boost::filesystem::path result;
112 for (boost::filesystem::path::iterator i = p.begin(); i != p.end(); ++i) {
114 if (boost::filesystem::is_symlink (result) || result.filename() == "..") {
117 result = result.parent_path ();
119 } else if (*i != ".") {
124 set_directory (result.string ());
126 if (!boost::filesystem::exists (directory())) {
128 throw OpenFileError (directory());
130 boost::filesystem::create_directory (directory());
134 _external_audio_stream = ExternalAudioStream::create ();
140 _log = new FileLog (file ("log"));
141 set_dci_date_today ();
144 Film::Film (Film const & o)
145 : boost::enable_shared_from_this<Film> (o)
147 , _directory (o._directory)
149 , _use_dci_name (o._use_dci_name)
150 , _content (o._content)
151 , _trust_content_header (o._trust_content_header)
152 , _dcp_content_type (o._dcp_content_type)
153 , _format (o._format)
155 , _filters (o._filters)
156 , _scaler (o._scaler)
157 , _trim_start (o._trim_start)
158 , _trim_end (o._trim_end)
159 , _dcp_ab (o._dcp_ab)
160 , _content_audio_stream (o._content_audio_stream)
161 , _external_audio (o._external_audio)
162 , _use_content_audio (o._use_content_audio)
163 , _audio_gain (o._audio_gain)
164 , _audio_delay (o._audio_delay)
165 , _still_duration (o._still_duration)
166 , _subtitle_stream (o._subtitle_stream)
167 , _with_subtitles (o._with_subtitles)
168 , _subtitle_offset (o._subtitle_offset)
169 , _subtitle_scale (o._subtitle_scale)
170 , _colour_lut (o._colour_lut)
171 , _j2k_bandwidth (o._j2k_bandwidth)
172 , _audio_language (o._audio_language)
173 , _subtitle_language (o._subtitle_language)
174 , _territory (o._territory)
175 , _rating (o._rating)
176 , _studio (o._studio)
177 , _facility (o._facility)
178 , _package_type (o._package_type)
180 , _length (o._length)
181 , _dcp_intrinsic_duration (o._dcp_intrinsic_duration)
182 , _content_digest (o._content_digest)
183 , _content_audio_streams (o._content_audio_streams)
184 , _external_audio_stream (o._external_audio_stream)
185 , _subtitle_streams (o._subtitle_streams)
186 , _frames_per_second (o._frames_per_second)
198 Film::video_state_identifier () const
202 pair<string, string> f = Filter::ffmpeg_strings (filters());
206 << "_" << content_digest()
207 << "_" << crop().left << "_" << crop().right << "_" << crop().top << "_" << crop().bottom
208 << "_" << f.first << "_" << f.second
209 << "_" << scaler()->id()
210 << "_" << j2k_bandwidth()
211 << "_" << boost::lexical_cast<int> (colour_lut());
214 pair<string, string> fa = Filter::ffmpeg_strings (Config::instance()->reference_filters());
215 s << "ab_" << Config::instance()->reference_scaler()->id() << "_" << fa.first << "_" << fa.second;
221 /** @return The path to the directory to write video frame hash files to */
223 Film::hash_dir () const
225 boost::filesystem::path p;
227 p /= video_state_identifier ();
228 return dir (p.string());
232 Film::video_mxf_dir () const
234 boost::filesystem::path p;
235 return dir ("video");
239 Film::video_mxf_filename () const
241 return video_state_identifier() + ".mxf";
244 /** Add suitable Jobs to the JobManager to create a DCP for this Film.
245 * @param true to transcode, false to use the WAV and J2K files that are already there.
248 Film::make_dcp (bool transcode)
250 set_dci_date_today ();
252 if (dcp_name().find ("/") != string::npos) {
253 throw BadSettingError ("name", "cannot contain slashes");
256 log()->log (String::compose ("DVD-o-matic %1 git %2 using %3", dvdomatic_version, dvdomatic_git_commit, dependency_version_summary()));
260 gethostname (buffer, sizeof (buffer));
261 log()->log (String::compose ("Starting to make DCP on %1", buffer));
264 log()->log (String::compose ("Content is %1; type %2", content_path(), (content_type() == STILL ? "still" : "video")));
266 log()->log (String::compose ("Content length %1", length().get()));
268 log()->log (String::compose ("Content digest %1", content_digest()));
269 log()->log (String::compose ("%1 threads", Config::instance()->num_local_encoding_threads()));
270 log()->log (String::compose ("J2K bandwidth %1", j2k_bandwidth()));
271 #ifdef DVDOMATIC_DEBUG
272 log()->log ("DVD-o-matic built in debug mode.");
274 log()->log ("DVD-o-matic built in optimised mode.");
277 log()->log ("libdcp built in debug mode.");
279 log()->log ("libdcp built in optimised mode.");
281 pair<string, int> const c = cpu_info ();
282 log()->log (String::compose ("CPU: %1, %2 processors", c.first, c.second));
285 throw MissingSettingError ("format");
288 if (content().empty ()) {
289 throw MissingSettingError ("content");
292 if (dcp_content_type() == 0) {
293 throw MissingSettingError ("content type");
296 if (name().empty()) {
297 throw MissingSettingError ("name");
301 od.decode_subtitles = with_subtitles ();
307 r = JobManager::instance()->add (shared_ptr<Job> (new ABTranscodeJob (shared_from_this(), od, shared_ptr<Job> ())));
309 r = JobManager::instance()->add (shared_ptr<Job> (new TranscodeJob (shared_from_this(), od, shared_ptr<Job> ())));
314 /** Start a job to examine our content file */
316 Film::examine_content ()
318 if (_examine_content_job) {
322 _examine_content_job.reset (new ExamineContentJob (shared_from_this(), shared_ptr<Job> ()));
323 _examine_content_job->Finished.connect (bind (&Film::examine_content_finished, this));
324 JobManager::instance()->add (_examine_content_job);
328 Film::examine_content_finished ()
330 _examine_content_job.reset ();
333 /** Start a job to send our DCP to the configured TMS */
335 Film::send_dcp_to_tms ()
337 shared_ptr<Job> j (new SCPDCPJob (shared_from_this(), shared_ptr<Job> ()));
338 JobManager::instance()->add (j);
341 /** Count the number of frames that have been encoded for this film.
342 * @return frame count.
345 Film::encoded_frames () const
352 for (boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (hash_dir ()); i != boost::filesystem::directory_iterator(); ++i) {
354 boost::this_thread::interruption_point ();
360 /** Write state to our `metadata' file */
362 Film::write_metadata () const
364 boost::mutex::scoped_lock lm (_state_mutex);
366 boost::filesystem::create_directories (directory());
368 string const m = file ("metadata");
369 ofstream f (m.c_str ());
371 throw CreateFileError (m);
374 f << "version " << state_version << "\n";
377 f << "name " << _name << "\n";
378 f << "use_dci_name " << _use_dci_name << "\n";
379 f << "content " << _content << "\n";
380 f << "trust_content_header " << (_trust_content_header ? "1" : "0") << "\n";
381 if (_dcp_content_type) {
382 f << "dcp_content_type " << _dcp_content_type->pretty_name () << "\n";
385 f << "format " << _format->as_metadata () << "\n";
387 f << "left_crop " << _crop.left << "\n";
388 f << "right_crop " << _crop.right << "\n";
389 f << "top_crop " << _crop.top << "\n";
390 f << "bottom_crop " << _crop.bottom << "\n";
391 for (vector<Filter const *>::const_iterator i = _filters.begin(); i != _filters.end(); ++i) {
392 f << "filter " << (*i)->id () << "\n";
394 f << "scaler " << _scaler->id () << "\n";
395 f << "trim_start " << _trim_start << "\n";
396 f << "trim_end " << _trim_end << "\n";
397 f << "dcp_ab " << (_dcp_ab ? "1" : "0") << "\n";
398 if (_content_audio_stream) {
399 f << "selected_content_audio_stream " << _content_audio_stream->to_string() << "\n";
401 for (vector<string>::const_iterator i = _external_audio.begin(); i != _external_audio.end(); ++i) {
402 f << "external_audio " << *i << "\n";
404 f << "use_content_audio " << (_use_content_audio ? "1" : "0") << "\n";
405 f << "audio_gain " << _audio_gain << "\n";
406 f << "audio_delay " << _audio_delay << "\n";
407 f << "still_duration " << _still_duration << "\n";
408 if (_subtitle_stream) {
409 f << "selected_subtitle_stream " << _subtitle_stream->to_string() << "\n";
411 f << "with_subtitles " << _with_subtitles << "\n";
412 f << "subtitle_offset " << _subtitle_offset << "\n";
413 f << "subtitle_scale " << _subtitle_scale << "\n";
414 f << "colour_lut " << _colour_lut << "\n";
415 f << "j2k_bandwidth " << _j2k_bandwidth << "\n";
416 f << "audio_language " << _audio_language << "\n";
417 f << "subtitle_language " << _subtitle_language << "\n";
418 f << "territory " << _territory << "\n";
419 f << "rating " << _rating << "\n";
420 f << "studio " << _studio << "\n";
421 f << "facility " << _facility << "\n";
422 f << "package_type " << _package_type << "\n";
424 f << "width " << _size.width << "\n";
425 f << "height " << _size.height << "\n";
426 f << "length " << _length.get_value_or(0) << "\n";
427 f << "dcp_intrinsic_duration " << _dcp_intrinsic_duration.get_value_or(0) << "\n";
428 f << "content_digest " << _content_digest << "\n";
430 for (vector<shared_ptr<AudioStream> >::const_iterator i = _content_audio_streams.begin(); i != _content_audio_streams.end(); ++i) {
431 f << "content_audio_stream " << (*i)->to_string () << "\n";
434 f << "external_audio_stream " << _external_audio_stream->to_string() << "\n";
436 for (vector<shared_ptr<SubtitleStream> >::const_iterator i = _subtitle_streams.begin(); i != _subtitle_streams.end(); ++i) {
437 f << "subtitle_stream " << (*i)->to_string () << "\n";
440 f << "frames_per_second " << _frames_per_second << "\n";
445 /** Read state from our metadata file */
447 Film::read_metadata ()
449 boost::mutex::scoped_lock lm (_state_mutex);
451 _external_audio.clear ();
452 _content_audio_streams.clear ();
453 _subtitle_streams.clear ();
455 boost::optional<int> version;
457 /* Backward compatibility things */
458 boost::optional<int> audio_sample_rate;
459 boost::optional<int> audio_stream_index;
460 boost::optional<int> subtitle_stream_index;
462 ifstream f (file ("metadata").c_str());
464 throw OpenFileError (file("metadata"));
467 multimap<string, string> kv = read_key_value (f);
469 /* We need version before anything else */
470 multimap<string, string>::iterator v = kv.find ("version");
471 if (v != kv.end ()) {
472 version = atoi (v->second.c_str());
475 for (multimap<string, string>::const_iterator i = kv.begin(); i != kv.end(); ++i) {
476 string const k = i->first;
477 string const v = i->second;
479 if (k == "audio_sample_rate") {
480 audio_sample_rate = atoi (v.c_str());
483 /* User-specified stuff */
486 } else if (k == "use_dci_name") {
487 _use_dci_name = (v == "1");
488 } else if (k == "content") {
490 } else if (k == "trust_content_header") {
491 _trust_content_header = (v == "1");
492 } else if (k == "dcp_content_type") {
493 _dcp_content_type = DCPContentType::from_pretty_name (v);
494 } else if (k == "format") {
495 _format = Format::from_metadata (v);
496 } else if (k == "left_crop") {
497 _crop.left = atoi (v.c_str ());
498 } else if (k == "right_crop") {
499 _crop.right = atoi (v.c_str ());
500 } else if (k == "top_crop") {
501 _crop.top = atoi (v.c_str ());
502 } else if (k == "bottom_crop") {
503 _crop.bottom = atoi (v.c_str ());
504 } else if (k == "filter") {
505 _filters.push_back (Filter::from_id (v));
506 } else if (k == "scaler") {
507 _scaler = Scaler::from_id (v);
508 } else if ( ((!version || version < 2) && k == "trim_start") || k == "trim_start") {
509 _trim_start = atoi (v.c_str ());
510 } else if ( ((!version || version < 2) && k == "trim_end") || k == "trim_end") {
511 _trim_end = atoi (v.c_str ());
512 } else if (k == "dcp_ab") {
513 _dcp_ab = (v == "1");
514 } else if (k == "selected_content_audio_stream" || (!version && k == "selected_audio_stream")) {
516 audio_stream_index = atoi (v.c_str ());
518 _content_audio_stream = audio_stream_factory (v, version);
520 } else if (k == "external_audio") {
521 _external_audio.push_back (v);
522 } else if (k == "use_content_audio") {
523 _use_content_audio = (v == "1");
524 } else if (k == "audio_gain") {
525 _audio_gain = atof (v.c_str ());
526 } else if (k == "audio_delay") {
527 _audio_delay = atoi (v.c_str ());
528 } else if (k == "still_duration") {
529 _still_duration = atoi (v.c_str ());
530 } else if (k == "selected_subtitle_stream") {
532 subtitle_stream_index = atoi (v.c_str ());
534 _subtitle_stream = subtitle_stream_factory (v, version);
536 } else if (k == "with_subtitles") {
537 _with_subtitles = (v == "1");
538 } else if (k == "subtitle_offset") {
539 _subtitle_offset = atoi (v.c_str ());
540 } else if (k == "subtitle_scale") {
541 _subtitle_scale = atof (v.c_str ());
542 } else if (k == "colour_lut") {
543 _colour_lut = atoi (v.c_str ());
544 } else if (k == "j2k_bandwidth") {
545 _j2k_bandwidth = atoi (v.c_str ());
546 } else if (k == "audio_language") {
548 } else if (k == "subtitle_language") {
549 _subtitle_language = v;
550 } else if (k == "territory") {
552 } else if (k == "rating") {
554 } else if (k == "studio") {
556 } else if (k == "facility") {
558 } else if (k == "package_type") {
564 _size.width = atoi (v.c_str ());
565 } else if (k == "height") {
566 _size.height = atoi (v.c_str ());
567 } else if (k == "length") {
568 int const vv = atoi (v.c_str ());
572 } else if (k == "dcp_intrinsic_duration") {
573 int const vv = atoi (v.c_str ());
575 _dcp_intrinsic_duration = vv;
577 } else if (k == "content_digest") {
579 } else if (k == "content_audio_stream" || (!version && k == "audio_stream")) {
580 _content_audio_streams.push_back (audio_stream_factory (v, version));
581 } else if (k == "external_audio_stream") {
582 _external_audio_stream = audio_stream_factory (v, version);
583 } else if (k == "subtitle_stream") {
584 _subtitle_streams.push_back (subtitle_stream_factory (v, version));
585 } else if (k == "frames_per_second") {
586 _frames_per_second = atof (v.c_str ());
591 if (audio_sample_rate) {
592 /* version < 1 didn't specify sample rate in the audio streams, so fill it in here */
593 for (vector<shared_ptr<AudioStream> >::iterator i = _content_audio_streams.begin(); i != _content_audio_streams.end(); ++i) {
594 (*i)->set_sample_rate (audio_sample_rate.get());
598 /* also the selected stream was specified as an index */
599 if (audio_stream_index && audio_stream_index.get() >= 0 && audio_stream_index.get() < (int) _content_audio_streams.size()) {
600 _content_audio_stream = _content_audio_streams[audio_stream_index.get()];
603 /* similarly the subtitle */
604 if (subtitle_stream_index && subtitle_stream_index.get() >= 0 && subtitle_stream_index.get() < (int) _subtitle_streams.size()) {
605 _subtitle_stream = _subtitle_streams[subtitle_stream_index.get()];
613 Film::cropped_size (libdcp::Size s) const
615 boost::mutex::scoped_lock lm (_state_mutex);
616 s.width -= _crop.left + _crop.right;
617 s.height -= _crop.top + _crop.bottom;
621 /** Given a directory name, return its full path within the Film's directory.
622 * The directory (and its parents) will be created if they do not exist.
625 Film::dir (string d) const
627 boost::mutex::scoped_lock lm (_directory_mutex);
628 boost::filesystem::path p;
631 boost::filesystem::create_directories (p);
635 /** Given a file or directory name, return its full path within the Film's directory.
636 * _directory_mutex must not be locked on entry.
639 Film::file (string f) const
641 boost::mutex::scoped_lock lm (_directory_mutex);
642 boost::filesystem::path p;
648 /** @return full path of the content (actual video) file
652 Film::content_path () const
654 boost::mutex::scoped_lock lm (_state_mutex);
655 if (boost::filesystem::path(_content).has_root_directory ()) {
659 return file (_content);
663 Film::content_type () const
665 if (boost::filesystem::is_directory (_content)) {
666 /* Directory of images, we assume */
670 if (still_image_file (_content)) {
677 /** @return The sampling rate that we will resample the audio to */
679 Film::target_audio_sample_rate () const
681 if (!audio_stream()) {
685 /* Resample to a DCI-approved sample rate */
686 double t = dcp_audio_sample_rate (audio_stream()->sample_rate());
688 DCPFrameRate dfr (frames_per_second ());
690 /* Compensate if the DCP is being run at a different frame rate
691 to the source; that is, if the video is run such that it will
692 look different in the DCP compared to the source (slower or faster).
693 skip/repeat doesn't come into effect here.
696 if (dfr.change_speed) {
697 t *= _frames_per_second * dfr.factor() / dfr.frames_per_second;
704 Film::still_duration_in_frames () const
706 return still_duration() * frames_per_second();
709 /** @return a DCI-compliant name for a DCP of this film */
711 Film::dci_name () const
715 string fixed_name = to_upper_copy (name());
716 for (size_t i = 0; i < fixed_name.length(); ++i) {
717 if (fixed_name[i] == ' ') {
722 /* Spec is that the name part should be maximum 14 characters, as I understand it */
723 if (fixed_name.length() > 14) {
724 fixed_name = fixed_name.substr (0, 14);
727 d << fixed_name << "_";
729 if (dcp_content_type()) {
730 d << dcp_content_type()->dci_name() << "_";
734 d << format()->dci_name() << "_";
737 if (!audio_language().empty ()) {
738 d << audio_language();
739 if (!subtitle_language().empty() && with_subtitles()) {
740 d << "-" << subtitle_language();
748 if (!territory().empty ()) {
750 if (!rating().empty ()) {
751 d << "-" << rating();
756 switch (audio_channels()) {
773 if (!studio().empty ()) {
774 d << studio() << "_";
777 d << boost::gregorian::to_iso_string (_dci_date) << "_";
779 if (!facility().empty ()) {
780 d << facility() << "_";
783 if (!package_type().empty ()) {
790 /** @return name to give the DCP */
792 Film::dcp_name () const
794 if (use_dci_name()) {
803 Film::set_directory (string d)
805 boost::mutex::scoped_lock lm (_state_mutex);
811 Film::set_name (string n)
814 boost::mutex::scoped_lock lm (_state_mutex);
817 signal_changed (NAME);
821 Film::set_use_dci_name (bool u)
824 boost::mutex::scoped_lock lm (_state_mutex);
827 signal_changed (USE_DCI_NAME);
831 Film::set_content (string c)
833 string check = directory ();
835 #if BOOST_FILESYSTEM_VERSION == 3
836 boost::filesystem::path slash ("/");
837 string platform_slash = slash.make_preferred().string ();
839 #ifdef DVDOMATIC_WINDOWS
840 string platform_slash = "\\";
842 string platform_slash = "/";
846 if (!ends_with (check, platform_slash)) {
847 check += platform_slash;
850 if (boost::filesystem::path(c).has_root_directory () && starts_with (c, check)) {
851 c = c.substr (_directory.length() + 1);
857 boost::mutex::scoped_lock lm (_state_mutex);
862 old_content = _content;
866 /* Reset streams here in case the new content doesn't have one or the other */
867 _content_audio_stream = shared_ptr<AudioStream> ();
868 _subtitle_stream = shared_ptr<SubtitleStream> ();
870 /* Start off using content audio */
871 set_use_content_audio (true);
873 /* Create a temporary decoder so that we can get information
878 Decoders d = decoder_factory (shared_from_this(), DecodeOptions(), 0);
880 set_size (d.video->native_size ());
881 set_frames_per_second (d.video->frames_per_second ());
882 set_subtitle_streams (d.video->subtitle_streams ());
884 set_content_audio_streams (d.audio->audio_streams ());
887 /* Start off with the first audio and subtitle streams */
888 if (d.audio && !d.audio->audio_streams().empty()) {
889 set_content_audio_stream (d.audio->audio_streams().front());
892 if (!d.video->subtitle_streams().empty()) {
893 set_subtitle_stream (d.video->subtitle_streams().front());
897 boost::mutex::scoped_lock lm (_state_mutex);
901 signal_changed (CONTENT);
907 boost::mutex::scoped_lock lm (_state_mutex);
908 _content = old_content;
914 switch (content_type()) {
916 set_format (Format::from_id ("var-185"));
919 set_format (Format::from_id ("185"));
923 /* Still image DCPs must use external audio */
924 if (content_type() == STILL) {
925 set_use_content_audio (false);
930 Film::set_trust_content_header (bool t)
933 boost::mutex::scoped_lock lm (_state_mutex);
934 _trust_content_header = t;
937 signal_changed (TRUST_CONTENT_HEADER);
939 if (!_trust_content_header && !content().empty()) {
940 /* We just said that we don't trust the content's header */
946 Film::set_dcp_content_type (DCPContentType const * t)
949 boost::mutex::scoped_lock lm (_state_mutex);
950 _dcp_content_type = t;
952 signal_changed (DCP_CONTENT_TYPE);
956 Film::set_format (Format const * f)
959 boost::mutex::scoped_lock lm (_state_mutex);
962 signal_changed (FORMAT);
966 Film::set_crop (Crop c)
969 boost::mutex::scoped_lock lm (_state_mutex);
972 signal_changed (CROP);
976 Film::set_left_crop (int c)
979 boost::mutex::scoped_lock lm (_state_mutex);
981 if (_crop.left == c) {
987 signal_changed (CROP);
991 Film::set_right_crop (int c)
994 boost::mutex::scoped_lock lm (_state_mutex);
995 if (_crop.right == c) {
1001 signal_changed (CROP);
1005 Film::set_top_crop (int c)
1008 boost::mutex::scoped_lock lm (_state_mutex);
1009 if (_crop.top == c) {
1015 signal_changed (CROP);
1019 Film::set_bottom_crop (int c)
1022 boost::mutex::scoped_lock lm (_state_mutex);
1023 if (_crop.bottom == c) {
1029 signal_changed (CROP);
1033 Film::set_filters (vector<Filter const *> f)
1036 boost::mutex::scoped_lock lm (_state_mutex);
1039 signal_changed (FILTERS);
1043 Film::set_scaler (Scaler const * s)
1046 boost::mutex::scoped_lock lm (_state_mutex);
1049 signal_changed (SCALER);
1053 Film::set_trim_start (int t)
1056 boost::mutex::scoped_lock lm (_state_mutex);
1059 signal_changed (TRIM_START);
1063 Film::set_trim_end (int t)
1066 boost::mutex::scoped_lock lm (_state_mutex);
1069 signal_changed (TRIM_END);
1073 Film::set_dcp_ab (bool a)
1076 boost::mutex::scoped_lock lm (_state_mutex);
1079 signal_changed (DCP_AB);
1083 Film::set_content_audio_stream (shared_ptr<AudioStream> s)
1086 boost::mutex::scoped_lock lm (_state_mutex);
1087 _content_audio_stream = s;
1089 signal_changed (CONTENT_AUDIO_STREAM);
1093 Film::set_external_audio (vector<string> a)
1096 boost::mutex::scoped_lock lm (_state_mutex);
1097 _external_audio = a;
1100 shared_ptr<ExternalAudioDecoder> decoder (new ExternalAudioDecoder (shared_from_this(), DecodeOptions(), 0));
1101 if (decoder->audio_stream()) {
1102 _external_audio_stream = decoder->audio_stream ();
1105 signal_changed (EXTERNAL_AUDIO);
1109 Film::set_use_content_audio (bool e)
1112 boost::mutex::scoped_lock lm (_state_mutex);
1113 _use_content_audio = e;
1116 signal_changed (USE_CONTENT_AUDIO);
1120 Film::set_audio_gain (float g)
1123 boost::mutex::scoped_lock lm (_state_mutex);
1126 signal_changed (AUDIO_GAIN);
1130 Film::set_audio_delay (int d)
1133 boost::mutex::scoped_lock lm (_state_mutex);
1136 signal_changed (AUDIO_DELAY);
1140 Film::set_still_duration (int d)
1143 boost::mutex::scoped_lock lm (_state_mutex);
1144 _still_duration = d;
1146 signal_changed (STILL_DURATION);
1150 Film::set_subtitle_stream (shared_ptr<SubtitleStream> s)
1153 boost::mutex::scoped_lock lm (_state_mutex);
1154 _subtitle_stream = s;
1156 signal_changed (SUBTITLE_STREAM);
1160 Film::set_with_subtitles (bool w)
1163 boost::mutex::scoped_lock lm (_state_mutex);
1164 _with_subtitles = w;
1166 signal_changed (WITH_SUBTITLES);
1170 Film::set_subtitle_offset (int o)
1173 boost::mutex::scoped_lock lm (_state_mutex);
1174 _subtitle_offset = o;
1176 signal_changed (SUBTITLE_OFFSET);
1180 Film::set_subtitle_scale (float s)
1183 boost::mutex::scoped_lock lm (_state_mutex);
1184 _subtitle_scale = s;
1186 signal_changed (SUBTITLE_SCALE);
1190 Film::set_colour_lut (int i)
1193 boost::mutex::scoped_lock lm (_state_mutex);
1196 signal_changed (COLOUR_LUT);
1200 Film::set_j2k_bandwidth (int b)
1203 boost::mutex::scoped_lock lm (_state_mutex);
1206 signal_changed (J2K_BANDWIDTH);
1210 Film::set_audio_language (string l)
1213 boost::mutex::scoped_lock lm (_state_mutex);
1214 _audio_language = l;
1216 signal_changed (DCI_METADATA);
1220 Film::set_subtitle_language (string l)
1223 boost::mutex::scoped_lock lm (_state_mutex);
1224 _subtitle_language = l;
1226 signal_changed (DCI_METADATA);
1230 Film::set_territory (string t)
1233 boost::mutex::scoped_lock lm (_state_mutex);
1236 signal_changed (DCI_METADATA);
1240 Film::set_rating (string r)
1243 boost::mutex::scoped_lock lm (_state_mutex);
1246 signal_changed (DCI_METADATA);
1250 Film::set_studio (string s)
1253 boost::mutex::scoped_lock lm (_state_mutex);
1256 signal_changed (DCI_METADATA);
1260 Film::set_facility (string f)
1263 boost::mutex::scoped_lock lm (_state_mutex);
1266 signal_changed (DCI_METADATA);
1270 Film::set_package_type (string p)
1273 boost::mutex::scoped_lock lm (_state_mutex);
1276 signal_changed (DCI_METADATA);
1280 Film::set_size (libdcp::Size s)
1283 boost::mutex::scoped_lock lm (_state_mutex);
1286 signal_changed (SIZE);
1290 Film::set_length (SourceFrame l)
1293 boost::mutex::scoped_lock lm (_state_mutex);
1296 signal_changed (LENGTH);
1300 Film::unset_length ()
1303 boost::mutex::scoped_lock lm (_state_mutex);
1304 _length = boost::none;
1306 signal_changed (LENGTH);
1310 Film::set_dcp_intrinsic_duration (int d)
1313 boost::mutex::scoped_lock lm (_state_mutex);
1314 _dcp_intrinsic_duration = d;
1316 signal_changed (DCP_INTRINSIC_DURATION);
1320 Film::set_content_digest (string d)
1323 boost::mutex::scoped_lock lm (_state_mutex);
1324 _content_digest = d;
1330 Film::set_content_audio_streams (vector<shared_ptr<AudioStream> > s)
1333 boost::mutex::scoped_lock lm (_state_mutex);
1334 _content_audio_streams = s;
1336 signal_changed (CONTENT_AUDIO_STREAMS);
1340 Film::set_subtitle_streams (vector<shared_ptr<SubtitleStream> > s)
1343 boost::mutex::scoped_lock lm (_state_mutex);
1344 _subtitle_streams = s;
1346 signal_changed (SUBTITLE_STREAMS);
1350 Film::set_frames_per_second (float f)
1353 boost::mutex::scoped_lock lm (_state_mutex);
1354 _frames_per_second = f;
1356 signal_changed (FRAMES_PER_SECOND);
1360 Film::signal_changed (Property p)
1363 boost::mutex::scoped_lock lm (_state_mutex);
1368 ui_signaller->emit (boost::bind (boost::ref (Changed), p));
1373 Film::audio_channels () const
1375 shared_ptr<AudioStream> s = audio_stream ();
1380 return s->channels ();
1384 Film::set_dci_date_today ()
1386 _dci_date = boost::gregorian::day_clock::local_day ();
1389 boost::shared_ptr<AudioStream>
1390 Film::audio_stream () const
1392 if (use_content_audio()) {
1393 return _content_audio_stream;
1396 return _external_audio_stream;
1400 Film::hash_path (int f) const
1402 boost::filesystem::path p;
1407 s << setfill('0') << f << ".md5";
1414 Film::j2c_path (int f, bool t) const
1416 boost::filesystem::path p;
1418 p /= video_state_identifier ();
1422 s << setfill('0') << f << ".j2c";