use super::PocState;
use crate::windows::d3d12_video_decode::hevc_vps_sps_pps::Sps;
fn test_sps(log2_max_pic_order_cnt_lsb: u32) -> Sps {
Sps {
pic_width_in_luma_samples: 352,
pic_height_in_luma_samples: 288,
log2_max_pic_order_cnt_lsb,
max_dec_pic_buffering: 4,
log2_min_cb_size: 6,
log2_diff_max_min_cb_size: 2,
log2_min_tb_size: 2,
log2_diff_max_min_tb_size: 3,
max_transform_hierarchy_depth_inter: 2,
max_transform_hierarchy_depth_intra: 1,
amp_enabled_flag: true,
sample_adaptive_offset_enabled_flag: false,
sps_temporal_mvp_enabled_flag: false,
strong_intra_smoothing_enabled_flag: true,
}
}
#[test]
fn idr_resets_poc_to_zero_and_updates_state_when_reference() {
let sps = test_sps(8);
let state = PocState::default();
let (poc, next) = state.compute(&sps, None, true, true);
assert_eq!(poc, 0);
let (poc2, _) = next.compute(&sps, Some(0), false, true);
assert_eq!(poc2, 0);
}
#[test]
fn idr_as_non_reference_does_not_update_state() {
let sps = test_sps(8);
let mut state = PocState::default();
let (_, seeded) = state.compute(&sps, None, true, true);
let (_, seeded) = seeded.compute(&sps, Some(4), false, true);
state = seeded;
let (poc, unchanged) = state.compute(&sps, None, true, false);
assert_eq!(poc, 0); assert_eq!(unchanged, state); }
#[test]
fn non_idr_poc_matches_lsb_directly_with_no_wrap() {
let sps = test_sps(8); let state = PocState::default(); let (poc, _) = state.compute(&sps, Some(5), false, true);
assert_eq!(poc, 5);
}
#[test]
fn poc_msb_wraps_forward_when_lsb_decreases_past_half_range() {
let sps = test_sps(8); let state = PocState::default();
let (_, state) = state.compute(&sps, Some(100), false, true);
let (_, state) = state.compute(&sps, Some(200), false, true);
let (poc, _) = state.compute(&sps, Some(10), false, true);
assert_eq!(poc, 256 + 10);
}
#[test]
fn poc_msb_wraps_backward_when_lsb_increases_past_half_range() {
let sps = test_sps(8); let state = PocState::default();
let (_, state) = state.compute(&sps, Some(10), false, true);
let (poc, _) = state.compute(&sps, Some(250), false, true);
assert_eq!(poc, -256 + 250);
}
#[test]
fn non_reference_picture_does_not_update_persisted_state() {
let sps = test_sps(8);
let state = PocState::default();
let (_, after_ref) = state.compute(&sps, Some(5), false, true);
let (poc_non_ref, unchanged) = after_ref.compute(&sps, Some(50), false, false);
assert_eq!(poc_non_ref, 50);
assert_eq!(unchanged, after_ref);
let (poc_next, _) = unchanged.compute(&sps, Some(6), false, true);
assert_eq!(poc_next, 6);
}