Emit the large bits of pointless silence which are the cause of #252 in half-second...
authorCarl Hetherington <cth@carlh.net>
Mon, 9 Jun 2014 22:13:27 +0000 (23:13 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 9 Jun 2014 22:13:27 +0000 (23:13 +0100)
ChangeLog
src/lib/ffmpeg_decoder.cc

index d473393f14c397ef898a231b0e00456fb4bbc7a3..4ad416fcce2329aec4bc860da3340b2a1ecbfefc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2014-06-09  Carl Hetherington  <cth@carlh.net>
 
+       * Work-around out-of-memory crashes with large start trims (#252).
+
        * Version 1.69.24 released.
 
 2014-06-06  Carl Hetherington  <cth@carlh.net>
index 04dd7fd2d27fb141c1f4e17f5df9bbc54a10f829..a51b521d0fe22918010a6976c5ae754dd9d8e051 100644 (file)
@@ -422,15 +422,18 @@ FFmpegDecoder::decode_audio_packet ()
 
                                if (pts > 0) {
                                        /* Emit some silence */
-                                       shared_ptr<AudioBuffers> silence (
-                                               new AudioBuffers (
-                                                       _ffmpeg_content->audio_channels(),
-                                                       pts * _ffmpeg_content->content_audio_frame_rate()
-                                                       )
-                                               );
+                                       int64_t frames = pts * _ffmpeg_content->content_audio_frame_rate ();
+                                       while (frames > 0) {
+                                               int64_t const this_time = min (frames, (int64_t) _ffmpeg_content->content_audio_frame_rate() / 2);
+                                               
+                                               shared_ptr<AudioBuffers> silence (
+                                                       new AudioBuffers (_ffmpeg_content->audio_channels(), this_time)
+                                                       );
                                        
-                                       silence->make_silent ();
-                                       audio (silence, _audio_position);
+                                               silence->make_silent ();
+                                               audio (silence, _audio_position);
+                                               frames -= this_time;
+                                       }
                                }
                        }