diff --git a/src/lib/video/local/video_source_local_linux.rs b/src/lib/video/local/video_source_local_linux.rs index c8fbc52f..e96863e3 100644 --- a/src/lib/video/local/video_source_local_linux.rs +++ b/src/lib/video/local/video_source_local_linux.rs @@ -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, }); } diff --git a/src/lib/video/types.rs b/src/lib/video/types.rs index ad969f9d..eec06957 100644 --- a/src/lib/video/types.rs +++ b/src/lib/video/types.rs @@ -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 { 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) } }