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 ()
346 _analyse_audio_job.reset ();
348 AudioAnalysisFinished ();
352 Film::examine_content_finished ()
354 _examine_content_job.reset ();
357 /** Start a job to send our DCP to the configured TMS */
359 Film::send_dcp_to_tms ()
361 shared_ptr<Job> j (new SCPDCPJob (shared_from_this()));
362 JobManager::instance()->add (j);
365 /** Count the number of frames that have been encoded for this film.
366 * @return frame count.
369 Film::encoded_frames () const
376 for (boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (info_dir ()); i != boost::filesystem::directory_iterator(); ++i) {
378 boost::this_thread::interruption_point ();
384 /** Write state to our `metadata' file */
386 Film::write_metadata () const
388 boost::mutex::scoped_lock lm (_state_mutex);
390 boost::filesystem::create_directories (directory());
392 string const m = file ("metadata");
393 ofstream f (m.c_str ());
395 throw CreateFileError (m);
398 f << "version " << state_version << "\n";
401 f << "name " << _name << "\n";
402 f << "use_dci_name " << _use_dci_name << "\n";
403 f << "content " << _content << "\n";
404 f << "trust_content_header " << (_trust_content_header ? "1" : "0") << "\n";
405 if (_dcp_content_type) {
406 f << "dcp_content_type " << _dcp_content_type->dci_name () << "\n";
409 f << "format " << _format->as_metadata () << "\n";
411 f << "left_crop " << _crop.left << "\n";
412 f << "right_crop " << _crop.right << "\n";
413 f << "top_crop " << _crop.top << "\n";
414 f << "bottom_crop " << _crop.bottom << "\n";
415 for (vector<Filter const *>::const_iterator i = _filters.begin(); i != _filters.end(); ++i) {
416 f << "filter " << (*i)->id () << "\n";
418 f << "scaler " << _scaler->id () << "\n";
419 f << "trim_start " << _trim_start << "\n";
420 f << "trim_end " << _trim_end << "\n";
421 f << "dcp_ab " << (_dcp_ab ? "1" : "0") << "\n";
422 if (_content_audio_stream) {
423 f << "selected_content_audio_stream " << _content_audio_stream->to_string() << "\n";
425 for (vector<string>::const_iterator i = _external_audio.begin(); i != _external_audio.end(); ++i) {
426 f << "external_audio " << *i << "\n";
428 f << "use_content_audio " << (_use_content_audio ? "1" : "0") << "\n";
429 f << "audio_gain " << _audio_gain << "\n";
430 f << "audio_delay " << _audio_delay << "\n";
431 f << "still_duration " << _still_duration << "\n";
432 if (_subtitle_stream) {
433 f << "selected_subtitle_stream " << _subtitle_stream->to_string() << "\n";
435 f << "with_subtitles " << _with_subtitles << "\n";
436 f << "subtitle_offset " << _subtitle_offset << "\n";
437 f << "subtitle_scale " << _subtitle_scale << "\n";
438 f << "colour_lut " << _colour_lut << "\n";
439 f << "j2k_bandwidth " << _j2k_bandwidth << "\n";
440 _dci_metadata.write (f);
441 f << "dci_date " << boost::gregorian::to_iso_string (_dci_date) << "\n";
442 f << "width " << _size.width << "\n";
443 f << "height " << _size.height << "\n";
444 f << "length " << _length.get_value_or(0) << "\n";
445 f << "dcp_intrinsic_duration " << _dcp_intrinsic_duration.get_value_or(0) << "\n";
446 f << "content_digest " << _content_digest << "\n";
448 for (vector<shared_ptr<AudioStream> >::const_iterator i = _content_audio_streams.begin(); i != _content_audio_streams.end(); ++i) {
449 f << "content_audio_stream " << (*i)->to_string () << "\n";
452 f << "external_audio_stream " << _external_audio_stream->to_string() << "\n";
454 for (vector<shared_ptr<SubtitleStream> >::const_iterator i = _subtitle_streams.begin(); i != _subtitle_streams.end(); ++i) {
455 f << "subtitle_stream " << (*i)->to_string () << "\n";
458 f << "frames_per_second " << _frames_per_second << "\n";
463 /** Read state from our metadata file */
465 Film::read_metadata ()
467 boost::mutex::scoped_lock lm (_state_mutex);
469 _external_audio.clear ();
470 _content_audio_streams.clear ();
471 _subtitle_streams.clear ();
473 boost::optional<int> version;
475 /* Backward compatibility things */
476 boost::optional<int> audio_sample_rate;
477 boost::optional<int> audio_stream_index;
478 boost::optional<int> subtitle_stream_index;
480 ifstream f (file ("metadata").c_str());
482 throw OpenFileError (file ("metadata"));
485 multimap<string, string> kv = read_key_value (f);
487 /* We need version before anything else */
488 multimap<string, string>::iterator v = kv.find ("version");
489 if (v != kv.end ()) {
490 version = atoi (v->second.c_str());
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 == "audio_sample_rate") {
498 audio_sample_rate = atoi (v.c_str());
501 /* User-specified stuff */
504 } else if (k == "use_dci_name") {
505 _use_dci_name = (v == "1");
506 } else if (k == "content") {
508 } else if (k == "trust_content_header") {
509 _trust_content_header = (v == "1");
510 } else if (k == "dcp_content_type") {
512 _dcp_content_type = DCPContentType::from_pretty_name (v);
514 _dcp_content_type = DCPContentType::from_dci_name (v);
516 } else if (k == "format") {
517 _format = Format::from_metadata (v);
518 } else if (k == "left_crop") {
519 _crop.left = atoi (v.c_str ());
520 } else if (k == "right_crop") {
521 _crop.right = atoi (v.c_str ());
522 } else if (k == "top_crop") {
523 _crop.top = atoi (v.c_str ());
524 } else if (k == "bottom_crop") {
525 _crop.bottom = atoi (v.c_str ());
526 } else if (k == "filter") {
527 _filters.push_back (Filter::from_id (v));
528 } else if (k == "scaler") {
529 _scaler = Scaler::from_id (v);
530 } else if ( ((!version || version < 2) && k == "dcp_trim_start") || k == "trim_start") {
531 _trim_start = atoi (v.c_str ());
532 } else if ( ((!version || version < 2) && k == "dcp_trim_end") || k == "trim_end") {
533 _trim_end = atoi (v.c_str ());
534 } else if (k == "dcp_ab") {
535 _dcp_ab = (v == "1");
536 } else if (k == "selected_content_audio_stream" || (!version && k == "selected_audio_stream")) {
538 audio_stream_index = atoi (v.c_str ());
540 _content_audio_stream = audio_stream_factory (v, version);
542 } else if (k == "external_audio") {
543 _external_audio.push_back (v);
544 } else if (k == "use_content_audio") {
545 _use_content_audio = (v == "1");
546 } else if (k == "audio_gain") {
547 _audio_gain = atof (v.c_str ());
548 } else if (k == "audio_delay") {
549 _audio_delay = atoi (v.c_str ());
550 } else if (k == "still_duration") {
551 _still_duration = atoi (v.c_str ());
552 } else if (k == "selected_subtitle_stream") {
554 subtitle_stream_index = atoi (v.c_str ());
556 _subtitle_stream = subtitle_stream_factory (v, version);
558 } else if (k == "with_subtitles") {
559 _with_subtitles = (v == "1");
560 } else if (k == "subtitle_offset") {
561 _subtitle_offset = atoi (v.c_str ());
562 } else if (k == "subtitle_scale") {
563 _subtitle_scale = atof (v.c_str ());
564 } else if (k == "colour_lut") {
565 _colour_lut = atoi (v.c_str ());
566 } else if (k == "j2k_bandwidth") {
567 _j2k_bandwidth = atoi (v.c_str ());
568 } else if (k == "dci_date") {
569 _dci_date = boost::gregorian::from_undelimited_string (v);
572 _dci_metadata.read (k, v);
576 _size.width = atoi (v.c_str ());
577 } else if (k == "height") {
578 _size.height = atoi (v.c_str ());
579 } else if (k == "length") {
580 int const vv = atoi (v.c_str ());
584 } else if (k == "dcp_intrinsic_duration") {
585 int const vv = atoi (v.c_str ());
587 _dcp_intrinsic_duration = vv;
589 } else if (k == "content_digest") {
591 } else if (k == "content_audio_stream" || (!version && k == "audio_stream")) {
592 _content_audio_streams.push_back (audio_stream_factory (v, version));
593 } else if (k == "external_audio_stream") {
594 _external_audio_stream = audio_stream_factory (v, version);
595 } else if (k == "subtitle_stream") {
596 _subtitle_streams.push_back (subtitle_stream_factory (v, version));
597 } else if (k == "frames_per_second") {
598 _frames_per_second = atof (v.c_str ());
603 if (audio_sample_rate) {
604 /* version < 1 didn't specify sample rate in the audio streams, so fill it in here */
605 for (vector<shared_ptr<AudioStream> >::iterator i = _content_audio_streams.begin(); i != _content_audio_streams.end(); ++i) {
606 (*i)->set_sample_rate (audio_sample_rate.get());
610 /* also the selected stream was specified as an index */
611 if (audio_stream_index && audio_stream_index.get() >= 0 && audio_stream_index.get() < (int) _content_audio_streams.size()) {
612 _content_audio_stream = _content_audio_streams[audio_stream_index.get()];
615 /* similarly the subtitle */
616 if (subtitle_stream_index && subtitle_stream_index.get() >= 0 && subtitle_stream_index.get() < (int) _subtitle_streams.size()) {
617 _subtitle_stream = _subtitle_streams[subtitle_stream_index.get()];
625 Film::cropped_size (libdcp::Size s) const
627 boost::mutex::scoped_lock lm (_state_mutex);
628 s.width -= _crop.left + _crop.right;
629 s.height -= _crop.top + _crop.bottom;
633 /** Given a directory name, return its full path within the Film's directory.
634 * The directory (and its parents) will be created if they do not exist.
637 Film::dir (string d) const
639 boost::mutex::scoped_lock lm (_directory_mutex);
641 boost::filesystem::path p;
645 boost::filesystem::create_directories (p);
650 /** Given a file or directory name, return its full path within the Film's directory.
651 * _directory_mutex must not be locked on entry.
652 * Any required parent directories will be created.
655 Film::file (string f) const
657 boost::mutex::scoped_lock lm (_directory_mutex);
659 boost::filesystem::path p;
663 boost::filesystem::create_directories (p.parent_path ());
668 /** @return full path of the content (actual video) file
672 Film::content_path () const
674 boost::mutex::scoped_lock lm (_state_mutex);
675 if (boost::filesystem::path(_content).has_root_directory ()) {
679 return file (_content);
683 Film::content_type () const
685 if (boost::filesystem::is_directory (_content)) {
686 /* Directory of images, we assume */
690 if (still_image_file (_content)) {
697 /** @return The sampling rate that we will resample the audio to */
699 Film::target_audio_sample_rate () const
701 if (!audio_stream()) {
705 /* Resample to a DCI-approved sample rate */
706 double t = dcp_audio_sample_rate (audio_stream()->sample_rate());
708 DCPFrameRate dfr (frames_per_second ());
710 /* Compensate if the DCP is being run at a different frame rate
711 to the source; that is, if the video is run such that it will
712 look different in the DCP compared to the source (slower or faster).
713 skip/repeat doesn't come into effect here.
716 if (dfr.change_speed) {
717 t *= _frames_per_second * dfr.factor() / dfr.frames_per_second;
724 Film::still_duration_in_frames () const
726 return still_duration() * frames_per_second();
729 /** @return a DCI-compliant name for a DCP of this film */
731 Film::dci_name (bool if_created_now) const
735 string fixed_name = to_upper_copy (name());
736 for (size_t i = 0; i < fixed_name.length(); ++i) {
737 if (fixed_name[i] == ' ') {
742 /* Spec is that the name part should be maximum 14 characters, as I understand it */
743 if (fixed_name.length() > 14) {
744 fixed_name = fixed_name.substr (0, 14);
747 d << fixed_name << "_";
749 if (dcp_content_type()) {
750 d << dcp_content_type()->dci_name() << "_";
754 d << format()->dci_name() << "_";
757 DCIMetadata const dm = dci_metadata ();
759 if (!dm.audio_language.empty ()) {
760 d << dm.audio_language;
761 if (!dm.subtitle_language.empty() && with_subtitles()) {
762 d << "-" << dm.subtitle_language;
770 if (!dm.territory.empty ()) {
772 if (!dm.rating.empty ()) {
773 d << "-" << dm.rating;
778 switch (audio_channels()) {
795 if (!dm.studio.empty ()) {
796 d << dm.studio << "_";
799 if (if_created_now) {
800 d << boost::gregorian::to_iso_string (boost::gregorian::day_clock::local_day ()) << "_";
802 d << boost::gregorian::to_iso_string (_dci_date) << "_";
805 if (!dm.facility.empty ()) {
806 d << dm.facility << "_";
809 if (!dm.package_type.empty ()) {
810 d << dm.package_type;
816 /** @return name to give the DCP */
818 Film::dcp_name (bool if_created_now) const
820 if (use_dci_name()) {
821 return dci_name (if_created_now);
829 Film::set_directory (string d)
831 boost::mutex::scoped_lock lm (_state_mutex);
837 Film::set_name (string n)
840 boost::mutex::scoped_lock lm (_state_mutex);
843 signal_changed (NAME);
847 Film::set_use_dci_name (bool u)
850 boost::mutex::scoped_lock lm (_state_mutex);
853 signal_changed (USE_DCI_NAME);
857 Film::set_content (string c)
859 string check = directory ();
861 boost::filesystem::path slash ("/");
862 string platform_slash = slash.make_preferred().string ();
864 if (!ends_with (check, platform_slash)) {
865 check += platform_slash;
868 if (boost::filesystem::path(c).has_root_directory () && starts_with (c, check)) {
869 c = c.substr (_directory.length() + 1);
875 boost::mutex::scoped_lock lm (_state_mutex);
880 old_content = _content;
884 /* Reset streams here in case the new content doesn't have one or the other */
885 _content_audio_stream = shared_ptr<AudioStream> ();
886 _subtitle_stream = shared_ptr<SubtitleStream> ();
888 /* Start off using content audio */
889 set_use_content_audio (true);
891 /* Create a temporary decoder so that we can get information
896 Decoders d = decoder_factory (shared_from_this(), DecodeOptions());
898 set_size (d.video->native_size ());
899 set_frames_per_second (d.video->frames_per_second ());
900 set_subtitle_streams (d.video->subtitle_streams ());
902 set_content_audio_streams (d.audio->audio_streams ());
906 boost::mutex::scoped_lock lm (_state_mutex);
910 signal_changed (CONTENT);
912 /* Start off with the first audio and subtitle streams */
913 if (d.audio && !d.audio->audio_streams().empty()) {
914 set_content_audio_stream (d.audio->audio_streams().front());
917 if (!d.video->subtitle_streams().empty()) {
918 set_subtitle_stream (d.video->subtitle_streams().front());
925 boost::mutex::scoped_lock lm (_state_mutex);
926 _content = old_content;
932 switch (content_type()) {
934 set_format (Format::from_id ("var-185"));
937 set_format (Format::from_id ("185"));
941 /* Still image DCPs must use external audio */
942 if (content_type() == STILL) {
943 set_use_content_audio (false);
948 Film::set_trust_content_header (bool t)
951 boost::mutex::scoped_lock lm (_state_mutex);
952 _trust_content_header = t;
955 signal_changed (TRUST_CONTENT_HEADER);
957 if (!_trust_content_header && !content().empty()) {
958 /* We just said that we don't trust the content's header */
964 Film::set_dcp_content_type (DCPContentType const * t)
967 boost::mutex::scoped_lock lm (_state_mutex);
968 _dcp_content_type = t;
970 signal_changed (DCP_CONTENT_TYPE);
974 Film::set_format (Format const * f)
977 boost::mutex::scoped_lock lm (_state_mutex);
980 signal_changed (FORMAT);
984 Film::set_crop (Crop c)
987 boost::mutex::scoped_lock lm (_state_mutex);
990 signal_changed (CROP);
994 Film::set_left_crop (int c)
997 boost::mutex::scoped_lock lm (_state_mutex);
999 if (_crop.left == c) {
1005 signal_changed (CROP);
1009 Film::set_right_crop (int c)
1012 boost::mutex::scoped_lock lm (_state_mutex);
1013 if (_crop.right == c) {
1019 signal_changed (CROP);
1023 Film::set_top_crop (int c)
1026 boost::mutex::scoped_lock lm (_state_mutex);
1027 if (_crop.top == c) {
1033 signal_changed (CROP);
1037 Film::set_bottom_crop (int c)
1040 boost::mutex::scoped_lock lm (_state_mutex);
1041 if (_crop.bottom == c) {
1047 signal_changed (CROP);
1051 Film::set_filters (vector<Filter const *> f)
1054 boost::mutex::scoped_lock lm (_state_mutex);
1057 signal_changed (FILTERS);
1061 Film::set_scaler (Scaler const * s)
1064 boost::mutex::scoped_lock lm (_state_mutex);
1067 signal_changed (SCALER);
1071 Film::set_trim_start (int t)
1074 boost::mutex::scoped_lock lm (_state_mutex);
1077 signal_changed (TRIM_START);
1081 Film::set_trim_end (int t)
1084 boost::mutex::scoped_lock lm (_state_mutex);
1087 signal_changed (TRIM_END);
1091 Film::set_dcp_ab (bool a)
1094 boost::mutex::scoped_lock lm (_state_mutex);
1097 signal_changed (DCP_AB);
1101 Film::set_content_audio_stream (shared_ptr<AudioStream> s)
1104 boost::mutex::scoped_lock lm (_state_mutex);
1105 _content_audio_stream = s;
1107 signal_changed (CONTENT_AUDIO_STREAM);
1111 Film::set_external_audio (vector<string> a)
1114 boost::mutex::scoped_lock lm (_state_mutex);
1115 _external_audio = a;
1118 shared_ptr<ExternalAudioDecoder> decoder (new ExternalAudioDecoder (shared_from_this(), DecodeOptions()));
1119 if (decoder->audio_stream()) {
1120 _external_audio_stream = decoder->audio_stream ();
1123 signal_changed (EXTERNAL_AUDIO);
1127 Film::set_use_content_audio (bool e)
1130 boost::mutex::scoped_lock lm (_state_mutex);
1131 _use_content_audio = e;
1134 signal_changed (USE_CONTENT_AUDIO);
1138 Film::set_audio_gain (float g)
1141 boost::mutex::scoped_lock lm (_state_mutex);
1144 signal_changed (AUDIO_GAIN);
1148 Film::set_audio_delay (int d)
1151 boost::mutex::scoped_lock lm (_state_mutex);
1154 signal_changed (AUDIO_DELAY);
1158 Film::set_still_duration (int d)
1161 boost::mutex::scoped_lock lm (_state_mutex);
1162 _still_duration = d;
1164 signal_changed (STILL_DURATION);
1168 Film::set_subtitle_stream (shared_ptr<SubtitleStream> s)
1171 boost::mutex::scoped_lock lm (_state_mutex);
1172 _subtitle_stream = s;
1174 signal_changed (SUBTITLE_STREAM);
1178 Film::set_with_subtitles (bool w)
1181 boost::mutex::scoped_lock lm (_state_mutex);
1182 _with_subtitles = w;
1184 signal_changed (WITH_SUBTITLES);
1188 Film::set_subtitle_offset (int o)
1191 boost::mutex::scoped_lock lm (_state_mutex);
1192 _subtitle_offset = o;
1194 signal_changed (SUBTITLE_OFFSET);
1198 Film::set_subtitle_scale (float s)
1201 boost::mutex::scoped_lock lm (_state_mutex);
1202 _subtitle_scale = s;
1204 signal_changed (SUBTITLE_SCALE);
1208 Film::set_colour_lut (int i)
1211 boost::mutex::scoped_lock lm (_state_mutex);
1214 signal_changed (COLOUR_LUT);
1218 Film::set_j2k_bandwidth (int b)
1221 boost::mutex::scoped_lock lm (_state_mutex);
1224 signal_changed (J2K_BANDWIDTH);
1228 Film::set_dci_metadata (DCIMetadata m)
1231 boost::mutex::scoped_lock lm (_state_mutex);
1234 signal_changed (DCI_METADATA);
1238 Film::set_size (libdcp::Size s)
1241 boost::mutex::scoped_lock lm (_state_mutex);
1244 signal_changed (SIZE);
1248 Film::set_length (SourceFrame l)
1251 boost::mutex::scoped_lock lm (_state_mutex);
1254 signal_changed (LENGTH);
1258 Film::unset_length ()
1261 boost::mutex::scoped_lock lm (_state_mutex);
1262 _length = boost::none;
1264 signal_changed (LENGTH);
1268 Film::set_dcp_intrinsic_duration (int d)
1271 boost::mutex::scoped_lock lm (_state_mutex);
1272 _dcp_intrinsic_duration = d;
1274 signal_changed (DCP_INTRINSIC_DURATION);
1278 Film::set_content_digest (string d)
1281 boost::mutex::scoped_lock lm (_state_mutex);
1282 _content_digest = d;
1288 Film::set_content_audio_streams (vector<shared_ptr<AudioStream> > s)
1291 boost::mutex::scoped_lock lm (_state_mutex);
1292 _content_audio_streams = s;
1294 signal_changed (CONTENT_AUDIO_STREAMS);
1298 Film::set_subtitle_streams (vector<shared_ptr<SubtitleStream> > s)
1301 boost::mutex::scoped_lock lm (_state_mutex);
1302 _subtitle_streams = s;
1304 signal_changed (SUBTITLE_STREAMS);
1308 Film::set_frames_per_second (float f)
1311 boost::mutex::scoped_lock lm (_state_mutex);
1312 _frames_per_second = f;
1314 signal_changed (FRAMES_PER_SECOND);
1318 Film::signal_changed (Property p)
1321 boost::mutex::scoped_lock lm (_state_mutex);
1326 ui_signaller->emit (boost::bind (boost::ref (Changed), p));
1331 Film::audio_channels () const
1333 shared_ptr<AudioStream> s = audio_stream ();
1338 return s->channels ();
1342 Film::set_dci_date_today ()
1344 _dci_date = boost::gregorian::day_clock::local_day ();
1347 boost::shared_ptr<AudioStream>
1348 Film::audio_stream () const
1350 if (use_content_audio()) {
1351 return _content_audio_stream;
1354 return _external_audio_stream;
1358 Film::info_path (int f) const
1360 boost::filesystem::path p;
1365 s << setfill('0') << f << ".md5";
1369 /* info_dir() will already have added any initial bit of the path,
1370 so don't call file() on this.
1376 Film::j2c_path (int f, bool t) const
1378 boost::filesystem::path p;
1380 p /= video_state_identifier ();
1384 s << setfill('0') << f << ".j2c";
1391 return file (p.string ());
1394 /** Make an educated guess as to whether we have a complete DCP
1396 * @return true if we do.
1400 Film::have_dcp () const
1403 libdcp::DCP dcp (dir (dcp_name()));