Skip audio analysis when there is no audio content (#596).
authorCarl Hetherington <cth@carlh.net>
Wed, 10 Jun 2015 15:38:55 +0000 (16:38 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 10 Jun 2015 15:38:55 +0000 (16:38 +0100)
ChangeLog
src/lib/analyse_audio_job.cc

index 47678af18cc01ec284dc3161e266fc15e1fd5143..9db166734b0bb00b7d2c99262b43d43ac18c02bd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2015-06-10  c.hetherington  <cth@carlh.net>
+
+       * Skip audio analysis when there is no audio content (#596).
+
 2015-06-09  Carl Hetherington  <cth@carlh.net>
 
        * Version 2.0.49 released.
index 31b9dccae953e4ced010feeab571e5a12fadd3a6..b17dd07dcb0869cb1891aecbe7068319a433a1f0 100644 (file)
@@ -23,6 +23,7 @@
 #include "compose.hpp"
 #include "film.h"
 #include "player.h"
+#include <boost/foreach.hpp>
 
 #include "i18n.h"
 
@@ -31,6 +32,7 @@ using std::max;
 using std::min;
 using std::cout;
 using boost::shared_ptr;
+using boost::dynamic_pointer_cast;
 
 int const AnalyseAudioJob::_num_points = 1024;
 
@@ -69,11 +71,20 @@ AnalyseAudioJob::run ()
        _current.resize (_film->audio_channels ());
        _analysis.reset (new AudioAnalysis (_film->audio_channels ()));
 
-       _done = 0;
-       DCPTime const block = DCPTime::from_seconds (1.0 / 8);
-       for (DCPTime t; t < _film->length(); t += block) {
-               analyse (player->get_audio (t, block, false));
-               set_progress (t.seconds() / _film->length().seconds());
+       bool has_any_audio = false;
+       BOOST_FOREACH (shared_ptr<Content> c, _film->content ()) {
+               if (dynamic_pointer_cast<AudioContent> (c)) {
+                       has_any_audio = true;
+               }
+       }
+
+       if (has_any_audio) {
+               _done = 0;
+               DCPTime const block = DCPTime::from_seconds (1.0 / 8);
+               for (DCPTime t; t < _film->length(); t += block) {
+                       analyse (player->get_audio (t, block, false));
+                       set_progress (t.seconds() / _film->length().seconds());
+               }
        }
 
        _analysis->set_peak (_overall_peak, DCPTime::from_frames (_overall_peak_frame, _film->audio_frame_rate ()));