diff --git a/libs/scrap/src/common/codec.rs b/libs/scrap/src/common/codec.rs index 81ed5824a..0f5b5dad3 100644 --- a/libs/scrap/src/common/codec.rs +++ b/libs/scrap/src/common/codec.rs @@ -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, diff --git a/libs/scrap/src/common/hwcodec.rs b/libs/scrap/src/common/hwcodec.rs index efd250bc1..3ee91ca8b 100644 --- a/libs/scrap/src/common/hwcodec.rs +++ b/libs/scrap/src/common/hwcodec.rs @@ -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) -> 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], diff --git a/libs/scrap/src/common/mediacodec.rs b/libs/scrap/src/common/mediacodec.rs index eaaa0ddd7..9c64a4ace 100644 --- a/libs/scrap/src/common/mediacodec.rs +++ b/libs/scrap/src/common/mediacodec.rs @@ -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 { // 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, diff --git a/libs/scrap/src/common/mod.rs b/libs/scrap/src/common/mod.rs index d57939e5e..80b4e7813 100644 --- a/libs/scrap/src/common/mod.rs +++ b/libs/scrap/src/common/mod.rs @@ -53,22 +53,32 @@ pub enum ImageFormat { pub struct ImageRgb { pub raw: Vec, - 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] diff --git a/libs/scrap/src/common/vpxcodec.rs b/libs/scrap/src/common/vpxcodec.rs index a64a1b05f..21d88ef0c 100644 --- a/libs/scrap/src/common/vpxcodec.rs +++ b/libs/scrap/src/common/vpxcodec.rs @@ -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], diff --git a/src/flutter.rs b/src/flutter.rs index 91962d5ea..f08b6a569 100644 --- a/src/flutter.rs +++ b/src/flutter.rs @@ -242,7 +242,7 @@ impl VideoRenderer { rgba.raw.len() as _, rgba.w as _, rgba.h as _, - rgba.stride as _, + rgba.stride() as _, ) }; }