forge
Explore
Log in

Don't you dare go Hollow

S2: packed header kind is a PackedKind enum, not u32 constants; the unknown-kind error arm is gone with it

Browse files at this commit

8c693a296e816e8f885dcb20492a915da359370dAhmet Kaan GümüşParent: 4fd4ed4
crates/ec-hw/src/enc/headers.rsmodified+20 -22
@@ -10,12 +10,12 @@
10 //! driver was given, or the header describes a picture other than the one the10 //! driver was given, or the header describes a picture other than the one the
11 //! hardware coded.11 //! hardware coded.
12 12
13-/// `VAEncPackedHeaderSequence`: packed sequence-level header bits.13+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
14-pub const PACKED_HEADER_SEQUENCE: u32 = 1;14+pub(crate) enum PackedKind {
15-/// `VAEncPackedHeaderPicture`: packed picture-level header bits.15+ Sequence,
16-pub const PACKED_HEADER_PICTURE: u32 = 2;16+ Picture,
17-/// `VAEncPackedHeaderSlice`: packed slice-level header bits.17+ Slice,
18-pub const PACKED_HEADER_SLICE: u32 = 3;18+}
19 19
20 use ec_core::BitWriter;20 use ec_core::BitWriter;
21 21
@@ -26,13 +26,13 @@ use super::Colour;
26 /// The bit length matters for slice headers, which do not end on a byte26 /// The bit length matters for slice headers, which do not end on a byte
27 /// boundary — the driver continues the bitstream from exactly that bit.27 /// boundary — the driver continues the bitstream from exactly that bit.
28 pub(crate) struct Packed {28 pub(crate) struct Packed {
29- pub(crate) kind: u32,29+ pub(crate) kind: PackedKind,
30 pub(crate) bytes: Vec<u8>,30 pub(crate) bytes: Vec<u8>,
31 pub(crate) bits: u32,31 pub(crate) bits: u32,
32 }32 }
33 33
34 /// Wrap a complete NAL: start code, header byte(s), escaped payload.34 /// Wrap a complete NAL: start code, header byte(s), escaped payload.
35-fn nal(kind: u32, header: &[u8], rbsp: &[u8], padding_bits: u32) -> Packed {35+fn nal(kind: PackedKind, header: &[u8], rbsp: &[u8], padding_bits: u32) -> Packed {
36 let mut bytes = vec![0, 0, 0, 1];36 let mut bytes = vec![0, 0, 0, 1];
37 bytes.extend_from_slice(header);37 bytes.extend_from_slice(header);
38 let mut escaped = Vec::with_capacity(rbsp.len() + 8);38 let mut escaped = Vec::with_capacity(rbsp.len() + 8);
@@ -133,7 +133,7 @@ pub(super) fn h264_sps(p: &H264Params) -> Packed {
133 w.write_ue(0); // max_num_reorder_frames133 w.write_ue(0); // max_num_reorder_frames
134 w.write_ue(1); // max_dec_frame_buffering = max_num_ref_frames134 w.write_ue(1); // max_dec_frame_buffering = max_num_ref_frames
135 trailing(&mut w);135 trailing(&mut w);
136- nal(PACKED_HEADER_SEQUENCE, &[0x67], &w.into_bytes(), 0)136+ nal(PackedKind::Sequence, &[0x67], &w.into_bytes(), 0)
137 }137 }
138 138
139 /// The picture parameter set (7.3.2.2).139 /// The picture parameter set (7.3.2.2).
@@ -160,7 +160,7 @@ pub(super) fn h264_pps(p: &H264Params) -> Packed {
160 w.write_se(0); // second_chroma_qp_index_offset160 w.write_se(0); // second_chroma_qp_index_offset
161 }161 }
162 trailing(&mut w);162 trailing(&mut w);
163- nal(PACKED_HEADER_PICTURE, &[0x68], &w.into_bytes(), 0)163+ nal(PackedKind::Picture, &[0x68], &w.into_bytes(), 0)
164 }164 }
165 165
166 /// The slice header (7.3.3), up to but *not* including the slice data.166 /// The slice header (7.3.3), up to but *not* including the slice data.
@@ -202,7 +202,7 @@ pub(super) fn h264_slice_header(idr: bool, frame_num: u32, idr_pic_id: u32) -> P
202 let padding = (8 - bits % 8) % 8;202 let padding = (8 - bits % 8) % 8;
203 w.align_to_byte();203 w.align_to_byte();
204 let header = if idr { 0x65 } else { 0x61 };204 let header = if idr { 0x65 } else { 0x61 };
205- nal(PACKED_HEADER_SLICE, &[header], &w.into_bytes(), padding)205+ nal(PackedKind::Slice, &[header], &w.into_bytes(), padding)
206 }206 }
207 207
208 /// `rbsp_trailing_bits` (7.3.2.11).208 /// `rbsp_trailing_bits` (7.3.2.11).
@@ -220,8 +220,7 @@ fn trailing(w: &mut BitWriter) {
220 /// The syntax crate writes all four structures, so the encoder and the software220 /// The syntax crate writes all four structures, so the encoder and the software
221 /// HEVC path in this family share one definition of what a parameter set is.221 /// HEVC path in this family share one definition of what a parameter set is.
222 pub(super) mod hevc {222 pub(super) mod hevc {
223- #[allow(unused_imports)]223+ use super::PackedKind;
224- use super::{PACKED_HEADER_PICTURE, PACKED_HEADER_SEQUENCE, PACKED_HEADER_SLICE};
225 use ec_h265_syntax::{224 use ec_h265_syntax::{
226 ConformanceWindow, NalHeader, NalUnitType, Pps, ProfileTierLevel, ShortTermRefPicSet,225 ConformanceWindow, NalHeader, NalUnitType, Pps, ProfileTierLevel, ShortTermRefPicSet,
227 SliceHeader, SliceType, Sps, Vps,226 SliceHeader, SliceType, Sps, Vps,
@@ -350,7 +349,7 @@ pub(super) mod hevc {
350 349
351 pub(in crate::enc) fn packed_vps(vps: &Vps) -> Packed {350 pub(in crate::enc) fn packed_vps(vps: &Vps) -> Packed {
352 nal(351 nal(
353- PACKED_HEADER_SEQUENCE,352+ PackedKind::Sequence,
354 &NalHeader::new(NalUnitType::Vps).to_bytes(),353 &NalHeader::new(NalUnitType::Vps).to_bytes(),
355 &vps.to_rbsp(),354 &vps.to_rbsp(),
356 0,355 0,
@@ -359,7 +358,7 @@ pub(super) mod hevc {
359 358
360 pub(in crate::enc) fn packed_sps(sps: &Sps) -> Packed {359 pub(in crate::enc) fn packed_sps(sps: &Sps) -> Packed {
361 nal(360 nal(
362- PACKED_HEADER_SEQUENCE,361+ PackedKind::Sequence,
363 &NalHeader::new(NalUnitType::Sps).to_bytes(),362 &NalHeader::new(NalUnitType::Sps).to_bytes(),
364 &sps.to_rbsp(),363 &sps.to_rbsp(),
365 0,364 0,
@@ -368,7 +367,7 @@ pub(super) mod hevc {
368 367
369 pub(in crate::enc) fn packed_pps(pps: &Pps) -> Packed {368 pub(in crate::enc) fn packed_pps(pps: &Pps) -> Packed {
370 nal(369 nal(
371- PACKED_HEADER_PICTURE,370+ PackedKind::Picture,
372 &NalHeader::new(NalUnitType::Pps).to_bytes(),371 &NalHeader::new(NalUnitType::Pps).to_bytes(),
373 &pps.to_rbsp(),372 &pps.to_rbsp(),
374 0,373 0,
@@ -399,7 +398,7 @@ pub(super) mod hevc {
399 // alignment bit has to be in what it is given.398 // alignment bit has to be in what it is given.
400 header.write(&mut w, sps, pps, nal_type);399 header.write(&mut w, sps, pps, nal_type);
401 nal(400 nal(
402- PACKED_HEADER_SLICE,401+ PackedKind::Slice,
403 &NalHeader::new(nal_type).to_bytes(),402 &NalHeader::new(nal_type).to_bytes(),
404 &w.into_bytes(),403 &w.into_bytes(),
405 0,404 0,
@@ -422,8 +421,7 @@ pub(super) mod hevc {
422 /// syntax: a field written here that disagrees with the parameter buffer is a421 /// syntax: a field written here that disagrees with the parameter buffer is a
423 /// picture described two ways, and the driver believes this one.422 /// picture described two ways, and the driver believes this one.
424 pub(super) mod av1 {423 pub(super) mod av1 {
425- #[allow(unused_imports)]424+ use super::PackedKind;
426- use super::{PACKED_HEADER_PICTURE, PACKED_HEADER_SEQUENCE, PACKED_HEADER_SLICE};
427 use ec_core::BitWriter;425 use ec_core::BitWriter;
428 426
429 use super::{Colour, Packed};427 use super::{Colour, Packed};
@@ -438,7 +436,7 @@ pub(super) mod av1 {
438 const OBU_SIZE_BYTES: usize = 2;436 const OBU_SIZE_BYTES: usize = 2;
439 437
440 /// Wrap a payload as one OBU: header byte, fixed-width `obu_size`, payload.438 /// Wrap a payload as one OBU: header byte, fixed-width `obu_size`, payload.
441- fn obu(kind: u32, obu_type: u8, payload: Vec<u8>) -> Packed {439+ fn obu(kind: PackedKind, obu_type: u8, payload: Vec<u8>) -> Packed {
442 let mut bytes = Vec::with_capacity(payload.len() + 1 + OBU_SIZE_BYTES);440 let mut bytes = Vec::with_capacity(payload.len() + 1 + OBU_SIZE_BYTES);
443 // forbidden(0) type(4) extension(0) has_size(1) reserved(0)441 // forbidden(0) type(4) extension(0) has_size(1) reserved(0)
444 bytes.push(obu_type << 3 | 0b010);442 bytes.push(obu_type << 3 | 0b010);
@@ -538,7 +536,7 @@ pub(super) mod av1 {
538 w.write_bit(false); // separate_uv_delta_q536 w.write_bit(false); // separate_uv_delta_q
539 w.write_bit(false); // film_grain_params_present537 w.write_bit(false); // film_grain_params_present
540 trailing(&mut w);538 trailing(&mut w);
541- obu(PACKED_HEADER_SEQUENCE, 1, w.into_bytes())539+ obu(PackedKind::Sequence, 1, w.into_bytes())
542 }540 }
543 541
544 /// What one picture's uncompressed header says.542 /// What one picture's uncompressed header says.
@@ -649,7 +647,7 @@ pub(super) mod av1 {
649 }647 }
650 }648 }
651 trailing(&mut w);649 trailing(&mut w);
652- let packed = obu(PACKED_HEADER_PICTURE, 3, w.into_bytes());650+ let packed = obu(PackedKind::Picture, 3, w.into_bytes());
653 let offsets = FrameHeaderOffsets {651 let offsets = FrameHeaderOffsets {
654 qindex,652 qindex,
655 segmentation,653 segmentation,
crates/ec-hw/src/enc/mod.rsmodified+3 -6
@@ -593,12 +593,9 @@ impl Encoder {
593 out: &mut Vec<BufferType>,593 out: &mut Vec<BufferType>,
594 ) -> Result<()> {594 ) -> Result<()> {
595 let kind = match packed.kind {595 let kind = match packed.kind {
596- headers::PACKED_HEADER_SEQUENCE => EncPackedHeaderType::Sequence,596+ headers::PackedKind::Sequence => EncPackedHeaderType::Sequence,
597- headers::PACKED_HEADER_PICTURE => EncPackedHeaderType::Picture,597+ headers::PackedKind::Picture => EncPackedHeaderType::Picture,
598- headers::PACKED_HEADER_SLICE => EncPackedHeaderType::Slice,598+ headers::PackedKind::Slice => EncPackedHeaderType::Slice,
599- other => {
600- return Err(Error::config(format!("unknown packed header kind {other}")));
601- }
602 };599 };
603 out.push(BufferType::EncPackedHeaderParameter(600 out.push(BufferType::EncPackedHeaderParameter(
604 EncPackedHeaderParameter::new(kind, packed.bits, true),601 EncPackedHeaderParameter::new(kind, packed.bits, true),