如何停止频繁运行GC_CONCURRENT?

时间:2012-04-09 07:24:24

标签: android audio audio-recording android-2.3-gingerbread

我正在使用一个线程,该线程使用AudioRecord类记录音频并放在recorderBUffer(Short []的链接列表)中,这是一个单独的线程,它对这些数据进行编码并将其放入playerBuffer(链表) [])。为了播放音频我正在使用AudioTrack类和onPeriodicNotification()我从playerBuffer读取数据并将其写入轨道。

代码很简单,直观。但它不应该按照它的方式工作。 GC_CONCURRENT一直吃掉,这导致AudioTrack如此频繁地重启(我猜!)。我从LogCat收到以下消息: -

04-09 12:25:13.757: E/Constructor(10100): inside constructor 
04-09 12:25:13.757: I/ApplicationPackageManager(10100): cscCountry is not German : INS
04-09 12:25:17.429: E/startRecording(10100): start Recording
04-09 12:25:17.445: I/AudioCapturer(10100): Audio Recorder created
04-09 12:25:17.546: I/Audio Player(10100): Audio Track instance created buffer Size : 2972
04-09 12:25:17.546: I/SpeexThread(10100): Thread Started Successfully..
04-09 12:25:17.734: D/dalvikvm(10100): GC_CONCURRENT freed 55K, 44% free 3208K/5639K, external 408K/517K, paused 4ms+6ms
04-09 12:25:17.945: D/dalvikvm(10100): GC_CONCURRENT freed 1K, 39% free 3765K/6151K, external 408K/517K, paused 3ms+8ms
04-09 12:25:18.148: D/dalvikvm(10100): GC_CONCURRENT freed <1K, 36% free 4277K/6663K, external 408K/517K, paused 3ms+8ms
04-09 12:25:18.414: D/dalvikvm(10100): GC_CONCURRENT freed <1K, 33% free 4981K/7367K, external 408K/517K, paused 3ms+9ms
04-09 12:25:18.734: D/dalvikvm(10100): GC_CONCURRENT freed <1K, 29% free 5877K/8263K, external 408K/517K, paused 3ms+9ms
04-09 12:25:18.828: W/AudioTrack(10100): obtainBuffer() track 0x1d0478 disabled, restarting
04-09 12:25:19.164: D/dalvikvm(10100): GC_CONCURRENT freed <1K, 26% free 7093K/9479K, external 408K/517K, paused 3ms+9ms
04-09 12:25:19.710: D/dalvikvm(10100): GC_CONCURRENT freed <1K, 22% free 8693K/11079K, external 408K/517K, paused 3ms+9ms
04-09 12:25:19.984: W/AudioTrack(10100): obtainBuffer() track 0x1d0478 disabled, restarting
04-09 12:25:20.414: D/dalvikvm(10100): GC_CONCURRENT freed <1K, 19% free 10741K/13127K, external 408K/517K, paused 3ms+9ms
04-09 12:25:21.156: W/AudioTrack(10100): obtainBuffer() track 0x1d0478 disabled, restarting
04-09 12:25:21.171: D/dalvikvm(10100): GC_CONCURRENT freed <1K, 16% free 12789K/15175K, external 408K/517K, paused 3ms+11ms
04-09 12:25:21.976: D/dalvikvm(10100): GC_CONCURRENT freed <1K, 14% free 14837K/17223K, external 408K/517K, paused 3ms+9ms
// same messages errors continue  
04-09 12:25:28.117: W/AudioTrack(10100): obtainBuffer() track 0x1d0478 disabled, restarting
04-09 12:25:29.242: D/dalvikvm(10100): GC_CONCURRENT freed 1K, 8% free 29172K/31559K, external 408K/517K, paused 3ms+11ms
04-09 12:25:29.273: W/AudioTrack(10100): obtainBuffer() track 0x1d0478 disabled, restarting
04-09 12:25:30.445: W/AudioTrack(10100): obtainBuffer() track 0x1d0478 disabled, restarting
04-09 12:25:30.507: D/dalvikvm(10100): GC_CONCURRENT freed 1K, 8% free 31220K/33607K, external 408K/517K, paused 4ms+12ms
04-09 12:25:31.601: W/AudioTrack(10100): obtainBuffer() track 0x1d0478 disabled, restarting
04-09 12:25:31.820: D/dalvikvm(10100): GC_CONCURRENT freed 1K, 7% free 33268K/35655K, external 408K/517K, paused 3ms+12ms
04-09 12:25:32.757: W/AudioTrack(10100): obtainBuffer() track 0x1d0478 disabled, restarting
04-09 12:25:33.187: D/dalvikvm(10100): GC_CONCURRENT freed 1K, 7% free 35316K/37703K, external 408K/517K, paused 3ms+13ms
04-09 12:25:33.929: W/AudioTrack(10100): obtainBuffer() track 0x1d0478 disabled, restarting
04-09 12:25:34.593: D/dalvikvm(10100): GC_CONCURRENT freed 1K, 7% free 37364K/39751K, external 408K/517K, paused 4ms+11ms
04-09 12:25:35.085: W/AudioTrack(10100): obtainBuffer() track 0x1d0478 disabled, restarting
04-09 12:25:36.039: D/dalvikvm(10100): GC_CONCURRENT freed 1K, 6% free 39412K/41799K, external 408K/517K, paused 3ms+12ms
04-09 12:25:36.242: W/AudioTrack(10100): obtainBuffer() track 0x1d0478 disabled, restarting
04-09 12:25:37.406: W/AudioTrack(10100): obtainBuffer() track 0x1d0478 disabled, restarting
04-09 12:25:37.617: D/dalvikvm(10100): GC_CONCURRENT freed 1K, 6% free 41460K/43847K, external 408K/517K, paused 5ms+13ms
04-09 12:25:38.640: D/dalvikvm(10100): GC_FOR_MALLOC freed 1K, 6% free 43507K/45895K, external 408K/517K, paused 933ms
04-09 12:25:38.656: I/SpeexThread(10100): exitting Thread
04-09 12:25:38.656: E/stopRecording(10100): stop Recording

每隔几毫秒重新启动一次AudiTrack,几乎连续调用GArbage Collection。如何最小化GArbage Colloection调用以及AudioTrack重启的原因是什么? Plz帮助...

1 个答案:

答案 0 :(得分:11)

问题的临时解决方案是使用dalvik.system.VMRuntime.getRuntime().setMinimumHeapSize(32 * 1024 * 1024);增加HeapSize但是这种方法不推荐,应该避免

通过广泛的调试,我发现真正的问题是由于重叠的接口和一些泄漏的功能。后来我删除其中一个界面,重新设计整体解决方案,重新设计代码,解决了我的问题

如果您有其他解决方案,请分享,