set fmt and stride to private in ImageRgb

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2023-04-28 12:35:46 +08:00
parent e3b66af8af
commit fc50a3e49d
6 changed files with 27 additions and 11 deletions

View File

@ -287,6 +287,7 @@ impl Decoder {
}
}
// rgb [in/out] fmt and stride must be set in ImageRgb
pub fn handle_video_frame(
&mut self,
frame: &video_frame::Union,
@ -335,6 +336,7 @@ impl Decoder {
}
}
// rgb [in/out] fmt and stride must be set in ImageRgb
fn handle_vpxs_video_frame(
decoder: &mut VpxDecoder,
vpxs: &EncodedVideoFrames,
@ -359,6 +361,7 @@ impl Decoder {
}
}
// rgb [in/out] fmt and stride must be set in ImageRgb
#[cfg(feature = "hwcodec")]
fn handle_hw_video_frame(
decoder: &mut HwDecoder,
@ -378,6 +381,7 @@ impl Decoder {
return Ok(ret);
}
// rgb [in/out] fmt and stride must be set in ImageRgb
#[cfg(feature = "mediacodec")]
fn handle_mediacodec_video_frame(
decoder: &mut MediaCodecDecoder,

View File

@ -227,15 +227,16 @@ pub struct HwDecoderImage<'a> {
}
impl HwDecoderImage<'_> {
// rgb [in/out] fmt and stride must be set in ImageRgb
pub fn to_fmt(&self, rgb: &mut ImageRgb, i420: &mut Vec<u8>) -> ResultType<()> {
let frame = self.frame;
rgb.w = frame.width as _;
rgb.h = frame.height as _;
// take dst_stride into account when you convert
let dst_stride = rgb.stride;
let dst_stride = rgb.stride();
match frame.pixfmt {
AVPixelFormat::AV_PIX_FMT_NV12 => hw::hw_nv12_to(
rgb.fmt,
rgb.fmt(),
frame.width as _,
frame.height as _,
&frame.data[0],
@ -248,7 +249,7 @@ impl HwDecoderImage<'_> {
),
AVPixelFormat::AV_PIX_FMT_YUV420P => {
hw::hw_i420_to(
rgb.fmt,
rgb.fmt(),
frame.width as _,
frame.height as _,
&frame.data[0],

View File

@ -50,9 +50,10 @@ impl MediaCodecDecoder {
MediaCodecDecoders { h264, h265 }
}
// rgb [in/out] fmt and stride must be set in ImageRgb
pub fn decode(&mut self, data: &[u8], rgb: &mut ImageRgb) -> ResultType<bool> {
// take dst_stride into account please
let dst_stride = rgb.stride;
let dst_stride = rgb.stride();
match self.dequeue_input_buffer(Duration::from_millis(10))? {
Some(mut input_buffer) => {
let mut buf = input_buffer.buffer_mut();
@ -90,7 +91,7 @@ impl MediaCodecDecoder {
let u_ptr = buf[u..].as_ptr();
let v_ptr = buf[v..].as_ptr();
unsafe {
match rgb.fmt {
match rgb.fmt() {
ImageFormat::ARGB => {
I420ToARGB(
y_ptr,

View File

@ -53,22 +53,32 @@ pub enum ImageFormat {
pub struct ImageRgb {
pub raw: Vec<u8>,
pub fmt: ImageFormat,
pub w: usize,
pub h: usize,
pub stride: usize,
fmt: ImageFormat,
stride: usize,
}
impl ImageRgb {
pub fn new(fmt: ImageFormat, stride: usize) -> Self {
Self {
raw: Vec::new(),
fmt,
w: 0,
h: 0,
fmt,
stride,
}
}
#[inline]
pub fn fmt(&self) -> ImageFormat {
self.fmt
}
#[inline]
pub fn stride(&self) -> usize {
self.stride
}
}
#[inline]

View File

@ -536,11 +536,11 @@ impl Image {
pub fn to(&self, rgb: &mut ImageRgb) {
rgb.w = self.width();
rgb.h = self.height();
let bytes_per_row = Self::get_bytes_per_row(rgb.w, rgb.fmt, rgb.stride);
let bytes_per_row = Self::get_bytes_per_row(rgb.w, rgb.fmt, rgb.stride());
rgb.raw.resize(rgb.h * bytes_per_row, 0);
let img = self.inner();
unsafe {
match rgb.fmt {
match rgb.fmt() {
ImageFormat::Raw => {
super::I420ToRAW(
img.planes[0],

View File

@ -242,7 +242,7 @@ impl VideoRenderer {
rgba.raw.len() as _,
rgba.w as _,
rgba.h as _,
rgba.stride as _,
rgba.stride() as _,
)
};
}