Skip to content

Commit

Permalink
src: lib: video: move VideoEncodeType's from_str to FromStr trait
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoantoniocardoso authored and patrickelectric committed Nov 4, 2024
1 parent 2ef9793 commit 85c61a3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/lib/video/local/video_source_local_linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ impl VideoSource for VideoSourceLocal {
match v4l_format.fourcc.str() {
Ok(encode_str) => {
formats.push(Format {
encode: VideoEncodeType::from_str(encode_str),
encode: encode_str.parse().unwrap(),
sizes,
});
}
Expand Down
13 changes: 8 additions & 5 deletions src/lib/video/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,20 @@ impl VideoSourceType {
}
}

impl VideoEncodeType {
//TODO: use trait fromstr, check others places
pub fn from_str(fourcc: &str) -> VideoEncodeType {
impl std::str::FromStr for VideoEncodeType {
type Err = std::convert::Infallible;

fn from_str(fourcc: &str) -> Result<Self, Self::Err> {
let fourcc = fourcc.to_uppercase();
match fourcc.as_str() {
let res = match fourcc.as_str() {
"H264" => VideoEncodeType::H264,
"H265" | "HEVC" => VideoEncodeType::H265,
"MJPG" => VideoEncodeType::Mjpg,
"YUYV" => VideoEncodeType::Yuyv,
_ => VideoEncodeType::Unknown(fourcc),
}
};

Ok(res)
}
}

Expand Down

0 comments on commit 85c61a3

Please sign in to comment.