mirror of
https://github.com/rustdesk/rustdesk.git
synced 2024-11-24 04:12:20 +08:00
set fmt and stride to private in ImageRgb
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
e3b66af8af
commit
fc50a3e49d
@ -287,6 +287,7 @@ impl Decoder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// rgb [in/out] fmt and stride must be set in ImageRgb
|
||||||
pub fn handle_video_frame(
|
pub fn handle_video_frame(
|
||||||
&mut self,
|
&mut self,
|
||||||
frame: &video_frame::Union,
|
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(
|
fn handle_vpxs_video_frame(
|
||||||
decoder: &mut VpxDecoder,
|
decoder: &mut VpxDecoder,
|
||||||
vpxs: &EncodedVideoFrames,
|
vpxs: &EncodedVideoFrames,
|
||||||
@ -359,6 +361,7 @@ impl Decoder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// rgb [in/out] fmt and stride must be set in ImageRgb
|
||||||
#[cfg(feature = "hwcodec")]
|
#[cfg(feature = "hwcodec")]
|
||||||
fn handle_hw_video_frame(
|
fn handle_hw_video_frame(
|
||||||
decoder: &mut HwDecoder,
|
decoder: &mut HwDecoder,
|
||||||
@ -378,6 +381,7 @@ impl Decoder {
|
|||||||
return Ok(ret);
|
return Ok(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// rgb [in/out] fmt and stride must be set in ImageRgb
|
||||||
#[cfg(feature = "mediacodec")]
|
#[cfg(feature = "mediacodec")]
|
||||||
fn handle_mediacodec_video_frame(
|
fn handle_mediacodec_video_frame(
|
||||||
decoder: &mut MediaCodecDecoder,
|
decoder: &mut MediaCodecDecoder,
|
||||||
|
@ -227,15 +227,16 @@ pub struct HwDecoderImage<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl HwDecoderImage<'_> {
|
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<()> {
|
pub fn to_fmt(&self, rgb: &mut ImageRgb, i420: &mut Vec<u8>) -> ResultType<()> {
|
||||||
let frame = self.frame;
|
let frame = self.frame;
|
||||||
rgb.w = frame.width as _;
|
rgb.w = frame.width as _;
|
||||||
rgb.h = frame.height as _;
|
rgb.h = frame.height as _;
|
||||||
// take dst_stride into account when you convert
|
// take dst_stride into account when you convert
|
||||||
let dst_stride = rgb.stride;
|
let dst_stride = rgb.stride();
|
||||||
match frame.pixfmt {
|
match frame.pixfmt {
|
||||||
AVPixelFormat::AV_PIX_FMT_NV12 => hw::hw_nv12_to(
|
AVPixelFormat::AV_PIX_FMT_NV12 => hw::hw_nv12_to(
|
||||||
rgb.fmt,
|
rgb.fmt(),
|
||||||
frame.width as _,
|
frame.width as _,
|
||||||
frame.height as _,
|
frame.height as _,
|
||||||
&frame.data[0],
|
&frame.data[0],
|
||||||
@ -248,7 +249,7 @@ impl HwDecoderImage<'_> {
|
|||||||
),
|
),
|
||||||
AVPixelFormat::AV_PIX_FMT_YUV420P => {
|
AVPixelFormat::AV_PIX_FMT_YUV420P => {
|
||||||
hw::hw_i420_to(
|
hw::hw_i420_to(
|
||||||
rgb.fmt,
|
rgb.fmt(),
|
||||||
frame.width as _,
|
frame.width as _,
|
||||||
frame.height as _,
|
frame.height as _,
|
||||||
&frame.data[0],
|
&frame.data[0],
|
||||||
|
@ -50,9 +50,10 @@ impl MediaCodecDecoder {
|
|||||||
MediaCodecDecoders { h264, h265 }
|
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> {
|
pub fn decode(&mut self, data: &[u8], rgb: &mut ImageRgb) -> ResultType<bool> {
|
||||||
// take dst_stride into account please
|
// 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))? {
|
match self.dequeue_input_buffer(Duration::from_millis(10))? {
|
||||||
Some(mut input_buffer) => {
|
Some(mut input_buffer) => {
|
||||||
let mut buf = input_buffer.buffer_mut();
|
let mut buf = input_buffer.buffer_mut();
|
||||||
@ -90,7 +91,7 @@ impl MediaCodecDecoder {
|
|||||||
let u_ptr = buf[u..].as_ptr();
|
let u_ptr = buf[u..].as_ptr();
|
||||||
let v_ptr = buf[v..].as_ptr();
|
let v_ptr = buf[v..].as_ptr();
|
||||||
unsafe {
|
unsafe {
|
||||||
match rgb.fmt {
|
match rgb.fmt() {
|
||||||
ImageFormat::ARGB => {
|
ImageFormat::ARGB => {
|
||||||
I420ToARGB(
|
I420ToARGB(
|
||||||
y_ptr,
|
y_ptr,
|
||||||
|
@ -53,22 +53,32 @@ pub enum ImageFormat {
|
|||||||
|
|
||||||
pub struct ImageRgb {
|
pub struct ImageRgb {
|
||||||
pub raw: Vec<u8>,
|
pub raw: Vec<u8>,
|
||||||
pub fmt: ImageFormat,
|
|
||||||
pub w: usize,
|
pub w: usize,
|
||||||
pub h: usize,
|
pub h: usize,
|
||||||
pub stride: usize,
|
fmt: ImageFormat,
|
||||||
|
stride: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ImageRgb {
|
impl ImageRgb {
|
||||||
pub fn new(fmt: ImageFormat, stride: usize) -> Self {
|
pub fn new(fmt: ImageFormat, stride: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
raw: Vec::new(),
|
raw: Vec::new(),
|
||||||
fmt,
|
|
||||||
w: 0,
|
w: 0,
|
||||||
h: 0,
|
h: 0,
|
||||||
|
fmt,
|
||||||
stride,
|
stride,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn fmt(&self) -> ImageFormat {
|
||||||
|
self.fmt
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn stride(&self) -> usize {
|
||||||
|
self.stride
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -536,11 +536,11 @@ impl Image {
|
|||||||
pub fn to(&self, rgb: &mut ImageRgb) {
|
pub fn to(&self, rgb: &mut ImageRgb) {
|
||||||
rgb.w = self.width();
|
rgb.w = self.width();
|
||||||
rgb.h = self.height();
|
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);
|
rgb.raw.resize(rgb.h * bytes_per_row, 0);
|
||||||
let img = self.inner();
|
let img = self.inner();
|
||||||
unsafe {
|
unsafe {
|
||||||
match rgb.fmt {
|
match rgb.fmt() {
|
||||||
ImageFormat::Raw => {
|
ImageFormat::Raw => {
|
||||||
super::I420ToRAW(
|
super::I420ToRAW(
|
||||||
img.planes[0],
|
img.planes[0],
|
||||||
|
@ -242,7 +242,7 @@ impl VideoRenderer {
|
|||||||
rgba.raw.len() as _,
|
rgba.raw.len() as _,
|
||||||
rgba.w as _,
|
rgba.w as _,
|
||||||
rgba.h as _,
|
rgba.h as _,
|
||||||
rgba.stride as _,
|
rgba.stride() as _,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user