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