#![forbid(unsafe_code)]
mod error;
pub use error::{Error, Result};
pub mod bits;
pub mod cabac;
pub mod ctu;
pub mod decoder;
pub mod filters;
pub mod frame;
pub mod intra;
pub mod itx;
mod mcscratch;
pub mod md5;
pub mod nal;
pub mod pic;
#[cfg(feature = "prof")]
pub mod prof;
#[macro_export]
macro_rules! prof_scope {
($stage:expr) => {
#[cfg(feature = "prof")]
let _prof_guard = $crate::prof::Scope::new($stage);
};
}
pub mod ps;
pub mod sei;
pub mod slice;
pub mod tables;
pub use rusty_h265_accel as accel;
pub use decoder::{Decoder, Stats};
pub use frame::{Frame, Picture, Plane};
#[cfg(test)]
mod silent_zero_guards {
use std::path::{Path, PathBuf};
fn rust_sources() -> Vec<PathBuf> {
let root = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap();
let mut out = Vec::new();
let mut stack = vec![root.join("rusty_h265"), root.join("rusty_h265-accel")];
while let Some(dir) = stack.pop() {
let Ok(entries) = std::fs::read_dir(&dir) else { continue };
for e in entries.flatten() {
let p = e.path();
if p.is_dir() {
stack.push(p);
} else if p.extension().is_some_and(|x| x == "rs") {
out.push(p);
}
}
}
out
}
#[test]
fn every_census_counter_is_actually_incremented() {
let files = rust_sources();
assert!(files.len() > 5, "source walk found nothing; the guard would pass vacuously");
let lib = files
.iter()
.find(|p| p.ends_with("rusty_h265-accel/src/lib.rs") || p.to_string_lossy().replace('\\', "/").ends_with("rusty_h265-accel/src/lib.rs"))
.expect("accel lib.rs");
let decl = std::fs::read_to_string(lib).unwrap();
let start = decl.find("counters!(").expect("counters! macro");
let end = decl[start..].find("\n );").expect("end of counters!") + start;
let names: Vec<String> = decl[start..end]
.lines()
.map(|l| l.trim().trim_end_matches(',').to_string())
.filter(|l| !l.is_empty() && l.chars().all(|c| c.is_ascii_uppercase() || c.is_ascii_digit() || c == '_'))
.collect();
assert!(names.len() > 20, "expected the full census, found {}", names.len());
let mut bodies = String::new();
for p in &files {
let t = std::fs::read_to_string(p).unwrap_or_default();
if std::ptr::eq(p, lib) {
bodies.push_str(&t[..start]);
bodies.push_str(&t[end..]);
} else {
bodies.push_str(&t);
}
}
let dead: Vec<&String> = names.iter().filter(|n| !bodies.contains(n.as_str())).collect();
assert!(
dead.is_empty(),
"census counters declared but never incremented — each reads 0 forever, \
and a 0 is indistinguishable from a cold path: {dead:?}"
);
}
#[test]
fn census_predicates_consult_the_same_switches_as_the_dispatch() {
for p in rust_sources() {
let t = std::fs::read_to_string(&p).unwrap_or_default();
for (i, line) in t.lines().enumerate() {
if line.contains("if ok") && line.contains("scalar_gate()") {
let lo = i.saturating_sub(12);
let window: String = t.lines().skip(lo).take(i - lo).collect::<Vec<_>>().join("\n");
if window.contains("let simd =") {
assert!(
window.contains("scalar_gate()"),
"{}:{}: dispatch consults `scalar_gate()` but the census \
predicate above it does not — the counter will report an \
arm that never ran",
p.display(),
i + 1
);
}
}
}
}
}
}