2016-11-03 61 views
5

我有简单的代码,将opus帧解码为音频样本。 它适用于Android,但它在Unity3D iOS项目中崩溃,并且不会在常规iOS项目中崩溃。iOS上的Opus解码器崩溃没有明显的原因

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 opus crash in 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

出现这种情况是由于一个符号冲突。 Unity 3D库定义了一些符号,包括compute_allocation(),这些符号也是由libopus定义和使用的。如果Unity 3D库位于链接器命令行上的libopus之前,那么它可能会引入该版本,这不适用于libopus。如果你需要两套,那么你可能需要重新命名冲突的符号。

+0

我很高兴你在这里回复!再次感谢。 – Tema

+0

是否有任何其他解决方案(例如配置编译器去除除某些名称之外的所有内容)?此解决方案可能会在Unity引入新的内部函数名称时破坏。 – Martin