diff options
Diffstat (limited to 'remuxer/src/segment_extractor.rs')
-rw-r--r-- | remuxer/src/segment_extractor.rs | 60 |
1 files changed, 0 insertions, 60 deletions
diff --git a/remuxer/src/segment_extractor.rs b/remuxer/src/segment_extractor.rs deleted file mode 100644 index 42c85f5..0000000 --- a/remuxer/src/segment_extractor.rs +++ /dev/null @@ -1,60 +0,0 @@ -/* - This file is part of jellything (https://codeberg.org/metamuffin/jellything) - which is licensed under the GNU Affero General Public License (version 3); see /COPYING. - Copyright (C) 2025 metamuffin <metamuffin.org> -*/ -use anyhow::{anyhow, bail, Result}; -use jellymatroska::{block::Block, read::EbmlReader, Master, MatroskaTag}; -use log::{debug, info, trace}; - -pub struct SegmentExtractIter<'a> { - segment: &'a mut EbmlReader, - extract: u64, -} - -impl<'a> SegmentExtractIter<'a> { - pub fn new(segment: &'a mut EbmlReader, extract: u64) -> Self { - Self { segment, extract } - } - - /// Returns the next block and sometimes its duration too. - pub fn next_block(&mut self) -> Result<(Block, Option<u64>)> { - let mut duration = None; - let mut group = false; - let mut saved_block = None; - loop { - let (_, item) = self.segment.next().ok_or(anyhow!("eof"))??; - match item { - MatroskaTag::Void(_) => (), - MatroskaTag::Crc32(_) => (), - MatroskaTag::Cluster(_) => (), - MatroskaTag::Timestamp(_) => (), - MatroskaTag::BlockGroup(Master::Start) => group = true, - MatroskaTag::BlockGroup(Master::End) => { - if !group { - bail!("group end without start"); - } - if let Some(block) = saved_block { - return Ok((block, duration)); - } - group = false; - } - MatroskaTag::BlockDuration(d) => duration = Some(d), - MatroskaTag::SimpleBlock(block) | MatroskaTag::Block(block) => { - if block.track == self.extract { - trace!("block: track={} tso={}", block.track, block.timestamp_off); - if group { - // can't return yet; there might be a BlockDuration coming - saved_block = Some(block); - } else { - return Ok((block, duration)); - } - } - } - MatroskaTag::Cues(_) => bail!("reached cues, this is the end"), - MatroskaTag::Segment(Master::End) => info!("extractor reached segment end"), - _ => debug!("(rs) tag ignored: {item:?}"), - } - } - } -} |