Don't let hint generation throw an exception in the presence of old audio analysis...
authorCarl Hetherington <cth@carlh.net>
Mon, 3 Oct 2016 22:42:39 +0000 (23:42 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 3 Oct 2016 22:42:39 +0000 (23:42 +0100)
ChangeLog
src/lib/hints.cc

index d19da4149a3842fff759237da1a335eed7269ded..64a781e82ffffa4eb5d63dc1bec4ec343290d3e7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2016-10-03  Carl Hetherington  <cth@carlh.net>
 
+       * Fix crash on make DCP if there are old audio analysis files.
+
        * Updated zh_CN translation from 刘汉源.
 
 2016-10-03  Carl Hetherington  <cth@carlh.net>
index b410252bd14ca5417a1a0a9405f4780cf5044a39..219b5139cda492b479af68ff76fd2c7ae6b18e76 100644 (file)
@@ -135,30 +135,36 @@ get_hints (shared_ptr<const Film> film)
 
        boost::filesystem::path path = film->audio_analysis_path (film->playlist ());
        if (boost::filesystem::exists (path)) {
-               shared_ptr<AudioAnalysis> an (new AudioAnalysis (path));
+               try {
+                       shared_ptr<AudioAnalysis> an (new AudioAnalysis (path));
 
-               string ch;
+                       string ch;
 
-               vector<AudioAnalysis::PeakTime> sample_peak = an->sample_peak ();
-               vector<float> true_peak = an->true_peak ();
+                       vector<AudioAnalysis::PeakTime> sample_peak = an->sample_peak ();
+                       vector<float> true_peak = an->true_peak ();
 
-               for (size_t i = 0; i < sample_peak.size(); ++i) {
-                       float const peak = max (sample_peak[i].peak, true_peak.empty() ? 0 : true_peak[i]);
-                       float const peak_dB = 20 * log10 (peak) + an->gain_correction (film->playlist ());
-                       if (peak_dB > -3) {
-                               ch += dcp::raw_convert<string> (short_audio_channel_name (i)) + ", ";
+                       for (size_t i = 0; i < sample_peak.size(); ++i) {
+                               float const peak = max (sample_peak[i].peak, true_peak.empty() ? 0 : true_peak[i]);
+                               float const peak_dB = 20 * log10 (peak) + an->gain_correction (film->playlist ());
+                               if (peak_dB > -3) {
+                                       ch += dcp::raw_convert<string> (short_audio_channel_name (i)) + ", ";
+                               }
                        }
-               }
 
-               ch = ch.substr (0, ch.length() - 2);
+                       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
-                                       )
-                               );
+                       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
+                                               )
+                                       );
+                       }
+               } catch (OldFormatError& e) {
+                       /* The audio analysis is too old to load in; just skip this hint as if
+                          it had never been run.
+                       */
                }
        }