aboutsummaryrefslogtreecommitdiff
path: root/remuxer/src
diff options
context:
space:
mode:
Diffstat (limited to 'remuxer/src')
-rw-r--r--remuxer/src/lib.rs54
1 files changed, 50 insertions, 4 deletions
diff --git a/remuxer/src/lib.rs b/remuxer/src/lib.rs
index 69a6f4b..8b4e2ed 100644
--- a/remuxer/src/lib.rs
+++ b/remuxer/src/lib.rs
@@ -1,9 +1,55 @@
-use std::path::PathBuf;
-
-use jellycommon::Source;
+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},
+ WebmIterator, WebmWriter,
+};
pub struct RemuxerContext {}
impl RemuxerContext {
- pub fn generate(&self, path_base: PathBuf, source: Source) {}
+ pub fn new() -> Arc<Self> {
+ Arc::new(Self {})
+ }
+
+ pub fn generate_into(
+ &self,
+ writer: impl Write,
+ path_base: PathBuf,
+ item: ItemInfo,
+ selection: Vec<u64>,
+ ) -> anyhow::Result<()> {
+ let source_path = path_base.join(item.source.path);
+ info!("remuxing {source_path:?} to have tracks {selection:?}");
+ let mut input = File::open(source_path)?;
+
+ let tags = WebmIterator::new(&mut input, &[MatroskaSpec::TrackEntry(Master::Start)]);
+ let mut output = WebmWriter::new(writer);
+
+ for tag in tags {
+ match tag.unwrap() {
+ x => {
+ // debug!("tag");
+ output.write(&x)?;
+ }
+ }
+ }
+ Ok(())
+ }
+}
+
+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())
+ }
+
+ fn flush(&mut self) -> std::io::Result<()> {
+ Ok(()) // TODO should we actually do something here?
+ }
}