0
我正在開發語音聊天,並使用speex來壓縮正在傳輸的數據。 但是我嘗試解碼接收到的數據時遇到了崩潰。Speex語音聊天:嘗試解碼時EXC_BAD_ACCESS崩潰
Init方法(只運行一次)::
/*Create a new encoder state in narrowband mode*/
state = speex_encoder_init(&speex_nb_mode);
/*Set the quality to 8 (15 kbps)*/
int tmp=8;
speex_encoder_ctl(state, SPEEX_SET_QUALITY, &tmp);
speex_bits_init(&bits);
壓縮方法:
AudioBuffer sourceBuffer = bufferList->mBuffers[0];
speex_bits_reset(&bits);
/*Encode the frame*/
speex_encode(state, sourceBuffer.mData, &bits);
char cbits[200];
int nbBytes = speex_bits_write(&bits, cbits, 200);
NSData *result = [[NSData alloc] initWithBytes:cbits length:200];
解壓縮方法:
NSLog(@"Lenght %d", [data length]);
speex_bits_reset(&bits);
/*Copy the data into the bit-stream struct*/
speex_bits_read_from(&bits, (void*)[data bytes], [data length]);
/*Decode the data*/
speex_decode(state, &bits, tempBuffer.mData);
相同 我使用此代碼壓縮數據初始化如前
它在speex_decode時沒有錯誤而崩潰。我檢查了輸入NSData的長度和輸出的長度,它們是相同的。裏面的字節是一樣的。
這就是問題所在 – edo42