2016-11-03 62 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