Files
filmcraft/crates/platform/tests/amf_probe.rs
T
00xJ0 2e92e5ed65 #880: AMF bindings from the AMF SDK headers, with checks, declines and HDR colour
Addresses the re-review at af71828b: AMD's notice, the SDK version and
an ATTRIBUTION row for amf/ffi.rs, ABI tests against the v1.5.3 headers
(AmfVariant is 8-byte aligned); private ffi / session modules and no
device.rs; null, pitch and size checks before writes, and every AMF
object released on every path; the same declines as NVENC; colour
properties and HDR10 metadata for HEVC and AV1; an av1C from the
sequence header; and H.264 / H.265 left to NVENC where it is present.
2026-11-17 17:33:54 -07:00

80 lines
2.5 KiB
Rust

//! AMD AMF hardware encoder integration tests.
#![cfg(target_os = "windows")]
use filmcraft_platform::amf::{Config, Profile, Session, av1_available, av1_hdr_available, hevc_available, hevc_hdr_available};
#[test]
fn test_amf_safe_session_h264() {
let cfg = Config {
width: 320,
height: 240,
fps: (30, 1),
bitrate_kbps: 1000,
max_bitrate_kbps: 1500,
cbr: false,
keyint: 30,
profile: Profile::H264High,
signal: Default::default(),
};
let mut session = match Session::open(&cfg) {
Ok(s) => s,
Err(e) => {
eprintln!("AMF H.264 Session::open skipped/failed: {e}");
return;
}
};
let y = vec![128u8; 320 * 240];
let u = vec![128u8; 160 * 120];
let v = vec![128u8; 160 * 120];
let mut total_packets = 0;
for i in 0..5 {
let pkts = session.encode_8bit(&y, &u, &v, i * 333_333, 333_333).unwrap();
total_packets += pkts.len();
}
let drain_pkts = session.drain().unwrap();
total_packets += drain_pkts.len();
println!("Total H.264 packets from safe AMF Session: {total_packets}");
assert!(total_packets >= 5);
}
#[test]
fn test_amf_safe_session_hevc() {
if !hevc_available() {
eprintln!("No AMD AMF HEVC encoder on this system, skipping test.");
return;
}
// Match the capability probe: some AMD runtimes reject smaller HEVC pictures.
let cfg = Config {
width: 640,
height: 360,
fps: (30, 1),
bitrate_kbps: 1000,
max_bitrate_kbps: 1500,
cbr: false,
keyint: 30,
profile: Profile::HevcMain,
signal: Default::default(),
};
let mut session = Session::open(&cfg).expect("AMF HEVC session failed after a successful capability probe");
let y = vec![128u8; 640 * 360];
let u = vec![128u8; 320 * 180];
let v = vec![128u8; 320 * 180];
let mut total_packets = 0;
for i in 0..5 {
let pkts = session.encode_8bit(&y, &u, &v, i * 333_333, 333_333).unwrap();
total_packets += pkts.len();
}
let drain_pkts = session.drain().unwrap();
total_packets += drain_pkts.len();
println!("Total HEVC packets from safe AMF Session: {total_packets}");
assert!(total_packets >= 5);
}
#[test]
fn test_amf_probes() {
println!("AMF hevc_available: {}", hevc_available());
println!("AMF hevc_hdr_available: {}", hevc_hdr_available());
println!("AMF av1_available: {}", av1_available());
println!("AMF av1_hdr_available: {}", av1_hdr_available());
}