Fix bad_alloc exception on audio analysis (and probably elsewhere).
authorCarl Hetherington <cth@carlh.net>
Tue, 12 Nov 2013 21:45:33 +0000 (21:45 +0000)
committerCarl Hetherington <cth@carlh.net>
Tue, 12 Nov 2013 21:45:33 +0000 (21:45 +0000)
ChangeLog
src/lib/player.cc

index 4e964d5c8c57c4927b3757e26e68aff02f3c6735..63d2c597e225c57e869a7fa374513fbc6639ee21 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2013-11-12  Carl Hetherington  <cth@carlh.net>
+
+       * Fix bad_alloc exception on audio analysis (and
+       probably elsewhere).
+
 2013-11-11  Carl Hetherington  <cth@carlh.net>
 
        * Version 1.28 released.
index 97d2cbdc0086a9e13058116839feb950910dbfdd..b5a96163182b458acf00a58661be273251ceab60 100644 (file)
@@ -221,20 +221,22 @@ Player::pass ()
        }
 
        if (_audio) {
-               Time audio_done_up_to = TIME_MAX;
+               boost::optional<Time> audio_done_up_to;
                for (list<shared_ptr<Piece> >::iterator i = _pieces.begin(); i != _pieces.end(); ++i) {
                        if ((*i)->decoder->done ()) {
                                continue;
                        }
 
                        if (dynamic_pointer_cast<AudioDecoder> ((*i)->decoder)) {
-                               audio_done_up_to = min (audio_done_up_to, (*i)->audio_position);
+                               audio_done_up_to = min (audio_done_up_to.get_value_or (TIME_MAX), (*i)->audio_position);
                        }
                }
 
-               TimedAudioBuffers<Time> tb = _audio_merger.pull (audio_done_up_to);
-               Audio (tb.audio, tb.time);
-               _audio_position += _film->audio_frames_to_time (tb.audio->frames ());
+               if (audio_done_up_to) {
+                       TimedAudioBuffers<Time> tb = _audio_merger.pull (audio_done_up_to.get ());
+                       Audio (tb.audio, tb.time);
+                       _audio_position += _film->audio_frames_to_time (tb.audio->frames ());
+               }
        }
                
        return false;