placeholder functions for decoding

This commit is contained in:
Muaz Ahmad 2023-10-09 14:40:57 +05:00
parent ba47cd1b3b
commit fc1465b52f
3 changed files with 60 additions and 2 deletions

9
src/decode/cmds.rs Normal file
View file

@ -0,0 +1,9 @@
use std::sync::Arc;
use std::error::Error;
use crate::util;
use crate::decode::codecs::Decoder;
pub fn spawn(metadata: Arc<util::Metadata>) -> Result<(impl Decoder, impl Decoder), Box<dyn Error>> {
todo!();
}

33
src/decode/codecs/mod.rs Normal file
View file

@ -0,0 +1,33 @@
use std::sync::mpsc;
use std::error::Error;
use crate::util;
pub trait Decoder {
fn write_nalu(&mut self, nalu: util::NALUPacket) -> Result<(), Box<dyn Error + Send + Sync>>;
fn write_loop(&mut self, chan_in: mpsc::Receiver<util::NALUPacket>, err_in: mpsc::Sender<Box<dyn Error + Send + Sync>>) {
loop {
let nalu = match chan_in.recv() {
Ok(x) => x,
Err(err) => {util::thread_freeze(err_in, Box::new(err)); return}
};
match self.write_nalu(nalu) {
Ok(_) => (),
Err(err) => {util::thread_freeze(err_in, err); return}
}
}
}
fn read_raw(&mut self) -> Result<util::RawMedia, Box<dyn Error + Send + Sync>>;
fn read_loop(&mut self, chan_out: mpsc::Sender<util::RawMedia>, err_in: mpsc::Sender<Box<dyn Error + Send + Sync>>) {
loop {
let raw_sample = match self.read_raw() {
Ok(x) => x,
Err(err) => {util::thread_freeze(err_in, err); return}
};
match chan_out.send(raw_sample) {
Ok(_) => (),
Err(err) => {util::thread_freeze(err_in, Box::new(err)); return}
}
}
}
}

View file

@ -1,8 +1,12 @@
mod cmds;
mod codecs;
use std::sync::{mpsc, Arc};
use std::error::Error;
use std::thread;
use crate::util;
use crate::decode::codecs::Decoder;
pub fn spawn(
v: mpsc::Receiver<util::NALUPacket>,
@ -19,15 +23,27 @@ pub fn spawn(
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();
let metadata_handle = metadata.clone();
let (v_decoder, a_decoder) = cmds::spawn(metadata.clone())?;
spawn_threads(v, raw_v_in, v_decoder, a, raw_a_in, a_decoder, err_in);
thread::spawn(move || {
&raw_v_in;
&raw_a_in;
&err_in;
&metadata_handle;
&v;
&a;
thread::park();
});
return Ok((raw_v_out, raw_a_out, err_out));
}
fn spawn_threads(
v: mpsc::Receiver<util::NALUPacket>,
raw_v_in: mpsc::Sender<util::RawMedia>,
v_decoder: impl Decoder,
a: mpsc::Receiver<util::NALUPacket>,
raw_a_in: mpsc::Sender<util::RawMedia>,
a_decoder: impl Decoder,
err_in: mpsc::Sender<Box<dyn Error + Send + Sync>>
) {
todo!();
}