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