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