Skip to content

Commit

Permalink
open the correct vulkan device
Browse files Browse the repository at this point in the history
  • Loading branch information
russelltg committed Nov 13, 2024
1 parent 31b2dfa commit 94bd749
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
24 changes: 19 additions & 5 deletions src/avhw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use ffmpeg::{
format::Pixel,
frame,
};
use ffmpeg_sys_next::AVVulkanFramesContext;
use ffmpeg_sys_next::{av_hwdevice_ctx_create_derived, AVVulkanFramesContext};

use crate::DrmModifier;

Expand Down Expand Up @@ -48,18 +48,32 @@ impl AvHwDevCtx {
}
}

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

let dev_cstr = CString::new(dri_device).unwrap();
let dev_cstr = CString::new(dri_device.to_str().unwrap()).unwrap();

let sts = av_hwdevice_ctx_create(
&mut hw_device_ctx,
ffmpeg_next::ffi::AVHWDeviceType::AV_HWDEVICE_TYPE_VULKAN,
&mut hw_device_ctx_drm,
ffmpeg_sys_next::AVHWDeviceType::AV_HWDEVICE_TYPE_DRM,
dev_cstr.as_ptr(),
null_mut(),
0,
);
if sts != 0 {
return Err(ffmpeg::Error::from(sts));
}

let sts = av_hwdevice_ctx_create_derived(
&mut hw_device_ctx,
ffmpeg_next::ffi::AVHWDeviceType::AV_HWDEVICE_TYPE_VULKAN,
hw_device_ctx_drm,
0,
);

av_buffer_unref(&mut hw_device_ctx_drm);

if sts != 0 {
Err(ffmpeg::Error::from(sts))
Expand Down
4 changes: 1 addition & 3 deletions src/cap_wlr_screencopy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ use wayland_protocols_wlr::screencopy::v1::client::{
zwlr_screencopy_manager_v1::ZwlrScreencopyManagerV1,
};

use crate::{
CaptureSource, DmabufFormat, DrmModifier, ReadyCopySource, State
};
use crate::{CaptureSource, DmabufFormat, DrmModifier, ReadyCopySource, State};

impl Dispatch<ZwlrScreencopyManagerV1, ()> for State<CapWlrScreencopy> {
fn event(
Expand Down
7 changes: 2 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1538,9 +1538,8 @@ impl EncState {

#[allow(unreachable_code)]
{
info!("Opening vulkan device 0");
error!("TODO: get correct vulkan device");
AvHwDevCtx::new_vulkan("0")
info!("Opening vulkan device from {}", dri_device.display());
AvHwDevCtx::new_vulkan(dri_device)
.map_err(|e| anyhow!("Failed to open vulkan device: {e}"))?
}
} else {
Expand Down Expand Up @@ -1930,7 +1929,6 @@ fn video_filter(
assert_eq!(sts, 0);
}


// sink
g.add(
&filter::find("buffersink").unwrap(),
Expand All @@ -1946,7 +1944,6 @@ fn video_filter(
)
.unwrap();


let output_real_pixfmt_name = unsafe {
from_utf8_unchecked(
CStr::from_ptr(av_get_pix_fmt_name(
Expand Down

0 comments on commit 94bd749

Please sign in to comment.