diff --git a/src/encode/codecs/audio.rs b/src/encode/codecs/audio.rs index 5b6123c..eb0e1b2 100644 --- a/src/encode/codecs/audio.rs +++ b/src/encode/codecs/audio.rs @@ -1,5 +1,5 @@ use std::error::Error; -use std::process::{Child, Command, Stdio, ChildStdin, ChildStdout}; +use std::process::{Child, Command, Stdio, ChildStdin}; use std::sync::Arc; use std::fs::File; @@ -15,8 +15,8 @@ impl Encoder for OpusEncoder { self.cmd.stdin.take().unwrap() } - fn stdout(&mut self) -> ChildStdout { - self.cmd.stdout.take().unwrap() + fn read_nalu(&mut self) -> Result> { + todo!(); } } diff --git a/src/encode/codecs/mod.rs b/src/encode/codecs/mod.rs index cd17ee1..21feb39 100644 --- a/src/encode/codecs/mod.rs +++ b/src/encode/codecs/mod.rs @@ -4,14 +4,27 @@ pub mod audio; use std::error::Error; use std::process::{ChildStdin, ChildStdout}; use std::sync::mpsc; -use std::io::{Read, Write}; +use std::io::Write; use std::thread; use crate::util; pub trait Encoder { fn stdin(&mut self) -> ChildStdin; - fn stdout(&mut self) -> ChildStdout; + fn read_nalu(&mut self) -> Result>; + + fn write_nalu_loop(&mut self, c_out: mpsc::Sender, c_err: mpsc::Sender>) { + loop { + let nalu = match self.read_nalu() { + Ok(x) => x, + Err(err) => {util::thread_freeze(c_err, err); return} + }; + match c_out.send(nalu) { + Ok(_) => (), + Err(err) => {util::thread_freeze(c_err, Box::new(err)); return} + } + } + } } fn write_raw(cmd_in: &mut ChildStdin, media: util::RawMedia) -> Result<(), Box> { @@ -19,7 +32,7 @@ fn write_raw(cmd_in: &mut ChildStdin, media: util::RawMedia) -> Result<(), Box Result> { +fn read_nalu(cmd_out: &mut ChildStdout) -> Result> { todo!(); } diff --git a/src/encode/codecs/video.rs b/src/encode/codecs/video.rs index 0b38ee0..d094086 100644 --- a/src/encode/codecs/video.rs +++ b/src/encode/codecs/video.rs @@ -1,5 +1,5 @@ use std::error::Error; -use std::process::{Child, Command, Stdio, ChildStdin, ChildStdout}; +use std::process::{Child, Command, Stdio, ChildStdin}; use std::sync::Arc; use std::fs::File; @@ -15,8 +15,8 @@ impl Encoder for VP9Encoder { self.cmd.stdin.take().unwrap() } - fn stdout(&mut self) -> ChildStdout { - self.cmd.stdout.take().unwrap() + fn read_nalu(&mut self) -> Result> { + todo!(); } }