U7: drop pixel-decode-off, syntax-check and motion-checksum modes (has_pixels guards, Checksum, set_pixel_decode, set_syntax_check, motion_checksum, parse_slice) and the dead pub helpers (y_u8, bit_depth_of, grey, fill_plane, dequantize_with, chroma_mv_420, ref_pic_* accessors, hdr/SEI wrappers). Test-only helpers moved to tests/it/common.rs; no output change
Browse files at this commit76bf5bffbce222c65850717e4e3963ddf3b6f734Parent: 1d28fe621 changed files +133 -468
- crates/ec-h265-syntax/src/sei.rs +12 -23
- crates/ec-h265/src/dec/cu_syntax.rs +6 -40
- crates/ec-h265/src/dec/cu_syntax/wpp.rs +23 -32
- crates/ec-h265/src/dec/deblock.rs +1 -4
- crates/ec-h265/src/dec/inter.rs +1 -4
- crates/ec-h265/src/dec/mod.rs +8 -80
- crates/ec-h265/src/dec/motion_field.rs +3 -54
- crates/ec-h265/src/dec/pic.rs +16 -52
- crates/ec-h265/src/dec/picjob.rs +9 -16
- crates/ec-h265/src/dec/recon.rs +0 -10
- crates/ec-h265/src/dec/rowfilter.rs +1 -6
- crates/ec-h265/src/dec/rps.rs +10 -22
- crates/ec-h265/src/dec/runner.rs +12 -49
- crates/ec-h265/src/dec/sao.rs +1 -4
- crates/ec-h265/src/dec/shared.rs +13 -28
- crates/ec-h265/src/decode.rs +1 -28
- crates/ec-h265/src/enc_p.rs +2 -2
- crates/ec-h265/src/encoder.rs +3 -3
- crates/ec-h265/src/transform.rs +0 -7
- crates/ec-h265/tests/it/common.rs +8 -3
- crates/ec-h265/tests/it/rext_generated.rs +3 -1
crates/ec-h265-syntax/src/sei.rsmodified+12 -23
| @@ -11,7 +11,6 @@ | |||
| 11 | //! RBSP, and refuses a malformed one rather than guessing. | 11 | //! RBSP, and refuses a malformed one rather than guessing. |
| 12 | 12 | ||
| 13 | use crate::md5::Md5; | 13 | use crate::md5::Md5; |
| 14 | -use crate::nal::{NalHeader, NalUnitType}; | ||
| 15 | use crate::ps::rbsp_trailing_bits; | 14 | use crate::ps::rbsp_trailing_bits; |
| 16 | use ec_core::bitio::BitWriter; | 15 | use ec_core::bitio::BitWriter; |
| 17 | use ec_core::color::ContentLight; | 16 | use ec_core::color::ContentLight; |
| @@ -48,19 +47,14 @@ fn sei_rbsp(messages: &[(u32, Vec<u8>)]) -> Vec<u8> { | |||
| 48 | } | 47 | } |
| 49 | 48 | ||
| 50 | /// The prefix SEI RBSP describing HDR mastering metadata, or `None` when there | 49 | /// The prefix SEI RBSP describing HDR mastering metadata, or `None` when there |
| 51 | -/// is nothing to say. | 50 | +/// is nothing to say. When `display` is given it is written verbatim (chromaticities |
| 51 | +/// and luminances), and the mastering pair inside `light` is ignored. The content light | ||
| 52 | +/// level comes from `light`. | ||
| 52 | /// | 53 | /// |
| 53 | /// Both messages are written whole or not at all: a `mastering_display_colour_volume` | 54 | /// Both messages are written whole or not at all: a `mastering_display_colour_volume` |
| 54 | /// with a zero luminance pair is what the oracle writes when it knows nothing, and a | 55 | /// with a zero luminance pair is what the oracle writes when it knows nothing, and a |
| 55 | /// tone map that believes it maps the film to black. | 56 | /// tone map that believes it maps the film to black. |
| 56 | -pub fn hdr_metadata_rbsp(light: ContentLight) -> Option<Vec<u8>> { | 57 | +pub fn hdr_metadata_rbsp( |
| 57 | - hdr_metadata_rbsp_with(None, light) | ||
| 58 | -} | ||
| 59 | - | ||
| 60 | -/// [`hdr_metadata_rbsp`] with an explicit mastering display: when `display` is | ||
| 61 | -/// given it is written verbatim (chromaticities and luminances), and the mastering | ||
| 62 | -/// pair inside `light` is ignored. The content light level comes from `light`. | ||
| 63 | -pub fn hdr_metadata_rbsp_with( | ||
| 64 | display: Option<MasteringDisplay>, | 58 | display: Option<MasteringDisplay>, |
| 65 | light: ContentLight, | 59 | light: ContentLight, |
| 66 | ) -> Option<Vec<u8>> { | 60 | ) -> Option<Vec<u8>> { |
| @@ -126,16 +120,6 @@ pub fn decoded_picture_hash_rbsp(planes: &[(&[u8], usize, usize, usize)]) -> Vec | |||
| 126 | sei_rbsp(&[(PAYLOAD_DECODED_PICTURE_HASH, payload)]) | 120 | sei_rbsp(&[(PAYLOAD_DECODED_PICTURE_HASH, payload)]) |
| 127 | } | 121 | } |
| 128 | 122 | ||
| 129 | -/// The NAL header a prefix SEI travels under. | ||
| 130 | -pub fn prefix_sei_header() -> NalHeader { | ||
| 131 | - NalHeader::new(NalUnitType::PrefixSei) | ||
| 132 | -} | ||
| 133 | - | ||
| 134 | -/// The NAL header a suffix SEI (the picture hash) travels under. | ||
| 135 | -pub fn suffix_sei_header() -> NalHeader { | ||
| 136 | - NalHeader::new(NalUnitType::SuffixSei) | ||
| 137 | -} | ||
| 138 | - | ||
| 139 | /// `payloadType` of the alternative transfer characteristics message (D.2.x). | 123 | /// `payloadType` of the alternative transfer characteristics message (D.2.x). |
| 140 | const PAYLOAD_ALTERNATIVE_TRANSFER: u32 = 147; | 124 | const PAYLOAD_ALTERNATIVE_TRANSFER: u32 = 147; |
| 141 | 125 | ||
| @@ -373,16 +357,21 @@ mod tests { | |||
| 373 | mastering_min: Some(0.005), | 357 | mastering_min: Some(0.005), |
| 374 | ..ContentLight::default() | 358 | ..ContentLight::default() |
| 375 | }; | 359 | }; |
| 376 | - let rbsp = hdr_metadata_rbsp(light).unwrap(); | 360 | + let rbsp = hdr_metadata_rbsp(None, light).unwrap(); |
| 377 | let mut annex_b = Vec::new(); | 361 | let mut annex_b = Vec::new(); |
| 378 | - crate::nal::write_annex_b(&mut annex_b, prefix_sei_header(), &rbsp, true); | 362 | + crate::nal::write_annex_b( |
| 363 | + &mut annex_b, | ||
| 364 | + crate::nal::NalHeader::new(crate::nal::NalUnitType::PrefixSei), | ||
| 365 | + &rbsp, | ||
| 366 | + true, | ||
| 367 | + ); | ||
| 379 | // ec-core's reader is the consumer this exists for. | 368 | // ec-core's reader is the consumer this exists for. |
| 380 | let read = ec_core::color::hevc_sei_light(&annex_b); | 369 | let read = ec_core::color::hevc_sei_light(&annex_b); |
| 381 | assert_eq!(read.max_cll, Some(1000.0)); | 370 | assert_eq!(read.max_cll, Some(1000.0)); |
| 382 | assert_eq!(read.max_fall, Some(400.0)); | 371 | assert_eq!(read.max_fall, Some(400.0)); |
| 383 | assert_eq!(read.mastering_max, Some(1000.0)); | 372 | assert_eq!(read.mastering_max, Some(1000.0)); |
| 384 | assert_eq!(read.mastering_min, Some(0.005)); | 373 | assert_eq!(read.mastering_min, Some(0.005)); |
| 385 | - assert!(hdr_metadata_rbsp(ContentLight::default()).is_none()); | 374 | + assert!(hdr_metadata_rbsp(None, ContentLight::default()).is_none()); |
| 386 | } | 375 | } |
| 387 | 376 | ||
| 388 | #[test] | 377 | #[test] |
crates/ec-h265/src/dec/cu_syntax.rsmodified+6 -40
| @@ -244,35 +244,6 @@ pub struct SliceStats { | |||
| 244 | pub trailing_bits_ok: bool, | 244 | pub trailing_bits_ok: bool, |
| 245 | } | 245 | } |
| 246 | 246 | ||
| 247 | -/// Parse one slice segment's data, from the byte after its header, to | ||
| 248 | -/// `end_of_slice_segment_flag`. `sink` sees every coding unit in decoding order. | ||
| 249 | -/// `motion` derives the motion of each prediction unit. | ||
| 250 | -/// | ||
| 251 | -/// A desync shows up as an `end_of_slice_segment_flag` at the wrong CTB, or as a | ||
| 252 | -/// trailing-bit pattern that is not the stop bit; both are errors. This form | ||
| 253 | -/// keeps only the syntax: no samples are produced. | ||
| 254 | -pub fn parse_slice( | ||
| 255 | - sps: &Sps, | ||
| 256 | - pps: &Pps, | ||
| 257 | - header: &SliceHeader, | ||
| 258 | - data: &[u8], | ||
| 259 | - motion: &mut dyn MotionSource, | ||
| 260 | - sink: &mut dyn FnMut(&CodingUnit), | ||
| 261 | -) -> Result<SliceStats> { | ||
| 262 | - let mut pic = PicState::for_sps_pps(sps, pps, false); | ||
| 263 | - parse_slice_into( | ||
| 264 | - sps, | ||
| 265 | - pps, | ||
| 266 | - header, | ||
| 267 | - data, | ||
| 268 | - motion, | ||
| 269 | - &mut pic, | ||
| 270 | - None, | ||
| 271 | - sink, | ||
| 272 | - &mut |_, _| {}, | ||
| 273 | - ) | ||
| 274 | -} | ||
| 275 | - | ||
| 276 | /// Parse one slice segment's data into `pic`. The block maps are always | 247 | /// Parse one slice segment's data into `pic`. The block maps are always |
| 277 | /// filled. When `pic` has sample planes (pixel decode), intra coding units are | 248 | /// filled. When `pic` has sample planes (pixel decode), intra coding units are |
| 278 | /// reconstructed in decoding order, and inter coding units are predicted from | 249 | /// reconstructed in decoding order, and inter coding units are predicted from |
| @@ -892,9 +863,6 @@ impl Parser<'_> { | |||
| 892 | /// Motion-compensated prediction of one prediction unit (8.5.3.3) into the | 863 | /// Motion-compensated prediction of one prediction unit (8.5.3.3) into the |
| 893 | /// picture's samples. Nothing happens without pixel decode. | 864 | /// picture's samples. Nothing happens without pixel decode. |
| 894 | fn predict_pu(&mut self, x: usize, y: usize, w: usize, h: usize, m: &Motion) -> Result<()> { | 865 | fn predict_pu(&mut self, x: usize, y: usize, w: usize, h: usize, m: &Motion) -> Result<()> { |
| 895 | - if !self.pic.has_pixels() { | ||
| 896 | - return Ok(()); | ||
| 897 | - } | ||
| 898 | let Some(refs) = self.refs else { | 866 | let Some(refs) = self.refs else { |
| 899 | return Err(Error::corrupt( | 867 | return Err(Error::corrupt( |
| 900 | "HEVC decode: an inter prediction unit in a slice with no reference lists", | 868 | "HEVC decode: an inter prediction unit in a slice with no reference lists", |
| @@ -1284,7 +1252,7 @@ impl Parser<'_> { | |||
| 1284 | { | 1252 | { |
| 1285 | self.cu_chroma_qp_offset(dec); | 1253 | self.cu_chroma_qp_offset(dec); |
| 1286 | } | 1254 | } |
| 1287 | - let recon = tx.intra && self.pic.has_pixels(); | 1255 | + let recon = tx.intra; |
| 1288 | let luma_mode = tx | 1256 | let luma_mode = tx |
| 1289 | .intra | 1257 | .intra |
| 1290 | .then(|| self.pic.info[self.pic.unit(x0, y0)].intra_mode); | 1258 | .then(|| self.pic.info[self.pic.unit(x0, y0)].intra_mode); |
| @@ -1680,13 +1648,11 @@ impl Parser<'_> { | |||
| 1680 | } else { | 1648 | } else { |
| 1681 | (x0 >> sx, y0 >> sy) | 1649 | (x0 >> sx, y0 >> sy) |
| 1682 | }; | 1650 | }; |
| 1683 | - if self.pic.has_pixels() { | 1651 | + let origin = self.pic.plane_origin(c); |
| 1684 | - let origin = self.pic.plane_origin(c); | 1652 | + let (stride, plane) = self.pic.plane_view_mut(c); |
| 1685 | - let (stride, plane) = self.pic.plane_view_mut(c); | 1653 | + for j in 0..sh { |
| 1686 | - for j in 0..sh { | 1654 | + let start = (y + j - origin) * stride + x; |
| 1687 | - let start = (y + j - origin) * stride + x; | 1655 | + plane[start..start + sw].copy_from_slice(&samples[j * sw..j * sw + sw]); |
| 1688 | - plane[start..start + sw].copy_from_slice(&samples[j * sw..j * sw + sw]); | ||
| 1689 | - } | ||
| 1690 | } | 1656 | } |
| 1691 | } | 1657 | } |
| 1692 | self.pic.update_info(x0, y0, n, n, |b| b.pcm = true); | 1658 | self.pic.update_info(x0, y0, n, n, |b| b.pcm = true); |
crates/ec-h265/src/dec/cu_syntax/wpp.rsmodified+23 -32
| @@ -104,13 +104,11 @@ impl Board { | |||
| 104 | let cw = self.width.div_ceil(1 << self.sub_x); | 104 | let cw = self.width.div_ceil(1 << self.sub_x); |
| 105 | let mut st = lock(&self.state); | 105 | let mut st = lock(&self.state); |
| 106 | let slot = &mut st.slots[ry]; | 106 | let slot = &mut st.slots[ry]; |
| 107 | - if pic.has_pixels() { | 107 | + let lr = (y0 + ctb - 1) - pic.origin_y; |
| 108 | - let lr = (y0 + ctb - 1) - pic.origin_y; | 108 | + slot.luma = pic.planes.y[lr * self.width..(lr + 1) * self.width].to_vec(); |
| 109 | - slot.luma = pic.planes.y[lr * self.width..(lr + 1) * self.width].to_vec(); | 109 | + let lc = ((y0 >> self.sub_y) + (ctb >> self.sub_y) - 1) - pic.origin_c; |
| 110 | - let lc = ((y0 >> self.sub_y) + (ctb >> self.sub_y) - 1) - pic.origin_c; | 110 | + slot.cb = pic.planes.cb[lc * cw..(lc + 1) * cw].to_vec(); |
| 111 | - slot.cb = pic.planes.cb[lc * cw..(lc + 1) * cw].to_vec(); | 111 | + slot.cr = pic.planes.cr[lc * cw..(lc + 1) * cw].to_vec(); |
| 112 | - slot.cr = pic.planes.cr[lc * cw..(lc + 1) * cw].to_vec(); | ||
| 113 | - } | ||
| 114 | let ur = (y0 + ctb - 4) / 4; | 112 | let ur = (y0 + ctb - 4) / 4; |
| 115 | let band_row = ur - pic.origin_unit / 4; | 113 | let band_row = ur - pic.origin_unit / 4; |
| 116 | slot.units = pic.info[band_row * self.w4..(band_row + 1) * self.w4].to_vec(); | 114 | slot.units = pic.info[band_row * self.w4..(band_row + 1) * self.w4].to_vec(); |
| @@ -157,11 +155,9 @@ impl Board { | |||
| 157 | (k * ctb) >> self.sub_x, | 155 | (k * ctb) >> self.sub_x, |
| 158 | (((k + 1) * ctb) >> self.sub_x).min(cw), | 156 | (((k + 1) * ctb) >> self.sub_x).min(cw), |
| 159 | ); | 157 | ); |
| 160 | - if pic.has_pixels() { | 158 | + pic.planes.y[a..b].copy_from_slice(&slot.luma[a..b]); |
| 161 | - pic.planes.y[a..b].copy_from_slice(&slot.luma[a..b]); | 159 | + pic.planes.cb[ca..cb_end].copy_from_slice(&slot.cb[ca..cb_end]); |
| 162 | - pic.planes.cb[ca..cb_end].copy_from_slice(&slot.cb[ca..cb_end]); | 160 | + pic.planes.cr[ca..cb_end].copy_from_slice(&slot.cr[ca..cb_end]); |
| 163 | - pic.planes.cr[ca..cb_end].copy_from_slice(&slot.cr[ca..cb_end]); | ||
| 164 | - } | ||
| 165 | let (ua, ub) = (k * ctb / 4, ((k + 1) * ctb / 4).min(self.w4)); | 161 | let (ua, ub) = (k * ctb / 4, ((k + 1) * ctb / 4).min(self.w4)); |
| 166 | pic.info[ua..ub].copy_from_slice(&slot.units[ua..ub]); | 162 | pic.info[ua..ub].copy_from_slice(&slot.units[ua..ub]); |
| 167 | pic.ctb[(ry - 1) * cols + k] = slot.ctb[k]; | 163 | pic.ctb[(ry - 1) * cols + k] = slot.ctb[k]; |
| @@ -216,14 +212,12 @@ impl Board { | |||
| 216 | } | 212 | } |
| 217 | if full { | 213 | if full { |
| 218 | // Band rows: the sample rows and unit row of the CTB row's last rows. | 214 | // Band rows: the sample rows and unit row of the CTB row's last rows. |
| 219 | - if pic.has_pixels() { | 215 | + let lr = (y0 + ctb - 1) - pic.origin_y; |
| 220 | - let lr = (y0 + ctb - 1) - pic.origin_y; | 216 | + slot.luma[a..b] |
| 221 | - slot.luma[a..b] | 217 | + .copy_from_slice(&pic.planes.y[lr * self.width + a..lr * self.width + b]); |
| 222 | - .copy_from_slice(&pic.planes.y[lr * self.width + a..lr * self.width + b]); | 218 | + let lc = ((y0 >> self.sub_y) + (ctb >> self.sub_y) - 1) - pic.origin_c; |
| 223 | - let lc = ((y0 >> self.sub_y) + (ctb >> self.sub_y) - 1) - pic.origin_c; | 219 | + slot.cb[ca..cb_end].copy_from_slice(&pic.planes.cb[lc * cw + ca..lc * cw + cb_end]); |
| 224 | - slot.cb[ca..cb_end].copy_from_slice(&pic.planes.cb[lc * cw + ca..lc * cw + cb_end]); | 220 | + slot.cr[ca..cb_end].copy_from_slice(&pic.planes.cr[lc * cw + ca..lc * cw + cb_end]); |
| 225 | - slot.cr[ca..cb_end].copy_from_slice(&pic.planes.cr[lc * cw + ca..lc * cw + cb_end]); | ||
| 226 | - } | ||
| 227 | let ur = (y0 + ctb - 4) / 4; | 221 | let ur = (y0 + ctb - 4) / 4; |
| 228 | let band_row = ur - pic.origin_unit / 4; | 222 | let band_row = ur - pic.origin_unit / 4; |
| 229 | slot.units[ua..ub] | 223 | slot.units[ua..ub] |
| @@ -501,7 +495,6 @@ pub(in crate::dec) fn parse_segment( | |||
| 501 | if ry0 > 0 { | 495 | if ry0 > 0 { |
| 502 | board.prefill(ry0 - 1, pic, &*source.field); | 496 | board.prefill(ry0 - 1, pic, &*source.field); |
| 503 | } | 497 | } |
| 504 | - let pixels = pic.has_pixels(); | ||
| 505 | let next = AtomicUsize::new(0); | 498 | let next = AtomicUsize::new(0); |
| 506 | let lists = source.lists; | 499 | let lists = source.lists; |
| 507 | let cur_poc = source.cur_poc; | 500 | let cur_poc = source.cur_poc; |
| @@ -517,7 +510,7 @@ pub(in crate::dec) fn parse_segment( | |||
| 517 | let y0 = ry << ctb_log2; | 510 | let y0 = ry << ctb_log2; |
| 518 | let bound = usize::from(ry > 0); | 511 | let bound = usize::from(ry > 0); |
| 519 | let own = ctb.min(global.height - y0); | 512 | let own = ctb.min(global.height - y0); |
| 520 | - let mut band = global.band(y0, own, pixels); | 513 | + let mut band = global.band(y0, own); |
| 521 | let mut field = field_global.band((y0 - 4 * bound) / 4, bound + own.div_ceil(4)); | 514 | let mut field = field_global.band((y0 - 4 * bound) / 4, bound + own.div_ceil(4)); |
| 522 | let row_start = if i == 0 { 0 } else { starts[i - 1] }; | 515 | let row_start = if i == 0 { 0 } else { starts[i - 1] }; |
| 523 | let row_len = (!last).then(|| starts[i] - row_start); | 516 | let row_len = (!last).then(|| starts[i] - row_start); |
| @@ -617,16 +610,14 @@ pub(in crate::dec) fn parse_segment( | |||
| 617 | let (sx, sy) = (pic.sub_x(), pic.sub_y()); | 610 | let (sx, sy) = (pic.sub_x(), pic.sub_y()); |
| 618 | let own_c = own.div_ceil(1 << sy); | 611 | let own_c = own.div_ceil(1 << sy); |
| 619 | let cw = pic.width.div_ceil(1 << sx); | 612 | let cw = pic.width.div_ceil(1 << sx); |
| 620 | - if pixels { | 613 | + let w = pic.width; |
| 621 | - let w = pic.width; | 614 | + pic.planes.y[y0 * w..(y0 + own) * w] |
| 622 | - pic.planes.y[y0 * w..(y0 + own) * w] | 615 | + .copy_from_slice(&done.band.planes.y[bound * w..(bound + own) * w]); |
| 623 | - .copy_from_slice(&done.band.planes.y[bound * w..(bound + own) * w]); | 616 | + let (c0, c1) = (y0 >> sy, (y0 >> sy) + own_c); |
| 624 | - let (c0, c1) = (y0 >> sy, (y0 >> sy) + own_c); | 617 | + pic.planes.cb[c0 * cw..c1 * cw] |
| 625 | - pic.planes.cb[c0 * cw..c1 * cw] | 618 | + .copy_from_slice(&done.band.planes.cb[bound * cw..(bound + own_c) * cw]); |
| 626 | - .copy_from_slice(&done.band.planes.cb[bound * cw..(bound + own_c) * cw]); | 619 | + pic.planes.cr[c0 * cw..c1 * cw] |
| 627 | - pic.planes.cr[c0 * cw..c1 * cw] | 620 | + .copy_from_slice(&done.band.planes.cr[bound * cw..(bound + own_c) * cw]); |
| 628 | - .copy_from_slice(&done.band.planes.cr[bound * cw..(bound + own_c) * cw]); | ||
| 629 | - } | ||
| 630 | let u0 = y0 / 4; | 621 | let u0 = y0 / 4; |
| 631 | let units = own.div_ceil(4); | 622 | let units = own.div_ceil(4); |
| 632 | pic.info[u0 * pic.w4..(u0 + units) * pic.w4] | 623 | pic.info[u0 * pic.w4..(u0 + units) * pic.w4] |
crates/ec-h265/src/dec/deblock.rsmodified+1 -4
| @@ -432,9 +432,6 @@ pub fn deblock_picture(pic: &mut PicState) { | |||
| 432 | /// side is in the rows above are filtered after those rows' own vertical edges, which | 432 | /// side is in the rows above are filtered after those rows' own vertical edges, which |
| 433 | /// is the order 8.7.2 gives for the whole picture. | 433 | /// is the order 8.7.2 gives for the whole picture. |
| 434 | pub fn deblock_rows(pic: &mut PicState, rows: Range<usize>) { | 434 | pub fn deblock_rows(pic: &mut PicState, rows: Range<usize>) { |
| 435 | - if !pic.has_pixels() { | ||
| 436 | - return; | ||
| 437 | - } | ||
| 438 | let (w, h) = (pic.width, pic.height); | 435 | let (w, h) = (pic.width, pic.height); |
| 439 | let (sx, sy) = (pic.sub_x(), pic.sub_y()); | 436 | let (sx, sy) = (pic.sub_x(), pic.sub_y()); |
| 440 | let (cw, ch) = (w.div_ceil(1 << sx), h.div_ceil(1 << sy)); | 437 | let (cw, ch) = (w.div_ceil(1 << sx), h.div_ceil(1 << sy)); |
| @@ -484,7 +481,7 @@ mod tests { | |||
| 484 | /// A 16x16 picture whose luma column `x` holds `value(x)`, with flat chroma, | 481 | /// A 16x16 picture whose luma column `x` holds `value(x)`, with flat chroma, |
| 485 | /// every unit intra at QP 37 and an edge on every unit. | 482 | /// every unit intra at QP 37 and an edge on every unit. |
| 486 | fn picture(value: impl Fn(usize) -> u16) -> PicState { | 483 | fn picture(value: impl Fn(usize) -> u16) -> PicState { |
| 487 | - let mut pic = PicState::new(16, 16, 4, 2, 8, 8, true); | 484 | + let mut pic = PicState::new(16, 16, 4, 2, 8, 8); |
| 488 | for y in 0..16 { | 485 | for y in 0..16 { |
| 489 | for x in 0..16 { | 486 | for x in 0..16 { |
| 490 | pic.planes.y[y * 16 + x] = value(x); | 487 | pic.planes.y[y * 16 + x] = value(x); |
crates/ec-h265/src/dec/inter.rsmodified+1 -4
| @@ -168,9 +168,6 @@ fn ref_picture(pic: &DecodedPicture) -> RefPicture<'_> { | |||
| 168 | /// Add the residual blocks of an inter coding unit to the samples its prediction | 168 | /// Add the residual blocks of an inter coding unit to the samples its prediction |
| 169 | /// units already wrote. | 169 | /// units already wrote. |
| 170 | pub fn add_residuals(pic: &mut PicState, residuals: &[ResidualBlock]) { | 170 | pub fn add_residuals(pic: &mut PicState, residuals: &[ResidualBlock]) { |
| 171 | - if !pic.has_pixels() { | ||
| 172 | - return; | ||
| 173 | - } | ||
| 174 | for block in residuals { | 171 | for block in residuals { |
| 175 | pic.add_residual( | 172 | pic.add_residual( |
| 176 | block.component, | 173 | block.component, |
| @@ -196,7 +193,7 @@ mod tests { | |||
| 196 | let (tx, rx) = mpsc::channel(); | 193 | let (tx, rx) = mpsc::channel(); |
| 197 | std::thread::spawn(move || { | 194 | std::thread::spawn(move || { |
| 198 | let (w, h) = (64usize, 64usize); | 195 | let (w, h) = (64usize, 64usize); |
| 199 | - let pic = Arc::new(SharedPic::new(0, w, h, (8, 8), true, 1)); | 196 | + let pic = Arc::new(SharedPic::new(0, w, h, (8, 8), 1)); |
| 200 | let src = DecodedPicture { | 197 | let src = DecodedPicture { |
| 201 | width: w, | 198 | width: w, |
| 202 | height: h, | 199 | height: h, |
crates/ec-h265/src/dec/mod.rsmodified+8 -80
| @@ -5,12 +5,7 @@ | |||
| 5 | //! Scope is the base layer of Main, Main 10 and range extension streams. Every slice | 5 | //! Scope is the base layer of Main, Main 10 and range extension streams. Every slice |
| 6 | //! goes through [`cu_syntax::parse_slice_into`], which parses the slice data | 6 | //! goes through [`cu_syntax::parse_slice_into`], which parses the slice data |
| 7 | //! and pixel-decodes it. Inter slices write placeholder samples (see | 7 | //! and pixel-decodes it. Inter slices write placeholder samples (see |
| 8 | -//! [`inter::placeholder_cu`]) until motion compensation lands. With pixel | 8 | +//! [`inter::placeholder_cu`]) until motion compensation lands. |
| 9 | -//! decode off ([`Decoder::set_pixel_decode`]) every slice is | ||
| 10 | -//! parsed and every picture is managed, but no samples are produced; that is | ||
| 11 | -//! the mode the picture-management tests use. [`Decoder::set_syntax_check`] | ||
| 12 | -//! adds the slice-data parse ([`cu_syntax::parse_slice`]) to that mode, for | ||
| 13 | -//! every slice type. | ||
| 14 | //! | 9 | //! |
| 15 | //! Decoded: Main, Main 10 and the range extension formats (4:0:0, 4:2:0, 4:2:2, 4:4:4 at | 10 | //! Decoded: Main, Main 10 and the range extension formats (4:0:0, 4:2:0, 4:2:2, 4:4:4 at |
| 16 | //! 8 to 12 bits) with transform-skip extensions, implicit and explicit RDPCM, persistent | 11 | //! 8 to 12 bits) with transform-skip extensions, implicit and explicit RDPCM, persistent |
| @@ -64,9 +59,8 @@ pub use meta::PictureMeta; | |||
| 64 | use picjob::{PicJob, SliceJob}; | 59 | use picjob::{PicJob, SliceJob}; |
| 65 | use rps::RpsInput; | 60 | use rps::RpsInput; |
| 66 | pub use rps::{RefEntry, RefPicLists, RefPicSet}; | 61 | pub use rps::{RefEntry, RefPicLists, RefPicSet}; |
| 67 | -use runner::{Budget, Checksum, Runner}; | 62 | +use runner::{Budget, Runner}; |
| 68 | use shared::SharedPic; | 63 | use shared::SharedPic; |
| 69 | -use std::sync::Mutex; | ||
| 70 | use std::thread::JoinHandle; | 64 | use std::thread::JoinHandle; |
| 71 | 65 | ||
| 72 | /// What [`Decoder::push_nal`] did with a NAL unit. | 66 | /// What [`Decoder::push_nal`] did with a NAL unit. |
| @@ -99,8 +93,6 @@ struct CurPicture { | |||
| 99 | runner: Runner, | 93 | runner: Runner, |
| 100 | /// The published picture (the samples and collocated motion that later pictures read). | 94 | /// The published picture (the samples and collocated motion that later pictures read). |
| 101 | shared: Arc<SharedPic>, | 95 | shared: Arc<SharedPic>, |
| 102 | - /// The motion checksum, set when the picture finishes. | ||
| 103 | - checksum: Arc<Checksum>, | ||
| 104 | /// The header of the picture's latest independent slice segment; the | 96 | /// The header of the picture's latest independent slice segment; the |
| 105 | /// dependent segments after it take their values from it. | 97 | /// dependent segments after it take their values from it. |
| 106 | header: Option<SliceHeader>, | 98 | header: Option<SliceHeader>, |
| @@ -142,13 +134,10 @@ pub struct Decoder { | |||
| 142 | vps: Vec<Option<Vps>>, | 134 | vps: Vec<Option<Vps>>, |
| 143 | sps: Vec<Option<Arc<Sps>>>, | 135 | sps: Vec<Option<Arc<Sps>>>, |
| 144 | pps: Vec<Option<Arc<Pps>>>, | 136 | pps: Vec<Option<Arc<Pps>>>, |
| 145 | - pixel_decode: bool, | ||
| 146 | /// Worker threads for the in-loop filters (see [`configured_threads`]). | 137 | /// Worker threads for the in-loop filters (see [`configured_threads`]). |
| 147 | threads: usize, | 138 | threads: usize, |
| 148 | /// The worker threads the pictures and their wavefront rows share. | 139 | /// The worker threads the pictures and their wavefront rows share. |
| 149 | budget: Arc<Budget>, | 140 | budget: Arc<Budget>, |
| 150 | - /// Parse every slice's data (all types) with [`cu_syntax`] when pixel decode is off. | ||
| 151 | - syntax_check: bool, | ||
| 152 | dpb: Dpb, | 141 | dpb: Dpb, |
| 153 | cur: Option<CurPicture>, | 142 | cur: Option<CurPicture>, |
| 154 | /// Set while the slices of a skipped RASL picture go by. | 143 | /// Set while the slices of a skipped RASL picture go by. |
| @@ -167,23 +156,12 @@ pub struct Decoder { | |||
| 167 | hdr_pending: PictureMeta, | 156 | hdr_pending: PictureMeta, |
| 168 | /// The HDR SEI in force in the current coded video sequence. | 157 | /// The HDR SEI in force in the current coded video sequence. |
| 169 | hdr_persist: PictureMeta, | 158 | hdr_persist: PictureMeta, |
| 170 | - /// The motion checksum of the finished pictures (see [`Decoder::motion_checksum`]). | ||
| 171 | - checksums: Mutex<ChecksumFold>, | ||
| 172 | /// Worker threads of the pictures that finished but may still run, oldest first. | 159 | /// Worker threads of the pictures that finished but may still run, oldest first. |
| 173 | in_flight: VecDeque<JoinHandle<()>>, | 160 | in_flight: VecDeque<JoinHandle<()>>, |
| 174 | /// The most pictures in flight (see [`picture_limit`]). | 161 | /// The most pictures in flight (see [`picture_limit`]). |
| 175 | max_in_flight: usize, | 162 | max_in_flight: usize, |
| 176 | } | 163 | } |
| 177 | 164 | ||
| 178 | -/// The motion checksum folded over the finished pictures in decoding order. | ||
| 179 | -#[derive(Default)] | ||
| 180 | -struct ChecksumFold { | ||
| 181 | - /// The fold of every picture whose checksum has been waited for. | ||
| 182 | - fold: u64, | ||
| 183 | - /// The checksums of the finished pictures not yet folded, in decoding order. | ||
| 184 | - pending: VecDeque<Arc<Checksum>>, | ||
| 185 | -} | ||
| 186 | - | ||
| 187 | impl Default for Decoder { | 165 | impl Default for Decoder { |
| 188 | fn default() -> Self { | 166 | fn default() -> Self { |
| 189 | Decoder::new() | 167 | Decoder::new() |
| @@ -191,16 +169,14 @@ impl Default for Decoder { | |||
| 191 | } | 169 | } |
| 192 | 170 | ||
| 193 | impl Decoder { | 171 | impl Decoder { |
| 194 | - /// A decoder with no parameter sets and pixel decode on. | 172 | + /// A decoder with no parameter sets. |
| 195 | pub fn new() -> Decoder { | 173 | pub fn new() -> Decoder { |
| 196 | Decoder { | 174 | Decoder { |
| 197 | vps: vec![None; 16], | 175 | vps: vec![None; 16], |
| 198 | sps: vec![None; 16], | 176 | sps: vec![None; 16], |
| 199 | pps: vec![None; 64], | 177 | pps: vec![None; 64], |
| 200 | - pixel_decode: true, | ||
| 201 | threads: configured_threads(), | 178 | threads: configured_threads(), |
| 202 | budget: Budget::new(configured_threads()), | 179 | budget: Budget::new(configured_threads()), |
| 203 | - syntax_check: false, | ||
| 204 | dpb: Dpb::new(), | 180 | dpb: Dpb::new(), |
| 205 | cur: None, | 181 | cur: None, |
| 206 | skipping: false, | 182 | skipping: false, |
| @@ -212,7 +188,6 @@ impl Decoder { | |||
| 212 | out: VecDeque::new(), | 188 | out: VecDeque::new(), |
| 213 | hdr_pending: PictureMeta::default(), | 189 | hdr_pending: PictureMeta::default(), |
| 214 | hdr_persist: PictureMeta::default(), | 190 | hdr_persist: PictureMeta::default(), |
| 215 | - checksums: Mutex::new(ChecksumFold::default()), | ||
| 216 | in_flight: VecDeque::new(), | 191 | in_flight: VecDeque::new(), |
| 217 | max_in_flight: picture_limit(configured_threads()), | 192 | max_in_flight: picture_limit(configured_threads()), |
| 218 | } | 193 | } |
| @@ -225,38 +200,6 @@ impl Decoder { | |||
| 225 | self.budget = Budget::new(self.threads); | 200 | self.budget = Budget::new(self.threads); |
| 226 | } | 201 | } |
| 227 | 202 | ||
| 228 | - /// Turn pixel decode on or off. Off parses every slice and manages every | ||
| 229 | - /// picture (RPS, POC, bumping) without producing samples; inter slices are | ||
| 230 | - /// accepted in that mode. | ||
| 231 | - pub fn set_pixel_decode(&mut self, on: bool) { | ||
| 232 | - self.pixel_decode = on; | ||
| 233 | - } | ||
| 234 | - | ||
| 235 | - /// Whether pixel decode is on. | ||
| 236 | - pub fn pixel_decode(&self) -> bool { | ||
| 237 | - self.pixel_decode | ||
| 238 | - } | ||
| 239 | - | ||
| 240 | - /// A hash of the motion field of every picture finished so far, in decoding order. | ||
| 241 | - /// Two decodes of the same stream give the same value; a change in any derived | ||
| 242 | - /// motion vector, reference index or prediction flag changes it. | ||
| 243 | - pub fn motion_checksum(&self) -> u64 { | ||
| 244 | - let mut fold = self.checksums.lock().unwrap_or_else(|e| e.into_inner()); | ||
| 245 | - while let Some(slot) = fold.pending.pop_front() { | ||
| 246 | - if let Some(sum) = slot.wait() { | ||
| 247 | - fold.fold = (fold.fold ^ sum).wrapping_mul(0x0000_0100_0000_01b3); | ||
| 248 | - } | ||
| 249 | - } | ||
| 250 | - fold.fold | ||
| 251 | - } | ||
| 252 | - | ||
| 253 | - /// With pixel decode off, also parse every slice's data with the CU syntax | ||
| 254 | - /// parser. A parse that does not reach `end_of_slice_segment_flag` at the | ||
| 255 | - /// end of the slice is an error from [`Decoder::push_nal`]. | ||
| 256 | - pub fn set_syntax_check(&mut self, on: bool) { | ||
| 257 | - self.syntax_check = on; | ||
| 258 | - } | ||
| 259 | - | ||
| 260 | /// The VPS stored under `id`. | 203 | /// The VPS stored under `id`. |
| 261 | pub fn vps(&self, id: u32) -> Option<&Vps> { | 204 | pub fn vps(&self, id: u32) -> Option<&Vps> { |
| 262 | self.vps.get(id as usize)?.as_ref() | 205 | self.vps.get(id as usize)?.as_ref() |
| @@ -521,10 +464,10 @@ impl Decoder { | |||
| 521 | irap_no_rasl: irap && no_rasl, | 464 | irap_no_rasl: irap && no_rasl, |
| 522 | width: sps.pic_width_in_luma_samples as usize, | 465 | width: sps.pic_width_in_luma_samples as usize, |
| 523 | height: sps.pic_height_in_luma_samples as usize, | 466 | height: sps.pic_height_in_luma_samples as usize, |
| 524 | - fill: self.pixel_decode.then_some(( | 467 | + fill: ( |
| 525 | sps.bit_depth_luma_minus8 + 8, | 468 | sps.bit_depth_luma_minus8 + 8, |
| 526 | sps.bit_depth_chroma_minus8 + 8, | 469 | sps.bit_depth_chroma_minus8 + 8, |
| 527 | - )), | 470 | + ), |
| 528 | chroma_format_idc: sps.chroma_format_idc, | 471 | chroma_format_idc: sps.chroma_format_idc, |
| 529 | }; | 472 | }; |
| 530 | let rps = self.dpb.apply_rps(&input); | 473 | let rps = self.dpb.apply_rps(&input); |
| @@ -559,7 +502,7 @@ impl Decoder { | |||
| 559 | } | 502 | } |
| 560 | 503 | ||
| 561 | // Frame threads: at most `threads` pictures in flight, so wait for the oldest. | 504 | // Frame threads: at most `threads` pictures in flight, so wait for the oldest. |
| 562 | - let threaded = self.threads > 1 && self.pixel_decode; | 505 | + let threaded = self.threads > 1; |
| 563 | if threaded { | 506 | if threaded { |
| 564 | while self.in_flight.len() >= self.max_in_flight { | 507 | while self.in_flight.len() >= self.max_in_flight { |
| 565 | if let Some(handle) = self.in_flight.pop_front() { | 508 | if let Some(handle) = self.in_flight.pop_front() { |
| @@ -575,13 +518,10 @@ impl Decoder { | |||
| 575 | 8 + sps.bit_depth_luma_minus8, | 518 | 8 + sps.bit_depth_luma_minus8, |
| 576 | 8 + sps.bit_depth_chroma_minus8, | 519 | 8 + sps.bit_depth_chroma_minus8, |
| 577 | ), | 520 | ), |
| 578 | - self.pixel_decode, | ||
| 579 | sps.chroma_format_idc, | 521 | sps.chroma_format_idc, |
| 580 | )); | 522 | )); |
| 581 | - let checksum = Arc::new(Checksum::default()); | ||
| 582 | let runner = Runner::start( | 523 | let runner = Runner::start( |
| 583 | PicJob::new(Arc::clone(&shared), Arc::clone(&self.budget)), | 524 | PicJob::new(Arc::clone(&shared), Arc::clone(&self.budget)), |
| 584 | - Arc::clone(&checksum), | ||
| 585 | threaded, | 525 | threaded, |
| 586 | ); | 526 | ); |
| 587 | self.cur = Some(CurPicture { | 527 | self.cur = Some(CurPicture { |
| @@ -594,7 +534,6 @@ impl Decoder { | |||
| 594 | lists: RefPicLists::default(), | 534 | lists: RefPicLists::default(), |
| 595 | runner, | 535 | runner, |
| 596 | shared, | 536 | shared, |
| 597 | - checksum, | ||
| 598 | all_intra: true, | 537 | all_intra: true, |
| 599 | meta, | 538 | meta, |
| 600 | }); | 539 | }); |
| @@ -602,7 +541,7 @@ impl Decoder { | |||
| 602 | } | 541 | } |
| 603 | 542 | ||
| 604 | /// Build the slice's reference lists, then hand the slice data to the picture's | 543 | /// Build the slice's reference lists, then hand the slice data to the picture's |
| 605 | - /// job. Nothing runs when pixel decode and the syntax check are both off. | 544 | + /// job. |
| 606 | fn decode_slice( | 545 | fn decode_slice( |
| 607 | &mut self, | 546 | &mut self, |
| 608 | slice: &SliceHeader, | 547 | slice: &SliceHeader, |
| @@ -612,7 +551,6 @@ impl Decoder { | |||
| 612 | sps: &Arc<Sps>, | 551 | sps: &Arc<Sps>, |
| 613 | pps: &Arc<Pps>, | 552 | pps: &Arc<Pps>, |
| 614 | ) -> Result<()> { | 553 | ) -> Result<()> { |
| 615 | - let pixel = self.pixel_decode; | ||
| 616 | let dpb = &self.dpb; | 554 | let dpb = &self.dpb; |
| 617 | let cur = self | 555 | let cur = self |
| 618 | .cur | 556 | .cur |
| @@ -624,9 +562,6 @@ impl Decoder { | |||
| 624 | if slice.slice_type != SliceType::I { | 562 | if slice.slice_type != SliceType::I { |
| 625 | cur.all_intra = false; | 563 | cur.all_intra = false; |
| 626 | } | 564 | } |
| 627 | - if !pixel && !self.syntax_check { | ||
| 628 | - return Ok(()); | ||
| 629 | - } | ||
| 630 | let data_off = (pos.header_bits / 8) as usize; | 565 | let data_off = (pos.header_bits / 8) as usize; |
| 631 | if data_off > rbsp.len() { | 566 | if data_off > rbsp.len() { |
| 632 | return Err(Error::corrupt( | 567 | return Err(Error::corrupt( |
| @@ -648,7 +583,7 @@ impl Decoder { | |||
| 648 | }) | 583 | }) |
| 649 | .collect() | 584 | .collect() |
| 650 | }; | 585 | }; |
| 651 | - let refs = if pixel && slice.slice_type != SliceType::I { | 586 | + let refs = if slice.slice_type != SliceType::I { |
| 652 | [lookup(&cur.lists.l0)?, lookup(&cur.lists.l1)?] | 587 | [lookup(&cur.lists.l0)?, lookup(&cur.lists.l1)?] |
| 653 | } else { | 588 | } else { |
| 654 | [Vec::new(), Vec::new()] | 589 | [Vec::new(), Vec::new()] |
| @@ -664,7 +599,6 @@ impl Decoder { | |||
| 664 | refs, | 599 | refs, |
| 665 | col, | 600 | col, |
| 666 | cur_poc: cur.poc, | 601 | cur_poc: cur.poc, |
| 667 | - pixel, | ||
| 668 | substreams, | 602 | substreams, |
| 669 | }); | 603 | }); |
| 670 | submitted | 604 | submitted |
| @@ -688,17 +622,11 @@ impl Decoder { | |||
| 688 | output, | 622 | output, |
| 689 | runner, | 623 | runner, |
| 690 | shared, | 624 | shared, |
| 691 | - checksum, | ||
| 692 | all_intra, | 625 | all_intra, |
| 693 | mut meta, | 626 | mut meta, |
| 694 | .. | 627 | .. |
| 695 | } = cur; | 628 | } = cur; |
| 696 | meta.intra_only = all_intra; | 629 | meta.intra_only = all_intra; |
| 697 | - self.checksums | ||
| 698 | - .lock() | ||
| 699 | - .unwrap_or_else(|e| e.into_inner()) | ||
| 700 | - .pending | ||
| 701 | - .push_back(checksum); | ||
| 702 | if let Some(handle) = runner.finish() { | 630 | if let Some(handle) = runner.finish() { |
| 703 | self.in_flight.push_back(handle); | 631 | self.in_flight.push_back(handle); |
| 704 | } | 632 | } |
crates/ec-h265/src/dec/motion_field.rsmodified+3 -54
| @@ -24,9 +24,6 @@ use super::{amvp, merge}; | |||
| 24 | use ec_h265_syntax::slice::{SliceHeader, SliceType}; | 24 | use ec_h265_syntax::slice::{SliceHeader, SliceType}; |
| 25 | use ec_h265_syntax::{Pps, Sps}; | 25 | use ec_h265_syntax::{Pps, Sps}; |
| 26 | 26 | ||
| 27 | -const FNV_OFFSET: u64 = 0xcbf2_9ce4_8422_2325; | ||
| 28 | -const FNV_PRIME: u64 = 0x0000_0100_0000_01b3; | ||
| 29 | - | ||
| 30 | /// The motion of one prediction block: `predFlagLX`, `refIdxLX` and `mvLX` for both | 27 | /// The motion of one prediction block: `predFlagLX`, `refIdxLX` and `mvLX` for both |
| 31 | /// lists. An unused list has reference index -1 and a zero vector, so two blocks | 28 | /// lists. An unused list has reference index -1 and a zero vector, so two blocks |
| 32 | /// with the same motion compare equal. | 29 | /// with the same motion compare equal. |
| @@ -116,7 +113,6 @@ pub struct MotionField { | |||
| 116 | cells: Vec<Option<FieldCell>>, | 113 | cells: Vec<Option<FieldCell>>, |
| 117 | /// The reference lists of each slice of the picture, indexed by `FieldCell::slice`. | 114 | /// The reference lists of each slice of the picture, indexed by `FieldCell::slice`. |
| 118 | pub slices: Vec<SliceRefs>, | 115 | pub slices: Vec<SliceRefs>, |
| 119 | - checksum: u64, | ||
| 120 | /// `TileId` of each CTB, raster order; empty when the picture has one tile. | 116 | /// `TileId` of each CTB, raster order; empty when the picture has one tile. |
| 121 | tiles: Vec<u16>, | 117 | tiles: Vec<u16>, |
| 122 | /// `CtbLog2SizeY` and the CTBs per row, for the tile lookup. | 118 | /// `CtbLog2SizeY` and the CTBs per row, for the tile lookup. |
| @@ -127,10 +123,6 @@ pub struct MotionField { | |||
| 127 | /// The 4x4 unit row of `cells[0..width4]`: zero for a whole picture, and the row above | 123 | /// The 4x4 unit row of `cells[0..width4]`: zero for a whole picture, and the row above |
| 128 | /// the band for a wavefront row band (see [`MotionField::band`]). | 124 | /// the band for a wavefront row band (see [`MotionField::band`]). |
| 129 | origin4: usize, | 125 | origin4: usize, |
| 130 | - /// A wavefront band: its stores are kept in `words` for the picture's checksum, which | ||
| 131 | - /// folds them in decoding order once the band is merged. | ||
| 132 | - band: bool, | ||
| 133 | - words: Vec<u64>, | ||
| 134 | } | 126 | } |
| 135 | 127 | ||
| 136 | impl MotionField { | 128 | impl MotionField { |
| @@ -144,14 +136,11 @@ impl MotionField { | |||
| 144 | width4, | 136 | width4, |
| 145 | cells: vec![None; width4 * height4], | 137 | cells: vec![None; width4 * height4], |
| 146 | slices: Vec::new(), | 138 | slices: Vec::new(), |
| 147 | - checksum: FNV_OFFSET, | ||
| 148 | tiles: Vec::new(), | 139 | tiles: Vec::new(), |
| 149 | ctb_log2: 0, | 140 | ctb_log2: 0, |
| 150 | ctb_cols: 0, | 141 | ctb_cols: 0, |
| 151 | cur_tile: 0, | 142 | cur_tile: 0, |
| 152 | origin4: 0, | 143 | origin4: 0, |
| 153 | - band: false, | ||
| 154 | - words: Vec::new(), | ||
| 155 | } | 144 | } |
| 156 | } | 145 | } |
| 157 | 146 | ||
| @@ -165,14 +154,11 @@ impl MotionField { | |||
| 165 | width4: self.width4, | 154 | width4: self.width4, |
| 166 | cells: vec![None; unit_rows * self.width4], | 155 | cells: vec![None; unit_rows * self.width4], |
| 167 | slices: Vec::new(), | 156 | slices: Vec::new(), |
| 168 | - checksum: FNV_OFFSET, | ||
| 169 | tiles: self.tiles.clone(), | 157 | tiles: self.tiles.clone(), |
| 170 | ctb_log2: self.ctb_log2, | 158 | ctb_log2: self.ctb_log2, |
| 171 | ctb_cols: self.ctb_cols, | 159 | ctb_cols: self.ctb_cols, |
| 172 | cur_tile: 0, | 160 | cur_tile: 0, |
| 173 | origin4, | 161 | origin4, |
| 174 | - band: true, | ||
| 175 | - words: Vec::new(), | ||
| 176 | } | 162 | } |
| 177 | } | 163 | } |
| 178 | 164 | ||
| @@ -198,18 +184,12 @@ impl MotionField { | |||
| 198 | } | 184 | } |
| 199 | 185 | ||
| 200 | /// Merge a finished band into this field: its cells from unit row `first_unit_row` on | 186 | /// Merge a finished band into this field: its cells from unit row `first_unit_row` on |
| 201 | - /// are copied, and its stores are folded into the checksum in decoding order. Bands | 187 | + /// are copied. |
| 202 | - /// merged in decoding order give the checksum a whole-picture decode would give. | ||
| 203 | pub fn merge_band(&mut self, band: &MotionField, first_unit_row: usize) { | 188 | pub fn merge_band(&mut self, band: &MotionField, first_unit_row: usize) { |
| 204 | let from = (first_unit_row - band.origin4) * self.width4; | 189 | let from = (first_unit_row - band.origin4) * self.width4; |
| 205 | let to = first_unit_row - self.origin4; | 190 | let to = first_unit_row - self.origin4; |
| 206 | let n = band.cells.len() - from; | 191 | let n = band.cells.len() - from; |
| 207 | self.cells[to * self.width4..to * self.width4 + n].copy_from_slice(&band.cells[from..]); | 192 | self.cells[to * self.width4..to * self.width4 + n].copy_from_slice(&band.cells[from..]); |
| 208 | - for words in band.words.as_chunks::<8>().0 { | ||
| 209 | - for &word in words { | ||
| 210 | - self.checksum = (self.checksum ^ word).wrapping_mul(FNV_PRIME); | ||
| 211 | - } | ||
| 212 | - } | ||
| 213 | } | 193 | } |
| 214 | 194 | ||
| 215 | /// The tile of each CTB (raster order), so that a neighbour in another tile is | 195 | /// The tile of each CTB (raster order), so that a neighbour in another tile is |
| @@ -313,30 +293,6 @@ impl MotionField { | |||
| 313 | Some(FieldCell { motion, slice }); | 293 | Some(FieldCell { motion, slice }); |
| 314 | } | 294 | } |
| 315 | } | 295 | } |
| 316 | - let mut words = [0u64; 8]; | ||
| 317 | - words[0] = x as u64; | ||
| 318 | - words[1] = y as u64; | ||
| 319 | - words[2] = w as u64; | ||
| 320 | - words[3] = h as u64; | ||
| 321 | - words[4] = u64::from(slice); | ||
| 322 | - words[5] = u64::from(motion.pred[0]) | (u64::from(motion.pred[1]) << 1); | ||
| 323 | - words[6] = (motion.ref_idx[0] as u8 as u64) | ((motion.ref_idx[1] as u8 as u64) << 8); | ||
| 324 | - words[7] = (motion.mv[0][0] as u16 as u64) | ||
| 325 | - | ((motion.mv[0][1] as u16 as u64) << 16) | ||
| 326 | - | ((motion.mv[1][0] as u16 as u64) << 32) | ||
| 327 | - | ((motion.mv[1][1] as u16 as u64) << 48); | ||
| 328 | - if self.band { | ||
| 329 | - self.words.extend_from_slice(&words); | ||
| 330 | - return; | ||
| 331 | - } | ||
| 332 | - for word in words { | ||
| 333 | - self.checksum = (self.checksum ^ word).wrapping_mul(FNV_PRIME); | ||
| 334 | - } | ||
| 335 | - } | ||
| 336 | - | ||
| 337 | - /// A hash of every stored block, in decoding order. Equal for equal derivations. | ||
| 338 | - pub fn checksum(&self) -> u64 { | ||
| 339 | - self.checksum | ||
| 340 | } | 296 | } |
| 341 | 297 | ||
| 342 | /// The motion of every 4x4 unit in the form the deblocking filter reads (8.7.2.4). | 298 | /// The motion of every 4x4 unit in the form the deblocking filter reads (8.7.2.4). |
| @@ -638,10 +594,8 @@ impl MotionSource for SliceMotion<'_> { | |||
| 638 | // The CTB row that ended is `row_end - ctb`; its motion is final. | 594 | // The CTB row that ended is `row_end - ctb`; its motion is final. |
| 639 | let ctb = 1usize << self.params.ctb_log2; | 595 | let ctb = 1usize << self.params.ctb_log2; |
| 640 | let y0 = row_end.saturating_sub(ctb); | 596 | let y0 = row_end.saturating_sub(ctb); |
| 641 | - if pic.has_pixels() { | 597 | + let (u0, u1) = (y0, row_end.min(self.field.height())); |
| 642 | - let (u0, u1) = (y0, row_end.min(self.field.height())); | 598 | + self.field.deblock_rows(&mut pic.motion, u0, u1); |
| 643 | - self.field.deblock_rows(&mut pic.motion, u0, u1); | ||
| 644 | - } | ||
| 645 | if let Some(shared) = &self.publish { | 599 | if let Some(shared) = &self.publish { |
| 646 | shared.publish_col(self.field, row_end); | 600 | shared.publish_col(self.field, row_end); |
| 647 | } | 601 | } |
| @@ -682,11 +636,6 @@ pub fn scale_mv(mv: [i32; 2], td: i32, tb: i32) -> [i32; 2] { | |||
| 682 | }) | 636 | }) |
| 683 | } | 637 | } |
| 684 | 638 | ||
| 685 | -/// The chroma vector of 4:2:0 content, in 1/8 chroma sample units (8.5.3.2.10): | ||
| 686 | -/// the luma quarter-sample vector, unchanged in value. | ||
| 687 | -pub fn chroma_mv_420(mv: [i16; 2]) -> [i32; 2] { | ||
| 688 | - to32(mv) | ||
| 689 | -} | ||
| 690 | 639 | ||
| 691 | /// A vector widened to `i32`. | 640 | /// A vector widened to `i32`. |
| 692 | pub fn to32(mv: [i16; 2]) -> [i32; 2] { | 641 | pub fn to32(mv: [i16; 2]) -> [i32; 2] { |
crates/ec-h265/src/dec/pic.rsmodified+16 -52
| @@ -163,7 +163,7 @@ pub struct PicState { | |||
| 163 | pub pps_cb_qp_offset: i32, | 163 | pub pps_cb_qp_offset: i32, |
| 164 | /// See `pps_cb_qp_offset`. | 164 | /// See `pps_cb_qp_offset`. |
| 165 | pub pps_cr_qp_offset: i32, | 165 | pub pps_cr_qp_offset: i32, |
| 166 | - /// The samples. Empty planes when the decoder runs without pixel decode. | 166 | + /// The samples. |
| 167 | pub planes: DecodedPicture, | 167 | pub planes: DecodedPicture, |
| 168 | /// Per 4x4 unit, `w4 * h4`. | 168 | /// Per 4x4 unit, `w4 * h4`. |
| 169 | pub info: Vec<BlockInfo>, | 169 | pub info: Vec<BlockInfo>, |
| @@ -189,8 +189,7 @@ pub struct PicState { | |||
| 189 | } | 189 | } |
| 190 | 190 | ||
| 191 | impl PicState { | 191 | impl PicState { |
| 192 | - /// The state of a `width` x `height` picture. With `pixels` false the | 192 | + /// The state of a `width` x `height` picture. |
| 193 | - /// sample planes are left empty and only the maps are kept. | ||
| 194 | #[allow(clippy::too_many_arguments)] // one value per picture-level SPS/PPS fact | 193 | #[allow(clippy::too_many_arguments)] // one value per picture-level SPS/PPS fact |
| 195 | pub fn new( | 194 | pub fn new( |
| 196 | width: usize, | 195 | width: usize, |
| @@ -199,27 +198,13 @@ impl PicState { | |||
| 199 | min_tb_log2: u32, | 198 | min_tb_log2: u32, |
| 200 | bit_depth_y: u32, | 199 | bit_depth_y: u32, |
| 201 | bit_depth_c: u32, | 200 | bit_depth_c: u32, |
| 202 | - pixels: bool, | ||
| 203 | ) -> PicState { | 201 | ) -> PicState { |
| 204 | let ctb = 1usize << ctb_log2; | 202 | let ctb = 1usize << ctb_log2; |
| 205 | let ctb_cols = width.div_ceil(ctb); | 203 | let ctb_cols = width.div_ceil(ctb); |
| 206 | let ctb_rows = height.div_ceil(ctb); | 204 | let ctb_rows = height.div_ceil(ctb); |
| 207 | let w4 = width.div_ceil(4); | 205 | let w4 = width.div_ceil(4); |
| 208 | let h4 = height.div_ceil(4); | 206 | let h4 = height.div_ceil(4); |
| 209 | - let planes = if pixels { | 207 | + let planes = DecodedPicture::grey_planes(width, height, bit_depth_y, bit_depth_c, 1); |
| 210 | - DecodedPicture::grey_planes(width, height, bit_depth_y, bit_depth_c) | ||
| 211 | - } else { | ||
| 212 | - DecodedPicture { | ||
| 213 | - width, | ||
| 214 | - height, | ||
| 215 | - bit_depth: bit_depth_y, | ||
| 216 | - bit_depth_c, | ||
| 217 | - chroma_format_idc: 1, | ||
| 218 | - y: Vec::new(), | ||
| 219 | - cb: Vec::new(), | ||
| 220 | - cr: Vec::new(), | ||
| 221 | - } | ||
| 222 | - }; | ||
| 223 | PicState { | 208 | PicState { |
| 224 | width, | 209 | width, |
| 225 | height, | 210 | height, |
| @@ -262,11 +247,6 @@ impl PicState { | |||
| 262 | crate::decode::chroma_shifts(self.chroma_format_idc).1 | 247 | crate::decode::chroma_shifts(self.chroma_format_idc).1 |
| 263 | } | 248 | } |
| 264 | 249 | ||
| 265 | - /// Whether the sample planes are allocated (pixel decode is on). | ||
| 266 | - pub fn has_pixels(&self) -> bool { | ||
| 267 | - !self.planes.y.is_empty() | ||
| 268 | - } | ||
| 269 | - | ||
| 270 | /// The three writable sample planes, for motion compensation. | 250 | /// The three writable sample planes, for motion compensation. |
| 271 | pub fn planes_mut(&mut self) -> [PlaneMut<'_>; 3] { | 251 | pub fn planes_mut(&mut self) -> [PlaneMut<'_>; 3] { |
| 272 | let (bd_y, bd_c) = (self.bit_depth_y, self.bit_depth_c); | 252 | let (bd_y, bd_c) = (self.bit_depth_y, self.bit_depth_c); |
| @@ -384,9 +364,8 @@ impl PicState { | |||
| 384 | } | 364 | } |
| 385 | } | 365 | } |
| 386 | 366 | ||
| 387 | - /// The state of a picture of `sps` and `pps`. With `pixels` on, the sample | 367 | + /// The state of a picture of `sps` and `pps`, its sample planes grey. |
| 388 | - /// planes are allocated, grey. | 368 | + pub fn for_sps_pps(sps: &Sps, pps: &Pps) -> PicState { |
| 389 | - pub fn for_sps_pps(sps: &Sps, pps: &Pps, pixels: bool) -> PicState { | ||
| 390 | let min_cb_log2 = sps.log2_min_cb_size_minus3 + 3; | 369 | let min_cb_log2 = sps.log2_min_cb_size_minus3 + 3; |
| 391 | let ctb_log2 = min_cb_log2 + sps.log2_diff_max_min_cb_size; | 370 | let ctb_log2 = min_cb_log2 + sps.log2_diff_max_min_cb_size; |
| 392 | let min_tb_log2 = sps.log2_min_tb_size_minus2 + 2; | 371 | let min_tb_log2 = sps.log2_min_tb_size_minus2 + 2; |
| @@ -397,19 +376,16 @@ impl PicState { | |||
| 397 | min_tb_log2, | 376 | min_tb_log2, |
| 398 | 8 + sps.bit_depth_luma_minus8, | 377 | 8 + sps.bit_depth_luma_minus8, |
| 399 | 8 + sps.bit_depth_chroma_minus8, | 378 | 8 + sps.bit_depth_chroma_minus8, |
| 400 | - pixels, | ||
| 401 | ); | 379 | ); |
| 402 | if sps.chroma_format_idc != 1 { | 380 | if sps.chroma_format_idc != 1 { |
| 403 | pic.chroma_format_idc = sps.chroma_format_idc; | 381 | pic.chroma_format_idc = sps.chroma_format_idc; |
| 404 | - if pixels { | 382 | + pic.planes = DecodedPicture::grey_planes( |
| 405 | - pic.planes = DecodedPicture::grey_planes_fmt( | 383 | + pic.width, |
| 406 | - pic.width, | 384 | + pic.height, |
| 407 | - pic.height, | 385 | + pic.bit_depth_y, |
| 408 | - pic.bit_depth_y, | 386 | + pic.bit_depth_c, |
| 409 | - pic.bit_depth_c, | 387 | + sps.chroma_format_idc, |
| 410 | - sps.chroma_format_idc, | 388 | + ); |
| 411 | - ); | ||
| 412 | - } | ||
| 413 | } | 389 | } |
| 414 | pic.constrained_intra_pred = pps.constrained_intra_pred; | 390 | pic.constrained_intra_pred = pps.constrained_intra_pred; |
| 415 | pic.strong_intra_smoothing = sps.strong_intra_smoothing; | 391 | pic.strong_intra_smoothing = sps.strong_intra_smoothing; |
| @@ -426,7 +402,7 @@ impl PicState { | |||
| 426 | /// first, so the band's first sample, unit and CTB rows are that row (copied in by | 402 | /// first, so the band's first sample, unit and CTB rows are that row (copied in by |
| 427 | /// the wavefront driver). The maps cover only the band; the CTB table is the | 403 | /// the wavefront driver). The maps cover only the band; the CTB table is the |
| 428 | /// whole picture's shape, and the tile scan and slice state are copied. | 404 | /// whole picture's shape, and the tile scan and slice state are copied. |
| 429 | - pub fn band(&self, y0: usize, own: usize, pixels: bool) -> PicState { | 405 | + pub fn band(&self, y0: usize, own: usize) -> PicState { |
| 430 | let bound = usize::from(y0 > 0); | 406 | let bound = usize::from(y0 > 0); |
| 431 | let own_units = own.div_ceil(4); | 407 | let own_units = own.div_ceil(4); |
| 432 | let (sx, sy) = crate::decode::chroma_shifts(self.chroma_format_idc); | 408 | let (sx, sy) = crate::decode::chroma_shifts(self.chroma_format_idc); |
| @@ -438,21 +414,9 @@ impl PicState { | |||
| 438 | bit_depth: self.bit_depth_y, | 414 | bit_depth: self.bit_depth_y, |
| 439 | bit_depth_c: self.bit_depth_c, | 415 | bit_depth_c: self.bit_depth_c, |
| 440 | chroma_format_idc: self.chroma_format_idc, | 416 | chroma_format_idc: self.chroma_format_idc, |
| 441 | - y: if pixels { | 417 | + y: vec![0; (bound + own) * self.width], |
| 442 | - vec![0; (bound + own) * self.width] | 418 | + cb: vec![0; (bound + own_c) * cw], |
| 443 | - } else { | 419 | + cr: vec![0; (bound + own_c) * cw], |
| 444 | - Vec::new() | ||
| 445 | - }, | ||
| 446 | - cb: if pixels { | ||
| 447 | - vec![0; (bound + own_c) * cw] | ||
| 448 | - } else { | ||
| 449 | - Vec::new() | ||
| 450 | - }, | ||
| 451 | - cr: if pixels { | ||
| 452 | - vec![0; (bound + own_c) * cw] | ||
| 453 | - } else { | ||
| 454 | - Vec::new() | ||
| 455 | - }, | ||
| 456 | }; | 420 | }; |
| 457 | PicState { | 421 | PicState { |
| 458 | width: self.width, | 422 | width: self.width, |
crates/ec-h265/src/dec/picjob.rsmodified+9 -16
| @@ -42,8 +42,6 @@ pub struct SliceJob { | |||
| 42 | pub col: Option<Arc<SharedPic>>, | 42 | pub col: Option<Arc<SharedPic>>, |
| 43 | /// `PicOrderCntVal` of the picture. | 43 | /// `PicOrderCntVal` of the picture. |
| 44 | pub cur_poc: i32, | 44 | pub cur_poc: i32, |
| 45 | - /// Reconstruct the samples (pixel decode). Off parses the syntax and the motion only. | ||
| 46 | - pub pixel: bool, | ||
| 47 | /// Where the substreams after the first start, relative to `data_off` (one per CTB row | 45 | /// Where the substreams after the first start, relative to `data_off` (one per CTB row |
| 48 | /// after the segment's first, from the entry points). Empty when there are none. | 46 | /// after the segment's first, from the entry points). Empty when there are none. |
| 49 | pub substreams: Vec<usize>, | 47 | pub substreams: Vec<usize>, |
| @@ -95,7 +93,7 @@ impl PicJob { | |||
| 95 | .. | 93 | .. |
| 96 | } = self; | 94 | } = self; |
| 97 | let (sps, pps) = (&*job.sps, &*job.pps); | 95 | let (sps, pps) = (&*job.sps, &*job.pps); |
| 98 | - let pic = pic.get_or_insert_with(|| PicState::for_sps_pps(sps, pps, job.pixel)); | 96 | + let pic = pic.get_or_insert_with(|| PicState::for_sps_pps(sps, pps)); |
| 99 | let (w, h) = ( | 97 | let (w, h) = ( |
| 100 | sps.pic_width_in_luma_samples as usize, | 98 | sps.pic_width_in_luma_samples as usize, |
| 101 | sps.pic_height_in_luma_samples as usize, | 99 | sps.pic_height_in_luma_samples as usize, |
| @@ -112,7 +110,7 @@ impl PicJob { | |||
| 112 | field.slices.push(SliceRefs::from_lists(&job.lists)); | 110 | field.slices.push(SliceRefs::from_lists(&job.lists)); |
| 113 | } | 111 | } |
| 114 | let slice = u16::try_from(field.slices.len().saturating_sub(1)).unwrap_or(u16::MAX); | 112 | let slice = u16::try_from(field.slices.len().saturating_sub(1)).unwrap_or(u16::MAX); |
| 115 | - let refs = if job.pixel && job.header.slice_type != SliceType::I { | 113 | + let refs = if job.header.slice_type != SliceType::I { |
| 116 | Some(InterRefs::new(job.refs, &job.header, sps)?) | 114 | Some(InterRefs::new(job.refs, &job.header, sps)?) |
| 117 | } else { | 115 | } else { |
| 118 | None | 116 | None |
| @@ -181,10 +179,9 @@ impl PicJob { | |||
| 181 | Ok(()) | 179 | Ok(()) |
| 182 | } | 180 | } |
| 183 | 181 | ||
| 184 | - /// The picture is complete: run the rest of the in-loop filters, publish every | 182 | + /// The picture is complete: run the rest of the in-loop filters, and publish every |
| 185 | - /// row and the collocated motion, and return the picture's motion checksum (`None` | 183 | + /// row and the collocated motion. |
| 186 | - /// when no slice ran). | 184 | + pub fn finish(&mut self) { |
| 187 | - pub fn finish(&mut self) -> Option<u64> { | ||
| 188 | let PicJob { | 185 | let PicJob { |
| 189 | shared, | 186 | shared, |
| 190 | pic, | 187 | pic, |
| @@ -194,22 +191,18 @@ impl PicJob { | |||
| 194 | } = self; | 191 | } = self; |
| 195 | let Some(mut pic) = pic.take() else { | 192 | let Some(mut pic) = pic.take() else { |
| 196 | shared.complete(); | 193 | shared.complete(); |
| 197 | - return None; | 194 | + return; |
| 198 | }; | 195 | }; |
| 199 | let h = shared.height; | 196 | let h = shared.height; |
| 200 | // Slices that finished no CTB row (or several tiles) left the motion of the | 197 | // Slices that finished no CTB row (or several tiles) left the motion of the |
| 201 | // units for the filter to read; fill every unit now. | 198 | // units for the filter to read; fill every unit now. |
| 202 | - let checksum = motion.take().map(|field| { | 199 | + if let Some(field) = motion.take() { |
| 203 | - if pic.has_pixels() { | 200 | + field.deblock_rows(&mut pic.motion, 0, h); |
| 204 | - field.deblock_rows(&mut pic.motion, 0, h); | ||
| 205 | - } | ||
| 206 | shared.publish_col(&field, h); | 201 | shared.publish_col(&field, h); |
| 207 | - field.checksum() | 202 | + } |
| 208 | - }); | ||
| 209 | let rows = pic.ctb_rows; | 203 | let rows = pic.ctb_rows; |
| 210 | let final_rows = filter.advance(&mut pic, rows); | 204 | let final_rows = filter.advance(&mut pic, rows); |
| 211 | shared.publish_rows(&pic.planes, final_rows); | 205 | shared.publish_rows(&pic.planes, final_rows); |
| 212 | shared.complete(); | 206 | shared.complete(); |
| 213 | - checksum | ||
| 214 | } | 207 | } |
| 215 | } | 208 | } |
crates/ec-h265/src/dec/recon.rsmodified+0 -10
| @@ -118,16 +118,6 @@ impl PicState { | |||
| 118 | } | 118 | } |
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | - /// Write `value` into every sample of an `n` x `n` block of component `c`. | ||
| 122 | - pub fn fill_plane(&mut self, c: usize, x: usize, y: usize, n: usize, value: u16) { | ||
| 123 | - let origin = self.plane_origin(c); | ||
| 124 | - let (stride, plane) = self.plane_view_mut(c); | ||
| 125 | - for j in 0..n { | ||
| 126 | - let start = (y + j - origin) * stride + x; | ||
| 127 | - plane[start..start + n].fill(value); | ||
| 128 | - } | ||
| 129 | - } | ||
| 130 | - | ||
| 131 | /// The row stride of the chroma planes. | 121 | /// The row stride of the chroma planes. |
| 132 | fn chroma_stride(&self) -> usize { | 122 | fn chroma_stride(&self) -> usize { |
| 133 | self.width.div_ceil(1 << self.sub_x()) | 123 | self.width.div_ceil(1 << self.sub_x()) |
crates/ec-h265/src/dec/rowfilter.rsmodified+1 -6
| @@ -53,9 +53,7 @@ impl RowFilter { | |||
| 53 | let ctb = 1usize << pic.ctb_log2; | 53 | let ctb = 1usize << pic.ctb_log2; |
| 54 | while self.deblocked < rows && (self.deblocked + 2 <= complete || all) { | 54 | while self.deblocked < rows && (self.deblocked + 2 <= complete || all) { |
| 55 | let r = self.deblocked; | 55 | let r = self.deblocked; |
| 56 | - if pic.has_pixels() { | 56 | + deblock::deblock_rows(pic, r * ctb..(r + 1) * ctb); |
| 57 | - deblock::deblock_rows(pic, r * ctb..(r + 1) * ctb); | ||
| 58 | - } | ||
| 59 | self.deblocked += 1; | 57 | self.deblocked += 1; |
| 60 | } | 58 | } |
| 61 | while self.filtered < rows | 59 | while self.filtered < rows |
| @@ -74,9 +72,6 @@ impl RowFilter { | |||
| 74 | 72 | ||
| 75 | /// SAO of CTB row `r` for the three planes, then remember its last deblocked line. | 73 | /// SAO of CTB row `r` for the three planes, then remember its last deblocked line. |
| 76 | fn sao_row(&mut self, pic: &mut PicState, r: usize) { | 74 | fn sao_row(&mut self, pic: &mut PicState, r: usize) { |
| 77 | - if !pic.has_pixels() { | ||
| 78 | - return; | ||
| 79 | - } | ||
| 80 | let ctb = 1usize << pic.ctb_log2; | 75 | let ctb = 1usize << pic.ctb_log2; |
| 81 | // Does any CTB of the row use SAO? Without one the row is final as it is. | 76 | // Does any CTB of the row use SAO? Without one the row is final as it is. |
| 82 | let sao_on = (r * pic.ctb_cols..(r + 1) * pic.ctb_cols).any(|i| { | 77 | let sao_on = (r * pic.ctb_cols..(r + 1) * pic.ctb_cols).any(|i| { |
crates/ec-h265/src/dec/rps.rsmodified+10 -22
| @@ -27,9 +27,8 @@ pub struct RpsInput<'a> { | |||
| 27 | /// Luma height of the picture, for generated pictures. | 27 | /// Luma height of the picture, for generated pictures. |
| 28 | pub height: usize, | 28 | pub height: usize, |
| 29 | /// Bit depths (luma, chroma) of a generated (8.3.3) picture, whose samples are | 29 | /// Bit depths (luma, chroma) of a generated (8.3.3) picture, whose samples are |
| 30 | - /// grey. `None` generates a picture without samples, for a decoder that does | 30 | + /// grey. |
| 31 | - /// not decode pixels. | 31 | + pub fill: (u32, u32), |
| 32 | - pub fill: Option<(u32, u32)>, | ||
| 33 | /// `chroma_format_idc` of the generated picture. | 32 | /// `chroma_format_idc` of the generated picture. |
| 34 | pub chroma_format_idc: u32, | 33 | pub chroma_format_idc: u32, |
| 35 | } | 34 | } |
| @@ -236,25 +235,14 @@ impl Dpb { | |||
| 236 | 235 | ||
| 237 | /// Generate a missing reference picture (8.3.3.2): grey samples, no output. | 236 | /// Generate a missing reference picture (8.3.3.2): grey samples, no output. |
| 238 | fn generate(&mut self, poc: i32, marking: Marking, input: &RpsInput<'_>) -> u32 { | 237 | fn generate(&mut self, poc: i32, marking: Marking, input: &RpsInput<'_>) -> u32 { |
| 239 | - let picture = match input.fill { | 238 | + let (bit_depth, bit_depth_c) = input.fill; |
| 240 | - Some((bit_depth, bit_depth_c)) => DecodedPicture::grey_planes_fmt( | 239 | + let picture = DecodedPicture::grey_planes( |
| 241 | - input.width, | 240 | + input.width, |
| 242 | - input.height, | 241 | + input.height, |
| 243 | - bit_depth, | 242 | + bit_depth, |
| 244 | - bit_depth_c, | 243 | + bit_depth_c, |
| 245 | - input.chroma_format_idc, | 244 | + input.chroma_format_idc, |
| 246 | - ), | 245 | + ); |
| 247 | - None => DecodedPicture { | ||
| 248 | - width: input.width, | ||
| 249 | - height: input.height, | ||
| 250 | - bit_depth: 8, | ||
| 251 | - bit_depth_c: 8, | ||
| 252 | - chroma_format_idc: input.chroma_format_idc, | ||
| 253 | - y: Vec::new(), | ||
| 254 | - cb: Vec::new(), | ||
| 255 | - cr: Vec::new(), | ||
| 256 | - }, | ||
| 257 | - }; | ||
| 258 | self.insert( | 246 | self.insert( |
| 259 | poc, | 247 | poc, |
| 260 | marking, | 248 | marking, |
crates/ec-h265/src/dec/runner.rsmodified+12 -49
| @@ -15,7 +15,7 @@ | |||
| 15 | 15 | ||
| 16 | use std::panic::{AssertUnwindSafe, catch_unwind}; | 16 | use std::panic::{AssertUnwindSafe, catch_unwind}; |
| 17 | use std::sync::mpsc::{self, Receiver, Sender}; | 17 | use std::sync::mpsc::{self, Receiver, Sender}; |
| 18 | -use std::sync::{Arc, Condvar, Mutex, MutexGuard}; | 18 | +use std::sync::{Arc, Mutex, MutexGuard}; |
| 19 | use std::thread::JoinHandle; | 19 | use std::thread::JoinHandle; |
| 20 | 20 | ||
| 21 | use super::picjob::{PicJob, SliceJob}; | 21 | use super::picjob::{PicJob, SliceJob}; |
| @@ -106,34 +106,6 @@ impl Drop for PictureSlot { | |||
| 106 | } | 106 | } |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | -/// The motion checksum of one picture (see [`super::Decoder::motion_checksum`]), set when | ||
| 110 | -/// the picture finishes. The value is `None` for a picture no slice ran in, and also for a | ||
| 111 | -/// picture that failed. | ||
| 112 | -#[derive(Debug, Default)] | ||
| 113 | -pub struct Checksum { | ||
| 114 | - value: Mutex<Option<Option<u64>>>, | ||
| 115 | - changed: Condvar, | ||
| 116 | -} | ||
| 117 | - | ||
| 118 | -impl Checksum { | ||
| 119 | - /// Store the picture's value and wake the readers. | ||
| 120 | - pub fn set(&self, value: Option<u64>) { | ||
| 121 | - *lock(&self.value) = Some(value); | ||
| 122 | - self.changed.notify_all(); | ||
| 123 | - } | ||
| 124 | - | ||
| 125 | - /// Wait until the value is stored. | ||
| 126 | - pub fn wait(&self) -> Option<u64> { | ||
| 127 | - let mut value = lock(&self.value); | ||
| 128 | - loop { | ||
| 129 | - if let Some(v) = *value { | ||
| 130 | - return v; | ||
| 131 | - } | ||
| 132 | - value = self.changed.wait(value).unwrap_or_else(|e| e.into_inner()); | ||
| 133 | - } | ||
| 134 | - } | ||
| 135 | -} | ||
| 136 | - | ||
| 137 | /// A message to a picture's worker. | 109 | /// A message to a picture's worker. |
| 138 | pub enum Msg { | 110 | pub enum Msg { |
| 139 | /// Run this slice segment. | 111 | /// Run this slice segment. |
| @@ -148,8 +120,6 @@ pub enum Runner { | |||
| 148 | Inline { | 120 | Inline { |
| 149 | /// The picture's job. | 121 | /// The picture's job. |
| 150 | job: Box<PicJob>, | 122 | job: Box<PicJob>, |
| 151 | - /// Set when the picture finishes. | ||
| 152 | - checksum: Arc<Checksum>, | ||
| 153 | }, | 123 | }, |
| 154 | /// On a worker thread that owns the job. | 124 | /// On a worker thread that owns the job. |
| 155 | Worker { | 125 | Worker { |
| @@ -162,15 +132,14 @@ pub enum Runner { | |||
| 162 | 132 | ||
| 163 | impl Runner { | 133 | impl Runner { |
| 164 | /// Start the decoding of the picture of `job`. `threaded` gives it a worker thread. | 134 | /// Start the decoding of the picture of `job`. `threaded` gives it a worker thread. |
| 165 | - pub fn start(job: PicJob, checksum: Arc<Checksum>, threaded: bool) -> Runner { | 135 | + pub fn start(job: PicJob, threaded: bool) -> Runner { |
| 166 | if !threaded { | 136 | if !threaded { |
| 167 | return Runner::Inline { | 137 | return Runner::Inline { |
| 168 | job: Box::new(job), | 138 | job: Box::new(job), |
| 169 | - checksum, | ||
| 170 | }; | 139 | }; |
| 171 | } | 140 | } |
| 172 | let (tx, rx) = mpsc::channel(); | 141 | let (tx, rx) = mpsc::channel(); |
| 173 | - let handle = std::thread::spawn(move || run_worker(rx, job, checksum)); | 142 | + let handle = std::thread::spawn(move || run_worker(rx, job)); |
| 174 | Runner::Worker { tx, handle } | 143 | Runner::Worker { tx, handle } |
| 175 | } | 144 | } |
| 176 | 145 | ||
| @@ -192,8 +161,8 @@ impl Runner { | |||
| 192 | /// goes on in the background; its handle is returned to be joined later. | 161 | /// goes on in the background; its handle is returned to be joined later. |
| 193 | pub fn finish(self) -> Option<JoinHandle<()>> { | 162 | pub fn finish(self) -> Option<JoinHandle<()>> { |
| 194 | match self { | 163 | match self { |
| 195 | - Runner::Inline { mut job, checksum } => { | 164 | + Runner::Inline { mut job } => { |
| 196 | - checksum.set(job.finish()); | 165 | + job.finish(); |
| 197 | None | 166 | None |
| 198 | } | 167 | } |
| 199 | Runner::Worker { tx, handle } => { | 168 | Runner::Worker { tx, handle } => { |
| @@ -206,17 +175,17 @@ impl Runner { | |||
| 206 | 175 | ||
| 207 | /// The body of a picture's worker thread. A failure, a panic, or a picture dropped before | 176 | /// The body of a picture's worker thread. A failure, a panic, or a picture dropped before |
| 208 | /// its finish marks the picture as failed, so that nothing waits on it forever. | 177 | /// its finish marks the picture as failed, so that nothing waits on it forever. |
| 209 | -fn run_worker(rx: Receiver<Msg>, mut job: PicJob, checksum: Arc<Checksum>) { | 178 | +fn run_worker(rx: Receiver<Msg>, mut job: PicJob) { |
| 210 | let shared = Arc::clone(job.shared()); | 179 | let shared = Arc::clone(job.shared()); |
| 211 | - let outcome = catch_unwind(AssertUnwindSafe(|| -> Result<Option<u64>> { | 180 | + let outcome = catch_unwind(AssertUnwindSafe(|| -> Result<()> { |
| 212 | loop { | 181 | loop { |
| 213 | let msg = rx.recv(); | 182 | let msg = rx.recv(); |
| 214 | let Ok(msg) = msg else { break }; | 183 | let Ok(msg) = msg else { break }; |
| 215 | match msg { | 184 | match msg { |
| 216 | Msg::Slice(slice) => job.run_slice(*slice)?, | 185 | Msg::Slice(slice) => job.run_slice(*slice)?, |
| 217 | Msg::Finish => { | 186 | Msg::Finish => { |
| 218 | - let sum = job.finish(); | 187 | + job.finish(); |
| 219 | - return Ok(sum); | 188 | + return Ok(()); |
| 220 | } | 189 | } |
| 221 | } | 190 | } |
| 222 | } | 191 | } |
| @@ -225,14 +194,8 @@ fn run_worker(rx: Receiver<Msg>, mut job: PicJob, checksum: Arc<Checksum>) { | |||
| 225 | )) | 194 | )) |
| 226 | })); | 195 | })); |
| 227 | match outcome { | 196 | match outcome { |
| 228 | - Ok(Ok(sum)) => checksum.set(sum), | 197 | + Ok(Ok(())) => {} |
| 229 | - Ok(Err(e)) => { | 198 | + Ok(Err(e)) => shared.fail(&e.to_string()), |
| 230 | - shared.fail(&e.to_string()); | 199 | + Err(_) => shared.fail("HEVC decode: the picture's worker thread panicked"), |
| 231 | - checksum.set(None); | ||
| 232 | - } | ||
| 233 | - Err(_) => { | ||
| 234 | - shared.fail("HEVC decode: the picture's worker thread panicked"); | ||
| 235 | - checksum.set(None); | ||
| 236 | - } | ||
| 237 | } | 200 | } |
| 238 | } | 201 | } |
crates/ec-h265/src/dec/sao.rsmodified+1 -4
| @@ -40,9 +40,6 @@ pub fn sao_picture(pic: &mut PicState) { | |||
| 40 | /// in parallel. A band reads the deblocked input (shared, read-only) and writes only | 40 | /// in parallel. A band reads the deblocked input (shared, read-only) and writes only |
| 41 | /// its own rows of the output, so the bands never touch the same sample. | 41 | /// its own rows of the output, so the bands never touch the same sample. |
| 42 | pub fn sao_picture_threads(pic: &mut PicState, threads: usize) { | 42 | pub fn sao_picture_threads(pic: &mut PicState, threads: usize) { |
| 43 | - if !pic.has_pixels() { | ||
| 44 | - return; | ||
| 45 | - } | ||
| 46 | let ro: &PicState = pic; | 43 | let ro: &PicState = pic; |
| 47 | let y = filter_plane(ro, 0, &ro.planes.y, threads); | 44 | let y = filter_plane(ro, 0, &ro.planes.y, threads); |
| 48 | let cb = filter_plane(ro, 1, &ro.planes.cb, threads); | 45 | let cb = filter_plane(ro, 1, &ro.planes.cb, threads); |
| @@ -362,7 +359,7 @@ mod tests { | |||
| 362 | 359 | ||
| 363 | /// A 16x16 8-bit picture with one 16x16 CTB and no slices. | 360 | /// A 16x16 8-bit picture with one 16x16 CTB and no slices. |
| 364 | fn picture() -> PicState { | 361 | fn picture() -> PicState { |
| 365 | - PicState::new(16, 16, 4, 2, 8, 8, true) | 362 | + PicState::new(16, 16, 4, 2, 8, 8) |
| 366 | } | 363 | } |
| 367 | 364 | ||
| 368 | /// SAO parameters for the luma component only. | 365 | /// SAO parameters for the luma component only. |
crates/ec-h265/src/dec/shared.rsmodified+13 -28
| @@ -55,41 +55,26 @@ fn lock<T>(m: &Mutex<T>) -> MutexGuard<'_, T> { | |||
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | impl SharedPic { | 57 | impl SharedPic { |
| 58 | - /// The storage of a `width` by `height` picture of POC `poc`. With `pixels` | 58 | + /// The storage of a `width` by `height` picture of POC `poc`. |
| 59 | - /// false no sample planes are allocated (the motion-only decode). | ||
| 60 | pub fn new( | 59 | pub fn new( |
| 61 | poc: i32, | 60 | poc: i32, |
| 62 | width: usize, | 61 | width: usize, |
| 63 | height: usize, | 62 | height: usize, |
| 64 | bit_depth: (u32, u32), | 63 | bit_depth: (u32, u32), |
| 65 | - pixels: bool, | ||
| 66 | chroma_format_idc: u32, | 64 | chroma_format_idc: u32, |
| 67 | ) -> SharedPic { | 65 | ) -> SharedPic { |
| 68 | - let planes = if pixels { | 66 | + let (sx, sy) = crate::decode::chroma_shifts(chroma_format_idc); |
| 69 | - let (sx, sy) = crate::decode::chroma_shifts(chroma_format_idc); | 67 | + let cw = width.div_ceil(1 << sx); |
| 70 | - let cw = width.div_ceil(1 << sx); | 68 | + let ch = height.div_ceil(1 << sy); |
| 71 | - let ch = height.div_ceil(1 << sy); | 69 | + let planes = DecodedPicture { |
| 72 | - DecodedPicture { | 70 | + width, |
| 73 | - width, | 71 | + height, |
| 74 | - height, | 72 | + bit_depth: bit_depth.0, |
| 75 | - bit_depth: bit_depth.0, | 73 | + bit_depth_c: bit_depth.1, |
| 76 | - bit_depth_c: bit_depth.1, | 74 | + chroma_format_idc, |
| 77 | - chroma_format_idc, | 75 | + y: vec![0; width * height], |
| 78 | - y: vec![0; width * height], | 76 | + cb: vec![0; cw * ch], |
| 79 | - cb: vec![0; cw * ch], | 77 | + cr: vec![0; cw * ch], |
| 80 | - cr: vec![0; cw * ch], | ||
| 81 | - } | ||
| 82 | - } else { | ||
| 83 | - DecodedPicture { | ||
| 84 | - width, | ||
| 85 | - height, | ||
| 86 | - bit_depth: 8, | ||
| 87 | - bit_depth_c: 8, | ||
| 88 | - chroma_format_idc, | ||
| 89 | - y: Vec::new(), | ||
| 90 | - cb: Vec::new(), | ||
| 91 | - cr: Vec::new(), | ||
| 92 | - } | ||
| 93 | }; | 78 | }; |
| 94 | SharedPic { | 79 | SharedPic { |
| 95 | width, | 80 | width, |
crates/ec-h265/src/decode.rsmodified+1 -28
| @@ -51,10 +51,7 @@ impl DecodedPicture { | |||
| 51 | let (sx, sy) = self.chroma_shifts(); | 51 | let (sx, sy) = self.chroma_shifts(); |
| 52 | (self.width.div_ceil(1 << sx), self.height.div_ceil(1 << sy)) | 52 | (self.width.div_ceil(1 << sx), self.height.div_ceil(1 << sy)) |
| 53 | } | 53 | } |
| 54 | - /// A picture of mid-grey samples (`1 << (bit_depth - 1)`). | 54 | + |
| 55 | - pub fn grey(width: usize, height: usize, bit_depth: u32) -> DecodedPicture { | ||
| 56 | - Self::grey_planes(width, height, bit_depth, bit_depth) | ||
| 57 | - } | ||
| 58 | 55 | ||
| 59 | /// A picture of mid-grey samples, each plane at its own bit depth. | 56 | /// A picture of mid-grey samples, each plane at its own bit depth. |
| 60 | pub fn grey_planes( | 57 | pub fn grey_planes( |
| @@ -62,16 +59,6 @@ impl DecodedPicture { | |||
| 62 | height: usize, | 59 | height: usize, |
| 63 | bit_depth: u32, | 60 | bit_depth: u32, |
| 64 | bit_depth_c: u32, | 61 | bit_depth_c: u32, |
| 65 | - ) -> DecodedPicture { | ||
| 66 | - Self::grey_planes_fmt(width, height, bit_depth, bit_depth_c, 1) | ||
| 67 | - } | ||
| 68 | - | ||
| 69 | - /// [`Self::grey_planes`] for any `chroma_format_idc`. | ||
| 70 | - pub fn grey_planes_fmt( | ||
| 71 | - width: usize, | ||
| 72 | - height: usize, | ||
| 73 | - bit_depth: u32, | ||
| 74 | - bit_depth_c: u32, | ||
| 75 | chroma_format_idc: u32, | 62 | chroma_format_idc: u32, |
| 76 | ) -> DecodedPicture { | 63 | ) -> DecodedPicture { |
| 77 | let mid = 1u16 << (bit_depth - 1); | 64 | let mid = 1u16 << (bit_depth - 1); |
| @@ -89,20 +76,6 @@ impl DecodedPicture { | |||
| 89 | cr: vec![mid_c; cw * ch], | 76 | cr: vec![mid_c; cw * ch], |
| 90 | } | 77 | } |
| 91 | } | 78 | } |
| 92 | - | ||
| 93 | - /// The bit depth of component `c` (0 luma, 1 and 2 chroma). | ||
| 94 | - pub fn bit_depth_of(&self, c: usize) -> u32 { | ||
| 95 | - if c == 0 { | ||
| 96 | - self.bit_depth | ||
| 97 | - } else { | ||
| 98 | - self.bit_depth_c | ||
| 99 | - } | ||
| 100 | - } | ||
| 101 | - | ||
| 102 | - /// The luma plane as 8-bit samples. Only meaningful for 8-bit pictures. | ||
| 103 | - pub fn y_u8(&self) -> Vec<u8> { | ||
| 104 | - self.y.iter().map(|&v| v as u8).collect() | ||
| 105 | - } | ||
| 106 | } | 79 | } |
| 107 | 80 | ||
| 108 | /// Decode one IDR access unit: VPS/SPS/PPS/slice NALs in Annex-B framing, one | 81 | /// Decode one IDR access unit: VPS/SPS/PPS/slice NALs in Annex-B framing, one |
crates/ec-h265/src/enc_p.rsmodified+2 -2
| @@ -577,7 +577,7 @@ impl<'a> PCoder<'a> { | |||
| 577 | bit_depth: bd, | 577 | bit_depth: bd, |
| 578 | }, | 578 | }, |
| 579 | ]; | 579 | ]; |
| 580 | - let mut pic = PicState::new(w, h, ctb_log2, 2, bd, bd, true); | 580 | + let mut pic = PicState::new(w, h, ctb_log2, 2, bd, bd); |
| 581 | pic.strong_intra_smoothing = true; // as the sequence parameter set says | 581 | pic.strong_intra_smoothing = true; // as the sequence parameter set says |
| 582 | pic.slices = vec![SliceFilter { | 582 | pic.slices = vec![SliceFilter { |
| 583 | deblock_disabled: !enc.cfg.deblock, | 583 | deblock_disabled: !enc.cfg.deblock, |
| @@ -1835,7 +1835,7 @@ pub(crate) fn code_p_picture( | |||
| 1835 | true, | 1835 | true, |
| 1836 | ); | 1836 | ); |
| 1837 | write_annex_b(&mut au, NalHeader::new(NalUnitType::TrailR), &rbsp, true); | 1837 | write_annex_b(&mut au, NalHeader::new(NalUnitType::TrailR), &rbsp, true); |
| 1838 | - let shared = Arc::new(SharedPic::new(poc, w, h, (8, 8), false, 1)); | 1838 | + let shared = Arc::new(SharedPic::new(poc, w, h, (8, 8), 1)); |
| 1839 | shared.publish_col(&field, h); | 1839 | shared.publish_col(&field, h); |
| 1840 | Ok((au, recon, PrevPic { field, shared })) | 1840 | Ok((au, recon, PrevPic { field, shared })) |
| 1841 | } | 1841 | } |
crates/ec-h265/src/encoder.rsmodified+3 -3
| @@ -989,9 +989,9 @@ impl Encoder { | |||
| 989 | true, | 989 | true, |
| 990 | ); | 990 | ); |
| 991 | if let Some(rbsp) = | 991 | if let Some(rbsp) = |
| 992 | - sei::hdr_metadata_rbsp_with(self.cfg.mastering_display, self.cfg.content_light) | 992 | + sei::hdr_metadata_rbsp(self.cfg.mastering_display, self.cfg.content_light) |
| 993 | { | 993 | { |
| 994 | - write_annex_b(&mut au, sei::prefix_sei_header(), &rbsp, true); | 994 | + write_annex_b(&mut au, NalHeader::new(NalUnitType::PrefixSei), &rbsp, true); |
| 995 | } | 995 | } |
| 996 | 996 | ||
| 997 | // Entry points count the bytes as they appear in the NAL, emulation | 997 | // Entry points count the bytes as they appear in the NAL, emulation |
| @@ -1033,7 +1033,7 @@ impl Encoder { | |||
| 1033 | (&bcb, w / 2 * bps, w / 2 * bps, h / 2), | 1033 | (&bcb, w / 2 * bps, w / 2 * bps, h / 2), |
| 1034 | (&bcr, w / 2 * bps, w / 2 * bps, h / 2), | 1034 | (&bcr, w / 2 * bps, w / 2 * bps, h / 2), |
| 1035 | ]); | 1035 | ]); |
| 1036 | - write_annex_b(&mut au, sei::suffix_sei_header(), &rbsp, false); | 1036 | + write_annex_b(&mut au, NalHeader::new(NalUnitType::SuffixSei), &rbsp, false); |
| 1037 | } | 1037 | } |
| 1038 | au | 1038 | au |
| 1039 | } | 1039 | } |
crates/ec-h265/src/transform.rsmodified+0 -7
| @@ -686,13 +686,6 @@ pub fn dequantize_bd(levels: &[i32], scaled: &mut [i32], n: usize, qp: i32, bit_ | |||
| 686 | dequantize_weighted(levels, scaled, n, qp, bit_depth, None); | 686 | dequantize_weighted(levels, scaled, n, qp, bit_depth, None); |
| 687 | } | 687 | } |
| 688 | 688 | ||
| 689 | -/// [`dequantize`] with a scaling matrix (8.6.4.2): `m` is the block's | ||
| 690 | -/// `ScalingFactor` in raster order, or `None` for the flat 16 that a stream | ||
| 691 | -/// without scaling lists (or a transform-skipped block larger than 4x4) uses. | ||
| 692 | -pub fn dequantize_with(levels: &[i32], scaled: &mut [i32], n: usize, qp: i32, m: Option<&[u8]>) { | ||
| 693 | - dequantize_weighted(levels, scaled, n, qp, 8, m); | ||
| 694 | -} | ||
| 695 | - | ||
| 696 | /// The loop behind every dequantize entry point: one block at `bit_depth`, with | 689 | /// The loop behind every dequantize entry point: one block at `bit_depth`, with |
| 697 | /// the weight matrix `m` (or flat 16 for `None`). | 690 | /// the weight matrix `m` (or flat 16 for `None`). |
| 698 | pub fn dequantize_weighted( | 691 | pub fn dequantize_weighted( |
crates/ec-h265/tests/it/common.rsmodified+8 -3
| @@ -192,9 +192,14 @@ pub fn pin_or_panic(site: &str, path: &std::path::Path, bytes: &[u8]) { | |||
| 192 | 192 | ||
| 193 | pub const PLANE_NAMES: [&str; 3] = ["Y", "Cb", "Cr"]; | 193 | pub const PLANE_NAMES: [&str; 3] = ["Y", "Cb", "Cr"]; |
| 194 | 194 | ||
| 195 | +/// The bit depth of component `c` (0 luma, 1 and 2 chroma). | ||
| 196 | +pub fn bit_depth_of(pic: &DecodedPicture, c: usize) -> u32 { | ||
| 197 | + if c == 0 { pic.bit_depth } else { pic.bit_depth_c } | ||
| 198 | +} | ||
| 199 | + | ||
| 195 | /// Bytes per sample of component `c`: 1 for 8-bit, 2 (little endian) above 8 bits. | 200 | /// Bytes per sample of component `c`: 1 for 8-bit, 2 (little endian) above 8 bits. |
| 196 | pub fn bytes_per_sample(pic: &DecodedPicture, c: usize) -> usize { | 201 | pub fn bytes_per_sample(pic: &DecodedPicture, c: usize) -> usize { |
| 197 | - if pic.bit_depth_of(c) > 8 { 2 } else { 1 } | 202 | + if bit_depth_of(pic, c) > 8 { 2 } else { 1 } |
| 198 | } | 203 | } |
| 199 | 204 | ||
| 200 | /// The samples of a picture cropped to its conformance window, as the bytes a YUV | 205 | /// The samples of a picture cropped to its conformance window, as the bytes a YUV |
| @@ -424,7 +429,7 @@ pub fn plane_matches(pic: &DecodedPicture, expected: &PictureHash) -> Vec<bool> | |||
| 424 | .map(|(i, &w)| { | 429 | .map(|(i, &w)| { |
| 425 | planes | 430 | planes |
| 426 | .get(i) | 431 | .get(i) |
| 427 | - .is_some_and(|p| plane_crc(p, pic.bit_depth_of(i)) == w) | 432 | + .is_some_and(|p| plane_crc(p, bit_depth_of(pic, i)) == w) |
| 428 | }) | 433 | }) |
| 429 | .collect(), | 434 | .collect(), |
| 430 | PictureHash::Checksum(want) => want | 435 | PictureHash::Checksum(want) => want |
| @@ -433,7 +438,7 @@ pub fn plane_matches(pic: &DecodedPicture, expected: &PictureHash) -> Vec<bool> | |||
| 433 | .map(|(i, &w)| { | 438 | .map(|(i, &w)| { |
| 434 | planes | 439 | planes |
| 435 | .get(i) | 440 | .get(i) |
| 436 | - .is_some_and(|p| plane_checksum(p, dims[i].0, pic.bit_depth_of(i)) == w) | 441 | + .is_some_and(|p| plane_checksum(p, dims[i].0, bit_depth_of(pic, i)) == w) |
| 437 | }) | 442 | }) |
| 438 | .collect(), | 443 | .collect(), |
| 439 | } | 444 | } |
crates/ec-h265/tests/it/rext_generated.rsmodified+3 -1
| @@ -7,6 +7,8 @@ use std::path::Path; | |||
| 7 | use ec_h265::Decoder; | 7 | use ec_h265::Decoder; |
| 8 | use ec_h265_syntax::md5::Md5; | 8 | use ec_h265_syntax::md5::Md5; |
| 9 | 9 | ||
| 10 | +use crate::common::bit_depth_of; | ||
| 11 | + | ||
| 10 | fn hex(d: [u8; 16]) -> String { | 12 | fn hex(d: [u8; 16]) -> String { |
| 11 | d.iter().map(|b| format!("{b:02x}")).collect() | 13 | d.iter().map(|b| format!("{b:02x}")).collect() |
| 12 | } | 14 | } |
| @@ -67,7 +69,7 @@ fn output_md5(data: &[u8]) -> Result<(String, usize), String> { | |||
| 67 | if plane.is_empty() { | 69 | if plane.is_empty() { |
| 68 | continue; | 70 | continue; |
| 69 | } | 71 | } |
| 70 | - let wide = p.bit_depth_of(c) > 8; | 72 | + let wide = bit_depth_of(p, c) > 8; |
| 71 | let mut bytes = Vec::new(); | 73 | let mut bytes = Vec::new(); |
| 72 | for y in y0..y1 { | 74 | for y in y0..y1 { |
| 73 | for x in x0..x1 { | 75 | for x in x0..x1 { |