W/AudioRecord(17145): obtainBuffer timed out (is the CPU pegged?) user=11b7f820, server=11b7f820
1〜2時間の録音後に受け取ります。AudioRecord からの read() が 0 バイトを読み取ったため、明らかに録音が停止します。私はこれに2週間以上苦労していますが、まだ解決策が見つかりません. audioRecord オブジェクトを初期化する方法は次のとおりです。
private void initPCMRecorder() throws Exception {
Log.d(getClass().getName(), "Initializing AudioRecord...");
int channelConfig = nChannels == 1 ? AudioFormat.CHANNEL_IN_MONO: AudioFormat.CHANNEL_IN_STEREO;
bufferSize = AudioRecord.getMinBufferSize(sRate, channelConfig, aFormat);
if (bufferSize == AudioRecord.ERROR_BAD_VALUE)
Log.e(getClass().getName(), "Bad encoding value, see logcat");
else if (bufferSize == AudioRecord.ERROR)
Log.e(getClass().getName(), "Error creating buffer size");
bufferSize *= 3;
buffer = new byte[bufferSize];
//check if is not yet released
if(aRecorder != null){
try {
aRecorder.release();
} catch (Exception e) {
Log.e(getClass().getName(), e.getMessage(), e);
}
}
System.out.println("Source="+aSource+"; sampRate="+sRate+"; format="+aFormat+"; bufSize="+bufferSize);
aRecorder = new AudioRecord(aSource, sRate, channelConfig, aFormat, bufferSize);
if (aRecorder.getState() != AudioRecord.STATE_INITIALIZED) {
throw new Exception("" + ErrorCodes.ERROR_CODE_0);
}
Log.d(getClass().getName(), "AudioRecord Initialized");
state = State.INITIALIZING;
}
そして私は二次スレッドを読みました。positionNotificationListener を使用しようとしましたが、結果は同じでした。
public void run() {
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
while (!stopped) {
while (!suspend) {
int result = aRecorder.read(buffer, 0, buffer.length);
if(result == AudioRecord.ERROR_INVALID_OPERATION){
Log.e(getClass().getName(), "aRecorder.read() returns ERROR_INVALID_OPERATION !!!");
continue;
}else if(result == AudioRecord.ERROR_BAD_VALUE){
Log.e(getClass().getName(), "aRecorder.read() returns ERROR_BAD_VALUE !!!");
continue;
}else if(result == 0){
Log.w(getClass().getName(), "SKIP audio block.");
continue;
}
payloadSize += buffer.length;
//data processing/writing is done in another thread
WAVData audioData = new WAVData(buffer);
audioData.setGain(rGain);
audioData.setBitsPerSamples(bitsPerSample);
audioData.setNrChannels(nChannels);
if(writersArray.size()>=1)
writersArray.get(writersArray.size() - 1).add(audioData);
}
// lock here
synchronized (lock) {
try {
lock.wait();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
}
}
}
編集(コンソールからエラーを追加 -com.audioRec.android.recorder
私のアプリです):
08-02 12:30:38.162: D/dalvikvm(1451): GC_CONCURRENT freed 7867K, 36% free 18889K/29447K, paused 17ms+8ms, total 151ms
08-02 12:30:38.953: D/dalvikvm(1451): GC_FOR_ALLOC freed 36K, 36% free 18892K/29447K, paused 46ms, total 47ms
08-02 12:30:39.063: D/dalvikvm(1451): GC_CONCURRENT freed <1K, 29% free 21196K/29447K, paused 18ms+6ms, total 108ms
08-02 12:30:59.004: W/AudioRecord(703): obtainBuffer timed out (is the CPU pegged?) user=00f49160, server=00f49160
08-02 12:30:59.515: W/AudioRecord(703): obtainBuffer timed out (is the CPU pegged?) user=00f49160, server=00f49160
08-02 12:31:00.035: W/AudioRecord(703): obtainBuffer timed out (is the CPU pegged?) user=00f49160, server=00f49160
08-02 12:31:00.526: W/com.audioRec.android.recorder.AudioRecorder$RecorderThread(703): SKIP audio block.
08-02 12:31:00.766: W/AudioRecord(703): obtainBuffer timed out (is the CPU pegged?) user=00f49160, server=00f49160
08-02 12:31:01.297: W/AudioRecord(703): obtainBuffer timed out (is the CPU pegged?) user=00f49160, server=00f49160
08-02 12:31:01.797: W/AudioRecord(703): obtainBuffer timed out (is the CPU pegged?) user=00f49160, server=00f49160
08-02 12:31:02.308: W/AudioRecord(703): obtainBuffer timed out (is the CPU pegged?) user=00f49160, server=00f49160
08-02 12:31:02.558: W/com.audioRec.android.recorder.AudioRecorder$RecorderThread(703): SKIP audio block.
08-02 12:31:02.558: D/com.audioRec.android.recorder.AudioRecorder$RecorderThread(703): MUST RESET AUDIORECORD....obtainBuffer timed out ?
08-02 12:31:02.568: D/com.audioRec.android.recorder.AudioRecorder$AudioRecordCalibrator(703): Calibrating AudioRecord object...
08-02 12:31:08.494: E/alsa_pcm(257): Arec: error5
08-02 12:31:08.494: W/AudioStreamInALSA(257): pcm_read() returned error n -5, Recovering from error
08-02 12:31:08.615: E/ALSADevice(257): standby handle h 0x4234f358
08-02 12:31:08.645: D/alsa_ucm(257): snd_use_case_set(): uc_mgr 0x42e24fb8 identifier _dismod value Capture Music
08-02 12:31:08.645: D/alsa_ucm(257): Set mixer controls for Capture Music enable 0
08-02 12:31:08.655: D/alsa_ucm(257): Setting mixer control: MultiMedia1 Mixer SLIM_0_TX, value: 0
08-02 12:31:08.655: E/ALSADevice(257): Number of modifiers 0
08-02 12:31:08.655: E/ALSADevice(257): usecase_type is 0
これで私を助けてください。私の頭に浮かぶ唯一の解決策は、0バイトを読み取り、audioRecordを再度停止/開始する2つの連続した read() をチェックすることですが、0,5秒の録音が失われます。