aboutsummaryrefslogtreecommitdiff
path: root/remuxer/src/import/mod.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-01-29 00:49:23 +0100
committermetamuffin <metamuffin@disroot.org>2023-01-29 00:49:23 +0100
commit0d9dc5672b0ba0c6c9988b0422837ceb00a5d7b8 (patch)
tree00298331af3fc9e510c3aa8cf37313f514558089 /remuxer/src/import/mod.rs
parent0427a45ce8fa4762b087eeaf7e24f00678ceb48b (diff)
downloadjellything-0d9dc5672b0ba0c6c9988b0422837ceb00a5d7b8.tar
jellything-0d9dc5672b0ba0c6c9988b0422837ceb00a5d7b8.tar.bz2
jellything-0d9dc5672b0ba0c6c9988b0422837ceb00a5d7b8.tar.zst
doesnt make any sense
Diffstat (limited to 'remuxer/src/import/mod.rs')
-rw-r--r--remuxer/src/import/mod.rs99
1 files changed, 52 insertions, 47 deletions
diff --git a/remuxer/src/import/mod.rs b/remuxer/src/import/mod.rs
index c3dbf49..01b211b 100644
--- a/remuxer/src/import/mod.rs
+++ b/remuxer/src/import/mod.rs
@@ -52,13 +52,13 @@ pub fn import_read(path: &PathBuf, input: &mut EbmlReader, iteminfo: &mut ItemIn
fn import_read_segment(
path: &PathBuf,
- children: &mut Unflatten,
+ segment: &mut Unflatten,
iteminfo: &mut ItemInfo,
) -> Result<()> {
let (mut timestamp_scale, mut duration) = (None, None);
let mut seek_index = HashMap::new();
- while let Some(Ok(Unflat { children, item })) = children.n() {
+ while let Some(Ok(Unflat { children, item })) = segment.n() {
match item {
MatroskaTag::SeekHead(_) => {}
MatroskaTag::Info(_) => {
@@ -173,62 +173,68 @@ fn import_read_segment(
MatroskaTag::Cluster(_) => {
let mut children = children.unwrap();
let mut pts = 0;
+ let mut position = children.position();
- while let Some(Ok(Unflat { children, item })) = children.n() {
- match item {
- MatroskaTag::Timestamp(ts) => pts = ts,
- MatroskaTag::BlockGroup(_) => {
- debug!("group");
- let mut children = children.unwrap();
- let pos = children.position();
- while let Some(Ok(Unflat { children: _, item })) = children.n() {
- match item {
- MatroskaTag::Block(ref buf) => {
- let block = Block::parse(buf)?;
- debug!(
- "block: track={} tso={}",
- block.track, block.timestamp_off
- );
- seek_index
- .entry(block.track)
- .or_insert(SeekIndex { blocks: vec![] })
- .blocks
- .push(BlockIndex {
- pts: pts + block.timestamp_off as u64,
- source_off: pos,
- size: block.data.len(),
- });
+ loop {
+ if let Some(Ok(Unflat { children, item })) = children.n() {
+ match item {
+ MatroskaTag::Timestamp(ts) => pts = ts,
+ MatroskaTag::BlockGroup(_) => {
+ debug!("group");
+ let mut children = children.unwrap();
+ while let Some(Ok(Unflat { children: _, item })) = children.n() {
+ match item {
+ MatroskaTag::Block(ref buf) => {
+ let block = Block::parse(buf)?;
+ debug!(
+ "block: track={} tso={}",
+ block.track, block.timestamp_off
+ );
+ seek_index
+ .entry(block.track)
+ .or_insert(SeekIndex { blocks: vec![] })
+ .blocks
+ .push(BlockIndex {
+ pts: pts + block.timestamp_off as u64,
+ source_off: position,
+ size: block.data.len(),
+ });
+ }
+ _ => trace!("{item:?}"),
}
- _ => trace!("{item:?}"),
}
}
+ MatroskaTag::SimpleBlock(buf) => {
+ let block = Block::parse(&buf)?;
+ debug!(
+ "simple block: track={} tso={}",
+ block.track, block.timestamp_off
+ );
+ seek_index
+ .entry(block.track)
+ .or_insert(SeekIndex { blocks: vec![] })
+ .blocks
+ .push(BlockIndex {
+ pts: pts + block.timestamp_off as u64,
+ source_off: position,
+ size: block.data.len(),
+ });
+ }
+ _ => debug!("(rsc) tag ignored: {item:?}"),
}
- MatroskaTag::SimpleBlock(buf) => {
- let block = Block::parse(&buf)?;
- debug!(
- "simple block: track={} tso={}",
- block.track, block.timestamp_off
- );
- seek_index
- .entry(block.track)
- .or_insert(SeekIndex { blocks: vec![] })
- .blocks
- .push(BlockIndex {
- pts: pts + block.timestamp_off as u64,
- source_off: 0,
- size: block.data.len(),
- });
- }
- _ => debug!("(rsc) tag ignored: {item:?}"),
+ } else {
+ break;
}
+ position = children.position();
}
}
_ => debug!("(rs) tag ignored: {item:?}"),
- }
+ };
}
for (tn, index) in seek_index {
+ info!("writing index {tn} with {} blocks", index.blocks.len());
bincode::encode_into_std_write(
index,
&mut File::create(path.with_extension(&format!("si.{tn}")))?,
@@ -236,7 +242,6 @@ fn import_read_segment(
)?;
}
- iteminfo.duration =
- (duration.unwrap() * timestamp_scale.unwrap() as f64) / 1_000_000_000_f64;
+ iteminfo.duration = (duration.unwrap() * timestamp_scale.unwrap() as f64) / 1_000_000_000_f64;
Ok(())
}