Merge branch '1.0' of ssh://houllier/home/carl/git/dvdomatic into 1.0
[dcpomatic.git] / src / lib / film.cc
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 #include <stdexcept>
21 #include <iostream>
22 #include <algorithm>
23 #include <fstream>
24 #include <cstdlib>
25 #include <sstream>
26 #include <iomanip>
27 #include <unistd.h>
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>
34 #include "film.h"
35 #include "job.h"
36 #include "filter.h"
37 #include "util.h"
38 #include "job_manager.h"
39 #include "ab_transcode_job.h"
40 #include "transcode_job.h"
41 #include "scp_dcp_job.h"
42 #include "log.h"
43 #include "exceptions.h"
44 #include "examine_content_job.h"
45 #include "scaler.h"
46 #include "config.h"
47 #include "version.h"
48 #include "ui_signaller.h"
49 #include "analyse_audio_job.h"
50 #include "playlist.h"
51 #include "player.h"
52 #include "ffmpeg_content.h"
53 #include "imagemagick_content.h"
54 #include "sndfile_content.h"
55 #include "dcp_content_type.h"
56 #include "ratio.h"
57
58 #include "i18n.h"
59
60 using std::string;
61 using std::stringstream;
62 using std::multimap;
63 using std::pair;
64 using std::map;
65 using std::vector;
66 using std::ifstream;
67 using std::ofstream;
68 using std::setfill;
69 using std::min;
70 using std::make_pair;
71 using std::endl;
72 using std::cout;
73 using std::list;
74 using boost::shared_ptr;
75 using boost::lexical_cast;
76 using boost::dynamic_pointer_cast;
77 using boost::to_upper_copy;
78 using boost::ends_with;
79 using boost::starts_with;
80 using boost::optional;
81 using libdcp::Size;
82
83 int const Film::state_version = 4;
84
85 /** Construct a Film object in a given directory.
86  *
87  *  @param d Film directory.
88  */
89
90 Film::Film (string d)
91         : _playlist (new Playlist)
92         , _use_dci_name (true)
93         , _dcp_content_type (Config::instance()->default_dcp_content_type ())
94         , _container (Config::instance()->default_container ())
95         , _scaler (Scaler::from_id ("bicubic"))
96         , _ab (false)
97         , _with_subtitles (false)
98         , _subtitle_offset (0)
99         , _subtitle_scale (1)
100         , _colour_lut (0)
101         , _j2k_bandwidth (200000000)
102         , _dci_metadata (Config::instance()->default_dci_metadata ())
103         , _dcp_video_frame_rate (0)
104         , _dcp_audio_channels (MAX_AUDIO_CHANNELS)
105         , _dirty (false)
106 {
107         set_dci_date_today ();
108
109         _playlist->Changed.connect (bind (&Film::playlist_changed, this));
110         _playlist->ContentChanged.connect (bind (&Film::playlist_content_changed, this, _1, _2));
111         
112         /* Make state.directory a complete path without ..s (where possible)
113            (Code swiped from Adam Bowen on stackoverflow)
114         */
115         
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 == "..") {
120                         if (boost::filesystem::is_symlink (result) || result.filename() == "..") {
121                                 result /= *i;
122                         } else {
123                                 result = result.parent_path ();
124                         }
125                 } else if (*i != ".") {
126                         result /= *i;
127                 }
128         }
129
130         set_directory (result.string ());
131         _log.reset (new FileLog (file ("log")));
132 }
133
134 Film::Film (Film const & o)
135         : boost::enable_shared_from_this<Film> (o)
136         /* note: the copied film shares the original's log */
137         , _log               (o._log)
138         , _playlist          (new Playlist (o._playlist))
139         , _directory         (o._directory)
140         , _name              (o._name)
141         , _use_dci_name      (o._use_dci_name)
142         , _dcp_content_type  (o._dcp_content_type)
143         , _container         (o._container)
144         , _scaler            (o._scaler)
145         , _ab                (o._ab)
146         , _with_subtitles    (o._with_subtitles)
147         , _subtitle_offset   (o._subtitle_offset)
148         , _subtitle_scale    (o._subtitle_scale)
149         , _colour_lut        (o._colour_lut)
150         , _j2k_bandwidth     (o._j2k_bandwidth)
151         , _dci_metadata      (o._dci_metadata)
152         , _dcp_video_frame_rate (o._dcp_video_frame_rate)
153         , _dci_date          (o._dci_date)
154         , _dirty             (o._dirty)
155 {
156         _playlist->ContentChanged.connect (bind (&Film::playlist_content_changed, this, _1, _2));
157 }
158
159 string
160 Film::video_state_identifier () const
161 {
162         assert (container ());
163         LocaleGuard lg;
164
165         stringstream s;
166         s << container()->id()
167           << "_" << _playlist->video_digest()
168           << "_" << _dcp_video_frame_rate
169           << "_" << scaler()->id()
170           << "_" << j2k_bandwidth()
171           << "_" << lexical_cast<int> (colour_lut());
172
173         if (ab()) {
174                 pair<string, string> fa = Filter::ffmpeg_strings (Config::instance()->reference_filters());
175                 s << "ab_" << Config::instance()->reference_scaler()->id() << "_" << fa.first << "_" << fa.second;
176         }
177
178         return s.str ();
179 }
180           
181 /** @return The path to the directory to write video frame info files to */
182 string
183 Film::info_dir () const
184 {
185         boost::filesystem::path p;
186         p /= "info";
187         p /= video_state_identifier ();
188         return dir (p.string());
189 }
190
191 string
192 Film::internal_video_mxf_dir () const
193 {
194         boost::filesystem::path p;
195         return dir ("video");
196 }
197
198 string
199 Film::internal_video_mxf_filename () const
200 {
201         return video_state_identifier() + ".mxf";
202 }
203
204 string
205 Film::dcp_video_mxf_filename () const
206 {
207         return filename_safe_name() + "_video.mxf";
208 }
209
210 string
211 Film::dcp_audio_mxf_filename () const
212 {
213         return filename_safe_name() + "_audio.mxf";
214 }
215
216 string
217 Film::filename_safe_name () const
218 {
219         string const n = name ();
220         string o;
221         for (size_t i = 0; i < n.length(); ++i) {
222                 if (isalnum (n[i])) {
223                         o += n[i];
224                 } else {
225                         o += "_";
226                 }
227         }
228
229         return o;
230 }
231
232 string
233 Film::audio_analysis_path () const
234 {
235         boost::filesystem::path p;
236         p /= "analysis";
237         p /= _playlist->audio_digest();
238         return file (p.string ());
239 }
240
241 /** Add suitable Jobs to the JobManager to create a DCP for this Film */
242 void
243 Film::make_dcp ()
244 {
245         set_dci_date_today ();
246         
247         if (dcp_name().find ("/") != string::npos) {
248                 throw BadSettingError (_("name"), _("cannot contain slashes"));
249         }
250         
251         log()->log (String::compose ("DCP-o-matic %1 git %2 using %3", dcpomatic_version, dcpomatic_git_commit, dependency_version_summary()));
252
253         {
254                 char buffer[128];
255                 gethostname (buffer, sizeof (buffer));
256                 log()->log (String::compose ("Starting to make DCP on %1", buffer));
257         }
258         
259 //      log()->log (String::compose ("Content is %1; type %2", content_path(), (content_type() == STILL ? _("still") : _("video"))));
260 //      if (length()) {
261 //              log()->log (String::compose ("Content length %1", length().get()));
262 //      }
263 //      log()->log (String::compose ("Content digest %1", content_digest()));
264 //      log()->log (String::compose ("Content at %1 fps, DCP at %2 fps", source_frame_rate(), dcp_frame_rate()));
265         log()->log (String::compose ("%1 threads", Config::instance()->num_local_encoding_threads()));
266         log()->log (String::compose ("J2K bandwidth %1", j2k_bandwidth()));
267 #ifdef DCPOMATIC_DEBUG
268         log()->log ("DCP-o-matic built in debug mode.");
269 #else
270         log()->log ("DCP-o-matic built in optimised mode.");
271 #endif
272 #ifdef LIBDCP_DEBUG
273         log()->log ("libdcp built in debug mode.");
274 #else
275         log()->log ("libdcp built in optimised mode.");
276 #endif
277         pair<string, int> const c = cpu_info ();
278         log()->log (String::compose ("CPU: %1, %2 processors", c.first, c.second));
279         
280         if (container() == 0) {
281                 throw MissingSettingError (_("container"));
282         }
283
284         if (_playlist->content().empty ()) {
285                 throw StringError (_("You must add some content to the DCP before creating it"));
286         }
287
288         if (dcp_content_type() == 0) {
289                 throw MissingSettingError (_("content type"));
290         }
291
292         if (name().empty()) {
293                 throw MissingSettingError (_("name"));
294         }
295
296         shared_ptr<Job> r;
297
298         if (ab()) {
299                 r = JobManager::instance()->add (shared_ptr<Job> (new ABTranscodeJob (shared_from_this())));
300         } else {
301                 r = JobManager::instance()->add (shared_ptr<Job> (new TranscodeJob (shared_from_this())));
302         }
303 }
304
305 /** Start a job to analyse the audio in our Playlist */
306 void
307 Film::analyse_audio ()
308 {
309         if (_analyse_audio_job) {
310                 return;
311         }
312
313         _analyse_audio_job.reset (new AnalyseAudioJob (shared_from_this()));
314         _analyse_audio_job->Finished.connect (bind (&Film::analyse_audio_finished, this));
315         JobManager::instance()->add (_analyse_audio_job);
316 }
317
318 void
319 Film::analyse_audio_finished ()
320 {
321         ensure_ui_thread ();
322
323         if (_analyse_audio_job->finished_ok ()) {
324                 AudioAnalysisSucceeded ();
325         }
326         
327         _analyse_audio_job.reset ();
328 }
329
330 /** Start a job to send our DCP to the configured TMS */
331 void
332 Film::send_dcp_to_tms ()
333 {
334         shared_ptr<Job> j (new SCPDCPJob (shared_from_this()));
335         JobManager::instance()->add (j);
336 }
337
338 /** Count the number of frames that have been encoded for this film.
339  *  @return frame count.
340  */
341 int
342 Film::encoded_frames () const
343 {
344         if (container() == 0) {
345                 return 0;
346         }
347
348         int N = 0;
349         for (boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (info_dir ()); i != boost::filesystem::directory_iterator(); ++i) {
350                 ++N;
351                 boost::this_thread::interruption_point ();
352         }
353
354         return N;
355 }
356
357 /** Write state to our `metadata' file */
358 void
359 Film::write_metadata () const
360 {
361         if (!boost::filesystem::exists (directory())) {
362                 boost::filesystem::create_directory (directory());
363         }
364         
365         boost::mutex::scoped_lock lm (_state_mutex);
366         LocaleGuard lg;
367
368         boost::filesystem::create_directories (directory());
369
370         xmlpp::Document doc;
371         xmlpp::Element* root = doc.create_root_node ("Metadata");
372
373         root->add_child("Version")->add_child_text (lexical_cast<string> (state_version));
374         root->add_child("Name")->add_child_text (_name);
375         root->add_child("UseDCIName")->add_child_text (_use_dci_name ? "1" : "0");
376
377         if (_dcp_content_type) {
378                 root->add_child("DCPContentType")->add_child_text (_dcp_content_type->dci_name ());
379         }
380
381         if (_container) {
382                 root->add_child("Container")->add_child_text (_container->id ());
383         }
384
385         root->add_child("Scaler")->add_child_text (_scaler->id ());
386         root->add_child("AB")->add_child_text (_ab ? "1" : "0");
387         root->add_child("WithSubtitles")->add_child_text (_with_subtitles ? "1" : "0");
388         root->add_child("SubtitleOffset")->add_child_text (lexical_cast<string> (_subtitle_offset));
389         root->add_child("SubtitleScale")->add_child_text (lexical_cast<string> (_subtitle_scale));
390         root->add_child("ColourLUT")->add_child_text (lexical_cast<string> (_colour_lut));
391         root->add_child("J2KBandwidth")->add_child_text (lexical_cast<string> (_j2k_bandwidth));
392         _dci_metadata.as_xml (root->add_child ("DCIMetadata"));
393         root->add_child("DCPVideoFrameRate")->add_child_text (lexical_cast<string> (_dcp_video_frame_rate));
394         root->add_child("DCIDate")->add_child_text (boost::gregorian::to_iso_string (_dci_date));
395         root->add_child("DCPAudioChannels")->add_child_text (lexical_cast<string> (_dcp_audio_channels));
396         _playlist->as_xml (root->add_child ("Playlist"));
397
398         doc.write_to_file_formatted (file ("metadata.xml"));
399         
400         _dirty = false;
401 }
402
403 /** Read state from our metadata file */
404 void
405 Film::read_metadata ()
406 {
407         boost::mutex::scoped_lock lm (_state_mutex);
408         LocaleGuard lg;
409
410         if (boost::filesystem::exists (file ("metadata")) && !boost::filesystem::exists (file ("metadata.xml"))) {
411                 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!"));
412         }
413
414         cxml::File f (file ("metadata.xml"), "Metadata");
415         
416         _name = f.string_child ("Name");
417         _use_dci_name = f.bool_child ("UseDCIName");
418
419         {
420                 optional<string> c = f.optional_string_child ("DCPContentType");
421                 if (c) {
422                         _dcp_content_type = DCPContentType::from_dci_name (c.get ());
423                 }
424         }
425
426         {
427                 optional<string> c = f.optional_string_child ("Container");
428                 if (c) {
429                         _container = Ratio::from_id (c.get ());
430                 }
431         }
432
433         _scaler = Scaler::from_id (f.string_child ("Scaler"));
434         _ab = f.bool_child ("AB");
435         _with_subtitles = f.bool_child ("WithSubtitles");
436         _subtitle_offset = f.number_child<float> ("SubtitleOffset");
437         _subtitle_scale = f.number_child<float> ("SubtitleScale");
438         _colour_lut = f.number_child<int> ("ColourLUT");
439         _j2k_bandwidth = f.number_child<int> ("J2KBandwidth");
440         _dci_metadata = DCIMetadata (f.node_child ("DCIMetadata"));
441         _dcp_video_frame_rate = f.number_child<int> ("DCPVideoFrameRate");
442         _dci_date = boost::gregorian::from_undelimited_string (f.string_child ("DCIDate"));
443         _dcp_audio_channels = f.number_child<int> ("DCPAudioChannels");
444
445         _playlist->set_from_xml (shared_from_this(), f.node_child ("Playlist"));
446
447         _dirty = false;
448 }
449
450 /** Given a directory name, return its full path within the Film's directory.
451  *  The directory (and its parents) will be created if they do not exist.
452  */
453 string
454 Film::dir (string d) const
455 {
456         boost::mutex::scoped_lock lm (_directory_mutex);
457         
458         boost::filesystem::path p;
459         p /= _directory;
460         p /= d;
461         
462         boost::filesystem::create_directories (p);
463         
464         return p.string ();
465 }
466
467 /** Given a file or directory name, return its full path within the Film's directory.
468  *  _directory_mutex must not be locked on entry.
469  *  Any required parent directories will be created.
470  */
471 string
472 Film::file (string f) const
473 {
474         boost::mutex::scoped_lock lm (_directory_mutex);
475
476         boost::filesystem::path p;
477         p /= _directory;
478         p /= f;
479
480         boost::filesystem::create_directories (p.parent_path ());
481         
482         return p.string ();
483 }
484
485 /** @return a DCI-compliant name for a DCP of this film */
486 string
487 Film::dci_name (bool if_created_now) const
488 {
489         stringstream d;
490
491         string fixed_name = to_upper_copy (name());
492         for (size_t i = 0; i < fixed_name.length(); ++i) {
493                 if (fixed_name[i] == ' ') {
494                         fixed_name[i] = '-';
495                 }
496         }
497
498         /* Spec is that the name part should be maximum 14 characters, as I understand it */
499         if (fixed_name.length() > 14) {
500                 fixed_name = fixed_name.substr (0, 14);
501         }
502
503         d << fixed_name;
504
505         if (dcp_content_type()) {
506                 d << "_" << dcp_content_type()->dci_name();
507         }
508
509         if (container()) {
510                 d << "_" << container()->dci_name();
511         }
512
513         DCIMetadata const dm = dci_metadata ();
514
515         if (!dm.audio_language.empty ()) {
516                 d << "_" << dm.audio_language;
517                 if (!dm.subtitle_language.empty()) {
518                         d << "-" << dm.subtitle_language;
519                 } else {
520                         d << "-XX";
521                 }
522         }
523
524         if (!dm.territory.empty ()) {
525                 d << "_" << dm.territory;
526                 if (!dm.rating.empty ()) {
527                         d << "-" << dm.rating;
528                 }
529         }
530
531         d << "_51_2K";
532
533         if (!dm.studio.empty ()) {
534                 d << "_" << dm.studio;
535         }
536
537         if (if_created_now) {
538                 d << "_" << boost::gregorian::to_iso_string (boost::gregorian::day_clock::local_day ());
539         } else {
540                 d << "_" << boost::gregorian::to_iso_string (_dci_date);
541         }
542
543         if (!dm.facility.empty ()) {
544                 d << "_" << dm.facility;
545         }
546
547         if (!dm.package_type.empty ()) {
548                 d << "_" << dm.package_type;
549         }
550
551         return d.str ();
552 }
553
554 /** @return name to give the DCP */
555 string
556 Film::dcp_name (bool if_created_now) const
557 {
558         if (use_dci_name()) {
559                 return dci_name (if_created_now);
560         }
561
562         return name();
563 }
564
565
566 void
567 Film::set_directory (string d)
568 {
569         boost::mutex::scoped_lock lm (_state_mutex);
570         _directory = d;
571         _dirty = true;
572 }
573
574 void
575 Film::set_name (string n)
576 {
577         {
578                 boost::mutex::scoped_lock lm (_state_mutex);
579                 _name = n;
580         }
581         signal_changed (NAME);
582 }
583
584 void
585 Film::set_use_dci_name (bool u)
586 {
587         {
588                 boost::mutex::scoped_lock lm (_state_mutex);
589                 _use_dci_name = u;
590         }
591         signal_changed (USE_DCI_NAME);
592 }
593
594 void
595 Film::set_dcp_content_type (DCPContentType const * t)
596 {
597         {
598                 boost::mutex::scoped_lock lm (_state_mutex);
599                 _dcp_content_type = t;
600         }
601         signal_changed (DCP_CONTENT_TYPE);
602 }
603
604 void
605 Film::set_container (Ratio const * c)
606 {
607         {
608                 boost::mutex::scoped_lock lm (_state_mutex);
609                 _container = c;
610         }
611         signal_changed (CONTAINER);
612 }
613
614 void
615 Film::set_scaler (Scaler const * s)
616 {
617         {
618                 boost::mutex::scoped_lock lm (_state_mutex);
619                 _scaler = s;
620         }
621         signal_changed (SCALER);
622 }
623
624 void
625 Film::set_ab (bool a)
626 {
627         {
628                 boost::mutex::scoped_lock lm (_state_mutex);
629                 _ab = a;
630         }
631         signal_changed (AB);
632 }
633
634 void
635 Film::set_with_subtitles (bool w)
636 {
637         {
638                 boost::mutex::scoped_lock lm (_state_mutex);
639                 _with_subtitles = w;
640         }
641         signal_changed (WITH_SUBTITLES);
642 }
643
644 void
645 Film::set_subtitle_offset (int o)
646 {
647         {
648                 boost::mutex::scoped_lock lm (_state_mutex);
649                 _subtitle_offset = o;
650         }
651         signal_changed (SUBTITLE_OFFSET);
652 }
653
654 void
655 Film::set_subtitle_scale (float s)
656 {
657         {
658                 boost::mutex::scoped_lock lm (_state_mutex);
659                 _subtitle_scale = s;
660         }
661         signal_changed (SUBTITLE_SCALE);
662 }
663
664 void
665 Film::set_colour_lut (int i)
666 {
667         {
668                 boost::mutex::scoped_lock lm (_state_mutex);
669                 _colour_lut = i;
670         }
671         signal_changed (COLOUR_LUT);
672 }
673
674 void
675 Film::set_j2k_bandwidth (int b)
676 {
677         {
678                 boost::mutex::scoped_lock lm (_state_mutex);
679                 _j2k_bandwidth = b;
680         }
681         signal_changed (J2K_BANDWIDTH);
682 }
683
684 void
685 Film::set_dci_metadata (DCIMetadata m)
686 {
687         {
688                 boost::mutex::scoped_lock lm (_state_mutex);
689                 _dci_metadata = m;
690         }
691         signal_changed (DCI_METADATA);
692 }
693
694
695 void
696 Film::set_dcp_video_frame_rate (int f)
697 {
698         {
699                 boost::mutex::scoped_lock lm (_state_mutex);
700                 _dcp_video_frame_rate = f;
701         }
702         signal_changed (DCP_VIDEO_FRAME_RATE);
703 }
704
705 void
706 Film::signal_changed (Property p)
707 {
708         {
709                 boost::mutex::scoped_lock lm (_state_mutex);
710                 _dirty = true;
711         }
712
713         switch (p) {
714         case Film::CONTENT:
715                 set_dcp_video_frame_rate (_playlist->best_dcp_frame_rate ());
716                 break;
717         default:
718                 break;
719         }
720
721         if (ui_signaller) {
722                 ui_signaller->emit (boost::bind (boost::ref (Changed), p));
723         }
724 }
725
726 void
727 Film::set_dci_date_today ()
728 {
729         _dci_date = boost::gregorian::day_clock::local_day ();
730 }
731
732 string
733 Film::info_path (int f) const
734 {
735         boost::filesystem::path p;
736         p /= info_dir ();
737
738         stringstream s;
739         s.width (8);
740         s << setfill('0') << f << ".md5";
741
742         p /= s.str();
743
744         /* info_dir() will already have added any initial bit of the path,
745            so don't call file() on this.
746         */
747         return p.string ();
748 }
749
750 string
751 Film::j2c_path (int f, bool t) const
752 {
753         boost::filesystem::path p;
754         p /= "j2c";
755         p /= video_state_identifier ();
756
757         stringstream s;
758         s.width (8);
759         s << setfill('0') << f << ".j2c";
760
761         if (t) {
762                 s << ".tmp";
763         }
764
765         p /= s.str();
766         return file (p.string ());
767 }
768
769 /** Make an educated guess as to whether we have a complete DCP
770  *  or not.
771  *  @return true if we do.
772  */
773
774 bool
775 Film::have_dcp () const
776 {
777         try {
778                 libdcp::DCP dcp (dir (dcp_name()));
779                 dcp.read ();
780         } catch (...) {
781                 return false;
782         }
783
784         return true;
785 }
786
787 shared_ptr<Player>
788 Film::player () const
789 {
790         return shared_ptr<Player> (new Player (shared_from_this (), _playlist));
791 }
792
793 shared_ptr<Playlist>
794 Film::playlist () const
795 {
796         boost::mutex::scoped_lock lm (_state_mutex);
797         return _playlist;
798 }
799
800 Playlist::ContentList
801 Film::content () const
802 {
803         return _playlist->content ();
804 }
805
806 void
807 Film::examine_and_add_content (shared_ptr<Content> c)
808 {
809         shared_ptr<Job> j (new ExamineContentJob (shared_from_this(), c));
810         JobManager::instance()->add (j);
811 }
812
813 void
814 Film::add_content (shared_ptr<Content> c)
815 {
816         /* Add video content after any existing content */
817         if (dynamic_pointer_cast<VideoContent> (c)) {
818                 c->set_start (_playlist->video_end ());
819         }
820
821         _playlist->add (c);
822 }
823
824 void
825 Film::remove_content (shared_ptr<Content> c)
826 {
827         _playlist->remove (c);
828 }
829
830 Time
831 Film::length () const
832 {
833         return _playlist->length ();
834 }
835
836 bool
837 Film::has_subtitles () const
838 {
839         return _playlist->has_subtitles ();
840 }
841
842 OutputVideoFrame
843 Film::best_dcp_video_frame_rate () const
844 {
845         return _playlist->best_dcp_frame_rate ();
846 }
847
848 void
849 Film::playlist_content_changed (boost::weak_ptr<Content> c, int p)
850 {
851         if (p == VideoContentProperty::VIDEO_FRAME_RATE) {
852                 set_dcp_video_frame_rate (_playlist->best_dcp_frame_rate ());
853         } 
854
855         if (ui_signaller) {
856                 ui_signaller->emit (boost::bind (boost::ref (ContentChanged), c, p));
857         }
858 }
859
860 void
861 Film::playlist_changed ()
862 {
863         signal_changed (CONTENT);
864 }       
865
866 int
867 Film::loop () const
868 {
869         return _playlist->loop ();
870 }
871
872 void
873 Film::set_loop (int c)
874 {
875         _playlist->set_loop (c);
876 }
877
878 OutputAudioFrame
879 Film::time_to_audio_frames (Time t) const
880 {
881         return t * dcp_audio_frame_rate () / TIME_HZ;
882 }
883
884 OutputVideoFrame
885 Film::time_to_video_frames (Time t) const
886 {
887         return t * dcp_video_frame_rate () / TIME_HZ;
888 }
889
890 Time
891 Film::audio_frames_to_time (OutputAudioFrame f) const
892 {
893         return f * TIME_HZ / dcp_audio_frame_rate ();
894 }
895
896 Time
897 Film::video_frames_to_time (OutputVideoFrame f) const
898 {
899         return f * TIME_HZ / dcp_video_frame_rate ();
900 }
901
902 OutputAudioFrame
903 Film::dcp_audio_frame_rate () const
904 {
905         /* XXX */
906         return 48000;
907 }
908
909 void
910 Film::set_sequence_video (bool s)
911 {
912         _playlist->set_sequence_video (s);
913 }
914
915 libdcp::Size
916 Film::full_frame () const
917 {
918         return libdcp::Size (2048, 1080);
919 }