aboutsummaryrefslogtreecommitdiff
path: root/remuxer/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'remuxer/src/lib.rs')
-rw-r--r--remuxer/src/lib.rs59
1 files changed, 42 insertions, 17 deletions
diff --git a/remuxer/src/lib.rs b/remuxer/src/lib.rs
index 95bd1ff..95e6e8b 100644
--- a/remuxer/src/lib.rs
+++ b/remuxer/src/lib.rs
@@ -1,9 +1,10 @@
+pub mod format;
+
use jellycommon::ItemInfo;
use log::{debug, info};
use std::{fs::File, io::Write, path::PathBuf, sync::Arc};
-use tokio::sync::mpsc::Sender;
use webm_iterable::{
- matroska_spec::{Master, MatroskaSpec, Block},
+ matroska_spec::{Block, Master, MatroskaSpec},
WebmIterator, WebmWriter,
};
@@ -17,6 +18,7 @@ impl RemuxerContext {
pub fn generate_into(
&self,
writer: impl Write,
+ offset: usize,
path_base: PathBuf,
item: ItemInfo,
selection: Vec<u64>,
@@ -28,9 +30,19 @@ impl RemuxerContext {
let tags = WebmIterator::new(&mut input, &[MatroskaSpec::TrackEntry(Master::Start)]);
let mut output = WebmWriter::new(writer);
+ let mut tscale = None;
+ let mut duration = None;
+ let mut ignore = false;
+
for tag in tags {
let tag = tag.unwrap();
match tag {
+ MatroskaSpec::SeekHead(Master::Start) | MatroskaSpec::Cues(Master::Start) => {
+ ignore = true
+ }
+ MatroskaSpec::SeekHead(Master::End) | MatroskaSpec::Cues(Master::End) => {
+ ignore = false
+ }
MatroskaSpec::TrackEntry(master) => {
let children = master.get_children();
let mut number = None;
@@ -50,17 +62,31 @@ impl RemuxerContext {
if selection.contains(&block.track) {
output.write(&tag)?;
}
- },
+ }
MatroskaSpec::SimpleBlock(ref data) => {
let data: &[u8] = &data;
let block: Block = data.try_into()?;
if selection.contains(&block.track) {
output.write(&tag)?;
}
- },
+ }
+ MatroskaSpec::Info(Master::Start) => (),
+ MatroskaSpec::TimestampScale(n) => tscale = Some(n),
+ MatroskaSpec::Duration(n) => duration = Some(n),
+ MatroskaSpec::Info(Master::End) => {
+ output.write(&MatroskaSpec::Info(Master::Full(vec![
+ MatroskaSpec::TimestampScale(tscale.unwrap()),
+ MatroskaSpec::Title(item.title.clone()),
+ MatroskaSpec::Duration(duration.unwrap()),
+ MatroskaSpec::MuxingApp("jellyremux".to_string()),
+ MatroskaSpec::WritingApp("jellything".to_string()),
+ ])))?;
+ }
x => {
- // debug!("tag");
- output.write(&x)?;
+ if !ignore {
+ debug!("{x:?}");
+ output.write(&x)?;
+ }
}
}
}
@@ -68,16 +94,15 @@ impl RemuxerContext {
}
}
-pub struct SendWriter(pub Sender<Vec<u8>>);
+// pub struct SendWriter(pub Sender<Vec<u8>>);
-impl Write for SendWriter {
- fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
- debug!("write {buf:?}");
- self.0.blocking_send(buf.to_owned()).unwrap();
- Ok(buf.len())
- }
+// impl Write for SendWriter {
+// fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
+// self.0.blocking_send(buf.to_owned()).unwrap();
+// Ok(buf.len())
+// }
- fn flush(&mut self) -> std::io::Result<()> {
- Ok(()) // TODO should we actually do something here?
- }
-}
+// fn flush(&mut self) -> std::io::Result<()> {
+// Ok(()) // TODO should we actually do something here?
+// }
+// }