mirror of
https://github.com/v0l/zap-stream-core.git
synced 2025-06-19 04:44:58 +00:00
feat: upgrade to ffmpeg-rs-raw (WIP)
This commit is contained in:
@ -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(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user