use media_codec_h265::{
nal::NalUnitType,
pps::Pps,
ps::ParameterSets,
slice::{SliceSegmentHeader, SliceType},
sps::Sps,
vps::Vps,
};
#[rustfmt::skip]
const VPS_DATA: &[u8] = &[
0x0C, 0x01, 0xFF, 0xFF, 0x01, 0x60, 0x00, 0x00, 0x00, 0xB0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5D, 0x95, 0xC0, 0x80,
];
#[rustfmt::skip]
const SPS_DATA: &[u8] = &[
0x01, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00, 0x9E, 0x28, 0x00, 0x00, 0x00, 0x1E, 0x90, 0x04, 0x10, 0x20, 0xB2, 0xDD, 0x49, 0x26,
0x17, 0x80, 0xB7, 0x02, 0x02, 0x00, 0x04, 0x00,
0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x20,
];
#[rustfmt::skip]
const PPS_DATA: &[u8] = &[
0xC1, 0x72, 0x86, 0x0C, 0x02, 0x24,
];
#[rustfmt::skip]
const IDR_SLICE_HEADER: &[u8] = &[
0xAD, 0xE0, 0x1F, 0x04, 0x84, 0x7F, 0x82, 0xFD, 0xFC, 0xD3, 0xFF, 0xA9, 0x70, 0x92, 0xB3, 0x65, 0x59, 0x41, 0xDF, 0x15, 0x95, 0x79, 0xE5, 0x45, 0xEB, 0x1B, 0x68, 0x0D, 0xB3, 0xFA, ];
#[test]
fn test_parse_idr_slice_header() {
let vps = Vps::parse(VPS_DATA).unwrap();
let sps = Sps::parse_with_vps(SPS_DATA, &vps).unwrap();
let pps = Pps::parse_with_sps(PPS_DATA, &sps).unwrap();
let mut param_sets = ParameterSets::new();
param_sets.add_vps(vps);
param_sets.add_sps(sps).unwrap();
param_sets.add_pps(pps).unwrap();
let header = SliceSegmentHeader::parse(IDR_SLICE_HEADER, NalUnitType::IdrNLp, ¶m_sets).unwrap();
assert!(header.first_slice_segment_in_pic_flag);
assert_eq!(header.pic_parameter_set_id, 0);
assert_eq!(header.slice_type, SliceType::I);
}
#[test]
fn test_slice_type() {
assert_eq!(SliceType::from_u8(0), Some(SliceType::B));
assert_eq!(SliceType::from_u8(1), Some(SliceType::P));
assert_eq!(SliceType::from_u8(2), Some(SliceType::I));
assert_eq!(SliceType::from_u8(3), None);
assert!(SliceType::I.is_intra());
assert!(!SliceType::I.is_inter());
assert!(!SliceType::P.is_intra());
assert!(SliceType::P.is_inter());
assert!(SliceType::P.is_p());
assert!(!SliceType::P.is_b());
assert!(SliceType::B.is_b());
assert!(!SliceType::B.is_p());
}