-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New architecture for vk-video initialization.
This change allows users to initialize `vk-video` with wgpu surfaces for rendering to an on-screen window. This was previously overlooked and there was no possibility to guarantee a `VulkanCtx` was able to render on screen. This patch also adds an example h264 player to vk-video.
- Loading branch information
1 parent
505fc07
commit ee1982c
Showing
25 changed files
with
1,752 additions
and
250 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#[cfg(vulkan)] | ||
mod player; | ||
|
||
#[cfg(vulkan)] | ||
fn main() { | ||
player::run() | ||
} | ||
|
||
#[cfg(not(vulkan))] | ||
fn main() { | ||
println!( | ||
"This crate doesn't work on your operating system, because it does not support vulkan" | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use std::{path::PathBuf, sync::mpsc, time::Duration}; | ||
|
||
use clap::Parser; | ||
use vk_video::VulkanInstance; | ||
use winit::{event_loop::EventLoop, window::WindowBuilder}; | ||
|
||
mod decoder; | ||
mod renderer; | ||
|
||
const FRAMES_BUFFER_LEN: usize = 20; | ||
|
||
#[derive(Parser)] | ||
#[command(version, about, long_about=None)] | ||
struct Args { | ||
/// an .h264 file to play | ||
filename: PathBuf, | ||
|
||
/// framerate to play the video at | ||
framerate: u64, | ||
} | ||
|
||
struct FrameWithPts { | ||
frame: wgpu::Texture, | ||
/// Presentation timestamp | ||
pts: Duration, | ||
} | ||
|
||
pub fn run() { | ||
let args = Args::parse(); | ||
let subscriber = tracing_subscriber::fmt() | ||
.with_max_level(tracing::Level::INFO) | ||
.finish(); | ||
|
||
tracing::subscriber::set_global_default(subscriber).unwrap(); | ||
|
||
let file = std::fs::File::open(&args.filename).expect("open file"); | ||
|
||
let event_loop = EventLoop::new().unwrap(); | ||
let window = WindowBuilder::new().build(&event_loop).unwrap(); | ||
|
||
let vulkan_instance = VulkanInstance::new().unwrap(); | ||
|
||
let mut surface = vulkan_instance | ||
.wgpu_instance | ||
.create_surface(&window) | ||
.unwrap(); | ||
|
||
let vulkan_device = vulkan_instance | ||
.create_device( | ||
wgpu::Features::empty(), | ||
wgpu::Limits::default(), | ||
&mut Some(&mut surface), | ||
) | ||
.unwrap(); | ||
|
||
let (tx, rx) = mpsc::sync_channel(FRAMES_BUFFER_LEN); | ||
let vulkan_device_clone = vulkan_device.clone(); | ||
|
||
std::thread::spawn(move || { | ||
decoder::run_decoder(tx, args.framerate, vulkan_device_clone, file); | ||
}); | ||
|
||
renderer::run_renderer(event_loop, &window, surface, &vulkan_device, rx); | ||
} |
Oops, something went wrong.