diff options
author | metamuffin <metamuffin@disroot.org> | 2024-01-28 03:21:03 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-01-28 03:21:03 +0100 |
commit | ce9eb140ab9243d1c87ace4727a82b7fa50f964b (patch) | |
tree | b64da94ba58f72a2371cdd8644dc48a178b7d260 /remuxer/src/seek_index.rs | |
parent | b514ec8cea2c2143e0bd7a0eb377c96a6f091d0d (diff) | |
download | jellything-ce9eb140ab9243d1c87ace4727a82b7fa50f964b.tar jellything-ce9eb140ab9243d1c87ace4727a82b7fa50f964b.tar.bz2 jellything-ce9eb140ab9243d1c87ace4727a82b7fa50f964b.tar.zst |
fix yet another fundamental issue in the ebml reader and seekindex.
Diffstat (limited to 'remuxer/src/seek_index.rs')
-rw-r--r-- | remuxer/src/seek_index.rs | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/remuxer/src/seek_index.rs b/remuxer/src/seek_index.rs index eba7344..7e9cee1 100644 --- a/remuxer/src/seek_index.rs +++ b/remuxer/src/seek_index.rs @@ -9,7 +9,7 @@ use jellycommon::seek_index::{BlockIndex, SeekIndex}; use jellymatroska::{ block::Block, read::EbmlReader, - unflatten::{IterWithPos, Unflat, Unflatten}, + unflatten::{Unflat, Unflatten}, MatroskaTag, }; use log::{debug, info, trace, warn}; @@ -30,7 +30,7 @@ pub fn import_seek_index(input: &mut EbmlReader) -> Result<BTreeMap<u64, SeekInd let mut seek_index = BTreeMap::new(); while let Some(item) = input.next() { let item = match item { - Ok(item) => item, + Ok((_, item)) => item, Err(e) => { if !matches!(e, jellymatroska::error::Error::Io(_)) { warn!("{e}"); @@ -67,20 +67,20 @@ fn import_seek_index_segment( MatroskaTag::Cluster(_) => { let mut children = children.unwrap(); let mut pts = 0; - let mut position = children.position(); - loop { - if let Some(Ok(Unflat { children, item, .. })) = children.n() { + if let Some(Ok(Unflat { + children, + item, + position, + })) = children.n() + { match item { MatroskaTag::Timestamp(ts) => pts = ts, MatroskaTag::BlockGroup(_) => { trace!("group"); let mut children = children.unwrap(); - // let position = children.position(); //? TODO where should this point to? cluster or block? // probably block while let Some(Ok(Unflat { - children: _, - item, - position: _block_position, + children: _, item, .. })) = children.n() { match item { @@ -90,7 +90,12 @@ fn import_seek_index_segment( "block: track={} tso={}", block.track, block.timestamp_off ); - seek_index_add(seek_index, &block, position, pts); + seek_index_add( + seek_index, + &block, + position.unwrap(), + pts, + ); } _ => trace!("{item:?}"), } @@ -104,14 +109,13 @@ fn import_seek_index_segment( block.timestamp_off ); trace!("{pts} {}", block.timestamp_off); - seek_index_add(seek_index, &block, position, pts); + seek_index_add(seek_index, &block, position.unwrap(), pts); } _ => trace!("(rsc) tag ignored: {item:?}"), } } else { break; } - position = children.position(); } } _ => debug!("(rs) tag ignored: {item:?}"), @@ -123,9 +127,23 @@ fn import_seek_index_segment( fn seek_index_add( seek_index: &mut BTreeMap<u64, SeekIndex>, block: &Block, - position: usize, + position: u64, pts_base: u64, ) { + //* I heard this helped debugging once. + // { + // let mut f = File::open("/home/muffin/videos/itte-yorushika.mkv").unwrap(); + // f.seek(std::io::SeekFrom::Start(position.try_into().unwrap())) + // .unwrap(); + // let mut buf = [0u8]; + // f.read_exact(&mut buf).unwrap(); + + // eprintln!("{}", buf[0]); + // if buf[0] != 0xa0 && buf[0] != 0xa3 { + // warn!("invalid position {position}") + // } + // } + let trs = seek_index .entry(block.track) .or_insert(SeekIndex::default()); |