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>
32 #include <libxml++/libxml++.h>
33 #include <libdcp/crypt_chain.h>
34 #include <libdcp/certificates.h>
40 #include "transcoder.h"
42 #include "job_manager.h"
43 #include "ab_transcode_job.h"
44 #include "transcode_job.h"
45 #include "scp_dcp_job.h"
46 #include "make_dcp_job.h"
49 #include "exceptions.h"
50 #include "examine_content_job.h"
52 #include "decoder_factory.h"
54 #include "check_hashes_job.h"
56 #include "ui_signaller.h"
57 #include "video_decoder.h"
58 #include "audio_decoder.h"
59 #include "external_audio_decoder.h"
62 using std::stringstream;
74 using boost::shared_ptr;
75 using boost::lexical_cast;
76 using boost::to_upper_copy;
77 using boost::ends_with;
78 using boost::starts_with;
79 using boost::optional;
81 int const Film::state_version = 1;
83 /** Construct a Film object in a given directory, reading any metadata
84 * file that exists in that directory. An exception will be thrown if
85 * must_exist is true and the specified directory does not exist.
87 * @param d Film directory.
88 * @param must_exist true to throw an exception if does not exist.
91 Film::Film (string d, bool must_exist)
92 : _use_dci_name (true)
93 , _trust_content_header (true)
94 , _dcp_content_type (0)
96 , _scaler (Scaler::from_id ("bicubic"))
100 , _use_content_audio (true)
103 , _still_duration (10)
104 , _with_subtitles (false)
105 , _subtitle_offset (0)
106 , _subtitle_scale (1)
108 , _frames_per_second (0)
111 /* Make state.directory a complete path without ..s (where possible)
112 (Code swiped from Adam Bowen on stackoverflow)
115 boost::filesystem::path p (boost::filesystem::system_complete (d));
116 boost::filesystem::path result;
117 for (boost::filesystem::path::iterator i = p.begin(); i != p.end(); ++i) {
119 if (boost::filesystem::is_symlink (result) || result.filename() == "..") {
122 result = result.parent_path ();
124 } else if (*i != ".") {
129 set_directory (result.string ());
131 if (!boost::filesystem::exists (directory())) {
133 throw OpenFileError (directory());
135 boost::filesystem::create_directory (directory());
139 _external_audio_stream = ExternalAudioStream::create ();
145 _log = new FileLog (file ("log"));
146 set_dci_date_today ();
149 Film::Film (Film const & o)
150 : boost::enable_shared_from_this<Film> (o)
152 , _directory (o._directory)
154 , _use_dci_name (o._use_dci_name)
155 , _content (o._content)
156 , _trust_content_header (o._trust_content_header)
157 , _dcp_content_type (o._dcp_content_type)
158 , _format (o._format)
160 , _filters (o._filters)
161 , _scaler (o._scaler)
162 , _dcp_trim_start (o._dcp_trim_start)
163 , _dcp_trim_end (o._dcp_trim_end)
164 , _dcp_ab (o._dcp_ab)
165 , _content_audio_stream (o._content_audio_stream)
166 , _external_audio (o._external_audio)
167 , _use_content_audio (o._use_content_audio)
168 , _audio_gain (o._audio_gain)
169 , _audio_delay (o._audio_delay)
170 , _still_duration (o._still_duration)
171 , _subtitle_stream (o._subtitle_stream)
172 , _with_subtitles (o._with_subtitles)
173 , _subtitle_offset (o._subtitle_offset)
174 , _subtitle_scale (o._subtitle_scale)
175 , _encrypted (o._encrypted)
176 , _audio_language (o._audio_language)
177 , _subtitle_language (o._subtitle_language)
178 , _territory (o._territory)
179 , _rating (o._rating)
180 , _studio (o._studio)
181 , _facility (o._facility)
182 , _package_type (o._package_type)
184 , _length (o._length)
185 , _content_digest (o._content_digest)
186 , _content_audio_streams (o._content_audio_streams)
187 , _external_audio_stream (o._external_audio_stream)
188 , _subtitle_streams (o._subtitle_streams)
189 , _frames_per_second (o._frames_per_second)
200 /** @return The path to the directory to write JPEG2000 files to */
202 Film::j2k_dir () const
206 boost::filesystem::path p;
211 pair<string, string> f = Filter::ffmpeg_strings (filters());
213 /* Write stuff to specify the filter / post-processing settings that are in use,
214 so that we don't get confused about J2K files generated using different
219 << "_" << content_digest()
220 << "_" << crop().left << "_" << crop().right << "_" << crop().top << "_" << crop().bottom
221 << "_" << f.first << "_" << f.second
222 << "_" << scaler()->id();
226 /* Similarly for the A/B case */
229 pair<string, string> fa = Filter::ffmpeg_strings (Config::instance()->reference_filters());
230 s << "ab_" << Config::instance()->reference_scaler()->id() << "_" << fa.first << "_" << fa.second;
234 return dir (p.string());
237 /** Add suitable Jobs to the JobManager to create a DCP for this Film.
238 * @param true to transcode, false to use the WAV and J2K files that are already there.
241 Film::make_dcp (bool transcode)
243 set_dci_date_today ();
245 if (dcp_name().find ("/") != string::npos) {
246 throw BadSettingError ("name", "cannot contain slashes");
249 log()->log (String::compose ("DVD-o-matic %1 git %2 using %3", dvdomatic_version, dvdomatic_git_commit, dependency_version_summary()));
253 gethostname (buffer, sizeof (buffer));
254 log()->log (String::compose ("Starting to make DCP on %1", buffer));
255 log()->log (String::compose ("Content is %1; type %2", content_path(), (content_type() == STILL ? "still" : "video")));
256 log()->log (String::compose ("Content length %1", length()));
260 throw MissingSettingError ("format");
263 if (content().empty ()) {
264 throw MissingSettingError ("content");
267 if (dcp_content_type() == 0) {
268 throw MissingSettingError ("content type");
271 if (name().empty()) {
272 throw MissingSettingError ("name");
275 shared_ptr<EncodeOptions> oe (new EncodeOptions (j2k_dir(), ".j2c", dir ("wavs")));
276 oe->out_size = format()->dcp_size ();
277 oe->padding = format()->dcp_padding (shared_from_this ());
279 oe->video_range = make_pair (dcp_trim_start(), dcp_trim_start() + dcp_length().get());
280 if (audio_stream()) {
281 oe->audio_range = make_pair (
283 video_frames_to_audio_frames (
284 oe->video_range.get().first,
285 dcp_audio_sample_rate (audio_stream()->sample_rate()),
286 dcp_frame_rate (frames_per_second()).frames_per_second
289 video_frames_to_audio_frames (
290 oe->video_range.get().second,
291 dcp_audio_sample_rate (audio_stream()->sample_rate()),
292 dcp_frame_rate (frames_per_second()).frames_per_second
299 oe->video_skip = dcp_frame_rate (frames_per_second()).skip;
301 shared_ptr<DecodeOptions> od (new DecodeOptions);
302 od->decode_subtitles = with_subtitles ();
308 r = JobManager::instance()->add (shared_ptr<Job> (new ABTranscodeJob (shared_from_this(), od, oe, shared_ptr<Job> ())));
310 r = JobManager::instance()->add (shared_ptr<Job> (new TranscodeJob (shared_from_this(), od, oe, shared_ptr<Job> ())));
314 r = JobManager::instance()->add (shared_ptr<Job> (new CheckHashesJob (shared_from_this(), od, oe, r)));
315 JobManager::instance()->add (shared_ptr<Job> (new MakeDCPJob (shared_from_this(), oe, r)));
318 /** Start a job to examine our content file */
320 Film::examine_content ()
322 if (_examine_content_job) {
326 _examine_content_job.reset (new ExamineContentJob (shared_from_this(), shared_ptr<Job> ()));
327 _examine_content_job->Finished.connect (bind (&Film::examine_content_finished, this));
328 JobManager::instance()->add (_examine_content_job);
332 Film::examine_content_finished ()
334 _examine_content_job.reset ();
337 /** @return full paths to any audio files that this Film has */
339 Film::audio_files () const
342 for (boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (dir("wavs")); i != boost::filesystem::directory_iterator(); ++i) {
343 f.push_back (i->path().string ());
349 /** Start a job to send our DCP to the configured TMS */
351 Film::send_dcp_to_tms ()
353 shared_ptr<Job> j (new SCPDCPJob (shared_from_this(), shared_ptr<Job> ()));
354 JobManager::instance()->add (j);
357 /** Count the number of frames that have been encoded for this film.
358 * @return frame count.
361 Film::encoded_frames () const
368 for (boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (j2k_dir ()); i != boost::filesystem::directory_iterator(); ++i) {
370 boost::this_thread::interruption_point ();
376 /** Write state to our `metadata' file */
378 Film::write_metadata () const
380 boost::mutex::scoped_lock lm (_state_mutex);
382 boost::filesystem::create_directories (directory());
384 string const m = file ("metadata");
385 ofstream f (m.c_str ());
387 throw CreateFileError (m);
390 f << "version " << state_version << "\n";
393 f << "name " << _name << "\n";
394 f << "use_dci_name " << _use_dci_name << "\n";
395 f << "content " << _content << "\n";
396 f << "trust_content_header " << (_trust_content_header ? "1" : "0") << "\n";
397 if (_dcp_content_type) {
398 f << "dcp_content_type " << _dcp_content_type->pretty_name () << "\n";
401 f << "format " << _format->as_metadata () << "\n";
403 f << "left_crop " << _crop.left << "\n";
404 f << "right_crop " << _crop.right << "\n";
405 f << "top_crop " << _crop.top << "\n";
406 f << "bottom_crop " << _crop.bottom << "\n";
407 for (vector<Filter const *>::const_iterator i = _filters.begin(); i != _filters.end(); ++i) {
408 f << "filter " << (*i)->id () << "\n";
410 f << "scaler " << _scaler->id () << "\n";
411 f << "dcp_trim_start " << _dcp_trim_start << "\n";
412 f << "dcp_trim_end " << _dcp_trim_end << "\n";
413 f << "dcp_ab " << (_dcp_ab ? "1" : "0") << "\n";
414 if (_content_audio_stream) {
415 f << "selected_content_audio_stream " << _content_audio_stream->to_string() << "\n";
417 for (vector<string>::const_iterator i = _external_audio.begin(); i != _external_audio.end(); ++i) {
418 f << "external_audio " << *i << "\n";
420 f << "use_content_audio " << (_use_content_audio ? "1" : "0") << "\n";
421 f << "audio_gain " << _audio_gain << "\n";
422 f << "audio_delay " << _audio_delay << "\n";
423 f << "still_duration " << _still_duration << "\n";
424 if (_subtitle_stream) {
425 f << "selected_subtitle_stream " << _subtitle_stream->to_string() << "\n";
427 f << "with_subtitles " << _with_subtitles << "\n";
428 f << "subtitle_offset " << _subtitle_offset << "\n";
429 f << "subtitle_scale " << _subtitle_scale << "\n";
430 f << "encrypted " << _encrypted << "\n";
431 f << "audio_language " << _audio_language << "\n";
432 f << "subtitle_language " << _subtitle_language << "\n";
433 f << "territory " << _territory << "\n";
434 f << "rating " << _rating << "\n";
435 f << "studio " << _studio << "\n";
436 f << "facility " << _facility << "\n";
437 f << "package_type " << _package_type << "\n";
439 f << "width " << _size.width << "\n";
440 f << "height " << _size.height << "\n";
441 f << "length " << _length.get_value_or(0) << "\n";
442 f << "content_digest " << _content_digest << "\n";
444 for (vector<shared_ptr<AudioStream> >::const_iterator i = _content_audio_streams.begin(); i != _content_audio_streams.end(); ++i) {
445 f << "content_audio_stream " << (*i)->to_string () << "\n";
448 f << "external_audio_stream " << _external_audio_stream->to_string() << "\n";
450 for (vector<shared_ptr<SubtitleStream> >::const_iterator i = _subtitle_streams.begin(); i != _subtitle_streams.end(); ++i) {
451 f << "subtitle_stream " << (*i)->to_string () << "\n";
454 f << "frames_per_second " << _frames_per_second << "\n";
459 /** Read state from our metadata file */
461 Film::read_metadata ()
463 boost::mutex::scoped_lock lm (_state_mutex);
465 _external_audio.clear ();
466 _content_audio_streams.clear ();
467 _subtitle_streams.clear ();
469 boost::optional<int> version;
471 /* Backward compatibility things */
472 boost::optional<int> audio_sample_rate;
473 boost::optional<int> audio_stream_index;
474 boost::optional<int> subtitle_stream_index;
476 ifstream f (file ("metadata").c_str());
478 throw OpenFileError (file("metadata"));
481 multimap<string, string> kv = read_key_value (f);
483 /* We need version before anything else */
484 multimap<string, string>::iterator v = kv.find ("version");
485 if (v != kv.end ()) {
486 version = atoi (v->second.c_str());
489 for (multimap<string, string>::const_iterator i = kv.begin(); i != kv.end(); ++i) {
490 string const k = i->first;
491 string const v = i->second;
493 if (k == "audio_sample_rate") {
494 audio_sample_rate = atoi (v.c_str());
497 /* User-specified stuff */
500 } else if (k == "use_dci_name") {
501 _use_dci_name = (v == "1");
502 } else if (k == "content") {
504 } else if (k == "trust_content_header") {
505 _trust_content_header = (v == "1");
506 } else if (k == "dcp_content_type") {
507 _dcp_content_type = DCPContentType::from_pretty_name (v);
508 } else if (k == "format") {
509 _format = Format::from_metadata (v);
510 } else if (k == "left_crop") {
511 _crop.left = atoi (v.c_str ());
512 } else if (k == "right_crop") {
513 _crop.right = atoi (v.c_str ());
514 } else if (k == "top_crop") {
515 _crop.top = atoi (v.c_str ());
516 } else if (k == "bottom_crop") {
517 _crop.bottom = atoi (v.c_str ());
518 } else if (k == "filter") {
519 _filters.push_back (Filter::from_id (v));
520 } else if (k == "scaler") {
521 _scaler = Scaler::from_id (v);
522 } else if (k == "dcp_trim_start") {
523 _dcp_trim_start = atoi (v.c_str ());
524 } else if (k == "dcp_trim_end") {
525 _dcp_trim_end = atoi (v.c_str ());
526 } else if (k == "dcp_ab") {
527 _dcp_ab = (v == "1");
528 } else if (k == "selected_content_audio_stream" || (!version && k == "selected_audio_stream")) {
530 audio_stream_index = atoi (v.c_str ());
532 _content_audio_stream = audio_stream_factory (v, version);
534 } else if (k == "external_audio") {
535 _external_audio.push_back (v);
536 } else if (k == "use_content_audio") {
537 _use_content_audio = (v == "1");
538 } else if (k == "audio_gain") {
539 _audio_gain = atof (v.c_str ());
540 } else if (k == "audio_delay") {
541 _audio_delay = atoi (v.c_str ());
542 } else if (k == "still_duration") {
543 _still_duration = atoi (v.c_str ());
544 } else if (k == "selected_subtitle_stream") {
546 subtitle_stream_index = atoi (v.c_str ());
548 _subtitle_stream = subtitle_stream_factory (v, version);
550 } else if (k == "with_subtitles") {
551 _with_subtitles = (v == "1");
552 } else if (k == "subtitle_offset") {
553 _subtitle_offset = atoi (v.c_str ());
554 } else if (k == "subtitle_scale") {
555 _subtitle_scale = atof (v.c_str ());
556 } else if (k == "encrypted") {
557 _encrypted = (v == "1");
558 } else if (k == "audio_language") {
560 } else if (k == "subtitle_language") {
561 _subtitle_language = v;
562 } else if (k == "territory") {
564 } else if (k == "rating") {
566 } else if (k == "studio") {
568 } else if (k == "facility") {
570 } else if (k == "package_type") {
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 == "content_digest") {
586 } else if (k == "content_audio_stream" || (!version && k == "audio_stream")) {
587 _content_audio_streams.push_back (audio_stream_factory (v, version));
588 } else if (k == "external_audio_stream") {
589 _external_audio_stream = audio_stream_factory (v, version);
590 } else if (k == "subtitle_stream") {
591 _subtitle_streams.push_back (subtitle_stream_factory (v, version));
592 } else if (k == "frames_per_second") {
593 _frames_per_second = atof (v.c_str ());
598 if (audio_sample_rate) {
599 /* version < 1 didn't specify sample rate in the audio streams, so fill it in here */
600 for (vector<shared_ptr<AudioStream> >::iterator i = _content_audio_streams.begin(); i != _content_audio_streams.end(); ++i) {
601 (*i)->set_sample_rate (audio_sample_rate.get());
605 /* also the selected stream was specified as an index */
606 if (audio_stream_index && audio_stream_index.get() >= 0 && audio_stream_index.get() < (int) _content_audio_streams.size()) {
607 _content_audio_stream = _content_audio_streams[audio_stream_index.get()];
610 /* similarly the subtitle */
611 if (subtitle_stream_index && subtitle_stream_index.get() >= 0 && subtitle_stream_index.get() < (int) _subtitle_streams.size()) {
612 _subtitle_stream = _subtitle_streams[subtitle_stream_index.get()];
620 Film::cropped_size (Size s) const
622 boost::mutex::scoped_lock lm (_state_mutex);
623 s.width -= _crop.left + _crop.right;
624 s.height -= _crop.top + _crop.bottom;
628 /** Given a directory name, return its full path within the Film's directory.
629 * The directory (and its parents) will be created if they do not exist.
632 Film::dir (string d) const
634 boost::mutex::scoped_lock lm (_directory_mutex);
635 boost::filesystem::path p;
638 boost::filesystem::create_directories (p);
642 /** Given a file or directory name, return its full path within the Film's directory.
643 * _directory_mutex must not be locked on entry.
646 Film::file (string f) const
648 boost::mutex::scoped_lock lm (_directory_mutex);
649 boost::filesystem::path p;
655 /** @return full path of the content (actual video) file
659 Film::content_path () const
661 boost::mutex::scoped_lock lm (_state_mutex);
662 if (boost::filesystem::path(_content).has_root_directory ()) {
666 return file (_content);
670 Film::content_type () const
672 if (boost::filesystem::is_directory (_content)) {
673 /* Directory of images, we assume */
677 if (still_image_file (_content)) {
684 /** @return The sampling rate that we will resample the audio to */
686 Film::target_audio_sample_rate () const
688 if (!audio_stream()) {
692 /* Resample to a DCI-approved sample rate */
693 double t = dcp_audio_sample_rate (audio_stream()->sample_rate());
695 DCPFrameRate dfr = dcp_frame_rate (frames_per_second ());
697 /* Compensate for the fact that video will be rounded to the
698 nearest integer number of frames per second.
701 t *= _frames_per_second * dfr.skip / dfr.frames_per_second;
708 Film::dcp_length () const
710 if (content_type() == STILL) {
711 return _still_duration * frames_per_second();
715 return boost::optional<int> ();
718 return length().get() - dcp_trim_start() - dcp_trim_end();
721 /** @return a DCI-compliant name for a DCP of this film */
723 Film::dci_name () const
727 string fixed_name = to_upper_copy (name());
728 for (size_t i = 0; i < fixed_name.length(); ++i) {
729 if (fixed_name[i] == ' ') {
734 /* Spec is that the name part should be maximum 14 characters, as I understand it */
735 if (fixed_name.length() > 14) {
736 fixed_name = fixed_name.substr (0, 14);
739 d << fixed_name << "_";
741 if (dcp_content_type()) {
742 d << dcp_content_type()->dci_name() << "_";
746 d << format()->dci_name() << "_";
749 if (!audio_language().empty ()) {
750 d << audio_language();
751 if (!subtitle_language().empty() && with_subtitles()) {
752 d << "-" << subtitle_language();
760 if (!territory().empty ()) {
762 if (!rating().empty ()) {
763 d << "-" << rating();
768 switch (audio_channels()) {
785 if (!studio().empty ()) {
786 d << studio() << "_";
789 d << boost::gregorian::to_iso_string (_dci_date) << "_";
791 if (!facility().empty ()) {
792 d << facility() << "_";
795 if (!package_type().empty ()) {
802 /** @return name to give the DCP */
804 Film::dcp_name () const
806 if (use_dci_name()) {
815 Film::set_directory (string d)
817 boost::mutex::scoped_lock lm (_state_mutex);
823 Film::set_name (string n)
826 boost::mutex::scoped_lock lm (_state_mutex);
829 signal_changed (NAME);
833 Film::set_use_dci_name (bool u)
836 boost::mutex::scoped_lock lm (_state_mutex);
839 signal_changed (USE_DCI_NAME);
843 Film::set_content (string c)
845 string check = directory ();
847 #if BOOST_FILESYSTEM_VERSION == 3
848 boost::filesystem::path slash ("/");
849 string platform_slash = slash.make_preferred().string ();
851 #ifdef DVDOMATIC_WINDOWS
852 string platform_slash = "\\";
854 string platform_slash = "/";
858 if (!ends_with (check, platform_slash)) {
859 check += platform_slash;
862 if (boost::filesystem::path(c).has_root_directory () && starts_with (c, check)) {
863 c = c.substr (_directory.length() + 1);
869 boost::mutex::scoped_lock lm (_state_mutex);
874 old_content = _content;
878 /* Reset streams here in case the new content doesn't have one or the other */
879 _content_audio_stream = shared_ptr<AudioStream> ();
880 _subtitle_stream = shared_ptr<SubtitleStream> ();
882 /* Start off using content audio */
883 set_use_content_audio (true);
885 /* Create a temporary decoder so that we can get information
890 shared_ptr<DecodeOptions> o (new DecodeOptions);
891 Decoders d = decoder_factory (shared_from_this(), o, 0);
893 set_size (d.video->native_size ());
894 set_frames_per_second (d.video->frames_per_second ());
895 set_subtitle_streams (d.video->subtitle_streams ());
897 set_content_audio_streams (d.audio->audio_streams ());
900 /* Start off with the first audio and subtitle streams */
901 if (d.audio && !d.audio->audio_streams().empty()) {
902 set_content_audio_stream (d.audio->audio_streams().front());
905 if (!d.video->subtitle_streams().empty()) {
906 set_subtitle_stream (d.video->subtitle_streams().front());
910 boost::mutex::scoped_lock lm (_state_mutex);
914 signal_changed (CONTENT);
920 boost::mutex::scoped_lock lm (_state_mutex);
921 _content = old_content;
927 switch (content_type()) {
929 set_format (Format::from_id ("var-185"));
932 set_format (Format::from_id ("185"));
936 /* Still image DCPs must use external audio */
937 if (content_type() == STILL) {
938 set_use_content_audio (false);
943 Film::set_trust_content_header (bool t)
946 boost::mutex::scoped_lock lm (_state_mutex);
947 _trust_content_header = t;
950 signal_changed (TRUST_CONTENT_HEADER);
952 if (!_trust_content_header && !content().empty()) {
953 /* We just said that we don't trust the content's header */
959 Film::set_dcp_content_type (DCPContentType const * t)
962 boost::mutex::scoped_lock lm (_state_mutex);
963 _dcp_content_type = t;
965 signal_changed (DCP_CONTENT_TYPE);
969 Film::set_format (Format const * f)
972 boost::mutex::scoped_lock lm (_state_mutex);
975 signal_changed (FORMAT);
979 Film::set_crop (Crop c)
982 boost::mutex::scoped_lock lm (_state_mutex);
985 signal_changed (CROP);
989 Film::set_left_crop (int c)
992 boost::mutex::scoped_lock lm (_state_mutex);
994 if (_crop.left == c) {
1000 signal_changed (CROP);
1004 Film::set_right_crop (int c)
1007 boost::mutex::scoped_lock lm (_state_mutex);
1008 if (_crop.right == c) {
1014 signal_changed (CROP);
1018 Film::set_top_crop (int c)
1021 boost::mutex::scoped_lock lm (_state_mutex);
1022 if (_crop.top == c) {
1028 signal_changed (CROP);
1032 Film::set_bottom_crop (int c)
1035 boost::mutex::scoped_lock lm (_state_mutex);
1036 if (_crop.bottom == c) {
1042 signal_changed (CROP);
1046 Film::set_filters (vector<Filter const *> f)
1049 boost::mutex::scoped_lock lm (_state_mutex);
1052 signal_changed (FILTERS);
1056 Film::set_scaler (Scaler const * s)
1059 boost::mutex::scoped_lock lm (_state_mutex);
1062 signal_changed (SCALER);
1066 Film::set_dcp_trim_start (int t)
1069 boost::mutex::scoped_lock lm (_state_mutex);
1070 _dcp_trim_start = t;
1072 signal_changed (DCP_TRIM_START);
1076 Film::set_dcp_trim_end (int t)
1079 boost::mutex::scoped_lock lm (_state_mutex);
1082 signal_changed (DCP_TRIM_END);
1086 Film::set_dcp_ab (bool a)
1089 boost::mutex::scoped_lock lm (_state_mutex);
1092 signal_changed (DCP_AB);
1096 Film::set_content_audio_stream (shared_ptr<AudioStream> s)
1099 boost::mutex::scoped_lock lm (_state_mutex);
1100 _content_audio_stream = s;
1102 signal_changed (CONTENT_AUDIO_STREAM);
1106 Film::set_external_audio (vector<string> a)
1109 boost::mutex::scoped_lock lm (_state_mutex);
1110 _external_audio = a;
1113 shared_ptr<DecodeOptions> o (new DecodeOptions);
1114 shared_ptr<ExternalAudioDecoder> decoder (new ExternalAudioDecoder (shared_from_this(), o, 0));
1115 if (decoder->audio_stream()) {
1116 _external_audio_stream = decoder->audio_stream ();
1119 signal_changed (EXTERNAL_AUDIO);
1123 Film::set_use_content_audio (bool e)
1126 boost::mutex::scoped_lock lm (_state_mutex);
1127 _use_content_audio = e;
1130 signal_changed (USE_CONTENT_AUDIO);
1134 Film::set_audio_gain (float g)
1137 boost::mutex::scoped_lock lm (_state_mutex);
1140 signal_changed (AUDIO_GAIN);
1144 Film::set_audio_delay (int d)
1147 boost::mutex::scoped_lock lm (_state_mutex);
1150 signal_changed (AUDIO_DELAY);
1154 Film::set_still_duration (int d)
1157 boost::mutex::scoped_lock lm (_state_mutex);
1158 _still_duration = d;
1160 signal_changed (STILL_DURATION);
1164 Film::set_subtitle_stream (shared_ptr<SubtitleStream> s)
1167 boost::mutex::scoped_lock lm (_state_mutex);
1168 _subtitle_stream = s;
1170 signal_changed (SUBTITLE_STREAM);
1174 Film::set_with_subtitles (bool w)
1177 boost::mutex::scoped_lock lm (_state_mutex);
1178 _with_subtitles = w;
1180 signal_changed (WITH_SUBTITLES);
1184 Film::set_subtitle_offset (int o)
1187 boost::mutex::scoped_lock lm (_state_mutex);
1188 _subtitle_offset = o;
1190 signal_changed (SUBTITLE_OFFSET);
1194 Film::set_subtitle_scale (float s)
1197 boost::mutex::scoped_lock lm (_state_mutex);
1198 _subtitle_scale = s;
1200 signal_changed (SUBTITLE_SCALE);
1204 Film::set_encrypted (bool e)
1207 boost::mutex::scoped_lock lm (_state_mutex);
1210 signal_changed (ENCRYPTED);
1214 Film::set_audio_language (string l)
1217 boost::mutex::scoped_lock lm (_state_mutex);
1218 _audio_language = l;
1220 signal_changed (DCI_METADATA);
1224 Film::set_subtitle_language (string l)
1227 boost::mutex::scoped_lock lm (_state_mutex);
1228 _subtitle_language = l;
1230 signal_changed (DCI_METADATA);
1234 Film::set_territory (string t)
1237 boost::mutex::scoped_lock lm (_state_mutex);
1240 signal_changed (DCI_METADATA);
1244 Film::set_rating (string r)
1247 boost::mutex::scoped_lock lm (_state_mutex);
1250 signal_changed (DCI_METADATA);
1254 Film::set_studio (string s)
1257 boost::mutex::scoped_lock lm (_state_mutex);
1260 signal_changed (DCI_METADATA);
1264 Film::set_facility (string f)
1267 boost::mutex::scoped_lock lm (_state_mutex);
1270 signal_changed (DCI_METADATA);
1274 Film::set_package_type (string p)
1277 boost::mutex::scoped_lock lm (_state_mutex);
1280 signal_changed (DCI_METADATA);
1284 Film::set_size (Size s)
1287 boost::mutex::scoped_lock lm (_state_mutex);
1290 signal_changed (SIZE);
1294 Film::set_length (SourceFrame l)
1297 boost::mutex::scoped_lock lm (_state_mutex);
1300 signal_changed (LENGTH);
1304 Film::unset_length ()
1307 boost::mutex::scoped_lock lm (_state_mutex);
1308 _length = boost::none;
1310 signal_changed (LENGTH);
1314 Film::set_content_digest (string d)
1317 boost::mutex::scoped_lock lm (_state_mutex);
1318 _content_digest = d;
1324 Film::set_content_audio_streams (vector<shared_ptr<AudioStream> > s)
1327 boost::mutex::scoped_lock lm (_state_mutex);
1328 _content_audio_streams = s;
1330 signal_changed (CONTENT_AUDIO_STREAMS);
1334 Film::set_subtitle_streams (vector<shared_ptr<SubtitleStream> > s)
1337 boost::mutex::scoped_lock lm (_state_mutex);
1338 _subtitle_streams = s;
1340 signal_changed (SUBTITLE_STREAMS);
1344 Film::set_frames_per_second (float f)
1347 boost::mutex::scoped_lock lm (_state_mutex);
1348 _frames_per_second = f;
1350 signal_changed (FRAMES_PER_SECOND);
1354 Film::signal_changed (Property p)
1357 boost::mutex::scoped_lock lm (_state_mutex);
1362 ui_signaller->emit (boost::bind (boost::ref (Changed), p));
1367 Film::audio_channels () const
1369 shared_ptr<AudioStream> s = audio_stream ();
1374 return s->channels ();
1378 Film::set_dci_date_today ()
1380 _dci_date = boost::gregorian::day_clock::local_day ();
1383 boost::shared_ptr<AudioStream>
1384 Film::audio_stream () const
1386 if (use_content_audio()) {
1387 return _content_audio_stream;
1390 return _external_audio_stream;
1395 list<shared_ptr<Screen> > screens,
1396 boost::posix_time::ptime from,
1397 boost::posix_time::ptime until,
1401 string const cd = Config::instance()->crypt_chain_directory ();
1402 if (boost::filesystem::is_empty (cd)) {
1403 libdcp::make_crypt_chain (cd);
1406 libdcp::CertificateChain chain;
1409 boost::filesystem::path p (cd);
1410 p /= "ca.self-signed.pem";
1411 chain.add (shared_ptr<libdcp::Certificate> (new libdcp::Certificate (p.string ())));
1415 boost::filesystem::path p (cd);
1416 p /= "intermediate.signed.pem";
1417 chain.add (shared_ptr<libdcp::Certificate> (new libdcp::Certificate (p.string ())));
1421 boost::filesystem::path p (cd);
1422 p /= "leaf.signed.pem";
1423 chain.add (shared_ptr<libdcp::Certificate> (new libdcp::Certificate (p.string ())));
1426 boost::filesystem::path signer_key (cd);
1427 signer_key /= "leaf.key";
1429 /* Find the DCP to make the KDM for */
1430 string const dir = this->directory ();
1432 for (boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator(dir); i != boost::filesystem::directory_iterator(); ++i) {
1433 if (boost::filesystem::is_directory (*i) && i->path().leaf() != "j2c" && i->path().leaf() != "wavs") {
1434 dcps.push_back (i->path().string());
1439 throw KDMError ("Could not find DCP to make KDM for");
1440 } else if (dcps.size() > 1) {
1441 throw KDMError ("More than one possible DCP to make KDM for");
1444 for (list<shared_ptr<Screen> >::iterator i = screens.begin(); i != screens.end(); ++i) {
1446 libdcp::DCP dcp (dcps.front ());
1449 /* XXX: single CPL only */
1450 shared_ptr<xmlpp::Document> kdm = dcp.cpls().front()->make_kdm (chain, signer_key.string(), (*i)->certificate, from, until);
1452 boost::filesystem::path out = directory;
1454 kdm->write_to_file_formatted (out.string());