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