ffcine-libplacebo-sys 0.2.0

Raw FFI bindings to libplacebo (bindgen), Vulkan backend
//! Raw FFI bindings to [libplacebo](https://code.videolan.org/videolan/libplacebo), generated by
//! bindgen from the system headers (pkg-config `libplacebo` >= 7.365). Covers the Vulkan backend,
//! the renderer, colour spaces, tone/gamut mapping, LUTs and custom (mpv `.hook`) shaders.
//!
//! Safe wrappers live in the `ffcine` crate's placebo backend.

#![allow(non_upper_case_globals, non_camel_case_types, non_snake_case)]
#![allow(clippy::all, clippy::pedantic)]

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

/// `libplacebo/utils/libav.h`: map libav `AVFrame`s (including `AV_PIX_FMT_VULKAN` hw frames, with
/// their `AVVkFrame` semaphores) to `pl_frame`s. `AVFrame` is opaque here: pass the pointer from
/// your libav bindings (e.g. `ffmpeg-sys-next`).
#[cfg(feature = "libav")]
pub mod libav {
    use super::{pl_frame, pl_gpu, pl_tex};
    use std::os::raw::c_void;

    /// `struct pl_avframe_params`.
    #[repr(C)]
    #[derive(Debug, Clone, Copy)]
    pub struct pl_avframe_params {
        /// `const AVFrame *`. Required.
        pub frame: *const c_void,
        /// Four reusable textures, required for software frames; may be null for hw frames.
        pub tex: *mut pl_tex,
        pub map_dovi: bool,
        pub map_dovi_force: bool,
    }

    unsafe extern "C" {
        pub fn pl_map_avframe_ex(
            gpu: pl_gpu,
            out_frame: *mut pl_frame,
            params: *const pl_avframe_params,
        ) -> bool;
        pub fn pl_unmap_avframe(gpu: pl_gpu, frame: *mut pl_frame);
        /// Fills colour/repr/planes metadata (not textures) from an `AVFrame`.
        pub fn pl_frame_from_avframe(out_frame: *mut pl_frame, frame: *const c_void);
        /// The `AVFrame *` a frame was mapped from.
        pub fn pl_get_mapped_avframe(frame: *const pl_frame) -> *mut c_void;
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn api_version_is_new_enough() {
        // pl_vulkan_queue.flags arrived in API 365.
        assert!(PL_API_VER >= 365, "PL_API_VER = {PL_API_VER}");
    }

    #[test]
    fn log_create_destroy() {
        // No GPU needed: a bare log object round-trips through the C API.
        unsafe {
            let mut log = pl_log_create_375(PL_API_VER as i32, std::ptr::null());
            assert!(!log.is_null());
            pl_log_destroy(&raw mut log);
            assert!(log.is_null());
        }
    }
}