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"))
105 , _with_subtitles (false)
106 , _subtitle_offset (0)
107 , _subtitle_scale (1)
109 , _j2k_bandwidth (200000000)
110 , _dci_metadata (Config::instance()->default_dci_metadata ())
111 , _dcp_frame_rate (0)
114 set_dci_date_today ();
116 _playlist->ContentChanged.connect (bind (&Film::content_changed, this, _1, _2));
118 /* Make state.directory a complete path without ..s (where possible)
119 (Code swiped from Adam Bowen on stackoverflow)
122 boost::filesystem::path p (boost::filesystem::system_complete (d));
123 boost::filesystem::path result;
124 for (boost::filesystem::path::iterator i = p.begin(); i != p.end(); ++i) {
126 if (boost::filesystem::is_symlink (result) || result.filename() == "..") {
129 result = result.parent_path ();
131 } else if (*i != ".") {
136 set_directory (result.string ());
138 if (!boost::filesystem::exists (directory())) {
140 throw OpenFileError (directory());
142 boost::filesystem::create_directory (directory());
150 _log.reset (new FileLog (file ("log")));
153 Film::Film (Film const & o)
154 : boost::enable_shared_from_this<Film> (o)
155 /* note: the copied film shares the original's log */
157 , _playlist (new Playlist)
158 , _directory (o._directory)
160 , _use_dci_name (o._use_dci_name)
161 , _trust_content_headers (o._trust_content_headers)
162 , _dcp_content_type (o._dcp_content_type)
163 , _format (o._format)
165 , _filters (o._filters)
166 , _scaler (o._scaler)
167 , _trim_start (o._trim_start)
168 , _trim_end (o._trim_end)
169 , _trim_type (o._trim_type)
171 , _audio_gain (o._audio_gain)
172 , _audio_delay (o._audio_delay)
173 , _with_subtitles (o._with_subtitles)
174 , _subtitle_offset (o._subtitle_offset)
175 , _subtitle_scale (o._subtitle_scale)
176 , _colour_lut (o._colour_lut)
177 , _j2k_bandwidth (o._j2k_bandwidth)
178 , _dci_metadata (o._dci_metadata)
179 , _dcp_frame_rate (o._dcp_frame_rate)
180 , _dci_date (o._dci_date)
183 for (ContentList::const_iterator i = o._content.begin(); i != o._content.end(); ++i) {
184 _content.push_back ((*i)->clone ());
187 _playlist->ContentChanged.connect (bind (&Film::content_changed, this, _1, _2));
189 _playlist->setup (_content);
193 Film::video_state_identifier () const
197 pair<string, string> f = Filter::ffmpeg_strings (filters());
201 << "_" << _playlist->video_digest()
202 << "_" << crop().left << "_" << crop().right << "_" << crop().top << "_" << crop().bottom
203 << "_" << _dcp_frame_rate
204 << "_" << f.first << "_" << f.second
205 << "_" << scaler()->id()
206 << "_" << j2k_bandwidth()
207 << "_" << boost::lexical_cast<int> (colour_lut());
210 pair<string, string> fa = Filter::ffmpeg_strings (Config::instance()->reference_filters());
211 s << "ab_" << Config::instance()->reference_scaler()->id() << "_" << fa.first << "_" << fa.second;
217 /** @return The path to the directory to write video frame info files to */
219 Film::info_dir () const
221 boost::filesystem::path p;
223 p /= video_state_identifier ();
224 return dir (p.string());
228 Film::internal_video_mxf_dir () const
230 boost::filesystem::path p;
231 return dir ("video");
235 Film::internal_video_mxf_filename () const
237 return video_state_identifier() + ".mxf";
241 Film::dcp_video_mxf_filename () const
243 return filename_safe_name() + "_video.mxf";
247 Film::dcp_audio_mxf_filename () const
249 return filename_safe_name() + "_audio.mxf";
253 Film::filename_safe_name () const
255 string const n = name ();
257 for (size_t i = 0; i < n.length(); ++i) {
258 if (isalnum (n[i])) {
269 Film::audio_analysis_path () const
271 boost::filesystem::path p;
273 p /= _playlist->audio_digest();
274 return file (p.string ());
277 /** Add suitable Jobs to the JobManager to create a DCP for this Film */
281 set_dci_date_today ();
283 if (dcp_name().find ("/") != string::npos) {
284 throw BadSettingError (_("name"), _("cannot contain slashes"));
287 log()->log (String::compose ("DCP-o-matic %1 git %2 using %3", dcpomatic_version, dcpomatic_git_commit, dependency_version_summary()));
291 gethostname (buffer, sizeof (buffer));
292 log()->log (String::compose ("Starting to make DCP on %1", buffer));
295 // log()->log (String::compose ("Content is %1; type %2", content_path(), (content_type() == STILL ? _("still") : _("video"))));
297 // log()->log (String::compose ("Content length %1", length().get()));
299 // log()->log (String::compose ("Content digest %1", content_digest()));
300 // log()->log (String::compose ("Content at %1 fps, DCP at %2 fps", source_frame_rate(), dcp_frame_rate()));
301 log()->log (String::compose ("%1 threads", Config::instance()->num_local_encoding_threads()));
302 log()->log (String::compose ("J2K bandwidth %1", j2k_bandwidth()));
303 #ifdef DCPOMATIC_DEBUG
304 log()->log ("DCP-o-matic built in debug mode.");
306 log()->log ("DCP-o-matic built in optimised mode.");
309 log()->log ("libdcp built in debug mode.");
311 log()->log ("libdcp built in optimised mode.");
313 pair<string, int> const c = cpu_info ();
314 log()->log (String::compose ("CPU: %1, %2 processors", c.first, c.second));
317 throw MissingSettingError (_("format"));
320 if (content().empty ()) {
321 throw MissingSettingError (_("content"));
324 if (dcp_content_type() == 0) {
325 throw MissingSettingError (_("content type"));
328 if (name().empty()) {
329 throw MissingSettingError (_("name"));
335 r = JobManager::instance()->add (shared_ptr<Job> (new ABTranscodeJob (shared_from_this())));
337 r = JobManager::instance()->add (shared_ptr<Job> (new TranscodeJob (shared_from_this())));
341 /** Start a job to analyse the audio in our Playlist */
343 Film::analyse_audio ()
345 if (_analyse_audio_job) {
349 _analyse_audio_job.reset (new AnalyseAudioJob (shared_from_this()));
350 _analyse_audio_job->Finished.connect (bind (&Film::analyse_audio_finished, this));
351 JobManager::instance()->add (_analyse_audio_job);
354 /** Start a job to examine a piece of content */
356 Film::examine_content (shared_ptr<Content> c)
358 shared_ptr<Job> j (new ExamineContentJob (shared_from_this(), c, trust_content_headers ()));
359 JobManager::instance()->add (j);
363 Film::analyse_audio_finished ()
367 if (_analyse_audio_job->finished_ok ()) {
368 AudioAnalysisSucceeded ();
371 _analyse_audio_job.reset ();
374 /** Start a job to send our DCP to the configured TMS */
376 Film::send_dcp_to_tms ()
378 shared_ptr<Job> j (new SCPDCPJob (shared_from_this()));
379 JobManager::instance()->add (j);
382 /** Count the number of frames that have been encoded for this film.
383 * @return frame count.
386 Film::encoded_frames () const
393 for (boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (info_dir ()); i != boost::filesystem::directory_iterator(); ++i) {
395 boost::this_thread::interruption_point ();
401 /** Write state to our `metadata' file */
403 Film::write_metadata () const
405 ContentList the_content = content ();
407 boost::mutex::scoped_lock lm (_state_mutex);
409 boost::filesystem::create_directories (directory());
412 xmlpp::Element* root = doc.create_root_node ("Metadata");
414 root->add_child("Version")->add_child_text (boost::lexical_cast<string> (state_version));
415 root->add_child("Name")->add_child_text (_name);
416 root->add_child("UseDCIName")->add_child_text (_use_dci_name ? "1" : "0");
417 root->add_child("TrustContentHeaders")->add_child_text (_trust_content_headers ? "1" : "0");
419 if (_dcp_content_type) {
420 root->add_child("DCPContentType")->add_child_text (_dcp_content_type->dci_name ());
424 root->add_child("Format")->add_child_text (_format->id ());
427 switch (_trim_type) {
429 root->add_child("TrimType")->add_child_text ("CPL");
432 root->add_child("TrimType")->add_child_text ("Encode");
435 root->add_child("LeftCrop")->add_child_text (boost::lexical_cast<string> (_crop.left));
436 root->add_child("RightCrop")->add_child_text (boost::lexical_cast<string> (_crop.right));
437 root->add_child("TopCrop")->add_child_text (boost::lexical_cast<string> (_crop.top));
438 root->add_child("BottomCrop")->add_child_text (boost::lexical_cast<string> (_crop.bottom));
440 for (vector<Filter const *>::const_iterator i = _filters.begin(); i != _filters.end(); ++i) {
441 root->add_child("Filter")->add_child_text ((*i)->id ());
444 root->add_child("Scaler")->add_child_text (_scaler->id ());
445 root->add_child("TrimStart")->add_child_text (boost::lexical_cast<string> (_trim_start));
446 root->add_child("TrimEnd")->add_child_text (boost::lexical_cast<string> (_trim_end));
447 root->add_child("AB")->add_child_text (_ab ? "1" : "0");
448 root->add_child("AudioGain")->add_child_text (boost::lexical_cast<string> (_audio_gain));
449 root->add_child("AudioDelay")->add_child_text (boost::lexical_cast<string> (_audio_delay));
450 root->add_child("WithSubtitles")->add_child_text (_with_subtitles ? "1" : "0");
451 root->add_child("SubtitleOffset")->add_child_text (boost::lexical_cast<string> (_subtitle_offset));
452 root->add_child("SubtitleScale")->add_child_text (boost::lexical_cast<string> (_subtitle_scale));
453 root->add_child("ColourLUT")->add_child_text (boost::lexical_cast<string> (_colour_lut));
454 root->add_child("J2KBandwidth")->add_child_text (boost::lexical_cast<string> (_j2k_bandwidth));
455 _dci_metadata.as_xml (root->add_child ("DCIMetadata"));
456 root->add_child("DCPFrameRate")->add_child_text (boost::lexical_cast<string> (_dcp_frame_rate));
457 root->add_child("DCIDate")->add_child_text (boost::gregorian::to_iso_string (_dci_date));
458 _audio_mapping.as_xml (root->add_child("AudioMapping"));
460 for (ContentList::iterator i = the_content.begin(); i != the_content.end(); ++i) {
461 (*i)->as_xml (root->add_child ("Content"));
464 doc.write_to_file_formatted (file ("metadata.xml"));
469 /** Read state from our metadata file */
471 Film::read_metadata ()
473 boost::mutex::scoped_lock lm (_state_mutex);
475 if (boost::filesystem::exists (file ("metadata")) && !boost::filesystem::exists (file ("metadata.xml"))) {
476 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!"));
479 cxml::File f (file ("metadata.xml"), "Metadata");
481 _name = f.string_child ("Name");
482 _use_dci_name = f.bool_child ("UseDCIName");
483 _trust_content_headers = f.bool_child ("TrustContentHeaders");
486 optional<string> c = f.optional_string_child ("DCPContentType");
488 _dcp_content_type = DCPContentType::from_dci_name (c.get ());
493 optional<string> c = f.optional_string_child ("Format");
495 _format = Format::from_id (c.get ());
500 optional<string> c = f.optional_string_child ("TrimType");
501 if (!c || c.get() == "CPL") {
503 } else if (c && c.get() == "Encode") {
508 _crop.left = f.number_child<int> ("LeftCrop");
509 _crop.right = f.number_child<int> ("RightCrop");
510 _crop.top = f.number_child<int> ("TopCrop");
511 _crop.bottom = f.number_child<int> ("BottomCrop");
514 list<shared_ptr<cxml::Node> > c = f.node_children ("Filter");
515 for (list<shared_ptr<cxml::Node> >::iterator i = c.begin(); i != c.end(); ++i) {
516 _filters.push_back (Filter::from_id ((*i)->content ()));
520 _scaler = Scaler::from_id (f.string_child ("Scaler"));
521 _trim_start = f.number_child<int> ("TrimStart");
522 _trim_end = f.number_child<int> ("TrimEnd");
523 _ab = f.bool_child ("AB");
524 _audio_gain = f.number_child<float> ("AudioGain");
525 _audio_delay = f.number_child<int> ("AudioDelay");
526 _with_subtitles = f.bool_child ("WithSubtitles");
527 _subtitle_offset = f.number_child<float> ("SubtitleOffset");
528 _subtitle_scale = f.number_child<float> ("SubtitleScale");
529 _colour_lut = f.number_child<int> ("ColourLUT");
530 _j2k_bandwidth = f.number_child<int> ("J2KBandwidth");
531 _dci_metadata = DCIMetadata (f.node_child ("DCIMetadata"));
532 _dcp_frame_rate = f.number_child<int> ("DCPFrameRate");
533 _dci_date = boost::gregorian::from_undelimited_string (f.string_child ("DCIDate"));
535 list<shared_ptr<cxml::Node> > c = f.node_children ("Content");
536 for (list<shared_ptr<cxml::Node> >::iterator i = c.begin(); i != c.end(); ++i) {
538 string const type = (*i)->string_child ("Type");
539 boost::shared_ptr<Content> c;
541 if (type == "FFmpeg") {
542 c.reset (new FFmpegContent (*i));
543 } else if (type == "ImageMagick") {
544 c.reset (new ImageMagickContent (*i));
545 } else if (type == "Sndfile") {
546 c.reset (new SndfileContent (*i));
549 _content.push_back (c);
552 /* This must come after we've loaded the content, as we're looking things up in _content */
553 _audio_mapping.set_from_xml (_content, f.node_child ("AudioMapping"));
557 _playlist->setup (_content);
561 Film::cropped_size (libdcp::Size s) const
563 boost::mutex::scoped_lock lm (_state_mutex);
564 s.width -= _crop.left + _crop.right;
565 s.height -= _crop.top + _crop.bottom;
569 /** Given a directory name, return its full path within the Film's directory.
570 * The directory (and its parents) will be created if they do not exist.
573 Film::dir (string d) const
575 boost::mutex::scoped_lock lm (_directory_mutex);
577 boost::filesystem::path p;
581 boost::filesystem::create_directories (p);
586 /** Given a file or directory name, return its full path within the Film's directory.
587 * _directory_mutex must not be locked on entry.
588 * Any required parent directories will be created.
591 Film::file (string f) const
593 boost::mutex::scoped_lock lm (_directory_mutex);
595 boost::filesystem::path p;
599 boost::filesystem::create_directories (p.parent_path ());
604 /** @return The sampling rate that we will resample the audio to */
606 Film::target_audio_sample_rate () const
612 /* Resample to a DCI-approved sample rate */
613 double t = dcp_audio_sample_rate (audio_frame_rate());
615 FrameRateConversion frc (video_frame_rate(), dcp_frame_rate());
617 /* Compensate if the DCP is being run at a different frame rate
618 to the source; that is, if the video is run such that it will
619 look different in the DCP compared to the source (slower or faster).
620 skip/repeat doesn't come into effect here.
623 if (frc.change_speed) {
624 t *= video_frame_rate() * frc.factor() / dcp_frame_rate();
630 /** @return a DCI-compliant name for a DCP of this film */
632 Film::dci_name (bool if_created_now) const
636 string fixed_name = to_upper_copy (name());
637 for (size_t i = 0; i < fixed_name.length(); ++i) {
638 if (fixed_name[i] == ' ') {
643 /* Spec is that the name part should be maximum 14 characters, as I understand it */
644 if (fixed_name.length() > 14) {
645 fixed_name = fixed_name.substr (0, 14);
650 if (dcp_content_type()) {
651 d << "_" << dcp_content_type()->dci_name();
655 d << "_" << format()->dci_name();
658 DCIMetadata const dm = dci_metadata ();
660 if (!dm.audio_language.empty ()) {
661 d << "_" << dm.audio_language;
662 if (!dm.subtitle_language.empty()) {
663 d << "-" << dm.subtitle_language;
669 if (!dm.territory.empty ()) {
670 d << "_" << dm.territory;
671 if (!dm.rating.empty ()) {
672 d << "-" << dm.rating;
676 switch (audio_channels ()) {
693 if (!dm.studio.empty ()) {
694 d << "_" << dm.studio;
697 if (if_created_now) {
698 d << "_" << boost::gregorian::to_iso_string (boost::gregorian::day_clock::local_day ());
700 d << "_" << boost::gregorian::to_iso_string (_dci_date);
703 if (!dm.facility.empty ()) {
704 d << "_" << dm.facility;
707 if (!dm.package_type.empty ()) {
708 d << "_" << dm.package_type;
714 /** @return name to give the DCP */
716 Film::dcp_name (bool if_created_now) const
718 if (use_dci_name()) {
719 return dci_name (if_created_now);
727 Film::set_directory (string d)
729 boost::mutex::scoped_lock lm (_state_mutex);
735 Film::set_name (string n)
738 boost::mutex::scoped_lock lm (_state_mutex);
741 signal_changed (NAME);
745 Film::set_use_dci_name (bool u)
748 boost::mutex::scoped_lock lm (_state_mutex);
751 signal_changed (USE_DCI_NAME);
755 Film::set_trust_content_headers (bool t)
758 boost::mutex::scoped_lock lm (_state_mutex);
759 _trust_content_headers = t;
762 signal_changed (TRUST_CONTENT_HEADERS);
764 if (!_trust_content_headers && !content().empty()) {
765 /* We just said that we don't trust the content's header */
766 ContentList c = content ();
767 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
768 examine_content (*i);
774 Film::set_dcp_content_type (DCPContentType const * t)
777 boost::mutex::scoped_lock lm (_state_mutex);
778 _dcp_content_type = t;
780 signal_changed (DCP_CONTENT_TYPE);
784 Film::set_format (Format const * f)
787 boost::mutex::scoped_lock lm (_state_mutex);
790 signal_changed (FORMAT);
794 Film::set_crop (Crop c)
797 boost::mutex::scoped_lock lm (_state_mutex);
800 signal_changed (CROP);
804 Film::set_left_crop (int c)
807 boost::mutex::scoped_lock lm (_state_mutex);
809 if (_crop.left == c) {
815 signal_changed (CROP);
819 Film::set_right_crop (int c)
822 boost::mutex::scoped_lock lm (_state_mutex);
823 if (_crop.right == c) {
829 signal_changed (CROP);
833 Film::set_top_crop (int c)
836 boost::mutex::scoped_lock lm (_state_mutex);
837 if (_crop.top == c) {
843 signal_changed (CROP);
847 Film::set_bottom_crop (int c)
850 boost::mutex::scoped_lock lm (_state_mutex);
851 if (_crop.bottom == c) {
857 signal_changed (CROP);
861 Film::set_filters (vector<Filter const *> f)
864 boost::mutex::scoped_lock lm (_state_mutex);
867 signal_changed (FILTERS);
871 Film::set_scaler (Scaler const * s)
874 boost::mutex::scoped_lock lm (_state_mutex);
877 signal_changed (SCALER);
881 Film::set_trim_start (int t)
884 boost::mutex::scoped_lock lm (_state_mutex);
887 signal_changed (TRIM_START);
891 Film::set_trim_end (int t)
894 boost::mutex::scoped_lock lm (_state_mutex);
897 signal_changed (TRIM_END);
901 Film::set_trim_type (TrimType t)
904 boost::mutex::scoped_lock lm (_state_mutex);
907 signal_changed (TRIM_TYPE);
911 Film::set_ab (bool a)
914 boost::mutex::scoped_lock lm (_state_mutex);
921 Film::set_audio_gain (float g)
924 boost::mutex::scoped_lock lm (_state_mutex);
927 signal_changed (AUDIO_GAIN);
931 Film::set_audio_delay (int d)
934 boost::mutex::scoped_lock lm (_state_mutex);
937 signal_changed (AUDIO_DELAY);
941 Film::set_with_subtitles (bool w)
944 boost::mutex::scoped_lock lm (_state_mutex);
947 signal_changed (WITH_SUBTITLES);
951 Film::set_subtitle_offset (int o)
954 boost::mutex::scoped_lock lm (_state_mutex);
955 _subtitle_offset = o;
957 signal_changed (SUBTITLE_OFFSET);
961 Film::set_subtitle_scale (float s)
964 boost::mutex::scoped_lock lm (_state_mutex);
967 signal_changed (SUBTITLE_SCALE);
971 Film::set_colour_lut (int i)
974 boost::mutex::scoped_lock lm (_state_mutex);
977 signal_changed (COLOUR_LUT);
981 Film::set_j2k_bandwidth (int b)
984 boost::mutex::scoped_lock lm (_state_mutex);
987 signal_changed (J2K_BANDWIDTH);
991 Film::set_dci_metadata (DCIMetadata m)
994 boost::mutex::scoped_lock lm (_state_mutex);
997 signal_changed (DCI_METADATA);
1002 Film::set_dcp_frame_rate (int f)
1005 boost::mutex::scoped_lock lm (_state_mutex);
1006 _dcp_frame_rate = f;
1008 signal_changed (DCP_FRAME_RATE);
1012 Film::signal_changed (Property p)
1015 boost::mutex::scoped_lock lm (_state_mutex);
1021 _playlist->setup (content ());
1022 set_dcp_frame_rate (best_dcp_frame_rate (video_frame_rate ()));
1023 set_audio_mapping (_playlist->default_audio_mapping ());
1030 ui_signaller->emit (boost::bind (boost::ref (Changed), p));
1035 Film::set_dci_date_today ()
1037 _dci_date = boost::gregorian::day_clock::local_day ();
1041 Film::info_path (int f) const
1043 boost::filesystem::path p;
1048 s << setfill('0') << f << ".md5";
1052 /* info_dir() will already have added any initial bit of the path,
1053 so don't call file() on this.
1059 Film::j2c_path (int f, bool t) const
1061 boost::filesystem::path p;
1063 p /= video_state_identifier ();
1067 s << setfill('0') << f << ".j2c";
1074 return file (p.string ());
1077 /** Make an educated guess as to whether we have a complete DCP
1079 * @return true if we do.
1083 Film::have_dcp () const
1086 libdcp::DCP dcp (dir (dcp_name()));
1096 Film::player () const
1098 boost::mutex::scoped_lock lm (_state_mutex);
1099 return shared_ptr<Player> (new Player (shared_from_this (), _playlist));
1103 Film::add_content (shared_ptr<Content> c)
1106 boost::mutex::scoped_lock lm (_state_mutex);
1107 _content.push_back (c);
1110 signal_changed (CONTENT);
1112 examine_content (c);
1116 Film::remove_content (shared_ptr<Content> c)
1119 boost::mutex::scoped_lock lm (_state_mutex);
1120 ContentList::iterator i = find (_content.begin(), _content.end(), c);
1121 if (i != _content.end ()) {
1126 signal_changed (CONTENT);
1130 Film::move_content_earlier (shared_ptr<Content> c)
1133 boost::mutex::scoped_lock lm (_state_mutex);
1134 ContentList::iterator i = find (_content.begin(), _content.end(), c);
1135 if (i == _content.begin () || i == _content.end()) {
1139 ContentList::iterator j = i;
1145 signal_changed (CONTENT);
1149 Film::move_content_later (shared_ptr<Content> c)
1152 boost::mutex::scoped_lock lm (_state_mutex);
1153 ContentList::iterator i = find (_content.begin(), _content.end(), c);
1154 if (i == _content.end()) {
1158 ContentList::iterator j = i;
1160 if (j == _content.end ()) {
1167 signal_changed (CONTENT);
1172 Film::audio_length () const
1174 return _playlist->audio_length ();
1178 Film::audio_channels () const
1180 return _playlist->audio_channels ();
1184 Film::audio_frame_rate () const
1186 return _playlist->audio_frame_rate ();
1190 Film::has_audio () const
1192 return _playlist->has_audio ();
1196 Film::video_frame_rate () const
1198 return _playlist->video_frame_rate ();
1202 Film::video_size () const
1204 return _playlist->video_size ();
1208 Film::video_length () const
1210 return _playlist->video_length ();
1213 /** Unfortunately this is needed as the GUI has FFmpeg-specific controls */
1214 shared_ptr<FFmpegContent>
1215 Film::ffmpeg () const
1217 boost::mutex::scoped_lock lm (_state_mutex);
1219 for (ContentList::const_iterator i = _content.begin (); i != _content.end(); ++i) {
1220 shared_ptr<FFmpegContent> f = boost::dynamic_pointer_cast<FFmpegContent> (*i);
1226 return shared_ptr<FFmpegContent> ();
1229 vector<FFmpegSubtitleStream>
1230 Film::ffmpeg_subtitle_streams () const
1232 shared_ptr<FFmpegContent> f = ffmpeg ();
1234 return f->subtitle_streams ();
1237 return vector<FFmpegSubtitleStream> ();
1240 boost::optional<FFmpegSubtitleStream>
1241 Film::ffmpeg_subtitle_stream () const
1243 shared_ptr<FFmpegContent> f = ffmpeg ();
1245 return f->subtitle_stream ();
1251 vector<FFmpegAudioStream>
1252 Film::ffmpeg_audio_streams () const
1254 shared_ptr<FFmpegContent> f = ffmpeg ();
1256 return f->audio_streams ();
1259 return vector<FFmpegAudioStream> ();
1262 boost::optional<FFmpegAudioStream>
1263 Film::ffmpeg_audio_stream () const
1265 shared_ptr<FFmpegContent> f = ffmpeg ();
1267 return f->audio_stream ();
1274 Film::set_ffmpeg_subtitle_stream (FFmpegSubtitleStream s)
1276 shared_ptr<FFmpegContent> f = ffmpeg ();
1278 f->set_subtitle_stream (s);
1283 Film::set_ffmpeg_audio_stream (FFmpegAudioStream s)
1285 shared_ptr<FFmpegContent> f = ffmpeg ();
1287 f->set_audio_stream (s);
1292 Film::set_audio_mapping (AudioMapping m)
1295 boost::mutex::scoped_lock lm (_state_mutex);
1299 signal_changed (AUDIO_MAPPING);
1303 Film::content_changed (boost::weak_ptr<Content> c, int p)
1305 if (p == VideoContentProperty::VIDEO_FRAME_RATE) {
1306 set_dcp_frame_rate (best_dcp_frame_rate (video_frame_rate ()));
1307 } else if (p == AudioContentProperty::AUDIO_CHANNELS) {
1308 set_audio_mapping (_playlist->default_audio_mapping ());
1312 ui_signaller->emit (boost::bind (boost::ref (ContentChanged), c, p));