Skip to content

Commit

Permalink
fix(pipeline): handle image-orientation tag from pipewire
Browse files Browse the repository at this point in the history
This is done automatically via videoflip element.

Closes #284
  • Loading branch information
SeaDve committed Mar 6, 2024
1 parent 7b690a8 commit 68916f1
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ fn make_pipewiresrc(fd: RawFd, path: &str) -> Result<gst::Element> {
Ok(src)
}

fn make_videoflip() -> Result<gst::Element> {
let videoflip = gst::ElementFactory::make("videoflip")
.property_from_str("video-direction", "auto")
.build()?;

Ok(videoflip)
}

/// Create a videocrop element that computes the crop from the given coordinates
/// and size.
fn make_videocrop(data: &SelectAreaData) -> Result<gst::Element> {
Expand Down Expand Up @@ -242,15 +250,15 @@ fn make_videocrop(data: &SelectAreaData) -> Result<gst::Element> {
///
/// Single stream:
///
/// pipewiresrc -> videorate
/// pipewiresrc -> videoflip -> videorate
///
/// Multiple streams:
///
/// pipewiresrc1 -> |
/// |
/// pipewiresrc2 -> | -> compositor -> videorate
/// |
/// pipewiresrcn -> |
/// pipewiresrc1 -> videoflip -> |
/// |
/// pipewiresrc2 -> videoflip -> | -> compositor -> videorate
/// |
/// pipewiresrcn -> videoflip -> |
pub fn make_pipewiresrc_bin(
fd: RawFd,
streams: &[Stream],
Expand All @@ -276,8 +284,9 @@ pub fn make_pipewiresrc_bin(
[] => bail!("No streams provided"),
[stream] => {
let pipewiresrc = make_pipewiresrc(fd, &stream.node_id().to_string())?;
bin.add(&pipewiresrc)?;
pipewiresrc.link(&videorate)?;
let videoflip = make_videoflip()?;
bin.add_many([&pipewiresrc, &videoflip])?;
gst::Element::link_many([&pipewiresrc, &videoflip, &videorate])?;
}
streams => {
let compositor = gst::ElementFactory::make("compositor").build()?;
Expand All @@ -287,13 +296,15 @@ pub fn make_pipewiresrc_bin(
let mut last_pos = 0;
for stream in streams {
let pipewiresrc = make_pipewiresrc(fd, &stream.node_id().to_string())?;
bin.add(&pipewiresrc)?;
let videoflip = make_videoflip()?;
bin.add_many([&pipewiresrc, &videoflip])?;
pipewiresrc.link(&videoflip)?;

let compositor_sink_pad = compositor
.request_pad_simple("sink_%u")
.context("Failed to request sink_%u pad from compositor")?;
compositor_sink_pad.set_property("xpos", last_pos);
pipewiresrc
videoflip
.static_pad("src")
.unwrap()
.link(&compositor_sink_pad)?;
Expand Down

0 comments on commit 68916f1

Please sign in to comment.