forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiBc0d4024Tahinli3 months ago866 commits

sys.rs698 lines, 26.7 KiBHistoryRawDownload
1//! Hand-written FFI for the subset of libva this family uses.
2//!
3//! # Why hand-written
4//!
5//! No `bindgen`: the family rule is no build-time tooling, and a generated
6//! 40k-line binding hides exactly the thing that has to be audited — the ABI
7//! assumptions. Everything here is transcribed from the system headers and is
8//! short enough to read in one sitting.
9//!
10//! # ABI assumptions (all four are load-bearing)
11//!
12//! 1. **libva 1.23.0 headers**, `/usr/include/va/{va.h,va_drm.h,va_drmcommon.h}`,
13//! target `x86_64-unknown-linux-gnu`, System V C ABI.
14//! 2. **C `enum` is `int` (4 bytes)** on this ABI. Every VA enum is transcribed
15//! as a plain `i32` type alias plus constants, *never* as a `#[repr(i32)]`
16//! Rust enum: the driver writes profile/entrypoint values into buffers we
17//! own, and a value we have no variant for would be instant UB on a real
18//! Rust enum. Interpretation happens in the safe layer
19//! ([`crate::caps::Profile::from_raw`]), which has an `Unknown(i32)` arm.
20//! This is the header-drift trap that broke cros-libva at libva >= 1.23.
21//! 3. **Struct layouts** below are checked by the `const _: () = assert!(...)`
22//! block at the end of this file against numbers printed by
23//! `crates/ec-va/abi-probe.c` compiled against the *system* headers. Rerun
24//! that probe after a libva upgrade; a mismatch means this file drifted.
25//! 4. **`VADisplay` is an opaque pointer**; we never dereference it.
26//!
27//! Points 1-3 are compile-time. They cannot see a libva that changes layout
28//! *after* this crate is built, so [`crate::Display::open`] additionally
29//! performs a **runtime** `vaInitialize` version check and refuses anything
30//! older than 1.23 with a typed error.
31
32// Every item keeps its exact C spelling so that this file can be diffed
33// against the headers by eye — the whole audit story of a hand-written FFI.
34#![allow(non_camel_case_types)]
35#![allow(non_snake_case)]
36#![allow(non_upper_case_globals)]
37// Fields keep their C names and are documented by the header line cited on
38// each item; restating "the fourcc field is the fourcc" 60 times would bury
39// the ABI notes that actually matter here.
40#![allow(missing_docs)]
41
42use std::ffi::{c_char, c_int, c_uint, c_void};
43
44// ---------------------------------------------------------------------------
45// Scalar types (va.h:260-262, 1580-1647, 2042, 4727)
46// ---------------------------------------------------------------------------
47
48/// Opaque display handle. Never dereferenced by this crate.
49pub type VADisplay = *mut c_void;
50/// Return status of every VA entry point. `va.h:262`.
51pub type VAStatus = i32;
52/// `va.h:1580`.
53pub type VAGenericID = c_uint;
54pub type VAConfigID = VAGenericID;
55pub type VAContextID = VAGenericID;
56pub type VASurfaceID = VAGenericID;
57pub type VABufferID = VAGenericID;
58pub type VAImageID = VAGenericID;
59
60/// C enum `VAProfile` (`va.h:502`), kept as `i32`. See ABI assumption 2.
61pub type VAProfile = i32;
62/// C enum `VAEntrypoint` (`va.h:552`), kept as `i32`.
63pub type VAEntrypoint = i32;
64/// C enum `VAConfigAttribType` (`va.h:619`), kept as `i32`.
65pub type VAConfigAttribType = i32;
66/// C enum `VASurfaceAttribType` (`va.h:1689`), kept as `i32`.
67pub type VASurfaceAttribType = i32;
68/// C enum `VAGenericValueType` (`va.h:1651`), kept as `i32`.
69pub type VAGenericValueType = i32;
70/// C enum `VABufferType` (`va.h:2044`), kept as `i32`.
71pub type VABufferType = i32;
72
73pub const VA_INVALID_ID: VAGenericID = 0xffff_ffff;
74pub const VA_INVALID_SURFACE: VASurfaceID = VA_INVALID_ID;
75
76// Status codes actually branched on; the rest are reported via `vaErrorStr`.
77// `va.h:264-309`.
78pub const VA_STATUS_SUCCESS: VAStatus = 0x0000_0000;
79pub const VA_STATUS_ERROR_INVALID_CONTEXT: VAStatus = 0x0000_0005;
80pub const VA_STATUS_ERROR_UNSUPPORTED_PROFILE: VAStatus = 0x0000_000c;
81pub const VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT: VAStatus = 0x0000_000d;
82pub const VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT: VAStatus = 0x0000_000e;
83pub const VA_STATUS_ERROR_MAX_NUM_EXCEEDED: VAStatus = 0x0000_000b;
84pub const VA_STATUS_ERROR_UNIMPLEMENTED: VAStatus = 0x0000_0014;
85pub const VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED: VAStatus = 0x0000_0013;
86pub const VA_STATUS_ERROR_OPERATION_FAILED: VAStatus = 0x0000_0001;
87pub const VA_STATUS_ERROR_INVALID_PARAMETER: VAStatus = 0x0000_0012;
88
89// Entrypoints (`va.h:552`).
90pub const VAEntrypointVLD: VAEntrypoint = 1;
91pub const VAEntrypointEncSlice: VAEntrypoint = 6;
92pub const VAEntrypointEncPicture: VAEntrypoint = 7;
93pub const VAEntrypointEncSliceLP: VAEntrypoint = 8;
94pub const VAEntrypointVideoProc: VAEntrypoint = 10;
95
96// Config attribute types (`va.h:619`).
97pub const VAConfigAttribRTFormat: VAConfigAttribType = 0;
98pub const VAConfigAttribRateControl: VAConfigAttribType = 5;
99pub const VAConfigAttribDecSliceMode: VAConfigAttribType = 6;
100pub const VAConfigAttribEncPackedHeaders: VAConfigAttribType = 10;
101pub const VAConfigAttribEncMaxRefFrames: VAConfigAttribType = 13;
102
103// RT formats (`va.h:1073-1090`).
104pub const VA_RT_FORMAT_YUV420: u32 = 0x0000_0001;
105pub const VA_RT_FORMAT_YUV422: u32 = 0x0000_0002;
106pub const VA_RT_FORMAT_YUV444: u32 = 0x0000_0004;
107pub const VA_RT_FORMAT_YUV400: u32 = 0x0000_0010;
108pub const VA_RT_FORMAT_YUV420_10: u32 = 0x0000_0100;
109pub const VA_RT_FORMAT_YUV422_10: u32 = 0x0000_0200;
110pub const VA_RT_FORMAT_YUV444_10: u32 = 0x0000_0400;
111pub const VA_RT_FORMAT_YUV420_12: u32 = 0x0000_1000;
112pub const VA_RT_FORMAT_RGB32: u32 = 0x0002_0000;
113
114// Surface attribute types (`va.h:1689`) and flags (`va.h:1681-1684`).
115pub const VASurfaceAttribNone: VASurfaceAttribType = 0;
116pub const VASurfaceAttribPixelFormat: VASurfaceAttribType = 1;
117pub const VASurfaceAttribMinWidth: VASurfaceAttribType = 2;
118pub const VASurfaceAttribMaxWidth: VASurfaceAttribType = 3;
119pub const VASurfaceAttribMinHeight: VASurfaceAttribType = 4;
120pub const VASurfaceAttribMaxHeight: VASurfaceAttribType = 5;
121pub const VASurfaceAttribMemoryType: VASurfaceAttribType = 6;
122pub const VASurfaceAttribUsageHint: VASurfaceAttribType = 8;
123
124pub const VA_SURFACE_ATTRIB_GETTABLE: u32 = 0x0000_0001;
125pub const VA_SURFACE_ATTRIB_SETTABLE: u32 = 0x0000_0002;
126
127pub const VA_SURFACE_ATTRIB_USAGE_HINT_GENERIC: u32 = 0x0000_0000;
128pub const VA_SURFACE_ATTRIB_USAGE_HINT_DECODER: u32 = 0x0000_0001;
129pub const VA_SURFACE_ATTRIB_USAGE_HINT_ENCODER: u32 = 0x0000_0002;
130pub const VA_SURFACE_ATTRIB_USAGE_HINT_EXPORT: u32 = 0x0000_0020;
131
132// Generic value discriminants (`va.h:1651`).
133pub const VAGenericValueTypeInteger: VAGenericValueType = 1;
134pub const VAGenericValueTypeFloat: VAGenericValueType = 2;
135pub const VAGenericValueTypePointer: VAGenericValueType = 3;
136pub const VAGenericValueTypeFunc: VAGenericValueType = 4;
137
138// Buffer types actually used by decode/encode paths (`va.h:2044`).
139pub const VAPictureParameterBufferType: VABufferType = 0;
140pub const VAIQMatrixBufferType: VABufferType = 1;
141pub const VASliceParameterBufferType: VABufferType = 4;
142pub const VASliceDataBufferType: VABufferType = 5;
143pub const VAImageBufferType: VABufferType = 9;
144pub const VAProbabilityBufferType: VABufferType = 13;
145pub const VAEncCodedBufferType: VABufferType = 21;
146pub const VAEncSequenceParameterBufferType: VABufferType = 22;
147pub const VAEncPictureParameterBufferType: VABufferType = 23;
148pub const VAEncSliceParameterBufferType: VABufferType = 24;
149pub const VAEncPackedHeaderParameterBufferType: VABufferType = 25;
150pub const VAEncPackedHeaderDataBufferType: VABufferType = 26;
151pub const VAEncMiscParameterBufferType: VABufferType = 27;
152/// `va.h:2086`, the VPP pipeline parameter buffer.
153pub const VAProcPipelineParameterBufferType: VABufferType = 41;
154
155// VPP filter types (`va_vpp.h:238-258`); only `None` and the HDR tone-mapping
156// filter are used here, but the whole ordinal run is transcribed since a
157// caller matching `vaQueryVideoProcFilters` output needs every value to tell
158// "no filter" from "a filter this build has no constant for".
159pub type VAProcFilterType = i32;
160pub const VAProcFilterNone: VAProcFilterType = 0;
161pub const VAProcFilterNoiseReduction: VAProcFilterType = 1;
162pub const VAProcFilterDeinterlacing: VAProcFilterType = 2;
163pub const VAProcFilterSharpening: VAProcFilterType = 3;
164pub const VAProcFilterColorBalance: VAProcFilterType = 4;
165pub const VAProcFilterSkinToneEnhancement: VAProcFilterType = 5;
166pub const VAProcFilterTotalColorCorrection: VAProcFilterType = 6;
167pub const VAProcFilterHVSNoiseReduction: VAProcFilterType = 7;
168pub const VAProcFilterHighDynamicRangeToneMapping: VAProcFilterType = 8;
169pub const VAProcFilter3DLUT: VAProcFilterType = 9;
170/// Sizes a `vaQueryVideoProcFilters` output array; never returned by it.
171pub const VAProcFilterCount: VAProcFilterType = 10;
172
173/// `VAProcColorStandardType`, `va_vpp.h:306`. `0` ("None") is what this crate
174/// always passes: implicit colour handling, no explicit conversion request.
175pub type VAProcColorStandardType = i32;
176/// `VAProcMode`, `va_vpp.h:447`. `0` is the driver-chosen default pipeline.
177pub type VAProcMode = i32;
178
179// Packed header bits an encoder may take over (`va.h:1199-1231`).
180pub const VA_ENC_PACKED_HEADER_NONE: u32 = 0x0000_0000;
181pub const VA_ENC_PACKED_HEADER_SEQUENCE: u32 = 0x0000_0001;
182pub const VA_ENC_PACKED_HEADER_PICTURE: u32 = 0x0000_0002;
183pub const VA_ENC_PACKED_HEADER_SLICE: u32 = 0x0000_0004;
184pub const VA_ENC_PACKED_HEADER_MISC: u32 = 0x0000_0008;
185pub const VA_ENC_PACKED_HEADER_RAW_DATA: u32 = 0x0000_0010;
186
187// Rate control modes (`va.h:1108-1164`).
188pub const VA_RC_NONE: u32 = 0x0000_0001;
189pub const VA_RC_CBR: u32 = 0x0000_0002;
190pub const VA_RC_VBR: u32 = 0x0000_0004;
191pub const VA_RC_CQP: u32 = 0x0000_0010;
192
193/// `vaCreateContext` flag: sequence contains only progressive frames (`va.h:1919`).
194pub const VA_PROGRESSIVE: c_int = 0x1;
195
196// DRM PRIME memory types and export flags (`va_drmcommon.h:78-94`, `va.h:4130-4150`).
197pub const VA_SURFACE_ATTRIB_MEM_TYPE_VA: u32 = 0x0000_0001;
198pub const VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM: u32 = 0x1000_0000;
199pub const VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME: u32 = 0x2000_0000;
200pub const VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2: u32 = 0x4000_0000;
201
202pub const VA_EXPORT_SURFACE_READ_ONLY: u32 = 0x0001;
203pub const VA_EXPORT_SURFACE_WRITE_ONLY: u32 = 0x0002;
204pub const VA_EXPORT_SURFACE_READ_WRITE: u32 = 0x0003;
205pub const VA_EXPORT_SURFACE_SEPARATE_LAYERS: u32 = 0x0004;
206pub const VA_EXPORT_SURFACE_COMPOSED_LAYERS: u32 = 0x0008;
207
208// FourCCs used by the family (`va.h:4400-4700`).
209pub const VA_FOURCC_NV12: u32 = 0x3231_564e;
210pub const VA_FOURCC_P010: u32 = 0x3031_3050;
211pub const VA_FOURCC_I420: u32 = 0x3032_3449;
212pub const VA_FOURCC_YV12: u32 = 0x3231_5659;
213
214// ---------------------------------------------------------------------------
215// Structs
216// ---------------------------------------------------------------------------
217
218/// `VAConfigAttrib`, `va.h:1155`.
219#[repr(C)]
220#[derive(Debug, Clone, Copy, PartialEq, Eq)]
221pub struct VAConfigAttrib {
222 pub type_: VAConfigAttribType,
223 pub value: u32,
224}
225
226/// The `value` union of `VAGenericValue`, `va.h:1663-1673`.
227///
228/// Only ever read after checking the sibling `type_` discriminant.
229#[repr(C)]
230#[derive(Clone, Copy)]
231pub union VAGenericValueUnion {
232 pub i: i32,
233 pub f: f32,
234 pub p: *mut c_void,
235 pub func: Option<extern "C" fn()>,
236}
237
238/// `VAGenericValue`, `va.h:1661`.
239#[repr(C)]
240#[derive(Clone, Copy)]
241pub struct VAGenericValue {
242 pub type_: VAGenericValueType,
243 pub value: VAGenericValueUnion,
244}
245
246/// `VASurfaceAttrib`, `va.h:1741`.
247#[repr(C)]
248#[derive(Clone, Copy)]
249pub struct VASurfaceAttrib {
250 pub type_: VASurfaceAttribType,
251 pub flags: u32,
252 pub value: VAGenericValue,
253}
254
255/// `VAImageFormat`, `va.h:4712`. `va_reserved` is `VA_PADDING_LOW` = 4 u32s.
256#[repr(C)]
257#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
258pub struct VAImageFormat {
259 pub fourcc: u32,
260 pub byte_order: u32,
261 pub bits_per_pixel: u32,
262 pub depth: u32,
263 pub red_mask: u32,
264 pub green_mask: u32,
265 pub blue_mask: u32,
266 pub alpha_mask: u32,
267 pub va_reserved: [u32; 4],
268}
269
270/// `VAImage`, `va.h:4729`.
271#[repr(C)]
272#[derive(Debug, Clone, Copy)]
273pub struct VAImage {
274 pub image_id: VAImageID,
275 pub format: VAImageFormat,
276 pub buf: VABufferID,
277 pub width: u16,
278 pub height: u16,
279 pub data_size: u32,
280 pub num_planes: u32,
281 pub pitches: [u32; 3],
282 pub offsets: [u32; 3],
283 pub num_palette_entries: i32,
284 pub entry_bytes: i32,
285 pub component_order: [i8; 4],
286 pub va_reserved: [u32; 4],
287}
288
289impl Default for VAImage {
290 fn default() -> Self {
291 // All-zero is a valid "not yet filled" VAImage; `image_id` is
292 // overwritten by vaDeriveImage/vaCreateImage before any use.
293 // SAFETY: every field is a plain integer or array of integers, so the
294 // all-zero bit pattern is a valid value of this type.
295 unsafe { std::mem::zeroed() }
296 }
297}
298
299/// One DRM object of a `VADRMPRIMESurfaceDescriptor`, `va_drmcommon.h:139-147`.
300#[repr(C)]
301#[derive(Debug, Clone, Copy)]
302pub struct VADRMPRIMEObject {
303 pub fd: c_int,
304 pub size: u32,
305 pub drm_format_modifier: u64,
306}
307
308/// One layer of a `VADRMPRIMESurfaceDescriptor`, `va_drmcommon.h:151-164`.
309#[repr(C)]
310#[derive(Debug, Clone, Copy)]
311pub struct VADRMPRIMELayer {
312 pub drm_format: u32,
313 pub num_planes: u32,
314 pub object_index: [u32; 4],
315 pub offset: [u32; 4],
316 pub pitch: [u32; 4],
317}
318
319/// `VADRMPRIMESurfaceDescriptor`, `va_drmcommon.h:130`. Used with
320/// [`VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2`].
321#[repr(C)]
322#[derive(Debug, Clone, Copy)]
323pub struct VADRMPRIMESurfaceDescriptor {
324 pub fourcc: u32,
325 pub width: u32,
326 pub height: u32,
327 pub num_objects: u32,
328 pub objects: [VADRMPRIMEObject; 4],
329 pub num_layers: u32,
330 pub layers: [VADRMPRIMELayer; 4],
331}
332
333impl Default for VADRMPRIMESurfaceDescriptor {
334 fn default() -> Self {
335 // SAFETY: all fields are integers or arrays of integer structs; the
336 // all-zero bit pattern is valid. `fd` = 0 is never treated as an owned
337 // descriptor because `num_objects` = 0 in that state.
338 unsafe { std::mem::zeroed() }
339 }
340}
341
342/// `VARectangle`, `va.h:406`.
343#[repr(C)]
344#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
345pub struct VARectangle {
346 pub x: i16,
347 pub y: i16,
348 pub width: u16,
349 pub height: u16,
350}
351
352/// `VAProcColorProperties`, `va_vpp.h:683`.
353#[repr(C)]
354#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
355pub struct VAProcColorProperties {
356 pub chroma_sample_location: u8,
357 pub color_range: u8,
358 pub colour_primaries: u8,
359 pub transfer_characteristics: u8,
360 pub matrix_coefficients: u8,
361 pub reserved: [u8; 3],
362}
363
364/// `VAProcPipelineParameterBuffer`, `va_vpp.h:886`.
365///
366/// Every field this crate does not set goes to its zero/NULL default, which
367/// libva documents as "whole surface, no filters, driver-chosen colour
368/// handling" (va_vpp.h:899,920,956,976) — the plain conversion this crate
369/// asks for. `va_reserved` must stay zeroed (`VA_PADDING_LARGE` - 16 = 16
370/// `u32`s on a 64-bit target, the layout the struct trailer promises).
371#[repr(C)]
372#[derive(Clone, Copy)]
373pub struct VAProcPipelineParameterBuffer {
374 pub surface: VASurfaceID,
375 pub surface_region: *const VARectangle,
376 pub surface_color_standard: VAProcColorStandardType,
377 pub output_region: *const VARectangle,
378 pub output_background_color: u32,
379 pub output_color_standard: VAProcColorStandardType,
380 pub pipeline_flags: u32,
381 pub filter_flags: u32,
382 pub filters: *mut VABufferID,
383 pub num_filters: u32,
384 pub forward_references: *mut VASurfaceID,
385 pub num_forward_references: u32,
386 pub backward_references: *mut VASurfaceID,
387 pub num_backward_references: u32,
388 pub rotation_state: u32,
389 pub blend_state: *const c_void,
390 pub mirror_state: u32,
391 pub additional_outputs: *mut VASurfaceID,
392 pub num_additional_outputs: u32,
393 pub input_surface_flag: u32,
394 pub output_surface_flag: u32,
395 pub input_color_properties: VAProcColorProperties,
396 pub output_color_properties: VAProcColorProperties,
397 pub processing_mode: VAProcMode,
398 pub output_hdr_metadata: *const c_void,
399 pub va_reserved: [u32; 16],
400}
401
402impl Default for VAProcPipelineParameterBuffer {
403 fn default() -> Self {
404 // SAFETY: every field is an integer, a struct of integers, or a
405 // pointer; the all-zero bit pattern is a valid (NULL / 0) value of
406 // each, matching the "whole surface, no extra filters" defaults the
407 // header documents.
408 unsafe { std::mem::zeroed() }
409 }
410}
411
412// ---------------------------------------------------------------------------
413// Entry points
414// ---------------------------------------------------------------------------
415
416#[link(name = "va")]
417unsafe extern "C" {
418 /// `va.h:403`. Returns a pointer to a static string; never NULL.
419 pub fn vaErrorStr(error_status: VAStatus) -> *const c_char;
420 /// `va.h:453`.
421 pub fn vaDisplayIsValid(dpy: VADisplay) -> c_int;
422 /// `va.h:465`.
423 pub fn vaInitialize(
424 dpy: VADisplay,
425 major_version: *mut c_int,
426 minor_version: *mut c_int,
427 ) -> VAStatus;
428 /// `va.h:474`.
429 pub fn vaTerminate(dpy: VADisplay) -> VAStatus;
430 /// `va.h:486`. Static string owned by the driver, valid until `vaTerminate`.
431 pub fn vaQueryVendorString(dpy: VADisplay) -> *const c_char;
432
433 /// `va.h:1524`.
434 pub fn vaMaxNumProfiles(dpy: VADisplay) -> c_int;
435 /// `va.h:1529`.
436 pub fn vaMaxNumEntrypoints(dpy: VADisplay) -> c_int;
437 /// `va.h:1534`.
438 pub fn vaMaxNumConfigAttributes(dpy: VADisplay) -> c_int;
439 /// `va.h:1544`.
440 pub fn vaQueryConfigProfiles(
441 dpy: VADisplay,
442 profile_list: *mut VAProfile,
443 num_profiles: *mut c_int,
444 ) -> VAStatus;
445 /// `va.h:1556`.
446 pub fn vaQueryConfigEntrypoints(
447 dpy: VADisplay,
448 profile: VAProfile,
449 entrypoint_list: *mut VAEntrypoint,
450 num_entrypoints: *mut c_int,
451 ) -> VAStatus;
452 /// `va.h:1571`. `attrib_list` is in/out: caller sets `type_`, driver fills `value`.
453 pub fn vaGetConfigAttributes(
454 dpy: VADisplay,
455 profile: VAProfile,
456 entrypoint: VAEntrypoint,
457 attrib_list: *mut VAConfigAttrib,
458 num_attribs: c_int,
459 ) -> VAStatus;
460 /// `va.h:1589`.
461 pub fn vaCreateConfig(
462 dpy: VADisplay,
463 profile: VAProfile,
464 entrypoint: VAEntrypoint,
465 attrib_list: *mut VAConfigAttrib,
466 num_attribs: c_int,
467 config_id: *mut VAConfigID,
468 ) -> VAStatus;
469 /// `va.h:1601`.
470 pub fn vaDestroyConfig(dpy: VADisplay, config_id: VAConfigID) -> VAStatus;
471
472 /// `va.h:1868`. Pass NULL `attrib_list` to only query the count.
473 pub fn vaQuerySurfaceAttributes(
474 dpy: VADisplay,
475 config: VAConfigID,
476 attrib_list: *mut VASurfaceAttrib,
477 num_attribs: *mut c_uint,
478 ) -> VAStatus;
479 /// `va.h:1894`.
480 pub fn vaCreateSurfaces(
481 dpy: VADisplay,
482 format: c_uint,
483 width: c_uint,
484 height: c_uint,
485 surfaces: *mut VASurfaceID,
486 num_surfaces: c_uint,
487 attrib_list: *mut VASurfaceAttrib,
488 num_attribs: c_uint,
489 ) -> VAStatus;
490 /// `va.h:1914`.
491 pub fn vaDestroySurfaces(
492 dpy: VADisplay,
493 surfaces: *mut VASurfaceID,
494 num_surfaces: c_int,
495 ) -> VAStatus;
496 /// `va.h:4185`. `descriptor` type is chosen by `mem_type`.
497 pub fn vaExportSurfaceHandle(
498 dpy: VADisplay,
499 surface_id: VASurfaceID,
500 mem_type: u32,
501 flags: u32,
502 descriptor: *mut c_void,
503 ) -> VAStatus;
504
505 /// `va.h:1933`.
506 pub fn vaCreateContext(
507 dpy: VADisplay,
508 config_id: VAConfigID,
509 picture_width: c_int,
510 picture_height: c_int,
511 flag: c_int,
512 render_targets: *mut VASurfaceID,
513 num_render_targets: c_int,
514 context: *mut VAContextID,
515 ) -> VAStatus;
516 /// `va.h:1949`.
517 pub fn vaDestroyContext(dpy: VADisplay, context: VAContextID) -> VAStatus;
518
519 /// `va.h:3833`. `data` NULL means "allocate, fill later via vaMapBuffer".
520 pub fn vaCreateBuffer(
521 dpy: VADisplay,
522 context: VAContextID,
523 type_: VABufferType,
524 size: c_uint,
525 num_elements: c_uint,
526 data: *mut c_void,
527 buf_id: *mut VABufferID,
528 ) -> VAStatus;
529 /// `va.h:3971`.
530 pub fn vaMapBuffer(dpy: VADisplay, buf_id: VABufferID, pbuf: *mut *mut c_void) -> VAStatus;
531 /// `va.h:4004`.
532 pub fn vaUnmapBuffer(dpy: VADisplay, buf_id: VABufferID) -> VAStatus;
533 /// `va.h:4018`.
534 pub fn vaDestroyBuffer(dpy: VADisplay, buffer_id: VABufferID) -> VAStatus;
535
536 /// `va.h:4205`.
537 pub fn vaBeginPicture(
538 dpy: VADisplay,
539 context: VAContextID,
540 render_target: VASurfaceID,
541 ) -> VAStatus;
542 /// `va.h:4214`.
543 pub fn vaRenderPicture(
544 dpy: VADisplay,
545 context: VAContextID,
546 buffers: *mut VABufferID,
547 num_buffers: c_int,
548 ) -> VAStatus;
549 /// `va.h:4229`.
550 pub fn vaEndPicture(dpy: VADisplay, context: VAContextID) -> VAStatus;
551 /// `va.h:4271`. Blocks until the render target is idle.
552 pub fn vaSyncSurface(dpy: VADisplay, render_target: VASurfaceID) -> VAStatus;
553
554 /// `va.h:4773`.
555 pub fn vaMaxNumImageFormats(dpy: VADisplay) -> c_int;
556 /// `va.h:4783`.
557 pub fn vaQueryImageFormats(
558 dpy: VADisplay,
559 format_list: *mut VAImageFormat,
560 num_formats: *mut c_int,
561 ) -> VAStatus;
562 /// `va.h:4796`.
563 pub fn vaCreateImage(
564 dpy: VADisplay,
565 format: *mut VAImageFormat,
566 width: c_int,
567 height: c_int,
568 image: *mut VAImage,
569 ) -> VAStatus;
570 /// `va.h:4807`.
571 pub fn vaDestroyImage(dpy: VADisplay, image: VAImageID) -> VAStatus;
572 /// `va.h:4827`.
573 pub fn vaGetImage(
574 dpy: VADisplay,
575 surface: VASurfaceID,
576 x: c_int,
577 y: c_int,
578 width: c_uint,
579 height: c_uint,
580 image: VAImageID,
581 ) -> VAStatus;
582 /// `va.h:4888`. Zero-copy view of a surface, when the driver allows it.
583 pub fn vaDeriveImage(dpy: VADisplay, surface: VASurfaceID, image: *mut VAImage) -> VAStatus;
584 /// `va.h:4860`. Copies an image into a surface — the encoder upload path.
585 pub fn vaPutImage(
586 dpy: VADisplay,
587 surface: VASurfaceID,
588 image: VAImageID,
589 src_x: c_int,
590 src_y: c_int,
591 src_width: c_uint,
592 src_height: c_uint,
593 dest_x: c_int,
594 dest_y: c_int,
595 dest_width: c_uint,
596 dest_height: c_uint,
597 ) -> VAStatus;
598 /// `va_vpp.h:1518`. Filters a VPP context's config supports.
599 pub fn vaQueryVideoProcFilters(
600 dpy: VADisplay,
601 context: VAContextID,
602 filters: *mut VAProcFilterType,
603 num_filters: *mut c_uint,
604 ) -> VAStatus;
605}
606
607#[link(name = "va-drm")]
608unsafe extern "C" {
609 /// `va_drm.h:45`. Returns NULL on failure. Does **not** take ownership of `fd`.
610 pub fn vaGetDisplayDRM(fd: c_int) -> VADisplay;
611}
612
613// ---------------------------------------------------------------------------
614// ABI transcription check
615// ---------------------------------------------------------------------------
616//
617// Reference output of `crates/ec-va/abi-probe.c` compiled against
618// /usr/include/va (libva 1.23.0) with gcc on x86_64:
619//
620// VAConfigAttrib size=8 align=4 type=0 value=4
621// VAGenericValue size=16 align=8 type=0 value=8
622// VASurfaceAttrib size=24 align=8 type=0 flags=4 value=8
623// VAImageFormat size=48 align=4 fourcc=0 .. va_reserved=32
624// VAImage size=120 align=4 image_id=0 format=4 buf=52
625// width=56 height=58 data_size=60
626// num_planes=64 pitches=68 offsets=80
627// num_palette_entries=92 entry_bytes=96
628// component_order=100 va_reserved=104
629// VADRMPRIMESurfaceDescriptor size=312 align=8 fourcc=0 width=4 height=8
630// num_objects=12 objects=16
631// num_layers=80 layers=84
632// object elem size=16, layer elem size=56
633// VARectangle size=8 align=2
634const _: () = {
635 use std::mem::{align_of, offset_of, size_of};
636
637 assert!(size_of::<VAConfigAttrib>() == 8 && align_of::<VAConfigAttrib>() == 4);
638 assert!(offset_of!(VAConfigAttrib, value) == 4);
639
640 assert!(size_of::<VAGenericValue>() == 16 && align_of::<VAGenericValue>() == 8);
641 assert!(offset_of!(VAGenericValue, value) == 8);
642
643 assert!(size_of::<VASurfaceAttrib>() == 24 && align_of::<VASurfaceAttrib>() == 8);
644 assert!(offset_of!(VASurfaceAttrib, flags) == 4);
645 assert!(offset_of!(VASurfaceAttrib, value) == 8);
646
647 assert!(size_of::<VAImageFormat>() == 48 && align_of::<VAImageFormat>() == 4);
648 assert!(offset_of!(VAImageFormat, va_reserved) == 32);
649
650 assert!(size_of::<VAImage>() == 120 && align_of::<VAImage>() == 4);
651 assert!(offset_of!(VAImage, format) == 4);
652 assert!(offset_of!(VAImage, buf) == 52);
653 assert!(offset_of!(VAImage, width) == 56);
654 assert!(offset_of!(VAImage, height) == 58);
655 assert!(offset_of!(VAImage, data_size) == 60);
656 assert!(offset_of!(VAImage, num_planes) == 64);
657 assert!(offset_of!(VAImage, pitches) == 68);
658 assert!(offset_of!(VAImage, offsets) == 80);
659 assert!(offset_of!(VAImage, num_palette_entries) == 92);
660 assert!(offset_of!(VAImage, entry_bytes) == 96);
661 assert!(offset_of!(VAImage, component_order) == 100);
662 assert!(offset_of!(VAImage, va_reserved) == 104);
663
664 assert!(size_of::<VADRMPRIMEObject>() == 16);
665 assert!(size_of::<VADRMPRIMELayer>() == 56);
666 assert!(
667 size_of::<VADRMPRIMESurfaceDescriptor>() == 312
668 && align_of::<VADRMPRIMESurfaceDescriptor>() == 8
669 );
670 assert!(offset_of!(VADRMPRIMESurfaceDescriptor, objects) == 16);
671 assert!(offset_of!(VADRMPRIMESurfaceDescriptor, num_layers) == 80);
672 assert!(offset_of!(VADRMPRIMESurfaceDescriptor, layers) == 84);
673
674 assert!(size_of::<VARectangle>() == 8 && align_of::<VARectangle>() == 2);
675
676 assert!(
677 size_of::<VAProcColorProperties>() == 8 && align_of::<VAProcColorProperties>() == 1
678 );
679
680 // 64-bit `va_vpp.h:886`: 25 fields down to `output_hdr_metadata` (152
681 // bytes on this target) plus `va_reserved[VA_PADDING_LARGE - 16]` (16
682 // `u32`s, 64 bytes) = 224.
683 assert!(
684 size_of::<VAProcPipelineParameterBuffer>() == 224
685 && align_of::<VAProcPipelineParameterBuffer>() == 8
686 );
687 assert!(offset_of!(VAProcPipelineParameterBuffer, surface_region) == 8);
688 assert!(offset_of!(VAProcPipelineParameterBuffer, input_color_properties) == 132);
689 assert!(offset_of!(VAProcPipelineParameterBuffer, output_color_properties) == 140);
690 assert!(offset_of!(VAProcPipelineParameterBuffer, processing_mode) == 148);
691 assert!(offset_of!(VAProcPipelineParameterBuffer, output_hdr_metadata) == 152);
692 assert!(offset_of!(VAProcPipelineParameterBuffer, va_reserved) == 160);
693
694 // Assumption 2: C `enum` and `unsigned int` are both 4 bytes here.
695 assert!(size_of::<VAStatus>() == 4);
696 assert!(size_of::<VAGenericID>() == 4);
697 assert!(size_of::<c_int>() == 4);
698};