mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-01-18 15:53:00 +08:00
implement RGB0 #2608
This commit is contained in:
parent
d910e7ad96
commit
38f66df091
@ -50,6 +50,12 @@ impl TraitCapturer for Capturer {
|
|||||||
} else {
|
} else {
|
||||||
x
|
x
|
||||||
})),
|
})),
|
||||||
|
PixelProvider::RGB0(w, h, x) => Ok(Frame(if self.2 {
|
||||||
|
crate::common::rgba_to_i420(w as _, h as _, &x, &mut self.3);
|
||||||
|
&self.3[..]
|
||||||
|
} else {
|
||||||
|
x
|
||||||
|
})),
|
||||||
PixelProvider::NONE => Err(std::io::ErrorKind::WouldBlock.into()),
|
PixelProvider::NONE => Err(std::io::ErrorKind::WouldBlock.into()),
|
||||||
_ => Err(map_err("Invalid data")),
|
_ => Err(map_err("Invalid data")),
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ use std::error::Error;
|
|||||||
pub enum PixelProvider<'a> {
|
pub enum PixelProvider<'a> {
|
||||||
// 8 bits per color
|
// 8 bits per color
|
||||||
RGB(usize, usize, &'a [u8]),
|
RGB(usize, usize, &'a [u8]),
|
||||||
|
RGB0(usize, usize, &'a [u8]),
|
||||||
BGR0(usize, usize, &'a [u8]),
|
BGR0(usize, usize, &'a [u8]),
|
||||||
// width, height, stride
|
// width, height, stride
|
||||||
BGR0S(usize, usize, usize, &'a [u8]),
|
BGR0S(usize, usize, usize, &'a [u8]),
|
||||||
@ -14,6 +15,7 @@ impl<'a> PixelProvider<'a> {
|
|||||||
pub fn size(&self) -> (usize, usize) {
|
pub fn size(&self) -> (usize, usize) {
|
||||||
match self {
|
match self {
|
||||||
PixelProvider::RGB(w, h, _) => (*w, *h),
|
PixelProvider::RGB(w, h, _) => (*w, *h),
|
||||||
|
PixelProvider::RGB0(w, h, _) => (*w, *h),
|
||||||
PixelProvider::BGR0(w, h, _) => (*w, *h),
|
PixelProvider::BGR0(w, h, _) => (*w, *h),
|
||||||
PixelProvider::BGR0S(w, h, _, _) => (*w, *h),
|
PixelProvider::BGR0S(w, h, _, _) => (*w, *h),
|
||||||
PixelProvider::NONE => (0, 0),
|
PixelProvider::NONE => (0, 0),
|
||||||
|
@ -117,6 +117,7 @@ impl Capturable for PipeWireCapturable {
|
|||||||
pub struct PipeWireRecorder {
|
pub struct PipeWireRecorder {
|
||||||
buffer: Option<gst::MappedBuffer<gst::buffer::Readable>>,
|
buffer: Option<gst::MappedBuffer<gst::buffer::Readable>>,
|
||||||
buffer_cropped: Vec<u8>,
|
buffer_cropped: Vec<u8>,
|
||||||
|
pix_fmt: String,
|
||||||
is_cropped: bool,
|
is_cropped: bool,
|
||||||
pipeline: gst::Pipeline,
|
pipeline: gst::Pipeline,
|
||||||
appsink: AppSink,
|
appsink: AppSink,
|
||||||
@ -144,19 +145,27 @@ impl PipeWireRecorder {
|
|||||||
|
|
||||||
pipeline.add_many(&[&src, &sink])?;
|
pipeline.add_many(&[&src, &sink])?;
|
||||||
src.link(&sink)?;
|
src.link(&sink)?;
|
||||||
|
|
||||||
let appsink = sink
|
let appsink = sink
|
||||||
.dynamic_cast::<AppSink>()
|
.dynamic_cast::<AppSink>()
|
||||||
.map_err(|_| GStreamerError("Sink element is expected to be an appsink!".into()))?;
|
.map_err(|_| GStreamerError("Sink element is expected to be an appsink!".into()))?;
|
||||||
appsink.set_caps(Some(&gst::Caps::new_simple(
|
let mut caps = gst::Caps::new_empty();
|
||||||
|
caps.merge_structure(gst::structure::Structure::new(
|
||||||
"video/x-raw",
|
"video/x-raw",
|
||||||
&[("format", &"BGRx")],
|
&[("format", &"BGRx")],
|
||||||
)));
|
));
|
||||||
|
caps.merge_structure(gst::structure::Structure::new(
|
||||||
|
"video/x-raw",
|
||||||
|
&[("format", &"RGBx")],
|
||||||
|
));
|
||||||
|
appsink.set_caps(Some(&caps));
|
||||||
|
|
||||||
pipeline.set_state(gst::State::Playing)?;
|
pipeline.set_state(gst::State::Playing)?;
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
pipeline,
|
pipeline,
|
||||||
appsink,
|
appsink,
|
||||||
buffer: None,
|
buffer: None,
|
||||||
|
pix_fmt: "".into(),
|
||||||
width: 0,
|
width: 0,
|
||||||
height: 0,
|
height: 0,
|
||||||
buffer_cropped: vec![],
|
buffer_cropped: vec![],
|
||||||
@ -179,6 +188,7 @@ impl Recorder for PipeWireRecorder {
|
|||||||
.ok_or("Failed to get structure")?;
|
.ok_or("Failed to get structure")?;
|
||||||
let w: i32 = cap.value("width")?.get()?;
|
let w: i32 = cap.value("width")?.get()?;
|
||||||
let h: i32 = cap.value("height")?.get()?;
|
let h: i32 = cap.value("height")?.get()?;
|
||||||
|
self.pix_fmt = cap.value("format")?.get()?;
|
||||||
let w = w as usize;
|
let w = w as usize;
|
||||||
let h = h as usize;
|
let h = h as usize;
|
||||||
let buf = sample
|
let buf = sample
|
||||||
@ -241,15 +251,16 @@ impl Recorder for PipeWireRecorder {
|
|||||||
if self.buffer.is_none() {
|
if self.buffer.is_none() {
|
||||||
return Err(Box::new(GStreamerError("No buffer available!".into())));
|
return Err(Box::new(GStreamerError("No buffer available!".into())));
|
||||||
}
|
}
|
||||||
Ok(PixelProvider::BGR0(
|
let buf = if self.is_cropped {
|
||||||
self.width,
|
|
||||||
self.height,
|
|
||||||
if self.is_cropped {
|
|
||||||
self.buffer_cropped.as_slice()
|
self.buffer_cropped.as_slice()
|
||||||
} else {
|
} else {
|
||||||
self.buffer.as_ref().unwrap().as_slice()
|
self.buffer.as_ref().unwrap().as_slice()
|
||||||
},
|
};
|
||||||
))
|
match self.pix_fmt.as_str() {
|
||||||
|
"BGRx" => Ok(PixelProvider::BGR0(self.width, self.height, buf)),
|
||||||
|
"RGBx" => Ok(PixelProvider::RGB0(self.width, self.height, buf)),
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user