basic placeholders for codecs H264 and AAC
This commit is contained in:
parent
fc1465b52f
commit
ad5d954edb
6 changed files with 109 additions and 9 deletions
|
@ -3,7 +3,16 @@ use std::error::Error;
|
||||||
|
|
||||||
use crate::util;
|
use crate::util;
|
||||||
use crate::decode::codecs::Decoder;
|
use crate::decode::codecs::Decoder;
|
||||||
|
use crate::decode::codecs;
|
||||||
|
|
||||||
pub fn spawn(metadata: Arc<util::Metadata>) -> Result<(impl Decoder, impl Decoder), Box<dyn Error>> {
|
pub fn spawn(metadata: Arc<util::Metadata>) -> Result<(impl Decoder, impl Decoder), Box<dyn Error>> {
|
||||||
todo!();
|
let v = match metadata.video.codec {
|
||||||
|
Some(util::VideoCodec::H264) => codecs::video::new_h264(metadata.clone())?,
|
||||||
|
_ => {return Err(Box::new(util::DecoderError::CodecNotImplemented));}
|
||||||
|
};
|
||||||
|
let a = match metadata.audio.codec {
|
||||||
|
Some(util::AudioCodec::AAC) => codecs::audio::new_aac(metadata)?,
|
||||||
|
_ => {return Err(Box::new(util::DecoderError::CodecNotImplemented));}
|
||||||
|
};
|
||||||
|
return Ok((v, a));
|
||||||
}
|
}
|
||||||
|
|
36
src/decode/codecs/audio.rs
Normal file
36
src/decode/codecs/audio.rs
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
use std::error::Error;
|
||||||
|
use std::process::{ChildStdin, ChildStdout, Command, Stdio};
|
||||||
|
use std::sync::Arc;
|
||||||
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
|
use crate::decode::codecs::Decoder;
|
||||||
|
use crate::util;
|
||||||
|
|
||||||
|
pub struct AACDecoder {
|
||||||
|
stdin: ChildStdin,
|
||||||
|
stdout: ChildStdout,
|
||||||
|
metadata: Arc<util::Metadata>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Decoder for AACDecoder {
|
||||||
|
fn write_nalu(&mut self, nalu: util::NALUPacket) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||||
|
self.stdin.write_all(nalu.packet_data.as_slice())?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
fn read_raw(&mut self) -> Result<util::RawMedia, Box<dyn Error + Send + Sync>> {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_aac(metadata: Arc<util::Metadata>) -> Result<AACDecoder, Box<dyn Error>> {
|
||||||
|
let cmd = Command::new("tee").stdin(Stdio::piped()).stdout(Stdio::piped()).spawn()?;
|
||||||
|
let stdin = match cmd.stdin {
|
||||||
|
Some(x) => x,
|
||||||
|
None => {return Err(Box::new(util::DecoderError::InvalidPipeInit))}
|
||||||
|
};
|
||||||
|
let stdout = match cmd.stdout {
|
||||||
|
Some(x) => x,
|
||||||
|
None => {return Err(Box::new(util::DecoderError::InvalidPipeInit))}
|
||||||
|
};
|
||||||
|
return Ok(AACDecoder {stdin: stdin, stdout: stdout, metadata: metadata})
|
||||||
|
}
|
|
@ -1,3 +1,6 @@
|
||||||
|
pub mod video;
|
||||||
|
pub mod audio;
|
||||||
|
|
||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
|
|
36
src/decode/codecs/video.rs
Normal file
36
src/decode/codecs/video.rs
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
use std::error::Error;
|
||||||
|
use std::process::{ChildStdin, ChildStdout, Stdio, Command};
|
||||||
|
use std::sync::Arc;
|
||||||
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
|
use crate::decode::codecs::Decoder;
|
||||||
|
use crate::util;
|
||||||
|
|
||||||
|
pub struct H264Decoder {
|
||||||
|
stdin: ChildStdin,
|
||||||
|
stdout: ChildStdout,
|
||||||
|
metadata: Arc<util::Metadata>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Decoder for H264Decoder {
|
||||||
|
fn write_nalu(&mut self, nalu: util::NALUPacket) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||||
|
self.stdin.write_all(nalu.packet_data.as_slice())?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
fn read_raw(&mut self) -> Result<util::RawMedia, Box<dyn Error + Send + Sync>> {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_h264(metadata: Arc<util::Metadata>) -> Result<H264Decoder, Box<dyn Error>> {
|
||||||
|
let cmd = Command::new("tee").stdin(Stdio::piped()).stdout(Stdio::piped()).spawn()?;
|
||||||
|
let stdin = match cmd.stdin {
|
||||||
|
Some(x) => x,
|
||||||
|
None => {return Err(Box::new(util::DecoderError::InvalidPipeInit))}
|
||||||
|
};
|
||||||
|
let stdout = match cmd.stdout {
|
||||||
|
Some(x) => x,
|
||||||
|
None => {return Err(Box::new(util::DecoderError::InvalidPipeInit))}
|
||||||
|
};
|
||||||
|
return Ok(H264Decoder {stdin: stdin, stdout: stdout, metadata: metadata});
|
||||||
|
}
|
|
@ -25,14 +25,6 @@ pub fn spawn(
|
||||||
let (err_in, err_out) = mpsc::channel();
|
let (err_in, err_out) = mpsc::channel();
|
||||||
let (v_decoder, a_decoder) = cmds::spawn(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);
|
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;
|
|
||||||
&v;
|
|
||||||
&a;
|
|
||||||
thread::park();
|
|
||||||
});
|
|
||||||
return Ok((raw_v_out, raw_a_out, err_out));
|
return Ok((raw_v_out, raw_a_out, err_out));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -128,6 +128,30 @@ impl fmt::Display for DemuxerError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum DecoderError {
|
||||||
|
CodecNotImplemented,
|
||||||
|
InvalidPipeInit,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Error for DecoderError {}
|
||||||
|
|
||||||
|
#[allow(unreachable_patterns)]
|
||||||
|
impl fmt::Debug for DecoderError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
DecoderError::CodecNotImplemented => write!(f, "Codec not recognized"),
|
||||||
|
DecoderError::InvalidPipeInit => write!(f, "Decoder has invalid piping"),
|
||||||
|
_ => write!(f, "Error not described yet")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for DecoderError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
fmt::Debug::fmt(self, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// funcs
|
// funcs
|
||||||
|
|
||||||
pub fn thread_freeze(err_sender: mpsc::Sender<Box<dyn Error + Send + Sync>>, err: Box<dyn Error + Send + Sync>) {
|
pub fn thread_freeze(err_sender: mpsc::Sender<Box<dyn Error + Send + Sync>>, err: Box<dyn Error + Send + Sync>) {
|
||||||
|
|
Loading…
Reference in a new issue