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:
+6
-12
@@ -7,8 +7,7 @@
|
||||
use super::ebml;
|
||||
use super::timeline::TimelineContinuity;
|
||||
use crate::disc::{
|
||||
AudioChannels, AudioStream, Chapter, Codec, ColorSpace, HdrFormat, Resolution, SampleRate,
|
||||
SubtitleStream, VideoStream,
|
||||
AudioStream, Chapter, Codec, ColorSpace, HdrFormat, Resolution, SubtitleStream, VideoStream,
|
||||
};
|
||||
use std::io::{self, Seek, Write};
|
||||
|
||||
@@ -515,16 +514,11 @@ impl MkvTrack {
|
||||
// the SamplingFrequency / Channels element (Matroska supplies its own
|
||||
// spec default) rather than writing a fabricated 48000 Hz / 6-channel
|
||||
// value into the file.
|
||||
let sr = if matches!(a.sample_rate, SampleRate::Unknown) {
|
||||
0.0
|
||||
} else {
|
||||
a.sample_rate.hz()
|
||||
};
|
||||
let ch = if matches!(a.channels, AudioChannels::Unknown) {
|
||||
0
|
||||
} else {
|
||||
a.channels.count()
|
||||
};
|
||||
// No guard needed: the accessors return 0 for Unknown, which is exactly
|
||||
// what this wants. They used to fabricate 6 channels at 48 kHz, so every
|
||||
// caller had to remember to check the variant first.
|
||||
let sr = a.sample_rate.hz();
|
||||
let ch = a.channels.count();
|
||||
|
||||
let name = a.label.clone();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user