forge
Explore
Log in

Don't you dare go Hollow

ec-hw golden_hw: add VA-direct decode pass over the same 8 fixtures; zero-pad frame indices to 4 digits

Browse files at this commit

79e4a4f65729676baf9fbcbf48288f94874ff4ccAhmet Kaan GümüşParent: 74a46ce
crates/ec-hw/examples/golden_hw.rsmodified+99 -5
@@ -2,9 +2,9 @@ use std::fs;
22 use std::panic::{self, AssertUnwindSafe};
33
44 use ec_hw::{
5- Backend, Capability, Codec, CodecProfile, CodedFrame, Direction, EncCodec, EncodeInput,
6- EncoderConfig, FrameMetadata, HwDecoder, HwEncoder, HwPicture, I420, I420_16, RateControlMode,
7- RgbFrame, RgbOrder, capabilities,
5+ Backend, Capability, Codec, CodecProfile, CodedFrame, Decoder as VaDecoder, Direction,
6+ EncCodec, EncodeInput, EncoderConfig, Frame, FrameMetadata, HwDecoder, HwEncoder, HwPicture,
7+ I420, I420_16, RateControlMode, RgbFrame, RgbOrder, capabilities,
88 };
99 use sha2::{Digest, Sha256};
1010
@@ -252,7 +252,7 @@ fn encode_case(
252252 .map_err(|e| e.to_string())?;
253253 Ok(coded
254254 .iter()
255- .map(|c| format!("{label}/{}\t{}", c.timestamp, sha_hex(&c.data)))
255+ .map(|c| format!("{label}/{:04}\t{}", c.timestamp, sha_hex(&c.data)))
256256 .collect())
257257 }
258258
@@ -310,13 +310,105 @@ fn drain(decoder: &mut HwDecoder, prefix: &str, lines: &mut Vec<String>) -> Resu
310310 while let Some(picture) = decoder.next_picture().map_err(|e| e.to_string())? {
311311 let index = lines.len();
312312 lines.push(format!(
313- "{prefix}/{index}\t{}",
313+ "{prefix}/{index:04}\t{}",
314314 sha_hex(&picture_bytes(&picture)?)
315315 ));
316316 }
317317 Ok(())
318318 }
319319
320+fn split_access_units(data: &[u8], codec: Codec) -> Vec<&[u8]> {
321+ let mut starts: Vec<usize> = Vec::new();
322+ let mut seen_slice = false;
323+ let mut i = 0usize;
324+ while i + 3 < data.len() {
325+ if data[i] != 0 || data[i + 1] != 0 || data[i + 2] != 1 {
326+ i += 1;
327+ continue;
328+ }
329+ let nal = i + 3;
330+ let (is_vcl, first_slice) = match codec {
331+ Codec::H264 => {
332+ let t = data[nal] & 0x1f;
333+ let first = data.get(nal + 1).is_some_and(|&b| b & 0x80 != 0);
334+ ((1..=5).contains(&t), first)
335+ }
336+ _ => {
337+ let t = (data[nal] >> 1) & 0x3f;
338+ let first = data.get(nal + 2).is_some_and(|&b| b & 0x80 != 0);
339+ (t <= 31, first)
340+ }
341+ };
342+ if is_vcl {
343+ if seen_slice && first_slice {
344+ starts.push(i);
345+ seen_slice = false;
346+ }
347+ if first_slice {
348+ seen_slice = true;
349+ }
350+ }
351+ i = nal + 1;
352+ }
353+ let mut out = Vec::new();
354+ let mut prev = 0usize;
355+ for &start in &starts {
356+ out.push(&data[prev..start]);
357+ prev = start;
358+ }
359+ if prev < data.len() {
360+ out.push(&data[prev..]);
361+ }
362+ out
363+}
364+
365+fn va_access_units(codec: Codec, data: &[u8]) -> Vec<&[u8]> {
366+ match codec {
367+ Codec::H264 | Codec::H265 => split_access_units(data, codec),
368+ Codec::Vp9 | Codec::Av1 => ivf_units(data),
369+ }
370+}
371+
372+fn frame_bytes(frame: &Frame) -> Result<Vec<u8>, String> {
373+ if frame.bit_depth > 8 {
374+ let f = frame.to_i420_16().map_err(|e| e.to_string())?;
375+ Ok([f.y, f.u, f.v]
376+ .concat()
377+ .iter()
378+ .flat_map(|s| s.to_le_bytes())
379+ .collect())
380+ } else {
381+ let f = frame.to_i420().map_err(|e| e.to_string())?;
382+ Ok([f.y, f.u, f.v].concat())
383+ }
384+}
385+
386+fn va_drain(decoder: &mut VaDecoder, prefix: &str, lines: &mut Vec<String>) -> Result<(), String> {
387+ while let Some(frame) = decoder.next_frame() {
388+ let index = lines.len();
389+ lines.push(format!(
390+ "{prefix}/{index:04}\t{}",
391+ sha_hex(&frame_bytes(&frame)?)
392+ ));
393+ }
394+ Ok(())
395+}
396+
397+fn va_decode_case(name: &str, codec: Codec, rel: &str) -> Outcome {
398+ let display = ec_va::open().map_err(|e| e.to_string())?;
399+ let data = fs::read(ec_testkit::fixture(rel)).map_err(|e| e.to_string())?;
400+ let mut decoder = VaDecoder::new(&display, codec).map_err(|e| e.to_string())?;
401+ let prefix = format!("hw/dec/va/{name}/{rel}");
402+ let mut lines = Vec::new();
403+ for (ts, unit) in va_access_units(codec, &data).into_iter().enumerate() {
404+ decoder.decode(unit, ts as i64).map_err(|e| e.to_string())?;
405+ va_drain(&mut decoder, &prefix, &mut lines)?;
406+ }
407+ decoder.flush().map_err(|e| e.to_string())?;
408+ va_drain(&mut decoder, &prefix, &mut lines)?;
409+ Ok(lines)
410+}
411+
320412 fn decode_case(name: &str, codec: Codec, rel: &str) -> Outcome {
321413 let data = fs::read(ec_testkit::fixture(rel)).map_err(|e| e.to_string())?;
322414 let mut decoder = HwDecoder::open(codec).map_err(|e| e.to_string())?;
@@ -376,6 +468,8 @@ fn main() {
376468 for (name, codec, rel) in DECODERS {
377469 let label = format!("hw/dec/{name}/{rel}");
378470 guard(&label, &|| decode_case(name, codec, rel), &mut out);
471+ let va_label = format!("hw/dec/va/{name}/{rel}");
472+ guard(&va_label, &|| va_decode_case(name, codec, rel), &mut out);
379473 }
380474 out.sort();
381475 for line in out {