Merge pull request #2629 from toriato/downgrade-gstreamer

downgrade gstreamer to 0.16
This commit is contained in:
RustDesk 2022-12-22 21:23:22 +08:00 committed by GitHub
commit 9514dc610f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 11 deletions

View File

@ -50,6 +50,12 @@ impl TraitCapturer for Capturer {
} else {
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()),
_ => Err(map_err("Invalid data")),
}

View File

@ -4,6 +4,7 @@ use std::error::Error;
pub enum PixelProvider<'a> {
// 8 bits per color
RGB(usize, usize, &'a [u8]),
RGB0(usize, usize, &'a [u8]),
BGR0(usize, usize, &'a [u8]),
// width, height, stride
BGR0S(usize, usize, usize, &'a [u8]),
@ -14,6 +15,7 @@ impl<'a> PixelProvider<'a> {
pub fn size(&self) -> (usize, usize) {
match self {
PixelProvider::RGB(w, h, _) => (*w, *h),
PixelProvider::RGB0(w, h, _) => (*w, *h),
PixelProvider::BGR0(w, h, _) => (*w, *h),
PixelProvider::BGR0S(w, h, _, _) => (*w, *h),
PixelProvider::NONE => (0, 0),

View File

@ -117,6 +117,7 @@ impl Capturable for PipeWireCapturable {
pub struct PipeWireRecorder {
buffer: Option<gst::MappedBuffer<gst::buffer::Readable>>,
buffer_cropped: Vec<u8>,
pix_fmt: String,
is_cropped: bool,
pipeline: gst::Pipeline,
appsink: AppSink,
@ -144,19 +145,27 @@ impl PipeWireRecorder {
pipeline.add_many(&[&src, &sink])?;
src.link(&sink)?;
let appsink = sink
.dynamic_cast::<AppSink>()
.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",
&[("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)?;
Ok(Self {
pipeline,
appsink,
buffer: None,
pix_fmt: "".into(),
width: 0,
height: 0,
buffer_cropped: vec![],
@ -181,6 +190,11 @@ impl Recorder for PipeWireRecorder {
let h: i32 = cap.get_value("height")?.get_some()?;
let w = w as usize;
let h = h as usize;
self.pix_fmt = cap
.get::<&str>("format")?
.ok_or("Failed to get pixel format")?
.to_string();
let buf = sample
.get_buffer_owned()
.ok_or_else(|| GStreamerError("Failed to get owned buffer.".into()))?;
@ -241,15 +255,22 @@ impl Recorder for PipeWireRecorder {
if self.buffer.is_none() {
return Err(Box::new(GStreamerError("No buffer available!".into())));
}
Ok(PixelProvider::BGR0(
self.width,
self.height,
if self.is_cropped {
self.buffer_cropped.as_slice()
} else {
self.buffer.as_ref().unwrap().as_slice()
},
))
let buf = if self.is_cropped {
self.buffer_cropped.as_slice()
} else {
self.buffer
.as_ref()
.ok_or("Failed to get buffer as ref")?
.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)),
_ => Err(Box::new(GStreamerError(format!(
"Unreachable! Unknown pix_fmt, {}",
&self.pix_fmt
)))),
}
}
}