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"
59 using std::stringstream;
70 using boost::shared_ptr;
71 using boost::lexical_cast;
72 using boost::to_upper_copy;
73 using boost::ends_with;
74 using boost::starts_with;
75 using boost::optional;
78 int const Film::state_version = 4;
80 /** Construct a Film object in a given directory, reading any metadata
81 * file that exists in that directory. An exception will be thrown if
82 * must_exist is true and the specified directory does not exist.
84 * @param d Film directory.
85 * @param must_exist true to throw an exception if does not exist.
88 Film::Film (string d, bool must_exist)
89 : _use_dci_name (true)
90 , _trust_content_header (true)
91 , _dcp_content_type (0)
93 , _scaler (Scaler::from_id ("bicubic"))
97 , _use_content_audio (true)
100 , _still_duration (10)
101 , _with_subtitles (false)
102 , _subtitle_offset (0)
103 , _subtitle_scale (1)
105 , _j2k_bandwidth (200000000)
106 , _dci_metadata (Config::instance()->default_dci_metadata ())
107 , _dcp_frame_rate (0)
108 , _source_frame_rate (0)
111 set_dci_date_today ();
113 /* Make state.directory a complete path without ..s (where possible)
114 (Code swiped from Adam Bowen on stackoverflow)
117 boost::filesystem::path p (boost::filesystem::system_complete (d));
118 boost::filesystem::path result;
119 for (boost::filesystem::path::iterator i = p.begin(); i != p.end(); ++i) {
121 if (boost::filesystem::is_symlink (result) || result.filename() == "..") {
124 result = result.parent_path ();
126 } else if (*i != ".") {
131 set_directory (result.string ());
133 if (!boost::filesystem::exists (directory())) {
135 throw OpenFileError (directory());
137 boost::filesystem::create_directory (directory());
141 _external_audio_stream = ExternalAudioStream::create ();
147 _log.reset (new FileLog (file ("log")));
150 Film::Film (Film const & o)
151 : boost::enable_shared_from_this<Film> (o)
152 /* note: the copied film shares the original's log */
154 , _directory (o._directory)
156 , _use_dci_name (o._use_dci_name)
157 , _content (o._content)
158 , _trust_content_header (o._trust_content_header)
159 , _dcp_content_type (o._dcp_content_type)
160 , _format (o._format)
162 , _filters (o._filters)
163 , _scaler (o._scaler)
164 , _trim_start (o._trim_start)
165 , _trim_end (o._trim_end)
166 , _dcp_ab (o._dcp_ab)
167 , _content_audio_stream (o._content_audio_stream)
168 , _external_audio (o._external_audio)
169 , _use_content_audio (o._use_content_audio)
170 , _audio_gain (o._audio_gain)
171 , _audio_delay (o._audio_delay)
172 , _still_duration (o._still_duration)
173 , _subtitle_stream (o._subtitle_stream)
174 , _with_subtitles (o._with_subtitles)
175 , _subtitle_offset (o._subtitle_offset)
176 , _subtitle_scale (o._subtitle_scale)
177 , _colour_lut (o._colour_lut)
178 , _j2k_bandwidth (o._j2k_bandwidth)
179 , _dci_metadata (o._dci_metadata)
180 , _dci_date (o._dci_date)
181 , _dcp_frame_rate (o._dcp_frame_rate)
183 , _length (o._length)
184 , _content_digest (o._content_digest)
185 , _content_audio_streams (o._content_audio_streams)
186 , _external_audio_stream (o._external_audio_stream)
187 , _subtitle_streams (o._subtitle_streams)
188 , _source_frame_rate (o._source_frame_rate)
200 Film::video_state_identifier () const
204 pair<string, string> f = Filter::ffmpeg_strings (filters());
208 << "_" << content_digest()
209 << "_" << crop().left << "_" << crop().right << "_" << crop().top << "_" << crop().bottom
210 << "_" << _dcp_frame_rate
211 << "_" << f.first << "_" << f.second
212 << "_" << scaler()->id()
213 << "_" << j2k_bandwidth()
214 << "_" << boost::lexical_cast<int> (colour_lut());
217 pair<string, string> fa = Filter::ffmpeg_strings (Config::instance()->reference_filters());
218 s << "ab_" << Config::instance()->reference_scaler()->id() << "_" << fa.first << "_" << fa.second;
224 /** @return The path to the directory to write video frame info files to */
226 Film::info_dir () const
228 boost::filesystem::path p;
230 p /= video_state_identifier ();
231 return dir (p.string());
235 Film::video_mxf_dir () const
237 boost::filesystem::path p;
238 return dir ("video");
242 Film::video_mxf_filename () const
244 return video_state_identifier() + ".mxf";
248 Film::audio_analysis_path () const
250 boost::filesystem::path p;
252 p /= content_digest();
253 return file (p.string ());
256 /** Add suitable Jobs to the JobManager to create a DCP for this Film */
260 set_dci_date_today ();
262 if (dcp_name().find ("/") != string::npos) {
263 throw BadSettingError (_("name"), _("cannot contain slashes"));
266 log()->log (String::compose ("DVD-o-matic %1 git %2 using %3", dvdomatic_version, dvdomatic_git_commit, dependency_version_summary()));
270 gethostname (buffer, sizeof (buffer));
271 log()->log (String::compose ("Starting to make DCP on %1", buffer));
274 log()->log (String::compose ("Content is %1; type %2", content_path(), (content_type() == STILL ? _("still") : _("video"))));
276 log()->log (String::compose ("Content length %1", length().get()));
278 log()->log (String::compose ("Content digest %1", content_digest()));
279 log()->log (String::compose ("Content at %1 fps, DCP at %2 fps", source_frame_rate(), dcp_frame_rate()));
280 log()->log (String::compose ("%1 threads", Config::instance()->num_local_encoding_threads()));
281 log()->log (String::compose ("J2K bandwidth %1", j2k_bandwidth()));
282 #ifdef DVDOMATIC_DEBUG
283 log()->log ("DVD-o-matic built in debug mode.");
285 log()->log ("DVD-o-matic built in optimised mode.");
288 log()->log ("libdcp built in debug mode.");
290 log()->log ("libdcp built in optimised mode.");
292 pair<string, int> const c = cpu_info ();
293 log()->log (String::compose ("CPU: %1, %2 processors", c.first, c.second));
296 throw MissingSettingError (_("format"));
299 if (content().empty ()) {
300 throw MissingSettingError (_("content"));
303 if (dcp_content_type() == 0) {
304 throw MissingSettingError (_("content type"));
307 if (name().empty()) {
308 throw MissingSettingError (_("name"));
312 od.decode_subtitles = with_subtitles ();
317 r = JobManager::instance()->add (shared_ptr<Job> (new ABTranscodeJob (shared_from_this(), od)));
319 r = JobManager::instance()->add (shared_ptr<Job> (new TranscodeJob (shared_from_this(), od)));
323 /** Start a job to analyse the audio of our content file */
325 Film::analyse_audio ()
327 if (_analyse_audio_job) {
331 _analyse_audio_job.reset (new AnalyseAudioJob (shared_from_this()));
332 _analyse_audio_job->Finished.connect (bind (&Film::analyse_audio_finished, this));
333 JobManager::instance()->add (_analyse_audio_job);
336 /** Start a job to examine our content file */
338 Film::examine_content ()
340 if (_examine_content_job) {
344 _examine_content_job.reset (new ExamineContentJob (shared_from_this()));
345 _examine_content_job->Finished.connect (bind (&Film::examine_content_finished, this));
346 JobManager::instance()->add (_examine_content_job);
350 Film::analyse_audio_finished ()
354 if (_analyse_audio_job->finished_ok ()) {
355 AudioAnalysisSucceeded ();
358 _analyse_audio_job.reset ();
362 Film::examine_content_finished ()
364 _examine_content_job.reset ();
367 /** Start a job to send our DCP to the configured TMS */
369 Film::send_dcp_to_tms ()
371 shared_ptr<Job> j (new SCPDCPJob (shared_from_this()));
372 JobManager::instance()->add (j);
375 /** Count the number of frames that have been encoded for this film.
376 * @return frame count.
379 Film::encoded_frames () const
386 for (boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (info_dir ()); i != boost::filesystem::directory_iterator(); ++i) {
388 boost::this_thread::interruption_point ();
394 /** Write state to our `metadata' file */
396 Film::write_metadata () const
398 boost::mutex::scoped_lock lm (_state_mutex);
400 boost::filesystem::create_directories (directory());
402 string const m = file ("metadata");
403 ofstream f (m.c_str ());
405 throw CreateFileError (m);
408 f << "version " << state_version << endl;
411 f << "name " << _name << endl;
412 f << "use_dci_name " << _use_dci_name << endl;
413 f << "content " << _content << endl;
414 f << "trust_content_header " << (_trust_content_header ? "1" : "0") << endl;
415 if (_dcp_content_type) {
416 f << "dcp_content_type " << _dcp_content_type->dci_name () << endl;
419 f << "format " << _format->as_metadata () << endl;
421 f << "left_crop " << _crop.left << endl;
422 f << "right_crop " << _crop.right << endl;
423 f << "top_crop " << _crop.top << endl;
424 f << "bottom_crop " << _crop.bottom << endl;
425 for (vector<Filter const *>::const_iterator i = _filters.begin(); i != _filters.end(); ++i) {
426 f << "filter " << (*i)->id () << endl;
428 f << "scaler " << _scaler->id () << endl;
429 f << "trim_start " << _trim_start << endl;
430 f << "trim_end " << _trim_end << endl;
431 f << "dcp_ab " << (_dcp_ab ? "1" : "0") << endl;
432 if (_content_audio_stream) {
433 f << "selected_content_audio_stream " << _content_audio_stream->to_string() << endl;
435 for (vector<string>::const_iterator i = _external_audio.begin(); i != _external_audio.end(); ++i) {
436 f << "external_audio " << *i << endl;
438 f << "use_content_audio " << (_use_content_audio ? "1" : "0") << endl;
439 f << "audio_gain " << _audio_gain << endl;
440 f << "audio_delay " << _audio_delay << endl;
441 f << "still_duration " << _still_duration << endl;
442 if (_subtitle_stream) {
443 f << "selected_subtitle_stream " << _subtitle_stream->to_string() << endl;
445 f << "with_subtitles " << _with_subtitles << endl;
446 f << "subtitle_offset " << _subtitle_offset << endl;
447 f << "subtitle_scale " << _subtitle_scale << endl;
448 f << "colour_lut " << _colour_lut << endl;
449 f << "j2k_bandwidth " << _j2k_bandwidth << endl;
450 _dci_metadata.write (f);
451 f << "dci_date " << boost::gregorian::to_iso_string (_dci_date) << endl;
452 f << "dcp_frame_rate " << _dcp_frame_rate << endl;
453 f << "width " << _size.width << endl;
454 f << "height " << _size.height << endl;
455 f << "length " << _length.get_value_or(0) << endl;
456 f << "content_digest " << _content_digest << endl;
458 for (vector<shared_ptr<AudioStream> >::const_iterator i = _content_audio_streams.begin(); i != _content_audio_streams.end(); ++i) {
459 f << "content_audio_stream " << (*i)->to_string () << endl;
462 f << "external_audio_stream " << _external_audio_stream->to_string() << endl;
464 for (vector<shared_ptr<SubtitleStream> >::const_iterator i = _subtitle_streams.begin(); i != _subtitle_streams.end(); ++i) {
465 f << "subtitle_stream " << (*i)->to_string () << endl;
468 f << "source_frame_rate " << _source_frame_rate << endl;
473 /** Read state from our metadata file */
475 Film::read_metadata ()
477 boost::mutex::scoped_lock lm (_state_mutex);
479 _external_audio.clear ();
480 _content_audio_streams.clear ();
481 _subtitle_streams.clear ();
483 boost::optional<int> version;
485 /* Backward compatibility things */
486 boost::optional<int> audio_sample_rate;
487 boost::optional<int> audio_stream_index;
488 boost::optional<int> subtitle_stream_index;
490 ifstream f (file ("metadata").c_str());
492 throw OpenFileError (file ("metadata"));
495 multimap<string, string> kv = read_key_value (f);
497 /* We need version before anything else */
498 multimap<string, string>::iterator v = kv.find ("version");
499 if (v != kv.end ()) {
500 version = atoi (v->second.c_str());
503 for (multimap<string, string>::const_iterator i = kv.begin(); i != kv.end(); ++i) {
504 string const k = i->first;
505 string const v = i->second;
507 if (k == "audio_sample_rate") {
508 audio_sample_rate = atoi (v.c_str());
511 /* User-specified stuff */
514 } else if (k == "use_dci_name") {
515 _use_dci_name = (v == "1");
516 } else if (k == "content") {
518 } else if (k == "trust_content_header") {
519 _trust_content_header = (v == "1");
520 } else if (k == "dcp_content_type") {
522 _dcp_content_type = DCPContentType::from_pretty_name (v);
524 _dcp_content_type = DCPContentType::from_dci_name (v);
526 } else if (k == "format") {
527 _format = Format::from_metadata (v);
528 } else if (k == "left_crop") {
529 _crop.left = atoi (v.c_str ());
530 } else if (k == "right_crop") {
531 _crop.right = atoi (v.c_str ());
532 } else if (k == "top_crop") {
533 _crop.top = atoi (v.c_str ());
534 } else if (k == "bottom_crop") {
535 _crop.bottom = atoi (v.c_str ());
536 } else if (k == "filter") {
537 _filters.push_back (Filter::from_id (v));
538 } else if (k == "scaler") {
539 _scaler = Scaler::from_id (v);
540 } else if ( ((!version || version < 2) && k == "dcp_trim_start") || k == "trim_start") {
541 _trim_start = atoi (v.c_str ());
542 } else if ( ((!version || version < 2) && k == "dcp_trim_end") || k == "trim_end") {
543 _trim_end = atoi (v.c_str ());
544 } else if (k == "dcp_ab") {
545 _dcp_ab = (v == "1");
546 } else if (k == "selected_content_audio_stream" || (!version && k == "selected_audio_stream")) {
548 audio_stream_index = atoi (v.c_str ());
550 _content_audio_stream = audio_stream_factory (v, version);
552 } else if (k == "external_audio") {
553 _external_audio.push_back (v);
554 } else if (k == "use_content_audio") {
555 _use_content_audio = (v == "1");
556 } else if (k == "audio_gain") {
557 _audio_gain = atof (v.c_str ());
558 } else if (k == "audio_delay") {
559 _audio_delay = atoi (v.c_str ());
560 } else if (k == "still_duration") {
561 _still_duration = atoi (v.c_str ());
562 } else if (k == "selected_subtitle_stream") {
564 subtitle_stream_index = atoi (v.c_str ());
566 _subtitle_stream = subtitle_stream_factory (v, version);
568 } else if (k == "with_subtitles") {
569 _with_subtitles = (v == "1");
570 } else if (k == "subtitle_offset") {
571 _subtitle_offset = atoi (v.c_str ());
572 } else if (k == "subtitle_scale") {
573 _subtitle_scale = atof (v.c_str ());
574 } else if (k == "colour_lut") {
575 _colour_lut = atoi (v.c_str ());
576 } else if (k == "j2k_bandwidth") {
577 _j2k_bandwidth = atoi (v.c_str ());
578 } else if (k == "dci_date") {
579 _dci_date = boost::gregorian::from_undelimited_string (v);
580 } else if (k == "dcp_frame_rate") {
581 _dcp_frame_rate = atoi (v.c_str ());
584 _dci_metadata.read (k, v);
588 _size.width = atoi (v.c_str ());
589 } else if (k == "height") {
590 _size.height = atoi (v.c_str ());
591 } else if (k == "length") {
592 int const vv = atoi (v.c_str ());
596 } else if (k == "content_digest") {
598 } else if (k == "content_audio_stream" || (!version && k == "audio_stream")) {
599 _content_audio_streams.push_back (audio_stream_factory (v, version));
600 } else if (k == "external_audio_stream") {
601 _external_audio_stream = audio_stream_factory (v, version);
602 } else if (k == "subtitle_stream") {
603 _subtitle_streams.push_back (subtitle_stream_factory (v, version));
604 } else if (k == "source_frame_rate") {
605 _source_frame_rate = atof (v.c_str ());
606 } else if (version < 4 && k == "frames_per_second") {
607 _source_frame_rate = atof (v.c_str ());
608 /* Fill in what would have been used for DCP frame rate by the older version */
609 _dcp_frame_rate = best_dcp_frame_rate (_source_frame_rate);
614 if (audio_sample_rate) {
615 /* version < 1 didn't specify sample rate in the audio streams, so fill it in here */
616 for (vector<shared_ptr<AudioStream> >::iterator i = _content_audio_streams.begin(); i != _content_audio_streams.end(); ++i) {
617 (*i)->set_sample_rate (audio_sample_rate.get());
621 /* also the selected stream was specified as an index */
622 if (audio_stream_index && audio_stream_index.get() >= 0 && audio_stream_index.get() < (int) _content_audio_streams.size()) {
623 _content_audio_stream = _content_audio_streams[audio_stream_index.get()];
626 /* similarly the subtitle */
627 if (subtitle_stream_index && subtitle_stream_index.get() >= 0 && subtitle_stream_index.get() < (int) _subtitle_streams.size()) {
628 _subtitle_stream = _subtitle_streams[subtitle_stream_index.get()];
636 Film::cropped_size (libdcp::Size s) const
638 boost::mutex::scoped_lock lm (_state_mutex);
639 s.width -= _crop.left + _crop.right;
640 s.height -= _crop.top + _crop.bottom;
644 /** Given a directory name, return its full path within the Film's directory.
645 * The directory (and its parents) will be created if they do not exist.
648 Film::dir (string d) const
650 boost::mutex::scoped_lock lm (_directory_mutex);
652 boost::filesystem::path p;
656 boost::filesystem::create_directories (p);
661 /** Given a file or directory name, return its full path within the Film's directory.
662 * _directory_mutex must not be locked on entry.
663 * Any required parent directories will be created.
666 Film::file (string f) const
668 boost::mutex::scoped_lock lm (_directory_mutex);
670 boost::filesystem::path p;
674 boost::filesystem::create_directories (p.parent_path ());
679 /** @return full path of the content (actual video) file
683 Film::content_path () const
685 boost::mutex::scoped_lock lm (_state_mutex);
686 if (boost::filesystem::path(_content).has_root_directory ()) {
690 return file (_content);
694 Film::content_type () const
696 if (boost::filesystem::is_directory (_content)) {
697 /* Directory of images, we assume */
701 if (still_image_file (_content)) {
708 /** @return The sampling rate that we will resample the audio to */
710 Film::target_audio_sample_rate () const
712 if (!audio_stream()) {
716 /* Resample to a DCI-approved sample rate */
717 double t = dcp_audio_sample_rate (audio_stream()->sample_rate());
719 FrameRateConversion frc (source_frame_rate(), dcp_frame_rate());
721 /* Compensate if the DCP is being run at a different frame rate
722 to the source; that is, if the video is run such that it will
723 look different in the DCP compared to the source (slower or faster).
724 skip/repeat doesn't come into effect here.
727 if (frc.change_speed) {
728 t *= source_frame_rate() * frc.factor() / dcp_frame_rate();
735 Film::still_duration_in_frames () const
737 return still_duration() * source_frame_rate();
740 /** @return a DCI-compliant name for a DCP of this film */
742 Film::dci_name (bool if_created_now) const
746 string fixed_name = to_upper_copy (name());
747 for (size_t i = 0; i < fixed_name.length(); ++i) {
748 if (fixed_name[i] == ' ') {
753 /* Spec is that the name part should be maximum 14 characters, as I understand it */
754 if (fixed_name.length() > 14) {
755 fixed_name = fixed_name.substr (0, 14);
758 d << fixed_name << "_";
760 if (dcp_content_type()) {
761 d << dcp_content_type()->dci_name() << "_";
765 d << format()->dci_name() << "_";
768 DCIMetadata const dm = dci_metadata ();
770 if (!dm.audio_language.empty ()) {
771 d << dm.audio_language;
772 if (!dm.subtitle_language.empty() && with_subtitles()) {
773 d << "-" << dm.subtitle_language;
781 if (!dm.territory.empty ()) {
783 if (!dm.rating.empty ()) {
784 d << "-" << dm.rating;
789 switch (audio_channels()) {
806 if (!dm.studio.empty ()) {
807 d << dm.studio << "_";
810 if (if_created_now) {
811 d << boost::gregorian::to_iso_string (boost::gregorian::day_clock::local_day ()) << "_";
813 d << boost::gregorian::to_iso_string (_dci_date) << "_";
816 if (!dm.facility.empty ()) {
817 d << dm.facility << "_";
820 if (!dm.package_type.empty ()) {
821 d << dm.package_type;
827 /** @return name to give the DCP */
829 Film::dcp_name (bool if_created_now) const
831 if (use_dci_name()) {
832 return dci_name (if_created_now);
840 Film::set_directory (string d)
842 boost::mutex::scoped_lock lm (_state_mutex);
848 Film::set_name (string n)
851 boost::mutex::scoped_lock lm (_state_mutex);
854 signal_changed (NAME);
858 Film::set_use_dci_name (bool u)
861 boost::mutex::scoped_lock lm (_state_mutex);
864 signal_changed (USE_DCI_NAME);
868 Film::set_content (string c)
870 string check = directory ();
872 boost::filesystem::path slash ("/");
873 string platform_slash = slash.make_preferred().string ();
875 if (!ends_with (check, platform_slash)) {
876 check += platform_slash;
879 if (boost::filesystem::path(c).has_root_directory () && starts_with (c, check)) {
880 c = c.substr (_directory.length() + 1);
886 boost::mutex::scoped_lock lm (_state_mutex);
891 old_content = _content;
895 /* Reset streams here in case the new content doesn't have one or the other */
896 _content_audio_stream = shared_ptr<AudioStream> ();
897 _subtitle_stream = shared_ptr<SubtitleStream> ();
899 /* Start off using content audio */
900 set_use_content_audio (true);
902 /* Create a temporary decoder so that we can get information
907 Decoders d = decoder_factory (shared_from_this(), DecodeOptions());
909 set_size (d.video->native_size ());
910 set_source_frame_rate (d.video->frames_per_second ());
911 set_dcp_frame_rate (best_dcp_frame_rate (source_frame_rate ()));
912 set_subtitle_streams (d.video->subtitle_streams ());
914 set_content_audio_streams (d.audio->audio_streams ());
918 boost::mutex::scoped_lock lm (_state_mutex);
922 signal_changed (CONTENT);
924 /* Start off with the first audio and subtitle streams */
925 if (d.audio && !d.audio->audio_streams().empty()) {
926 set_content_audio_stream (d.audio->audio_streams().front());
929 if (!d.video->subtitle_streams().empty()) {
930 set_subtitle_stream (d.video->subtitle_streams().front());
937 boost::mutex::scoped_lock lm (_state_mutex);
938 _content = old_content;
944 switch (content_type()) {
946 set_format (Format::from_id ("var-185"));
949 set_format (Format::from_id ("185"));
953 /* Still image DCPs must use external audio */
954 if (content_type() == STILL) {
955 set_use_content_audio (false);
960 Film::set_trust_content_header (bool t)
963 boost::mutex::scoped_lock lm (_state_mutex);
964 _trust_content_header = t;
967 signal_changed (TRUST_CONTENT_HEADER);
969 if (!_trust_content_header && !content().empty()) {
970 /* We just said that we don't trust the content's header */
976 Film::set_dcp_content_type (DCPContentType const * t)
979 boost::mutex::scoped_lock lm (_state_mutex);
980 _dcp_content_type = t;
982 signal_changed (DCP_CONTENT_TYPE);
986 Film::set_format (Format const * f)
989 boost::mutex::scoped_lock lm (_state_mutex);
992 signal_changed (FORMAT);
996 Film::set_crop (Crop c)
999 boost::mutex::scoped_lock lm (_state_mutex);
1002 signal_changed (CROP);
1006 Film::set_left_crop (int c)
1009 boost::mutex::scoped_lock lm (_state_mutex);
1011 if (_crop.left == c) {
1017 signal_changed (CROP);
1021 Film::set_right_crop (int c)
1024 boost::mutex::scoped_lock lm (_state_mutex);
1025 if (_crop.right == c) {
1031 signal_changed (CROP);
1035 Film::set_top_crop (int c)
1038 boost::mutex::scoped_lock lm (_state_mutex);
1039 if (_crop.top == c) {
1045 signal_changed (CROP);
1049 Film::set_bottom_crop (int c)
1052 boost::mutex::scoped_lock lm (_state_mutex);
1053 if (_crop.bottom == c) {
1059 signal_changed (CROP);
1063 Film::set_filters (vector<Filter const *> f)
1066 boost::mutex::scoped_lock lm (_state_mutex);
1069 signal_changed (FILTERS);
1073 Film::set_scaler (Scaler const * s)
1076 boost::mutex::scoped_lock lm (_state_mutex);
1079 signal_changed (SCALER);
1083 Film::set_trim_start (int t)
1086 boost::mutex::scoped_lock lm (_state_mutex);
1089 signal_changed (TRIM_START);
1093 Film::set_trim_end (int t)
1096 boost::mutex::scoped_lock lm (_state_mutex);
1099 signal_changed (TRIM_END);
1103 Film::set_dcp_ab (bool a)
1106 boost::mutex::scoped_lock lm (_state_mutex);
1109 signal_changed (DCP_AB);
1113 Film::set_content_audio_stream (shared_ptr<AudioStream> s)
1116 boost::mutex::scoped_lock lm (_state_mutex);
1117 _content_audio_stream = s;
1119 signal_changed (CONTENT_AUDIO_STREAM);
1123 Film::set_external_audio (vector<string> a)
1126 boost::mutex::scoped_lock lm (_state_mutex);
1127 _external_audio = a;
1130 shared_ptr<ExternalAudioDecoder> decoder (new ExternalAudioDecoder (shared_from_this(), DecodeOptions()));
1131 if (decoder->audio_stream()) {
1132 _external_audio_stream = decoder->audio_stream ();
1135 signal_changed (EXTERNAL_AUDIO);
1139 Film::set_use_content_audio (bool e)
1142 boost::mutex::scoped_lock lm (_state_mutex);
1143 _use_content_audio = e;
1146 signal_changed (USE_CONTENT_AUDIO);
1150 Film::set_audio_gain (float g)
1153 boost::mutex::scoped_lock lm (_state_mutex);
1156 signal_changed (AUDIO_GAIN);
1160 Film::set_audio_delay (int d)
1163 boost::mutex::scoped_lock lm (_state_mutex);
1166 signal_changed (AUDIO_DELAY);
1170 Film::set_still_duration (int d)
1173 boost::mutex::scoped_lock lm (_state_mutex);
1174 _still_duration = d;
1176 signal_changed (STILL_DURATION);
1180 Film::set_subtitle_stream (shared_ptr<SubtitleStream> s)
1183 boost::mutex::scoped_lock lm (_state_mutex);
1184 _subtitle_stream = s;
1186 signal_changed (SUBTITLE_STREAM);
1190 Film::set_with_subtitles (bool w)
1193 boost::mutex::scoped_lock lm (_state_mutex);
1194 _with_subtitles = w;
1196 signal_changed (WITH_SUBTITLES);
1200 Film::set_subtitle_offset (int o)
1203 boost::mutex::scoped_lock lm (_state_mutex);
1204 _subtitle_offset = o;
1206 signal_changed (SUBTITLE_OFFSET);
1210 Film::set_subtitle_scale (float s)
1213 boost::mutex::scoped_lock lm (_state_mutex);
1214 _subtitle_scale = s;
1216 signal_changed (SUBTITLE_SCALE);
1220 Film::set_colour_lut (int i)
1223 boost::mutex::scoped_lock lm (_state_mutex);
1226 signal_changed (COLOUR_LUT);
1230 Film::set_j2k_bandwidth (int b)
1233 boost::mutex::scoped_lock lm (_state_mutex);
1236 signal_changed (J2K_BANDWIDTH);
1240 Film::set_dci_metadata (DCIMetadata m)
1243 boost::mutex::scoped_lock lm (_state_mutex);
1246 signal_changed (DCI_METADATA);
1251 Film::set_dcp_frame_rate (int f)
1254 boost::mutex::scoped_lock lm (_state_mutex);
1255 _dcp_frame_rate = f;
1257 signal_changed (DCP_FRAME_RATE);
1261 Film::set_size (libdcp::Size s)
1264 boost::mutex::scoped_lock lm (_state_mutex);
1267 signal_changed (SIZE);
1271 Film::set_length (SourceFrame l)
1274 boost::mutex::scoped_lock lm (_state_mutex);
1277 signal_changed (LENGTH);
1281 Film::unset_length ()
1284 boost::mutex::scoped_lock lm (_state_mutex);
1285 _length = boost::none;
1287 signal_changed (LENGTH);
1291 Film::set_content_digest (string d)
1294 boost::mutex::scoped_lock lm (_state_mutex);
1295 _content_digest = d;
1301 Film::set_content_audio_streams (vector<shared_ptr<AudioStream> > s)
1304 boost::mutex::scoped_lock lm (_state_mutex);
1305 _content_audio_streams = s;
1307 signal_changed (CONTENT_AUDIO_STREAMS);
1311 Film::set_subtitle_streams (vector<shared_ptr<SubtitleStream> > s)
1314 boost::mutex::scoped_lock lm (_state_mutex);
1315 _subtitle_streams = s;
1317 signal_changed (SUBTITLE_STREAMS);
1321 Film::set_source_frame_rate (float f)
1324 boost::mutex::scoped_lock lm (_state_mutex);
1325 _source_frame_rate = f;
1327 signal_changed (SOURCE_FRAME_RATE);
1331 Film::signal_changed (Property p)
1334 boost::mutex::scoped_lock lm (_state_mutex);
1339 ui_signaller->emit (boost::bind (boost::ref (Changed), p));
1344 Film::audio_channels () const
1346 shared_ptr<AudioStream> s = audio_stream ();
1351 return s->channels ();
1355 Film::set_dci_date_today ()
1357 _dci_date = boost::gregorian::day_clock::local_day ();
1360 boost::shared_ptr<AudioStream>
1361 Film::audio_stream () const
1363 if (use_content_audio()) {
1364 return _content_audio_stream;
1367 return _external_audio_stream;
1371 Film::info_path (int f) const
1373 boost::filesystem::path p;
1378 s << setfill('0') << f << ".md5";
1382 /* info_dir() will already have added any initial bit of the path,
1383 so don't call file() on this.
1389 Film::j2c_path (int f, bool t) const
1391 boost::filesystem::path p;
1393 p /= video_state_identifier ();
1397 s << setfill('0') << f << ".j2c";
1404 return file (p.string ());
1407 /** Make an educated guess as to whether we have a complete DCP
1409 * @return true if we do.
1413 Film::have_dcp () const
1416 libdcp::DCP dcp (dir (dcp_name()));
1426 Film::has_audio () const
1428 if (use_content_audio()) {
1429 return audio_stream();
1432 vector<string> const e = external_audio ();
1433 for (vector<string>::const_iterator i = e.begin(); i != e.end(); ++i) {