#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum VideoCodecType {
Vp8,
Vp9,
}
impl VideoCodecType {
fn all() -> &'static [Self] {
&[Self::Vp8, Self::Vp9]
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CodecInfo {
pub codec: VideoCodecType,
pub decoding: DecodingInfo,
pub encoding: EncodingInfo,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DecodingInfo {
pub supported: bool,
pub hardware_accelerated: bool,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EncodingInfo {
pub supported: bool,
pub hardware_accelerated: bool,
pub profiles: EncodingProfiles,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum EncodingProfiles {
Vp9(Vec<Vp9EncodingProfile>),
Unsupported,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Vp9EncodingProfile {
Profile0,
Profile2,
}
pub fn supported_codecs() -> Vec<CodecInfo> {
VideoCodecType::all()
.iter()
.map(|&codec| CodecInfo {
codec,
decoding: decoding_info(codec),
encoding: encoding_info(codec),
})
.collect()
}
fn decoding_info(_codec: VideoCodecType) -> DecodingInfo {
DecodingInfo {
supported: true,
hardware_accelerated: false,
}
}
fn encoding_info(codec: VideoCodecType) -> EncodingInfo {
let profiles = match codec {
VideoCodecType::Vp8 => EncodingProfiles::Unsupported,
VideoCodecType::Vp9 => EncodingProfiles::Vp9(vec![
Vp9EncodingProfile::Profile0,
Vp9EncodingProfile::Profile2,
]),
};
EncodingInfo {
supported: true,
hardware_accelerated: false,
profiles,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn supported_codecs_returns_two_codecs() {
let codecs = supported_codecs();
assert_eq!(codecs.len(), 2);
assert_eq!(codecs[0].codec, VideoCodecType::Vp8);
assert_eq!(codecs[1].codec, VideoCodecType::Vp9);
}
#[test]
fn vp8_codec_info() {
let codecs = supported_codecs();
let vp8 = &codecs[0];
assert_eq!(
*vp8,
CodecInfo {
codec: VideoCodecType::Vp8,
decoding: DecodingInfo {
supported: true,
hardware_accelerated: false,
},
encoding: EncodingInfo {
supported: true,
hardware_accelerated: false,
profiles: EncodingProfiles::Unsupported,
},
}
);
}
#[test]
fn vp9_codec_info() {
let codecs = supported_codecs();
let vp9 = &codecs[1];
assert_eq!(
*vp9,
CodecInfo {
codec: VideoCodecType::Vp9,
decoding: DecodingInfo {
supported: true,
hardware_accelerated: false,
},
encoding: EncodingInfo {
supported: true,
hardware_accelerated: false,
profiles: EncodingProfiles::Vp9(vec![
Vp9EncodingProfile::Profile0,
Vp9EncodingProfile::Profile2,
]),
},
}
);
}
}