mirror of
https://github.com/v0l/zap-stream-core.git
synced 2025-06-19 21:21:01 +00:00
Refactor pipeline
This commit is contained in:
@ -8,7 +8,7 @@ use ffmpeg_sys_next::{
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::demux::info::DemuxStreamInfo;
|
||||
use crate::demux::info::DemuxerInfo;
|
||||
use crate::egress::EgressConfig;
|
||||
use crate::variant::VariantStream;
|
||||
|
||||
@ -17,11 +17,14 @@ pub mod runner;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub enum EgressType {
|
||||
/// HLS output egress
|
||||
HLS(EgressConfig),
|
||||
DASH,
|
||||
WHEP,
|
||||
MPEGTS(EgressConfig),
|
||||
|
||||
/// Record streams to local disk
|
||||
Recorder(EgressConfig),
|
||||
|
||||
/// Forward streams to another RTMP server
|
||||
RTMPForwarder(EgressConfig),
|
||||
}
|
||||
|
||||
impl Display for EgressType {
|
||||
@ -31,10 +34,8 @@ impl Display for EgressType {
|
||||
"{}",
|
||||
match self {
|
||||
EgressType::HLS(c) => format!("{}", c),
|
||||
EgressType::DASH => "DASH".to_owned(),
|
||||
EgressType::WHEP => "WHEP".to_owned(),
|
||||
EgressType::MPEGTS(c) => format!("{}", c),
|
||||
EgressType::Recorder(c) => format!("{}", c),
|
||||
EgressType::RTMPForwarder(c) => format!("{}", c),
|
||||
}
|
||||
)
|
||||
}
|
||||
@ -42,19 +43,21 @@ impl Display for EgressType {
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
|
||||
pub struct PipelineConfig {
|
||||
pub id: uuid::Uuid,
|
||||
pub recording: Vec<VariantStream>,
|
||||
pub id: Uuid,
|
||||
|
||||
/// Transcoded/Copied stream config
|
||||
pub variants: Vec<VariantStream>,
|
||||
|
||||
/// Output muxers
|
||||
pub egress: Vec<EgressType>,
|
||||
}
|
||||
|
||||
impl Display for PipelineConfig {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "\nPipeline Config ID={}", self.id)?;
|
||||
if !self.recording.is_empty() {
|
||||
write!(f, "\nRecording:")?;
|
||||
for r in &self.recording {
|
||||
write!(f, "\n\t{}", r)?;
|
||||
}
|
||||
write!(f, "\nVariants:")?;
|
||||
for v in &self.variants {
|
||||
write!(f, "\n\t{}", v)?;
|
||||
}
|
||||
if !self.egress.is_empty() {
|
||||
write!(f, "\nEgress:")?;
|
||||
@ -72,8 +75,6 @@ pub enum AVPacketSource {
|
||||
Demuxer(*mut AVStream),
|
||||
/// AVPacket from an encoder
|
||||
Encoder(Uuid),
|
||||
/// AVPacket from muxer
|
||||
Muxer(Uuid),
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
@ -98,10 +99,10 @@ pub enum PipelinePayload {
|
||||
AvPacket(*mut AVPacket, AVPacketSource),
|
||||
/// FFMpeg AVFrame
|
||||
AvFrame(*mut AVFrame, AVFrameSource),
|
||||
/// Information about the input stream
|
||||
SourceInfo(DemuxStreamInfo),
|
||||
/// Information about an encoder in this pipeline
|
||||
EncoderInfo(Uuid, *const AVCodecContext),
|
||||
/// Source stream information provided by the demuxer
|
||||
SourceInfo(DemuxerInfo),
|
||||
/// Flush pipeline
|
||||
Flush,
|
||||
}
|
||||
@ -113,8 +114,6 @@ unsafe impl Sync for PipelinePayload {}
|
||||
impl Clone for PipelinePayload {
|
||||
fn clone(&self) -> Self {
|
||||
match self {
|
||||
PipelinePayload::Empty => PipelinePayload::Empty,
|
||||
PipelinePayload::Bytes(b) => PipelinePayload::Bytes(b.clone()),
|
||||
PipelinePayload::AvPacket(p, v) => unsafe {
|
||||
assert!(!(**p).data.is_null(), "Cannot clone empty packet");
|
||||
let new_pkt = av_packet_clone(*p);
|
||||
@ -127,9 +126,11 @@ impl Clone for PipelinePayload {
|
||||
av_frame_copy_props(new_frame, *p);
|
||||
PipelinePayload::AvFrame(new_frame, v.clone())
|
||||
},
|
||||
PipelinePayload::SourceInfo(i) => PipelinePayload::SourceInfo(i.clone()),
|
||||
PipelinePayload::EncoderInfo(v, s) => PipelinePayload::EncoderInfo(*v, *s),
|
||||
PipelinePayload::Flush => PipelinePayload::Flush,
|
||||
PipelinePayload::Empty => PipelinePayload::Empty,
|
||||
PipelinePayload::Bytes(b) => PipelinePayload::Bytes(b.clone()),
|
||||
PipelinePayload::EncoderInfo(a, b) => PipelinePayload::EncoderInfo(*a, *b),
|
||||
PipelinePayload::SourceInfo(a) => PipelinePayload::SourceInfo(a.clone()),
|
||||
PipelinePayload::Flush => PipelinePayload::Flush
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -149,5 +150,5 @@ impl Drop for PipelinePayload {
|
||||
}
|
||||
|
||||
pub trait PipelineProcessor {
|
||||
fn process(&mut self) -> Result<(), Error>;
|
||||
fn process(&mut self, pkg: PipelinePayload) -> Result<Vec<PipelinePayload>, Error>;
|
||||
}
|
||||
|
Reference in New Issue
Block a user