iOS上的Opus解码器崩溃,原因不明。

6

我有一段简单的代码,可以将Opus帧解码为音频样本。

它在Android上工作正常,但在Unity3D iOS项目中会崩溃,并且在常规iOS项目中不会崩溃。

EXC_BAD_ACCESS (code=1, address=0x2f)

这两个项目共享同一个opus静态库和头文件。

#include "opus.h"

int test1(){
    unsigned char opus_chunk[] = {0x68, 0x97, 0x50, 0x0d,
        0xba, 0xa4, 0x80, 0x0d, 0x31, 0x21, 0x9c, 0xcf, 0x74, 0x98, 0xda, 0xc6,
        0xd5, 0x27, 0xcb, 0xd9, 0x51, 0xd7, 0xce, 0x90, 0xc5, 0x58, 0x94, 0x53,
        0xb0, 0xe9, 0xb4, 0xe4, 0xf4, 0x42, 0x4d, 0xc7, 0xa4, 0x61, 0xfa, 0xfe};
    int len = sizeof(opus_chunk);
    short samples[5760];
    int err1;
    OpusDecoder *decoder;
    decoder = opus_decoder_create(48000, 1, &err1);
    int n = opus_decode(decoder, opus_chunk, len, samples, 5760, 0);
    opus_decoder_destroy(decoder);

}

xcode中CELT崩溃的截图

堆栈跟踪:

#0  0x00b944ec in compute_allocation ()
#1  0x00c03698 in celt_decode_with_ec at ./opus_ios/build/src/opus-1.1.2/celt/celt_decoder.c:956
#2  0x00c2400c in opus_decode_frame at ./opus_ios/build/src/opus-1.1.2/src/opus_decoder.c:490
#3  0x00c24ea2 in opus_decode_native [inlined] at ./opus_ios/build/src/opus-1.1.2/src/opus_decoder.c:692
#4  0x00c24e80 in opus_decode at ./opus_ios/build/src/opus-1.1.2/src/opus_decoder.c:782

我比较了构建设置并使它们几乎相同。
错误听起来像是分配出现了问题。 opus_decoder_create 能够分配 OpusDecoder,但错误出现在 opus_decode
1个回答

4

这是由于符号冲突引起的。Unity 3D库定义了一些符号,包括compute_allocation(),这些符号也被libopus定义和使用。如果在链接器命令行中Unity 3D库先于libopus,它可能会引入与libopus不兼容的版本。如果您需要两个集合,则可能需要重命名冲突的符号。


很高兴你在这里回复了!再次感谢。 - Tema
有没有其他的解决方案(例如配置编译器以剥离除某些名称之外的所有内容)?这种解决方案可能会在Unity引入新的内部函数名称时失效。 - Martin
2023年才是真正的现实!统一+不和谐。opus_decode_float。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接