Background-threaded hints including line length of CCAPs.
authorCarl Hetherington <cth@carlh.net>
Thu, 26 Jul 2018 16:58:06 +0000 (17:58 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 26 Jul 2018 16:58:06 +0000 (17:58 +0100)
src/lib/hints.cc
src/lib/hints.h
src/tools/dcpomatic.cc
src/wx/hints_dialog.cc
src/wx/hints_dialog.h

index 31b2ad84922a0d4268d011f3cc96cbcdf15c2b03..77b10da15af85655c667f178e12d701a2f1fde2a 100644 (file)
@@ -30,6 +30,8 @@
 #include "audio_analysis.h"
 #include "compose.hpp"
 #include "util.h"
+#include "cross.h"
+#include "player.h"
 #include <dcp/raw_convert.h>
 #include <boost/foreach.hpp>
 #include <boost/algorithm/string.hpp>
@@ -44,12 +46,54 @@ using std::min;
 using std::max;
 using std::cout;
 using boost::shared_ptr;
+using boost::weak_ptr;
 using boost::optional;
+using boost::bind;
 
-vector<string>
-get_hints (shared_ptr<const Film> film)
+Hints::Hints (weak_ptr<const Film> film)
+       : _film (film)
+       , _thread (0)
+       , _long_ccap (false)
 {
-       vector<string> hints;
+
+}
+
+void
+Hints::stop_thread ()
+{
+       if (_thread) {
+               try {
+                       _thread->interrupt ();
+                       _thread->join ();
+               } catch (...) {
+
+               }
+
+               delete _thread;
+               _thread = 0;
+       }
+}
+
+Hints::~Hints ()
+{
+       stop_thread ();
+}
+
+void
+Hints::start ()
+{
+       stop_thread ();
+       _long_ccap = false;
+       _thread = new boost::thread (bind(&Hints::thread, this));
+}
+
+void
+Hints::thread ()
+{
+       shared_ptr<const Film> film = _film.lock ();
+       if (!film) {
+               return;
+       }
 
        ContentList content = film->content ();
 
@@ -70,16 +114,16 @@ get_hints (shared_ptr<const Film> film)
        }
 
        if (big_font_files) {
-               hints.push_back (_("You have specified a font file which is larger than 640kB.  This is very likely to cause problems on playback."));
+               hint (_("You have specified a font file which is larger than 640kB.  This is very likely to cause problems on playback."));
        }
 
        if (film->audio_channels() < 6) {
-               hints.push_back (_("Your DCP has fewer than 6 audio channels.  This may cause problems on some projectors."));
+               hint (_("Your DCP has fewer than 6 audio channels.  This may cause problems on some projectors."));
        }
 
        AudioProcessor const * ap = film->audio_processor();
        if (ap && (ap->id() == "stereo-5.1-upmix-a" || ap->id() == "stereo-5.1-upmix-b")) {
-               hints.push_back (_("You are using DCP-o-matic's stereo-to-5.1 upmixer.  This is experimental and may result in poor-quality audio.  If you continue, you should listen to the resulting DCP in a cinema to make sure that it sounds good."));
+               hint (_("You are using DCP-o-matic's stereo-to-5.1 upmixer.  This is experimental and may result in poor-quality audio.  If you continue, you should listen to the resulting DCP in a cinema to make sure that it sounds good."));
        }
 
        int flat_or_narrower = 0;
@@ -98,19 +142,19 @@ get_hints (shared_ptr<const Film> film)
        string const film_container = film->container()->id();
 
        if (scope && !flat_or_narrower && film_container == "185") {
-               hints.push_back (_("All of your content is in Scope (2.39:1) but your DCP's container is Flat (1.85:1).  This will letter-box your content inside a Flat (1.85:1) frame.  You may prefer to set your DCP's container to Scope (2.39:1) in the \"DCP\" tab."));
+               hint (_("All of your content is in Scope (2.39:1) but your DCP's container is Flat (1.85:1).  This will letter-box your content inside a Flat (1.85:1) frame.  You may prefer to set your DCP's container to Scope (2.39:1) in the \"DCP\" tab."));
        }
 
        if (!scope && flat_or_narrower && film_container == "239") {
-               hints.push_back (_("All of your content is at 1.85:1 or narrower but your DCP's container is Scope (2.39:1).  This will pillar-box your content inside a Flat (1.85:1) frame.  You may prefer to set your DCP's container to Flat (1.85:1) in the \"DCP\" tab."));
+               hint (_("All of your content is at 1.85:1 or narrower but your DCP's container is Scope (2.39:1).  This will pillar-box your content inside a Flat (1.85:1) frame.  You may prefer to set your DCP's container to Flat (1.85:1) in the \"DCP\" tab."));
        }
 
        if (film_container != "185" && film_container != "239" && film_container != "190") {
-               hints.push_back (_("Your DCP uses an unusual container ratio.  This may cause problems on some projectors.  If possible, use Flat or Scope for the DCP container ratio"));
+               hint (_("Your DCP uses an unusual container ratio.  This may cause problems on some projectors.  If possible, use Flat or Scope for the DCP container ratio"));
        }
 
        if (film->j2k_bandwidth() >= 245000000) {
-               hints.push_back (_("A few projectors have problems playing back very high bit-rate DCPs.  It is a good idea to drop the JPEG2000 bandwidth down to about 200Mbit/s; this is unlikely to have any visible effect on the image."));
+               hint (_("A few projectors have problems playing back very high bit-rate DCPs.  It is a good idea to drop the JPEG2000 bandwidth down to about 200Mbit/s; this is unlikely to have any visible effect on the image."));
        }
 
        if (film->interop() && film->video_frame_rate() != 24 && film->video_frame_rate() != 48) {
@@ -130,7 +174,7 @@ get_hints (shared_ptr<const Film> film)
                        h = _("You are set up for an Interop DCP at a frame rate which is not officially supported.  You are advised either to change the frame rate of your DCP or to make a SMPTE DCP instead (although SMPTE DCPs are not supported by all projectors).");
                }
 
-               hints.push_back (h);
+               hint (h);
        }
 
        optional<double> lowest_speed_up;
@@ -154,7 +198,7 @@ get_hints (shared_ptr<const Film> film)
        }
 
        if (worst_speed_up > 25.5/24.0) {
-               hints.push_back (_("There is a large difference between the frame rate of your DCP and that of some of your content.  This will cause your audio to play back at a much lower or higher pitch than it should.  You are advised to set your DCP frame rate to one closer to your content, provided that your target projection systems support your chosen DCP rate."));
+               hint (_("There is a large difference between the frame rate of your DCP and that of some of your content.  This will cause your audio to play back at a much lower or higher pitch than it should.  You are advised to set your DCP frame rate to one closer to your content, provided that your target projection systems support your chosen DCP rate."));
        }
 
        int vob = 0;
@@ -165,7 +209,7 @@ get_hints (shared_ptr<const Film> film)
        }
 
        if (vob > 1) {
-               hints.push_back (String::compose (_("You have %1 files that look like they are VOB files from DVD. You should join them to ensure smooth joins between the files."), vob));
+               hint (String::compose (_("You have %1 files that look like they are VOB files from DVD. You should join them to ensure smooth joins between the files."), vob));
        }
 
        int three_d = 0;
@@ -176,7 +220,7 @@ get_hints (shared_ptr<const Film> film)
        }
 
        if (three_d > 0 && !film->three_d()) {
-               hints.push_back (_("You are using 3D content but your DCP is set to 2D.  Set the DCP to 3D if you want to play it back on a 3D system (e.g. Real-D, MasterImage etc.)"));
+               hint (_("You are using 3D content but your DCP is set to 2D.  Set the DCP to 3D if you want to play it back on a 3D system (e.g. Real-D, MasterImage etc.)"));
        }
 
        boost::filesystem::path path = film->audio_analysis_path (film->playlist ());
@@ -200,11 +244,10 @@ get_hints (shared_ptr<const Film> film)
                        ch = ch.substr (0, ch.length() - 2);
 
                        if (!ch.empty ()) {
-                               hints.push_back (
-                                       String::compose (
-                                               _("Your audio level is very high (on %1).  You should reduce the gain of your audio content."),
-                                               ch
-                                               )
+                               hint (String::compose (
+                                             _("Your audio level is very high (on %1).  You should reduce the gain of your audio content."),
+                                             ch
+                                             )
                                        );
                        }
                } catch (OldFormatError& e) {
@@ -214,5 +257,36 @@ get_hints (shared_ptr<const Film> film)
                }
        }
 
-       return hints;
+       emit (bind(boost::ref(Progress), _("Examining closed captions")));
+
+       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));
+       }
+
+       emit (bind(boost::ref(Finished)));
+}
+
+void
+Hints::hint (string h)
+{
+       emit(bind(boost::ref(Hint), h));
+}
+
+void
+Hints::text (PlayerText text, TextType type, DCPTimePeriod period)
+{
+       if (type != TEXT_CLOSED_CAPTION) {
+               return;
+       }
+
+       BOOST_FOREACH (StringText i, text.text) {
+               if (!_long_ccap && i.text().length() > 30) {
+                       _long_ccap = true;
+                       hint (_("Some of your closed captions have lines longer than 30 characters, so they will probably be word-wrapped."));
+               }
+       }
 }
index 3a6850860c54da63110fc9c1ce4ac92a374449e6..ad66fb472a6a375137784bcfb0266cf954fb4bc5 100644 (file)
 
 */
 
-#include <boost/shared_ptr.hpp>
+#include "signaller.h"
+#include "player_text.h"
+#include "types.h"
+#include "dcpomatic_time.h"
+#include <boost/weak_ptr.hpp>
+#include <boost/signals2.hpp>
 #include <vector>
 #include <string>
 
 class Film;
 
-std::vector<std::string> get_hints (boost::shared_ptr<const Film> film);
+class Hints : public Signaller
+{
+public:
+       Hints (boost::weak_ptr<const Film> film);
+       ~Hints ();
+
+       void start ();
+
+       boost::signals2::signal<void (std::string)> Hint;
+       boost::signals2::signal<void (std::string)> Progress;
+       boost::signals2::signal<void (void)> Pulse;
+       boost::signals2::signal<void (void)> Finished;
+
+private:
+       void thread ();
+       void stop_thread ();
+       void hint (std::string h);
+       void text (PlayerText text, TextType type, DCPTimePeriod period);
+
+       boost::weak_ptr<const Film> _film;
+       boost::thread* _thread;
+
+       bool _long_ccap;
+};
index a97e12b6952f51f2dc00a28518ce678b5cc3c4b5..6972b35c4e1ac097a781bee3dacaf2fe481add6c 100644 (file)
@@ -636,7 +636,7 @@ private:
                        }
                }
 
-               if (!get_hints(_film).empty() && Config::instance()->show_hints_before_make_dcp()) {
+               if (Config::instance()->show_hints_before_make_dcp()) {
                        HintsDialog* hints = new HintsDialog (this, _film, false);
                        int const r = hints->ShowModal();
                        hints->Destroy ();
@@ -735,7 +735,7 @@ private:
                        return;
                }
 
-               if (!get_hints(_film).empty() && Config::instance()->show_hints_before_make_dcp()) {
+               if (Config::instance()->show_hints_before_make_dcp()) {
                        HintsDialog* hints = new HintsDialog (this, _film, false);
                        int const r = hints->ShowModal();
                        hints->Destroy ();
index 86a1602131fa9ab87b46c1aca4951cd991c4575b..1938e7cc4b0f45d55f842297c8ae5bfd7627d93d 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 using std::max;
 using std::vector;
 using std::string;
+using std::cout;
 using boost::shared_ptr;
 using boost::optional;
+using boost::bind;
 using boost::dynamic_pointer_cast;
 
 HintsDialog::HintsDialog (wxWindow* parent, boost::weak_ptr<Film> film, bool ok)
        : wxDialog (parent, wxID_ANY, _("Hints"))
        , _film (film)
+       , _hints (new Hints (film))
 {
        wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL);
+
+       _gauge = new wxGauge (this, wxID_ANY, 100);
+       sizer->Add (_gauge, 0, wxALL | wxEXPAND, DCPOMATIC_SIZER_GAP);
+       _gauge_message = new wxStaticText (this, wxID_ANY, wxT(""));
+       sizer->Add (_gauge_message, 0, wxALL | wxEXPAND, DCPOMATIC_SIZER_GAP);
+
        _text = new wxRichTextCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (400, 300), wxRE_READONLY);
        sizer->Add (_text, 1, wxEXPAND | wxALL, 6);
 
@@ -70,6 +79,11 @@ HintsDialog::HintsDialog (wxWindow* parent, boost::weak_ptr<Film> film, bool ok)
                _film_content_changed_connection = locked_film->ContentChanged.connect (boost::bind (&HintsDialog::film_changed, this));
        }
 
+       _hints->Hint.connect (bind (&HintsDialog::hint, this, _1));
+       _hints->Progress.connect (bind (&HintsDialog::progress, this, _1));
+       _hints->Pulse.connect (bind (&HintsDialog::pulse, this));
+       _hints->Finished.connect (bind (&HintsDialog::finished, this));
+
        film_changed ();
 }
 
@@ -77,19 +91,30 @@ void
 HintsDialog::film_changed ()
 {
        _text->Clear ();
+       _current.clear ();
 
        boost::shared_ptr<Film> film = _film.lock ();
        if (!film) {
                return;
        }
 
-       vector<string> hints = get_hints (film);
+       _gauge->Show ();
+       _gauge_message->Show ();
+       Layout ();
+       _gauge->SetValue (0);
+       update ();
+       _hints->start ();
+}
 
-       if (hints.empty ()) {
+void
+HintsDialog::update ()
+{
+       _text->Clear ();
+       if (_current.empty ()) {
                _text->WriteText (_("There are no hints: everything looks good!"));
        } else {
                _text->BeginStandardBullet (N_("standard/circle"), 1, 50);
-               BOOST_FOREACH (string i, hints) {
+               BOOST_FOREACH (string i, _current) {
                        _text->WriteText (std_to_wx (i));
                        _text->Newline ();
                }
@@ -97,8 +122,35 @@ HintsDialog::film_changed ()
        }
 }
 
+void
+HintsDialog::hint (string text)
+{
+       _current.push_back (text);
+       update ();
+}
+
 void
 HintsDialog::shut_up (wxCommandEvent& ev)
 {
        Config::instance()->set_show_hints_before_make_dcp (!ev.IsChecked());
 }
+
+void
+HintsDialog::pulse ()
+{
+       _gauge->Pulse ();
+}
+
+void
+HintsDialog::finished ()
+{
+       _gauge->Hide ();
+       _gauge_message->Hide ();
+       Layout ();
+}
+
+void
+HintsDialog::progress (string m)
+{
+       _gauge_message->SetLabel (std_to_wx(m));
+}
index c02cc8c85b0e196f71610e0718fe957f9b5594f6..06f979a74fde34d575dc07afed42354ce759dd12 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
@@ -24,6 +24,7 @@
 
 class wxRichTextCtrl;
 class Film;
+class Hints;
 
 class HintsDialog : public wxDialog
 {
@@ -33,9 +34,18 @@ public:
 private:
        void film_changed ();
        void shut_up (wxCommandEvent& ev);
+       void update ();
+       void hint (std::string text);
+       void pulse ();
+       void finished ();
+       void progress (std::string m);
 
        boost::weak_ptr<Film> _film;
+       wxGauge* _gauge;
+       wxStaticText* _gauge_message;
        wxRichTextCtrl* _text;
+       boost::shared_ptr<Hints> _hints;
+       std::list<std::string> _current;
 
        boost::signals2::scoped_connection _film_changed_connection;
        boost::signals2::scoped_connection _film_content_changed_connection;