boiler plate for encoder implementation
This commit is contained in:
parent
0b910df389
commit
89d9100c7e
5 changed files with 32 additions and 11 deletions
13
src/encode/cmds.rs
Normal file
13
src/encode/cmds.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
use std::error::Error;
|
||||
use std::sync::{Arc, mpsc};
|
||||
|
||||
use crate::util;
|
||||
use crate::encode::codecs::Encoder;
|
||||
|
||||
pub fn spawn(v_target: util::VideoCodec, a_target: util::AudioCodec) -> Result<(impl Encoder, impl Encoder), Box<dyn Error>> {
|
||||
todo!();
|
||||
}
|
||||
|
||||
pub fn handle_encoder(encoder: impl Encoder, c_in: mpsc::Receiver<util::RawMedia>, c_out: mpsc::Sender<util::NALUPacket>, metadata: Arc<util::Metadata>, c_err: mpsc::Sender<Box<dyn Error + Send + Sync>>) {
|
||||
todo!();
|
||||
}
|
2
src/encode/codecs/mod.rs
Normal file
2
src/encode/codecs/mod.rs
Normal file
|
@ -0,0 +1,2 @@
|
|||
pub trait Encoder {
|
||||
}
|
|
@ -1,3 +1,6 @@
|
|||
mod cmds;
|
||||
mod codecs;
|
||||
|
||||
use std::sync::{mpsc, Arc};
|
||||
use std::error::Error;
|
||||
use std::thread;
|
||||
|
@ -7,7 +10,9 @@ use crate::util;
|
|||
pub fn spawn(
|
||||
v: mpsc::Receiver<util::RawMedia>,
|
||||
a: mpsc::Receiver<util::RawMedia>,
|
||||
metadata: Arc<util::Metadata>
|
||||
metadata: Arc<util::Metadata>,
|
||||
v_target: util::VideoCodec,
|
||||
a_target: util::AudioCodec
|
||||
) -> Result<
|
||||
(
|
||||
mpsc::Receiver<util::NALUPacket>,
|
||||
|
@ -18,16 +23,15 @@ pub fn spawn(
|
|||
> {
|
||||
let (v_in, v_out) = mpsc::channel();
|
||||
let (a_in, a_out) = mpsc::channel();
|
||||
let (err_in, err_out) = mpsc::channel();
|
||||
let metadata_handle = metadata.clone();
|
||||
let (err_in_v, err_out) = mpsc::channel();
|
||||
let err_in_a = err_in_v.clone();
|
||||
let (v_encoder, a_encoder) = cmds::spawn(v_target, a_target)?;
|
||||
let metadata_cp = metadata.clone();
|
||||
thread::spawn(move || {
|
||||
&v;
|
||||
&a;
|
||||
&v_in;
|
||||
&a_in;
|
||||
&err_in;
|
||||
&metadata_handle;
|
||||
thread::park();
|
||||
cmds::handle_encoder(v_encoder, v, v_in, metadata_cp, err_in_v);
|
||||
});
|
||||
thread::spawn(move || {
|
||||
cmds::handle_encoder(a_encoder, a, a_in, metadata, err_in_a);
|
||||
});
|
||||
return Ok((v_out, a_out, err_out));
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ use std::time::Duration;
|
|||
fn init() -> Result<[mpsc::Receiver<Box<dyn std::error::Error + Send + Sync>>; 4], Box<dyn std::error::Error>>{
|
||||
let (v_out, a_out, metadata, demux_err_recv) = demux::spawn()?;
|
||||
let (raw_v_out, raw_a_out, decode_err_recv) = decode::spawn(v_out, a_out, metadata.clone())?;
|
||||
let (enc_v_out, enc_a_out, encode_err_recv) = encode::spawn(raw_v_out, raw_a_out, metadata.clone())?;
|
||||
let (enc_v_out, enc_a_out, encode_err_recv) = encode::spawn(raw_v_out, raw_a_out, metadata.clone(), util::VideoCodec::VP9, util::AudioCodec::OPUS)?;
|
||||
let muxer_err_recv = muxer::spawn(enc_v_out, enc_a_out, metadata.clone())?;
|
||||
return Ok([demux_err_recv, decode_err_recv, encode_err_recv, muxer_err_recv]);
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ pub struct VideoMetadata {
|
|||
|
||||
pub enum VideoCodec {
|
||||
H264,
|
||||
VP9,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -26,6 +27,7 @@ pub struct AudioMetadata {
|
|||
|
||||
pub enum AudioCodec {
|
||||
AAC,
|
||||
OPUS,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
|
Loading…
Reference in a new issue