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