mirror of
https://github.com/v0l/zap-stream-core.git
synced 2025-06-19 21:21:01 +00:00
Init demuxer
This commit is contained in:
25
src/pipeline/builder.rs
Normal file
25
src/pipeline/builder.rs
Normal file
@ -0,0 +1,25 @@
|
||||
use crate::demux::Demuxer;
|
||||
use crate::ingress::ConnectionInfo;
|
||||
use crate::pipeline::runner::PipelineRunner;
|
||||
use crate::pipeline::PipelineStep;
|
||||
use crate::webhook::Webhook;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct PipelineBuilder {
|
||||
webhook: Webhook,
|
||||
}
|
||||
|
||||
impl PipelineBuilder {
|
||||
pub fn new(webhook: Webhook) -> Self {
|
||||
Self { webhook }
|
||||
}
|
||||
|
||||
pub async fn build_for(&self, info: ConnectionInfo) -> Result<PipelineRunner, anyhow::Error> {
|
||||
let config = self.webhook.start(info).await?;
|
||||
|
||||
let mut steps: Vec<Box<dyn PipelineStep + Sync + Send>> = Vec::new();
|
||||
steps.push(Box::new(Demuxer::new()));
|
||||
|
||||
Ok(PipelineRunner::new(steps))
|
||||
}
|
||||
}
|
42
src/pipeline/mod.rs
Normal file
42
src/pipeline/mod.rs
Normal file
@ -0,0 +1,42 @@
|
||||
use async_trait::async_trait;
|
||||
use ffmpeg_sys_next::{av_packet_unref, AVPacket};
|
||||
use std::ops::DerefMut;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
pub mod builder;
|
||||
pub mod runner;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum PipelinePayload {
|
||||
/// No output
|
||||
Empty,
|
||||
/// Skip this step
|
||||
Skip,
|
||||
/// Raw bytes from ingress
|
||||
Bytes(bytes::Bytes),
|
||||
/// FFMpeg AVPacket
|
||||
AvPacket(*mut AVPacket),
|
||||
/// FFMpeg AVFrame
|
||||
AvFrame(),
|
||||
}
|
||||
|
||||
unsafe impl Send for PipelinePayload {}
|
||||
unsafe impl Sync for PipelinePayload {}
|
||||
|
||||
impl Drop for PipelinePayload {
|
||||
fn drop(&mut self) {
|
||||
match self {
|
||||
PipelinePayload::AvPacket(pkt) => unsafe {
|
||||
av_packet_unref(*pkt);
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait PipelineStep {
|
||||
fn name(&self) -> String;
|
||||
|
||||
async fn process(&mut self, pkg: PipelinePayload) -> Result<PipelinePayload, anyhow::Error>;
|
||||
}
|
21
src/pipeline/runner.rs
Normal file
21
src/pipeline/runner.rs
Normal file
@ -0,0 +1,21 @@
|
||||
use crate::pipeline::{PipelinePayload, PipelineStep};
|
||||
|
||||
pub struct PipelineRunner {
|
||||
steps: Vec<Box<dyn PipelineStep + Sync + Send>>,
|
||||
}
|
||||
|
||||
impl PipelineRunner {
|
||||
pub fn new(steps: Vec<Box<dyn PipelineStep + Sync + Send>>) -> Self {
|
||||
Self { steps }
|
||||
}
|
||||
|
||||
pub async fn push(&mut self, bytes: bytes::Bytes) -> Result<(), anyhow::Error> {
|
||||
let mut output = PipelinePayload::Bytes(bytes);
|
||||
for step in &mut self.steps {
|
||||
let output2 = step.process(output).await?;
|
||||
//info!("{} result: {:?}", step.name(), output2);
|
||||
output = output2;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user