forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB03dc6e9Tahinli3 months ago178 commits

sys.rs587 lines, 21.9 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
153// Packed header bits an encoder may take over (`va.h:1199-1231`).
154pub const VA_ENC_PACKED_HEADER_NONE: u32 = 0x0000_0000;
155pub const VA_ENC_PACKED_HEADER_SEQUENCE: u32 = 0x0000_0001;
156pub const VA_ENC_PACKED_HEADER_PICTURE: u32 = 0x0000_0002;
157pub const VA_ENC_PACKED_HEADER_SLICE: u32 = 0x0000_0004;
158pub const VA_ENC_PACKED_HEADER_MISC: u32 = 0x0000_0008;
159pub const VA_ENC_PACKED_HEADER_RAW_DATA: u32 = 0x0000_0010;
160
161// Rate control modes (`va.h:1108-1164`).
162pub const VA_RC_NONE: u32 = 0x0000_0001;
163pub const VA_RC_CBR: u32 = 0x0000_0002;
164pub const VA_RC_VBR: u32 = 0x0000_0004;
165pub const VA_RC_CQP: u32 = 0x0000_0010;
166
167/// `vaCreateContext` flag: sequence contains only progressive frames (`va.h:1919`).
168pub const VA_PROGRESSIVE: c_int = 0x1;
169
170// DRM PRIME memory types and export flags (`va_drmcommon.h:78-94`, `va.h:4130-4150`).
171pub const VA_SURFACE_ATTRIB_MEM_TYPE_VA: u32 = 0x0000_0001;
172pub const VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM: u32 = 0x1000_0000;
173pub const VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME: u32 = 0x2000_0000;
174pub const VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2: u32 = 0x4000_0000;
175
176pub const VA_EXPORT_SURFACE_READ_ONLY: u32 = 0x0001;
177pub const VA_EXPORT_SURFACE_WRITE_ONLY: u32 = 0x0002;
178pub const VA_EXPORT_SURFACE_READ_WRITE: u32 = 0x0003;
179pub const VA_EXPORT_SURFACE_SEPARATE_LAYERS: u32 = 0x0004;
180pub const VA_EXPORT_SURFACE_COMPOSED_LAYERS: u32 = 0x0008;
181
182// FourCCs used by the family (`va.h:4400-4700`).
183pub const VA_FOURCC_NV12: u32 = 0x3231_564e;
184pub const VA_FOURCC_P010: u32 = 0x3031_3050;
185pub const VA_FOURCC_I420: u32 = 0x3032_3449;
186pub const VA_FOURCC_YV12: u32 = 0x3231_5659;
187
188// ---------------------------------------------------------------------------
189// Structs
190// ---------------------------------------------------------------------------
191
192/// `VAConfigAttrib`, `va.h:1155`.
193#[repr(C)]
194#[derive(Debug, Clone, Copy, PartialEq, Eq)]
195pub struct VAConfigAttrib {
196 pub type_: VAConfigAttribType,
197 pub value: u32,
198}
199
200/// The `value` union of `VAGenericValue`, `va.h:1663-1673`.
201///
202/// Only ever read after checking the sibling `type_` discriminant.
203#[repr(C)]
204#[derive(Clone, Copy)]
205pub union VAGenericValueUnion {
206 pub i: i32,
207 pub f: f32,
208 pub p: *mut c_void,
209 pub func: Option<extern "C" fn()>,
210}
211
212/// `VAGenericValue`, `va.h:1661`.
213#[repr(C)]
214#[derive(Clone, Copy)]
215pub struct VAGenericValue {
216 pub type_: VAGenericValueType,
217 pub value: VAGenericValueUnion,
218}
219
220/// `VASurfaceAttrib`, `va.h:1741`.
221#[repr(C)]
222#[derive(Clone, Copy)]
223pub struct VASurfaceAttrib {
224 pub type_: VASurfaceAttribType,
225 pub flags: u32,
226 pub value: VAGenericValue,
227}
228
229/// `VAImageFormat`, `va.h:4712`. `va_reserved` is `VA_PADDING_LOW` = 4 u32s.
230#[repr(C)]
231#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
232pub struct VAImageFormat {
233 pub fourcc: u32,
234 pub byte_order: u32,
235 pub bits_per_pixel: u32,
236 pub depth: u32,
237 pub red_mask: u32,
238 pub green_mask: u32,
239 pub blue_mask: u32,
240 pub alpha_mask: u32,
241 pub va_reserved: [u32; 4],
242}
243
244/// `VAImage`, `va.h:4729`.
245#[repr(C)]
246#[derive(Debug, Clone, Copy)]
247pub struct VAImage {
248 pub image_id: VAImageID,
249 pub format: VAImageFormat,
250 pub buf: VABufferID,
251 pub width: u16,
252 pub height: u16,
253 pub data_size: u32,
254 pub num_planes: u32,
255 pub pitches: [u32; 3],
256 pub offsets: [u32; 3],
257 pub num_palette_entries: i32,
258 pub entry_bytes: i32,
259 pub component_order: [i8; 4],
260 pub va_reserved: [u32; 4],
261}
262
263impl Default for VAImage {
264 fn default() -> Self {
265 // All-zero is a valid "not yet filled" VAImage; `image_id` is
266 // overwritten by vaDeriveImage/vaCreateImage before any use.
267 // SAFETY: every field is a plain integer or array of integers, so the
268 // all-zero bit pattern is a valid value of this type.
269 unsafe { std::mem::zeroed() }
270 }
271}
272
273/// One DRM object of a `VADRMPRIMESurfaceDescriptor`, `va_drmcommon.h:139-147`.
274#[repr(C)]
275#[derive(Debug, Clone, Copy)]
276pub struct VADRMPRIMEObject {
277 pub fd: c_int,
278 pub size: u32,
279 pub drm_format_modifier: u64,
280}
281
282/// One layer of a `VADRMPRIMESurfaceDescriptor`, `va_drmcommon.h:151-164`.
283#[repr(C)]
284#[derive(Debug, Clone, Copy)]
285pub struct VADRMPRIMELayer {
286 pub drm_format: u32,
287 pub num_planes: u32,
288 pub object_index: [u32; 4],
289 pub offset: [u32; 4],
290 pub pitch: [u32; 4],
291}
292
293/// `VADRMPRIMESurfaceDescriptor`, `va_drmcommon.h:130`. Used with
294/// [`VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2`].
295#[repr(C)]
296#[derive(Debug, Clone, Copy)]
297pub struct VADRMPRIMESurfaceDescriptor {
298 pub fourcc: u32,
299 pub width: u32,
300 pub height: u32,
301 pub num_objects: u32,
302 pub objects: [VADRMPRIMEObject; 4],
303 pub num_layers: u32,
304 pub layers: [VADRMPRIMELayer; 4],
305}
306
307impl Default for VADRMPRIMESurfaceDescriptor {
308 fn default() -> Self {
309 // SAFETY: all fields are integers or arrays of integer structs; the
310 // all-zero bit pattern is valid. `fd` = 0 is never treated as an owned
311 // descriptor because `num_objects` = 0 in that state.
312 unsafe { std::mem::zeroed() }
313 }
314}
315
316/// `VARectangle`, `va.h:406`.
317#[repr(C)]
318#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
319pub struct VARectangle {
320 pub x: i16,
321 pub y: i16,
322 pub width: u16,
323 pub height: u16,
324}
325
326// ---------------------------------------------------------------------------
327// Entry points
328// ---------------------------------------------------------------------------
329
330#[link(name = "va")]
331unsafe extern "C" {
332 /// `va.h:403`. Returns a pointer to a static string; never NULL.
333 pub fn vaErrorStr(error_status: VAStatus) -> *const c_char;
334 /// `va.h:453`.
335 pub fn vaDisplayIsValid(dpy: VADisplay) -> c_int;
336 /// `va.h:465`.
337 pub fn vaInitialize(
338 dpy: VADisplay,
339 major_version: *mut c_int,
340 minor_version: *mut c_int,
341 ) -> VAStatus;
342 /// `va.h:474`.
343 pub fn vaTerminate(dpy: VADisplay) -> VAStatus;
344 /// `va.h:486`. Static string owned by the driver, valid until `vaTerminate`.
345 pub fn vaQueryVendorString(dpy: VADisplay) -> *const c_char;
346
347 /// `va.h:1524`.
348 pub fn vaMaxNumProfiles(dpy: VADisplay) -> c_int;
349 /// `va.h:1529`.
350 pub fn vaMaxNumEntrypoints(dpy: VADisplay) -> c_int;
351 /// `va.h:1534`.
352 pub fn vaMaxNumConfigAttributes(dpy: VADisplay) -> c_int;
353 /// `va.h:1544`.
354 pub fn vaQueryConfigProfiles(
355 dpy: VADisplay,
356 profile_list: *mut VAProfile,
357 num_profiles: *mut c_int,
358 ) -> VAStatus;
359 /// `va.h:1556`.
360 pub fn vaQueryConfigEntrypoints(
361 dpy: VADisplay,
362 profile: VAProfile,
363 entrypoint_list: *mut VAEntrypoint,
364 num_entrypoints: *mut c_int,
365 ) -> VAStatus;
366 /// `va.h:1571`. `attrib_list` is in/out: caller sets `type_`, driver fills `value`.
367 pub fn vaGetConfigAttributes(
368 dpy: VADisplay,
369 profile: VAProfile,
370 entrypoint: VAEntrypoint,
371 attrib_list: *mut VAConfigAttrib,
372 num_attribs: c_int,
373 ) -> VAStatus;
374 /// `va.h:1589`.
375 pub fn vaCreateConfig(
376 dpy: VADisplay,
377 profile: VAProfile,
378 entrypoint: VAEntrypoint,
379 attrib_list: *mut VAConfigAttrib,
380 num_attribs: c_int,
381 config_id: *mut VAConfigID,
382 ) -> VAStatus;
383 /// `va.h:1601`.
384 pub fn vaDestroyConfig(dpy: VADisplay, config_id: VAConfigID) -> VAStatus;
385
386 /// `va.h:1868`. Pass NULL `attrib_list` to only query the count.
387 pub fn vaQuerySurfaceAttributes(
388 dpy: VADisplay,
389 config: VAConfigID,
390 attrib_list: *mut VASurfaceAttrib,
391 num_attribs: *mut c_uint,
392 ) -> VAStatus;
393 /// `va.h:1894`.
394 pub fn vaCreateSurfaces(
395 dpy: VADisplay,
396 format: c_uint,
397 width: c_uint,
398 height: c_uint,
399 surfaces: *mut VASurfaceID,
400 num_surfaces: c_uint,
401 attrib_list: *mut VASurfaceAttrib,
402 num_attribs: c_uint,
403 ) -> VAStatus;
404 /// `va.h:1914`.
405 pub fn vaDestroySurfaces(
406 dpy: VADisplay,
407 surfaces: *mut VASurfaceID,
408 num_surfaces: c_int,
409 ) -> VAStatus;
410 /// `va.h:4185`. `descriptor` type is chosen by `mem_type`.
411 pub fn vaExportSurfaceHandle(
412 dpy: VADisplay,
413 surface_id: VASurfaceID,
414 mem_type: u32,
415 flags: u32,
416 descriptor: *mut c_void,
417 ) -> VAStatus;
418
419 /// `va.h:1933`.
420 pub fn vaCreateContext(
421 dpy: VADisplay,
422 config_id: VAConfigID,
423 picture_width: c_int,
424 picture_height: c_int,
425 flag: c_int,
426 render_targets: *mut VASurfaceID,
427 num_render_targets: c_int,
428 context: *mut VAContextID,
429 ) -> VAStatus;
430 /// `va.h:1949`.
431 pub fn vaDestroyContext(dpy: VADisplay, context: VAContextID) -> VAStatus;
432
433 /// `va.h:3833`. `data` NULL means "allocate, fill later via vaMapBuffer".
434 pub fn vaCreateBuffer(
435 dpy: VADisplay,
436 context: VAContextID,
437 type_: VABufferType,
438 size: c_uint,
439 num_elements: c_uint,
440 data: *mut c_void,
441 buf_id: *mut VABufferID,
442 ) -> VAStatus;
443 /// `va.h:3971`.
444 pub fn vaMapBuffer(dpy: VADisplay, buf_id: VABufferID, pbuf: *mut *mut c_void) -> VAStatus;
445 /// `va.h:4004`.
446 pub fn vaUnmapBuffer(dpy: VADisplay, buf_id: VABufferID) -> VAStatus;
447 /// `va.h:4018`.
448 pub fn vaDestroyBuffer(dpy: VADisplay, buffer_id: VABufferID) -> VAStatus;
449
450 /// `va.h:4205`.
451 pub fn vaBeginPicture(
452 dpy: VADisplay,
453 context: VAContextID,
454 render_target: VASurfaceID,
455 ) -> VAStatus;
456 /// `va.h:4214`.
457 pub fn vaRenderPicture(
458 dpy: VADisplay,
459 context: VAContextID,
460 buffers: *mut VABufferID,
461 num_buffers: c_int,
462 ) -> VAStatus;
463 /// `va.h:4229`.
464 pub fn vaEndPicture(dpy: VADisplay, context: VAContextID) -> VAStatus;
465 /// `va.h:4271`. Blocks until the render target is idle.
466 pub fn vaSyncSurface(dpy: VADisplay, render_target: VASurfaceID) -> VAStatus;
467
468 /// `va.h:4773`.
469 pub fn vaMaxNumImageFormats(dpy: VADisplay) -> c_int;
470 /// `va.h:4783`.
471 pub fn vaQueryImageFormats(
472 dpy: VADisplay,
473 format_list: *mut VAImageFormat,
474 num_formats: *mut c_int,
475 ) -> VAStatus;
476 /// `va.h:4796`.
477 pub fn vaCreateImage(
478 dpy: VADisplay,
479 format: *mut VAImageFormat,
480 width: c_int,
481 height: c_int,
482 image: *mut VAImage,
483 ) -> VAStatus;
484 /// `va.h:4807`.
485 pub fn vaDestroyImage(dpy: VADisplay, image: VAImageID) -> VAStatus;
486 /// `va.h:4827`.
487 pub fn vaGetImage(
488 dpy: VADisplay,
489 surface: VASurfaceID,
490 x: c_int,
491 y: c_int,
492 width: c_uint,
493 height: c_uint,
494 image: VAImageID,
495 ) -> VAStatus;
496 /// `va.h:4888`. Zero-copy view of a surface, when the driver allows it.
497 pub fn vaDeriveImage(dpy: VADisplay, surface: VASurfaceID, image: *mut VAImage) -> VAStatus;
498 /// `va.h:4860`. Copies an image into a surface — the encoder upload path.
499 pub fn vaPutImage(
500 dpy: VADisplay,
501 surface: VASurfaceID,
502 image: VAImageID,
503 src_x: c_int,
504 src_y: c_int,
505 src_width: c_uint,
506 src_height: c_uint,
507 dest_x: c_int,
508 dest_y: c_int,
509 dest_width: c_uint,
510 dest_height: c_uint,
511 ) -> VAStatus;
512}
513
514#[link(name = "va-drm")]
515unsafe extern "C" {
516 /// `va_drm.h:45`. Returns NULL on failure. Does **not** take ownership of `fd`.
517 pub fn vaGetDisplayDRM(fd: c_int) -> VADisplay;
518}
519
520// ---------------------------------------------------------------------------
521// ABI transcription check
522// ---------------------------------------------------------------------------
523//
524// Reference output of `crates/ec-va/abi-probe.c` compiled against
525// /usr/include/va (libva 1.23.0) with gcc on x86_64:
526//
527// VAConfigAttrib size=8 align=4 type=0 value=4
528// VAGenericValue size=16 align=8 type=0 value=8
529// VASurfaceAttrib size=24 align=8 type=0 flags=4 value=8
530// VAImageFormat size=48 align=4 fourcc=0 .. va_reserved=32
531// VAImage size=120 align=4 image_id=0 format=4 buf=52
532// width=56 height=58 data_size=60
533// num_planes=64 pitches=68 offsets=80
534// num_palette_entries=92 entry_bytes=96
535// component_order=100 va_reserved=104
536// VADRMPRIMESurfaceDescriptor size=312 align=8 fourcc=0 width=4 height=8
537// num_objects=12 objects=16
538// num_layers=80 layers=84
539// object elem size=16, layer elem size=56
540// VARectangle size=8 align=2
541const _: () = {
542 use std::mem::{align_of, offset_of, size_of};
543
544 assert!(size_of::<VAConfigAttrib>() == 8 && align_of::<VAConfigAttrib>() == 4);
545 assert!(offset_of!(VAConfigAttrib, value) == 4);
546
547 assert!(size_of::<VAGenericValue>() == 16 && align_of::<VAGenericValue>() == 8);
548 assert!(offset_of!(VAGenericValue, value) == 8);
549
550 assert!(size_of::<VASurfaceAttrib>() == 24 && align_of::<VASurfaceAttrib>() == 8);
551 assert!(offset_of!(VASurfaceAttrib, flags) == 4);
552 assert!(offset_of!(VASurfaceAttrib, value) == 8);
553
554 assert!(size_of::<VAImageFormat>() == 48 && align_of::<VAImageFormat>() == 4);
555 assert!(offset_of!(VAImageFormat, va_reserved) == 32);
556
557 assert!(size_of::<VAImage>() == 120 && align_of::<VAImage>() == 4);
558 assert!(offset_of!(VAImage, format) == 4);
559 assert!(offset_of!(VAImage, buf) == 52);
560 assert!(offset_of!(VAImage, width) == 56);
561 assert!(offset_of!(VAImage, height) == 58);
562 assert!(offset_of!(VAImage, data_size) == 60);
563 assert!(offset_of!(VAImage, num_planes) == 64);
564 assert!(offset_of!(VAImage, pitches) == 68);
565 assert!(offset_of!(VAImage, offsets) == 80);
566 assert!(offset_of!(VAImage, num_palette_entries) == 92);
567 assert!(offset_of!(VAImage, entry_bytes) == 96);
568 assert!(offset_of!(VAImage, component_order) == 100);
569 assert!(offset_of!(VAImage, va_reserved) == 104);
570
571 assert!(size_of::<VADRMPRIMEObject>() == 16);
572 assert!(size_of::<VADRMPRIMELayer>() == 56);
573 assert!(
574 size_of::<VADRMPRIMESurfaceDescriptor>() == 312
575 && align_of::<VADRMPRIMESurfaceDescriptor>() == 8
576 );
577 assert!(offset_of!(VADRMPRIMESurfaceDescriptor, objects) == 16);
578 assert!(offset_of!(VADRMPRIMESurfaceDescriptor, num_layers) == 80);
579 assert!(offset_of!(VADRMPRIMESurfaceDescriptor, layers) == 84);
580
581 assert!(size_of::<VARectangle>() == 8 && align_of::<VARectangle>() == 2);
582
583 // Assumption 2: C `enum` and `unsigned int` are both 4 bytes here.
584 assert!(size_of::<VAStatus>() == 4);
585 assert!(size_of::<VAGenericID>() == 4);
586 assert!(size_of::<c_int>() == 4);
587};