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