Skip to content

Commit

Permalink
refactor: replace pointers to OpusDecoder with mutable references
Browse files Browse the repository at this point in the history
  • Loading branch information
DCNick3 committed Jun 28, 2024
1 parent ccafed9 commit 0a77c3e
Show file tree
Hide file tree
Showing 17 changed files with 309 additions and 293 deletions.
2 changes: 1 addition & 1 deletion src/celt/bands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1976,7 +1976,7 @@ pub unsafe fn quant_all_bands(
);
}
nstart_bytes = ec_save.offs as i32;
nend_bytes = (*ec).storage as i32;
nend_bytes = ec.storage as i32;
bytes_buf = ec.buf.as_ptr().offset(nstart_bytes as isize);
save_bytes = nend_bytes - nstart_bytes;
memcpy(
Expand Down
8 changes: 4 additions & 4 deletions src/celt/celt_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ pub unsafe fn celt_decode_with_ec(
}
if silence != 0 {
tell = len * 8;
(*dec).nbits_total += tell - ec_tell(dec);
dec.nbits_total += tell - ec_tell(dec);
}
postfilter_gain = 0 as opus_val16;
postfilter_pitch = 0;
Expand Down Expand Up @@ -1411,7 +1411,7 @@ pub unsafe fn celt_decode_with_ec(
break;
}
}
(*st).rng = (*dec).rng;
(*st).rng = dec.rng;
deemphasis(
out_syn.as_mut_ptr(),
pcm,
Expand Down Expand Up @@ -1441,7 +1441,7 @@ pub unsafe fn opus_custom_decoder_ctl_impl(
match request {
CELT_SET_START_BAND_REQUEST => {
let value: i32 = ap.arg::<i32>();
if value < 0 || value >= (*(*st).mode).nbEBands as i32 {
if value < 0 || value >= (*st).mode.nbEBands as i32 {
current_block = 7990025728955927862;
} else {
(*st).start = value;
Expand All @@ -1450,7 +1450,7 @@ pub unsafe fn opus_custom_decoder_ctl_impl(
}
CELT_SET_END_BAND_REQUEST => {
let value_0: i32 = ap.arg::<i32>();
if value_0 < 1 || value_0 > (*(*st).mode).nbEBands as i32 {
if value_0 < 1 || value_0 > (*st).mode.nbEBands as i32 {
current_block = 7990025728955927862;
} else {
(*st).end = value_0;
Expand Down
10 changes: 5 additions & 5 deletions src/celt/celt_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ unsafe fn tf_encode(
let mut logp: i32 = 0;
let mut budget: u32 = 0;
let mut tell: u32 = 0;
budget = ((*enc).storage).wrapping_mul(8);
budget = enc.storage.wrapping_mul(8);
tell = ec_tell(enc) as u32;
logp = if isTransient != 0 { 2 } else { 4 };
tf_select_rsv = (LM > 0 && tell.wrapping_add(logp as u32).wrapping_add(1) <= budget) as i32;
Expand Down Expand Up @@ -2045,8 +2045,8 @@ pub unsafe fn celt_encode_with_ec(
oldLogE2 = oldLogE.offset((CC * nbEBands) as isize);
energyError = oldLogE2.offset((CC * nbEBands) as isize);
if let Some(enc) = enc.as_mut() {
tell0_frac = ec_tell_frac(*enc) as i32;
tell = ec_tell(*enc);
tell0_frac = ec_tell_frac(enc) as i32;
tell = ec_tell(enc);
nbFilledBytes = tell + 4 >> 3;
} else {
tell = 1;
Expand Down Expand Up @@ -2187,7 +2187,7 @@ pub unsafe fn celt_encode_with_ec(
ec_enc_shrink(enc, nbCompressedBytes as u32);
}
tell = nbCompressedBytes * 8;
(*enc).nbits_total += tell - ec_tell(enc);
enc.nbits_total += tell - ec_tell(enc);
}
c = 0;
loop {
Expand Down Expand Up @@ -3293,7 +3293,7 @@ pub unsafe fn celt_encode_with_ec(
} else {
(*st).consec_transient = 0;
}
(*st).rng = (*enc).rng;
(*st).rng = enc.rng;
ec_enc_done(enc);
if ec_get_error(enc) != 0 {
return OPUS_INTERNAL_ERROR;
Expand Down
2 changes: 1 addition & 1 deletion src/celt/quant_bands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ pub unsafe fn unquant_coarse_energy(
beta = beta_coef[LM as usize];
coef = pred_coef[LM as usize];
}
budget = ((*dec).storage).wrapping_mul(8) as i32;
budget = dec.storage.wrapping_mul(8) as i32;
i = start;
while i < end {
c = 0;
Expand Down
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,13 @@ pub use crate::src::opus_encoder::{
opus_encoder_destroy, opus_encoder_get_size, opus_encoder_init, OpusEncoder,
};
// opus_decoder
#[allow(deprecated)]
pub use crate::src::opus_decoder::{
opus_decode, opus_decode_float, opus_decoder_create, opus_decoder_ctl_impl,
opus_decoder_destroy, opus_decoder_get_nb_samples, opus_decoder_get_size, opus_decoder_init,
opus_decoder_create, opus_decoder_destroy, opus_decoder_get_size, opus_decoder_init,
};

pub use crate::src::opus_decoder::{
opus_decode, opus_decode_float, opus_decoder_ctl_impl, opus_decoder_get_nb_samples,
opus_packet_get_bandwidth, opus_packet_get_nb_channels, opus_packet_get_nb_frames,
opus_packet_get_nb_samples, OpusDecoder,
};
Expand Down
10 changes: 5 additions & 5 deletions src/silk/CNG.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ pub fn silk_CNG_Reset(psDec: &mut silk_decoder_state) {
let mut i: i32 = 0;
let mut NLSF_step_Q15: i32 = 0;
let mut NLSF_acc_Q15: i32 = 0;
NLSF_step_Q15 = 0x7fff / ((*psDec).LPC_order + 1);
NLSF_step_Q15 = 0x7fff / (psDec.LPC_order + 1);
NLSF_acc_Q15 = 0;
i = 0;
while i < (*psDec).LPC_order {
while i < psDec.LPC_order {
NLSF_acc_Q15 += NLSF_step_Q15;
(*psDec).sCNG.CNG_smth_NLSF_Q15[i as usize] = NLSF_acc_Q15 as i16;
psDec.sCNG.CNG_smth_NLSF_Q15[i as usize] = NLSF_acc_Q15 as i16;
i += 1;
}
(*psDec).sCNG.CNG_smth_Gain_Q16 = 0;
(*psDec).sCNG.rand_seed = 3176576;
psDec.sCNG.CNG_smth_Gain_Q16 = 0;
psDec.sCNG.rand_seed = 3176576;
}
pub unsafe fn silk_CNG(
psDec: *mut silk_decoder_state,
Expand Down
11 changes: 5 additions & 6 deletions src/silk/decode_indices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ pub unsafe fn silk_decode_indices(
}
(*psDec).indices.NLSFIndices[0 as usize] = ec_dec_icdf(
psRangeDec,
&(*(*psDec).psNLSF_CB).CB1_iCDF[(((*psDec).indices.signalType as i32 >> 1)
* (*(*psDec).psNLSF_CB).nVectors as i32)
as usize..],
&(*psDec).psNLSF_CB.CB1_iCDF[(((*psDec).indices.signalType as i32 >> 1)
* (*psDec).psNLSF_CB.nVectors as i32) as usize..],
8,
) as i8;
silk_NLSF_unpack(
Expand All @@ -67,12 +66,12 @@ pub unsafe fn silk_decode_indices(
(*psDec).psNLSF_CB,
(*psDec).indices.NLSFIndices[0 as usize] as i32,
);
assert!((*(*psDec).psNLSF_CB).order as i32 == (*psDec).LPC_order);
assert!((*psDec).psNLSF_CB.order as i32 == (*psDec).LPC_order);
i = 0;
while i < (*(*psDec).psNLSF_CB).order as i32 {
while i < (*psDec).psNLSF_CB.order as i32 {
Ix = ec_dec_icdf(
psRangeDec,
&(*(*psDec).psNLSF_CB).ec_iCDF[*ec_ix.as_mut_ptr().offset(i as isize) as usize..],
&(*psDec).psNLSF_CB.ec_iCDF[*ec_ix.as_mut_ptr().offset(i as isize) as usize..],
8,
);
if Ix == 0 {
Expand Down
4 changes: 2 additions & 2 deletions src/silk/enc_API.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ pub unsafe fn silk_Encode(
}
TargetRate_bps -= (*psEnc).nBitsExceeded * 1000 / 500;
if prefillFlag == 0 && (*psEnc).state_Fxx[0 as usize].sCmn.nFramesEncoded > 0 {
let bitsBalance: i32 = ec_tell(&mut **psRangeEnc.as_mut().unwrap())
let bitsBalance: i32 = ec_tell(psRangeEnc.as_mut().unwrap())
- (*psEnc).nBitsUsedLBRR
- nBits * (*psEnc).state_Fxx[0 as usize].sCmn.nFramesEncoded;
TargetRate_bps -= bitsBalance * 1000 / 500;
Expand Down Expand Up @@ -791,7 +791,7 @@ pub unsafe fn silk_Encode(
}
if prefillFlag == 0 {
ec_enc_patch_initial_bits(
&mut **psRangeEnc.as_mut().unwrap(),
psRangeEnc.as_mut().unwrap(),
flags as u32,
(((*psEnc).state_Fxx[0 as usize].sCmn.nFramesPerPacket + 1)
* (*encControl).nChannelsInternal) as u32,
Expand Down
14 changes: 7 additions & 7 deletions src/silk/encode_indices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ pub unsafe fn silk_encode_indices(
ec_enc_icdf(
psRangeEnc,
(*psIndices).NLSFIndices[0 as usize] as i32,
&(*(*psEncC).psNLSF_CB).CB1_iCDF[(((*psIndices).signalType as i32 >> 1)
* (*(*psEncC).psNLSF_CB).nVectors as i32)
&(*psEncC).psNLSF_CB.CB1_iCDF[(((*psIndices).signalType as i32 >> 1)
* (*psEncC).psNLSF_CB.nVectors as i32)
as usize..],
8,
);
Expand All @@ -88,14 +88,14 @@ pub unsafe fn silk_encode_indices(
(*psEncC).psNLSF_CB,
(*psIndices).NLSFIndices[0 as usize] as i32,
);
assert!((*(*psEncC).psNLSF_CB).order as i32 == (*psEncC).predictLPCOrder);
assert!((*psEncC).psNLSF_CB.order as i32 == (*psEncC).predictLPCOrder);
i = 0;
while i < (*(*psEncC).psNLSF_CB).order as i32 {
while i < (*psEncC).psNLSF_CB.order as i32 {
if (*psIndices).NLSFIndices[(i + 1) as usize] as i32 >= NLSF_QUANT_MAX_AMPLITUDE {
ec_enc_icdf(
psRangeEnc,
2 * NLSF_QUANT_MAX_AMPLITUDE,
&(*(*psEncC).psNLSF_CB).ec_iCDF[*ec_ix.as_mut_ptr().offset(i as isize) as usize..],
&(*psEncC).psNLSF_CB.ec_iCDF[*ec_ix.as_mut_ptr().offset(i as isize) as usize..],
8,
);
ec_enc_icdf(
Expand All @@ -108,7 +108,7 @@ pub unsafe fn silk_encode_indices(
ec_enc_icdf(
psRangeEnc,
0,
&(*(*psEncC).psNLSF_CB).ec_iCDF[*ec_ix.as_mut_ptr().offset(i as isize) as usize..],
&(*psEncC).psNLSF_CB.ec_iCDF[*ec_ix.as_mut_ptr().offset(i as isize) as usize..],
8,
);
ec_enc_icdf(
Expand All @@ -121,7 +121,7 @@ pub unsafe fn silk_encode_indices(
ec_enc_icdf(
psRangeEnc,
(*psIndices).NLSFIndices[(i + 1) as usize] as i32 + NLSF_QUANT_MAX_AMPLITUDE,
&(*(*psEncC).psNLSF_CB).ec_iCDF[*ec_ix.as_mut_ptr().offset(i as isize) as usize..],
&(*psEncC).psNLSF_CB.ec_iCDF[*ec_ix.as_mut_ptr().offset(i as isize) as usize..],
8,
);
}
Expand Down
8 changes: 4 additions & 4 deletions src/silk/float/encode_frame_FLP.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ pub unsafe fn silk_encode_frame_FLP(
psRangeEnc.restore(sRangeEnc_copy2);
assert!(sRangeEnc_copy2.offs <= 1275);
memcpy(
(*psRangeEnc).buf.as_mut_ptr() as *mut core::ffi::c_void,
psRangeEnc.buf.as_mut_ptr() as *mut core::ffi::c_void,
ec_buf_copy.as_mut_ptr() as *const core::ffi::c_void,
sRangeEnc_copy2.offs as u64,
);
Expand Down Expand Up @@ -334,11 +334,11 @@ pub unsafe fn silk_encode_frame_FLP(
if gainsID != gainsID_lower {
gainsID_lower = gainsID;
sRangeEnc_copy2 = psRangeEnc.save();
assert!((*psRangeEnc).offs <= 1275);
assert!(psRangeEnc.offs <= 1275);
memcpy(
ec_buf_copy.as_mut_ptr() as *mut core::ffi::c_void,
(*psRangeEnc).buf.as_mut_ptr() as *const core::ffi::c_void,
(*psRangeEnc).offs as u64,
psRangeEnc.buf.as_mut_ptr() as *const core::ffi::c_void,
psRangeEnc.offs as u64,
);
memcpy(
&mut sNSQ_copy2 as *mut silk_nsq_state as *mut core::ffi::c_void,
Expand Down
Loading

0 comments on commit 0a77c3e

Please sign in to comment.