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;
69 using boost::shared_ptr;
70 using boost::lexical_cast;
71 using boost::to_upper_copy;
72 using boost::ends_with;
73 using boost::starts_with;
74 using boost::optional;
77 int const Film::state_version = 3;
79 /** Construct a Film object in a given directory, reading any metadata
80 * file that exists in that directory. An exception will be thrown if
81 * must_exist is true and the specified directory does not exist.
83 * @param d Film directory.
84 * @param must_exist true to throw an exception if does not exist.
87 Film::Film (string d, bool must_exist)
88 : _use_dci_name (true)
89 , _trust_content_header (true)
90 , _dcp_content_type (0)
92 , _scaler (Scaler::from_id (N_("bicubic")))
96 , _use_content_audio (true)
99 , _still_duration (10)
100 , _with_subtitles (false)
101 , _subtitle_offset (0)
102 , _subtitle_scale (1)
104 , _j2k_bandwidth (200000000)
105 , _dci_metadata (Config::instance()->default_dci_metadata ())
106 , _frames_per_second (0)
109 set_dci_date_today ();
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) {
118 if (*i == N_("..")) {
119 if (boost::filesystem::is_symlink (result) || result.filename() == N_("..")) {
122 result = result.parent_path ();
124 } else if (*i != N_(".")) {
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 (N_("log")));
148 Film::Film (Film const & o)
149 : boost::enable_shared_from_this<Film> (o)
151 , _directory (o._directory)
153 , _use_dci_name (o._use_dci_name)
154 , _content (o._content)
155 , _trust_content_header (o._trust_content_header)
156 , _dcp_content_type (o._dcp_content_type)
157 , _format (o._format)
159 , _filters (o._filters)
160 , _scaler (o._scaler)
161 , _trim_start (o._trim_start)
162 , _trim_end (o._trim_end)
163 , _dcp_ab (o._dcp_ab)
164 , _content_audio_stream (o._content_audio_stream)
165 , _external_audio (o._external_audio)
166 , _use_content_audio (o._use_content_audio)
167 , _audio_gain (o._audio_gain)
168 , _audio_delay (o._audio_delay)
169 , _still_duration (o._still_duration)
170 , _subtitle_stream (o._subtitle_stream)
171 , _with_subtitles (o._with_subtitles)
172 , _subtitle_offset (o._subtitle_offset)
173 , _subtitle_scale (o._subtitle_scale)
174 , _colour_lut (o._colour_lut)
175 , _j2k_bandwidth (o._j2k_bandwidth)
176 , _dci_metadata (o._dci_metadata)
177 , _dci_date (o._dci_date)
179 , _length (o._length)
180 , _dcp_intrinsic_duration (o._dcp_intrinsic_duration)
181 , _content_digest (o._content_digest)
182 , _content_audio_streams (o._content_audio_streams)
183 , _external_audio_stream (o._external_audio_stream)
184 , _subtitle_streams (o._subtitle_streams)
185 , _frames_per_second (o._frames_per_second)
197 Film::video_state_identifier () const
201 pair<string, string> f = Filter::ffmpeg_strings (filters());
205 << N_("_") << content_digest()
206 << N_("_") << crop().left << N_("_") << crop().right << N_("_") << crop().top << N_("_") << crop().bottom
207 << N_("_") << f.first << N_("_") << f.second
208 << N_("_") << scaler()->id()
209 << N_("_") << j2k_bandwidth()
210 << N_("_") << boost::lexical_cast<int> (colour_lut());
213 pair<string, string> fa = Filter::ffmpeg_strings (Config::instance()->reference_filters());
214 s << N_("ab_") << Config::instance()->reference_scaler()->id() << N_("_") << fa.first << N_("_") << fa.second;
220 /** @return The path to the directory to write video frame info files to */
222 Film::info_dir () const
224 boost::filesystem::path p;
226 p /= video_state_identifier ();
227 return dir (p.string());
231 Film::video_mxf_dir () const
233 boost::filesystem::path p;
234 return dir (N_("video"));
238 Film::video_mxf_filename () const
240 return video_state_identifier() + N_(".mxf");
244 Film::audio_analysis_path () const
246 boost::filesystem::path p;
248 p /= content_digest();
249 return file (p.string ());
252 /** Add suitable Jobs to the JobManager to create a DCP for this Film */
256 set_dci_date_today ();
258 if (dcp_name().find (N_("/")) != string::npos) {
259 throw BadSettingError (_("name"), _("cannot contain slashes"));
262 log()->log (String::compose (N_("DVD-o-matic %1 git %2 using %3"), dvdomatic_version, dvdomatic_git_commit, dependency_version_summary()));
266 gethostname (buffer, sizeof (buffer));
267 log()->log (String::compose (N_("Starting to make DCP on %1"), buffer));
270 log()->log (String::compose (N_("Content is %1; type %2"), content_path(), (content_type() == STILL ? _("still") : _("video"))));
272 log()->log (String::compose (N_("Content length %1"), length().get()));
274 log()->log (String::compose (N_("Content digest %1"), content_digest()));
275 log()->log (String::compose (N_("%1 threads"), Config::instance()->num_local_encoding_threads()));
276 log()->log (String::compose (N_("J2K bandwidth %1"), j2k_bandwidth()));
277 #ifdef DVDOMATIC_DEBUG
278 log()->log (N_("DVD-o-matic built in debug mode."));
280 log()->log (N_("DVD-o-matic built in optimised mode."));
283 log()->log (N_("libdcp built in debug mode."));
285 log()->log (N_("libdcp built in optimised mode."));
287 pair<string, int> const c = cpu_info ();
288 log()->log (String::compose (N_("CPU: %1, %2 processors"), c.first, c.second));
291 throw MissingSettingError (_("format"));
294 if (content().empty ()) {
295 throw MissingSettingError (_("content"));
298 if (dcp_content_type() == 0) {
299 throw MissingSettingError (_("content type"));
302 if (name().empty()) {
303 throw MissingSettingError (_("name"));
307 od.decode_subtitles = with_subtitles ();
312 r = JobManager::instance()->add (shared_ptr<Job> (new ABTranscodeJob (shared_from_this(), od)));
314 r = JobManager::instance()->add (shared_ptr<Job> (new TranscodeJob (shared_from_this(), od)));
318 /** Start a job to analyse the audio of our content file */
320 Film::analyse_audio ()
322 if (_analyse_audio_job) {
326 _analyse_audio_job.reset (new AnalyseAudioJob (shared_from_this()));
327 _analyse_audio_job->Finished.connect (bind (&Film::analyse_audio_finished, this));
328 JobManager::instance()->add (_analyse_audio_job);
331 /** Start a job to examine our content file */
333 Film::examine_content ()
335 if (_examine_content_job) {
339 _examine_content_job.reset (new ExamineContentJob (shared_from_this()));
340 _examine_content_job->Finished.connect (bind (&Film::examine_content_finished, this));
341 JobManager::instance()->add (_examine_content_job);
345 Film::analyse_audio_finished ()
348 _analyse_audio_job.reset ();
350 AudioAnalysisFinished ();
354 Film::examine_content_finished ()
356 _examine_content_job.reset ();
359 /** Start a job to send our DCP to the configured TMS */
361 Film::send_dcp_to_tms ()
363 shared_ptr<Job> j (new SCPDCPJob (shared_from_this()));
364 JobManager::instance()->add (j);
367 /** Count the number of frames that have been encoded for this film.
368 * @return frame count.
371 Film::encoded_frames () const
378 for (boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (info_dir ()); i != boost::filesystem::directory_iterator(); ++i) {
380 boost::this_thread::interruption_point ();
386 /** Write state to our `metadata' file */
388 Film::write_metadata () const
390 boost::mutex::scoped_lock lm (_state_mutex);
392 boost::filesystem::create_directories (directory());
394 string const m = file (N_("metadata"));
395 ofstream f (m.c_str ());
397 throw CreateFileError (m);
400 f << N_("version ") << state_version << N_("\n");
403 f << N_("name ") << _name << N_("\n");
404 f << N_("use_dci_name ") << _use_dci_name << N_("\n");
405 f << N_("content ") << _content << N_("\n");
406 f << N_("trust_content_header ") << (_trust_content_header ? N_("1") : N_("0")) << N_("\n");
407 if (_dcp_content_type) {
408 f << N_("dcp_content_type ") << _dcp_content_type->dci_name () << N_("\n");
411 f << N_("format ") << _format->as_metadata () << N_("\n");
413 f << N_("left_crop ") << _crop.left << N_("\n");
414 f << N_("right_crop ") << _crop.right << N_("\n");
415 f << N_("top_crop ") << _crop.top << N_("\n");
416 f << N_("bottom_crop ") << _crop.bottom << N_("\n");
417 for (vector<Filter const *>::const_iterator i = _filters.begin(); i != _filters.end(); ++i) {
418 f << N_("filter ") << (*i)->id () << N_("\n");
420 f << N_("scaler ") << _scaler->id () << N_("\n");
421 f << N_("trim_start ") << _trim_start << N_("\n");
422 f << N_("trim_end ") << _trim_end << N_("\n");
423 f << N_("dcp_ab ") << (_dcp_ab ? N_("1") : N_("0")) << N_("\n");
424 if (_content_audio_stream) {
425 f << N_("selected_content_audio_stream ") << _content_audio_stream->to_string() << N_("\n");
427 for (vector<string>::const_iterator i = _external_audio.begin(); i != _external_audio.end(); ++i) {
428 f << N_("external_audio ") << *i << N_("\n");
430 f << N_("use_content_audio ") << (_use_content_audio ? N_("1") : N_("0")) << N_("\n");
431 f << N_("audio_gain ") << _audio_gain << N_("\n");
432 f << N_("audio_delay ") << _audio_delay << N_("\n");
433 f << N_("still_duration ") << _still_duration << N_("\n");
434 if (_subtitle_stream) {
435 f << N_("selected_subtitle_stream ") << _subtitle_stream->to_string() << N_("\n");
437 f << N_("with_subtitles ") << _with_subtitles << N_("\n");
438 f << N_("subtitle_offset ") << _subtitle_offset << N_("\n");
439 f << N_("subtitle_scale ") << _subtitle_scale << N_("\n");
440 f << N_("colour_lut ") << _colour_lut << N_("\n");
441 f << N_("j2k_bandwidth ") << _j2k_bandwidth << N_("\n");
442 _dci_metadata.write (f);
443 f << N_("dci_date ") << boost::gregorian::to_iso_string (_dci_date) << N_("\n");
444 f << N_("width ") << _size.width << N_("\n");
445 f << N_("height ") << _size.height << N_("\n");
446 f << N_("length ") << _length.get_value_or(0) << N_("\n");
447 f << N_("dcp_intrinsic_duration ") << _dcp_intrinsic_duration.get_value_or(0) << N_("\n");
448 f << N_("content_digest ") << _content_digest << N_("\n");
450 for (vector<shared_ptr<AudioStream> >::const_iterator i = _content_audio_streams.begin(); i != _content_audio_streams.end(); ++i) {
451 f << N_("content_audio_stream ") << (*i)->to_string () << N_("\n");
454 f << N_("external_audio_stream ") << _external_audio_stream->to_string() << N_("\n");
456 for (vector<shared_ptr<SubtitleStream> >::const_iterator i = _subtitle_streams.begin(); i != _subtitle_streams.end(); ++i) {
457 f << N_("subtitle_stream ") << (*i)->to_string () << N_("\n");
460 f << N_("frames_per_second ") << _frames_per_second << N_("\n");
465 /** Read state from our metadata file */
467 Film::read_metadata ()
469 boost::mutex::scoped_lock lm (_state_mutex);
471 _external_audio.clear ();
472 _content_audio_streams.clear ();
473 _subtitle_streams.clear ();
475 boost::optional<int> version;
477 /* Backward compatibility things */
478 boost::optional<int> audio_sample_rate;
479 boost::optional<int> audio_stream_index;
480 boost::optional<int> subtitle_stream_index;
482 ifstream f (file (N_("metadata")).c_str());
484 throw OpenFileError (file (N_("metadata")));
487 multimap<string, string> kv = read_key_value (f);
489 /* We need version before anything else */
490 multimap<string, string>::iterator v = kv.find (N_("version"));
491 if (v != kv.end ()) {
492 version = atoi (v->second.c_str());
495 for (multimap<string, string>::const_iterator i = kv.begin(); i != kv.end(); ++i) {
496 string const k = i->first;
497 string const v = i->second;
499 if (k == N_("audio_sample_rate")) {
500 audio_sample_rate = atoi (v.c_str());
503 /* User-specified stuff */
504 if (k == N_("name")) {
506 } else if (k == N_("use_dci_name")) {
507 _use_dci_name = (v == N_("1"));
508 } else if (k == N_("content")) {
510 } else if (k == N_("trust_content_header")) {
511 _trust_content_header = (v == N_("1"));
512 } else if (k == N_("dcp_content_type")) {
514 _dcp_content_type = DCPContentType::from_pretty_name (v);
516 _dcp_content_type = DCPContentType::from_dci_name (v);
518 } else if (k == N_("format")) {
519 _format = Format::from_metadata (v);
520 } else if (k == N_("left_crop")) {
521 _crop.left = atoi (v.c_str ());
522 } else if (k == N_("right_crop")) {
523 _crop.right = atoi (v.c_str ());
524 } else if (k == N_("top_crop")) {
525 _crop.top = atoi (v.c_str ());
526 } else if (k == N_("bottom_crop")) {
527 _crop.bottom = atoi (v.c_str ());
528 } else if (k == N_("filter")) {
529 _filters.push_back (Filter::from_id (v));
530 } else if (k == N_("scaler")) {
531 _scaler = Scaler::from_id (v);
532 } else if ( ((!version || version < 2) && k == N_("dcp_trim_start")) || k == N_("trim_start")) {
533 _trim_start = atoi (v.c_str ());
534 } else if ( ((!version || version < 2) && k == N_("dcp_trim_end")) || k == N_("trim_end")) {
535 _trim_end = atoi (v.c_str ());
536 } else if (k == N_("dcp_ab")) {
537 _dcp_ab = (v == N_("1"));
538 } else if (k == N_("selected_content_audio_stream") || (!version && k == N_("selected_audio_stream"))) {
540 audio_stream_index = atoi (v.c_str ());
542 _content_audio_stream = audio_stream_factory (v, version);
544 } else if (k == N_("external_audio")) {
545 _external_audio.push_back (v);
546 } else if (k == N_("use_content_audio")) {
547 _use_content_audio = (v == N_("1"));
548 } else if (k == N_("audio_gain")) {
549 _audio_gain = atof (v.c_str ());
550 } else if (k == N_("audio_delay")) {
551 _audio_delay = atoi (v.c_str ());
552 } else if (k == N_("still_duration")) {
553 _still_duration = atoi (v.c_str ());
554 } else if (k == N_("selected_subtitle_stream")) {
556 subtitle_stream_index = atoi (v.c_str ());
558 _subtitle_stream = subtitle_stream_factory (v, version);
560 } else if (k == N_("with_subtitles")) {
561 _with_subtitles = (v == N_("1"));
562 } else if (k == N_("subtitle_offset")) {
563 _subtitle_offset = atoi (v.c_str ());
564 } else if (k == N_("subtitle_scale")) {
565 _subtitle_scale = atof (v.c_str ());
566 } else if (k == N_("colour_lut")) {
567 _colour_lut = atoi (v.c_str ());
568 } else if (k == N_("j2k_bandwidth")) {
569 _j2k_bandwidth = atoi (v.c_str ());
570 } else if (k == N_("dci_date")) {
571 _dci_date = boost::gregorian::from_undelimited_string (v);
574 _dci_metadata.read (k, v);
577 if (k == N_("width")) {
578 _size.width = atoi (v.c_str ());
579 } else if (k == N_("height")) {
580 _size.height = atoi (v.c_str ());
581 } else if (k == N_("length")) {
582 int const vv = atoi (v.c_str ());
586 } else if (k == N_("dcp_intrinsic_duration")) {
587 int const vv = atoi (v.c_str ());
589 _dcp_intrinsic_duration = vv;
591 } else if (k == N_("content_digest")) {
593 } else if (k == N_("content_audio_stream") || (!version && k == N_("audio_stream"))) {
594 _content_audio_streams.push_back (audio_stream_factory (v, version));
595 } else if (k == N_("external_audio_stream")) {
596 _external_audio_stream = audio_stream_factory (v, version);
597 } else if (k == N_("subtitle_stream")) {
598 _subtitle_streams.push_back (subtitle_stream_factory (v, version));
599 } else if (k == N_("frames_per_second")) {
600 _frames_per_second = atof (v.c_str ());
605 if (audio_sample_rate) {
606 /* version < 1 didn't specify sample rate in the audio streams, so fill it in here */
607 for (vector<shared_ptr<AudioStream> >::iterator i = _content_audio_streams.begin(); i != _content_audio_streams.end(); ++i) {
608 (*i)->set_sample_rate (audio_sample_rate.get());
612 /* also the selected stream was specified as an index */
613 if (audio_stream_index && audio_stream_index.get() >= 0 && audio_stream_index.get() < (int) _content_audio_streams.size()) {
614 _content_audio_stream = _content_audio_streams[audio_stream_index.get()];
617 /* similarly the subtitle */
618 if (subtitle_stream_index && subtitle_stream_index.get() >= 0 && subtitle_stream_index.get() < (int) _subtitle_streams.size()) {
619 _subtitle_stream = _subtitle_streams[subtitle_stream_index.get()];
627 Film::cropped_size (libdcp::Size s) const
629 boost::mutex::scoped_lock lm (_state_mutex);
630 s.width -= _crop.left + _crop.right;
631 s.height -= _crop.top + _crop.bottom;
635 /** Given a directory name, return its full path within the Film's directory.
636 * The directory (and its parents) will be created if they do not exist.
639 Film::dir (string d) const
641 boost::mutex::scoped_lock lm (_directory_mutex);
643 boost::filesystem::path p;
647 boost::filesystem::create_directories (p);
652 /** Given a file or directory name, return its full path within the Film's directory.
653 * _directory_mutex must not be locked on entry.
654 * Any required parent directories will be created.
657 Film::file (string f) const
659 boost::mutex::scoped_lock lm (_directory_mutex);
661 boost::filesystem::path p;
665 boost::filesystem::create_directories (p.parent_path ());
670 /** @return full path of the content (actual video) file
674 Film::content_path () const
676 boost::mutex::scoped_lock lm (_state_mutex);
677 if (boost::filesystem::path(_content).has_root_directory ()) {
681 return file (_content);
685 Film::content_type () const
687 if (boost::filesystem::is_directory (_content)) {
688 /* Directory of images, we assume */
692 if (still_image_file (_content)) {
699 /** @return The sampling rate that we will resample the audio to */
701 Film::target_audio_sample_rate () const
703 if (!audio_stream()) {
707 /* Resample to a DCI-approved sample rate */
708 double t = dcp_audio_sample_rate (audio_stream()->sample_rate());
710 DCPFrameRate dfr (frames_per_second ());
712 /* Compensate if the DCP is being run at a different frame rate
713 to the source; that is, if the video is run such that it will
714 look different in the DCP compared to the source (slower or faster).
715 skip/repeat doesn't come into effect here.
718 if (dfr.change_speed) {
719 t *= _frames_per_second * dfr.factor() / dfr.frames_per_second;
726 Film::still_duration_in_frames () const
728 return still_duration() * frames_per_second();
731 /** @return a DCI-compliant name for a DCP of this film */
733 Film::dci_name (bool if_created_now) const
737 string fixed_name = to_upper_copy (name());
738 for (size_t i = 0; i < fixed_name.length(); ++i) {
739 if (fixed_name[i] == ' ') {
744 /* Spec is that the name part should be maximum 14 characters, as I understand it */
745 if (fixed_name.length() > 14) {
746 fixed_name = fixed_name.substr (0, 14);
749 d << fixed_name << N_("_");
751 if (dcp_content_type()) {
752 d << dcp_content_type()->dci_name() << N_("_");
756 d << format()->dci_name() << N_("_");
759 DCIMetadata const dm = dci_metadata ();
761 if (!dm.audio_language.empty ()) {
762 d << dm.audio_language;
763 if (!dm.subtitle_language.empty() && with_subtitles()) {
764 d << N_("-") << dm.subtitle_language;
772 if (!dm.territory.empty ()) {
774 if (!dm.rating.empty ()) {
775 d << N_("-") << dm.rating;
780 switch (audio_channels()) {
797 if (!dm.studio.empty ()) {
798 d << dm.studio << N_("_");
801 if (if_created_now) {
802 d << boost::gregorian::to_iso_string (boost::gregorian::day_clock::local_day ()) << N_("_");
804 d << boost::gregorian::to_iso_string (_dci_date) << N_("_");
807 if (!dm.facility.empty ()) {
808 d << dm.facility << N_("_");
811 if (!dm.package_type.empty ()) {
812 d << dm.package_type;
818 /** @return name to give the DCP */
820 Film::dcp_name (bool if_created_now) const
822 if (use_dci_name()) {
823 return dci_name (if_created_now);
831 Film::set_directory (string d)
833 boost::mutex::scoped_lock lm (_state_mutex);
839 Film::set_name (string n)
842 boost::mutex::scoped_lock lm (_state_mutex);
845 signal_changed (NAME);
849 Film::set_use_dci_name (bool u)
852 boost::mutex::scoped_lock lm (_state_mutex);
855 signal_changed (USE_DCI_NAME);
859 Film::set_content (string c)
861 string check = directory ();
863 boost::filesystem::path slash (N_("/"));
864 string platform_slash = slash.make_preferred().string ();
866 if (!ends_with (check, platform_slash)) {
867 check += platform_slash;
870 if (boost::filesystem::path(c).has_root_directory () && starts_with (c, check)) {
871 c = c.substr (_directory.length() + 1);
877 boost::mutex::scoped_lock lm (_state_mutex);
882 old_content = _content;
886 /* Reset streams here in case the new content doesn't have one or the other */
887 _content_audio_stream = shared_ptr<AudioStream> ();
888 _subtitle_stream = shared_ptr<SubtitleStream> ();
890 /* Start off using content audio */
891 set_use_content_audio (true);
893 /* Create a temporary decoder so that we can get information
898 Decoders d = decoder_factory (shared_from_this(), DecodeOptions());
900 set_size (d.video->native_size ());
901 set_frames_per_second (d.video->frames_per_second ());
902 set_subtitle_streams (d.video->subtitle_streams ());
904 set_content_audio_streams (d.audio->audio_streams ());
908 boost::mutex::scoped_lock lm (_state_mutex);
912 signal_changed (CONTENT);
914 /* Start off with the first audio and subtitle streams */
915 if (d.audio && !d.audio->audio_streams().empty()) {
916 set_content_audio_stream (d.audio->audio_streams().front());
919 if (!d.video->subtitle_streams().empty()) {
920 set_subtitle_stream (d.video->subtitle_streams().front());
927 boost::mutex::scoped_lock lm (_state_mutex);
928 _content = old_content;
934 switch (content_type()) {
936 set_format (Format::from_id (N_("var-185")));
939 set_format (Format::from_id (N_("185")));
943 /* Still image DCPs must use external audio */
944 if (content_type() == STILL) {
945 set_use_content_audio (false);
950 Film::set_trust_content_header (bool t)
953 boost::mutex::scoped_lock lm (_state_mutex);
954 _trust_content_header = t;
957 signal_changed (TRUST_CONTENT_HEADER);
959 if (!_trust_content_header && !content().empty()) {
960 /* We just said that we don't trust the content's header */
966 Film::set_dcp_content_type (DCPContentType const * t)
969 boost::mutex::scoped_lock lm (_state_mutex);
970 _dcp_content_type = t;
972 signal_changed (DCP_CONTENT_TYPE);
976 Film::set_format (Format const * f)
979 boost::mutex::scoped_lock lm (_state_mutex);
982 signal_changed (FORMAT);
986 Film::set_crop (Crop c)
989 boost::mutex::scoped_lock lm (_state_mutex);
992 signal_changed (CROP);
996 Film::set_left_crop (int c)
999 boost::mutex::scoped_lock lm (_state_mutex);
1001 if (_crop.left == c) {
1007 signal_changed (CROP);
1011 Film::set_right_crop (int c)
1014 boost::mutex::scoped_lock lm (_state_mutex);
1015 if (_crop.right == c) {
1021 signal_changed (CROP);
1025 Film::set_top_crop (int c)
1028 boost::mutex::scoped_lock lm (_state_mutex);
1029 if (_crop.top == c) {
1035 signal_changed (CROP);
1039 Film::set_bottom_crop (int c)
1042 boost::mutex::scoped_lock lm (_state_mutex);
1043 if (_crop.bottom == c) {
1049 signal_changed (CROP);
1053 Film::set_filters (vector<Filter const *> f)
1056 boost::mutex::scoped_lock lm (_state_mutex);
1059 signal_changed (FILTERS);
1063 Film::set_scaler (Scaler const * s)
1066 boost::mutex::scoped_lock lm (_state_mutex);
1069 signal_changed (SCALER);
1073 Film::set_trim_start (int t)
1076 boost::mutex::scoped_lock lm (_state_mutex);
1079 signal_changed (TRIM_START);
1083 Film::set_trim_end (int t)
1086 boost::mutex::scoped_lock lm (_state_mutex);
1089 signal_changed (TRIM_END);
1093 Film::set_dcp_ab (bool a)
1096 boost::mutex::scoped_lock lm (_state_mutex);
1099 signal_changed (DCP_AB);
1103 Film::set_content_audio_stream (shared_ptr<AudioStream> s)
1106 boost::mutex::scoped_lock lm (_state_mutex);
1107 _content_audio_stream = s;
1109 signal_changed (CONTENT_AUDIO_STREAM);
1113 Film::set_external_audio (vector<string> a)
1116 boost::mutex::scoped_lock lm (_state_mutex);
1117 _external_audio = a;
1120 shared_ptr<ExternalAudioDecoder> decoder (new ExternalAudioDecoder (shared_from_this(), DecodeOptions()));
1121 if (decoder->audio_stream()) {
1122 _external_audio_stream = decoder->audio_stream ();
1125 signal_changed (EXTERNAL_AUDIO);
1129 Film::set_use_content_audio (bool e)
1132 boost::mutex::scoped_lock lm (_state_mutex);
1133 _use_content_audio = e;
1136 signal_changed (USE_CONTENT_AUDIO);
1140 Film::set_audio_gain (float g)
1143 boost::mutex::scoped_lock lm (_state_mutex);
1146 signal_changed (AUDIO_GAIN);
1150 Film::set_audio_delay (int d)
1153 boost::mutex::scoped_lock lm (_state_mutex);
1156 signal_changed (AUDIO_DELAY);
1160 Film::set_still_duration (int d)
1163 boost::mutex::scoped_lock lm (_state_mutex);
1164 _still_duration = d;
1166 signal_changed (STILL_DURATION);
1170 Film::set_subtitle_stream (shared_ptr<SubtitleStream> s)
1173 boost::mutex::scoped_lock lm (_state_mutex);
1174 _subtitle_stream = s;
1176 signal_changed (SUBTITLE_STREAM);
1180 Film::set_with_subtitles (bool w)
1183 boost::mutex::scoped_lock lm (_state_mutex);
1184 _with_subtitles = w;
1186 signal_changed (WITH_SUBTITLES);
1190 Film::set_subtitle_offset (int o)
1193 boost::mutex::scoped_lock lm (_state_mutex);
1194 _subtitle_offset = o;
1196 signal_changed (SUBTITLE_OFFSET);
1200 Film::set_subtitle_scale (float s)
1203 boost::mutex::scoped_lock lm (_state_mutex);
1204 _subtitle_scale = s;
1206 signal_changed (SUBTITLE_SCALE);
1210 Film::set_colour_lut (int i)
1213 boost::mutex::scoped_lock lm (_state_mutex);
1216 signal_changed (COLOUR_LUT);
1220 Film::set_j2k_bandwidth (int b)
1223 boost::mutex::scoped_lock lm (_state_mutex);
1226 signal_changed (J2K_BANDWIDTH);
1230 Film::set_dci_metadata (DCIMetadata m)
1233 boost::mutex::scoped_lock lm (_state_mutex);
1236 signal_changed (DCI_METADATA);
1240 Film::set_size (libdcp::Size s)
1243 boost::mutex::scoped_lock lm (_state_mutex);
1246 signal_changed (SIZE);
1250 Film::set_length (SourceFrame l)
1253 boost::mutex::scoped_lock lm (_state_mutex);
1256 signal_changed (LENGTH);
1260 Film::unset_length ()
1263 boost::mutex::scoped_lock lm (_state_mutex);
1264 _length = boost::none;
1266 signal_changed (LENGTH);
1270 Film::set_dcp_intrinsic_duration (int d)
1273 boost::mutex::scoped_lock lm (_state_mutex);
1274 _dcp_intrinsic_duration = d;
1276 signal_changed (DCP_INTRINSIC_DURATION);
1280 Film::set_content_digest (string d)
1283 boost::mutex::scoped_lock lm (_state_mutex);
1284 _content_digest = d;
1290 Film::set_content_audio_streams (vector<shared_ptr<AudioStream> > s)
1293 boost::mutex::scoped_lock lm (_state_mutex);
1294 _content_audio_streams = s;
1296 signal_changed (CONTENT_AUDIO_STREAMS);
1300 Film::set_subtitle_streams (vector<shared_ptr<SubtitleStream> > s)
1303 boost::mutex::scoped_lock lm (_state_mutex);
1304 _subtitle_streams = s;
1306 signal_changed (SUBTITLE_STREAMS);
1310 Film::set_frames_per_second (float f)
1313 boost::mutex::scoped_lock lm (_state_mutex);
1314 _frames_per_second = f;
1316 signal_changed (FRAMES_PER_SECOND);
1320 Film::signal_changed (Property p)
1323 boost::mutex::scoped_lock lm (_state_mutex);
1328 ui_signaller->emit (boost::bind (boost::ref (Changed), p));
1333 Film::audio_channels () const
1335 shared_ptr<AudioStream> s = audio_stream ();
1340 return s->channels ();
1344 Film::set_dci_date_today ()
1346 _dci_date = boost::gregorian::day_clock::local_day ();
1349 boost::shared_ptr<AudioStream>
1350 Film::audio_stream () const
1352 if (use_content_audio()) {
1353 return _content_audio_stream;
1356 return _external_audio_stream;
1360 Film::info_path (int f) const
1362 boost::filesystem::path p;
1367 s << setfill('0') << f << N_(".md5");
1371 /* info_dir() will already have added any initial bit of the path,
1372 so don't call file() on this.
1378 Film::j2c_path (int f, bool t) const
1380 boost::filesystem::path p;
1382 p /= video_state_identifier ();
1386 s << setfill('0') << f << N_(".j2c");
1393 return file (p.string ());
1396 /** Make an educated guess as to whether we have a complete DCP
1398 * @return true if we do.
1402 Film::have_dcp () const
1405 libdcp::DCP dcp (dir (dcp_name()));