make encoder output handle nalu read on codec basis for delimiting

This commit is contained in:
Muaz Ahmad 2023-10-16 12:37:10 +05:00
parent 71a3ef569a
commit d33742b96f
3 changed files with 22 additions and 9 deletions

View file

@ -1,5 +1,5 @@
use std::error::Error; 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::sync::Arc;
use std::fs::File; use std::fs::File;
@ -15,8 +15,8 @@ impl Encoder for OpusEncoder {
self.cmd.stdin.take().unwrap() self.cmd.stdin.take().unwrap()
} }
fn stdout(&mut self) -> ChildStdout { fn read_nalu(&mut self) -> Result<util::NALUPacket, Box<dyn Error + Send + Sync>> {
self.cmd.stdout.take().unwrap() todo!();
} }
} }

View file

@ -4,14 +4,27 @@ pub mod audio;
use std::error::Error; use std::error::Error;
use std::process::{ChildStdin, ChildStdout}; use std::process::{ChildStdin, ChildStdout};
use std::sync::mpsc; use std::sync::mpsc;
use std::io::{Read, Write}; use std::io::Write;
use std::thread; use std::thread;
use crate::util; use crate::util;
pub trait Encoder { pub trait Encoder {
fn stdin(&mut self) -> ChildStdin; fn stdin(&mut self) -> ChildStdin;
fn stdout(&mut self) -> ChildStdout; fn read_nalu(&mut self) -> Result<util::NALUPacket, Box<dyn Error + Send + Sync>>;
fn write_nalu_loop(&mut self, c_out: mpsc::Sender<util::NALUPacket>, c_err: mpsc::Sender<Box<dyn Error + Send + Sync>>) {
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<dyn Error + Send + Sync>> { fn write_raw(cmd_in: &mut ChildStdin, media: util::RawMedia) -> Result<(), Box<dyn Error + Send + Sync>> {
@ -19,7 +32,7 @@ fn write_raw(cmd_in: &mut ChildStdin, media: util::RawMedia) -> Result<(), Box<d
Ok(()) Ok(())
} }
fn read_raw(cmd_out: &mut ChildStdout) -> Result<util::NALUPacket, Box<dyn Error>> { fn read_nalu(cmd_out: &mut ChildStdout) -> Result<util::NALUPacket, Box<dyn Error>> {
todo!(); todo!();
} }

View file

@ -1,5 +1,5 @@
use std::error::Error; 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::sync::Arc;
use std::fs::File; use std::fs::File;
@ -15,8 +15,8 @@ impl Encoder for VP9Encoder {
self.cmd.stdin.take().unwrap() self.cmd.stdin.take().unwrap()
} }
fn stdout(&mut self) -> ChildStdout { fn read_nalu(&mut self) -> Result<util::NALUPacket, Box<dyn Error + Send + Sync>> {
self.cmd.stdout.take().unwrap() todo!();
} }
} }