Qt JNI:decodeIndirectRef中的间接引用0x61382e48无效

时间:2015-02-12 07:29:43

标签: java android qt java-native-interface jnienv

我正在尝试从Android上的麦克风捕获音频数据的Qt项目。 我评论了这篇文章:Android AudioRecord example,并将其写入Qt代码。

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);
}

但是,在这一行 int result = mAudioRecorder-&gt; callMethod(“read”,“([BII] I”,缓冲区,偏移量,大小); 应用程序崩溃并在日志后输出。

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)

我猜这个错误是导致JNI调用错误的原因,但我找不到原因。

增加: 我发现 0x61382e48 是缓冲区数组的地址

编辑:AudioRecord的Android指南为here

欢迎任何建议。

0 个答案:

没有答案