aboutsummaryrefslogtreecommitdiff
path: root/remuxer/src
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-01-27 21:48:22 +0100
committermetamuffin <metamuffin@disroot.org>2023-01-27 21:48:22 +0100
commita742f7dbd8bda0bf23a6d5273e5dd2f83b9d4c9f (patch)
tree49ba83ef7aec7b2bf4ff61b41c621696c45c6e95 /remuxer/src
parent04e3ebfdda613be0e58290a49536116cc57ad147 (diff)
downloadjellything-a742f7dbd8bda0bf23a6d5273e5dd2f83b9d4c9f.tar
jellything-a742f7dbd8bda0bf23a6d5273e5dd2f83b9d4c9f.tar.bz2
jellything-a742f7dbd8bda0bf23a6d5273e5dd2f83b9d4c9f.tar.zst
clippy
Diffstat (limited to 'remuxer/src')
-rw-r--r--remuxer/src/import/mod.rs22
-rw-r--r--remuxer/src/lib.rs67
2 files changed, 59 insertions, 30 deletions
diff --git a/remuxer/src/import/mod.rs b/remuxer/src/import/mod.rs
index 1ceca1e..c3dbf49 100644
--- a/remuxer/src/import/mod.rs
+++ b/remuxer/src/import/mod.rs
@@ -26,7 +26,7 @@ pub fn import_read(path: &PathBuf, input: &mut EbmlReader, iteminfo: &mut ItemIn
match item {
MatroskaTag::Ebml(_) => {
let mut iter = Unflatten::new_with_end(input, item);
- while let Some(Ok(Unflat { children: _, item })) = iter.next() {
+ while let Some(Ok(Unflat { children: _, item })) = iter.n() {
match item {
MatroskaTag::DocType(t) => {
if !matches!(t.as_str(), "matroska" | "webm") {
@@ -58,12 +58,12 @@ fn import_read_segment(
let (mut timestamp_scale, mut duration) = (None, None);
let mut seek_index = HashMap::new();
- while let Some(Ok(Unflat { children, item })) = children.next() {
+ while let Some(Ok(Unflat { children, item })) = children.n() {
match item {
MatroskaTag::SeekHead(_) => {}
MatroskaTag::Info(_) => {
let mut children = children.unwrap();
- while let Some(Ok(Unflat { children: _, item })) = children.next() {
+ while let Some(Ok(Unflat { children: _, item })) = children.n() {
match item {
MatroskaTag::TimestampScale(v) => timestamp_scale = Some(v),
MatroskaTag::Duration(v) => duration = Some(v),
@@ -76,7 +76,7 @@ fn import_read_segment(
MatroskaTag::Chapters(_) => {}
MatroskaTag::Tracks(_) => {
let mut children = children.unwrap();
- while let Some(Ok(Unflat { children, item })) = children.next() {
+ while let Some(Ok(Unflat { children, item })) = children.n() {
match item {
MatroskaTag::TrackEntry(_) => {
let mut children = children.unwrap();
@@ -98,7 +98,7 @@ fn import_read_segment(
None, None, None, None, None, None, None, None, None, None, None,
None, None,
);
- while let Some(Ok(Unflat { children, item })) = children.next() {
+ while let Some(Ok(Unflat { children, item })) = children.n() {
match item {
MatroskaTag::CodecID(b) => codec = Some(b),
MatroskaTag::Language(v) => language = Some(v),
@@ -109,7 +109,7 @@ fn import_read_segment(
MatroskaTag::DefaultDuration(v) => default_duration = Some(v),
MatroskaTag::Audio(_) => {
let mut children = children.unwrap();
- while let Some(Ok(Unflat { item, .. })) = children.next() {
+ while let Some(Ok(Unflat { item, .. })) = children.n() {
match item {
MatroskaTag::Channels(v) => {
channels = Some(v as usize)
@@ -124,7 +124,7 @@ fn import_read_segment(
}
MatroskaTag::Video(_) => {
let mut children = children.unwrap();
- while let Some(Ok(Unflat { item, .. })) = children.next() {
+ while let Some(Ok(Unflat { item, .. })) = children.n() {
match item {
MatroskaTag::PixelWidth(v) => width = Some(v),
MatroskaTag::PixelHeight(v) => height = Some(v),
@@ -174,14 +174,14 @@ fn import_read_segment(
let mut children = children.unwrap();
let mut pts = 0;
- while let Some(Ok(Unflat { children, item })) = children.next() {
+ 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.next() {
+ while let Some(Ok(Unflat { children: _, item })) = children.n() {
match item {
MatroskaTag::Block(ref buf) => {
let block = Block::parse(buf)?;
@@ -231,12 +231,12 @@ fn import_read_segment(
for (tn, index) in seek_index {
bincode::encode_into_std_write(
index,
- &mut File::create(path.with_extension(&format!("si.{}", tn)))?,
+ &mut File::create(path.with_extension(&format!("si.{tn}")))?,
bincode::config::standard(),
)?;
}
iteminfo.duration =
- (duration.unwrap() * timestamp_scale.unwrap() as f64) as f64 / 1_000_000_000 as f64;
+ (duration.unwrap() * timestamp_scale.unwrap() as f64) / 1_000_000_000_f64;
Ok(())
}
diff --git a/remuxer/src/lib.rs b/remuxer/src/lib.rs
index 1dfbacd..3ce6b78 100644
--- a/remuxer/src/lib.rs
+++ b/remuxer/src/lib.rs
@@ -21,6 +21,7 @@ use std::{collections::VecDeque, fs::File, io::Write, path::PathBuf};
pub struct RemuxerContext {}
impl RemuxerContext {
+ #[allow(clippy::new_without_default)]
pub fn new() -> Self {
Self {}
}
@@ -63,7 +64,7 @@ impl RemuxerContext {
info!("\t {}", info);
let file = File::open(&source_path).context("opening source file")?;
let mut index =
- File::open(source_path.with_extension(&format!("si.{}", info.track_number)))
+ File::open(source_path.with_extension(format!("si.{}", info.track_number)))
.context("opening seek index file")?;
let index = bincode::decode_from_std_read::<SeekIndex, _, _>(
&mut index,
@@ -79,7 +80,6 @@ impl RemuxerContext {
temp_index: 0,
})
})
- .into_iter()
.collect::<anyhow::Result<Vec<_>>>()?;
output.write_tag(&MatroskaTag::Ebml(Master::Collected(vec![
@@ -101,7 +101,7 @@ impl RemuxerContext {
output.write_tag(&MatroskaTag::Info(Master::Collected(vec![
MatroskaTag::TimestampScale(1_000_000),
MatroskaTag::Duration(iteminfo.duration * 1000.0),
- MatroskaTag::Title(iteminfo.title.clone()),
+ MatroskaTag::Title(iteminfo.title),
MatroskaTag::MuxingApp("jellyremux".to_string()),
MatroskaTag::WritingApp("jellything".to_string()),
])))?;
@@ -145,7 +145,7 @@ impl RemuxerContext {
if best_block.pts > cluster_pts + 2_000 {
let cluster_content_size = 1 // timestamp tag
+ 1 // timestamp tag size
- + EbmlWriter::vint_length(cluster_pts as u64) // timestamp tag value
+ + EbmlWriter::vint_length(cluster_pts) // timestamp tag value
+ p;
let cluster_header_size = 4 // tag length
+ EbmlWriter::vint_length(cluster_content_size as u64)// size varint
@@ -153,7 +153,7 @@ impl RemuxerContext {
clusters.push(ClusterLayout {
position: gp,
timestamp: cluster_pts,
- blocks: std::mem::replace(&mut cluster, vec![]),
+ blocks: std::mem::take(&mut cluster),
});
cluster_pts = best_block.pts;
@@ -174,6 +174,34 @@ impl RemuxerContext {
clusters
};
+ output.write_tag(&MatroskaTag::Cues(Master::Collected(
+ segment_layout
+ .iter()
+ .map(|cluster| {
+ MatroskaTag::CuePoint(Master::Collected(
+ [
+ MatroskaTag::CueTime(cluster.timestamp),
+ MatroskaTag::CueTrackPositions(Master::Collected(
+ [
+ MatroskaTag::CueTrack(0),
+ MatroskaTag::CueClusterPosition(cluster.position as u64),
+ ]
+ .to_vec(),
+ )),
+ MatroskaTag::CueTrackPositions(Master::Collected(
+ [
+ MatroskaTag::CueTrack(1),
+ MatroskaTag::CueClusterPosition(cluster.position as u64),
+ ]
+ .to_vec(),
+ )),
+ ]
+ .to_vec(),
+ ))
+ })
+ .collect(),
+ )))?;
+
struct ReaderD<'a> {
_info: SourceTrack,
peek: Option<AbsoluteBlock>,
@@ -206,6 +234,7 @@ impl RemuxerContext {
});
}
+ let segment_start_position = output.position();
for (cluster_index, cluster) in segment_layout.into_iter().enumerate() {
info!(
"writing cluster {cluster_index} (pts_base={}) with {} blocks",
@@ -214,9 +243,9 @@ impl RemuxerContext {
);
debug!(
"calculation was {} bytes off",
- cluster.position as i64 - output.position() as i64
+ cluster.position as i64 - (output.position() - segment_start_position) as i64
);
- let mut cluster_blocks = vec![MatroskaTag::Timestamp(cluster.timestamp as u64)];
+ let mut cluster_blocks = vec![MatroskaTag::Timestamp(cluster.timestamp)];
for (block_index, iblock) in cluster.blocks {
let kn = &mut ks[block_index];
let mut block = kn
@@ -268,14 +297,14 @@ impl SegmentExtractIter<'_> {
}
pub fn read(&mut self) -> Result<()> {
- let Unflat { children, item } = self.segment.next().ok_or(anyhow!("eof"))??;
+ let Unflat { children, item } = self.segment.n().ok_or(anyhow!("eof"))??;
let mut pts_base = 0;
match item {
MatroskaTag::SeekHead(_) => {}
MatroskaTag::Info(_) => {}
MatroskaTag::Cluster(_) => {
let mut children = children.unwrap();
- while let Some(Ok(Unflat { children, item })) = children.next() {
+ while let Some(Ok(Unflat { children, item })) = children.n() {
match item {
MatroskaTag::Crc32(_) => (),
MatroskaTag::Timestamp(ts) => {
@@ -286,18 +315,17 @@ impl SegmentExtractIter<'_> {
trace!("group");
let mut children = children.unwrap();
- let mut duration = None;
+ // let mut duration = None;
let mut block = None;
- while let Some(Ok(Unflat { children: _, item })) = children.next() {
+ while let Some(Ok(Unflat { children: _, item })) = children.n() {
match item {
MatroskaTag::Block(buf) => block = Some(buf),
- MatroskaTag::BlockDuration(v) => duration = Some(v),
+ // MatroskaTag::BlockDuration(v) => duration = Some(v),
_ => debug!("ignored {item:?}"),
}
}
// TODO duration
- drop(duration);
let block = Block::parse(&block.unwrap())?;
if block.track == self.extract {
trace!("block: track={} tso={}", block.track, block.timestamp_off);
@@ -333,12 +361,13 @@ impl SegmentExtractIter<'_> {
}
pub fn track_to_ebml(number: u64, track: &SourceTrack) -> MatroskaTag {
- let mut els = Vec::new();
- els.push(MatroskaTag::TrackNumber(number));
- els.push(MatroskaTag::TrackUID(number));
- els.push(MatroskaTag::FlagLacing(0));
- els.push(MatroskaTag::Language(track.language.clone()));
- els.push(MatroskaTag::CodecID(track.codec.clone()));
+ let mut els = vec![
+ MatroskaTag::TrackNumber(number),
+ MatroskaTag::TrackUID(number),
+ MatroskaTag::FlagLacing(0),
+ MatroskaTag::Language(track.language.clone()),
+ MatroskaTag::CodecID(track.codec.clone()),
+ ];
if let Some(d) = &track.default_duration {
els.push(MatroskaTag::DefaultDuration(*d));
}