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 <libcxml/cxml.h>
39 #include "job_manager.h"
40 #include "ab_transcode_job.h"
41 #include "transcode_job.h"
42 #include "scp_dcp_job.h"
44 #include "exceptions.h"
45 #include "examine_content_job.h"
49 #include "ui_signaller.h"
50 #include "analyse_audio_job.h"
53 #include "ffmpeg_content.h"
54 #include "imagemagick_content.h"
55 #include "sndfile_content.h"
56 #include "dcp_content_type.h"
61 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;
82 int const Film::state_version = 4;
84 /** Construct a Film object in a given directory, reading any metadata
85 * file that exists in that directory. An exception will be thrown if
86 * must_exist is true and the specified directory does not exist.
88 * @param d Film directory.
89 * @param must_exist true to throw an exception if does not exist.
92 Film::Film (string d, bool must_exist)
93 : _playlist (new Playlist)
94 , _use_dci_name (true)
95 , _trust_content_headers (true)
96 , _dcp_content_type (0)
97 , _format (Format::from_id ("185"))
98 , _scaler (Scaler::from_id ("bicubic"))
104 , _with_subtitles (false)
105 , _subtitle_offset (0)
106 , _subtitle_scale (1)
108 , _j2k_bandwidth (200000000)
109 , _dci_metadata (Config::instance()->default_dci_metadata ())
110 , _dcp_frame_rate (0)
113 set_dci_date_today ();
115 _playlist->ContentChanged.connect (bind (&Film::content_changed, this, _1, _2));
117 /* Make state.directory a complete path without ..s (where possible)
118 (Code swiped from Adam Bowen on stackoverflow)
121 boost::filesystem::path p (boost::filesystem::system_complete (d));
122 boost::filesystem::path result;
123 for (boost::filesystem::path::iterator i = p.begin(); i != p.end(); ++i) {
125 if (boost::filesystem::is_symlink (result) || result.filename() == "..") {
128 result = result.parent_path ();
130 } else if (*i != ".") {
135 set_directory (result.string ());
137 if (!boost::filesystem::exists (directory())) {
139 throw OpenFileError (directory());
141 boost::filesystem::create_directory (directory());
149 _log.reset (new FileLog (file ("log")));
152 Film::Film (Film const & o)
153 : boost::enable_shared_from_this<Film> (o)
154 /* note: the copied film shares the original's log */
156 , _playlist (new Playlist)
157 , _directory (o._directory)
159 , _use_dci_name (o._use_dci_name)
160 , _trust_content_headers (o._trust_content_headers)
161 , _dcp_content_type (o._dcp_content_type)
162 , _format (o._format)
164 , _filters (o._filters)
165 , _scaler (o._scaler)
166 , _trim_start (o._trim_start)
167 , _trim_end (o._trim_end)
169 , _audio_gain (o._audio_gain)
170 , _audio_delay (o._audio_delay)
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 , _dcp_frame_rate (o._dcp_frame_rate)
178 , _dci_date (o._dci_date)
181 for (ContentList::const_iterator i = o._content.begin(); i != o._content.end(); ++i) {
182 _content.push_back ((*i)->clone ());
185 _playlist->ContentChanged.connect (bind (&Film::content_changed, this, _1, _2));
187 _playlist->setup (_content);
191 Film::video_state_identifier () const
195 pair<string, string> f = Filter::ffmpeg_strings (filters());
199 << "_" << _playlist->video_digest()
200 << "_" << crop().left << "_" << crop().right << "_" << crop().top << "_" << crop().bottom
201 << "_" << _dcp_frame_rate
202 << "_" << f.first << "_" << f.second
203 << "_" << scaler()->id()
204 << "_" << j2k_bandwidth()
205 << "_" << boost::lexical_cast<int> (colour_lut());
208 pair<string, string> fa = Filter::ffmpeg_strings (Config::instance()->reference_filters());
209 s << "ab_" << Config::instance()->reference_scaler()->id() << "_" << fa.first << "_" << fa.second;
215 /** @return The path to the directory to write video frame info files to */
217 Film::info_dir () const
219 boost::filesystem::path p;
221 p /= video_state_identifier ();
222 return dir (p.string());
226 Film::video_mxf_dir () const
228 boost::filesystem::path p;
229 return dir ("video");
233 Film::video_mxf_filename () const
235 return video_state_identifier() + ".mxf";
239 Film::audio_analysis_path () const
241 boost::filesystem::path p;
243 p /= _playlist->audio_digest();
244 return file (p.string ());
247 /** Add suitable Jobs to the JobManager to create a DCP for this Film */
251 set_dci_date_today ();
253 if (dcp_name().find ("/") != string::npos) {
254 throw BadSettingError (_("name"), _("cannot contain slashes"));
257 log()->log (String::compose ("DCP-o-matic %1 git %2 using %3", dcpomatic_version, dcpomatic_git_commit, dependency_version_summary()));
261 gethostname (buffer, sizeof (buffer));
262 log()->log (String::compose ("Starting to make DCP on %1", buffer));
265 // log()->log (String::compose ("Content is %1; type %2", content_path(), (content_type() == STILL ? _("still") : _("video"))));
267 // log()->log (String::compose ("Content length %1", length().get()));
269 // log()->log (String::compose ("Content digest %1", content_digest()));
270 // log()->log (String::compose ("Content at %1 fps, DCP at %2 fps", source_frame_rate(), dcp_frame_rate()));
271 log()->log (String::compose ("%1 threads", Config::instance()->num_local_encoding_threads()));
272 log()->log (String::compose ("J2K bandwidth %1", j2k_bandwidth()));
273 #ifdef DCPOMATIC_DEBUG
274 log()->log ("DCP-o-matic built in debug mode.");
276 log()->log ("DCP-o-matic built in optimised mode.");
279 log()->log ("libdcp built in debug mode.");
281 log()->log ("libdcp built in optimised mode.");
283 pair<string, int> const c = cpu_info ();
284 log()->log (String::compose ("CPU: %1, %2 processors", c.first, c.second));
287 throw MissingSettingError (_("format"));
290 if (content().empty ()) {
291 throw MissingSettingError (_("content"));
294 if (dcp_content_type() == 0) {
295 throw MissingSettingError (_("content type"));
298 if (name().empty()) {
299 throw MissingSettingError (_("name"));
305 r = JobManager::instance()->add (shared_ptr<Job> (new ABTranscodeJob (shared_from_this())));
307 r = JobManager::instance()->add (shared_ptr<Job> (new TranscodeJob (shared_from_this())));
311 /** Start a job to analyse the audio in our Playlist */
313 Film::analyse_audio ()
315 if (_analyse_audio_job) {
319 _analyse_audio_job.reset (new AnalyseAudioJob (shared_from_this()));
320 _analyse_audio_job->Finished.connect (bind (&Film::analyse_audio_finished, this));
321 JobManager::instance()->add (_analyse_audio_job);
324 /** Start a job to examine a piece of content */
326 Film::examine_content (shared_ptr<Content> c)
328 shared_ptr<Job> j (new ExamineContentJob (shared_from_this(), c, trust_content_headers ()));
329 JobManager::instance()->add (j);
333 Film::analyse_audio_finished ()
337 if (_analyse_audio_job->finished_ok ()) {
338 AudioAnalysisSucceeded ();
341 _analyse_audio_job.reset ();
344 /** Start a job to send our DCP to the configured TMS */
346 Film::send_dcp_to_tms ()
348 shared_ptr<Job> j (new SCPDCPJob (shared_from_this()));
349 JobManager::instance()->add (j);
352 /** Count the number of frames that have been encoded for this film.
353 * @return frame count.
356 Film::encoded_frames () const
363 for (boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (info_dir ()); i != boost::filesystem::directory_iterator(); ++i) {
365 boost::this_thread::interruption_point ();
371 /** Write state to our `metadata' file */
373 Film::write_metadata () const
375 ContentList the_content = content ();
377 boost::mutex::scoped_lock lm (_state_mutex);
379 boost::filesystem::create_directories (directory());
382 xmlpp::Element* root = doc.create_root_node ("Metadata");
384 root->add_child("Version")->add_child_text (boost::lexical_cast<string> (state_version));
385 root->add_child("Name")->add_child_text (_name);
386 root->add_child("UseDCIName")->add_child_text (_use_dci_name ? "1" : "0");
387 root->add_child("TrustContentHeaders")->add_child_text (_trust_content_headers ? "1" : "0");
388 if (_dcp_content_type) {
389 root->add_child("DCPContentType")->add_child_text (_dcp_content_type->dci_name ());
392 root->add_child("Format")->add_child_text (_format->id ());
394 root->add_child("LeftCrop")->add_child_text (boost::lexical_cast<string> (_crop.left));
395 root->add_child("RightCrop")->add_child_text (boost::lexical_cast<string> (_crop.right));
396 root->add_child("TopCrop")->add_child_text (boost::lexical_cast<string> (_crop.top));
397 root->add_child("BottomCrop")->add_child_text (boost::lexical_cast<string> (_crop.bottom));
399 for (vector<Filter const *>::const_iterator i = _filters.begin(); i != _filters.end(); ++i) {
400 root->add_child("Filter")->add_child_text ((*i)->id ());
403 root->add_child("Scaler")->add_child_text (_scaler->id ());
404 root->add_child("TrimStart")->add_child_text (boost::lexical_cast<string> (_trim_start));
405 root->add_child("TrimEnd")->add_child_text (boost::lexical_cast<string> (_trim_end));
406 root->add_child("AB")->add_child_text (_ab ? "1" : "0");
407 root->add_child("AudioGain")->add_child_text (boost::lexical_cast<string> (_audio_gain));
408 root->add_child("AudioDelay")->add_child_text (boost::lexical_cast<string> (_audio_delay));
409 root->add_child("WithSubtitles")->add_child_text (_with_subtitles ? "1" : "0");
410 root->add_child("SubtitleOffset")->add_child_text (boost::lexical_cast<string> (_subtitle_offset));
411 root->add_child("SubtitleScale")->add_child_text (boost::lexical_cast<string> (_subtitle_scale));
412 root->add_child("ColourLUT")->add_child_text (boost::lexical_cast<string> (_colour_lut));
413 root->add_child("J2KBandwidth")->add_child_text (boost::lexical_cast<string> (_j2k_bandwidth));
414 _dci_metadata.as_xml (root->add_child ("DCIMetadata"));
415 root->add_child("DCPFrameRate")->add_child_text (boost::lexical_cast<string> (_dcp_frame_rate));
416 root->add_child("DCIDate")->add_child_text (boost::gregorian::to_iso_string (_dci_date));
417 _audio_mapping.as_xml (root->add_child("AudioMapping"));
419 for (ContentList::iterator i = the_content.begin(); i != the_content.end(); ++i) {
420 (*i)->as_xml (root->add_child ("Content"));
423 doc.write_to_file_formatted (file ("metadata.xml"));
428 /** Read state from our metadata file */
430 Film::read_metadata ()
432 boost::mutex::scoped_lock lm (_state_mutex);
434 if (boost::filesystem::exists (file ("metadata")) && !boost::filesystem::exists (file ("metadata.xml"))) {
435 throw StringError (_("This film was created with an older version of DCP-o-matic, and unfortunately it cannot be loaded into this version. You will need to create a new Film, re-add your content and set it up again. Sorry!"));
438 cxml::File f (file ("metadata.xml"), "Metadata");
440 _name = f.string_child ("Name");
441 _use_dci_name = f.bool_child ("UseDCIName");
442 _trust_content_headers = f.bool_child ("TrustContentHeaders");
445 optional<string> c = f.optional_string_child ("DCPContentType");
447 _dcp_content_type = DCPContentType::from_dci_name (c.get ());
452 optional<string> c = f.optional_string_child ("Format");
454 _format = Format::from_id (c.get ());
458 _crop.left = f.number_child<int> ("LeftCrop");
459 _crop.right = f.number_child<int> ("RightCrop");
460 _crop.top = f.number_child<int> ("TopCrop");
461 _crop.bottom = f.number_child<int> ("BottomCrop");
464 list<shared_ptr<cxml::Node> > c = f.node_children ("Filter");
465 for (list<shared_ptr<cxml::Node> >::iterator i = c.begin(); i != c.end(); ++i) {
466 _filters.push_back (Filter::from_id ((*i)->content ()));
470 _scaler = Scaler::from_id (f.string_child ("Scaler"));
471 _trim_start = f.number_child<int> ("TrimStart");
472 _trim_end = f.number_child<int> ("TrimEnd");
473 _ab = f.bool_child ("AB");
474 _audio_gain = f.number_child<float> ("AudioGain");
475 _audio_delay = f.number_child<int> ("AudioDelay");
476 _with_subtitles = f.bool_child ("WithSubtitles");
477 _subtitle_offset = f.number_child<float> ("SubtitleOffset");
478 _subtitle_scale = f.number_child<float> ("SubtitleScale");
479 _colour_lut = f.number_child<int> ("ColourLUT");
480 _j2k_bandwidth = f.number_child<int> ("J2KBandwidth");
481 _dci_metadata = DCIMetadata (f.node_child ("DCIMetadata"));
482 _dcp_frame_rate = f.number_child<int> ("DCPFrameRate");
483 _dci_date = boost::gregorian::from_undelimited_string (f.string_child ("DCIDate"));
485 list<shared_ptr<cxml::Node> > c = f.node_children ("Content");
486 for (list<shared_ptr<cxml::Node> >::iterator i = c.begin(); i != c.end(); ++i) {
488 string const type = (*i)->string_child ("Type");
489 boost::shared_ptr<Content> c;
491 if (type == "FFmpeg") {
492 c.reset (new FFmpegContent (*i));
493 } else if (type == "ImageMagick") {
494 c.reset (new ImageMagickContent (*i));
495 } else if (type == "Sndfile") {
496 c.reset (new SndfileContent (*i));
499 _content.push_back (c);
502 /* This must come after we've loaded the content, as we're looking things up in _content */
503 _audio_mapping.set_from_xml (_content, f.node_child ("AudioMapping"));
507 _playlist->setup (_content);
511 Film::cropped_size (libdcp::Size s) const
513 boost::mutex::scoped_lock lm (_state_mutex);
514 s.width -= _crop.left + _crop.right;
515 s.height -= _crop.top + _crop.bottom;
519 /** Given a directory name, return its full path within the Film's directory.
520 * The directory (and its parents) will be created if they do not exist.
523 Film::dir (string d) const
525 boost::mutex::scoped_lock lm (_directory_mutex);
527 boost::filesystem::path p;
531 boost::filesystem::create_directories (p);
536 /** Given a file or directory name, return its full path within the Film's directory.
537 * _directory_mutex must not be locked on entry.
538 * Any required parent directories will be created.
541 Film::file (string f) const
543 boost::mutex::scoped_lock lm (_directory_mutex);
545 boost::filesystem::path p;
549 boost::filesystem::create_directories (p.parent_path ());
554 /** @return The sampling rate that we will resample the audio to */
556 Film::target_audio_sample_rate () const
562 /* Resample to a DCI-approved sample rate */
563 double t = dcp_audio_sample_rate (audio_frame_rate());
565 FrameRateConversion frc (video_frame_rate(), dcp_frame_rate());
567 /* Compensate if the DCP is being run at a different frame rate
568 to the source; that is, if the video is run such that it will
569 look different in the DCP compared to the source (slower or faster).
570 skip/repeat doesn't come into effect here.
573 if (frc.change_speed) {
574 t *= video_frame_rate() * frc.factor() / dcp_frame_rate();
580 /** @return a DCI-compliant name for a DCP of this film */
582 Film::dci_name (bool if_created_now) const
586 string fixed_name = to_upper_copy (name());
587 for (size_t i = 0; i < fixed_name.length(); ++i) {
588 if (fixed_name[i] == ' ') {
593 /* Spec is that the name part should be maximum 14 characters, as I understand it */
594 if (fixed_name.length() > 14) {
595 fixed_name = fixed_name.substr (0, 14);
600 if (dcp_content_type()) {
601 d << "_" << dcp_content_type()->dci_name();
605 d << "_" << format()->dci_name();
608 DCIMetadata const dm = dci_metadata ();
610 if (!dm.audio_language.empty ()) {
611 d << "_" << dm.audio_language;
612 if (!dm.subtitle_language.empty()) {
613 d << "-" << dm.subtitle_language;
619 if (!dm.territory.empty ()) {
620 d << "_" << dm.territory;
621 if (!dm.rating.empty ()) {
622 d << "-" << dm.rating;
626 switch (audio_channels ()) {
643 if (!dm.studio.empty ()) {
644 d << "_" << dm.studio;
647 if (if_created_now) {
648 d << "_" << boost::gregorian::to_iso_string (boost::gregorian::day_clock::local_day ());
650 d << "_" << boost::gregorian::to_iso_string (_dci_date);
653 if (!dm.facility.empty ()) {
654 d << "_" << dm.facility;
657 if (!dm.package_type.empty ()) {
658 d << "_" << dm.package_type;
664 /** @return name to give the DCP */
666 Film::dcp_name (bool if_created_now) const
668 if (use_dci_name()) {
669 return dci_name (if_created_now);
677 Film::set_directory (string d)
679 boost::mutex::scoped_lock lm (_state_mutex);
685 Film::set_name (string n)
688 boost::mutex::scoped_lock lm (_state_mutex);
691 signal_changed (NAME);
695 Film::set_use_dci_name (bool u)
698 boost::mutex::scoped_lock lm (_state_mutex);
701 signal_changed (USE_DCI_NAME);
705 Film::set_trust_content_headers (bool t)
708 boost::mutex::scoped_lock lm (_state_mutex);
709 _trust_content_headers = t;
712 signal_changed (TRUST_CONTENT_HEADERS);
714 if (!_trust_content_headers && !content().empty()) {
715 /* We just said that we don't trust the content's header */
716 ContentList c = content ();
717 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
718 examine_content (*i);
724 Film::set_dcp_content_type (DCPContentType const * t)
727 boost::mutex::scoped_lock lm (_state_mutex);
728 _dcp_content_type = t;
730 signal_changed (DCP_CONTENT_TYPE);
734 Film::set_format (Format const * f)
737 boost::mutex::scoped_lock lm (_state_mutex);
740 signal_changed (FORMAT);
744 Film::set_crop (Crop c)
747 boost::mutex::scoped_lock lm (_state_mutex);
750 signal_changed (CROP);
754 Film::set_left_crop (int c)
757 boost::mutex::scoped_lock lm (_state_mutex);
759 if (_crop.left == c) {
765 signal_changed (CROP);
769 Film::set_right_crop (int c)
772 boost::mutex::scoped_lock lm (_state_mutex);
773 if (_crop.right == c) {
779 signal_changed (CROP);
783 Film::set_top_crop (int c)
786 boost::mutex::scoped_lock lm (_state_mutex);
787 if (_crop.top == c) {
793 signal_changed (CROP);
797 Film::set_bottom_crop (int c)
800 boost::mutex::scoped_lock lm (_state_mutex);
801 if (_crop.bottom == c) {
807 signal_changed (CROP);
811 Film::set_filters (vector<Filter const *> f)
814 boost::mutex::scoped_lock lm (_state_mutex);
817 signal_changed (FILTERS);
821 Film::set_scaler (Scaler const * s)
824 boost::mutex::scoped_lock lm (_state_mutex);
827 signal_changed (SCALER);
831 Film::set_trim_start (int t)
834 boost::mutex::scoped_lock lm (_state_mutex);
837 signal_changed (TRIM_START);
841 Film::set_trim_end (int t)
844 boost::mutex::scoped_lock lm (_state_mutex);
847 signal_changed (TRIM_END);
851 Film::set_ab (bool a)
854 boost::mutex::scoped_lock lm (_state_mutex);
861 Film::set_audio_gain (float g)
864 boost::mutex::scoped_lock lm (_state_mutex);
867 signal_changed (AUDIO_GAIN);
871 Film::set_audio_delay (int d)
874 boost::mutex::scoped_lock lm (_state_mutex);
877 signal_changed (AUDIO_DELAY);
881 Film::set_with_subtitles (bool w)
884 boost::mutex::scoped_lock lm (_state_mutex);
887 signal_changed (WITH_SUBTITLES);
891 Film::set_subtitle_offset (int o)
894 boost::mutex::scoped_lock lm (_state_mutex);
895 _subtitle_offset = o;
897 signal_changed (SUBTITLE_OFFSET);
901 Film::set_subtitle_scale (float s)
904 boost::mutex::scoped_lock lm (_state_mutex);
907 signal_changed (SUBTITLE_SCALE);
911 Film::set_colour_lut (int i)
914 boost::mutex::scoped_lock lm (_state_mutex);
917 signal_changed (COLOUR_LUT);
921 Film::set_j2k_bandwidth (int b)
924 boost::mutex::scoped_lock lm (_state_mutex);
927 signal_changed (J2K_BANDWIDTH);
931 Film::set_dci_metadata (DCIMetadata m)
934 boost::mutex::scoped_lock lm (_state_mutex);
937 signal_changed (DCI_METADATA);
942 Film::set_dcp_frame_rate (int f)
945 boost::mutex::scoped_lock lm (_state_mutex);
948 signal_changed (DCP_FRAME_RATE);
952 Film::signal_changed (Property p)
955 boost::mutex::scoped_lock lm (_state_mutex);
961 _playlist->setup (content ());
962 set_dcp_frame_rate (best_dcp_frame_rate (video_frame_rate ()));
963 set_audio_mapping (_playlist->default_audio_mapping ());
970 ui_signaller->emit (boost::bind (boost::ref (Changed), p));
975 Film::set_dci_date_today ()
977 _dci_date = boost::gregorian::day_clock::local_day ();
981 Film::info_path (int f) const
983 boost::filesystem::path p;
988 s << setfill('0') << f << ".md5";
992 /* info_dir() will already have added any initial bit of the path,
993 so don't call file() on this.
999 Film::j2c_path (int f, bool t) const
1001 boost::filesystem::path p;
1003 p /= video_state_identifier ();
1007 s << setfill('0') << f << ".j2c";
1014 return file (p.string ());
1017 /** Make an educated guess as to whether we have a complete DCP
1019 * @return true if we do.
1023 Film::have_dcp () const
1026 libdcp::DCP dcp (dir (dcp_name()));
1036 Film::player () const
1038 boost::mutex::scoped_lock lm (_state_mutex);
1039 return shared_ptr<Player> (new Player (shared_from_this (), _playlist));
1043 Film::add_content (shared_ptr<Content> c)
1046 boost::mutex::scoped_lock lm (_state_mutex);
1047 _content.push_back (c);
1050 signal_changed (CONTENT);
1052 examine_content (c);
1056 Film::remove_content (shared_ptr<Content> c)
1059 boost::mutex::scoped_lock lm (_state_mutex);
1060 ContentList::iterator i = find (_content.begin(), _content.end(), c);
1061 if (i != _content.end ()) {
1066 signal_changed (CONTENT);
1070 Film::move_content_earlier (shared_ptr<Content> c)
1073 boost::mutex::scoped_lock lm (_state_mutex);
1074 ContentList::iterator i = find (_content.begin(), _content.end(), c);
1075 if (i == _content.begin () || i == _content.end()) {
1079 ContentList::iterator j = i;
1085 signal_changed (CONTENT);
1089 Film::move_content_later (shared_ptr<Content> c)
1092 boost::mutex::scoped_lock lm (_state_mutex);
1093 ContentList::iterator i = find (_content.begin(), _content.end(), c);
1094 if (i == _content.end()) {
1098 ContentList::iterator j = i;
1100 if (j == _content.end ()) {
1107 signal_changed (CONTENT);
1112 Film::audio_length () const
1114 return _playlist->audio_length ();
1118 Film::audio_channels () const
1120 return _playlist->audio_channels ();
1124 Film::audio_frame_rate () const
1126 return _playlist->audio_frame_rate ();
1130 Film::has_audio () const
1132 return _playlist->has_audio ();
1136 Film::video_frame_rate () const
1138 return _playlist->video_frame_rate ();
1142 Film::video_size () const
1144 return _playlist->video_size ();
1148 Film::video_length () const
1150 return _playlist->video_length ();
1153 /** Unfortunately this is needed as the GUI has FFmpeg-specific controls */
1154 shared_ptr<FFmpegContent>
1155 Film::ffmpeg () const
1157 boost::mutex::scoped_lock lm (_state_mutex);
1159 for (ContentList::const_iterator i = _content.begin (); i != _content.end(); ++i) {
1160 shared_ptr<FFmpegContent> f = boost::dynamic_pointer_cast<FFmpegContent> (*i);
1166 return shared_ptr<FFmpegContent> ();
1169 vector<FFmpegSubtitleStream>
1170 Film::ffmpeg_subtitle_streams () const
1172 shared_ptr<FFmpegContent> f = ffmpeg ();
1174 return f->subtitle_streams ();
1177 return vector<FFmpegSubtitleStream> ();
1180 boost::optional<FFmpegSubtitleStream>
1181 Film::ffmpeg_subtitle_stream () const
1183 shared_ptr<FFmpegContent> f = ffmpeg ();
1185 return f->subtitle_stream ();
1191 vector<FFmpegAudioStream>
1192 Film::ffmpeg_audio_streams () const
1194 shared_ptr<FFmpegContent> f = ffmpeg ();
1196 return f->audio_streams ();
1199 return vector<FFmpegAudioStream> ();
1202 boost::optional<FFmpegAudioStream>
1203 Film::ffmpeg_audio_stream () const
1205 shared_ptr<FFmpegContent> f = ffmpeg ();
1207 return f->audio_stream ();
1214 Film::set_ffmpeg_subtitle_stream (FFmpegSubtitleStream s)
1216 shared_ptr<FFmpegContent> f = ffmpeg ();
1218 f->set_subtitle_stream (s);
1223 Film::set_ffmpeg_audio_stream (FFmpegAudioStream s)
1225 shared_ptr<FFmpegContent> f = ffmpeg ();
1227 f->set_audio_stream (s);
1232 Film::set_audio_mapping (AudioMapping m)
1235 boost::mutex::scoped_lock lm (_state_mutex);
1239 signal_changed (AUDIO_MAPPING);
1243 Film::content_changed (boost::weak_ptr<Content> c, int p)
1245 if (p == VideoContentProperty::VIDEO_FRAME_RATE) {
1246 set_dcp_frame_rate (best_dcp_frame_rate (video_frame_rate ()));
1247 } else if (p == AudioContentProperty::AUDIO_CHANNELS) {
1248 set_audio_mapping (_playlist->default_audio_mapping ());
1252 ui_signaller->emit (boost::bind (boost::ref (ContentChanged), c, p));