From 188b4ed521a40d402ad5710aaabf95c435549935 Mon Sep 17 00:00:00 2001 From: Sludge <96552222+SludgePhD@users.noreply.github.com> Date: Sat, 17 Jun 2023 21:36:06 +0200 Subject: [PATCH] publish notice --- Cargo.toml | 2 +- examples/infodump.rs | 152 ------------------------- examples/jpeg-decode.rs | 133 ---------------------- examples/vainfo.rs | 44 -------- src/lib.rs | 239 +--------------------------------------- 5 files changed, 3 insertions(+), 567 deletions(-) delete mode 100644 examples/infodump.rs delete mode 100644 examples/jpeg-decode.rs delete mode 100644 examples/vainfo.rs diff --git a/Cargo.toml b/Cargo.toml index 7f3e068..d80bbb6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "v-ayylmao" -version = "0.0.4" +version = "0.0.5" edition = "2021" license = "0BSD" description = "High-level VA-API bindings" diff --git a/examples/infodump.rs b/examples/infodump.rs deleted file mode 100644 index cd9d15c..0000000 --- a/examples/infodump.rs +++ /dev/null @@ -1,152 +0,0 @@ -use std::error::Error; - -use v_ayylmao::{ - config::{Config, ConfigAttribType}, - context::Context, - display::Display, - surface::RTFormat, - vpp::Filters, - Entrypoint, Profile, -}; -use winit::event_loop::EventLoop; - -fn main() -> Result<(), Box> { - env_logger::builder() - .filter_module(env!("CARGO_PKG_NAME"), log::LevelFilter::Trace) - .init(); - - let ev = EventLoop::new(); - - // Safety: `ev` is dropped after the `display` and all derived resources are dropped. - // FIXME: use the safe API once winit implements `HasRawDisplayHandle` for `EventLoop`. - let display = unsafe { Display::new_unmanaged(&*ev)? }; - println!( - "API Version: {}.{}", - display.version_major(), - display.version_minor() - ); - println!("Display API: {:?}", display.display_api()); - println!("Vendor string: {}", display.query_vendor_string()?); - - let profiles = display.query_profiles()?; - println!("Supported Profiles:"); - for profile in profiles { - println!("- {:?}", profile); - for entrypoint in display.query_entrypoints(profile)? { - println!(" - Entrypoint {:?}", entrypoint); - - let config = Config::new(&display, profile, entrypoint)?; - let attribs = config.query_config_attributes()?; - println!(" {} config attributes", attribs.len()); - for attrib in attribs { - print!(" - {:?} ", attrib.attrib_type()); - - if attrib.attrib_type() == ConfigAttribType::RTFormat { - println!("{:?}", RTFormat::from_bits_truncate(attrib.raw_value())); - } else { - println!("{:08x}", attrib.raw_value()); - } - } - let attribs = match config.query_surface_attributes() { - Ok(attribs) => attribs, - Err(e) => { - println!(" Could not query surface attributes: {e}"); - continue; - } - }; - println!(" {} surface attributes", attribs.len()); - for attrib in attribs { - print!(" - {:?} ", attrib.ty()); - if attrib.flags().is_empty() { - print!("(not supported)"); - } else { - print!("{:?}", attrib.flags()); - if let Some(value) = attrib.as_enum() { - print!(" {:?}", value); - } else { - print!(" {:?}", attrib.raw_value()); - } - } - println!(); - } - } - } - - let formats = display.query_image_formats()?; - println!("{} supported image formats", formats.len()); - for format in formats { - println!( - "- {} {:?}, {} bpp, depth={}, Rm={:#010x}, Gm={:#010x}, Bm={:#010x}, Am={:#010x}", - format.pixel_format(), - format.byte_order(), - format.bits_per_pixel(), - format.depth(), - format.red_mask(), - format.green_mask(), - format.blue_mask(), - format.alpha_mask(), - ); - } - - let formats = display.query_subpicture_format()?; - println!("{} supported subpicture formats", formats.len()); - for format in formats { - let img = format.image_format(); - println!( - "- {} {:?}, {} bpp, depth={}, Rm={:#010x}, Gm={:#010x}, Bm={:#010x}, Am={:#010x}", - img.pixel_format(), - img.byte_order(), - img.bits_per_pixel(), - img.depth(), - img.red_mask(), - img.green_mask(), - img.blue_mask(), - img.alpha_mask(), - ); - println!(" Flags: {:?}", format.flags()); - } - - let display_attributes = display.query_display_attributes()?; - println!("{} supported display attributes", display_attributes.len()); - for attrib in display_attributes { - println!( - "- {:?} {:?} [{}-{}] ({})", - attrib.ty(), - attrib.flags(), - attrib.min_value(), - attrib.max_value(), - attrib.value(), - ); - } - - if display.query_profiles()?.contains(Profile::None) - && display - .query_entrypoints(Profile::None)? - .contains(Entrypoint::VideoProc) - { - let config = Config::new(&display, Profile::None, Entrypoint::VideoProc)?; - let context = Context::new(&config, 512, 512)?; - let proc_filters = context.query_video_processing_filters()?; - println!("{} supported video processing filters", proc_filters.len()); - for filter in proc_filters { - println!("- {:?}", filter); - } - - let caps = context.query_video_processing_pipeline_caps(&mut Filters::new())?; - println!("Empty pipeline capabilities:"); - println!("- Pipeline Flags: {:?}", caps.pipeline_flags()); - println!("- Filter Flags: {:?}", caps.filter_flags()); - println!( - "- Input Color Standards: {:?}", - caps.input_color_standards() - ); - println!( - "- Output Color Standards: {:?}", - caps.output_color_standards() - ); - println!("- Input Pixel Formats: {:?}", caps.input_pixel_formats()); - println!("- Output Pixel Formats: {:?}", caps.output_pixel_formats()); - } - - Ok(()) -} diff --git a/examples/jpeg-decode.rs b/examples/jpeg-decode.rs deleted file mode 100644 index 6281f7e..0000000 --- a/examples/jpeg-decode.rs +++ /dev/null @@ -1,133 +0,0 @@ -use std::{rc::Rc, time::Instant}; - -use anyhow::bail; -use softbuffer::GraphicsContext; -use v_ayylmao::{ - display::Display, - jpeg::{JpegDecodeSession, JpegInfo}, -}; -use winit::{ - dpi::PhysicalSize, - event::{ElementState, Event, KeyboardInput, MouseButton, VirtualKeyCode, WindowEvent}, - event_loop::{ControlFlow, EventLoop}, - window::WindowBuilder, -}; - -fn main() -> anyhow::Result<()> { - env_logger::builder() - .filter_module( - &env!("CARGO_PKG_NAME").replace('-', "_"), - log::LevelFilter::Trace, - ) - .filter_module(env!("CARGO_CRATE_NAME"), log::LevelFilter::Trace) - .init(); - - let jpeg = match std::env::args_os().skip(1).next() { - Some(file) => std::fs::read(file)?, - None => bail!("usage: jpeg-decode "), - }; - let mut read = &*jpeg; - let mut dec = jpeg_decoder::Decoder::new(&mut read); - let start = Instant::now(); - let control_data = dec.decode()?; - log::info!("jpeg-decoder took {:?}", start.elapsed()); - let control_data = control_data - .chunks(3) - .map(|pix| { - let [r, g, b] = [pix[0], pix[1], pix[2]].map(u32::from); - r << 16 | g << 8 | b - }) - .collect::>(); - let info = dec.info().unwrap(); - log::info!("image size: {}x{}", info.width, info.height); - - let ev = EventLoop::new(); - let win = WindowBuilder::new() - .with_inner_size(PhysicalSize::new(info.width, info.height)) - .with_resizable(false) - .build(&ev)?; - let win = Rc::new(win); - - let mut graphics_context = unsafe { GraphicsContext::new(&win, &win) }.unwrap(); - - let display = Display::new(win.clone())?; - - let jpeg_info = JpegInfo::new(&jpeg)?; - let mut context = JpegDecodeSession::new(&display, jpeg_info.width(), jpeg_info.height())?; - for _ in 0..20 { - let mapping = context.decode(&jpeg)?; - let start = Instant::now(); - let _data = mapping.to_vec(); - log::trace!("copy from VABuffer took {:?}", start.elapsed()); - } - let mapping = context.decode(&jpeg)?; - - log::debug!("{} byte output", mapping.len()); - - let start = Instant::now(); - let data = mapping.to_vec(); - log::trace!("copy from VABuffer took {:?}", start.elapsed()); - let start = Instant::now(); - let data = data.to_vec(); - log::trace!("vec copy took {:?}", start.elapsed()); - - let start = Instant::now(); - let decoded_data: Vec<_> = data - .chunks(4) - .take(jpeg_info.width() as usize * jpeg_info.height() as usize) // ignore trailing padding bytes - .map(|pix| { - let [r, g, b, _a] = [pix[0], pix[1], pix[2], pix[3]].map(u32::from); - r << 16 | g << 8 | b - }) - .collect(); - log::trace!("conversion took {:?}", start.elapsed()); - - let mut show_control_data = false; - ev.run(move |event, _tgt, control_flow| { - *control_flow = ControlFlow::Wait; - - match event { - Event::RedrawRequested(_) => { - let (width, height) = { - let size = win.inner_size(); - (size.width, size.height) - }; - let data = if show_control_data { - &control_data - } else { - &decoded_data - }; - graphics_context.set_buffer(data, width as u16, height as u16); - win.set_title(&format!("control={}", show_control_data)); - } - Event::WindowEvent { - event: WindowEvent::CloseRequested, - .. - } => { - *control_flow = ControlFlow::Exit; - } - Event::WindowEvent { - event: - WindowEvent::KeyboardInput { - input: - KeyboardInput { - virtual_keycode: Some(VirtualKeyCode::Space), - state: ElementState::Pressed, - .. - }, - .. - } - | WindowEvent::MouseInput { - state: ElementState::Pressed, - button: MouseButton::Left, - .. - }, - .. - } => { - show_control_data = !show_control_data; - win.request_redraw(); - } - _ => {} - } - }) -} diff --git a/examples/vainfo.rs b/examples/vainfo.rs deleted file mode 100644 index bdb5b6d..0000000 --- a/examples/vainfo.rs +++ /dev/null @@ -1,44 +0,0 @@ -use std::error::Error; - -use v_ayylmao::display::Display; -use winit::event_loop::EventLoop; - -fn main() -> Result<(), Box> { - env_logger::builder() - .filter_module(env!("CARGO_PKG_NAME"), log::LevelFilter::Trace) - .init(); - - let ev = EventLoop::new(); - - // Safety: `ev` is dropped after the `display` and all derived resources are dropped. - // FIXME: use the safe API once winit implements `HasRawDisplayHandle` for `EventLoop`. - let display = unsafe { Display::new_unmanaged(&*ev)? }; - println!( - "API Version: {}.{}", - display.version_major(), - display.version_minor() - ); - println!("Display API: {:?}", display.display_api()); - println!("Vendor string: {}", display.query_vendor_string()?); - - let profiles = display.query_profiles()?; - let width = profiles - .clone() - .into_iter() - .map(|prof| format!("{:?}", prof).len()) - .max(); - - println!("Supported Profiles:"); - for profile in profiles { - print!("{:>1$?}: ", profile, width.unwrap()); - for (i, entrypoint) in display.query_entrypoints(profile)?.into_iter().enumerate() { - if i != 0 { - print!(" + "); - } - print!("{:?}", entrypoint); - } - println!(); - } - - Ok(()) -} diff --git a/src/lib.rs b/src/lib.rs index f665aab..0ad07ae 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,238 +1,3 @@ -//! VA-API bindings. +//! This crate has been renamed to [`fev`]. //! -//! See [`Display`][display::Display] for the main entry point into the library. - -#[macro_use] -mod macros; -mod dlopen; -mod pixelformat; -mod raw; - -pub mod buffer; -pub mod config; -pub mod context; -pub mod display; -pub mod error; -pub mod image; -pub mod jpeg; -pub mod subpicture; -pub mod surface; -pub mod vpp; - -pub use pixelformat::PixelFormat; - -use std::{ffi::c_int, vec}; - -use error::{Error, VAError, VAStatus}; - -type Result = std::result::Result; - -ffi_enum! { - /// A codec profile that may be accelerated with libva. - pub enum Profile: c_int { - /// "Misc" profile for format-independent operations. - None = -1, - MPEG2Simple = 0, - MPEG2Main = 1, - MPEG4Simple = 2, - MPEG4AdvancedSimple = 3, - MPEG4Main = 4, - H264Baseline = 5, - H264Main = 6, - H264High = 7, - VC1Simple = 8, - VC1Main = 9, - VC1Advanced = 10, - H263Baseline = 11, - JPEGBaseline = 12, - H264ConstrainedBaseline = 13, - VP8Version0_3 = 14, - H264MultiviewHigh = 15, - H264StereoHigh = 16, - HEVCMain = 17, - HEVCMain10 = 18, - VP9Profile0 = 19, - VP9Profile1 = 20, - VP9Profile2 = 21, - VP9Profile3 = 22, - HEVCMain12 = 23, - HEVCMain422_10 = 24, - HEVCMain422_12 = 25, - HEVCMain444 = 26, - HEVCMain444_10 = 27, - HEVCMain444_12 = 28, - HEVCSccMain = 29, - HEVCSccMain10 = 30, - HEVCSccMain444 = 31, - AV1Profile0 = 32, - AV1Profile1 = 33, - HEVCSccMain444_10 = 34, - Protected = 35, - } -} - -ffi_enum! { - /// An entrypoint represents a specific operation on image or video data. - pub enum Entrypoint: c_int { - /// Variable-length decoding (of video slices or pictures). - VLD = 1, - IZZ = 2, - IDCT = 3, - MoComp = 4, - Deblocking = 5, - /// Video slice encoding. - EncSlice = 6, - /// Picture encoding (eg. for JPEGs) - EncPicture = 7, - EncSliceLP = 8, - /// The video processing API. See [`crate::vpp`] for more info. - VideoProc = 10, - /// Flexible Encoding Infrastructure - FEI = 11, - Stats = 12, - ProtectedTEEComm = 13, - ProtectedContent = 14, - } -} - -ffi_enum! { - /// Image rotation values. - pub enum Rotation: u32 { - NONE = 0x00000000, - R90 = 0x00000001, - R180 = 0x00000002, - R270 = 0x00000003, - } -} - -bitflags! { - /// Mirroring directions. - pub struct Mirror: u32 { - const NONE = 0; - const HORIZONTAL = 0x00000001; - const VERTICAL = 0x00000002; - } -} - -bitflags! { - /// Indicates what part of the slice is being submitted. - /// - /// Typically, the whole slice is submitted at once ([`SliceDataFlags::ALL`]). - pub struct SliceDataFlags: u32 { - /// The entire slice is being submitted at once. - const ALL = 0x00; - const BEGIN = 0x01; - const MIDDLE = 0x02; - const END = 0x04; - } -} - -/// Codec-independent slice parameters. -#[derive(Debug, Clone, Copy)] -#[repr(C)] -pub struct SliceParameterBufferBase { - slice_data_size: u32, - slice_data_offset: u32, - slice_data_flags: SliceDataFlags, -} - -impl SliceParameterBufferBase { - #[inline] - pub fn new(slice_data_size: u32) -> Self { - Self { - slice_data_size, - slice_data_offset: 0, - slice_data_flags: SliceDataFlags::ALL, - } - } - - #[inline] - pub fn slice_data_size(&self) -> u32 { - self.slice_data_size - } - - #[inline] - pub fn slice_data_offset(&self) -> u32 { - self.slice_data_offset - } - - #[inline] - pub fn set_slice_data_offset(&mut self, slice_data_offset: u32) { - self.slice_data_offset = slice_data_offset; - } - - #[inline] - pub fn slice_data_flags(&self) -> SliceDataFlags { - self.slice_data_flags - } - - #[inline] - pub fn set_slice_data_flags(&mut self, flags: SliceDataFlags) { - self.slice_data_flags = flags; - } -} - -/// A list of [`Profile`]s. -#[derive(Clone)] -pub struct Profiles { - vec: Vec, -} - -impl Profiles { - pub fn len(&self) -> usize { - self.vec.len() - } - - pub fn is_empty(&self) -> bool { - self.vec.is_empty() - } - - pub fn contains(&self, profile: Profile) -> bool { - self.vec.contains(&profile) - } -} - -impl IntoIterator for Profiles { - type Item = Profile; - type IntoIter = vec::IntoIter; - - fn into_iter(self) -> Self::IntoIter { - self.vec.into_iter() - } -} - -/// A list of [`Entrypoint`]s. -#[derive(Clone)] -pub struct Entrypoints { - vec: Vec, -} - -impl Entrypoints { - pub fn contains(&self, entrypoint: Entrypoint) -> bool { - self.vec.contains(&entrypoint) - } -} - -impl IntoIterator for Entrypoints { - type Item = Entrypoint; - type IntoIter = vec::IntoIter; - - fn into_iter(self) -> Self::IntoIter { - self.vec.into_iter() - } -} - -fn check(status: VAStatus) -> Result<()> { - if status == VAStatus::SUCCESS { - Ok(()) - } else { - Err(Error::from(VAError(status.0))) - } -} - -fn check_log(status: VAStatus, location: &'static str) { - match check(status) { - Ok(()) => {} - Err(e) => log::error!("ignoring error in {location}: {e}"), - } -} +//! [`fev`]: https://crates.io/crates/fev