зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1512450 - Clean up reslicing of audio buffers in AudioIPC's server data callback. r=chunmin
--HG-- extra : amend_source : c7e3943507cde2d321aa1f6b03054cd028336f88
This commit is contained in:
Родитель
658dc05260
Коммит
5ed3387542
|
@ -85,11 +85,16 @@ impl ServerStreamCallbacks {
|
|||
fn data_callback(&mut self, input: &[u8], output: &mut [u8]) -> isize {
|
||||
trace!("Stream data callback: {} {}", input.len(), output.len());
|
||||
|
||||
// len is of input and output is frame len. Turn these into the real lengths.
|
||||
// FFI wrapper (data_cb_c) converted buffers to [u8] slices but len is frames *not* bytes.
|
||||
// Convert slices to correct length now we have {input,output}_frame_size available.
|
||||
let real_input = unsafe {
|
||||
let nbytes = input.len() * self.input_frame_size as usize;
|
||||
slice::from_raw_parts(input.as_ptr(), nbytes)
|
||||
};
|
||||
let real_output = unsafe {
|
||||
let nbytes = output.len() * self.output_frame_size as usize;
|
||||
slice::from_raw_parts_mut(output.as_mut_ptr(), nbytes)
|
||||
};
|
||||
|
||||
self.input_shm.write(real_input).unwrap();
|
||||
|
||||
|
@ -104,10 +109,7 @@ impl ServerStreamCallbacks {
|
|||
Ok(CallbackResp::Data(frames)) => {
|
||||
if frames >= 0 {
|
||||
let nbytes = frames as usize * self.output_frame_size as usize;
|
||||
let real_output = unsafe {
|
||||
trace!("Resize output to {}", nbytes);
|
||||
slice::from_raw_parts_mut(output.as_mut_ptr(), nbytes)
|
||||
};
|
||||
trace!("Reslice output to {}", nbytes);
|
||||
self.output_shm.read(&mut real_output[..nbytes]).unwrap();
|
||||
}
|
||||
frames
|
||||
|
|
Загрузка…
Ссылка в новой задаче