From 46e8ef415e50ecf767ec5e9124bcc56c9190a0f0 Mon Sep 17 00:00:00 2001 From: Apehum Date: Wed, 18 Oct 2023 13:25:39 +0800 Subject: [PATCH] fix(rust): copy java samples to rust vec in encoder --- rust/src/encoder.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rust/src/encoder.rs b/rust/src/encoder.rs index 4a47cdb..fdeb7f3 100644 --- a/rust/src/encoder.rs +++ b/rust/src/encoder.rs @@ -172,7 +172,10 @@ unsafe fn encoder_encode<'local>( .err_into_opus_exception("Failed to get samples array length".into())? as usize; - let samples_vec = vec![0i16 as jshort; samples_length]; + let mut samples_vec = vec![0i16 as jshort; samples_length]; + + env.get_short_array_region(samples, 0, &mut samples_vec) + .err_into_opus_exception("Failed to copy samples to rust vec".into())?; let result = container.encoder.encode_vec(&samples_vec, container.mtu_size as usize) .err_into_opus_exception("Failed to encode audio".into())?;