0

出于基准测试的目的,我重复加载一个 .wav 文件,离线处理它并使用 SuperpoweredSDK 保存输出。但是经过一些迭代后(在我的情况下为 4),当我尝试释放 shortIntBuffer 时,我收到错误“A/libc:无效地址或损坏块 0x5e825000 的地址传递给 dlfree”。

extern "C" JNIEXPORT void JNICALL
Java_com_example_sebas_superpoweredtest_MainActivity_testDecoderReuse(JNIEnv *env, jobject instance,
                                                                  jstring apkPath_,
                                                                  jlong fileOffset,
                                                                  jlong fileLength,
                                                                  jstring outputFileName_) {

    const char *apkPath = env->GetStringUTFChars(apkPath_, 0);
    const char *outputFileName = env->GetStringUTFChars(outputFileName_, 0);

    SuperpoweredDecoder decoder;
    short int* shortIntBuffer;
    FILE* fd;

    for(int i = 0; i < 100; ++i) {

        __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "RUN %d", i+1);

        //open InputFile
        const char *openError = decoder.open(apkPath, false, fileOffset, fileLength);
        if (openError) {
            __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "%s", openError);
            return;
        };

        shortIntBuffer = new short int[decoder.samplesPerFrame * 4 + 16384] {0};

        fd = createWAV(outputFileName, decoder.samplerate, 2);
        if (!fd) {
            __android_log_print(ANDROID_LOG_ERROR,LOG_TAG, "Failed creating File %s", outputFileName);
            return;
        };

        //process samples
        unsigned int samplesDecoded;

        while (true) {
            // Decode one frame. samplesDecoded will be overwritten with the actual decoded number of samples.
            samplesDecoded = decoder.samplesPerFrame;
            if (decoder.decode(shortIntBuffer, &samplesDecoded) == SUPERPOWEREDDECODER_ERROR) {
                __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Error while decoding samples.");
                break;
            }

            if (samplesDecoded < 1) break;

            // Write the audio to disk.
            fwrite(shortIntBuffer, 1, samplesDecoded * 4, fd);
        };

        //close resources
        if(fd) {
            closeWAV(fd);
            __android_log_print(ANDROID_LOG_ERROR,LOG_TAG, "Closed wav.");
        }


        delete[](shortIntBuffer); // <- SIGSEGV (signal SIGSEGV: invalid address (fault address: 0xdeadbaad))
        __android_log_print(ANDROID_LOG_ERROR,LOG_TAG, "Deleted shortInBuffer");


    }

    env->ReleaseStringUTFChars(apkPath_, apkPath);
    env->ReleaseStringUTFChars(outputFileName_, outputFileName);
}

我不明白为什么代码在第一次迭代中运行良好,但不适用于所有迭代。很高兴收到您的来信来解决这个问题。

提前致谢

这是我收到消息时的 LLDB 帧:“致命信号 11 (SIGSEGV) at 0xfde0fdec (code=1), thread 9779 (upperpoweredtest)”

LLDB 帧

4

0 回答 0