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());
152 _log.reset (new FileLog (file ("log")));
155 Film::Film (Film const & o)
156 : boost::enable_shared_from_this<Film> (o)
157 /* note: the copied film shares the original's log */
159 , _playlist (new Playlist)
160 , _directory (o._directory)
162 , _use_dci_name (o._use_dci_name)
163 , _trust_content_headers (o._trust_content_headers)
164 , _dcp_content_type (o._dcp_content_type)
165 , _format (o._format)
167 , _filters (o._filters)
168 , _scaler (o._scaler)
169 , _trim_start (o._trim_start)
170 , _trim_end (o._trim_end)
171 , _trim_type (o._trim_type)
173 , _audio_gain (o._audio_gain)
174 , _audio_delay (o._audio_delay)
175 , _with_subtitles (o._with_subtitles)
176 , _subtitle_offset (o._subtitle_offset)
177 , _subtitle_scale (o._subtitle_scale)
178 , _colour_lut (o._colour_lut)
179 , _j2k_bandwidth (o._j2k_bandwidth)
180 , _dci_metadata (o._dci_metadata)
181 , _dcp_frame_rate (o._dcp_frame_rate)
182 , _dci_date (o._dci_date)
185 for (ContentList::const_iterator i = o._content.begin(); i != o._content.end(); ++i) {
186 _content.push_back ((*i)->clone ());
189 _playlist->ContentChanged.connect (bind (&Film::content_changed, this, _1, _2));
191 _playlist->setup (_content);
195 Film::video_state_identifier () const
200 pair<string, string> f = Filter::ffmpeg_strings (filters());
204 << "_" << _playlist->video_digest()
205 << "_" << crop().left << "_" << crop().right << "_" << crop().top << "_" << crop().bottom
206 << "_" << _dcp_frame_rate
207 << "_" << f.first << "_" << f.second
208 << "_" << scaler()->id()
209 << "_" << j2k_bandwidth()
210 << "_" << boost::lexical_cast<int> (colour_lut());
213 pair<string, string> fa = Filter::ffmpeg_strings (Config::instance()->reference_filters());
214 s << "ab_" << Config::instance()->reference_scaler()->id() << "_" << fa.first << "_" << 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::internal_video_mxf_dir () const
233 boost::filesystem::path p;
234 return dir ("video");
238 Film::internal_video_mxf_filename () const
240 return video_state_identifier() + ".mxf";
244 Film::dcp_video_mxf_filename () const
246 return filename_safe_name() + "_video.mxf";
250 Film::dcp_audio_mxf_filename () const
252 return filename_safe_name() + "_audio.mxf";
256 Film::filename_safe_name () const
258 string const n = name ();
260 for (size_t i = 0; i < n.length(); ++i) {
261 if (isalnum (n[i])) {
272 Film::audio_analysis_path () const
274 boost::filesystem::path p;
276 p /= _playlist->audio_digest();
277 return file (p.string ());
280 /** Add suitable Jobs to the JobManager to create a DCP for this Film */
284 set_dci_date_today ();
286 if (dcp_name().find ("/") != string::npos) {
287 throw BadSettingError (_("name"), _("cannot contain slashes"));
290 log()->log (String::compose ("DCP-o-matic %1 git %2 using %3", dcpomatic_version, dcpomatic_git_commit, dependency_version_summary()));
294 gethostname (buffer, sizeof (buffer));
295 log()->log (String::compose ("Starting to make DCP on %1", buffer));
298 // log()->log (String::compose ("Content is %1; type %2", content_path(), (content_type() == STILL ? _("still") : _("video"))));
300 // log()->log (String::compose ("Content length %1", length().get()));
302 // log()->log (String::compose ("Content digest %1", content_digest()));
303 // log()->log (String::compose ("Content at %1 fps, DCP at %2 fps", source_frame_rate(), dcp_frame_rate()));
304 log()->log (String::compose ("%1 threads", Config::instance()->num_local_encoding_threads()));
305 log()->log (String::compose ("J2K bandwidth %1", j2k_bandwidth()));
306 #ifdef DCPOMATIC_DEBUG
307 log()->log ("DCP-o-matic built in debug mode.");
309 log()->log ("DCP-o-matic built in optimised mode.");
312 log()->log ("libdcp built in debug mode.");
314 log()->log ("libdcp built in optimised mode.");
316 pair<string, int> const c = cpu_info ();
317 log()->log (String::compose ("CPU: %1, %2 processors", c.first, c.second));
320 throw MissingSettingError (_("format"));
323 if (content().empty ()) {
324 throw MissingSettingError (_("content"));
327 if (dcp_content_type() == 0) {
328 throw MissingSettingError (_("content type"));
331 if (name().empty()) {
332 throw MissingSettingError (_("name"));
338 r = JobManager::instance()->add (shared_ptr<Job> (new ABTranscodeJob (shared_from_this())));
340 r = JobManager::instance()->add (shared_ptr<Job> (new TranscodeJob (shared_from_this())));
344 /** Start a job to analyse the audio in our Playlist */
346 Film::analyse_audio ()
348 if (_analyse_audio_job) {
352 _analyse_audio_job.reset (new AnalyseAudioJob (shared_from_this()));
353 _analyse_audio_job->Finished.connect (bind (&Film::analyse_audio_finished, this));
354 JobManager::instance()->add (_analyse_audio_job);
357 /** Start a job to examine a piece of content */
359 Film::examine_content (shared_ptr<Content> c)
361 shared_ptr<Job> j (new ExamineContentJob (shared_from_this(), c, trust_content_headers ()));
362 JobManager::instance()->add (j);
366 Film::analyse_audio_finished ()
370 if (_analyse_audio_job->finished_ok ()) {
371 AudioAnalysisSucceeded ();
374 _analyse_audio_job.reset ();
377 /** Start a job to send our DCP to the configured TMS */
379 Film::send_dcp_to_tms ()
381 shared_ptr<Job> j (new SCPDCPJob (shared_from_this()));
382 JobManager::instance()->add (j);
385 /** Count the number of frames that have been encoded for this film.
386 * @return frame count.
389 Film::encoded_frames () const
396 for (boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (info_dir ()); i != boost::filesystem::directory_iterator(); ++i) {
398 boost::this_thread::interruption_point ();
404 /** Write state to our `metadata' file */
406 Film::write_metadata () const
408 ContentList the_content = content ();
410 boost::mutex::scoped_lock lm (_state_mutex);
413 boost::filesystem::create_directories (directory());
416 xmlpp::Element* root = doc.create_root_node ("Metadata");
418 root->add_child("Version")->add_child_text (boost::lexical_cast<string> (state_version));
419 root->add_child("Name")->add_child_text (_name);
420 root->add_child("UseDCIName")->add_child_text (_use_dci_name ? "1" : "0");
421 root->add_child("TrustContentHeaders")->add_child_text (_trust_content_headers ? "1" : "0");
423 if (_dcp_content_type) {
424 root->add_child("DCPContentType")->add_child_text (_dcp_content_type->dci_name ());
428 root->add_child("Format")->add_child_text (_format->id ());
431 switch (_trim_type) {
433 root->add_child("TrimType")->add_child_text ("CPL");
436 root->add_child("TrimType")->add_child_text ("Encode");
439 root->add_child("LeftCrop")->add_child_text (boost::lexical_cast<string> (_crop.left));
440 root->add_child("RightCrop")->add_child_text (boost::lexical_cast<string> (_crop.right));
441 root->add_child("TopCrop")->add_child_text (boost::lexical_cast<string> (_crop.top));
442 root->add_child("BottomCrop")->add_child_text (boost::lexical_cast<string> (_crop.bottom));
444 for (vector<Filter const *>::const_iterator i = _filters.begin(); i != _filters.end(); ++i) {
445 root->add_child("Filter")->add_child_text ((*i)->id ());
448 root->add_child("Scaler")->add_child_text (_scaler->id ());
449 root->add_child("TrimStart")->add_child_text (boost::lexical_cast<string> (_trim_start));
450 root->add_child("TrimEnd")->add_child_text (boost::lexical_cast<string> (_trim_end));
451 root->add_child("AB")->add_child_text (_ab ? "1" : "0");
452 root->add_child("AudioGain")->add_child_text (boost::lexical_cast<string> (_audio_gain));
453 root->add_child("AudioDelay")->add_child_text (boost::lexical_cast<string> (_audio_delay));
454 root->add_child("WithSubtitles")->add_child_text (_with_subtitles ? "1" : "0");
455 root->add_child("SubtitleOffset")->add_child_text (boost::lexical_cast<string> (_subtitle_offset));
456 root->add_child("SubtitleScale")->add_child_text (boost::lexical_cast<string> (_subtitle_scale));
457 root->add_child("ColourLUT")->add_child_text (boost::lexical_cast<string> (_colour_lut));
458 root->add_child("J2KBandwidth")->add_child_text (boost::lexical_cast<string> (_j2k_bandwidth));
459 _dci_metadata.as_xml (root->add_child ("DCIMetadata"));
460 root->add_child("DCPFrameRate")->add_child_text (boost::lexical_cast<string> (_dcp_frame_rate));
461 root->add_child("DCIDate")->add_child_text (boost::gregorian::to_iso_string (_dci_date));
462 _audio_mapping.as_xml (root->add_child("AudioMapping"));
464 for (ContentList::iterator i = the_content.begin(); i != the_content.end(); ++i) {
465 (*i)->as_xml (root->add_child ("Content"));
468 doc.write_to_file_formatted (file ("metadata.xml"));
473 /** Read state from our metadata file */
475 Film::read_metadata ()
477 boost::mutex::scoped_lock lm (_state_mutex);
480 if (boost::filesystem::exists (file ("metadata")) && !boost::filesystem::exists (file ("metadata.xml"))) {
481 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!"));
484 cxml::File f (file ("metadata.xml"), "Metadata");
486 _name = f.string_child ("Name");
487 _use_dci_name = f.bool_child ("UseDCIName");
488 _trust_content_headers = f.bool_child ("TrustContentHeaders");
491 optional<string> c = f.optional_string_child ("DCPContentType");
493 _dcp_content_type = DCPContentType::from_dci_name (c.get ());
498 optional<string> c = f.optional_string_child ("Format");
500 _format = Format::from_id (c.get ());
505 optional<string> c = f.optional_string_child ("TrimType");
506 if (!c || c.get() == "CPL") {
508 } else if (c && c.get() == "Encode") {
513 _crop.left = f.number_child<int> ("LeftCrop");
514 _crop.right = f.number_child<int> ("RightCrop");
515 _crop.top = f.number_child<int> ("TopCrop");
516 _crop.bottom = f.number_child<int> ("BottomCrop");
519 list<shared_ptr<cxml::Node> > c = f.node_children ("Filter");
520 for (list<shared_ptr<cxml::Node> >::iterator i = c.begin(); i != c.end(); ++i) {
521 _filters.push_back (Filter::from_id ((*i)->content ()));
525 _scaler = Scaler::from_id (f.string_child ("Scaler"));
526 _trim_start = f.number_child<int> ("TrimStart");
527 _trim_end = f.number_child<int> ("TrimEnd");
528 _ab = f.bool_child ("AB");
529 _audio_gain = f.number_child<float> ("AudioGain");
530 _audio_delay = f.number_child<int> ("AudioDelay");
531 _with_subtitles = f.bool_child ("WithSubtitles");
532 _subtitle_offset = f.number_child<float> ("SubtitleOffset");
533 _subtitle_scale = f.number_child<float> ("SubtitleScale");
534 _colour_lut = f.number_child<int> ("ColourLUT");
535 _j2k_bandwidth = f.number_child<int> ("J2KBandwidth");
536 _dci_metadata = DCIMetadata (f.node_child ("DCIMetadata"));
537 _dcp_frame_rate = f.number_child<int> ("DCPFrameRate");
538 _dci_date = boost::gregorian::from_undelimited_string (f.string_child ("DCIDate"));
540 list<shared_ptr<cxml::Node> > c = f.node_children ("Content");
541 for (list<shared_ptr<cxml::Node> >::iterator i = c.begin(); i != c.end(); ++i) {
543 string const type = (*i)->string_child ("Type");
544 boost::shared_ptr<Content> c;
546 if (type == "FFmpeg") {
547 c.reset (new FFmpegContent (*i));
548 } else if (type == "ImageMagick") {
549 c.reset (new ImageMagickContent (*i));
550 } else if (type == "Sndfile") {
551 c.reset (new SndfileContent (*i));
554 _content.push_back (c);
557 /* This must come after we've loaded the content, as we're looking things up in _content */
558 _audio_mapping.set_from_xml (_content, f.node_child ("AudioMapping"));
562 _playlist->setup (_content);
566 Film::cropped_size (libdcp::Size s) const
568 boost::mutex::scoped_lock lm (_state_mutex);
569 s.width -= _crop.left + _crop.right;
570 s.height -= _crop.top + _crop.bottom;
574 /** Given a directory name, return its full path within the Film's directory.
575 * The directory (and its parents) will be created if they do not exist.
578 Film::dir (string d) const
580 boost::mutex::scoped_lock lm (_directory_mutex);
582 boost::filesystem::path p;
586 boost::filesystem::create_directories (p);
591 /** Given a file or directory name, return its full path within the Film's directory.
592 * _directory_mutex must not be locked on entry.
593 * Any required parent directories will be created.
596 Film::file (string f) const
598 boost::mutex::scoped_lock lm (_directory_mutex);
600 boost::filesystem::path p;
604 boost::filesystem::create_directories (p.parent_path ());
609 /** @return The sampling rate that we will resample the audio to */
611 Film::target_audio_sample_rate () const
617 /* Resample to a DCI-approved sample rate */
618 double t = dcp_audio_sample_rate (audio_frame_rate());
620 FrameRateConversion frc (video_frame_rate(), dcp_frame_rate());
622 /* Compensate if the DCP is being run at a different frame rate
623 to the source; that is, if the video is run such that it will
624 look different in the DCP compared to the source (slower or faster).
625 skip/repeat doesn't come into effect here.
628 if (frc.change_speed) {
629 t *= video_frame_rate() * frc.factor() / dcp_frame_rate();
635 /** @return a DCI-compliant name for a DCP of this film */
637 Film::dci_name (bool if_created_now) const
641 string fixed_name = to_upper_copy (name());
642 for (size_t i = 0; i < fixed_name.length(); ++i) {
643 if (fixed_name[i] == ' ') {
648 /* Spec is that the name part should be maximum 14 characters, as I understand it */
649 if (fixed_name.length() > 14) {
650 fixed_name = fixed_name.substr (0, 14);
655 if (dcp_content_type()) {
656 d << "_" << dcp_content_type()->dci_name();
660 d << "_" << format()->dci_name();
663 DCIMetadata const dm = dci_metadata ();
665 if (!dm.audio_language.empty ()) {
666 d << "_" << dm.audio_language;
667 if (!dm.subtitle_language.empty()) {
668 d << "-" << dm.subtitle_language;
674 if (!dm.territory.empty ()) {
675 d << "_" << dm.territory;
676 if (!dm.rating.empty ()) {
677 d << "-" << dm.rating;
681 switch (audio_channels ()) {
698 if (!dm.studio.empty ()) {
699 d << "_" << dm.studio;
702 if (if_created_now) {
703 d << "_" << boost::gregorian::to_iso_string (boost::gregorian::day_clock::local_day ());
705 d << "_" << boost::gregorian::to_iso_string (_dci_date);
708 if (!dm.facility.empty ()) {
709 d << "_" << dm.facility;
712 if (!dm.package_type.empty ()) {
713 d << "_" << dm.package_type;
719 /** @return name to give the DCP */
721 Film::dcp_name (bool if_created_now) const
723 if (use_dci_name()) {
724 return dci_name (if_created_now);
732 Film::set_directory (string d)
734 boost::mutex::scoped_lock lm (_state_mutex);
740 Film::set_name (string n)
743 boost::mutex::scoped_lock lm (_state_mutex);
746 signal_changed (NAME);
750 Film::set_use_dci_name (bool u)
753 boost::mutex::scoped_lock lm (_state_mutex);
756 signal_changed (USE_DCI_NAME);
760 Film::set_trust_content_headers (bool t)
763 boost::mutex::scoped_lock lm (_state_mutex);
764 _trust_content_headers = t;
767 signal_changed (TRUST_CONTENT_HEADERS);
769 if (!_trust_content_headers && !content().empty()) {
770 /* We just said that we don't trust the content's header */
771 ContentList c = content ();
772 for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
773 examine_content (*i);
779 Film::set_dcp_content_type (DCPContentType const * t)
782 boost::mutex::scoped_lock lm (_state_mutex);
783 _dcp_content_type = t;
785 signal_changed (DCP_CONTENT_TYPE);
789 Film::set_format (Format const * f)
792 boost::mutex::scoped_lock lm (_state_mutex);
795 signal_changed (FORMAT);
799 Film::set_crop (Crop c)
802 boost::mutex::scoped_lock lm (_state_mutex);
805 signal_changed (CROP);
809 Film::set_left_crop (int c)
812 boost::mutex::scoped_lock lm (_state_mutex);
814 if (_crop.left == c) {
820 signal_changed (CROP);
824 Film::set_right_crop (int c)
827 boost::mutex::scoped_lock lm (_state_mutex);
828 if (_crop.right == c) {
834 signal_changed (CROP);
838 Film::set_top_crop (int c)
841 boost::mutex::scoped_lock lm (_state_mutex);
842 if (_crop.top == c) {
848 signal_changed (CROP);
852 Film::set_bottom_crop (int c)
855 boost::mutex::scoped_lock lm (_state_mutex);
856 if (_crop.bottom == c) {
862 signal_changed (CROP);
866 Film::set_filters (vector<Filter const *> f)
869 boost::mutex::scoped_lock lm (_state_mutex);
872 signal_changed (FILTERS);
876 Film::set_scaler (Scaler const * s)
879 boost::mutex::scoped_lock lm (_state_mutex);
882 signal_changed (SCALER);
886 Film::set_trim_start (int t)
889 boost::mutex::scoped_lock lm (_state_mutex);
892 signal_changed (TRIM_START);
896 Film::set_trim_end (int t)
899 boost::mutex::scoped_lock lm (_state_mutex);
902 signal_changed (TRIM_END);
906 Film::set_trim_type (TrimType t)
909 boost::mutex::scoped_lock lm (_state_mutex);
912 signal_changed (TRIM_TYPE);
916 Film::set_ab (bool a)
919 boost::mutex::scoped_lock lm (_state_mutex);
926 Film::set_audio_gain (float g)
929 boost::mutex::scoped_lock lm (_state_mutex);
932 signal_changed (AUDIO_GAIN);
936 Film::set_audio_delay (int d)
939 boost::mutex::scoped_lock lm (_state_mutex);
942 signal_changed (AUDIO_DELAY);
946 Film::set_with_subtitles (bool w)
949 boost::mutex::scoped_lock lm (_state_mutex);
952 signal_changed (WITH_SUBTITLES);
956 Film::set_subtitle_offset (int o)
959 boost::mutex::scoped_lock lm (_state_mutex);
960 _subtitle_offset = o;
962 signal_changed (SUBTITLE_OFFSET);
966 Film::set_subtitle_scale (float s)
969 boost::mutex::scoped_lock lm (_state_mutex);
972 signal_changed (SUBTITLE_SCALE);
976 Film::set_colour_lut (int i)
979 boost::mutex::scoped_lock lm (_state_mutex);
982 signal_changed (COLOUR_LUT);
986 Film::set_j2k_bandwidth (int b)
989 boost::mutex::scoped_lock lm (_state_mutex);
992 signal_changed (J2K_BANDWIDTH);
996 Film::set_dci_metadata (DCIMetadata m)
999 boost::mutex::scoped_lock lm (_state_mutex);
1002 signal_changed (DCI_METADATA);
1007 Film::set_dcp_frame_rate (int f)
1010 boost::mutex::scoped_lock lm (_state_mutex);
1011 _dcp_frame_rate = f;
1013 signal_changed (DCP_FRAME_RATE);
1017 Film::signal_changed (Property p)
1020 boost::mutex::scoped_lock lm (_state_mutex);
1026 _playlist->setup (content ());
1027 set_dcp_frame_rate (best_dcp_frame_rate (video_frame_rate ()));
1028 set_audio_mapping (_playlist->default_audio_mapping ());
1035 ui_signaller->emit (boost::bind (boost::ref (Changed), p));
1040 Film::set_dci_date_today ()
1042 _dci_date = boost::gregorian::day_clock::local_day ();
1046 Film::info_path (int f) const
1048 boost::filesystem::path p;
1053 s << setfill('0') << f << ".md5";
1057 /* info_dir() will already have added any initial bit of the path,
1058 so don't call file() on this.
1064 Film::j2c_path (int f, bool t) const
1066 boost::filesystem::path p;
1068 p /= video_state_identifier ();
1072 s << setfill('0') << f << ".j2c";
1079 return file (p.string ());
1082 /** Make an educated guess as to whether we have a complete DCP
1084 * @return true if we do.
1088 Film::have_dcp () const
1091 libdcp::DCP dcp (dir (dcp_name()));
1101 Film::player () const
1103 boost::mutex::scoped_lock lm (_state_mutex);
1104 return shared_ptr<Player> (new Player (shared_from_this (), _playlist));
1108 Film::add_content (shared_ptr<Content> c)
1111 boost::mutex::scoped_lock lm (_state_mutex);
1112 _content.push_back (c);
1115 signal_changed (CONTENT);
1117 examine_content (c);
1121 Film::remove_content (shared_ptr<Content> c)
1124 boost::mutex::scoped_lock lm (_state_mutex);
1125 ContentList::iterator i = find (_content.begin(), _content.end(), c);
1126 if (i != _content.end ()) {
1131 signal_changed (CONTENT);
1135 Film::move_content_earlier (shared_ptr<Content> c)
1138 boost::mutex::scoped_lock lm (_state_mutex);
1139 ContentList::iterator i = find (_content.begin(), _content.end(), c);
1140 if (i == _content.begin () || i == _content.end()) {
1144 ContentList::iterator j = i;
1150 signal_changed (CONTENT);
1154 Film::move_content_later (shared_ptr<Content> c)
1157 boost::mutex::scoped_lock lm (_state_mutex);
1158 ContentList::iterator i = find (_content.begin(), _content.end(), c);
1159 if (i == _content.end()) {
1163 ContentList::iterator j = i;
1165 if (j == _content.end ()) {
1172 signal_changed (CONTENT);
1177 Film::audio_length () const
1179 return _playlist->audio_length ();
1183 Film::audio_channels () const
1185 return _playlist->audio_channels ();
1189 Film::audio_frame_rate () const
1191 return _playlist->audio_frame_rate ();
1195 Film::has_audio () const
1197 return _playlist->has_audio ();
1201 Film::video_frame_rate () const
1203 return _playlist->video_frame_rate ();
1207 Film::video_size () const
1209 return _playlist->video_size ();
1213 Film::video_length () const
1215 return _playlist->video_length ();
1218 /** Unfortunately this is needed as the GUI has FFmpeg-specific controls */
1219 shared_ptr<FFmpegContent>
1220 Film::ffmpeg () const
1222 boost::mutex::scoped_lock lm (_state_mutex);
1224 for (ContentList::const_iterator i = _content.begin (); i != _content.end(); ++i) {
1225 shared_ptr<FFmpegContent> f = boost::dynamic_pointer_cast<FFmpegContent> (*i);
1231 return shared_ptr<FFmpegContent> ();
1234 vector<FFmpegSubtitleStream>
1235 Film::ffmpeg_subtitle_streams () const
1237 shared_ptr<FFmpegContent> f = ffmpeg ();
1239 return f->subtitle_streams ();
1242 return vector<FFmpegSubtitleStream> ();
1245 boost::optional<FFmpegSubtitleStream>
1246 Film::ffmpeg_subtitle_stream () const
1248 shared_ptr<FFmpegContent> f = ffmpeg ();
1250 return f->subtitle_stream ();
1256 vector<FFmpegAudioStream>
1257 Film::ffmpeg_audio_streams () const
1259 shared_ptr<FFmpegContent> f = ffmpeg ();
1261 return f->audio_streams ();
1264 return vector<FFmpegAudioStream> ();
1267 boost::optional<FFmpegAudioStream>
1268 Film::ffmpeg_audio_stream () const
1270 shared_ptr<FFmpegContent> f = ffmpeg ();
1272 return f->audio_stream ();
1279 Film::set_ffmpeg_subtitle_stream (FFmpegSubtitleStream s)
1281 shared_ptr<FFmpegContent> f = ffmpeg ();
1283 f->set_subtitle_stream (s);
1288 Film::set_ffmpeg_audio_stream (FFmpegAudioStream s)
1290 shared_ptr<FFmpegContent> f = ffmpeg ();
1292 f->set_audio_stream (s);
1297 Film::set_audio_mapping (AudioMapping m)
1300 boost::mutex::scoped_lock lm (_state_mutex);
1304 signal_changed (AUDIO_MAPPING);
1308 Film::content_changed (boost::weak_ptr<Content> c, int p)
1310 if (p == VideoContentProperty::VIDEO_FRAME_RATE) {
1311 set_dcp_frame_rate (best_dcp_frame_rate (video_frame_rate ()));
1312 } else if (p == AudioContentProperty::AUDIO_CHANNELS) {
1313 set_audio_mapping (_playlist->default_audio_mapping ());
1317 ui_signaller->emit (boost::bind (boost::ref (ContentChanged), c, p));