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"
54 #include "analyse_audio_job.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;
75 int const Film::state_version = 3;
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 , _dci_metadata (Config::instance()->default_dci_metadata ())
104 , _frames_per_second (0)
107 set_dci_date_today ();
109 /* Make state.directory a complete path without ..s (where possible)
110 (Code swiped from Adam Bowen on stackoverflow)
113 boost::filesystem::path p (boost::filesystem::system_complete (d));
114 boost::filesystem::path result;
115 for (boost::filesystem::path::iterator i = p.begin(); i != p.end(); ++i) {
117 if (boost::filesystem::is_symlink (result) || result.filename() == "..") {
120 result = result.parent_path ();
122 } else if (*i != ".") {
127 set_directory (result.string ());
129 if (!boost::filesystem::exists (directory())) {
131 throw OpenFileError (directory());
133 boost::filesystem::create_directory (directory());
137 _external_audio_stream = ExternalAudioStream::create ();
143 _log = new FileLog (file ("log"));
146 Film::Film (Film const & o)
147 : boost::enable_shared_from_this<Film> (o)
149 , _directory (o._directory)
151 , _use_dci_name (o._use_dci_name)
152 , _content (o._content)
153 , _trust_content_header (o._trust_content_header)
154 , _dcp_content_type (o._dcp_content_type)
155 , _format (o._format)
157 , _filters (o._filters)
158 , _scaler (o._scaler)
159 , _trim_start (o._trim_start)
160 , _trim_end (o._trim_end)
161 , _dcp_ab (o._dcp_ab)
162 , _content_audio_stream (o._content_audio_stream)
163 , _external_audio (o._external_audio)
164 , _use_content_audio (o._use_content_audio)
165 , _audio_gain (o._audio_gain)
166 , _audio_delay (o._audio_delay)
167 , _still_duration (o._still_duration)
168 , _subtitle_stream (o._subtitle_stream)
169 , _with_subtitles (o._with_subtitles)
170 , _subtitle_offset (o._subtitle_offset)
171 , _subtitle_scale (o._subtitle_scale)
172 , _colour_lut (o._colour_lut)
173 , _j2k_bandwidth (o._j2k_bandwidth)
174 , _dci_metadata (o._dci_metadata)
175 , _dci_date (o._dci_date)
177 , _length (o._length)
178 , _dcp_intrinsic_duration (o._dcp_intrinsic_duration)
179 , _content_digest (o._content_digest)
180 , _content_audio_streams (o._content_audio_streams)
181 , _external_audio_stream (o._external_audio_stream)
182 , _subtitle_streams (o._subtitle_streams)
183 , _frames_per_second (o._frames_per_second)
195 Film::video_state_identifier () const
199 pair<string, string> f = Filter::ffmpeg_strings (filters());
203 << "_" << content_digest()
204 << "_" << crop().left << "_" << crop().right << "_" << crop().top << "_" << crop().bottom
205 << "_" << f.first << "_" << f.second
206 << "_" << scaler()->id()
207 << "_" << j2k_bandwidth()
208 << "_" << boost::lexical_cast<int> (colour_lut());
211 pair<string, string> fa = Filter::ffmpeg_strings (Config::instance()->reference_filters());
212 s << "ab_" << Config::instance()->reference_scaler()->id() << "_" << fa.first << "_" << fa.second;
218 /** @return The path to the directory to write video frame info files to */
220 Film::info_dir () const
222 boost::filesystem::path p;
224 p /= video_state_identifier ();
225 return dir (p.string());
229 Film::video_mxf_dir () const
231 boost::filesystem::path p;
232 return dir ("video");
236 Film::video_mxf_filename () const
238 return video_state_identifier() + ".mxf";
242 Film::audio_analysis_path () const
244 boost::filesystem::path p;
246 p /= content_digest();
247 return file (p.string ());
250 /** Add suitable Jobs to the JobManager to create a DCP for this Film */
254 set_dci_date_today ();
256 if (dcp_name().find ("/") != string::npos) {
257 throw BadSettingError ("name", "cannot contain slashes");
260 log()->log (String::compose ("DVD-o-matic %1 git %2 using %3", dvdomatic_version, dvdomatic_git_commit, dependency_version_summary()));
264 gethostname (buffer, sizeof (buffer));
265 log()->log (String::compose ("Starting to make DCP on %1", buffer));
268 log()->log (String::compose ("Content is %1; type %2", content_path(), (content_type() == STILL ? "still" : "video")));
270 log()->log (String::compose ("Content length %1", length().get()));
272 log()->log (String::compose ("Content digest %1", content_digest()));
273 log()->log (String::compose ("%1 threads", Config::instance()->num_local_encoding_threads()));
274 log()->log (String::compose ("J2K bandwidth %1", j2k_bandwidth()));
275 #ifdef DVDOMATIC_DEBUG
276 log()->log ("DVD-o-matic built in debug mode.");
278 log()->log ("DVD-o-matic built in optimised mode.");
281 log()->log ("libdcp built in debug mode.");
283 log()->log ("libdcp built in optimised mode.");
285 pair<string, int> const c = cpu_info ();
286 log()->log (String::compose ("CPU: %1, %2 processors", c.first, c.second));
289 throw MissingSettingError ("format");
292 if (content().empty ()) {
293 throw MissingSettingError ("content");
296 if (dcp_content_type() == 0) {
297 throw MissingSettingError ("content type");
300 if (name().empty()) {
301 throw MissingSettingError ("name");
305 od.decode_subtitles = with_subtitles ();
310 r = JobManager::instance()->add (shared_ptr<Job> (new ABTranscodeJob (shared_from_this(), od)));
312 r = JobManager::instance()->add (shared_ptr<Job> (new TranscodeJob (shared_from_this(), od)));
316 /** Start a job to analyse the audio of our content file */
318 Film::analyse_audio ()
320 if (_analyse_audio_job) {
324 _analyse_audio_job.reset (new AnalyseAudioJob (shared_from_this()));
325 _analyse_audio_job->Finished.connect (bind (&Film::analyse_audio_finished, this));
326 JobManager::instance()->add (_analyse_audio_job);
329 /** Start a job to examine our content file */
331 Film::examine_content ()
333 if (_examine_content_job) {
337 _examine_content_job.reset (new ExamineContentJob (shared_from_this()));
338 _examine_content_job->Finished.connect (bind (&Film::examine_content_finished, this));
339 JobManager::instance()->add (_examine_content_job);
343 Film::analyse_audio_finished ()
345 _analyse_audio_job.reset ();
349 Film::examine_content_finished ()
351 _examine_content_job.reset ();
354 /** Start a job to send our DCP to the configured TMS */
356 Film::send_dcp_to_tms ()
358 shared_ptr<Job> j (new SCPDCPJob (shared_from_this()));
359 JobManager::instance()->add (j);
362 /** Count the number of frames that have been encoded for this film.
363 * @return frame count.
366 Film::encoded_frames () const
373 for (boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (info_dir ()); i != boost::filesystem::directory_iterator(); ++i) {
375 boost::this_thread::interruption_point ();
381 /** Write state to our `metadata' file */
383 Film::write_metadata () const
385 boost::mutex::scoped_lock lm (_state_mutex);
387 boost::filesystem::create_directories (directory());
389 string const m = file ("metadata");
390 ofstream f (m.c_str ());
392 throw CreateFileError (m);
395 f << "version " << state_version << "\n";
398 f << "name " << _name << "\n";
399 f << "use_dci_name " << _use_dci_name << "\n";
400 f << "content " << _content << "\n";
401 f << "trust_content_header " << (_trust_content_header ? "1" : "0") << "\n";
402 if (_dcp_content_type) {
403 f << "dcp_content_type " << _dcp_content_type->dci_name () << "\n";
406 f << "format " << _format->as_metadata () << "\n";
408 f << "left_crop " << _crop.left << "\n";
409 f << "right_crop " << _crop.right << "\n";
410 f << "top_crop " << _crop.top << "\n";
411 f << "bottom_crop " << _crop.bottom << "\n";
412 for (vector<Filter const *>::const_iterator i = _filters.begin(); i != _filters.end(); ++i) {
413 f << "filter " << (*i)->id () << "\n";
415 f << "scaler " << _scaler->id () << "\n";
416 f << "trim_start " << _trim_start << "\n";
417 f << "trim_end " << _trim_end << "\n";
418 f << "dcp_ab " << (_dcp_ab ? "1" : "0") << "\n";
419 if (_content_audio_stream) {
420 f << "selected_content_audio_stream " << _content_audio_stream->to_string() << "\n";
422 for (vector<string>::const_iterator i = _external_audio.begin(); i != _external_audio.end(); ++i) {
423 f << "external_audio " << *i << "\n";
425 f << "use_content_audio " << (_use_content_audio ? "1" : "0") << "\n";
426 f << "audio_gain " << _audio_gain << "\n";
427 f << "audio_delay " << _audio_delay << "\n";
428 f << "still_duration " << _still_duration << "\n";
429 if (_subtitle_stream) {
430 f << "selected_subtitle_stream " << _subtitle_stream->to_string() << "\n";
432 f << "with_subtitles " << _with_subtitles << "\n";
433 f << "subtitle_offset " << _subtitle_offset << "\n";
434 f << "subtitle_scale " << _subtitle_scale << "\n";
435 f << "colour_lut " << _colour_lut << "\n";
436 f << "j2k_bandwidth " << _j2k_bandwidth << "\n";
437 _dci_metadata.write (f);
438 f << "dci_date " << boost::gregorian::to_iso_string (_dci_date) << "\n";
439 f << "width " << _size.width << "\n";
440 f << "height " << _size.height << "\n";
441 f << "length " << _length.get_value_or(0) << "\n";
442 f << "dcp_intrinsic_duration " << _dcp_intrinsic_duration.get_value_or(0) << "\n";
443 f << "content_digest " << _content_digest << "\n";
445 for (vector<shared_ptr<AudioStream> >::const_iterator i = _content_audio_streams.begin(); i != _content_audio_streams.end(); ++i) {
446 f << "content_audio_stream " << (*i)->to_string () << "\n";
449 f << "external_audio_stream " << _external_audio_stream->to_string() << "\n";
451 for (vector<shared_ptr<SubtitleStream> >::const_iterator i = _subtitle_streams.begin(); i != _subtitle_streams.end(); ++i) {
452 f << "subtitle_stream " << (*i)->to_string () << "\n";
455 f << "frames_per_second " << _frames_per_second << "\n";
460 /** Read state from our metadata file */
462 Film::read_metadata ()
464 boost::mutex::scoped_lock lm (_state_mutex);
466 _external_audio.clear ();
467 _content_audio_streams.clear ();
468 _subtitle_streams.clear ();
470 boost::optional<int> version;
472 /* Backward compatibility things */
473 boost::optional<int> audio_sample_rate;
474 boost::optional<int> audio_stream_index;
475 boost::optional<int> subtitle_stream_index;
477 ifstream f (file ("metadata").c_str());
479 throw OpenFileError (file ("metadata"));
482 multimap<string, string> kv = read_key_value (f);
484 /* We need version before anything else */
485 multimap<string, string>::iterator v = kv.find ("version");
486 if (v != kv.end ()) {
487 version = atoi (v->second.c_str());
490 for (multimap<string, string>::const_iterator i = kv.begin(); i != kv.end(); ++i) {
491 string const k = i->first;
492 string const v = i->second;
494 if (k == "audio_sample_rate") {
495 audio_sample_rate = atoi (v.c_str());
498 /* User-specified stuff */
501 } else if (k == "use_dci_name") {
502 _use_dci_name = (v == "1");
503 } else if (k == "content") {
505 } else if (k == "trust_content_header") {
506 _trust_content_header = (v == "1");
507 } else if (k == "dcp_content_type") {
509 _dcp_content_type = DCPContentType::from_pretty_name (v);
511 _dcp_content_type = DCPContentType::from_dci_name (v);
513 } else if (k == "format") {
514 _format = Format::from_metadata (v);
515 } else if (k == "left_crop") {
516 _crop.left = atoi (v.c_str ());
517 } else if (k == "right_crop") {
518 _crop.right = atoi (v.c_str ());
519 } else if (k == "top_crop") {
520 _crop.top = atoi (v.c_str ());
521 } else if (k == "bottom_crop") {
522 _crop.bottom = atoi (v.c_str ());
523 } else if (k == "filter") {
524 _filters.push_back (Filter::from_id (v));
525 } else if (k == "scaler") {
526 _scaler = Scaler::from_id (v);
527 } else if ( ((!version || version < 2) && k == "dcp_trim_start") || k == "trim_start") {
528 _trim_start = atoi (v.c_str ());
529 } else if ( ((!version || version < 2) && k == "dcp_trim_end") || k == "trim_end") {
530 _trim_end = atoi (v.c_str ());
531 } else if (k == "dcp_ab") {
532 _dcp_ab = (v == "1");
533 } else if (k == "selected_content_audio_stream" || (!version && k == "selected_audio_stream")) {
535 audio_stream_index = atoi (v.c_str ());
537 _content_audio_stream = audio_stream_factory (v, version);
539 } else if (k == "external_audio") {
540 _external_audio.push_back (v);
541 } else if (k == "use_content_audio") {
542 _use_content_audio = (v == "1");
543 } else if (k == "audio_gain") {
544 _audio_gain = atof (v.c_str ());
545 } else if (k == "audio_delay") {
546 _audio_delay = atoi (v.c_str ());
547 } else if (k == "still_duration") {
548 _still_duration = atoi (v.c_str ());
549 } else if (k == "selected_subtitle_stream") {
551 subtitle_stream_index = atoi (v.c_str ());
553 _subtitle_stream = subtitle_stream_factory (v, version);
555 } else if (k == "with_subtitles") {
556 _with_subtitles = (v == "1");
557 } else if (k == "subtitle_offset") {
558 _subtitle_offset = atoi (v.c_str ());
559 } else if (k == "subtitle_scale") {
560 _subtitle_scale = atof (v.c_str ());
561 } else if (k == "colour_lut") {
562 _colour_lut = atoi (v.c_str ());
563 } else if (k == "j2k_bandwidth") {
564 _j2k_bandwidth = atoi (v.c_str ());
565 } else if (k == "dci_date") {
566 _dci_date = boost::gregorian::from_undelimited_string (v);
569 _dci_metadata.read (k, v);
573 _size.width = atoi (v.c_str ());
574 } else if (k == "height") {
575 _size.height = atoi (v.c_str ());
576 } else if (k == "length") {
577 int const vv = atoi (v.c_str ());
581 } else if (k == "dcp_intrinsic_duration") {
582 int const vv = atoi (v.c_str ());
584 _dcp_intrinsic_duration = vv;
586 } else if (k == "content_digest") {
588 } else if (k == "content_audio_stream" || (!version && k == "audio_stream")) {
589 _content_audio_streams.push_back (audio_stream_factory (v, version));
590 } else if (k == "external_audio_stream") {
591 _external_audio_stream = audio_stream_factory (v, version);
592 } else if (k == "subtitle_stream") {
593 _subtitle_streams.push_back (subtitle_stream_factory (v, version));
594 } else if (k == "frames_per_second") {
595 _frames_per_second = atof (v.c_str ());
600 if (audio_sample_rate) {
601 /* version < 1 didn't specify sample rate in the audio streams, so fill it in here */
602 for (vector<shared_ptr<AudioStream> >::iterator i = _content_audio_streams.begin(); i != _content_audio_streams.end(); ++i) {
603 (*i)->set_sample_rate (audio_sample_rate.get());
607 /* also the selected stream was specified as an index */
608 if (audio_stream_index && audio_stream_index.get() >= 0 && audio_stream_index.get() < (int) _content_audio_streams.size()) {
609 _content_audio_stream = _content_audio_streams[audio_stream_index.get()];
612 /* similarly the subtitle */
613 if (subtitle_stream_index && subtitle_stream_index.get() >= 0 && subtitle_stream_index.get() < (int) _subtitle_streams.size()) {
614 _subtitle_stream = _subtitle_streams[subtitle_stream_index.get()];
622 Film::cropped_size (libdcp::Size s) const
624 boost::mutex::scoped_lock lm (_state_mutex);
625 s.width -= _crop.left + _crop.right;
626 s.height -= _crop.top + _crop.bottom;
630 /** Given a directory name, return its full path within the Film's directory.
631 * The directory (and its parents) will be created if they do not exist.
634 Film::dir (string d) const
636 boost::mutex::scoped_lock lm (_directory_mutex);
638 boost::filesystem::path p;
642 boost::filesystem::create_directories (p);
647 /** Given a file or directory name, return its full path within the Film's directory.
648 * _directory_mutex must not be locked on entry.
649 * Any required parent directories will be created.
652 Film::file (string f) const
654 boost::mutex::scoped_lock lm (_directory_mutex);
656 boost::filesystem::path p;
660 boost::filesystem::create_directories (p.parent_path ());
665 /** @return full path of the content (actual video) file
669 Film::content_path () const
671 boost::mutex::scoped_lock lm (_state_mutex);
672 if (boost::filesystem::path(_content).has_root_directory ()) {
676 return file (_content);
680 Film::content_type () const
682 if (boost::filesystem::is_directory (_content)) {
683 /* Directory of images, we assume */
687 if (still_image_file (_content)) {
694 /** @return The sampling rate that we will resample the audio to */
696 Film::target_audio_sample_rate () const
698 if (!audio_stream()) {
702 /* Resample to a DCI-approved sample rate */
703 double t = dcp_audio_sample_rate (audio_stream()->sample_rate());
705 DCPFrameRate dfr (frames_per_second ());
707 /* Compensate if the DCP is being run at a different frame rate
708 to the source; that is, if the video is run such that it will
709 look different in the DCP compared to the source (slower or faster).
710 skip/repeat doesn't come into effect here.
713 if (dfr.change_speed) {
714 t *= _frames_per_second * dfr.factor() / dfr.frames_per_second;
721 Film::still_duration_in_frames () const
723 return still_duration() * frames_per_second();
726 /** @return a DCI-compliant name for a DCP of this film */
728 Film::dci_name (bool if_created_now) const
732 string fixed_name = to_upper_copy (name());
733 for (size_t i = 0; i < fixed_name.length(); ++i) {
734 if (fixed_name[i] == ' ') {
739 /* Spec is that the name part should be maximum 14 characters, as I understand it */
740 if (fixed_name.length() > 14) {
741 fixed_name = fixed_name.substr (0, 14);
744 d << fixed_name << "_";
746 if (dcp_content_type()) {
747 d << dcp_content_type()->dci_name() << "_";
751 d << format()->dci_name() << "_";
754 DCIMetadata const dm = dci_metadata ();
756 if (!dm.audio_language.empty ()) {
757 d << dm.audio_language;
758 if (!dm.subtitle_language.empty() && with_subtitles()) {
759 d << "-" << dm.subtitle_language;
767 if (!dm.territory.empty ()) {
769 if (!dm.rating.empty ()) {
770 d << "-" << dm.rating;
775 switch (audio_channels()) {
792 if (!dm.studio.empty ()) {
793 d << dm.studio << "_";
796 if (if_created_now) {
797 d << boost::gregorian::to_iso_string (boost::gregorian::day_clock::local_day ()) << "_";
799 d << boost::gregorian::to_iso_string (_dci_date) << "_";
802 if (!dm.facility.empty ()) {
803 d << dm.facility << "_";
806 if (!dm.package_type.empty ()) {
807 d << dm.package_type;
813 /** @return name to give the DCP */
815 Film::dcp_name (bool if_created_now) const
817 if (use_dci_name()) {
818 return dci_name (if_created_now);
826 Film::set_directory (string d)
828 boost::mutex::scoped_lock lm (_state_mutex);
834 Film::set_name (string n)
837 boost::mutex::scoped_lock lm (_state_mutex);
840 signal_changed (NAME);
844 Film::set_use_dci_name (bool u)
847 boost::mutex::scoped_lock lm (_state_mutex);
850 signal_changed (USE_DCI_NAME);
854 Film::set_content (string c)
856 string check = directory ();
858 boost::filesystem::path slash ("/");
859 string platform_slash = slash.make_preferred().string ();
861 if (!ends_with (check, platform_slash)) {
862 check += platform_slash;
865 if (boost::filesystem::path(c).has_root_directory () && starts_with (c, check)) {
866 c = c.substr (_directory.length() + 1);
872 boost::mutex::scoped_lock lm (_state_mutex);
877 old_content = _content;
881 /* Reset streams here in case the new content doesn't have one or the other */
882 _content_audio_stream = shared_ptr<AudioStream> ();
883 _subtitle_stream = shared_ptr<SubtitleStream> ();
885 /* Start off using content audio */
886 set_use_content_audio (true);
888 /* Create a temporary decoder so that we can get information
893 Decoders d = decoder_factory (shared_from_this(), DecodeOptions());
895 set_size (d.video->native_size ());
896 set_frames_per_second (d.video->frames_per_second ());
897 set_subtitle_streams (d.video->subtitle_streams ());
899 set_content_audio_streams (d.audio->audio_streams ());
903 boost::mutex::scoped_lock lm (_state_mutex);
907 signal_changed (CONTENT);
909 /* Start off with the first audio and subtitle streams */
910 if (d.audio && !d.audio->audio_streams().empty()) {
911 set_content_audio_stream (d.audio->audio_streams().front());
914 if (!d.video->subtitle_streams().empty()) {
915 set_subtitle_stream (d.video->subtitle_streams().front());
922 boost::mutex::scoped_lock lm (_state_mutex);
923 _content = old_content;
929 switch (content_type()) {
931 set_format (Format::from_id ("var-185"));
934 set_format (Format::from_id ("185"));
938 /* Still image DCPs must use external audio */
939 if (content_type() == STILL) {
940 set_use_content_audio (false);
945 Film::set_trust_content_header (bool t)
948 boost::mutex::scoped_lock lm (_state_mutex);
949 _trust_content_header = t;
952 signal_changed (TRUST_CONTENT_HEADER);
954 if (!_trust_content_header && !content().empty()) {
955 /* We just said that we don't trust the content's header */
961 Film::set_dcp_content_type (DCPContentType const * t)
964 boost::mutex::scoped_lock lm (_state_mutex);
965 _dcp_content_type = t;
967 signal_changed (DCP_CONTENT_TYPE);
971 Film::set_format (Format const * f)
974 boost::mutex::scoped_lock lm (_state_mutex);
977 signal_changed (FORMAT);
981 Film::set_crop (Crop c)
984 boost::mutex::scoped_lock lm (_state_mutex);
987 signal_changed (CROP);
991 Film::set_left_crop (int c)
994 boost::mutex::scoped_lock lm (_state_mutex);
996 if (_crop.left == c) {
1002 signal_changed (CROP);
1006 Film::set_right_crop (int c)
1009 boost::mutex::scoped_lock lm (_state_mutex);
1010 if (_crop.right == c) {
1016 signal_changed (CROP);
1020 Film::set_top_crop (int c)
1023 boost::mutex::scoped_lock lm (_state_mutex);
1024 if (_crop.top == c) {
1030 signal_changed (CROP);
1034 Film::set_bottom_crop (int c)
1037 boost::mutex::scoped_lock lm (_state_mutex);
1038 if (_crop.bottom == c) {
1044 signal_changed (CROP);
1048 Film::set_filters (vector<Filter const *> f)
1051 boost::mutex::scoped_lock lm (_state_mutex);
1054 signal_changed (FILTERS);
1058 Film::set_scaler (Scaler const * s)
1061 boost::mutex::scoped_lock lm (_state_mutex);
1064 signal_changed (SCALER);
1068 Film::set_trim_start (int t)
1071 boost::mutex::scoped_lock lm (_state_mutex);
1074 signal_changed (TRIM_START);
1078 Film::set_trim_end (int t)
1081 boost::mutex::scoped_lock lm (_state_mutex);
1084 signal_changed (TRIM_END);
1088 Film::set_dcp_ab (bool a)
1091 boost::mutex::scoped_lock lm (_state_mutex);
1094 signal_changed (DCP_AB);
1098 Film::set_content_audio_stream (shared_ptr<AudioStream> s)
1101 boost::mutex::scoped_lock lm (_state_mutex);
1102 _content_audio_stream = s;
1104 signal_changed (CONTENT_AUDIO_STREAM);
1108 Film::set_external_audio (vector<string> a)
1111 boost::mutex::scoped_lock lm (_state_mutex);
1112 _external_audio = a;
1115 shared_ptr<ExternalAudioDecoder> decoder (new ExternalAudioDecoder (shared_from_this(), DecodeOptions()));
1116 if (decoder->audio_stream()) {
1117 _external_audio_stream = decoder->audio_stream ();
1120 signal_changed (EXTERNAL_AUDIO);
1124 Film::set_use_content_audio (bool e)
1127 boost::mutex::scoped_lock lm (_state_mutex);
1128 _use_content_audio = e;
1131 signal_changed (USE_CONTENT_AUDIO);
1135 Film::set_audio_gain (float g)
1138 boost::mutex::scoped_lock lm (_state_mutex);
1141 signal_changed (AUDIO_GAIN);
1145 Film::set_audio_delay (int d)
1148 boost::mutex::scoped_lock lm (_state_mutex);
1151 signal_changed (AUDIO_DELAY);
1155 Film::set_still_duration (int d)
1158 boost::mutex::scoped_lock lm (_state_mutex);
1159 _still_duration = d;
1161 signal_changed (STILL_DURATION);
1165 Film::set_subtitle_stream (shared_ptr<SubtitleStream> s)
1168 boost::mutex::scoped_lock lm (_state_mutex);
1169 _subtitle_stream = s;
1171 signal_changed (SUBTITLE_STREAM);
1175 Film::set_with_subtitles (bool w)
1178 boost::mutex::scoped_lock lm (_state_mutex);
1179 _with_subtitles = w;
1181 signal_changed (WITH_SUBTITLES);
1185 Film::set_subtitle_offset (int o)
1188 boost::mutex::scoped_lock lm (_state_mutex);
1189 _subtitle_offset = o;
1191 signal_changed (SUBTITLE_OFFSET);
1195 Film::set_subtitle_scale (float s)
1198 boost::mutex::scoped_lock lm (_state_mutex);
1199 _subtitle_scale = s;
1201 signal_changed (SUBTITLE_SCALE);
1205 Film::set_colour_lut (int i)
1208 boost::mutex::scoped_lock lm (_state_mutex);
1211 signal_changed (COLOUR_LUT);
1215 Film::set_j2k_bandwidth (int b)
1218 boost::mutex::scoped_lock lm (_state_mutex);
1221 signal_changed (J2K_BANDWIDTH);
1225 Film::set_dci_metadata (DCIMetadata m)
1228 boost::mutex::scoped_lock lm (_state_mutex);
1231 signal_changed (DCI_METADATA);
1235 Film::set_size (libdcp::Size s)
1238 boost::mutex::scoped_lock lm (_state_mutex);
1241 signal_changed (SIZE);
1245 Film::set_length (SourceFrame l)
1248 boost::mutex::scoped_lock lm (_state_mutex);
1251 signal_changed (LENGTH);
1255 Film::unset_length ()
1258 boost::mutex::scoped_lock lm (_state_mutex);
1259 _length = boost::none;
1261 signal_changed (LENGTH);
1265 Film::set_dcp_intrinsic_duration (int d)
1268 boost::mutex::scoped_lock lm (_state_mutex);
1269 _dcp_intrinsic_duration = d;
1271 signal_changed (DCP_INTRINSIC_DURATION);
1275 Film::set_content_digest (string d)
1278 boost::mutex::scoped_lock lm (_state_mutex);
1279 _content_digest = d;
1285 Film::set_content_audio_streams (vector<shared_ptr<AudioStream> > s)
1288 boost::mutex::scoped_lock lm (_state_mutex);
1289 _content_audio_streams = s;
1291 signal_changed (CONTENT_AUDIO_STREAMS);
1295 Film::set_subtitle_streams (vector<shared_ptr<SubtitleStream> > s)
1298 boost::mutex::scoped_lock lm (_state_mutex);
1299 _subtitle_streams = s;
1301 signal_changed (SUBTITLE_STREAMS);
1305 Film::set_frames_per_second (float f)
1308 boost::mutex::scoped_lock lm (_state_mutex);
1309 _frames_per_second = f;
1311 signal_changed (FRAMES_PER_SECOND);
1315 Film::signal_changed (Property p)
1318 boost::mutex::scoped_lock lm (_state_mutex);
1323 ui_signaller->emit (boost::bind (boost::ref (Changed), p));
1328 Film::audio_channels () const
1330 shared_ptr<AudioStream> s = audio_stream ();
1335 return s->channels ();
1339 Film::set_dci_date_today ()
1341 _dci_date = boost::gregorian::day_clock::local_day ();
1344 boost::shared_ptr<AudioStream>
1345 Film::audio_stream () const
1347 if (use_content_audio()) {
1348 return _content_audio_stream;
1351 return _external_audio_stream;
1355 Film::info_path (int f) const
1357 boost::filesystem::path p;
1362 s << setfill('0') << f << ".md5";
1366 /* info_dir() will already have added any initial bit of the path,
1367 so don't call file() on this.
1373 Film::j2c_path (int f, bool t) const
1375 boost::filesystem::path p;
1377 p /= video_state_identifier ();
1381 s << setfill('0') << f << ".j2c";
1388 return file (p.string ());
1391 /** Make an educated guess as to whether we have a complete DCP
1393 * @return true if we do.
1397 Film::have_dcp () const
1400 libdcp::DCP dcp (dir (dcp_name()));