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 = 4;
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 , _dcp_frame_rate (0)
107 , _source_frame_rate (0)
110 set_dci_date_today ();
112 /* Make state.directory a complete path without ..s (where possible)
113 (Code swiped from Adam Bowen on stackoverflow)
116 boost::filesystem::path p (boost::filesystem::system_complete (d));
117 boost::filesystem::path result;
118 for (boost::filesystem::path::iterator i = p.begin(); i != p.end(); ++i) {
119 if (*i == N_("..")) {
120 if (boost::filesystem::is_symlink (result) || result.filename() == N_("..")) {
123 result = result.parent_path ();
125 } else if (*i != N_(".")) {
130 set_directory (result.string ());
132 if (!boost::filesystem::exists (directory())) {
134 throw OpenFileError (directory());
136 boost::filesystem::create_directory (directory());
140 _external_audio_stream = ExternalAudioStream::create ();
146 _log = new FileLog (file (N_("log")));
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 , _trim_start (o._trim_start)
163 , _trim_end (o._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 , _colour_lut (o._colour_lut)
176 , _j2k_bandwidth (o._j2k_bandwidth)
177 , _dci_metadata (o._dci_metadata)
178 , _dci_date (o._dci_date)
179 , _dcp_frame_rate (o._dcp_frame_rate)
181 , _length (o._length)
182 , _dcp_intrinsic_duration (o._dcp_intrinsic_duration)
183 , _content_digest (o._content_digest)
184 , _content_audio_streams (o._content_audio_streams)
185 , _external_audio_stream (o._external_audio_stream)
186 , _subtitle_streams (o._subtitle_streams)
187 , _source_frame_rate (o._source_frame_rate)
199 Film::video_state_identifier () const
203 pair<string, string> f = Filter::ffmpeg_strings (filters());
207 << N_("_") << content_digest()
208 << N_("_") << crop().left << N_("_") << crop().right << N_("_") << crop().top << N_("_") << crop().bottom
209 << N_("_") << _dcp_frame_rate
210 << N_("_") << f.first << N_("_") << f.second
211 << N_("_") << scaler()->id()
212 << N_("_") << j2k_bandwidth()
213 << N_("_") << boost::lexical_cast<int> (colour_lut());
216 pair<string, string> fa = Filter::ffmpeg_strings (Config::instance()->reference_filters());
217 s << N_("ab_") << Config::instance()->reference_scaler()->id() << N_("_") << fa.first << N_("_") << fa.second;
223 /** @return The path to the directory to write video frame info files to */
225 Film::info_dir () const
227 boost::filesystem::path p;
229 p /= video_state_identifier ();
230 return dir (p.string());
234 Film::video_mxf_dir () const
236 boost::filesystem::path p;
237 return dir (N_("video"));
241 Film::video_mxf_filename () const
243 return video_state_identifier() + N_(".mxf");
247 Film::audio_analysis_path () const
249 boost::filesystem::path p;
251 p /= content_digest();
252 return file (p.string ());
255 /** Add suitable Jobs to the JobManager to create a DCP for this Film */
259 set_dci_date_today ();
261 if (dcp_name().find (N_("/")) != string::npos) {
262 throw BadSettingError (_("name"), _("cannot contain slashes"));
265 log()->log (String::compose (N_("DVD-o-matic %1 git %2 using %3"), dvdomatic_version, dvdomatic_git_commit, dependency_version_summary()));
269 gethostname (buffer, sizeof (buffer));
270 log()->log (String::compose (N_("Starting to make DCP on %1"), buffer));
273 log()->log (String::compose (N_("Content is %1; type %2"), content_path(), (content_type() == STILL ? _("still") : _("video"))));
275 log()->log (String::compose (N_("Content length %1"), length().get()));
277 log()->log (String::compose (N_("Content digest %1"), content_digest()));
278 log()->log (String::compose ("Content at %1 fps, DCP at %2 fps", source_frame_rate(), dcp_frame_rate()));
279 log()->log (String::compose (N_("%1 threads"), Config::instance()->num_local_encoding_threads()));
280 log()->log (String::compose (N_("J2K bandwidth %1"), j2k_bandwidth()));
281 #ifdef DVDOMATIC_DEBUG
282 log()->log (N_("DVD-o-matic built in debug mode."));
284 log()->log (N_("DVD-o-matic built in optimised mode."));
287 log()->log (N_("libdcp built in debug mode."));
289 log()->log (N_("libdcp built in optimised mode."));
291 pair<string, int> const c = cpu_info ();
292 log()->log (String::compose (N_("CPU: %1, %2 processors"), c.first, c.second));
295 throw MissingSettingError (_("format"));
298 if (content().empty ()) {
299 throw MissingSettingError (_("content"));
302 if (dcp_content_type() == 0) {
303 throw MissingSettingError (_("content type"));
306 if (name().empty()) {
307 throw MissingSettingError (_("name"));
311 od.decode_subtitles = with_subtitles ();
316 r = JobManager::instance()->add (shared_ptr<Job> (new ABTranscodeJob (shared_from_this(), od)));
318 r = JobManager::instance()->add (shared_ptr<Job> (new TranscodeJob (shared_from_this(), od)));
322 /** Start a job to analyse the audio of our content file */
324 Film::analyse_audio ()
326 if (_analyse_audio_job) {
330 _analyse_audio_job.reset (new AnalyseAudioJob (shared_from_this()));
331 _analyse_audio_job->Finished.connect (bind (&Film::analyse_audio_finished, this));
332 JobManager::instance()->add (_analyse_audio_job);
335 /** Start a job to examine our content file */
337 Film::examine_content ()
339 if (_examine_content_job) {
343 _examine_content_job.reset (new ExamineContentJob (shared_from_this()));
344 _examine_content_job->Finished.connect (bind (&Film::examine_content_finished, this));
345 JobManager::instance()->add (_examine_content_job);
349 Film::analyse_audio_finished ()
352 _analyse_audio_job.reset ();
354 AudioAnalysisFinished ();
358 Film::examine_content_finished ()
360 _examine_content_job.reset ();
363 /** Start a job to send our DCP to the configured TMS */
365 Film::send_dcp_to_tms ()
367 shared_ptr<Job> j (new SCPDCPJob (shared_from_this()));
368 JobManager::instance()->add (j);
371 /** Count the number of frames that have been encoded for this film.
372 * @return frame count.
375 Film::encoded_frames () const
382 for (boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (info_dir ()); i != boost::filesystem::directory_iterator(); ++i) {
384 boost::this_thread::interruption_point ();
390 /** Write state to our `metadata' file */
392 Film::write_metadata () const
394 boost::mutex::scoped_lock lm (_state_mutex);
396 boost::filesystem::create_directories (directory());
398 string const m = file (N_("metadata"));
399 ofstream f (m.c_str ());
401 throw CreateFileError (m);
404 f << N_("version ") << state_version << N_("\n");
407 f << N_("name ") << _name << N_("\n");
408 f << N_("use_dci_name ") << _use_dci_name << N_("\n");
409 f << N_("content ") << _content << N_("\n");
410 f << N_("trust_content_header ") << (_trust_content_header ? N_("1") : N_("0")) << N_("\n");
411 if (_dcp_content_type) {
412 f << N_("dcp_content_type ") << _dcp_content_type->dci_name () << N_("\n");
415 f << N_("format ") << _format->as_metadata () << N_("\n");
417 f << N_("left_crop ") << _crop.left << N_("\n");
418 f << N_("right_crop ") << _crop.right << N_("\n");
419 f << N_("top_crop ") << _crop.top << N_("\n");
420 f << N_("bottom_crop ") << _crop.bottom << N_("\n");
421 for (vector<Filter const *>::const_iterator i = _filters.begin(); i != _filters.end(); ++i) {
422 f << N_("filter ") << (*i)->id () << N_("\n");
424 f << N_("scaler ") << _scaler->id () << N_("\n");
425 f << N_("trim_start ") << _trim_start << N_("\n");
426 f << N_("trim_end ") << _trim_end << N_("\n");
427 f << N_("dcp_ab ") << (_dcp_ab ? N_("1") : N_("0")) << N_("\n");
428 if (_content_audio_stream) {
429 f << N_("selected_content_audio_stream ") << _content_audio_stream->to_string() << N_("\n");
431 for (vector<string>::const_iterator i = _external_audio.begin(); i != _external_audio.end(); ++i) {
432 f << N_("external_audio ") << *i << N_("\n");
434 f << N_("use_content_audio ") << (_use_content_audio ? N_("1") : N_("0")) << N_("\n");
435 f << N_("audio_gain ") << _audio_gain << N_("\n");
436 f << N_("audio_delay ") << _audio_delay << N_("\n");
437 f << N_("still_duration ") << _still_duration << N_("\n");
438 if (_subtitle_stream) {
439 f << N_("selected_subtitle_stream ") << _subtitle_stream->to_string() << N_("\n");
441 f << N_("with_subtitles ") << _with_subtitles << N_("\n");
442 f << N_("subtitle_offset ") << _subtitle_offset << N_("\n");
443 f << N_("subtitle_scale ") << _subtitle_scale << N_("\n");
444 f << N_("colour_lut ") << _colour_lut << N_("\n");
445 f << N_("j2k_bandwidth ") << _j2k_bandwidth << N_("\n");
446 _dci_metadata.write (f);
447 f << N_("dci_date ") << boost::gregorian::to_iso_string (_dci_date) << N_("\n");
448 f << N_("dcp_frame_rate ") << _dcp_frame_rate << "\n";
449 f << N_("width ") << _size.width << N_("\n");
450 f << N_("height ") << _size.height << N_("\n");
451 f << N_("length ") << _length.get_value_or(0) << N_("\n");
452 f << N_("dcp_intrinsic_duration ") << _dcp_intrinsic_duration.get_value_or(0) << N_("\n");
453 f << N_("content_digest ") << _content_digest << N_("\n");
455 for (vector<shared_ptr<AudioStream> >::const_iterator i = _content_audio_streams.begin(); i != _content_audio_streams.end(); ++i) {
456 f << N_("content_audio_stream ") << (*i)->to_string () << N_("\n");
459 f << N_("external_audio_stream ") << _external_audio_stream->to_string() << N_("\n");
461 for (vector<shared_ptr<SubtitleStream> >::const_iterator i = _subtitle_streams.begin(); i != _subtitle_streams.end(); ++i) {
462 f << N_("subtitle_stream ") << (*i)->to_string () << N_("\n");
465 f << N_("source_frame_rate ") << _source_frame_rate << N_("\n");
470 /** Read state from our metadata file */
472 Film::read_metadata ()
474 boost::mutex::scoped_lock lm (_state_mutex);
476 _external_audio.clear ();
477 _content_audio_streams.clear ();
478 _subtitle_streams.clear ();
480 boost::optional<int> version;
482 /* Backward compatibility things */
483 boost::optional<int> audio_sample_rate;
484 boost::optional<int> audio_stream_index;
485 boost::optional<int> subtitle_stream_index;
487 ifstream f (file (N_("metadata")).c_str());
489 throw OpenFileError (file (N_("metadata")));
492 multimap<string, string> kv = read_key_value (f);
494 /* We need version before anything else */
495 multimap<string, string>::iterator v = kv.find (N_("version"));
496 if (v != kv.end ()) {
497 version = atoi (v->second.c_str());
500 for (multimap<string, string>::const_iterator i = kv.begin(); i != kv.end(); ++i) {
501 string const k = i->first;
502 string const v = i->second;
504 if (k == N_("audio_sample_rate")) {
505 audio_sample_rate = atoi (v.c_str());
508 /* User-specified stuff */
509 if (k == N_("name")) {
511 } else if (k == N_("use_dci_name")) {
512 _use_dci_name = (v == N_("1"));
513 } else if (k == N_("content")) {
515 } else if (k == N_("trust_content_header")) {
516 _trust_content_header = (v == N_("1"));
517 } else if (k == N_("dcp_content_type")) {
519 _dcp_content_type = DCPContentType::from_pretty_name (v);
521 _dcp_content_type = DCPContentType::from_dci_name (v);
523 } else if (k == N_("format")) {
524 _format = Format::from_metadata (v);
525 } else if (k == N_("left_crop")) {
526 _crop.left = atoi (v.c_str ());
527 } else if (k == N_("right_crop")) {
528 _crop.right = atoi (v.c_str ());
529 } else if (k == N_("top_crop")) {
530 _crop.top = atoi (v.c_str ());
531 } else if (k == N_("bottom_crop")) {
532 _crop.bottom = atoi (v.c_str ());
533 } else if (k == N_("filter")) {
534 _filters.push_back (Filter::from_id (v));
535 } else if (k == N_("scaler")) {
536 _scaler = Scaler::from_id (v);
537 } else if ( ((!version || version < 2) && k == N_("dcp_trim_start")) || k == N_("trim_start")) {
538 _trim_start = atoi (v.c_str ());
539 } else if ( ((!version || version < 2) && k == N_("dcp_trim_end")) || k == N_("trim_end")) {
540 _trim_end = atoi (v.c_str ());
541 } else if (k == N_("dcp_ab")) {
542 _dcp_ab = (v == N_("1"));
543 } else if (k == N_("selected_content_audio_stream") || (!version && k == N_("selected_audio_stream"))) {
545 audio_stream_index = atoi (v.c_str ());
547 _content_audio_stream = audio_stream_factory (v, version);
549 } else if (k == N_("external_audio")) {
550 _external_audio.push_back (v);
551 } else if (k == N_("use_content_audio")) {
552 _use_content_audio = (v == N_("1"));
553 } else if (k == N_("audio_gain")) {
554 _audio_gain = atof (v.c_str ());
555 } else if (k == N_("audio_delay")) {
556 _audio_delay = atoi (v.c_str ());
557 } else if (k == N_("still_duration")) {
558 _still_duration = atoi (v.c_str ());
559 } else if (k == N_("selected_subtitle_stream")) {
561 subtitle_stream_index = atoi (v.c_str ());
563 _subtitle_stream = subtitle_stream_factory (v, version);
565 } else if (k == N_("with_subtitles")) {
566 _with_subtitles = (v == N_("1"));
567 } else if (k == N_("subtitle_offset")) {
568 _subtitle_offset = atoi (v.c_str ());
569 } else if (k == N_("subtitle_scale")) {
570 _subtitle_scale = atof (v.c_str ());
571 } else if (k == N_("colour_lut")) {
572 _colour_lut = atoi (v.c_str ());
573 } else if (k == N_("j2k_bandwidth")) {
574 _j2k_bandwidth = atoi (v.c_str ());
575 } else if (k == N_("dci_date")) {
576 _dci_date = boost::gregorian::from_undelimited_string (v);
577 } else if (k == "dcp_frame_rate") {
578 _dcp_frame_rate = atoi (v.c_str ());
581 _dci_metadata.read (k, v);
584 if (k == N_("width")) {
585 _size.width = atoi (v.c_str ());
586 } else if (k == N_("height")) {
587 _size.height = atoi (v.c_str ());
588 } else if (k == N_("length")) {
589 int const vv = atoi (v.c_str ());
593 } else if (k == N_("dcp_intrinsic_duration")) {
594 int const vv = atoi (v.c_str ());
596 _dcp_intrinsic_duration = vv;
598 } else if (k == N_("content_digest")) {
600 } else if (k == N_("content_audio_stream") || (!version && k == N_("audio_stream"))) {
601 _content_audio_streams.push_back (audio_stream_factory (v, version));
602 } else if (k == N_("external_audio_stream")) {
603 _external_audio_stream = audio_stream_factory (v, version);
604 } else if (k == N_("subtitle_stream")) {
605 _subtitle_streams.push_back (subtitle_stream_factory (v, version));
606 } else if (k == N_("source_frame_rate")) {
607 _source_frame_rate = atof (v.c_str ());
608 } else if (version < 4 && k == "frames_per_second") {
609 _source_frame_rate = atof (v.c_str ());
610 /* Fill in what would have been used for DCP frame rate by the older version */
611 _dcp_frame_rate = best_dcp_frame_rate (_source_frame_rate);
616 if (audio_sample_rate) {
617 /* version < 1 didn't specify sample rate in the audio streams, so fill it in here */
618 for (vector<shared_ptr<AudioStream> >::iterator i = _content_audio_streams.begin(); i != _content_audio_streams.end(); ++i) {
619 (*i)->set_sample_rate (audio_sample_rate.get());
623 /* also the selected stream was specified as an index */
624 if (audio_stream_index && audio_stream_index.get() >= 0 && audio_stream_index.get() < (int) _content_audio_streams.size()) {
625 _content_audio_stream = _content_audio_streams[audio_stream_index.get()];
628 /* similarly the subtitle */
629 if (subtitle_stream_index && subtitle_stream_index.get() >= 0 && subtitle_stream_index.get() < (int) _subtitle_streams.size()) {
630 _subtitle_stream = _subtitle_streams[subtitle_stream_index.get()];
638 Film::cropped_size (libdcp::Size s) const
640 boost::mutex::scoped_lock lm (_state_mutex);
641 s.width -= _crop.left + _crop.right;
642 s.height -= _crop.top + _crop.bottom;
646 /** Given a directory name, return its full path within the Film's directory.
647 * The directory (and its parents) will be created if they do not exist.
650 Film::dir (string d) const
652 boost::mutex::scoped_lock lm (_directory_mutex);
654 boost::filesystem::path p;
658 boost::filesystem::create_directories (p);
663 /** Given a file or directory name, return its full path within the Film's directory.
664 * _directory_mutex must not be locked on entry.
665 * Any required parent directories will be created.
668 Film::file (string f) const
670 boost::mutex::scoped_lock lm (_directory_mutex);
672 boost::filesystem::path p;
676 boost::filesystem::create_directories (p.parent_path ());
681 /** @return full path of the content (actual video) file
685 Film::content_path () const
687 boost::mutex::scoped_lock lm (_state_mutex);
688 if (boost::filesystem::path(_content).has_root_directory ()) {
692 return file (_content);
696 Film::content_type () const
698 if (boost::filesystem::is_directory (_content)) {
699 /* Directory of images, we assume */
703 if (still_image_file (_content)) {
710 /** @return The sampling rate that we will resample the audio to */
712 Film::target_audio_sample_rate () const
714 if (!audio_stream()) {
718 /* Resample to a DCI-approved sample rate */
719 double t = dcp_audio_sample_rate (audio_stream()->sample_rate());
721 FrameRateConversion frc (source_frame_rate(), dcp_frame_rate());
723 /* Compensate if the DCP is being run at a different frame rate
724 to the source; that is, if the video is run such that it will
725 look different in the DCP compared to the source (slower or faster).
726 skip/repeat doesn't come into effect here.
729 if (frc.change_speed) {
730 t *= source_frame_rate() * frc.factor() / dcp_frame_rate();
737 Film::still_duration_in_frames () const
739 return still_duration() * source_frame_rate();
742 /** @return a DCI-compliant name for a DCP of this film */
744 Film::dci_name (bool if_created_now) const
748 string fixed_name = to_upper_copy (name());
749 for (size_t i = 0; i < fixed_name.length(); ++i) {
750 if (fixed_name[i] == ' ') {
755 /* Spec is that the name part should be maximum 14 characters, as I understand it */
756 if (fixed_name.length() > 14) {
757 fixed_name = fixed_name.substr (0, 14);
760 d << fixed_name << N_("_");
762 if (dcp_content_type()) {
763 d << dcp_content_type()->dci_name() << N_("_");
767 d << format()->dci_name() << N_("_");
770 DCIMetadata const dm = dci_metadata ();
772 if (!dm.audio_language.empty ()) {
773 d << dm.audio_language;
774 if (!dm.subtitle_language.empty() && with_subtitles()) {
775 d << N_("-") << dm.subtitle_language;
783 if (!dm.territory.empty ()) {
785 if (!dm.rating.empty ()) {
786 d << N_("-") << dm.rating;
791 switch (audio_channels()) {
808 if (!dm.studio.empty ()) {
809 d << dm.studio << N_("_");
812 if (if_created_now) {
813 d << boost::gregorian::to_iso_string (boost::gregorian::day_clock::local_day ()) << N_("_");
815 d << boost::gregorian::to_iso_string (_dci_date) << N_("_");
818 if (!dm.facility.empty ()) {
819 d << dm.facility << N_("_");
822 if (!dm.package_type.empty ()) {
823 d << dm.package_type;
829 /** @return name to give the DCP */
831 Film::dcp_name (bool if_created_now) const
833 if (use_dci_name()) {
834 return dci_name (if_created_now);
842 Film::set_directory (string d)
844 boost::mutex::scoped_lock lm (_state_mutex);
850 Film::set_name (string n)
853 boost::mutex::scoped_lock lm (_state_mutex);
856 signal_changed (NAME);
860 Film::set_use_dci_name (bool u)
863 boost::mutex::scoped_lock lm (_state_mutex);
866 signal_changed (USE_DCI_NAME);
870 Film::set_content (string c)
872 string check = directory ();
874 boost::filesystem::path slash (N_("/"));
875 string platform_slash = slash.make_preferred().string ();
877 if (!ends_with (check, platform_slash)) {
878 check += platform_slash;
881 if (boost::filesystem::path(c).has_root_directory () && starts_with (c, check)) {
882 c = c.substr (_directory.length() + 1);
888 boost::mutex::scoped_lock lm (_state_mutex);
893 old_content = _content;
897 /* Reset streams here in case the new content doesn't have one or the other */
898 _content_audio_stream = shared_ptr<AudioStream> ();
899 _subtitle_stream = shared_ptr<SubtitleStream> ();
901 /* Start off using content audio */
902 set_use_content_audio (true);
904 /* Create a temporary decoder so that we can get information
909 Decoders d = decoder_factory (shared_from_this(), DecodeOptions());
911 set_size (d.video->native_size ());
912 set_source_frame_rate (d.video->frames_per_second ());
913 set_dcp_frame_rate (best_dcp_frame_rate (source_frame_rate ()));
914 set_subtitle_streams (d.video->subtitle_streams ());
916 set_content_audio_streams (d.audio->audio_streams ());
920 boost::mutex::scoped_lock lm (_state_mutex);
924 signal_changed (CONTENT);
926 /* Start off with the first audio and subtitle streams */
927 if (d.audio && !d.audio->audio_streams().empty()) {
928 set_content_audio_stream (d.audio->audio_streams().front());
931 if (!d.video->subtitle_streams().empty()) {
932 set_subtitle_stream (d.video->subtitle_streams().front());
939 boost::mutex::scoped_lock lm (_state_mutex);
940 _content = old_content;
946 switch (content_type()) {
948 set_format (Format::from_id (N_("var-185")));
951 set_format (Format::from_id (N_("185")));
955 /* Still image DCPs must use external audio */
956 if (content_type() == STILL) {
957 set_use_content_audio (false);
962 Film::set_trust_content_header (bool t)
965 boost::mutex::scoped_lock lm (_state_mutex);
966 _trust_content_header = t;
969 signal_changed (TRUST_CONTENT_HEADER);
971 if (!_trust_content_header && !content().empty()) {
972 /* We just said that we don't trust the content's header */
978 Film::set_dcp_content_type (DCPContentType const * t)
981 boost::mutex::scoped_lock lm (_state_mutex);
982 _dcp_content_type = t;
984 signal_changed (DCP_CONTENT_TYPE);
988 Film::set_format (Format const * f)
991 boost::mutex::scoped_lock lm (_state_mutex);
994 signal_changed (FORMAT);
998 Film::set_crop (Crop c)
1001 boost::mutex::scoped_lock lm (_state_mutex);
1004 signal_changed (CROP);
1008 Film::set_left_crop (int c)
1011 boost::mutex::scoped_lock lm (_state_mutex);
1013 if (_crop.left == c) {
1019 signal_changed (CROP);
1023 Film::set_right_crop (int c)
1026 boost::mutex::scoped_lock lm (_state_mutex);
1027 if (_crop.right == c) {
1033 signal_changed (CROP);
1037 Film::set_top_crop (int c)
1040 boost::mutex::scoped_lock lm (_state_mutex);
1041 if (_crop.top == c) {
1047 signal_changed (CROP);
1051 Film::set_bottom_crop (int c)
1054 boost::mutex::scoped_lock lm (_state_mutex);
1055 if (_crop.bottom == c) {
1061 signal_changed (CROP);
1065 Film::set_filters (vector<Filter const *> f)
1068 boost::mutex::scoped_lock lm (_state_mutex);
1071 signal_changed (FILTERS);
1075 Film::set_scaler (Scaler const * s)
1078 boost::mutex::scoped_lock lm (_state_mutex);
1081 signal_changed (SCALER);
1085 Film::set_trim_start (int t)
1088 boost::mutex::scoped_lock lm (_state_mutex);
1091 signal_changed (TRIM_START);
1095 Film::set_trim_end (int t)
1098 boost::mutex::scoped_lock lm (_state_mutex);
1101 signal_changed (TRIM_END);
1105 Film::set_dcp_ab (bool a)
1108 boost::mutex::scoped_lock lm (_state_mutex);
1111 signal_changed (DCP_AB);
1115 Film::set_content_audio_stream (shared_ptr<AudioStream> s)
1118 boost::mutex::scoped_lock lm (_state_mutex);
1119 _content_audio_stream = s;
1121 signal_changed (CONTENT_AUDIO_STREAM);
1125 Film::set_external_audio (vector<string> a)
1128 boost::mutex::scoped_lock lm (_state_mutex);
1129 _external_audio = a;
1132 shared_ptr<ExternalAudioDecoder> decoder (new ExternalAudioDecoder (shared_from_this(), DecodeOptions()));
1133 if (decoder->audio_stream()) {
1134 _external_audio_stream = decoder->audio_stream ();
1137 signal_changed (EXTERNAL_AUDIO);
1141 Film::set_use_content_audio (bool e)
1144 boost::mutex::scoped_lock lm (_state_mutex);
1145 _use_content_audio = e;
1148 signal_changed (USE_CONTENT_AUDIO);
1152 Film::set_audio_gain (float g)
1155 boost::mutex::scoped_lock lm (_state_mutex);
1158 signal_changed (AUDIO_GAIN);
1162 Film::set_audio_delay (int d)
1165 boost::mutex::scoped_lock lm (_state_mutex);
1168 signal_changed (AUDIO_DELAY);
1172 Film::set_still_duration (int d)
1175 boost::mutex::scoped_lock lm (_state_mutex);
1176 _still_duration = d;
1178 signal_changed (STILL_DURATION);
1182 Film::set_subtitle_stream (shared_ptr<SubtitleStream> s)
1185 boost::mutex::scoped_lock lm (_state_mutex);
1186 _subtitle_stream = s;
1188 signal_changed (SUBTITLE_STREAM);
1192 Film::set_with_subtitles (bool w)
1195 boost::mutex::scoped_lock lm (_state_mutex);
1196 _with_subtitles = w;
1198 signal_changed (WITH_SUBTITLES);
1202 Film::set_subtitle_offset (int o)
1205 boost::mutex::scoped_lock lm (_state_mutex);
1206 _subtitle_offset = o;
1208 signal_changed (SUBTITLE_OFFSET);
1212 Film::set_subtitle_scale (float s)
1215 boost::mutex::scoped_lock lm (_state_mutex);
1216 _subtitle_scale = s;
1218 signal_changed (SUBTITLE_SCALE);
1222 Film::set_colour_lut (int i)
1225 boost::mutex::scoped_lock lm (_state_mutex);
1228 signal_changed (COLOUR_LUT);
1232 Film::set_j2k_bandwidth (int b)
1235 boost::mutex::scoped_lock lm (_state_mutex);
1238 signal_changed (J2K_BANDWIDTH);
1242 Film::set_dci_metadata (DCIMetadata m)
1245 boost::mutex::scoped_lock lm (_state_mutex);
1248 signal_changed (DCI_METADATA);
1253 Film::set_dcp_frame_rate (int f)
1256 boost::mutex::scoped_lock lm (_state_mutex);
1257 _dcp_frame_rate = f;
1259 signal_changed (DCP_FRAME_RATE);
1263 Film::set_size (libdcp::Size s)
1266 boost::mutex::scoped_lock lm (_state_mutex);
1269 signal_changed (SIZE);
1273 Film::set_length (SourceFrame l)
1276 boost::mutex::scoped_lock lm (_state_mutex);
1279 signal_changed (LENGTH);
1283 Film::unset_length ()
1286 boost::mutex::scoped_lock lm (_state_mutex);
1287 _length = boost::none;
1289 signal_changed (LENGTH);
1293 Film::set_dcp_intrinsic_duration (int d)
1296 boost::mutex::scoped_lock lm (_state_mutex);
1297 _dcp_intrinsic_duration = d;
1299 signal_changed (DCP_INTRINSIC_DURATION);
1303 Film::set_content_digest (string d)
1306 boost::mutex::scoped_lock lm (_state_mutex);
1307 _content_digest = d;
1313 Film::set_content_audio_streams (vector<shared_ptr<AudioStream> > s)
1316 boost::mutex::scoped_lock lm (_state_mutex);
1317 _content_audio_streams = s;
1319 signal_changed (CONTENT_AUDIO_STREAMS);
1323 Film::set_subtitle_streams (vector<shared_ptr<SubtitleStream> > s)
1326 boost::mutex::scoped_lock lm (_state_mutex);
1327 _subtitle_streams = s;
1329 signal_changed (SUBTITLE_STREAMS);
1333 Film::set_source_frame_rate (float f)
1336 boost::mutex::scoped_lock lm (_state_mutex);
1337 _source_frame_rate = f;
1339 signal_changed (SOURCE_FRAME_RATE);
1343 Film::signal_changed (Property p)
1346 boost::mutex::scoped_lock lm (_state_mutex);
1351 ui_signaller->emit (boost::bind (boost::ref (Changed), p));
1356 Film::audio_channels () const
1358 shared_ptr<AudioStream> s = audio_stream ();
1363 return s->channels ();
1367 Film::set_dci_date_today ()
1369 _dci_date = boost::gregorian::day_clock::local_day ();
1372 boost::shared_ptr<AudioStream>
1373 Film::audio_stream () const
1375 if (use_content_audio()) {
1376 return _content_audio_stream;
1379 return _external_audio_stream;
1383 Film::info_path (int f) const
1385 boost::filesystem::path p;
1390 s << setfill('0') << f << N_(".md5");
1394 /* info_dir() will already have added any initial bit of the path,
1395 so don't call file() on this.
1401 Film::j2c_path (int f, bool t) const
1403 boost::filesystem::path p;
1405 p /= video_state_identifier ();
1409 s << setfill('0') << f << N_(".j2c");
1416 return file (p.string ());
1419 /** Make an educated guess as to whether we have a complete DCP
1421 * @return true if we do.
1425 Film::have_dcp () const
1428 libdcp::DCP dcp (dir (dcp_name()));