Skip to main content

vpl_sys/
consts.rs

1//! Hand-transcribed oneVPL numeric constants.
2//!
3//! Every value here is copied verbatim from the vendored headers under
4//! `vendor/api/vpl/` (pinned commit — see `vendor/README.md`), cited by file
5//! and (approximate) line. These are plain C `enum { NAME = value, ... };`
6//! blocks that are **not** attached to a named/typedef'd type `bindgen` would
7//! pick up under this crate's `allowlist_type("_?mfx.*")` filter (see
8//! `build.rs`), so they are transcribed by hand instead of generated — a
9//! small, closed, independently-checkable set.
10
11use crate::raw::mfxStatus;
12
13// ---- mfxdefs.h: mfxStatus (status/error codes) ----------------------------
14// Only the subset this crate's Stage 1 CPU-upload encode path actually checks.
15
16/// No error. (`mfxdefs.h`)
17pub const MFX_ERR_NONE: mfxStatus = 0;
18/// Unknown error. (`mfxdefs.h`)
19pub const MFX_ERR_UNKNOWN: mfxStatus = -1;
20/// Null pointer. (`mfxdefs.h`)
21pub const MFX_ERR_NULL_PTR: mfxStatus = -2;
22/// Unsupported feature. (`mfxdefs.h`)
23pub const MFX_ERR_UNSUPPORTED: mfxStatus = -3;
24/// Failed to allocate memory. (`mfxdefs.h`)
25pub const MFX_ERR_MEMORY_ALLOC: mfxStatus = -4;
26/// Insufficient buffer at input/output. (`mfxdefs.h`)
27pub const MFX_ERR_NOT_ENOUGH_BUFFER: mfxStatus = -5;
28/// Invalid handle. (`mfxdefs.h`)
29pub const MFX_ERR_INVALID_HANDLE: mfxStatus = -6;
30/// Member function called before initialization. (`mfxdefs.h`)
31pub const MFX_ERR_NOT_INITIALIZED: mfxStatus = -8;
32/// Expect more data at input — not a hard failure; the caller has not fed
33/// enough frames yet for a packet to be ready. (`mfxdefs.h`)
34pub const MFX_ERR_MORE_DATA: mfxStatus = -10;
35/// Expect more surface at output. (`mfxdefs.h`)
36pub const MFX_ERR_MORE_SURFACE: mfxStatus = -11;
37/// Lost the hardware acceleration device. (`mfxdefs.h`)
38pub const MFX_ERR_DEVICE_LOST: mfxStatus = -13;
39/// Incompatible video parameters. (`mfxdefs.h`)
40pub const MFX_ERR_INCOMPATIBLE_VIDEO_PARAM: mfxStatus = -14;
41/// Invalid video parameters. (`mfxdefs.h`)
42pub const MFX_ERR_INVALID_VIDEO_PARAM: mfxStatus = -15;
43/// Device operation failure caused by GPU hang. (`mfxdefs.h`)
44pub const MFX_ERR_GPU_HANG: mfxStatus = -21;
45/// The previous asynchronous operation is in execution — not a hard failure.
46/// (`mfxdefs.h`)
47pub const MFX_WRN_IN_EXECUTION: mfxStatus = 1;
48/// The hardware acceleration device is busy — retry. (`mfxdefs.h`)
49pub const MFX_WRN_DEVICE_BUSY: mfxStatus = 2;
50/// Software acceleration is used (no real HW path) — the caller should treat
51/// this as a degraded-but-successful `Init`, not a failure. (`mfxdefs.h`)
52pub const MFX_WRN_PARTIAL_ACCELERATION: mfxStatus = 4;
53/// Incompatible video parameters (non-fatal — the library adjusted them).
54/// (`mfxdefs.h`)
55pub const MFX_WRN_INCOMPATIBLE_VIDEO_PARAM: mfxStatus = 5;
56
57/// `true` for any `MFX_ERR_*`/`MFX_WRN_*` value this crate treats as "the call
58/// itself succeeded" (`MFX_ERR_NONE` or a positive `MFX_WRN_*` warning code).
59#[must_use]
60pub const fn mfx_succeeded(status: mfxStatus) -> bool {
61    status >= MFX_ERR_NONE
62}
63
64// ---- mfxcommon.h: mfxIMPL (implementation selector) ------------------------
65// `typedef mfxI32 mfxIMPL;` values, `mfxcommon.h` ~line 100-121.
66
67/// A single specific hardware implementation. (`mfxcommon.h`)
68///
69/// **Do not pass this alone to `MFXInitEx` against a directly-loaded
70/// implementation library** (this crate's MVP dispatcher, bypassing the real
71/// oneVPL dispatcher — see `dispatcher` module docs): hardware-confirmed on
72/// this workspace's Intel UHD 770 to return `MFX_ERR_UNSUPPORTED` from
73/// `libmfxhw64.dll`. Use [`MFX_IMPL_HARDWARE_ANY`] instead — see that
74/// constant's docs for why.
75pub const MFX_IMPL_HARDWARE: i32 = 0x0002;
76/// Any hardware implementation, unconstrained — **this crate's session-open
77/// implementation selector**. (`mfxcommon.h`)
78///
79/// Hardware-confirmed on this workspace's Intel UHD 770
80/// (`libmfxhw64.dll`/`libvpl.dll`'s `MFXInitEx` compat shim, both tried): the
81/// "any" wildcard (`0x0004`) succeeds where the specific-adapter selector
82/// [`MFX_IMPL_HARDWARE`] (`0x0002`) returns `MFX_ERR_UNSUPPORTED`, with or
83/// without [`MFX_IMPL_VIA_D3D11`] additionally OR'd in — plausibly because
84/// the real oneVPL dispatcher normally resolves "the specific hardware
85/// adapter" *before* calling into an implementation library, a resolution
86/// step this crate's MVP dispatcher does not perform (see `dispatcher`
87/// module docs). Not documented anywhere upstream; discovered empirically by
88/// sweeping every `MFX_IMPL_*`/`MFX_IMPL_VIA_*` combination against real
89/// hardware (`vpl-sys/src/dispatcher_tests.rs`'s hardware-gated test).
90pub const MFX_IMPL_HARDWARE_ANY: i32 = 0x0004;
91/// Acceleration-mode bit: use `Direct3D11` for hardware acceleration.
92/// (`mfxcommon.h`)
93///
94/// OR into [`MFX_IMPL_HARDWARE_ANY`] for `MFXInitEx`. Hardware-confirmed:
95/// **optional** for session creation itself (`MFX_IMPL_HARDWARE_ANY` alone
96/// also succeeds on this workspace's Intel UHD 770) but kept explicit for
97/// this crate's Stage 1 CPU-upload path since the runtime's internal
98/// hardware encode block always goes through a D3D11 acceleration context on
99/// Windows regardless of whether input surfaces are system- or video-memory.
100pub const MFX_IMPL_VIA_D3D11: i32 = 0x0300;
101
102// ---- mfxstructures.h: ColorFourCC / CodecFormatFourCC ----------------------
103// `#define MFX_MAKEFOURCC(A,B,C,D) ((int)A + ((int)B<<8) + ((int)C<<16) + ((int)D<<24))`
104// (`mfxcommon.h` line 20). Computed here via the identical formula, not pasted
105// as a magic number, so the derivation stays checkable against the header.
106
107const fn make_fourcc(a: u8, b: u8, c: u8, d: u8) -> u32 {
108    (a as u32) | ((b as u32) << 8) | ((c as u32) << 16) | ((d as u32) << 24)
109}
110
111/// AVC / H.264 codec ID. (`mfxstructures.h` line ~1142)
112pub const MFX_CODEC_AVC: u32 = make_fourcc(b'A', b'V', b'C', b' ');
113/// HEVC / H.265 codec ID. (`mfxstructures.h` line 1143)
114pub const MFX_CODEC_HEVC: u32 = make_fourcc(b'H', b'E', b'V', b'C');
115/// AV1 codec ID. (`mfxstructures.h` line 1148)
116pub const MFX_CODEC_AV1: u32 = make_fourcc(b'A', b'V', b'1', b' ');
117/// NV12 color format. (`mfxstructures.h` line ~162)
118pub const MFX_FOURCC_NV12: u32 = make_fourcc(b'N', b'V', b'1', b'2');
119
120// ---- mfxstructures.h: PicStruct / ChromaFormat -----------------------------
121
122/// Progressive picture. (`mfxstructures.h` line 247)
123pub const MFX_PICSTRUCT_PROGRESSIVE: u16 = 0x01;
124/// 4:2:0 chroma sampling. (`mfxstructures.h` line 265)
125pub const MFX_CHROMAFORMAT_YUV420: u16 = 1;
126
127// ---- mfxstructures.h: CodecProfile / CodecLevel (AVC) ----------------------
128
129/// AVC Baseline profile. (`mfxstructures.h` line 1172)
130pub const MFX_PROFILE_AVC_BASELINE: u16 = 66;
131/// AVC level 4.1 (covers up to 1080p30-ish; ample for this stage's test sizes).
132/// (`mfxstructures.h` line 1207)
133pub const MFX_LEVEL_AVC_41: u16 = 41;
134
135// ---- mfxstructures.h: CodecProfile / CodecLevel (HEVC) ---------------------
136
137/// HEVC Main (8-bit 4:2:0) profile. (`mfxstructures.h` line 1263)
138pub const MFX_PROFILE_HEVC_MAIN: u16 = 1;
139/// HEVC level 4.1 — matches this crate's AVC 4.1 choice, ample for this
140/// stage's test sizes. (`mfxstructures.h` line 1278)
141pub const MFX_LEVEL_HEVC_41: u16 = 41;
142
143// ---- mfxstructures.h: CodecProfile / CodecLevel (AV1) ----------------------
144
145/// AV1 Main profile. (`mfxstructures.h` line 1304)
146pub const MFX_PROFILE_AV1_MAIN: u16 = 1;
147/// AV1 level 4.1. (`mfxstructures.h` line 1320)
148pub const MFX_LEVEL_AV1_41: u16 = 41;
149
150// ---- mfxstructures.h: TargetUsage ------------------------------------------
151
152/// Balanced quality/speed target usage (`MFX_TARGETUSAGE_4`). (`mfxstructures.h`
153/// line ~1396-1406)
154pub const MFX_TARGETUSAGE_BALANCED: u16 = 4;
155
156// ---- mfxstructures.h: RateControlMethod ------------------------------------
157
158/// Constant bitrate. (`mfxstructures.h` line 1412)
159pub const MFX_RATECONTROL_CBR: u16 = 1;
160/// Constant QP. (`mfxstructures.h` line 1414)
161pub const MFX_RATECONTROL_CQP: u16 = 3;
162
163// ---- mfxstructures.h: IOPattern ---------------------------------------------
164
165/// Input is a linear buffer directly in system memory (CPU-upload path — this
166/// crate's only Stage 1 path). (`mfxstructures.h` line 1135)
167pub const MFX_IOPATTERN_IN_SYSTEM_MEMORY: u16 = 0x02;
168
169// ---- mfxstructures.h: FrameType flags --------------------------------------
170
171/// I-frame. (`mfxstructures.h` line 2984)
172pub const MFX_FRAMETYPE_I: u16 = 0x0001;
173/// Reference frame. (`mfxstructures.h` line 2989)
174pub const MFX_FRAMETYPE_REF: u16 = 0x0040;
175/// IDR frame. (`mfxstructures.h` line 2990)
176pub const MFX_FRAMETYPE_IDR: u16 = 0x0080;
177
178// ---- mfxstructures.h: mfxHandleType -----------------------------------------
179
180/// Pointer to `ID3D11Device`.
181///
182/// **Not used by this crate's Stage 1 CPU-upload path**; kept for the
183/// documented future Zero-Copy D3D11 work (see
184/// `mediaway-encoder-quicksync/adr/0001`). (`mfxstructures.h` line 437)
185pub const MFX_HANDLE_D3D11_DEVICE: u32 = 3;
186
187// ---- mfxcommon.h: GPUCopy -----------------------------------------------------
188
189/// Default GPU-copy hinting (let the runtime decide). (`mfxcommon.h` line 190)
190pub const MFX_GPUCOPY_DEFAULT: u16 = 0;