diff --git a/media/mp4parse-rust/mp4parse/src/lib.rs b/media/mp4parse-rust/mp4parse/src/lib.rs index c857960e0c53..2fa854f6421c 100644 --- a/media/mp4parse-rust/mp4parse/src/lib.rs +++ b/media/mp4parse-rust/mp4parse/src/lib.rs @@ -835,24 +835,30 @@ fn read_edts(f: &mut BMFFBox, track: &mut Track) -> Result<()> { match b.head.name { BoxType::EditListBox => { let elst = read_elst(&mut b)?; + if elst.edits.len() < 1 { + debug!("empty edit list"); + continue; + } let mut empty_duration = 0; let mut idx = 0; - if elst.edits.len() > 2 { - return Err(Error::Unsupported("more than two edits")); - } if elst.edits[idx].media_time == -1 { - empty_duration = elst.edits[idx].segment_duration; if elst.edits.len() < 2 { - return Err(Error::InvalidData("expected additional edit")); + debug!("expected additional edit, ignoring edit list"); + continue; } + empty_duration = elst.edits[idx].segment_duration; idx += 1; } track.empty_duration = Some(MediaScaledTime(empty_duration)); - if elst.edits[idx].media_time < 0 { - return Err(Error::InvalidData("unexpected negative media time in edit")); + let media_time = elst.edits[idx].media_time; + if media_time < 0 { + debug!("unexpected negative media time in edit"); } - track.media_time = Some(TrackScaledTime::(elst.edits[idx].media_time as u64, + track.media_time = Some(TrackScaledTime::(std::cmp::max(0, media_time) as u64, track.id)); + if elst.edits.len() > 2 { + debug!("ignoring edit list with {} entries", elst.edits.len()); + } debug!("{:?}", elst); } _ => skip_box_content(&mut b)?, @@ -1068,9 +1074,6 @@ fn read_tkhd(src: &mut BMFFBox) -> Result { fn read_elst(src: &mut BMFFBox) -> Result { let (version, _) = read_fullbox_extra(src)?; let edit_count = be_u32_with_limit(src)?; - if edit_count == 0 { - return Err(Error::InvalidData("invalid edit count")); - } let mut edits = Vec::new(); for _ in 0..edit_count { let (segment_duration, media_time) = match version { @@ -1094,6 +1097,9 @@ fn read_elst(src: &mut BMFFBox) -> Result { })?; } + // Padding could be added in some contents. + skip_box_remain(src)?; + Ok(EditListBox { edits: edits, }) diff --git a/media/mp4parse-rust/mp4parse/src/tests.rs b/media/mp4parse-rust/mp4parse/src/tests.rs index 14e0e27818c5..2cba11138e1d 100644 --- a/media/mp4parse-rust/mp4parse/src/tests.rs +++ b/media/mp4parse-rust/mp4parse/src/tests.rs @@ -759,9 +759,8 @@ fn read_elst_zero_entries() { let mut iter = super::BoxIter::new(&mut stream); let mut stream = iter.next_box().unwrap().unwrap(); match super::read_elst(&mut stream) { - Err(Error::InvalidData(s)) => assert_eq!(s, "invalid edit count"), - Ok(_) => panic!("expected an error result"), - _ => panic!("expected a different error result"), + Ok(elst) => assert_eq!(elst.edits.len(), 0), + _ => panic!("expected no error"), } } @@ -780,6 +779,7 @@ fn make_elst() -> Cursor> { fn read_edts_bogus() { // First edit list entry has a media_time of -1, so we expect a second // edit list entry to be present to provide a valid media_time. + // Bogus edts are ignored. let mut stream = make_box(BoxSize::Auto, b"edts", |s| { s.append_bytes(&make_elst().into_inner()) }); @@ -787,9 +787,11 @@ fn read_edts_bogus() { let mut stream = iter.next_box().unwrap().unwrap(); let mut track = super::Track::new(0); match super::read_edts(&mut stream, &mut track) { - Err(Error::InvalidData(s)) => assert_eq!(s, "expected additional edit"), - Ok(_) => panic!("expected an error result"), - _ => panic!("expected a different error result"), + Ok(_) => { + assert_eq!(track.media_time, None); + assert_eq!(track.empty_duration, None); + } + _ => panic!("expected no error"), } } diff --git a/media/mp4parse-rust/update-rust.sh b/media/mp4parse-rust/update-rust.sh index 70fb65621b1a..388d77b2490c 100755 --- a/media/mp4parse-rust/update-rust.sh +++ b/media/mp4parse-rust/update-rust.sh @@ -2,7 +2,7 @@ # Script to update mp4parse-rust sources to latest upstream # Default version. -VER="9e70cb418401c152cd3183aab06b084c0ce3f3e6" +VER="2dc5127a69bc9bf891972e269e3abde0b77612f5" # Accept version or commit from the command line. if test -n "$1"; then