问题
I am trying the Qt project that captures audio data from mic on android. I refereed this article : Android AudioRecord example, and wrote it to Qt code.
int recorderSampleRate = 44100;
int recorderChannels = QAndroidJniObject::getStaticField<jint>("android/media/AudioFormat", "CHANNEL_IN_MONO");
int recorderAudioEncoding = QAndroidJniObject::getStaticField<jint>("android/media/AudioFormat", "ENCODING_PCM_16BIT");
int sourceType = QAndroidJniObject::getStaticField<jint>("android/media/MediaRecorder$AudioSource", "MIC");
int bsize = QAndroidJniObject::callStaticMethod<int>("android/media/AudioRecord", "getMinBufferSize", "(III)I", recorderSampleRate, recorderChannels, recorderAudioEncoding);
mAudioRecorder = new QAndroidJniObject("android/media/AudioRecord", "(IIIII)V", sourceType, recorderSampleRate, recorderChannels, recorderAudioEncoding, BufferElements2Rec * BytesPerElement);
// starting capture.
mAudioRecorder->callMethod<void>("startRecording", "()V");
// ready buffer.
jint size = BufferElements2Rec * BytesPerElement;
jbyte buffers[size * 2];
qDebug() << "start capture";
while(true)
{
{
jint offset = 0;
// read cached audio data from AudioRecord
int result = mAudioRecorder->callMethod<jint>("read", "([BII)I", buffers, offset, size);
qDebug() << "readed byte size " << result;
}
// wait a bit for new audio data.
msleep(10);
}
But, at this line int result = mAudioRecorder->callMethod("read", "([BII)I", buffers, offset, size); the app crashed and outputted following log.
W/dalvikvm(24772): Invalid indirect reference 0x61382e48 in decodeIndirectRef
E/dalvikvm(24772): VM aborting
F/libc (24772): Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1), thread 24975 (ldAndroidCaptur)
I guessed this error was cause of bad JNI calling, but I couldn't find the reason.
Addition: I found 0x61382e48 is a address of buffers array
EDIT : Android guide for AudioRecord is here.
Welcome any advices.
来源:https://stackoverflow.com/questions/28471691/qt-jni-invalid-indirect-reference-0x61382e48-in-decodeindirectref