diff options
author | metamuffin <metamuffin@disroot.org> | 2024-06-10 15:28:36 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-06-10 15:28:36 +0200 |
commit | 05d11426a8e60fa060733eb8ae7843bc2ae9725c (patch) | |
tree | 57cfad9cedf1eb50de193f1657b42234745c044e /remuxer/src | |
parent | c0365c8c64f403fd9ee75c0db1a9ed6134633e8f (diff) | |
download | jellything-05d11426a8e60fa060733eb8ae7843bc2ae9725c.tar jellything-05d11426a8e60fa060733eb8ae7843bc2ae9725c.tar.bz2 jellything-05d11426a8e60fa060733eb8ae7843bc2ae9725c.tar.zst |
apply many clippy issue
Diffstat (limited to 'remuxer/src')
-rw-r--r-- | remuxer/src/extract.rs | 6 | ||||
-rw-r--r-- | remuxer/src/fragment.rs | 2 | ||||
-rw-r--r-- | remuxer/src/remux.rs | 6 | ||||
-rw-r--r-- | remuxer/src/seek_index.rs | 81 | ||||
-rw-r--r-- | remuxer/src/segment_extractor.rs | 2 |
5 files changed, 42 insertions, 55 deletions
diff --git a/remuxer/src/extract.rs b/remuxer/src/extract.rs index e70adf4..a9b4835 100644 --- a/remuxer/src/extract.rs +++ b/remuxer/src/extract.rs @@ -10,10 +10,8 @@ use jellymatroska::{block::Block, read::EbmlReader, Master, MatroskaTag}; use log::debug; use std::{fs::File, io::BufReader, path::PathBuf}; -pub fn extract_track( - path_base: PathBuf, - track_info: LocalTrack, -) -> anyhow::Result<Vec<(u64, Option<u64>, Vec<u8>)>> { +pub type TrackExtract = Vec<(u64, Option<u64>, Vec<u8>)>; +pub fn extract_track(path_base: PathBuf, track_info: LocalTrack) -> anyhow::Result<TrackExtract> { let source_path = path_base.join(track_info.path); let file = File::open(&source_path)?; let mut reader = EbmlReader::new(BufReader::new(file)); diff --git a/remuxer/src/fragment.rs b/remuxer/src/fragment.rs index cd395f9..872b1e0 100644 --- a/remuxer/src/fragment.rs +++ b/remuxer/src/fragment.rs @@ -186,7 +186,7 @@ pub fn write_fragment_into( let mut blocks = vec![MatroskaTag::Timestamp(start_block.pts)]; for i in start_block_index..end_block_index { let index_block = &index.blocks[i]; - let (mut block, duration) = reader.next()?; + let (mut block, duration) = reader.next_block()?; assert_eq!(index_block.size, block.data.len(), "seek index is wrong"); diff --git a/remuxer/src/remux.rs b/remuxer/src/remux.rs index 733dc49..9419847 100644 --- a/remuxer/src/remux.rs +++ b/remuxer/src/remux.rs @@ -305,7 +305,7 @@ pub fn remux_stream_into( for (block_track, index_block) in cluster.blocks { let track_reader = &mut track_readers[block_track]; // TODO handle duration - let mut block = track_reader.stream.next()?.0; + let mut block = track_reader.stream.next_block()?.0; assert_eq!(index_block.size, block.data.len(), "seek index is wrong"); @@ -326,8 +326,8 @@ fn find_first_cluster_with_off( skip: usize, track: usize, ) -> Option<u64> { - for skip in skip..segment_layout.len() { - if let Some(off) = segment_layout[skip].source_offsets[track] { + for cluster in segment_layout.iter().skip(skip) { + if let Some(off) = cluster.source_offsets[track] { return Some(off); } } diff --git a/remuxer/src/seek_index.rs b/remuxer/src/seek_index.rs index 5bec6e6..7008696 100644 --- a/remuxer/src/seek_index.rs +++ b/remuxer/src/seek_index.rs @@ -18,7 +18,7 @@ use std::{collections::BTreeMap, fs::File, io::BufReader, path::Path, sync::Arc} pub fn get_seek_index(path: &Path) -> anyhow::Result<Arc<BTreeMap<u64, Arc<SeekIndex>>>> { cache_memory(&["seekindex", path.to_str().unwrap()], move || { info!("generating seek index for {path:?}"); - let input = File::open(&path).context("opening source file")?; + let input = File::open(path).context("opening source file")?; let mut input = EbmlReader::new(BufReader::new(input)); let index = import_seek_index(&mut input)?; info!("done"); @@ -67,52 +67,43 @@ fn import_seek_index_segment( MatroskaTag::Cluster(_) => { let mut children = children.unwrap(); let mut pts = 0; - loop { - 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(); - while let Some(Ok(Unflat { - children: _, item, .. - })) = children.n() - { - match item { - MatroskaTag::Block(ref block) => { - debug!( - "block: track={} tso={}", - block.track, block.timestamp_off - ); - seek_index_add( - seek_index, - &block, - position.unwrap(), - pts, - ); - } - _ => trace!("{item:?}"), + while 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(); + while let Some(Ok(Unflat { + children: _, item, .. + })) = children.n() + { + match item { + MatroskaTag::Block(ref block) => { + debug!( + "block: track={} tso={}", + block.track, block.timestamp_off + ); + seek_index_add(seek_index, block, position.unwrap(), pts); } + _ => trace!("{item:?}"), } } - MatroskaTag::SimpleBlock(block) => { - trace!( - "simple block: track={} tso={}", - block.track, - block.timestamp_off - ); - trace!("{pts} {}", block.timestamp_off); - seek_index_add(seek_index, &block, position.unwrap(), pts); - } - _ => trace!("(rsc) tag ignored: {item:?}"), } - } else { - break; + MatroskaTag::SimpleBlock(block) => { + trace!( + "simple block: track={} tso={}", + block.track, + block.timestamp_off + ); + trace!("{pts} {}", block.timestamp_off); + seek_index_add(seek_index, &block, position.unwrap(), pts); + } + _ => trace!("(rsc) tag ignored: {item:?}"), } } } @@ -142,9 +133,7 @@ fn seek_index_add( // } // } - let trs = seek_index - .entry(block.track) - .or_insert(SeekIndex::default()); + let trs = seek_index.entry(block.track).or_default(); if block.keyframe { trs.keyframes.push(trs.blocks.len()); diff --git a/remuxer/src/segment_extractor.rs b/remuxer/src/segment_extractor.rs index 2a12802..ca9e90f 100644 --- a/remuxer/src/segment_extractor.rs +++ b/remuxer/src/segment_extractor.rs @@ -18,7 +18,7 @@ impl<'a> SegmentExtractIter<'a> { } /// Returns the next block and sometimes its duration too. - pub fn next(&mut self) -> Result<(Block, Option<u64>)> { + pub fn next_block(&mut self) -> Result<(Block, Option<u64>)> { let mut duration = None; let mut group = false; let mut saved_block = None; |