Skip to content

fix: Add handling for missing VideoFormat on Linux #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

meocoder31099
Copy link

I am using COSMIC DE, which uses VideoFormat::RGBA instead of VideoFormat::BGRx like GNOME or KDE, so it leads to a panic "Unsupported frame format received".

In the current code, VideoFormat::RGBA is included in the list of output formats for the buffer

pw::spa::pod::property!(
FormatProperties::VideoFormat,
Choice,
Enum,
Id,
pw::spa::param::video::VideoFormat::RGB,
pw::spa::param::video::VideoFormat::RGBA,
pw::spa::param::video::VideoFormat::RGBx,
pw::spa::param::video::VideoFormat::BGRx,
),

but the case where VideoFormat is VideoFormat::RGBA is not handled
if let Err(e) = match user_data.format.format() {
VideoFormat::RGBx => user_data.tx.send(Frame::RGBx(RGBxFrame {
display_time: timestamp as u64,
width: frame_size.width as i32,
height: frame_size.height as i32,
data: frame_data,
})),
VideoFormat::RGB => user_data.tx.send(Frame::RGB(RGBFrame {
display_time: timestamp as u64,
width: frame_size.width as i32,
height: frame_size.height as i32,
data: frame_data,
})),
VideoFormat::xBGR => user_data.tx.send(Frame::XBGR(XBGRFrame {
display_time: timestamp as u64,
width: frame_size.width as i32,
height: frame_size.height as i32,
data: frame_data,
})),
VideoFormat::BGRx => user_data.tx.send(Frame::BGRx(BGRxFrame {
display_time: timestamp as u64,
width: frame_size.width as i32,
height: frame_size.height as i32,
data: frame_data,
})),
_ => panic!("Unsupported frame format received"),
} {
eprintln!("{e}");
}

This PR will fix it.

@meocoder31099 meocoder31099 changed the title fix: Add handling for missing VideoFormat fix: Add handling for missing VideoFormat on Linux Mar 13, 2025
let offset = unsafe { (*(*(*buffer).datas).chunk).offset as u64 };
let raw_fd = unsafe { (*(*buffer).datas).fd as RawFd };
let mmap_ptr = unsafe {
mmap(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not safe for dmabuf, see the "DMA-BUF Mapping Warning" section in the PipeWire docs.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issues with tiling and compression can be addressed by requesting PipeWire to provide a linear modifier for the DMA-BUF. Synchronization is also handled by invoking the DMA_BUF_IOCTL_SYNC ioctl before and after any CPU access to the buffer. However, the problem of accessing the DMA-BUF being extremely slow remains unresolved as I am not familiar with the graphics APIs necessary to handle this efficiently.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced this is the way to go about handling dmabufs for two reasons:

  1. The current implementation should work (there may be bugs causing it to not work + the missing handling of RGBA and MemFd that you kindly fixed in this PR) because the video source node should never give dmabufs when no modifiers is set. The only portal implementation I've tested with that doesn't respect this was cosmic's. Our param_changed callback might not handle params correctly, I'll take a look at it.
  2. scap's frame types only store data in Vec<u8>, so any dmabuf handling would basically just do the same that the portal would do for SHM.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are absolutely correct. My current implementation will work if you are using COSMIC DE, but it will not guarantee working in all cases due to factors beyond our control (notably, if the portal does not respect the requested parameters from scap)

@meocoder31099 meocoder31099 marked this pull request as draft March 24, 2025 15:18
@meocoder31099 meocoder31099 marked this pull request as ready for review April 16, 2025 03:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants