forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB8a5feaaTahinli2 months ago3162 commits

lib.rs73 lines, 2.2 KiBHistoryRawDownload
1//! Native VP8 (RFC 6386) decoder — the future replacement for edith's
2//! runtime-dlopen'd libvpx seat.
3//!
4//! The crate is written from the specification ([RFC 6386]) alone; libvpx's
5//! output is used only as a test oracle (sample-exactness witnesses), never
6//! as code to port. Every module documents the spec section it implements.
7//!
8//! [RFC 6386]: https://www.rfc-editor.org/rfc/rfc6386
9//!
10//! # Unsafe
11//!
12//! This crate contains no `unsafe` code.
13
14#![deny(unsafe_code)]
15#![warn(missing_docs)]
16
17pub mod bool;
18pub mod decode;
19pub mod frame;
20pub mod header;
21pub mod intra;
22pub mod loopfilter;
23mod mc;
24pub mod modes;
25pub mod stream;
26pub mod tables;
27pub mod tokens;
28pub mod transform;
29
30pub use ec_core::{Error, Result};
31pub use header::PersistedState;
32
33/// Whether `EC_VP8_TRACE` decision tracing is enabled, resolved once per
34/// process. A `var_os` per bool read was 46% of the decode profile (each
35/// call locks std's ENV lock and allocates); `OnceLock::get_or_init` was
36/// no better, so the hot path is a single relaxed atomic load.
37pub(crate) fn trace_enabled() -> bool {
38 use std::sync::atomic::{AtomicU8, Ordering};
39 static STATE: AtomicU8 = AtomicU8::new(0);
40 match STATE.load(Ordering::Relaxed) {
41 0 => {
42 let on = std::env::var_os("EC_VP8_TRACE").is_some();
43 STATE.store(if on { 2 } else { 1 }, Ordering::Relaxed);
44 on
45 }
46 1 => false,
47 _ => true,
48 }
49}
50
51/// Cached AVX2 availability for the explicit-SIMD kernels (`mc`).
52#[cfg(target_arch = "x86_64")]
53pub(crate) fn avx2_supported() -> bool {
54 static AVX2: std::sync::LazyLock<bool> =
55 std::sync::LazyLock::new(|| std::arch::is_x86_feature_detected!("avx2"));
56 *AVX2
57}
58
59/// Whether `EC_VP8_DEBUG` per-macroblock dumps are enabled (same shape as
60/// [`trace_enabled`]; the check sits in the per-MB reconstruct path).
61pub(crate) fn debug_enabled() -> bool {
62 use std::sync::atomic::{AtomicU8, Ordering};
63 static STATE: AtomicU8 = AtomicU8::new(0);
64 match STATE.load(Ordering::Relaxed) {
65 0 => {
66 let on = std::env::var_os("EC_VP8_DEBUG").is_some();
67 STATE.store(if on { 2 } else { 1 }, Ordering::Relaxed);
68 on
69 }
70 1 => false,
71 _ => true,
72 }
73}