aboutsummaryrefslogtreecommitdiff
path: root/remuxer/src
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-01-28 23:41:32 +0100
committermetamuffin <metamuffin@disroot.org>2024-01-28 23:41:32 +0100
commitab0e2e306b7872d1c1e6494994070f52fe1b3c00 (patch)
tree859228b2cad149bc4cb4a76299ec29cd36ac28d0 /remuxer/src
parent1b8181e34fbbc6a6dfb89afa704e1e1d8fe7ff68 (diff)
downloadjellything-ab0e2e306b7872d1c1e6494994070f52fe1b3c00.tar
jellything-ab0e2e306b7872d1c1e6494994070f52fe1b3c00.tar.bz2
jellything-ab0e2e306b7872d1c1e6494994070f52fe1b3c00.tar.zst
direct io for blocks
Diffstat (limited to 'remuxer/src')
-rw-r--r--remuxer/src/extract.rs5
-rw-r--r--remuxer/src/remux.rs15
-rw-r--r--remuxer/src/seek_index.rs6
-rw-r--r--remuxer/src/segment_extractor.rs3
-rw-r--r--remuxer/src/snippet.rs4
5 files changed, 11 insertions, 22 deletions
diff --git a/remuxer/src/extract.rs b/remuxer/src/extract.rs
index 1b2b50c..bef5d4d 100644
--- a/remuxer/src/extract.rs
+++ b/remuxer/src/extract.rs
@@ -44,14 +44,13 @@ pub fn read_group(segment: &mut EbmlReader) -> anyhow::Result<(u64, Block)> {
MatroskaTag::Crc32(_) => (),
MatroskaTag::Cluster(_) => bail!("unexpected cluster"),
MatroskaTag::Timestamp(_) => (),
- MatroskaTag::SimpleBlock(_buf) => {
- let block = Block::parse(&_buf)?;
+ MatroskaTag::SimpleBlock(block) => {
return Ok((1000, block)); // HDMV/PGS does not use duration?!
}
MatroskaTag::BlockGroup(Master::Start) => (),
MatroskaTag::BlockGroup(Master::End) => return Ok((dur.unwrap(), block.unwrap())),
MatroskaTag::BlockDuration(duration) => dur = Some(duration),
- MatroskaTag::Block(buf) => block = Some(Block::parse(&buf)?),
+ MatroskaTag::Block(blk) => block = Some(blk),
MatroskaTag::Cues(_) => bail!("reached cues, this is the end"),
MatroskaTag::Segment(Master::End) => bail!("extractor reached segment end"),
_ => debug!("(rs) tag ignored: {item:?}"),
diff --git a/remuxer/src/remux.rs b/remuxer/src/remux.rs
index 851b43d..a919354 100644
--- a/remuxer/src/remux.rs
+++ b/remuxer/src/remux.rs
@@ -13,7 +13,6 @@ use jellycommon::{
LocalTrack, NodePublic, SourceTrack,
};
use jellymatroska::{
- block::Block,
read::EbmlReader,
write::{bad_vint_length, vint_length, EbmlWriter},
Master, MatroskaTag,
@@ -262,7 +261,6 @@ pub fn remux_stream_into(
}
struct ReaderD<'a> {
- peek: Option<Block>,
stream: SegmentExtractIter<'a>,
mapped: u64,
}
@@ -280,12 +278,10 @@ pub fn remux_stream_into(
MatroskaTag::Cluster(Master::Start), // TODO shouldn't this be a child of cluster?
)
.context("seeking in input")?;
- let mut stream =
- SegmentExtractIter::new(&mut inp.reader, inp.source_track_index as u64);
+ let stream = SegmentExtractIter::new(&mut inp.reader, inp.source_track_index as u64);
Ok(ReaderD {
mapped: inp.mapped,
- peek: Some(stream.next()?.0), // TODO handle duration
stream,
})
})
@@ -309,10 +305,8 @@ pub fn remux_stream_into(
let mut cluster_blocks = vec![MatroskaTag::Timestamp(cluster.timestamp)];
for (block_track, index_block) in cluster.blocks {
let track_reader = &mut track_readers[block_track];
- let mut block = track_reader
- .peek
- .replace(track_reader.stream.next()?.0) // TODO handle duration
- .expect("source file too short");
+ // TODO handle duration
+ let mut block = track_reader.stream.next()?.0;
assert_eq!(index_block.size, block.data.len(), "seek index is wrong");
@@ -320,8 +314,7 @@ pub fn remux_stream_into(
block.timestamp_off = (index_block.pts - cluster.timestamp).try_into().unwrap();
trace!("n={} tso={}", block.track, block.timestamp_off);
- let buf = block.dump();
- cluster_blocks.push(MatroskaTag::SimpleBlock(buf))
+ cluster_blocks.push(MatroskaTag::SimpleBlock(block))
}
output.write_tag(&MatroskaTag::Cluster(Master::Collected(cluster_blocks)))?;
}
diff --git a/remuxer/src/seek_index.rs b/remuxer/src/seek_index.rs
index 7e9cee1..5bec6e6 100644
--- a/remuxer/src/seek_index.rs
+++ b/remuxer/src/seek_index.rs
@@ -84,8 +84,7 @@ fn import_seek_index_segment(
})) = children.n()
{
match item {
- MatroskaTag::Block(ref buf) => {
- let block = Block::parse(buf)?;
+ MatroskaTag::Block(ref block) => {
debug!(
"block: track={} tso={}",
block.track, block.timestamp_off
@@ -101,8 +100,7 @@ fn import_seek_index_segment(
}
}
}
- MatroskaTag::SimpleBlock(buf) => {
- let block = Block::parse(&buf)?;
+ MatroskaTag::SimpleBlock(block) => {
trace!(
"simple block: track={} tso={}",
block.track,
diff --git a/remuxer/src/segment_extractor.rs b/remuxer/src/segment_extractor.rs
index ec645c3..2a12802 100644
--- a/remuxer/src/segment_extractor.rs
+++ b/remuxer/src/segment_extractor.rs
@@ -40,8 +40,7 @@ impl<'a> SegmentExtractIter<'a> {
group = false;
}
MatroskaTag::BlockDuration(d) => duration = Some(d),
- MatroskaTag::SimpleBlock(buf) | MatroskaTag::Block(buf) => {
- let block = Block::parse(&buf)?;
+ MatroskaTag::SimpleBlock(block) | MatroskaTag::Block(block) => {
if block.track == self.extract {
trace!("block: track={} tso={}", block.track, block.timestamp_off);
if group {
diff --git a/remuxer/src/snippet.rs b/remuxer/src/snippet.rs
index daa50a9..ff391a2 100644
--- a/remuxer/src/snippet.rs
+++ b/remuxer/src/snippet.rs
@@ -196,10 +196,10 @@ pub fn write_snippet_into(
if let Some(duration) = duration {
blocks.push(MatroskaTag::BlockGroup(Master::Collected(vec![
MatroskaTag::BlockDuration(duration),
- MatroskaTag::Block(block.dump()),
+ MatroskaTag::Block(block),
])))
} else {
- blocks.push(MatroskaTag::SimpleBlock(block.dump()))
+ blocks.push(MatroskaTag::SimpleBlock(block))
}
}
output.write_tag(&MatroskaTag::Cluster(Master::Collected(blocks)))?;