Stop the live rip path muxing Blu-ray 3D differently from the ISO path

Five defects, four of them the same shape: a local reimplementation of
logic the crate already had, which had drifted from it. Each is now fixed
by calling the canonical version rather than by patching the copy.

DiscStream::new — the live disc:// path — built every parser through the
plain codec lookup and never asked whether a video stream was an MVC
dependent view, though resolve::build_demux_state does. The same 3D disc
therefore muxed correctly from an ISO and incorrectly ripped live. The
open-coded loop is gone; both paths now call build_demux_state.

collect_psi_section reimplemented the continuity-counter gap test and
disagreed with process_packet in the same file: it tolerated neither a
duplicate packet nor an adaptation-field-only packet, which per ISO/IEC
13818-1 §2.4.3.3 does not increment the counter. A spec-legal PMT
continuation was read as desync and the title's stream list came back
empty. Both callers now share one `cc_is_gap`, and a duplicate packet's
payload is no longer appended twice — doing so would have corrupted the
section the check exists to protect.

The json:// sink called the channel-count and sample-rate accessors
unconditionally, and both fabricate a concrete value for Unknown, so it
reported a confident 5.1 at 48 kHz for audio whose format was unknown
while its own neighbouring string fields said "unknown". The keys are now
omitted, matching mkv.rs. This matters more than it did: a sample-rate
ladder fixed earlier in this audit means Unknown now reaches consumers
that used to receive a wrong-but-concrete value.

For an audio:// or sub:// sink the reference video track's output is
filtered out, so its first PTS was never recorded and every delay was
computed against zero — baking a wrong DELAY into the filename. The
reference is now recorded whenever a frame is on the reference track,
independent of whether that track has an output, so a normal title gets a
correct delay; where no reference is ever observed the tag is omitted
rather than guessed.

A third copy of the channel/sample-rate mapping exists in src/diag.rs and
was left alone as outside the confirmed set. It is the same drift shape
and is recorded for the next round.
This commit is contained in:
Matthew Jackson
2026-07-30 09:18:33 -07:00
parent 3f7d7af472
commit b8fa5e74dc
5 changed files with 489 additions and 59 deletions
+54 -2
View File
@@ -178,12 +178,26 @@ fn stream_json(s: &DiscStream) -> serde_json::Value {
"pid": a.pid,
"language": a.language,
"channels": a.channels.to_string(),
"channel_count": a.channels.count(),
"sample_rate": a.sample_rate.to_string(),
"sample_rate_hz": a.sample_rate.hz(),
"secondary": a.secondary,
"purpose": purpose_id(a.purpose),
});
// `AudioChannels::count()` and `SampleRate::hz()` FABRICATE a concrete
// value for the `Unknown` variant (6 channels / 48000 Hz), so calling
// them unconditionally reported a confident 5.1 / 48 kHz for audio
// whose format is genuinely unknown — contradicting the neighbouring
// `channels` / `sample_rate` strings, which honestly say "unknown".
// Omit the numeric key entirely instead: the same guard `mkv.rs`
// applies before writing Channels / SamplingFrequency (there it emits
// 0 so the EBML serializer drops the element). Kept as a guard here
// rather than fixed in `count()`/`hz()` because those return
// non-optional scalars that other callers rely on.
if !matches!(a.channels, crate::disc::AudioChannels::Unknown) {
o["channel_count"] = json!(a.channels.count());
}
if !matches!(a.sample_rate, crate::disc::SampleRate::Unknown) {
o["sample_rate_hz"] = json!(a.sample_rate.hz());
}
if !a.label.is_empty() {
o["label"] = json!(a.label);
}
@@ -346,6 +360,44 @@ mod tests {
assert_eq!(v["chapters"][1]["name"], "2");
}
/// An audio stream whose channel layout / sample rate are genuinely unknown
/// must not be reported with a fabricated 5.1 / 48 kHz. `AudioChannels::count()`
/// maps `Unknown` to 6 and `SampleRate::hz()` maps `Unknown` to 48000, so the
/// numeric fields must be omitted rather than computed — otherwise the JSON
/// contradicts its own `channels` / `sample_rate` strings ("unknown").
#[test]
fn unknown_audio_layout_omits_fabricated_numeric_fields() {
use crate::disc::{AudioChannels, AudioStream, Codec, DiscTitle};
use crate::disc::{LabelPurpose, SampleRate, Stream as DiscStream};
let mut t = DiscTitle::empty();
t.streams = vec![DiscStream::Audio(AudioStream {
pid: 0x1100,
codec: Codec::DtsHdMa,
channels: AudioChannels::Unknown,
language: "eng".into(),
sample_rate: SampleRate::Unknown,
secondary: false,
purpose: LabelPurpose::Normal,
label: String::new(),
})];
let v = title_json(&t);
let a = &v["streams"][0];
// The honest string fields.
assert_eq!(a["channels"], "unknown");
assert_eq!(a["sample_rate"], "unknown");
// The numeric fields must not assert a value the scan never resolved.
assert!(
a["channel_count"].is_null(),
"unknown channel layout must not report a channel_count, got {}",
a["channel_count"]
);
assert!(
a["sample_rate_hz"].is_null(),
"unknown sample rate must not report a sample_rate_hz, got {}",
a["sample_rate_hz"]
);
}
#[test]
fn video_json_carries_resolution_and_hdr() {
use crate::disc::Codec;