-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from gomadoufu/feat-#69
- Loading branch information
Showing
9 changed files
with
246 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
use crate::parser::{ | ||
destruct::Elements, | ||
parse::{InputType, OutputFormat}, | ||
}; | ||
|
||
use std::{collections::HashMap, vec}; | ||
|
||
#[derive(Debug)] | ||
pub struct Builder { | ||
arguments: Elements, | ||
arg_map: HashMap<String, String>, | ||
} | ||
|
||
impl Builder { | ||
pub fn new(arguments: Elements) -> Builder { | ||
let arg_map = map_args() | ||
.iter() | ||
.map(|(k, v)| (k.to_string(), v.to_string())) | ||
.collect(); | ||
Builder { arguments, arg_map } | ||
} | ||
pub fn build(&self) -> Vec<String> { | ||
let mut result = vec![]; | ||
result.push(self.match_input_type()); | ||
result.push("!".to_string()); | ||
// カメラから、指定された解像度の映像を取得しておく。後で変換しない。 | ||
result.push(format!( | ||
"{},{},{}", | ||
self.arguments.iformat, | ||
format_args!("width={}", self.arguments.iwidth), | ||
format_args!("height={}", self.arguments.iheight), | ||
)); | ||
result.push("!".to_string()); | ||
result.push("videoconvert".to_string()); | ||
result.push("!".to_string()); | ||
result.push(self.match_oformat()); | ||
result.push("!".to_string()); | ||
result.push(self.match_rtp()); | ||
result.push("!".to_string()); | ||
result.push("udpsink".to_string()); | ||
result.push(format!("host={}", self.arguments.ohost)); | ||
result.push(format!("port={}", self.arguments.oport)); | ||
|
||
result | ||
} | ||
|
||
fn match_input_type(&self) -> String { | ||
match self.arguments.itype { | ||
InputType::Test => self.arg_map.get("test").unwrap().to_string(), | ||
InputType::Mipi => self.arg_map.get("mipi").unwrap().to_string(), | ||
InputType::Usb => self.arg_map.get("usb").unwrap().to_string(), | ||
} | ||
} | ||
|
||
fn match_oformat(&self) -> String { | ||
match &self.arguments.oformat { | ||
OutputFormat::H264 if self.arguments.hardware => { | ||
self.arg_map.get("h264hard").unwrap().to_string() | ||
} | ||
OutputFormat::H264 => self.arg_map.get("h264soft").unwrap().to_string(), | ||
OutputFormat::Vp8 if self.arguments.hardware => { | ||
self.arg_map.get("vp8hard").unwrap().to_string() | ||
} | ||
OutputFormat::Vp8 => self.arg_map.get("vp8soft").unwrap().to_string(), | ||
} | ||
} | ||
|
||
fn match_rtp(&self) -> String { | ||
match self.arguments.oformat { | ||
OutputFormat::H264 => self.arg_map.get("h264rtp").unwrap().to_string(), | ||
OutputFormat::Vp8 => self.arg_map.get("vp8rtp").unwrap().to_string(), | ||
} | ||
} | ||
} | ||
|
||
fn map_args() -> Vec<(&'static str, &'static str)> { | ||
let result = vec![ | ||
("test", "videotestsrc"), | ||
("mipi", "libcamerasrc"), | ||
("usb", "-v v4l2src"), | ||
("h264soft", "x264enc"), | ||
("h264hard", "v4l2h264enc ! 'video/x-h264,level=(string)4'"), | ||
("vp8soft", "vp8enc"), | ||
("vp8hard", "omxvp8enc"), | ||
("vp8rtp", "rtpvp8pay"), | ||
("h264rtp", "rtph264pay"), | ||
]; | ||
result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod build; | ||
pub mod exec; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use super::parse::{Cli, Command, InputFormat, InputType, OutputCommands, OutputFormat}; | ||
|
||
#[derive(Debug)] | ||
pub struct Elements { | ||
pub itype: InputType, | ||
pub iformat: InputFormat, | ||
pub iwidth: i32, | ||
pub iheight: i32, | ||
pub oformat: OutputFormat, | ||
pub ohost: String, | ||
pub oport: i32, | ||
pub hardware: bool, | ||
pub dry_run: bool, | ||
pub show: bool, | ||
} | ||
|
||
impl Elements { | ||
pub fn destruct(cli: Cli) -> Elements { | ||
match cli.input { | ||
Command::Show => Elements { | ||
itype: InputType::Test, | ||
iformat: InputFormat::Yuy2, | ||
iwidth: 0, | ||
iheight: 0, | ||
oformat: OutputFormat::H264, | ||
ohost: "".to_string(), | ||
oport: 0, | ||
hardware: false, | ||
dry_run: false, | ||
show: true, | ||
}, | ||
Command::Input(input) => { | ||
let itype = input.input_type; | ||
let iformat = input.format; | ||
match input.output { | ||
OutputCommands::Output(output) => { | ||
let iwidth = output.width; | ||
let iheight = output.height; | ||
let oformat = output.format; | ||
let ohost = output.host; | ||
let oport = output.port; | ||
let hardware = output.hardware_encode; | ||
let dry_run = output.dry_run; | ||
let show = false; | ||
Elements { | ||
itype, | ||
iformat, | ||
iwidth, | ||
iheight, | ||
oformat, | ||
ohost, | ||
oport, | ||
hardware, | ||
dry_run, | ||
show, | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
pub mod convert; | ||
pub mod destruct; | ||
pub mod parse; |
Oops, something went wrong.