diff options
author | metamuffin <metamuffin@disroot.org> | 2023-08-03 20:37:11 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-08-03 20:37:11 +0200 |
commit | 5b71ccaf2bbe34f1d39d4f38f2b5c2090a9761b1 (patch) | |
tree | ee66fbaec90cb0e2d3a9eb3d8e7a450fd45846b3 /remuxer/src/import/mod.rs | |
parent | c71a10717392cc321b97e3f2173645e78c263488 (diff) | |
download | jellything-5b71ccaf2bbe34f1d39d4f38f2b5c2090a9761b1.tar jellything-5b71ccaf2bbe34f1d39d4f38f2b5c2090a9761b1.tar.bz2 jellything-5b71ccaf2bbe34f1d39d4f38f2b5c2090a9761b1.tar.zst |
refactor import script
Diffstat (limited to 'remuxer/src/import/mod.rs')
-rw-r--r-- | remuxer/src/import/mod.rs | 89 |
1 files changed, 9 insertions, 80 deletions
diff --git a/remuxer/src/import/mod.rs b/remuxer/src/import/mod.rs index 7b0b371..4c5275e 100644 --- a/remuxer/src/import/mod.rs +++ b/remuxer/src/import/mod.rs @@ -3,29 +3,24 @@ which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2023 metamuffin <metamuffin.org> */ +pub mod seek_index; + use anyhow::{anyhow, bail, Result}; -use jellycommon::{BlockIndex, LocalTrack, SeekIndex, SourceTrack, SourceTrackKind}; +use jellycommon::{LocalTrack, SourceTrack, SourceTrackKind}; use jellymatroska::{ - block::Block, matroska::MatroskaTag, read::EbmlReader, unflatten::{IterWithPos, Unflat, Unflatten}, }; -use log::{debug, error, info, trace, warn}; -use std::{collections::BTreeMap, path::PathBuf}; +use log::{debug, error, info, warn}; +use std::path::PathBuf; -pub fn import_read( +pub fn import_metadata( path: &PathBuf, input: &mut EbmlReader, -) -> Result<( - Vec<SourceTrack>, - Vec<LocalTrack>, - BTreeMap<u64, SeekIndex>, - f64, -)> { +) -> Result<(Vec<SourceTrack>, Vec<LocalTrack>, f64)> { let mut iteminfo = Vec::new(); let mut private = Vec::new(); - let mut seek_index = BTreeMap::new(); let mut dur = None; while let Some(item) = input.next() { let item = match item { @@ -60,7 +55,6 @@ pub fn import_read( &mut children, &mut iteminfo, &mut private, - &mut seek_index, )?); info!("segment end"); } @@ -68,7 +62,7 @@ pub fn import_read( } } - Ok((iteminfo, private, seek_index, dur.unwrap_or(0.))) + Ok((iteminfo, private, dur.unwrap_or(0.))) } fn import_read_segment( @@ -76,7 +70,6 @@ fn import_read_segment( segment: &mut Unflatten, iteminfo: &mut Vec<SourceTrack>, private: &mut Vec<LocalTrack>, - seek_index: &mut BTreeMap<u64, SeekIndex>, ) -> Result<Option<f64>> { let (mut timestamp_scale, mut duration) = (None, None); @@ -193,71 +186,7 @@ fn import_read_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() { - match item { - MatroskaTag::Timestamp(ts) => pts = ts, - MatroskaTag::BlockGroup(_) => { - debug!("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, - })) = 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:?}"), - } - } - } - MatroskaTag::SimpleBlock(buf) => { - let block = Block::parse(&buf)?; - debug!( - "simple block: track={} tso={}", - block.track, block.timestamp_off - ); - debug!("{pts} {}", block.timestamp_off); - seek_index - .entry(block.track) - .or_insert(SeekIndex { blocks: vec![] }) - .blocks - .push(BlockIndex { - pts: (pts as i64 + block.timestamp_off as i64) as u64, - source_off: position, - size: block.data.len(), - }); - } - _ => debug!("(rsc) tag ignored: {item:?}"), - } - } else { - break; - } - position = children.position(); - } - } + MatroskaTag::Cluster(_) => {} _ => debug!("(rs) tag ignored: {item:?}"), }; } |