0

我在退货线路上遇到错误。我的代码:

extern "C" DLL_PUBLIC jbyteArray Java_com_ngochoang_playerdemo_AudioNativeLib_navProcessBytes(JNIEnv *env, jobject thiz, jbyteArray data, jint size)
{
    LOGV("JNI call soundtouch.navProcessBytes");
    int bufferSize = size*5;
    SAMPLETYPE sampleBuffer[bufferSize];
    pSoundTouch.putSamples((SAMPLETYPE*)data, size);
    TotalNSamples = pSoundTouch.receiveSamples(sampleBuffer, bufferSize);
    LOGV("JNI call soundtouch.navProcessBytes END");
    return (jbyteArray)sampleBuffer;
}

错误:

致命信号 11 (SIGSEGV) 位于 0xdeadd00d (code=1),线程 5980 (Thread-753)

谢谢

4

1 回答 1

0

我解决了我的问题。

extern "C" DLL_PUBLIC jbyteArray Java_com_ngochoang_playerdemo_AudioNativeLib_navProcessBytes(JNIEnv *env, jobject thiz, jbyteArray data, jint size)
{
    LOGV("JNI call soundtouch.navProcessBytes");
    int bufferSize = size*5;
    SAMPLETYPE sampleBuffer[bufferSize];
    pSoundTouch.putSamples((SAMPLETYPE*)data, size);
    TotalNSamples = pSoundTouch.receiveSamples(sampleBuffer, bufferSize);
    jbyteArray ret = env->NewByteArray(bufferSize);
    env->SetByteArrayRegion(ret, 0, bufferSize, (jbyte *)sampleBuffer);
    LOGV("JNI call soundtouch.navProcessBytes END");
    return ret;
}

需要使用 JNI 函数 SetByteArrayRegion 将其复制到 jbyteArray

于 2013-10-24T12:00:11.373 回答