forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'audio-seek-landing'

Browse files at this commit

dbe43b04098b7fccf2b63e90711817e173405ef8Ahmet Kaan GümüşParent: e1b58c9c3d09c7
crates/ec-matroska/tests/matroska.rsmodified+99 -1
@@ -8,7 +8,7 @@ use std::io::BufReader;
88 use std::path::{Path, PathBuf};
99 use std::process::Command;
1010
11-use ec_core::{Demuxer, Error, Muxer, SeekMode, TimeBase, Timestamp};
11+use ec_core::{Demuxer, Error, MediaType, Muxer, SeekMode, TimeBase, Timestamp};
1212 use ec_matroska::{MatroskaDemuxer, MatroskaMuxer};
1313
1414 fn fixtures() -> PathBuf {
@@ -711,3 +711,101 @@ fn the_first_cluster_is_reachable_when_no_cue_names_it() {
711711 break;
712712 }
713713 }
714+
715+
716+/// Where our own demuxer's seek lands on a real 5.1 E-AC-3 Matroska, in
717+/// *timestamp* -- split from decode, per the round's charter: this measures
718+/// only [`MatroskaDemuxer::seek`] plus the first packet's `pts`, against what
719+/// `ffprobe` reports for the same track near the same instant. If this lands
720+/// exact, the +0.145 s the consumer measured is downstream of the demuxer
721+/// (the AC-3 decoder or its frame-count bookkeeping in `engine`), not here.
722+///
723+/// Skipped, not failed, without the film: a claim about his library cannot be
724+/// made by a machine that does not have it.
725+#[test]
726+fn seek_landing_on_his_eac3_film_matches_ffprobe() {
727+ same_class_sweep(
728+ "/home/user/Downloads/reeld/reeld.mkv",
729+ &[600.0, 610.0],
730+ );
731+ // Same-class sweep (round charter task 3): an Opus 5.1 Matroska, a codec
732+ // that already goes through this crate's demuxer -- if this lands as
733+ // tight as the E-AC-3 one, the demuxer's seek is not codec-specific and
734+ // the +0.145 s the consumer measured on the E-AC-3 path is downstream of
735+ // it either way.
736+ same_class_sweep(
737+ "/home/user/Downloads/reelb.mkv",
738+ &[600.0, 610.0],
739+ );
740+}
741+
742+/// Where our own demuxer's seek lands on `path`, in *timestamp* -- split from
743+/// decode, per the round's charter: this measures only
744+/// [`MatroskaDemuxer::seek`] plus the first packet's `pts`, against what
745+/// `ffprobe` reports for the same track near the same instant.
746+///
747+/// Skipped, not failed, without the film: a claim about his library cannot be
748+/// made by a machine that does not have it.
749+fn same_class_sweep(path: &str, wants: &[f64]) {
750+ let film = Path::new(path);
751+ if !film.exists() {
752+ eprintln!("skipped: {path} is not present");
753+ return;
754+ }
755+ let mut demux =
756+ MatroskaDemuxer::new(BufReader::new(File::open(film).expect("opens"))).expect("demuxes");
757+ let audio = demux
758+ .streams()
759+ .iter()
760+ .find(|s| s.params.codec.media_type() == MediaType::Audio)
761+ .expect("the film has an audio stream")
762+ .clone();
763+
764+ for &want in wants {
765+ let target = Timestamp::new(
766+ (want * audio.time_base.den() as f64 / audio.time_base.num() as f64).round() as i64,
767+ audio.time_base,
768+ );
769+ demux
770+ .seek(audio.index, target, SeekMode::SyncBefore)
771+ .expect("seek");
772+ let landed = loop {
773+ let packet = demux.next_packet().expect("a packet after the seek");
774+ if packet.stream == audio.index {
775+ break packet.pts.expect("audio packet carries a pts");
776+ }
777+ };
778+ let our_secs = landed as f64 * audio.time_base.num() as f64 / audio.time_base.den() as f64;
779+
780+ let ffprobe = Command::new("ffprobe")
781+ .args([
782+ "-v",
783+ "error",
784+ "-select_streams",
785+ "a:0",
786+ "-show_entries",
787+ "packet=pts_time",
788+ "-of",
789+ "csv=p=0",
790+ "-read_intervals",
791+ ])
792+ .arg(format!("{want}%+#1"))
793+ .arg(film)
794+ .output();
795+ let Ok(ffprobe) = ffprobe else {
796+ eprintln!("skipped ffprobe cross-check: ffprobe not runnable");
797+ eprintln!("want {want}s, our demuxer landed at {our_secs:.3}s (pts {landed})");
798+ continue;
799+ };
800+ let reference: f64 = String::from_utf8_lossy(&ffprobe.stdout)
801+ .lines()
802+ .next()
803+ .unwrap_or("")
804+ .trim()
805+ .parse()
806+ .unwrap_or(f64::NAN);
807+ eprintln!(
808+ "want {want}s: our demuxer landed {our_secs:.3}s (pts {landed}), ffprobe's own packet at {reference:.3}s"
809+ );
810+ }
811+}