#![allow(
clippy::unwrap_used,
clippy::expect_used,
clippy::print_stderr,
reason = "test modules may unwrap / print"
)]
use super::*;
use crate::VideoInputPreference;
use mediaway_common::{CodecKind, PixelFormat, Rational, VideoFrameStorage};
#[test]
fn open_rejects_zero_copy_gpu_this_stage() {
let config = VideoEncoderConfig {
codec: CodecKind::H264,
width: 176,
height: 144,
time_base: Rational::new(1, 30),
bitrate_bps: 0,
pixel_format: PixelFormat::Nv12,
input: VideoInputPreference::ZeroCopyGpu,
gpu_device: None,
};
assert!(matches!(
QuickSyncVideoEncoder::open(&config),
Err(EncodeError::Unsupported)
));
}
#[test]
fn public_api_real_encode_or_skips() {
let width = 176u32;
let height = 144u32;
let config = VideoEncoderConfig {
codec: CodecKind::H264,
width,
height,
time_base: Rational::new(1, 30),
bitrate_bps: 500_000,
pixel_format: PixelFormat::Nv12,
input: VideoInputPreference::CpuUploadOk,
gpu_device: None,
};
let mut encoder = match QuickSyncVideoEncoder::open(&config) {
Ok(e) => e,
Err(e) => {
eprintln!("skip: QuickSyncVideoEncoder::open failed ({e:?}) — no oneVPL runtime?");
return;
}
};
let plane = (width as usize) * (height as usize);
let mut data = vec![0u8; plane + plane / 2];
data[plane..].fill(128);
for i in 0..8i64 {
let frame = VideoFrame {
pts: i,
duration: 1,
width,
height,
format: PixelFormat::Nv12,
storage: VideoFrameStorage::Cpu {
data: Bytes::from(data.clone()),
},
};
encoder
.push_frame(&frame)
.expect("push_frame should succeed against real hardware");
}
encoder.flush().expect("flush should succeed");
let mut count = 0usize;
while let Some(_p) = encoder.poll_packet().expect("poll_packet should not error") {
count += 1;
}
assert!(count > 0, "expected at least one real encoded packet");
eprintln!("mediaway-encoder-quicksync: public API real encode produced {count} packet(s)");
}