feat: upgrade to ffmpeg-rs-raw (WIP)

This commit is contained in:
2024-11-13 11:43:28 +00:00
parent 96e4a38e09
commit 6f618ef58f
27 changed files with 712 additions and 2372 deletions

View File

@ -1,50 +1,19 @@
use anyhow::Result;
use log::info;
use std::path::PathBuf;
use log::{error, info};
use tokio::io::AsyncReadExt;
use tokio::sync::mpsc::unbounded_channel;
use crate::ingress::{spawn_pipeline, ConnectionInfo};
use crate::settings::Settings;
use crate::ingress::ConnectionInfo;
use crate::pipeline::builder::PipelineBuilder;
pub async fn listen(path: PathBuf, builder: PipelineBuilder) -> Result<(), anyhow::Error> {
pub async fn listen(path: PathBuf, settings: Settings) -> Result<()> {
info!("Sending file {}", path.to_str().unwrap());
tokio::spawn(async move {
let (tx, rx) = unbounded_channel();
let info = ConnectionInfo {
ip_addr: "".to_owned(),
endpoint: "file-input".to_owned(),
};
let info = ConnectionInfo {
ip_addr: "127.0.0.1:6969".to_string(),
endpoint: "file-input".to_owned(),
};
let file = std::fs::File::open(path)?;
spawn_pipeline(info, settings, Box::new(file));
if let Ok(mut pl) = builder.build_for(info, rx).await {
std::thread::spawn(move || loop {
if let Err(e) = pl.run() {
error!("Pipeline error: {}\n{}", e, e.backtrace());
break;
}
});
if let Ok(mut stream) = tokio::fs::File::open(path).await {
let mut buf = [0u8; 4096];
loop {
if let Ok(r) = stream.read(&mut buf).await {
if r > 0 {
if let Err(e) = tx.send(bytes::Bytes::copy_from_slice(&buf[..r])) {
error!("Failed to send file: {}", e);
break;
}
} else {
break;
}
} else {
break;
}
}
info!("EOF");
}
}
});
Ok(())
}