ffcine_libplacebo_sys/lib.rs
1//! Raw FFI bindings to [libplacebo](https://code.videolan.org/videolan/libplacebo), generated by
2//! bindgen from the system headers (pkg-config `libplacebo` >= 7.365). Covers the Vulkan backend,
3//! the renderer, colour spaces, tone/gamut mapping, LUTs and custom (mpv `.hook`) shaders.
4//!
5//! docs.rs uses a documentation-only API 375 snapshot; normal builds regenerate
6//! bindings from the installed headers. No snapshot is used for native linking.
7//!
8//! Safe wrappers live in the `ffcine` crate's placebo backend.
9
10#![allow(non_upper_case_globals, non_camel_case_types, non_snake_case)]
11#![allow(clippy::all, clippy::pedantic)]
12
13include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
14
15/// `libplacebo/utils/libav.h`: map libav `AVFrame`s (including `AV_PIX_FMT_VULKAN` hw frames, with
16/// their `AVVkFrame` semaphores) to `pl_frame`s. `AVFrame` is opaque here: pass the pointer from
17/// your libav bindings (e.g. `ffmpeg-sys-next`).
18#[cfg(feature = "libav")]
19pub mod libav {
20 use super::{pl_frame, pl_gpu, pl_tex};
21 use std::os::raw::c_void;
22
23 /// `struct pl_avframe_params`.
24 #[repr(C)]
25 #[derive(Debug, Clone, Copy)]
26 pub struct pl_avframe_params {
27 /// `const AVFrame *`. Required.
28 pub frame: *const c_void,
29 /// Four reusable textures, required for software frames; may be null for hw frames.
30 pub tex: *mut pl_tex,
31 pub map_dovi: bool,
32 pub map_dovi_force: bool,
33 }
34
35 unsafe extern "C" {
36 pub fn pl_map_avframe_ex(
37 gpu: pl_gpu,
38 out_frame: *mut pl_frame,
39 params: *const pl_avframe_params,
40 ) -> bool;
41 pub fn pl_unmap_avframe(gpu: pl_gpu, frame: *mut pl_frame);
42 /// Fills colour/repr/planes metadata (not textures) from an `AVFrame`.
43 pub fn pl_frame_from_avframe(out_frame: *mut pl_frame, frame: *const c_void);
44 /// The `AVFrame *` a frame was mapped from.
45 pub fn pl_get_mapped_avframe(frame: *const pl_frame) -> *mut c_void;
46 }
47}
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn api_version_is_new_enough() {
55 // pl_vulkan_queue.flags arrived in API 365.
56 assert!(PL_API_VER >= 365, "PL_API_VER = {PL_API_VER}");
57 }
58
59 #[test]
60 fn log_create_destroy() {
61 // No GPU needed: a bare log object round-trips through the C API.
62 unsafe {
63 let mut log = pl_log_create_375(PL_API_VER as i32, std::ptr::null());
64 assert!(!log.is_null());
65 pl_log_destroy(&raw mut log);
66 assert!(log.is_null());
67 }
68 }
69}