Skip to content

Commit

Permalink
improve vaapi init failure error message
Browse files Browse the repository at this point in the history
  • Loading branch information
russelltg committed Oct 8, 2023
1 parent 63d3586 commit 22fe51c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/avhw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct AvHwDevCtx {
}

impl AvHwDevCtx {
pub fn new_libva(dri_device: &str) -> Self {
pub fn new_libva(dri_device: &str) -> Result<Self, ffmpeg::Error> {
unsafe {
let mut hw_device_ctx = null_mut();

Expand All @@ -31,9 +31,12 @@ impl AvHwDevCtx {
opts.as_mut_ptr(),
0,
);
assert_eq!(sts, 0, "failed to open {dri_device}");

Self { ptr: hw_device_ctx }
if sts != 0 {
Err(ffmpeg::Error::from(sts))
} else {
Ok(Self { ptr: hw_device_ctx })
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,10 @@ impl EncState {

eprintln!("Opening libva device from DRM device {dri_device}");

let mut hw_device_ctx = AvHwDevCtx::new_libva(dri_device);
let mut hw_device_ctx = match AvHwDevCtx::new_libva(dri_device) {
Ok(hdc) => hdc,
Err(e) => bail!("Failed to load vaapi device: {e}\nThis is likely *not* a bug in wl-screenrec, but an issue with your vaapi installation. Follow your distribution's instructions. If you're pretty sure you've done this correctly, create a new issue with the output of `vainfo` and if `wf-recorder -c h264_vaapi -d /dev/dri/card0` works."),
};
let mut frames_rgb = hw_device_ctx
.create_frame_ctx(capture_pixfmt, capture_w, capture_h)
.unwrap();
Expand Down

0 comments on commit 22fe51c

Please sign in to comment.