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 "sndfile_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"))
98 , _use_content_audio (true)
101 , _still_duration (10)
102 , _with_subtitles (false)
103 , _subtitle_offset (0)
104 , _subtitle_scale (1)
106 , _j2k_bandwidth (200000000)
107 , _dci_metadata (Config::instance()->default_dci_metadata ())
108 , _dcp_frame_rate (0)
109 , _source_frame_rate (0)
112 set_dci_date_today ();
114 /* Make state.directory a complete path without ..s (where possible)
115 (Code swiped from Adam Bowen on stackoverflow)
118 boost::filesystem::path p (boost::filesystem::system_complete (d));
119 boost::filesystem::path result;
120 for (boost::filesystem::path::iterator i = p.begin(); i != p.end(); ++i) {
122 if (boost::filesystem::is_symlink (result) || result.filename() == "..") {
125 result = result.parent_path ();
127 } else if (*i != ".") {
132 set_directory (result.string ());
134 if (!boost::filesystem::exists (directory())) {
136 throw OpenFileError (directory());
138 boost::filesystem::create_directory (directory());
142 _sndfile_stream = SndfileStream::create ();
150 _log.reset (new FileLog (file ("log")));
153 Film::Film (Film const & o)
154 : boost::enable_shared_from_this<Film> (o)
155 /* note: the copied film shares the original's log */
157 , _directory (o._directory)
159 , _use_dci_name (o._use_dci_name)
160 , _content (o._content)
161 , _trust_content_header (o._trust_content_header)
162 , _dcp_content_type (o._dcp_content_type)
163 , _format (o._format)
165 , _filters (o._filters)
166 , _scaler (o._scaler)
167 , _trim_start (o._trim_start)
168 , _trim_end (o._trim_end)
169 , _trim_type (o._trim_type)
170 , _dcp_ab (o._dcp_ab)
171 , _content_audio_stream (o._content_audio_stream)
172 , _external_audio (o._external_audio)
173 , _use_content_audio (o._use_content_audio)
174 , _audio_gain (o._audio_gain)
175 , _audio_delay (o._audio_delay)
176 , _still_duration (o._still_duration)
177 , _subtitle_stream (o._subtitle_stream)
178 , _with_subtitles (o._with_subtitles)
179 , _subtitle_offset (o._subtitle_offset)
180 , _subtitle_scale (o._subtitle_scale)
181 , _colour_lut (o._colour_lut)
182 , _j2k_bandwidth (o._j2k_bandwidth)
183 , _dci_metadata (o._dci_metadata)
184 , _dci_date (o._dci_date)
185 , _dcp_frame_rate (o._dcp_frame_rate)
187 , _length (o._length)
188 , _content_digest (o._content_digest)
189 , _content_audio_streams (o._content_audio_streams)
190 , _sndfile_stream (o._sndfile_stream)
191 , _subtitle_streams (o._subtitle_streams)
192 , _source_frame_rate (o._source_frame_rate)
204 Film::video_state_identifier () const
208 pair<string, string> f = Filter::ffmpeg_strings (filters());
212 << "_" << content_digest()
213 << "_" << crop().left << "_" << crop().right << "_" << crop().top << "_" << crop().bottom
214 << "_" << _dcp_frame_rate
215 << "_" << f.first << "_" << f.second
216 << "_" << scaler()->id()
217 << "_" << j2k_bandwidth()
218 << "_" << boost::lexical_cast<int> (colour_lut());
221 pair<string, string> fa = Filter::ffmpeg_strings (Config::instance()->reference_filters());
222 s << "ab_" << Config::instance()->reference_scaler()->id() << "_" << fa.first << "_" << fa.second;
228 /** @return The path to the directory to write video frame info files to */
230 Film::info_dir () const
232 boost::filesystem::path p;
234 p /= video_state_identifier ();
235 return dir (p.string());
239 Film::internal_video_mxf_dir () const
241 boost::filesystem::path p;
242 return dir ("video");
246 Film::internal_video_mxf_filename () const
248 return video_state_identifier() + ".mxf";
252 Film::dcp_video_mxf_filename () const
254 return filename_safe_name() + "_video.mxf";
258 Film::dcp_audio_mxf_filename () const
260 return filename_safe_name() + "_audio.mxf";
264 Film::filename_safe_name () const
266 string const n = name ();
268 for (size_t i = 0; i < n.length(); ++i) {
269 if (isalnum (n[i])) {
280 Film::audio_analysis_path () const
282 boost::filesystem::path p;
284 p /= content_digest();
285 return file (p.string ());
288 /** Add suitable Jobs to the JobManager to create a DCP for this Film */
292 set_dci_date_today ();
294 if (dcp_name().find ("/") != string::npos) {
295 throw BadSettingError (_("name"), _("cannot contain slashes"));
298 log()->log (String::compose ("DVD-o-matic %1 git %2 using %3", dvdomatic_version, dvdomatic_git_commit, dependency_version_summary()));
302 gethostname (buffer, sizeof (buffer));
303 log()->log (String::compose ("Starting to make DCP on %1", buffer));
306 log()->log (String::compose ("Content is %1; type %2", content_path(), (content_type() == STILL ? _("still") : _("video"))));
308 log()->log (String::compose ("Content length %1", length().get()));
310 log()->log (String::compose ("Content digest %1", content_digest()));
311 log()->log (String::compose ("Content at %1 fps, DCP at %2 fps", source_frame_rate(), dcp_frame_rate()));
312 log()->log (String::compose ("%1 threads", Config::instance()->num_local_encoding_threads()));
313 log()->log (String::compose ("J2K bandwidth %1", j2k_bandwidth()));
314 #ifdef DVDOMATIC_DEBUG
315 log()->log ("DVD-o-matic built in debug mode.");
317 log()->log ("DVD-o-matic built in optimised mode.");
320 log()->log ("libdcp built in debug mode.");
322 log()->log ("libdcp built in optimised mode.");
324 pair<string, int> const c = cpu_info ();
325 log()->log (String::compose ("CPU: %1, %2 processors", c.first, c.second));
328 throw MissingSettingError (_("format"));
331 if (content().empty ()) {
332 throw MissingSettingError (_("content"));
335 if (dcp_content_type() == 0) {
336 throw MissingSettingError (_("content type"));
339 if (name().empty()) {
340 throw MissingSettingError (_("name"));
344 od.decode_subtitles = with_subtitles ();
349 r = JobManager::instance()->add (shared_ptr<Job> (new ABTranscodeJob (shared_from_this(), od)));
351 r = JobManager::instance()->add (shared_ptr<Job> (new TranscodeJob (shared_from_this(), od)));
355 /** Start a job to analyse the audio of our content file */
357 Film::analyse_audio ()
359 if (_analyse_audio_job) {
363 _analyse_audio_job.reset (new AnalyseAudioJob (shared_from_this()));
364 _analyse_audio_job->Finished.connect (bind (&Film::analyse_audio_finished, this));
365 JobManager::instance()->add (_analyse_audio_job);
368 /** Start a job to examine our content file */
370 Film::examine_content ()
372 if (_examine_content_job) {
376 _examine_content_job.reset (new ExamineContentJob (shared_from_this()));
377 _examine_content_job->Finished.connect (bind (&Film::examine_content_finished, this));
378 JobManager::instance()->add (_examine_content_job);
382 Film::analyse_audio_finished ()
386 if (_analyse_audio_job->finished_ok ()) {
387 AudioAnalysisSucceeded ();
390 _analyse_audio_job.reset ();
394 Film::examine_content_finished ()
396 _examine_content_job.reset ();
399 /** Start a job to send our DCP to the configured TMS */
401 Film::send_dcp_to_tms ()
403 shared_ptr<Job> j (new SCPDCPJob (shared_from_this()));
404 JobManager::instance()->add (j);
407 /** Count the number of frames that have been encoded for this film.
408 * @return frame count.
411 Film::encoded_frames () const
418 for (boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (info_dir ()); i != boost::filesystem::directory_iterator(); ++i) {
420 boost::this_thread::interruption_point ();
426 /** Write state to our `metadata' file */
428 Film::write_metadata () const
430 boost::mutex::scoped_lock lm (_state_mutex);
432 boost::filesystem::create_directories (directory());
434 string const m = file ("metadata");
435 ofstream f (m.c_str ());
437 throw CreateFileError (m);
440 f << "version " << state_version << endl;
443 f << "name " << _name << endl;
444 f << "use_dci_name " << _use_dci_name << endl;
445 f << "content " << _content << endl;
446 f << "trust_content_header " << (_trust_content_header ? "1" : "0") << endl;
447 if (_dcp_content_type) {
448 f << "dcp_content_type " << _dcp_content_type->dci_name () << endl;
451 f << "format " << _format->as_metadata () << endl;
453 f << "left_crop " << _crop.left << endl;
454 f << "right_crop " << _crop.right << endl;
455 f << "top_crop " << _crop.top << endl;
456 f << "bottom_crop " << _crop.bottom << endl;
457 for (vector<Filter const *>::const_iterator i = _filters.begin(); i != _filters.end(); ++i) {
458 f << "filter " << (*i)->id () << endl;
460 f << "scaler " << _scaler->id () << endl;
461 f << "trim_start " << _trim_start << endl;
462 f << "trim_end " << _trim_end << endl;
463 switch (_trim_type) {
465 f << "trim_type cpl\n";
468 f << "trim_type encode\n";
471 f << "dcp_ab " << (_dcp_ab ? "1" : "0") << endl;
472 if (_content_audio_stream) {
473 f << "selected_content_audio_stream " << _content_audio_stream->to_string() << endl;
475 for (vector<string>::const_iterator i = _external_audio.begin(); i != _external_audio.end(); ++i) {
476 f << "external_audio " << *i << endl;
478 f << "use_content_audio " << (_use_content_audio ? "1" : "0") << endl;
479 f << "audio_gain " << _audio_gain << endl;
480 f << "audio_delay " << _audio_delay << endl;
481 f << "still_duration " << _still_duration << endl;
482 if (_subtitle_stream) {
483 f << "selected_subtitle_stream " << _subtitle_stream->to_string() << endl;
485 f << "with_subtitles " << _with_subtitles << endl;
486 f << "subtitle_offset " << _subtitle_offset << endl;
487 f << "subtitle_scale " << _subtitle_scale << endl;
488 f << "colour_lut " << _colour_lut << endl;
489 f << "j2k_bandwidth " << _j2k_bandwidth << endl;
490 _dci_metadata.write (f);
491 f << "dci_date " << boost::gregorian::to_iso_string (_dci_date) << endl;
492 f << "dcp_frame_rate " << _dcp_frame_rate << endl;
493 f << "width " << _size.width << endl;
494 f << "height " << _size.height << endl;
495 f << "length " << _length.get_value_or(0) << endl;
496 f << "content_digest " << _content_digest << endl;
498 for (vector<shared_ptr<AudioStream> >::const_iterator i = _content_audio_streams.begin(); i != _content_audio_streams.end(); ++i) {
499 f << "content_audio_stream " << (*i)->to_string () << endl;
502 f << "external_audio_stream " << _sndfile_stream->to_string() << endl;
504 for (vector<shared_ptr<SubtitleStream> >::const_iterator i = _subtitle_streams.begin(); i != _subtitle_streams.end(); ++i) {
505 f << "subtitle_stream " << (*i)->to_string () << endl;
508 f << "source_frame_rate " << _source_frame_rate << endl;
513 /** Read state from our metadata file */
515 Film::read_metadata ()
517 boost::mutex::scoped_lock lm (_state_mutex);
519 _external_audio.clear ();
520 _content_audio_streams.clear ();
521 _subtitle_streams.clear ();
523 boost::optional<int> version;
525 /* Backward compatibility things */
526 boost::optional<int> audio_sample_rate;
527 boost::optional<int> audio_stream_index;
528 boost::optional<int> subtitle_stream_index;
530 ifstream f (file ("metadata").c_str());
532 throw OpenFileError (file ("metadata"));
535 multimap<string, string> kv = read_key_value (f);
537 /* We need version before anything else */
538 multimap<string, string>::iterator v = kv.find ("version");
539 if (v != kv.end ()) {
540 version = atoi (v->second.c_str());
543 for (multimap<string, string>::const_iterator i = kv.begin(); i != kv.end(); ++i) {
544 string const k = i->first;
545 string const v = i->second;
547 if (k == "audio_sample_rate") {
548 audio_sample_rate = atoi (v.c_str());
551 /* User-specified stuff */
554 } else if (k == "use_dci_name") {
555 _use_dci_name = (v == "1");
556 } else if (k == "content") {
558 } else if (k == "trust_content_header") {
559 _trust_content_header = (v == "1");
560 } else if (k == "dcp_content_type") {
562 _dcp_content_type = DCPContentType::from_pretty_name (v);
564 _dcp_content_type = DCPContentType::from_dci_name (v);
566 } else if (k == "format") {
567 _format = Format::from_metadata (v);
568 } else if (k == "left_crop") {
569 _crop.left = atoi (v.c_str ());
570 } else if (k == "right_crop") {
571 _crop.right = atoi (v.c_str ());
572 } else if (k == "top_crop") {
573 _crop.top = atoi (v.c_str ());
574 } else if (k == "bottom_crop") {
575 _crop.bottom = atoi (v.c_str ());
576 } else if (k == "filter") {
577 _filters.push_back (Filter::from_id (v));
578 } else if (k == "scaler") {
579 _scaler = Scaler::from_id (v);
580 } else if ( ((!version || version < 2) && k == "dcp_trim_start") || k == "trim_start") {
581 _trim_start = atoi (v.c_str ());
582 } else if ( ((!version || version < 2) && k == "dcp_trim_end") || k == "trim_end") {
583 _trim_end = atoi (v.c_str ());
584 } else if (k == "trim_type") {
587 } else if (v == "encode") {
590 } else if (k == "dcp_ab") {
591 _dcp_ab = (v == "1");
592 } else if (k == "selected_content_audio_stream" || (!version && k == "selected_audio_stream")) {
594 audio_stream_index = atoi (v.c_str ());
596 _content_audio_stream = audio_stream_factory (v, version);
598 } else if (k == "external_audio") {
599 _external_audio.push_back (v);
600 } else if (k == "use_content_audio") {
601 _use_content_audio = (v == "1");
602 } else if (k == "audio_gain") {
603 _audio_gain = atof (v.c_str ());
604 } else if (k == "audio_delay") {
605 _audio_delay = atoi (v.c_str ());
606 } else if (k == "still_duration") {
607 _still_duration = atoi (v.c_str ());
608 } else if (k == "selected_subtitle_stream") {
610 subtitle_stream_index = atoi (v.c_str ());
612 _subtitle_stream = subtitle_stream_factory (v, version);
614 } else if (k == "with_subtitles") {
615 _with_subtitles = (v == "1");
616 } else if (k == "subtitle_offset") {
617 _subtitle_offset = atoi (v.c_str ());
618 } else if (k == "subtitle_scale") {
619 _subtitle_scale = atof (v.c_str ());
620 } else if (k == "colour_lut") {
621 _colour_lut = atoi (v.c_str ());
622 } else if (k == "j2k_bandwidth") {
623 _j2k_bandwidth = atoi (v.c_str ());
624 } else if (k == "dci_date") {
625 _dci_date = boost::gregorian::from_undelimited_string (v);
626 } else if (k == "dcp_frame_rate") {
627 _dcp_frame_rate = atoi (v.c_str ());
630 _dci_metadata.read (k, v);
634 _size.width = atoi (v.c_str ());
635 } else if (k == "height") {
636 _size.height = atoi (v.c_str ());
637 } else if (k == "length") {
638 int const vv = atoi (v.c_str ());
642 } else if (k == "content_digest") {
644 } else if (k == "content_audio_stream" || (!version && k == "audio_stream")) {
645 _content_audio_streams.push_back (audio_stream_factory (v, version));
646 } else if (k == "external_audio_stream") {
647 _sndfile_stream = audio_stream_factory (v, version);
648 } else if (k == "subtitle_stream") {
649 _subtitle_streams.push_back (subtitle_stream_factory (v, version));
650 } else if (k == "source_frame_rate") {
651 _source_frame_rate = atof (v.c_str ());
652 } else if (version < 4 && k == "frames_per_second") {
653 _source_frame_rate = atof (v.c_str ());
654 /* Fill in what would have been used for DCP frame rate by the older version */
655 _dcp_frame_rate = best_dcp_frame_rate (_source_frame_rate);
660 if (audio_sample_rate) {
661 /* version < 1 didn't specify sample rate in the audio streams, so fill it in here */
662 for (vector<shared_ptr<AudioStream> >::iterator i = _content_audio_streams.begin(); i != _content_audio_streams.end(); ++i) {
663 (*i)->set_sample_rate (audio_sample_rate.get());
667 /* also the selected stream was specified as an index */
668 if (audio_stream_index && audio_stream_index.get() >= 0 && audio_stream_index.get() < (int) _content_audio_streams.size()) {
669 _content_audio_stream = _content_audio_streams[audio_stream_index.get()];
672 /* similarly the subtitle */
673 if (subtitle_stream_index && subtitle_stream_index.get() >= 0 && subtitle_stream_index.get() < (int) _subtitle_streams.size()) {
674 _subtitle_stream = _subtitle_streams[subtitle_stream_index.get()];
682 Film::cropped_size (libdcp::Size s) const
684 boost::mutex::scoped_lock lm (_state_mutex);
685 s.width -= _crop.left + _crop.right;
686 s.height -= _crop.top + _crop.bottom;
690 /** Given a directory name, return its full path within the Film's directory.
691 * The directory (and its parents) will be created if they do not exist.
694 Film::dir (string d) const
696 boost::mutex::scoped_lock lm (_directory_mutex);
698 boost::filesystem::path p;
702 boost::filesystem::create_directories (p);
707 /** Given a file or directory name, return its full path within the Film's directory.
708 * _directory_mutex must not be locked on entry.
709 * Any required parent directories will be created.
712 Film::file (string f) const
714 boost::mutex::scoped_lock lm (_directory_mutex);
716 boost::filesystem::path p;
720 boost::filesystem::create_directories (p.parent_path ());
725 /** @return full path of the content (actual video) file
729 Film::content_path () const
731 boost::mutex::scoped_lock lm (_state_mutex);
732 if (boost::filesystem::path(_content).has_root_directory ()) {
736 return file (_content);
740 Film::content_type () const
742 if (boost::filesystem::is_directory (_content)) {
743 /* Directory of images, we assume */
747 if (still_image_file (_content)) {
754 /** @return The sampling rate that we will resample the audio to */
756 Film::target_audio_sample_rate () const
758 if (!audio_stream()) {
762 /* Resample to a DCI-approved sample rate */
763 double t = dcp_audio_sample_rate (audio_stream()->sample_rate());
765 FrameRateConversion frc (source_frame_rate(), dcp_frame_rate());
767 /* Compensate if the DCP is being run at a different frame rate
768 to the source; that is, if the video is run such that it will
769 look different in the DCP compared to the source (slower or faster).
770 skip/repeat doesn't come into effect here.
773 if (frc.change_speed) {
774 t *= source_frame_rate() * frc.factor() / dcp_frame_rate();
781 Film::still_duration_in_frames () const
783 return still_duration() * source_frame_rate();
786 /** @return a DCI-compliant name for a DCP of this film */
788 Film::dci_name (bool if_created_now) const
792 string fixed_name = to_upper_copy (name());
793 for (size_t i = 0; i < fixed_name.length(); ++i) {
794 if (fixed_name[i] == ' ') {
799 /* Spec is that the name part should be maximum 14 characters, as I understand it */
800 if (fixed_name.length() > 14) {
801 fixed_name = fixed_name.substr (0, 14);
806 if (dcp_content_type()) {
807 d << "_" << dcp_content_type()->dci_name();
811 d << "_" << format()->dci_name();
814 DCIMetadata const dm = dci_metadata ();
816 if (!dm.audio_language.empty ()) {
817 d << "_" << dm.audio_language;
818 if (!dm.subtitle_language.empty()) {
819 d << "-" << dm.subtitle_language;
825 if (!dm.territory.empty ()) {
826 d << "_" << dm.territory;
827 if (!dm.rating.empty ()) {
828 d << "-" << dm.rating;
832 switch (audio_channels()) {
849 if (!dm.studio.empty ()) {
850 d << "_" << dm.studio;
853 if (if_created_now) {
854 d << "_" << boost::gregorian::to_iso_string (boost::gregorian::day_clock::local_day ());
856 d << "_" << boost::gregorian::to_iso_string (_dci_date);
859 if (!dm.facility.empty ()) {
860 d << "_" << dm.facility;
863 if (!dm.package_type.empty ()) {
864 d << "_" << dm.package_type;
870 /** @return name to give the DCP */
872 Film::dcp_name (bool if_created_now) const
874 if (use_dci_name()) {
875 return dci_name (if_created_now);
883 Film::set_directory (string d)
885 boost::mutex::scoped_lock lm (_state_mutex);
891 Film::set_name (string n)
894 boost::mutex::scoped_lock lm (_state_mutex);
897 signal_changed (NAME);
901 Film::set_use_dci_name (bool u)
904 boost::mutex::scoped_lock lm (_state_mutex);
907 signal_changed (USE_DCI_NAME);
911 Film::set_content (string c)
913 string check = directory ();
915 boost::filesystem::path slash ("/");
916 string platform_slash = slash.make_preferred().string ();
918 if (!ends_with (check, platform_slash)) {
919 check += platform_slash;
922 if (boost::filesystem::path(c).has_root_directory () && starts_with (c, check)) {
923 c = c.substr (_directory.length() + 1);
929 boost::mutex::scoped_lock lm (_state_mutex);
934 old_content = _content;
938 /* Reset streams here in case the new content doesn't have one or the other */
939 _content_audio_stream = shared_ptr<AudioStream> ();
940 _subtitle_stream = shared_ptr<SubtitleStream> ();
942 /* Start off using content audio */
943 set_use_content_audio (true);
945 /* Create a temporary decoder so that we can get information
950 Decoders d = decoder_factory (shared_from_this(), DecodeOptions());
952 set_size (d.video->native_size ());
953 set_source_frame_rate (d.video->frames_per_second ());
954 set_dcp_frame_rate (best_dcp_frame_rate (source_frame_rate ()));
955 set_subtitle_streams (d.video->subtitle_streams ());
957 set_content_audio_streams (d.audio->audio_streams ());
961 boost::mutex::scoped_lock lm (_state_mutex);
965 signal_changed (CONTENT);
967 /* Start off with the first audio and subtitle streams */
968 if (d.audio && !d.audio->audio_streams().empty()) {
969 set_content_audio_stream (d.audio->audio_streams().front());
972 if (!d.video->subtitle_streams().empty()) {
973 set_subtitle_stream (d.video->subtitle_streams().front());
980 boost::mutex::scoped_lock lm (_state_mutex);
981 _content = old_content;
987 switch (content_type()) {
989 set_format (Format::from_id ("var-185"));
992 set_format (Format::from_id ("185"));
996 /* Still image DCPs must use external audio */
997 if (content_type() == STILL) {
998 set_use_content_audio (false);
1003 Film::set_trust_content_header (bool t)
1006 boost::mutex::scoped_lock lm (_state_mutex);
1007 _trust_content_header = t;
1010 signal_changed (TRUST_CONTENT_HEADER);
1012 if (!_trust_content_header && !content().empty()) {
1013 /* We just said that we don't trust the content's header */
1019 Film::set_dcp_content_type (DCPContentType const * t)
1022 boost::mutex::scoped_lock lm (_state_mutex);
1023 _dcp_content_type = t;
1025 signal_changed (DCP_CONTENT_TYPE);
1029 Film::set_format (Format const * f)
1032 boost::mutex::scoped_lock lm (_state_mutex);
1035 signal_changed (FORMAT);
1039 Film::set_crop (Crop c)
1042 boost::mutex::scoped_lock lm (_state_mutex);
1045 signal_changed (CROP);
1049 Film::set_left_crop (int c)
1052 boost::mutex::scoped_lock lm (_state_mutex);
1054 if (_crop.left == c) {
1060 signal_changed (CROP);
1064 Film::set_right_crop (int c)
1067 boost::mutex::scoped_lock lm (_state_mutex);
1068 if (_crop.right == c) {
1074 signal_changed (CROP);
1078 Film::set_top_crop (int c)
1081 boost::mutex::scoped_lock lm (_state_mutex);
1082 if (_crop.top == c) {
1088 signal_changed (CROP);
1092 Film::set_bottom_crop (int c)
1095 boost::mutex::scoped_lock lm (_state_mutex);
1096 if (_crop.bottom == c) {
1102 signal_changed (CROP);
1106 Film::set_filters (vector<Filter const *> f)
1109 boost::mutex::scoped_lock lm (_state_mutex);
1112 signal_changed (FILTERS);
1116 Film::set_scaler (Scaler const * s)
1119 boost::mutex::scoped_lock lm (_state_mutex);
1122 signal_changed (SCALER);
1126 Film::set_trim_start (int t)
1129 boost::mutex::scoped_lock lm (_state_mutex);
1132 signal_changed (TRIM_START);
1136 Film::set_trim_end (int t)
1139 boost::mutex::scoped_lock lm (_state_mutex);
1142 signal_changed (TRIM_END);
1146 Film::set_trim_type (TrimType t)
1149 boost::mutex::scoped_lock lm (_state_mutex);
1152 signal_changed (TRIM_TYPE);
1156 Film::set_dcp_ab (bool a)
1159 boost::mutex::scoped_lock lm (_state_mutex);
1162 signal_changed (DCP_AB);
1166 Film::set_content_audio_stream (shared_ptr<AudioStream> s)
1169 boost::mutex::scoped_lock lm (_state_mutex);
1170 _content_audio_stream = s;
1172 signal_changed (CONTENT_AUDIO_STREAM);
1176 Film::set_external_audio (vector<string> a)
1179 boost::mutex::scoped_lock lm (_state_mutex);
1180 _external_audio = a;
1183 shared_ptr<SndfileDecoder> decoder (new SndfileDecoder (shared_from_this(), DecodeOptions()));
1184 if (decoder->audio_stream()) {
1185 _sndfile_stream = decoder->audio_stream ();
1188 signal_changed (EXTERNAL_AUDIO);
1192 Film::set_use_content_audio (bool e)
1195 boost::mutex::scoped_lock lm (_state_mutex);
1196 _use_content_audio = e;
1199 signal_changed (USE_CONTENT_AUDIO);
1203 Film::set_audio_gain (float g)
1206 boost::mutex::scoped_lock lm (_state_mutex);
1209 signal_changed (AUDIO_GAIN);
1213 Film::set_audio_delay (int d)
1216 boost::mutex::scoped_lock lm (_state_mutex);
1219 signal_changed (AUDIO_DELAY);
1223 Film::set_still_duration (int d)
1226 boost::mutex::scoped_lock lm (_state_mutex);
1227 _still_duration = d;
1229 signal_changed (STILL_DURATION);
1233 Film::set_subtitle_stream (shared_ptr<SubtitleStream> s)
1236 boost::mutex::scoped_lock lm (_state_mutex);
1237 _subtitle_stream = s;
1239 signal_changed (SUBTITLE_STREAM);
1243 Film::set_with_subtitles (bool w)
1246 boost::mutex::scoped_lock lm (_state_mutex);
1247 _with_subtitles = w;
1249 signal_changed (WITH_SUBTITLES);
1253 Film::set_subtitle_offset (int o)
1256 boost::mutex::scoped_lock lm (_state_mutex);
1257 _subtitle_offset = o;
1259 signal_changed (SUBTITLE_OFFSET);
1263 Film::set_subtitle_scale (float s)
1266 boost::mutex::scoped_lock lm (_state_mutex);
1267 _subtitle_scale = s;
1269 signal_changed (SUBTITLE_SCALE);
1273 Film::set_colour_lut (int i)
1276 boost::mutex::scoped_lock lm (_state_mutex);
1279 signal_changed (COLOUR_LUT);
1283 Film::set_j2k_bandwidth (int b)
1286 boost::mutex::scoped_lock lm (_state_mutex);
1289 signal_changed (J2K_BANDWIDTH);
1293 Film::set_dci_metadata (DCIMetadata m)
1296 boost::mutex::scoped_lock lm (_state_mutex);
1299 signal_changed (DCI_METADATA);
1304 Film::set_dcp_frame_rate (int f)
1307 boost::mutex::scoped_lock lm (_state_mutex);
1308 _dcp_frame_rate = f;
1310 signal_changed (DCP_FRAME_RATE);
1314 Film::set_size (libdcp::Size s)
1317 boost::mutex::scoped_lock lm (_state_mutex);
1320 signal_changed (SIZE);
1324 Film::set_length (SourceFrame l)
1327 boost::mutex::scoped_lock lm (_state_mutex);
1330 signal_changed (LENGTH);
1334 Film::unset_length ()
1337 boost::mutex::scoped_lock lm (_state_mutex);
1338 _length = boost::none;
1340 signal_changed (LENGTH);
1344 Film::set_content_digest (string d)
1347 boost::mutex::scoped_lock lm (_state_mutex);
1348 _content_digest = d;
1354 Film::set_content_audio_streams (vector<shared_ptr<AudioStream> > s)
1357 boost::mutex::scoped_lock lm (_state_mutex);
1358 _content_audio_streams = s;
1360 signal_changed (CONTENT_AUDIO_STREAMS);
1364 Film::set_subtitle_streams (vector<shared_ptr<SubtitleStream> > s)
1367 boost::mutex::scoped_lock lm (_state_mutex);
1368 _subtitle_streams = s;
1370 signal_changed (SUBTITLE_STREAMS);
1374 Film::set_source_frame_rate (float f)
1377 boost::mutex::scoped_lock lm (_state_mutex);
1378 _source_frame_rate = f;
1380 signal_changed (SOURCE_FRAME_RATE);
1384 Film::signal_changed (Property p)
1387 boost::mutex::scoped_lock lm (_state_mutex);
1392 ui_signaller->emit (boost::bind (boost::ref (Changed), p));
1397 Film::audio_channels () const
1399 shared_ptr<AudioStream> s = audio_stream ();
1404 return s->channels ();
1408 Film::set_dci_date_today ()
1410 _dci_date = boost::gregorian::day_clock::local_day ();
1413 boost::shared_ptr<AudioStream>
1414 Film::audio_stream () const
1416 if (use_content_audio()) {
1417 return _content_audio_stream;
1420 return _sndfile_stream;
1424 Film::info_path (int f) const
1426 boost::filesystem::path p;
1431 s << setfill('0') << f << ".md5";
1435 /* info_dir() will already have added any initial bit of the path,
1436 so don't call file() on this.
1442 Film::j2c_path (int f, bool t) const
1444 boost::filesystem::path p;
1446 p /= video_state_identifier ();
1450 s << setfill('0') << f << ".j2c";
1457 return file (p.string ());
1460 /** Make an educated guess as to whether we have a complete DCP
1462 * @return true if we do.
1466 Film::have_dcp () const
1469 libdcp::DCP dcp (dir (dcp_name()));
1479 Film::has_audio () const
1481 if (use_content_audio()) {
1482 return audio_stream();
1485 vector<string> const e = external_audio ();
1486 for (vector<string>::const_iterator i = e.begin(); i != e.end(); ++i) {