opt codec

1. use src width/height to convert yuv
2. align dst yuv to avoid illegal memory access
3. init yuvfmt when new codec
4. move remote reset calls from empty conns judge to emtpy remote conns
   judge

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages
2023-11-02 16:57:24 +08:00
parent 48dbc06b29
commit 534bfad50f
13 changed files with 229 additions and 138 deletions

View File

@@ -43,7 +43,7 @@ impl crate::TraitCapturer for Capturer {
unsafe {
std::ptr::copy_nonoverlapping(buf.as_ptr(), self.rgba.as_mut_ptr(), buf.len())
};
Ok(Frame::new(&self.rgba, self.height()))
Ok(Frame::new(&self.rgba, self.width(), self.height()))
} else {
return Err(io::ErrorKind::WouldBlock.into());
}
@@ -51,16 +51,23 @@ impl crate::TraitCapturer for Capturer {
}
pub struct Frame<'a> {
pub data: &'a [u8],
pub stride: Vec<usize>,
data: &'a [u8],
width: usize,
height: usize,
stride: Vec<usize>,
}
impl<'a> Frame<'a> {
pub fn new(data: &'a [u8], h: usize) -> Self {
let stride = data.len() / h;
let mut v = Vec::new();
v.push(stride);
Frame { data, stride: v }
pub fn new(data: &'a [u8], width: usize, height: usize) -> Self {
let stride0 = data.len() / height;
let mut stride = Vec::new();
stride.push(stride0);
Frame {
data,
width,
height,
stride,
}
}
}
@@ -69,6 +76,14 @@ impl<'a> crate::TraitFrame for Frame<'a> {
self.data
}
fn width(&self) -> usize {
self.width
}
fn height(&self) -> usize {
self.height
}
fn stride(&self) -> Vec<usize> {
self.stride.clone()
}