mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-16 20:25:02 +00:00
Merge pull request #1144 from vangel76/fix/mpegts-ts-flags-pmt
MPEG-TS: a PAT or PMT packet sent twice no longer damages the section
This commit is contained in:
@@ -791,6 +791,23 @@ fn scrambled_packet_is_skipped_with_a_warning() {
|
||||
assert!(total(&f) < total(&base));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn repeated_pat_and_pmt_packets_are_dropped_before_the_section_parser() {
|
||||
let clean = audio_ts(2);
|
||||
let first = |pid: u16| {
|
||||
(0..clean.len() / 188).map(|i| i * 188).find(|&o| (((clean[o + 1] & 0x1F) as u16) << 8 | clean[o + 2] as u16) == pid).expect("packet exists")
|
||||
};
|
||||
let mut dup = clean.clone();
|
||||
for pid in [0x100, 0] {
|
||||
let o = first(pid);
|
||||
let copy = dup[o..o + 188].to_vec();
|
||||
dup.splice(o + 188..o + 188, copy);
|
||||
}
|
||||
let f = open(&dup).unwrap();
|
||||
assert!(f.warnings.iter().any(|w| w.contains("2 duplicate packet(s) dropped")), "{:?}", f.warnings);
|
||||
assert!(!f.warnings.iter().any(|w| w.contains("continuity") || w.contains("CRC")), "{:?}", f.warnings);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn duplicate_packet_is_dropped_but_a_different_payload_with_the_same_counter_is_kept() {
|
||||
let clean = audio_ts(6);
|
||||
|
||||
@@ -497,6 +497,7 @@ pub(crate) fn scan<S: ByteSource + ?Sized>(src: &S, packet_size: usize, sync_off
|
||||
let mut warnings: Vec<String> = Vec::new();
|
||||
let mut pat = Psi::default();
|
||||
let mut pmt = PmtState::default();
|
||||
let mut psi_dup: HashMap<u16, DupGuard> = HashMap::new();
|
||||
let mut es: HashMap<u16, EsState> = HashMap::new();
|
||||
let mut order: Vec<u16> = Vec::new();
|
||||
// one timestamp unwrapper for the program: its streams share one clock, so a stream whose
|
||||
@@ -560,6 +561,13 @@ pub(crate) fn scan<S: ByteSource + ?Sized>(src: &S, packet_size: usize, sync_off
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if pk.pid == 0 || Some(pk.pid) == pmt.pmt_pid {
|
||||
// a repeated packet would append its payload to the section in progress
|
||||
if psi_dup.entry(pk.pid).or_default().is_dup(&pk) {
|
||||
duplicates += 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if pk.pid == 0 {
|
||||
feed_pat(&pk, &mut pat, &mut pmt, &mut crc_errors);
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user