From a0dcd5d6f1f0555be9a3a2978fc2e0a0732332fd Mon Sep 17 00:00:00 2001 From: Muaz Ahmad Date: Fri, 6 Oct 2023 23:43:50 +0500 Subject: [PATCH] baseline implementations so testing can happen --- src/decode/mod.rs | 5 ++++- src/encode/mod.rs | 5 ++++- src/main.rs | 13 ++++++++++++- src/muxer/mod.rs | 3 ++- src/util/mod.rs | 22 +++++++++++++++++----- 5 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/decode/mod.rs b/src/decode/mod.rs index 72d9556..2117121 100644 --- a/src/decode/mod.rs +++ b/src/decode/mod.rs @@ -14,5 +14,8 @@ pub fn spawn( ), Box > { - todo!(); + let (_raw_v_in, raw_v_out) = mpsc::channel(); + let (_raw_a_in, raw_a_out) = mpsc::channel(); + let (_err_in, err_out) = mpsc::channel(); + return Ok((raw_v_out, raw_a_out, err_out)); } diff --git a/src/encode/mod.rs b/src/encode/mod.rs index 07fa3d6..6e3f157 100644 --- a/src/encode/mod.rs +++ b/src/encode/mod.rs @@ -15,5 +15,8 @@ pub fn spawn( ), Box > { - todo!(); + let (v_in, v_out) = mpsc::channel(); + let (a_in, a_out) = mpsc::channel(); + let (err_in, err_out) = mpsc::channel(); + return Ok((v_out, a_out, err_out)); } diff --git a/src/main.rs b/src/main.rs index 59f5411..9f4336c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,8 @@ mod muxer; use std::process::exit; use std::sync::mpsc; +use std::thread; +use std::time::Duration; fn init() -> Result<[mpsc::Receiver>; 4], Box>{ let (v_out, a_out, metadata, demux_err_recv) = demux::spawn()?; @@ -16,7 +18,16 @@ fn init() -> Result<[mpsc::Receiver>; 4 } fn process(error_handles: [mpsc::Receiver>; 4]) -> Result<(), Box> { - todo!(); + loop { + for i in 0..4 { + match error_handles[i].try_recv() { + Ok(err) => return Err(err), + Err(mpsc::TryRecvError::Empty) => (), + Err(err) => return Err(Box::new(util::ThreadError(i))), + } + } + thread::sleep(Duration::from_millis(100)); + } } fn main() { diff --git a/src/muxer/mod.rs b/src/muxer/mod.rs index 6a9e922..110e4b9 100644 --- a/src/muxer/mod.rs +++ b/src/muxer/mod.rs @@ -11,5 +11,6 @@ pub fn spawn( mpsc::Receiver>, Box > { - todo!(); + let (err_in, err_out) = mpsc::channel(); + return Ok(err_out); } diff --git a/src/util/mod.rs b/src/util/mod.rs index 262af45..78550b1 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -49,11 +49,6 @@ impl Metadata { } } -pub enum FileType { - FLV, - MPEGTS, -} - pub enum NALUPacketType { Audio, Video, @@ -76,6 +71,23 @@ pub struct RawMedia { // Errors +pub struct ThreadError(pub usize); + +impl Error for ThreadError {} + +impl fmt::Debug for ThreadError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "Disconnect Error in thread index {}, data pipe broken", self.0) + } +} + +impl fmt::Display for ThreadError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(self, f) + } +} + + pub enum DemuxerError { UnknownSyncByte, FLVUnknownTagType,