Try doing it after Pango::init().
[dcpomatic.git] / src / lib / hints.cc
index 943991d2bc584f839f2a1eff085218106b35f8cc..d3ad9dd235f92453e76d358cc66e1d144505377a 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2016-2018 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2016-2019 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
@@ -56,39 +56,35 @@ Hints::Hints (weak_ptr<const Film> film)
        , _long_ccap (false)
        , _overlap_ccap (false)
        , _too_many_ccap_lines (false)
+       , _stop (false)
 {
 
 }
 
 void
-Hints::stop_thread ()
+Hints::start ()
 {
-       if (_thread) {
-               try {
-                       _thread->interrupt ();
-                       _thread->join ();
-               } catch (...) {
-
-               }
-
-               delete _thread;
-               _thread = 0;
-       }
+       _thread = new boost::thread (bind(&Hints::thread, this));
 }
 
 Hints::~Hints ()
 {
-       stop_thread ();
-}
+       if (!_thread) {
+               return;
+       }
 
-void
-Hints::start ()
-{
-       stop_thread ();
-       _long_ccap = false;
-       _overlap_ccap = false;
-       _too_many_ccap_lines = false;
-       _thread = new boost::thread (bind(&Hints::thread, this));
+       try {
+               {
+                       boost::mutex::scoped_lock lm (_mutex);
+                       _stop = true;
+               }
+               _thread->interrupt ();
+               _thread->join ();
+       } catch (...) {
+
+       }
+
+       delete _thread;
 }
 
 void
@@ -106,11 +102,9 @@ Hints::thread ()
                BOOST_FOREACH (shared_ptr<Content> i, content) {
                        BOOST_FOREACH (shared_ptr<TextContent> j, i->text) {
                                BOOST_FOREACH (shared_ptr<Font> k, j->fonts()) {
-                                       for (int l = 0; l < FontFiles::VARIANTS; ++l) {
-                                               optional<boost::filesystem::path> const p = k->file (static_cast<FontFiles::Variant>(l));
-                                               if (p && boost::filesystem::file_size (p.get()) >= (640 * 1024)) {
-                                                       big_font_files = true;
-                                               }
+                                       optional<boost::filesystem::path> const p = k->file ();
+                                       if (p && boost::filesystem::file_size(p.get()) >= (640 * 1024)) {
+                                               big_font_files = true;
                                        }
                                }
                        }
@@ -181,6 +175,10 @@ Hints::thread ()
                hint (h);
        }
 
+       if (film->video_frame_rate() > 30) {
+               hint (String::compose(_("You are set up for a DCP at a frame rate of %1.  This frame rate is not supported by all projectors.  You are advised to change the DCP frame rate to %2."), film->video_frame_rate(), film->video_frame_rate() / 2));
+       }
+
        optional<double> lowest_speed_up;
        optional<double> highest_speed_up;
        BOOST_FOREACH (shared_ptr<const Content> i, content) {
@@ -266,9 +264,25 @@ Hints::thread ()
        shared_ptr<Player> player (new Player (film, film->playlist ()));
        player->set_ignore_video ();
        player->set_ignore_audio ();
-       player->Text.connect (bind(&Hints::text, this, _1, _2, _3));
-       while (!player->pass ()) {
-               bind (boost::ref(Pulse));
+       player->Text.connect (bind(&Hints::text, this, _1, _2, _4));
+
+       struct timeval last_pulse;
+       gettimeofday (&last_pulse, 0);
+
+       while (!player->pass()) {
+
+               struct timeval now;
+               gettimeofday (&now, 0);
+               if ((seconds(now) - seconds(last_pulse)) > 1) {
+                       {
+                               boost::mutex::scoped_lock lm (_mutex);
+                               if (_stop) {
+                                       break;
+                               }
+                       }
+                       emit (bind (boost::ref(Pulse)));
+                       last_pulse = now;
+               }
        }
 
        emit (bind(boost::ref(Finished)));
@@ -287,9 +301,9 @@ Hints::text (PlayerText text, TextType type, DCPTimePeriod period)
                return;
        }
 
-       int lines = text.text.size();
-       BOOST_FOREACH (StringText i, text.text) {
-               if (i.text().length() > CLOSED_CAPTION_LENGTH) {
+       int lines = text.string.size();
+       BOOST_FOREACH (StringText i, text.string) {
+               if (utf8_strlen(i.text()) > CLOSED_CAPTION_LENGTH) {
                        ++lines;
                        if (!_long_ccap) {
                                _long_ccap = true;