Reference index spans its whole 8x8, and numbering precedes marking
Browse files at this commit4b8dc73f66806447d54a88486e85b387874be130Parent: 276058c- fix
- reference index spans its whole 8x8, and numbering precedes marking
2 changed files +41 -4
- crates/ec-h264/src/decoder.rs +31 -4
- crates/ec-h264/src/dpb.rs +10 -0
crates/ec-h264/src/decoder.rsmodified+31 -4
| @@ -512,6 +512,17 @@ impl Decoder { | |||
| 512 | sh.num_ref_idx_l1_active, sh.header_bits, &rbsp[..rbsp.len().min(6)] | 512 | sh.num_ref_idx_l1_active, sh.header_bits, &rbsp[..rbsp.len().min(6)] |
| 513 | ); | 513 | ); |
| 514 | } | 514 | } |
| 515 | + if trace_enabled() && !sh.slice_type.is_intra() { | ||
| 516 | + for x in 0..2 { | ||
| 517 | + let l: Vec<(u32, i32)> = (0..lists[x].len()) | ||
| 518 | + .filter_map(|i| lists[x].get(i)) | ||
| 519 | + .map(|k| (self.dpb.frames[k].frame_num, self.dpb.frames[k].poc)) | ||
| 520 | + .collect(); | ||
| 521 | + if !l.is_empty() { | ||
| 522 | + eprintln!(" RefPicList{x} (frame_num, poc): {l:?}"); | ||
| 523 | + } | ||
| 524 | + } | ||
| 525 | + } | ||
| 515 | let intra_slice = sh.slice_type.is_intra(); | 526 | let intra_slice = sh.slice_type.is_intra(); |
| 516 | let b_slice = sh.slice_type == SliceType::B; | 527 | let b_slice = sh.slice_type == SliceType::B; |
| 517 | if !intra_slice && ctx.lists[0].len() == 0 { | 528 | if !intra_slice && ctx.lists[0].len() == 0 { |
| @@ -1475,12 +1486,19 @@ fn decode_inter_mb( | |||
| 1475 | let by = (mb_y * 4 + py) as i32; | 1486 | let by = (mb_y * 4 + py) as i32; |
| 1476 | let inc = ref_idx_cond(pic, &mvc, bx - 1, by, list) | 1487 | let inc = ref_idx_cond(pic, &mvc, bx - 1, by, list) |
| 1477 | + 2 * ref_idx_cond(pic, &mvc, bx, by - 1, list); | 1488 | + 2 * ref_idx_cond(pic, &mvc, bx, by - 1, list); |
| 1478 | - r.ref_idx(ctx.num_ref_idx[list] as u32 - 1, inc)? as i8 | 1489 | + let v = r.ref_idx(ctx.num_ref_idx[list] as u32 - 1, inc)? as i8; |
| 1490 | + if trace_enabled() { | ||
| 1491 | + eprintln!(" ref_idx part {part} list {list} inc {inc} = {v}"); | ||
| 1492 | + } | ||
| 1493 | + v | ||
| 1479 | }; | 1494 | }; |
| 1480 | motion.ref_idx[list][part] = idx; | 1495 | motion.ref_idx[list][part] = idx; |
| 1481 | - // Publish it so the next partition's context can see it. | 1496 | + // Publish it over the whole macroblock partition — one |
| 1497 | + // reference index covers an entire 8x8, however it is further | ||
| 1498 | + // split — so the next partition's context (9.3.3.1.1.6) and | ||
| 1499 | + // the mvd contexts of 9.3.3.1.1.7 see it everywhere. | ||
| 1482 | let (px, py) = part_origin(&shape, part, (0, 0)); | 1500 | let (px, py) = part_origin(&shape, part, (0, 0)); |
| 1483 | - let (pw, ph) = part_size(&shape, &motion, part); | 1501 | + let (pw, ph) = mb_part_size(&shape); |
| 1484 | for dy in 0..ph { | 1502 | for dy in 0..ph { |
| 1485 | for dx in 0..pw { | 1503 | for dx in 0..pw { |
| 1486 | let bi = (mb_y * 4 + py + dy) * pic.mb_w * 4 + mb_x * 4 + px + dx; | 1504 | let bi = (mb_y * 4 + py + dy) * pic.mb_w * 4 + mb_x * 4 + px + dx; |
| @@ -1528,7 +1546,10 @@ fn decode_inter_mb( | |||
| 1528 | }; | 1546 | }; |
| 1529 | let v = r.mvd(comp, inc)?; | 1547 | let v = r.mvd(comp, inc)?; |
| 1530 | if trace_enabled() { | 1548 | if trace_enabled() { |
| 1531 | - eprintln!(" mvd part {part} sp {sp} list {list} comp {comp} inc {inc} = {v}"); | 1549 | + eprintln!( |
| 1550 | + " mvd part {part} sp {sp} at ({px},{py}) list {list} comp {comp} \ | ||
| 1551 | + absA {a} absB {bb} inc {inc} = {v}" | ||
| 1552 | + ); | ||
| 1532 | } | 1553 | } |
| 1533 | mvd[comp] = i16::try_from(v) | 1554 | mvd[comp] = i16::try_from(v) |
| 1534 | .map_err(|_| Error::corrupt("mvd outside the level limits"))?; | 1555 | .map_err(|_| Error::corrupt("mvd outside the level limits"))?; |
| @@ -1694,6 +1715,12 @@ fn sp_offset(shape: &MbShape, m: &MbMotion, part: usize, sp: usize) -> (usize, u | |||
| 1694 | } | 1715 | } |
| 1695 | } | 1716 | } |
| 1696 | 1717 | ||
| 1718 | +/// Size of one *macroblock* partition in 4x4 blocks: always 8x8 for a | ||
| 1719 | +/// macroblock that carries sub-macroblock types, however those split it. | ||
| 1720 | +fn mb_part_size(shape: &MbShape) -> (usize, usize) { | ||
| 1721 | + if shape.sub { (2, 2) } else { (shape.w, shape.h) } | ||
| 1722 | +} | ||
| 1723 | + | ||
| 1697 | /// Size of one (sub-)macroblock partition in 4x4 blocks. | 1724 | /// Size of one (sub-)macroblock partition in 4x4 blocks. |
| 1698 | fn part_size(shape: &MbShape, m: &MbMotion, part: usize) -> (usize, usize) { | 1725 | fn part_size(shape: &MbShape, m: &MbMotion, part: usize) -> (usize, usize) { |
| 1699 | if shape.sub { | 1726 | if shape.sub { |
crates/ec-h264/src/dpb.rsmodified+10 -0
| @@ -227,6 +227,8 @@ impl Picture { | |||
| 227 | self.output = false; | 227 | self.output = false; |
| 228 | self.non_existing = false; | 228 | self.non_existing = false; |
| 229 | self.long_term_frame_idx = 0; | 229 | self.long_term_frame_idx = 0; |
| 230 | + self.frame_num_wrap = 0; | ||
| 231 | + self.pic_num = 0; | ||
| 230 | } | 232 | } |
| 231 | 233 | ||
| 232 | /// Replicate every plane's borders once the picture is fully reconstructed. | 234 | /// Replicate every plane's borders once the picture is fully reconstructed. |
| @@ -812,6 +814,14 @@ impl Dpb { | |||
| 812 | let has_mmco5 = marking.is_some_and(|m| m.mmcos.iter().any(|c| c.op == 5)); | 814 | let has_mmco5 = marking.is_some_and(|m| m.mmcos.iter().any(|c| c.op == 5)); |
| 813 | pic.output = true; | 815 | pic.output = true; |
| 814 | pic.complete = true; | 816 | pic.complete = true; |
| 817 | + // Clause 8.2.4.1 against this picture's frame_num, which is what both | ||
| 818 | + // the sliding window (8.2.5.3) and the MMCO picture numbers (8.2.5.4) | ||
| 819 | + // compare. An intra slice never built a reference list, so this is the | ||
| 820 | + // only place the numbering is guaranteed to be current — and the | ||
| 821 | + // picture being stored has no FrameNumWrap of its own until now. | ||
| 822 | + self.number_short_term(info.frame_num, sps); | ||
| 823 | + pic.frame_num_wrap = pic.frame_num as i32; | ||
| 824 | + pic.pic_num = pic.frame_num as i32; | ||
| 815 | 825 | ||
| 816 | if info.is_idr { | 826 | if info.is_idr { |
| 817 | let no_output = marking.is_some_and(|m| m.no_output_of_prior_pics); | 827 | let no_output = marking.is_some_and(|m| m.no_output_of_prior_pics); |