use bytes::Bytes;
use crate::VideoError;
use super::nal_type;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct H265Config {
pub vps: Bytes,
pub sps: Bytes,
pub pps: Bytes,
}
impl H265Config {
pub fn new(
vps: impl AsRef<[u8]>,
sps: impl AsRef<[u8]>,
pps: impl AsRef<[u8]>,
) -> Result<Self, VideoError> {
let vps = Bytes::copy_from_slice(vps.as_ref());
let sps = Bytes::copy_from_slice(sps.as_ref());
let pps = Bytes::copy_from_slice(pps.as_ref());
if nal_type(&vps) != Some(32) {
return Err(VideoError::InvalidAnnexB(
"H.265 VPS has the wrong NAL type",
));
}
if nal_type(&sps) != Some(33) {
return Err(VideoError::InvalidAnnexB(
"H.265 SPS has the wrong NAL type",
));
}
if nal_type(&pps) != Some(34) {
return Err(VideoError::InvalidAnnexB(
"H.265 PPS has the wrong NAL type",
));
}
Ok(Self { vps, sps, pps })
}
}