mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-06-12 11:19:21 +00:00
lewton: Don't copy decoded samples if no channel reordering is needed
This commit is contained in:
parent
87f2c3b025
commit
a43ad8f2dd
|
@ -418,33 +418,32 @@ impl LewtonDec {
|
||||||
return element.finish_frame(None, 1);
|
return element.finish_frame(None, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut outbuf = element
|
let outbuf = if let Some(ref reorder_map) = state.reorder_map {
|
||||||
.allocate_output_buffer(sample_count as usize * audio_info.bpf() as usize)
|
let mut outbuf = element
|
||||||
.map_err(|_| {
|
.allocate_output_buffer(sample_count as usize * audio_info.bpf() as usize)
|
||||||
gst_element_error!(
|
.map_err(|_| {
|
||||||
element,
|
gst_element_error!(
|
||||||
gst::StreamError::Decode,
|
element,
|
||||||
["Failed to allocate output buffer"]
|
gst::StreamError::Decode,
|
||||||
);
|
["Failed to allocate output buffer"]
|
||||||
gst::FlowError::Error
|
);
|
||||||
})?;
|
gst::FlowError::Error
|
||||||
|
})?;
|
||||||
|
{
|
||||||
|
// And copy the decoded data into our output buffer while reordering the channels to the
|
||||||
|
// GStreamer channel order
|
||||||
|
let outbuf = outbuf.get_mut().unwrap();
|
||||||
|
let mut outmap = outbuf.map_writable().map_err(|_| {
|
||||||
|
gst_element_error!(
|
||||||
|
element,
|
||||||
|
gst::StreamError::Decode,
|
||||||
|
["Failed to map output buffer writable"]
|
||||||
|
);
|
||||||
|
gst::FlowError::Error
|
||||||
|
})?;
|
||||||
|
|
||||||
// And copy the decoded data into our output buffer, if needed
|
let outdata = outmap.as_mut_slice_of::<f32>().unwrap();
|
||||||
// while reordering the channels to the GStreamer channel order
|
let channels = audio_info.channels() as usize;
|
||||||
{
|
|
||||||
let outbuf = outbuf.get_mut().unwrap();
|
|
||||||
let mut outmap = outbuf.map_writable().map_err(|_| {
|
|
||||||
gst_element_error!(
|
|
||||||
element,
|
|
||||||
gst::StreamError::Decode,
|
|
||||||
["Failed to map output buffer writable"]
|
|
||||||
);
|
|
||||||
gst::FlowError::Error
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let outdata = outmap.as_mut_slice_of::<f32>().unwrap();
|
|
||||||
let channels = audio_info.channels() as usize;
|
|
||||||
if let Some(ref reorder_map) = state.reorder_map {
|
|
||||||
assert!(reorder_map.len() >= channels);
|
assert!(reorder_map.len() >= channels);
|
||||||
assert!(reorder_map[..channels].iter().all(|c| *c < channels));
|
assert!(reorder_map[..channels].iter().all(|c| *c < channels));
|
||||||
|
|
||||||
|
@ -456,10 +455,24 @@ impl LewtonDec {
|
||||||
output[reorder_map[c]] = *s;
|
output[reorder_map[c]] = *s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
outdata.copy_from_slice(&decoded.samples);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
outbuf
|
||||||
|
} else {
|
||||||
|
struct CastVec(Vec<f32>);
|
||||||
|
impl AsRef<[u8]> for CastVec {
|
||||||
|
fn as_ref(&self) -> &[u8] {
|
||||||
|
self.0.as_byte_slice()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl AsMut<[u8]> for CastVec {
|
||||||
|
fn as_mut(&mut self) -> &mut [u8] {
|
||||||
|
self.0.as_mut_byte_slice()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gst::Buffer::from_mut_slice(CastVec(decoded.samples))
|
||||||
|
};
|
||||||
|
|
||||||
element.finish_frame(Some(outbuf), 1)
|
element.finish_frame(Some(outbuf), 1)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue