Stop AudioChannels and SampleRate fabricating a value for Unknown
Three copies of the same two mappings existed. The canonical accessors returned 6 channels and 48000 Hz for Unknown; a third copy in diag.rs returned 0. The honest one was the copy. A plausible wrong answer is worse than an obvious one. Six channels at 48 kHz is indistinguishable from a real 5.1 track, so every caller became responsible for remembering to check the variant first — and this crate walked into exactly that: the json:// sink reported a confident 5.1 for audio whose neighbouring fields said "unknown". That was fixed at the call site earlier in this audit; this fixes it at the source. The accessors now return 0, which is what both in-crate call sites already coerced Unknown to by hand, so their guards are gone and the behaviour is unchanged. Zero is also obviously wrong if it ever reaches output, where six is not. The diag.rs duplicates are deleted rather than corrected — a fourth copy would have drifted too. Their only caller was a trace line in the same file, now on the canonical accessors. Their tests moved across and gained the Unknown case, which is the point: restoring either fabricated value fails both. Found by the round-7 correctness agent while fixing the json:// sink; it flagged the third copy as out of its scope rather than touching it.
This commit is contained in:
+11
-2
@@ -1035,7 +1035,14 @@ impl AudioChannels {
|
||||
AudioChannels::Surround51 => 6,
|
||||
AudioChannels::Surround61 => 7,
|
||||
AudioChannels::Surround71 => 8,
|
||||
AudioChannels::Unknown => 6,
|
||||
// 0, not 6. An unknown layout has no channel count, and returning a
|
||||
// plausible one made every caller responsible for remembering to
|
||||
// check the variant first — a trap, and one this crate walked into:
|
||||
// the json:// sink reported a confident 5.1 for audio its own
|
||||
// neighbouring fields called "unknown". 0 is the value Matroska and
|
||||
// the sinks already coerce Unknown to, and unlike 6 it is obviously
|
||||
// wrong if it ever reaches output.
|
||||
AudioChannels::Unknown => 0,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1082,7 +1089,9 @@ impl SampleRate {
|
||||
SampleRate::S96 => 96000.0,
|
||||
SampleRate::S176_4 => 176400.0,
|
||||
SampleRate::S192 => 192000.0,
|
||||
SampleRate::Unknown => 48000.0,
|
||||
// 0.0, not 48000.0 — see AudioChannels::count. A fabricated rate is
|
||||
// indistinguishable from a real one; a zero is not.
|
||||
SampleRate::Unknown => 0.0,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user