Commit b9fef7ce authored by Thomas Daede's avatar Thomas Daede

Bring back desync_finder from the dead.

Activate it with feature=desync_finder rather than debug.

Print to stdout rather than stderr because the latter deadlocks.
parent b02c36e5
......@@ -16,6 +16,7 @@ default = ["binaries", "nasm"]
nasm = ["nasm-rs"]
dump_ivf = ["ivf"]
quick_test = []
desync_finder = []
[dependencies]
arg_enum_proc_macro = "0.1.1"
......
......@@ -1872,20 +1872,20 @@ impl FieldMap {
for (name, start, end) in &self.map {
// eprintln!("{} {} {} val {}", name, start, end, addr);
if addr >= *start && addr < *end {
eprintln!(" CDF {}", name);
eprintln!("");
println!(" CDF {}", name);
println!();
return;
}
}
eprintln!(" CDF address not found {}", addr);
println!(" CDF address not found {}", addr);
}
}
macro_rules! symbol_with_update {
($self:ident, $w:ident, $s:expr, $cdf:expr) => {
$w.symbol_with_update($s, $cdf);
#[cfg(debug)] {
#[cfg(feature = "desync_finder")] {
if let Some(map) = $self.fc_map.as_ref() {
map.lookup($cdf.as_ptr() as usize);
}
......@@ -1916,7 +1916,7 @@ pub struct ContextWriterCheckpoint {
pub struct ContextWriter<'a> {
pub bc: BlockContext<'a>,
pub fc: &'a mut CDFContext,
#[cfg(debug)]
#[cfg(feature = "desync_finder")]
fc_map: Option<FieldMap> // For debugging purposes
}
......@@ -1927,10 +1927,10 @@ impl<'a> ContextWriter<'a> {
let mut cw = ContextWriter {
fc,
bc,
#[cfg(debug)]
#[cfg(feature = "desync_finder")]
fc_map: Default::default()
};
#[cfg(debug)] {
#[cfg(feature = "desync_finder")] {
if std::env::var_os("RAV1E_DEBUG").is_some() {
cw.fc_map = Some(FieldMap {
map: cw.fc.build_map()
......@@ -3647,20 +3647,15 @@ impl<'a> ContextWriter<'a> {
1
};
symbol_with_update!(
self,
w,
eob_pt - 1,
match eob_multi_size {
0 => &mut self.fc.eob_flag_cdf16[plane_type][eob_multi_ctx],
1 => &mut self.fc.eob_flag_cdf32[plane_type][eob_multi_ctx],
2 => &mut self.fc.eob_flag_cdf64[plane_type][eob_multi_ctx],
3 => &mut self.fc.eob_flag_cdf128[plane_type][eob_multi_ctx],
4 => &mut self.fc.eob_flag_cdf256[plane_type][eob_multi_ctx],
5 => &mut self.fc.eob_flag_cdf512[plane_type][eob_multi_ctx],
_ => &mut self.fc.eob_flag_cdf1024[plane_type][eob_multi_ctx],
}
);
match eob_multi_size {
0 => { symbol_with_update!(self, w, eob_pt - 1, &mut self.fc.eob_flag_cdf16[plane_type][eob_multi_ctx]); },
1 => { symbol_with_update!(self, w, eob_pt - 1, &mut self.fc.eob_flag_cdf32[plane_type][eob_multi_ctx]); },
2 => { symbol_with_update!(self, w, eob_pt - 1, &mut self.fc.eob_flag_cdf64[plane_type][eob_multi_ctx]); },
3 => { symbol_with_update!(self, w, eob_pt - 1, &mut self.fc.eob_flag_cdf128[plane_type][eob_multi_ctx]); },
4 => { symbol_with_update!(self, w, eob_pt - 1, &mut self.fc.eob_flag_cdf256[plane_type][eob_multi_ctx]); },
5 => { symbol_with_update!(self, w, eob_pt - 1, &mut self.fc.eob_flag_cdf512[plane_type][eob_multi_ctx]); },
_ => { symbol_with_update!(self, w, eob_pt - 1, &mut self.fc.eob_flag_cdf1024[plane_type][eob_multi_ctx]); },
}
let eob_offset_bits = k_eob_offset_bits[eob_pt as usize];
......@@ -3815,7 +3810,7 @@ impl<'a> ContextWriter<'a> {
pub fn rollback(&mut self, checkpoint: &ContextWriterCheckpoint) {
*self.fc = checkpoint.fc;
self.bc.rollback(&checkpoint.bc);
#[cfg(debug)] {
#[cfg(feature = "desync_finder")] {
if self.fc_map.is_some() {
self.fc_map = Some(FieldMap {
map: self.fc.build_map()
......
......@@ -303,7 +303,7 @@ impl<S> WriterBase<S> {
/// Internal constructor called by the subtypes that implement the
/// actual encoder and Recorder.
fn new(storage: S) -> Self {
WriterBase { rng: 0x8000, cnt: -9, debug: false, fake_bits_frac: 0, s: storage }
WriterBase { rng: 0x8000, cnt: -9, debug: std::env::var_os("RAV1E_DEBUG").is_some(), fake_bits_frac: 0, s: storage }
}
/// Compute low and range values from token cdf values and local state
......@@ -409,7 +409,7 @@ impl<S> WriterBase<S> {
}
}
#[cfg(debug)]
#[cfg(feature = "desync_finder")]
fn print_backtrace(&self, s: u32) {
let mut depth = 3;
backtrace::trace(|frame| {
......@@ -420,7 +420,7 @@ impl<S> WriterBase<S> {
if depth == 0 {
backtrace::resolve(ip, |symbol| {
if let Some(name) = symbol.name() {
eprintln!("Writing symbol {} from {}", s, name);
println!("Writing symbol {} from {}", s, name);
}
});
false
......@@ -551,7 +551,7 @@ where
/// must be exactly 32768. There should be at most 16 values.
fn symbol_with_update(&mut self, s: u32, cdf: &mut [u16]) {
let nsymbs = cdf.len() - 1;
#[cfg(debug)]
#[cfg(feature = "desync_finder")]
{
if self.debug {
self.print_backtrace(s);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment