diff --git a/src/decode/codecs/audio.rs b/src/decode/codecs/audio.rs index 877cf23..efab7a6 100644 --- a/src/decode/codecs/audio.rs +++ b/src/decode/codecs/audio.rs @@ -1,36 +1,34 @@ use std::error::Error; -use std::process::{ChildStdin, ChildStdout, Command, Stdio}; -use std::sync::Arc; +use std::process::{Child, Command, Stdio}; +use std::sync::{Arc, Mutex}; use std::io::{Read, Write}; +use std::fs::File; use crate::decode::codecs::Decoder; use crate::util; pub struct AACDecoder { - stdin: ChildStdin, - stdout: ChildStdout, + cmd: Child, metadata: Arc, } -impl Decoder for AACDecoder { - fn write_nalu(&mut self, nalu: util::NALUPacket) -> Result<(), Box> { - self.stdin.write_all(nalu.packet_data.as_slice())?; +impl Decoder for Arc> { + fn write_nalu(&self, nalu: util::NALUPacket) -> Result<(), Box> { + let mut self_ptr = self.lock().unwrap(); + let mut pipe = match &self_ptr.cmd.stdin { + Some(x) => x, + None => {return Err(Box::new(util::DecoderError::BrokenInPipe))} + }; + pipe.write_all(nalu.packet_data.as_slice())?; Ok(()) } - fn read_raw(&mut self) -> Result> { + fn read_raw(&self) -> Result> { todo!(); } } pub fn new_aac(metadata: Arc) -> Result> { - 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}) + let f = File::create("raw.aac")?; + let cmd = Command::new("tee").stdin(Stdio::piped()).stdout(f).spawn()?; + return Ok(AACDecoder {cmd: cmd, metadata: metadata}) } diff --git a/src/decode/codecs/video.rs b/src/decode/codecs/video.rs index b26c929..7673deb 100644 --- a/src/decode/codecs/video.rs +++ b/src/decode/codecs/video.rs @@ -1,36 +1,34 @@ use std::error::Error; -use std::process::{ChildStdin, ChildStdout, Stdio, Command}; -use std::sync::Arc; +use std::process::{Child, Stdio, Command}; +use std::sync::{Arc, Mutex}; use std::io::{Read, Write}; +use std::fs::File; use crate::decode::codecs::Decoder; use crate::util; pub struct H264Decoder { - stdin: ChildStdin, - stdout: ChildStdout, + cmd: Child, metadata: Arc, } -impl Decoder for H264Decoder { - fn write_nalu(&mut self, nalu: util::NALUPacket) -> Result<(), Box> { - self.stdin.write_all(nalu.packet_data.as_slice())?; +impl Decoder for Arc> { + fn write_nalu(&self, nalu: util::NALUPacket) -> Result<(), Box> { + let mut self_ptr = self.lock().unwrap(); + let mut pipe = match &self_ptr.cmd.stdin { + Some(x) => x, + None => {return Err(Box::new(util::DecoderError::BrokenInPipe))} + }; + pipe.write_all(nalu.packet_data.as_slice())?; Ok(()) } - fn read_raw(&mut self) -> Result> { + fn read_raw(&self) -> Result> { todo!(); } } pub fn new_h264(metadata: Arc) -> Result> { - 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}); + let f = File::create("raw.h264")?; + let cmd = Command::new("tee").stdin(Stdio::piped()).stdout(f).spawn()?; + return Ok(H264Decoder {cmd: cmd, metadata: metadata}); }