From 89d9100c7ea50cab89c72d55a589a274dd4b4613 Mon Sep 17 00:00:00 2001 From: Muaz Ahmad Date: Thu, 12 Oct 2023 13:57:11 +0500 Subject: [PATCH] boiler plate for encoder implementation --- src/encode/cmds.rs | 13 +++++++++++++ src/encode/codecs/mod.rs | 2 ++ src/encode/mod.rs | 24 ++++++++++++++---------- src/main.rs | 2 +- src/util/mod.rs | 2 ++ 5 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 src/encode/cmds.rs create mode 100644 src/encode/codecs/mod.rs diff --git a/src/encode/cmds.rs b/src/encode/cmds.rs new file mode 100644 index 0000000..452b43f --- /dev/null +++ b/src/encode/cmds.rs @@ -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> { + todo!(); +} + +pub fn handle_encoder(encoder: impl Encoder, c_in: mpsc::Receiver, c_out: mpsc::Sender, metadata: Arc, c_err: mpsc::Sender>) { + todo!(); +} diff --git a/src/encode/codecs/mod.rs b/src/encode/codecs/mod.rs new file mode 100644 index 0000000..b9e0233 --- /dev/null +++ b/src/encode/codecs/mod.rs @@ -0,0 +1,2 @@ +pub trait Encoder { +} diff --git a/src/encode/mod.rs b/src/encode/mod.rs index 8553ec6..60c8435 100644 --- a/src/encode/mod.rs +++ b/src/encode/mod.rs @@ -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, a: mpsc::Receiver, - metadata: Arc + metadata: Arc, + v_target: util::VideoCodec, + a_target: util::AudioCodec ) -> Result< ( mpsc::Receiver, @@ -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)); } diff --git a/src/main.rs b/src/main.rs index ea0f692..fca4d83 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,7 @@ use std::time::Duration; fn init() -> Result<[mpsc::Receiver>; 4], Box>{ 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]); } diff --git a/src/util/mod.rs b/src/util/mod.rs index a6ae57d..03d0711 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -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)]