From c419819c0f56d18758c99270b9a010c1d348908d Mon Sep 17 00:00:00 2001 From: fufesou Date: Fri, 3 Mar 2023 10:58:48 +0800 Subject: [PATCH] rename all stride_align to stride Signed-off-by: fufesou --- libs/scrap/examples/record-screen.rs | 4 ++-- libs/scrap/src/common/codec.rs | 24 ++++++++++++------------ libs/scrap/src/common/convert.rs | 12 ++++++------ libs/scrap/src/common/hwcodec.rs | 18 +++++++++--------- libs/scrap/src/common/mediacodec.rs | 4 ++-- libs/scrap/src/common/mod.rs | 4 ++-- libs/scrap/src/common/vpxcodec.rs | 12 ++++++------ src/client.rs | 4 ++-- src/common.rs | 4 ++-- src/flutter.rs | 6 +++--- 10 files changed, 46 insertions(+), 46 deletions(-) diff --git a/libs/scrap/examples/record-screen.rs b/libs/scrap/examples/record-screen.rs index 5df97838e..13ebc5f7d 100644 --- a/libs/scrap/examples/record-screen.rs +++ b/libs/scrap/examples/record-screen.rs @@ -18,7 +18,7 @@ use webm::mux; use webm::mux::Track; use scrap::vpxcodec as vpx_encode; -use scrap::{TraitCapturer, Capturer, Display, STRIDE_ALIGN}; +use scrap::{TraitCapturer, Capturer, Display, STRIDE}; const USAGE: &'static str = " Simple WebM screen capture. @@ -137,7 +137,7 @@ fn main() -> io::Result<()> { if let Ok(frame) = c.frame(Duration::from_millis(0)) { let ms = time.as_secs() * 1000 + time.subsec_millis() as u64; - for frame in vpx.encode(ms as i64, &frame, STRIDE_ALIGN).unwrap() { + for frame in vpx.encode(ms as i64, &frame, STRIDE).unwrap() { vt.add_frame(frame.data, frame.pts as u64 * 1_000_000, frame.key); } } diff --git a/libs/scrap/src/common/codec.rs b/libs/scrap/src/common/codec.rs index 1aada72e2..1f02f86d7 100644 --- a/libs/scrap/src/common/codec.rs +++ b/libs/scrap/src/common/codec.rs @@ -306,18 +306,18 @@ impl Decoder { pub fn handle_video_frame( &mut self, frame: &video_frame::Union, - stride_align: usize, + stride: usize, fmt: ImageFormat, rgb: &mut Vec, ) -> ResultType { match frame { video_frame::Union::Vp9s(vp9s) => { - Decoder::handle_vp9s_video_frame(&mut self.vpx, vp9s, stride_align, fmt, rgb) + Decoder::handle_vp9s_video_frame(&mut self.vpx, vp9s, stride, fmt, rgb) } #[cfg(feature = "hwcodec")] video_frame::Union::H264s(h264s) => { if let Some(decoder) = &mut self.hw.h264 { - Decoder::handle_hw_video_frame(decoder, h264s, fmt, rgb, &mut self.i420) + Decoder::handle_hw_video_frame(decoder, h264s, stride, fmt, rgb, &mut self.i420) } else { Err(anyhow!("don't support h264!")) } @@ -325,7 +325,7 @@ impl Decoder { #[cfg(feature = "hwcodec")] video_frame::Union::H265s(h265s) => { if let Some(decoder) = &mut self.hw.h265 { - Decoder::handle_hw_video_frame(decoder, h265s, fmt, rgb, &mut self.i420) + Decoder::handle_hw_video_frame(decoder, h265s, stride, fmt, rgb, &mut self.i420) } else { Err(anyhow!("don't support h265!")) } @@ -333,7 +333,7 @@ impl Decoder { #[cfg(feature = "mediacodec")] video_frame::Union::H264s(h264s) => { if let Some(decoder) = &mut self.media_codec.h264 { - Decoder::handle_mediacodec_video_frame(decoder, h264s, fmt, rgb) + Decoder::handle_mediacodec_video_frame(decoder, h264s, stride, fmt, rgb) } else { Err(anyhow!("don't support h264!")) } @@ -341,7 +341,7 @@ impl Decoder { #[cfg(feature = "mediacodec")] video_frame::Union::H265s(h265s) => { if let Some(decoder) = &mut self.media_codec.h265 { - Decoder::handle_mediacodec_video_frame(decoder, h265s, fmt, rgb) + Decoder::handle_mediacodec_video_frame(decoder, h265s, stride, fmt, rgb) } else { Err(anyhow!("don't support h265!")) } @@ -353,7 +353,7 @@ impl Decoder { fn handle_vp9s_video_frame( decoder: &mut VpxDecoder, vp9s: &EncodedVideoFrames, - stride_align: usize, + stride: usize, fmt: ImageFormat, rgb: &mut Vec, ) -> ResultType { @@ -371,7 +371,7 @@ impl Decoder { if last_frame.is_null() { Ok(false) } else { - last_frame.to(fmt, stride_align, rgb); + last_frame.to(fmt, stride, rgb); Ok(true) } } @@ -380,7 +380,7 @@ impl Decoder { fn handle_hw_video_frame( decoder: &mut HwDecoder, frames: &EncodedVideoFrames, - stride_align: usize, + stride: usize, fmt: ImageFormat, raw: &mut Vec, i420: &mut Vec, @@ -389,7 +389,7 @@ impl Decoder { for h264 in frames.frames.iter() { for image in decoder.decode(&h264.data)? { // TODO: just process the last frame - if image.to_fmt(stride_align, fmt, raw, i420).is_ok() { + if image.to_fmt(stride, fmt, raw, i420).is_ok() { ret = true; } } @@ -401,13 +401,13 @@ impl Decoder { fn handle_mediacodec_video_frame( decoder: &mut MediaCodecDecoder, frames: &EncodedVideoFrames, - stride_align: usize, + stride: usize, fmt: ImageFormat, raw: &mut Vec, ) -> ResultType { let mut ret = false; for h264 in frames.frames.iter() { - return decoder.decode(&h264.data, stride_align, fmt, raw); + return decoder.decode(&h264.data, stride, fmt, raw); } return Ok(false); } diff --git a/libs/scrap/src/common/convert.rs b/libs/scrap/src/common/convert.rs index f3ad51a21..1c19ac0c0 100644 --- a/libs/scrap/src/common/convert.rs +++ b/libs/scrap/src/common/convert.rs @@ -144,7 +144,7 @@ extern "C" { fn get_vpx_i420_stride( width: usize, height: usize, - stride_align: usize, + stride: usize, ) -> (usize, usize, usize, usize, usize, usize) { let mut img = Default::default(); unsafe { @@ -153,7 +153,7 @@ fn get_vpx_i420_stride( vpx_img_fmt::VPX_IMG_FMT_I420, width as _, height as _, - stride_align as _, + stride as _, 0x1 as _, ); } @@ -169,7 +169,7 @@ fn get_vpx_i420_stride( pub fn i420_to_rgb(width: usize, height: usize, src: &[u8], dst: &mut Vec) { let (_, _, src_stride_y, src_stride_uv, u, v) = - get_vpx_i420_stride(width, height, super::STRIDE_ALIGN); + get_vpx_i420_stride(width, height, super::STRIDE); let src_y = src.as_ptr(); let src_u = src[u..].as_ptr(); let src_v = src[v..].as_ptr(); @@ -192,7 +192,7 @@ pub fn i420_to_rgb(width: usize, height: usize, src: &[u8], dst: &mut Vec) { pub fn bgra_to_i420(width: usize, height: usize, src: &[u8], dst: &mut Vec) { let (_, h, dst_stride_y, dst_stride_uv, u, v) = - get_vpx_i420_stride(width, height, super::STRIDE_ALIGN); + get_vpx_i420_stride(width, height, super::STRIDE); dst.resize(h * dst_stride_y * 2, 0); // waste some memory to ensure memory safety let dst_y = dst.as_mut_ptr(); let dst_u = dst[u..].as_mut_ptr(); @@ -215,7 +215,7 @@ pub fn bgra_to_i420(width: usize, height: usize, src: &[u8], dst: &mut Vec) pub fn rgba_to_i420(width: usize, height: usize, src: &[u8], dst: &mut Vec) { let (_, h, dst_stride_y, dst_stride_uv, u, v) = - get_vpx_i420_stride(width, height, super::STRIDE_ALIGN); + get_vpx_i420_stride(width, height, super::STRIDE); dst.resize(h * dst_stride_y * 2, 0); // waste some memory to ensure memory safety let dst_y = dst.as_mut_ptr(); let dst_u = dst[u..].as_mut_ptr(); @@ -246,7 +246,7 @@ pub unsafe fn nv12_to_i420( dst: &mut Vec, ) { let (_, h, dst_stride_y, dst_stride_uv, u, v) = - get_vpx_i420_stride(width, height, super::STRIDE_ALIGN); + get_vpx_i420_stride(width, height, super::STRIDE); dst.resize(h * dst_stride_y * 2, 0); // waste some memory to ensure memory safety let dst_y = dst.as_mut_ptr(); let dst_u = dst[u..].as_mut_ptr(); diff --git a/libs/scrap/src/common/hwcodec.rs b/libs/scrap/src/common/hwcodec.rs index 82f8b7283..0047672a4 100644 --- a/libs/scrap/src/common/hwcodec.rs +++ b/libs/scrap/src/common/hwcodec.rs @@ -1,6 +1,6 @@ use crate::{ codec::{EncoderApi, EncoderCfg}, - hw, ImageFormat, HW_STRIDE_ALIGN, + hw, ImageFormat, HW_STRIDE, }; use hbb_common::{ anyhow::{anyhow, Context}, @@ -52,7 +52,7 @@ impl EncoderApi for HwEncoder { width: config.width as _, height: config.height as _, pixfmt: DEFAULT_PIXFMT, - align: HW_STRIDE_ALIGN as _, + align: HW_STRIDE as _, bitrate: config.bitrate * 1000, timebase: DEFAULT_TIME_BASE, gop: DEFAULT_GOP, @@ -236,7 +236,7 @@ pub struct HwDecoderImage<'a> { } impl HwDecoderImage<'_> { - pub fn to_fmt(&self, stride_align: usize, fmt: ImageFormat, fmt_data: &mut Vec, i420: &mut Vec) -> ResultType<()> { + pub fn to_fmt(&self, stride: usize, fmt: ImageFormat, fmt_data: &mut Vec, i420: &mut Vec) -> ResultType<()> { let frame = self.frame; match frame.pixfmt { AVPixelFormat::AV_PIX_FMT_NV12 => hw::hw_nv12_to( @@ -249,7 +249,7 @@ impl HwDecoderImage<'_> { frame.linesize[1] as _, fmt_data, i420, - HW_STRIDE_ALIGN, + HW_STRIDE, ), AVPixelFormat::AV_PIX_FMT_YUV420P => { hw::hw_i420_to( @@ -269,12 +269,12 @@ impl HwDecoderImage<'_> { } } - pub fn bgra(&self, stride_align: usize, bgra: &mut Vec, i420: &mut Vec) -> ResultType<()> { - self.to_fmt(stride_align, ImageFormat::ARGB, bgra, i420) + pub fn bgra(&self, stride: usize, bgra: &mut Vec, i420: &mut Vec) -> ResultType<()> { + self.to_fmt(stride, ImageFormat::ARGB, bgra, i420) } - pub fn rgba(&self, stride_align: usize, rgba: &mut Vec, i420: &mut Vec) -> ResultType<()> { - self.to_fmt(stride_align, ImageFormat::ABGR, rgba, i420) + pub fn rgba(&self, stride: usize, rgba: &mut Vec, i420: &mut Vec) -> ResultType<()> { + self.to_fmt(stride, ImageFormat::ABGR, rgba, i420) } } @@ -296,7 +296,7 @@ pub fn check_config() { width: 1920, height: 1080, pixfmt: DEFAULT_PIXFMT, - align: HW_STRIDE_ALIGN as _, + align: HW_STRIDE as _, bitrate: 0, timebase: DEFAULT_TIME_BASE, gop: DEFAULT_GOP, diff --git a/libs/scrap/src/common/mediacodec.rs b/libs/scrap/src/common/mediacodec.rs index 694a5e3ed..306b511f6 100644 --- a/libs/scrap/src/common/mediacodec.rs +++ b/libs/scrap/src/common/mediacodec.rs @@ -50,8 +50,8 @@ impl MediaCodecDecoder { MediaCodecDecoders { h264, h265 } } - // to-do: apply stride_align to raw output data - pub fn decode(&mut self, data: &[u8], stride_align: usize, fmt: ImageFormat, raw: &mut Vec) -> ResultType { + // to-do: apply stride to raw output data + pub fn decode(&mut self, data: &[u8], stride: usize, fmt: ImageFormat, raw: &mut Vec) -> ResultType { match self.dequeue_input_buffer(Duration::from_millis(10))? { Some(mut input_buffer) => { let mut buf = input_buffer.buffer_mut(); diff --git a/libs/scrap/src/common/mod.rs b/libs/scrap/src/common/mod.rs index c7da57734..bc193d22d 100644 --- a/libs/scrap/src/common/mod.rs +++ b/libs/scrap/src/common/mod.rs @@ -37,8 +37,8 @@ pub mod hwcodec; pub mod mediacodec; pub mod vpxcodec; pub use self::convert::*; -pub const STRIDE_ALIGN: usize = 64; // commonly used in libvpx vpx_img_alloc caller -pub const HW_STRIDE_ALIGN: usize = 0; // recommended by av_frame_get_buffer +pub const STRIDE: usize = 64; // commonly used in libvpx vpx_img_alloc caller +pub const HW_STRIDE: usize = 0; // recommended by av_frame_get_buffer pub mod record; mod vpx; diff --git a/libs/scrap/src/common/vpxcodec.rs b/libs/scrap/src/common/vpxcodec.rs index a94db61b4..3ee3e391f 100644 --- a/libs/scrap/src/common/vpxcodec.rs +++ b/libs/scrap/src/common/vpxcodec.rs @@ -6,7 +6,7 @@ use hbb_common::anyhow::{anyhow, Context}; use hbb_common::message_proto::{EncodedVideoFrame, EncodedVideoFrames, Message, VideoFrame}; use hbb_common::{get_time, ResultType}; -use crate::STRIDE_ALIGN; +use crate::STRIDE; use crate::{codec::EncoderApi, ImageFormat}; use super::vpx::{vp8e_enc_control_id::*, vpx_codec_err_t::*, *}; @@ -202,7 +202,7 @@ impl EncoderApi for VpxEncoder { fn encode_to_message(&mut self, frame: &[u8], ms: i64) -> ResultType { let mut frames = Vec::new(); for ref frame in self - .encode(ms, frame, STRIDE_ALIGN) + .encode(ms, frame, STRIDE) .with_context(|| "Failed to encode")? { frames.push(VpxEncoder::create_frame(frame)); @@ -232,7 +232,7 @@ impl EncoderApi for VpxEncoder { } impl VpxEncoder { - pub fn encode(&mut self, pts: i64, data: &[u8], stride_align: usize) -> Result { + pub fn encode(&mut self, pts: i64, data: &[u8], stride: usize) -> Result { if 2 * data.len() < 3 * self.width * self.height { return Err(Error::FailedCall("len not enough".to_string())); } @@ -243,7 +243,7 @@ impl VpxEncoder { vpx_img_fmt::VPX_IMG_FMT_I420, self.width as _, self.height as _, - stride_align as _, + stride as _, data.as_ptr() as _, )); @@ -539,7 +539,7 @@ impl Image { self.inner().stride[iplane] } - pub fn to(&self, fmt: ImageFormat, stride_align: usize, dst: &mut Vec) { + pub fn to(&self, fmt: ImageFormat, stride: usize, dst: &mut Vec) { let h = self.height(); let w = self.width(); let bytes_per_pixel = match fmt { @@ -548,7 +548,7 @@ impl Image { }; // https://github.com/lemenkov/libyuv/blob/6900494d90ae095d44405cd4cc3f346971fa69c9/source/convert_argb.cc#L128 // https://github.com/lemenkov/libyuv/blob/6900494d90ae095d44405cd4cc3f346971fa69c9/source/convert_argb.cc#L129 - let bytes_per_row = (w * bytes_per_pixel + stride_align - 1) & !(stride_align - 1); + let bytes_per_row = (w * bytes_per_pixel + stride - 1) & !(stride - 1); dst.resize(h * bytes_per_row, 0); let img = self.inner(); unsafe { diff --git a/src/client.rs b/src/client.rs index 2249c98e4..14cba6c85 100644 --- a/src/client.rs +++ b/src/client.rs @@ -49,7 +49,7 @@ use scrap::{ }; use crate::{ - common::{self, is_keyboard_mode_supported, STRIDE_ALIGN_RGBA_OUTPUT}, + common::{self, is_keyboard_mode_supported, DST_STRIDE_RGBA}, server::video_service::{SCRAP_X11_REF_URL, SCRAP_X11_REQUIRED}, }; @@ -944,7 +944,7 @@ impl VideoHandler { } match &vf.union { Some(frame) => { - let res = self.decoder.handle_video_frame(frame, STRIDE_ALIGN_RGBA_OUTPUT, ImageFormat::ARGB, &mut self.rgb); + let res = self.decoder.handle_video_frame(frame, DST_STRIDE_RGBA, ImageFormat::ARGB, &mut self.rgb); if self.record { self.recorder .lock() diff --git a/src/common.rs b/src/common.rs index c781d3eaf..28d8dddc4 100644 --- a/src/common.rs +++ b/src/common.rs @@ -42,9 +42,9 @@ pub const SYNC_PEER_INFO_DISPLAYS: i32 = 1; #[cfg(all(target_os = "macos", feature = "flutter_texture_render"))] // https://developer.apple.com/forums/thread/712709 // Memory alignment should be multiple of 64. -pub const STRIDE_ALIGN_RGBA_OUTPUT: usize = 64; +pub const DST_STRIDE_RGBA: usize = 64; #[cfg(not(all(target_os = "macos", feature = "flutter_texture_render")))] -pub const STRIDE_ALIGN_RGBA_OUTPUT: usize = 1; +pub const DST_STRIDE_RGBA: usize = 1; // the executable name of the portable version pub const PORTABLE_APPNAME_RUNTIME_ENV_KEY: &str = "RUSTDESK_APPNAME"; diff --git a/src/flutter.rs b/src/flutter.rs index 03949f89d..1fbf92c12 100644 --- a/src/flutter.rs +++ b/src/flutter.rs @@ -154,7 +154,7 @@ pub struct FlutterHandler { #[cfg(feature = "flutter_texture_render")] pub type FlutterRgbaRendererPluginOnRgba = - unsafe extern "C" fn(texture_rgba: *mut c_void, buffer: *const u8, len: c_int, width: c_int, height: c_int, stride_align: c_int); + unsafe extern "C" fn(texture_rgba: *mut c_void, buffer: *const u8, len: c_int, width: c_int, height: c_int, stride: c_int); // Video Texture Renderer in Flutter #[cfg(feature = "flutter_texture_render")] @@ -206,7 +206,7 @@ impl VideoRenderer { self.width = width; self.height = height; self.data_len = if width > 0 && height > 0 { - let sa1 = crate::common::STRIDE_ALIGN_RGBA_OUTPUT - 1; + let sa1 = crate::common::DST_STRIDE_RGBA - 1; let row_bytes = (width as usize * 4 + sa1) & !sa1; row_bytes * height as usize } else { @@ -226,7 +226,7 @@ impl VideoRenderer { rgba.len() as _, self.width as _, self.height as _, - crate::common::STRIDE_ALIGN_RGBA_OUTPUT as _, + crate::common::DST_STRIDE_RGBA as _, ) }; }