forge
Explore
Log in

Don't you dare go Hollow

ec-hw: H.264 DPB generic over the surface type and ungated (dpb264.rs, h264_common.rs), for the Vulkan decoder

Browse files at this commit

c58ee896b647127ec129183d994ae91fc18d3fe8Ahmet Kaan GümüşParent: e98bba9
crates/ec-hw/src/dec/h264.rsmodified+5 -28
@@ -10,10 +10,11 @@ use ec_h264_syntax::{
1010 use ec_va::caps::Profile;
1111 use ec_va::{Buffer, Display};
1212
13-use super::dpb264::{Dpb, Mark, PicInfo, Picture, Poc, RefList};
1413 use super::{ReadyFrames, Session, StreamInfo};
14+use crate::dpb264::{self, Mark, PicInfo, Poc, RefList};
1515 use crate::error::{Error, Result};
1616 use crate::frame::{Colour, Frame};
17+use crate::h264_common::{peek_pps_id, vui_colour_tags};
1718 use crate::params::h264::{
1819 IQMatrixBufferH264, PICTURE_LONG_TERM_REFERENCE, PICTURE_SHORT_TERM_REFERENCE, PicFields,
1920 PictureParameterBufferH264, SeqFields, SliceParameterBufferH264, VAPictureH264,
@@ -75,6 +76,9 @@ struct Current {
7576 ref_padded: bool,
7677 }
7778
79+type Dpb = dpb264::Dpb<Rc<PooledSurface>>;
80+type Picture = dpb264::Picture<Rc<PooledSurface>>;
81+
7882 /// A stateless H.264 decoder.
7983 pub struct H264Decoder {
8084 display: Rc<Display>,
@@ -489,33 +493,6 @@ impl H264Decoder {
489493 }
490494 }
491495
492-/// An SPS's VUI `colour_description` and range flag, as [`Tags`] for
493-/// [`ColorDescription::resolve`]. [`Tags::default()`] when the VUI has no
494-/// `video_signal_type` at all.
495-fn vui_colour_tags(sps: &Sps) -> Tags {
496- let Some(vui) = &sps.vui else {
497- return Tags::default();
498- };
499- if vui.video_format.is_none() {
500- return Tags::default();
501- }
502- let (_primaries, transfer, matrix) = vui.colour_description.unwrap_or((0, 0, 0));
503- Tags::from_codes(
504- u64::from(matrix),
505- u64::from(transfer),
506- if vui.video_full_range { 2 } else { 1 },
507- )
508-}
509-
510-/// The `pic_parameter_set_id` of a slice header, which is the second syntax
511-/// element and needs no parameter set to read.
512-fn peek_pps_id(rbsp: &[u8]) -> Result<u32> {
513- let mut r = ec_core::BitReader::new(rbsp);
514- r.read_ue()?; // first_mb_in_slice
515- r.read_ue()?; // slice_type
516- Ok(r.read_ue()?)
517-}
518-
519496 /// The VA profile for a stream, from its SPS.
520497 fn profile_for(sps: &Sps) -> Result<Profile> {
521498 Ok(match sps.profile_idc {
crates/ec-hw/src/dec/mod.rsmodified+0 -1
@@ -33,7 +33,6 @@ use crate::pool::SurfacePool;
3333 pub use crate::types::Codec;
3434
3535 mod av1;
36-mod dpb264;
3736 mod h264;
3837 mod vp9;
3938
crates/ec-hw/src/dec/dpb264.rs → crates/ec-hw/src/dpb264.rsrenamed+13 -14
@@ -7,12 +7,9 @@
77 //! told the whole buffer on every picture, so these lists are the parameter
88 //! buffer's contents rather than an internal detail.
99
10-use std::rc::Rc;
11-
1210 use ec_h264_syntax::{DecRefPicMarking, RefPicListMod, SliceType, Sps};
1311
1412 use crate::error::{Error, Result};
15-use crate::pool::PooledSurface;
1613
1714 /// Maximum pictures held at once (Annex A caps the DPB at 16 frames; the extra
1815 /// slot is the picture being decoded).
@@ -30,11 +27,11 @@ pub(crate) enum Mark {
3027 }
3128
3229 /// One picture in the buffer.
33-pub(crate) struct Picture {
30+pub(crate) struct Picture<S> {
3431 /// Identity, so "the picture just stored" survives reordering.
3532 pub id: i32,
3633 /// The surface it decoded into.
37- pub surface: Rc<PooledSurface>,
34+ pub surface: S,
3835 /// Presentation timestamp of the access unit it came from.
3936 pub timestamp: i64,
4037 /// `frame_num`.
@@ -62,7 +59,7 @@ pub(crate) struct Picture {
6259 pub output: bool,
6360 }
6461
65-impl Picture {
62+impl<S> Picture<S> {
6663 fn stored(&self) -> bool {
6764 self.output || self.mark != Mark::Unused
6865 }
@@ -124,8 +121,8 @@ pub(crate) struct PicInfo {
124121 }
125122
126123 /// The decoded picture buffer and the cross-picture state of clause 8.2.
127-pub(crate) struct Dpb {
128- pub frames: Vec<Picture>,
124+pub(crate) struct Dpb<S> {
125+ pub frames: Vec<Picture<S>>,
129126 next_id: i32,
130127 max_frames: usize,
131128 max_reorder: usize,
@@ -141,8 +138,8 @@ pub(crate) struct Dpb {
141138 last_id: i32,
142139 }
143140
144-impl Default for Dpb {
145- fn default() -> Dpb {
141+impl<S> Default for Dpb<S> {
142+ fn default() -> Dpb<S> {
146143 Dpb {
147144 frames: Vec::new(),
148145 next_id: 0,
@@ -162,7 +159,7 @@ impl Default for Dpb {
162159 }
163160 }
164161
165-impl Dpb {
162+impl<S: Clone> Dpb<S> {
166163 /// Adopt the buffer limits of `sps` (Annex A / VUI).
167164 pub(crate) fn configure(&mut self, sps: &Sps) {
168165 let level_frames = max_dpb_frames(sps);
@@ -335,7 +332,7 @@ impl Dpb {
335332 .frames
336333 .iter()
337334 .max_by_key(|p| p.frame_num_wrap)
338- .map(|p| Rc::clone(&p.surface))
335+ .map(|p| p.surface.clone())
339336 else {
340337 // Nothing decoded yet: there is no picture to stand in for the
341338 // missing ones, and the next IDR will resynchronise anyway.
@@ -597,7 +594,7 @@ impl Dpb {
597594 /// a reference and for bookkeeping, but must never be handed to a caller.
598595 pub(crate) fn store(
599596 &mut self,
600- mut pic: Picture,
597+ mut pic: Picture<S>,
601598 sps: &Sps,
602599 info: &PicInfo,
603600 marking: Option<&DecRefPicMarking>,
@@ -699,7 +696,7 @@ impl Dpb {
699696 /// Adaptive marking (8.2.5.4).
700697 fn apply_mmco(
701698 &mut self,
702- pic: &mut Picture,
699+ pic: &mut Picture<S>,
703700 m: &DecRefPicMarking,
704701 info: &PicInfo,
705702 ) -> Result<()> {
@@ -878,6 +875,8 @@ pub(crate) fn gap_frame_nums(prev_ref: u32, frame_num: u32, max: u32) -> impl It
878875 mod tests {
879876 use super::*;
880877
878+ type Dpb = super::Dpb<u32>;
879+
881880 fn sps_for(poc_type: u8) -> Sps {
882881 let mut sps = Sps {
883882 profile_idc: 100,
crates/ec-hw/src/h264_common.rsadded+31 -0
@@ -0,0 +1,31 @@
1+use ec_core::color::Tags;
2+use ec_h264_syntax::Sps;
3+
4+use crate::error::Result;
5+
6+/// An SPS's VUI `colour_description` and range flag, as [`Tags`] for
7+/// [`ec_core::color::ColorDescription::resolve`]. [`Tags::default()`] when the VUI has no
8+/// `video_signal_type` at all.
9+pub(crate) fn vui_colour_tags(sps: &Sps) -> Tags {
10+ let Some(vui) = &sps.vui else {
11+ return Tags::default();
12+ };
13+ if vui.video_format.is_none() {
14+ return Tags::default();
15+ }
16+ let (_primaries, transfer, matrix) = vui.colour_description.unwrap_or((0, 0, 0));
17+ Tags::from_codes(
18+ u64::from(matrix),
19+ u64::from(transfer),
20+ if vui.video_full_range { 2 } else { 1 },
21+ )
22+}
23+
24+/// The `pic_parameter_set_id` of a slice header, which is the second syntax
25+/// element and needs no parameter set to read.
26+pub(crate) fn peek_pps_id(rbsp: &[u8]) -> Result<u32> {
27+ let mut r = ec_core::BitReader::new(rbsp);
28+ r.read_ue()?; // first_mb_in_slice
29+ r.read_ue()?; // slice_type
30+ Ok(r.read_ue()?)
31+}
crates/ec-hw/src/lib.rsmodified+4 -0
@@ -59,6 +59,10 @@ pub mod dec;
5959 #[cfg(target_os = "linux")]
6060 pub mod enc;
6161 pub mod error;
62+#[cfg_attr(not(target_os = "linux"), allow(dead_code))]
63+pub(crate) mod dpb264;
64+#[cfg_attr(not(target_os = "linux"), allow(dead_code))]
65+pub(crate) mod h264_common;
6266 pub mod hw;
6367 #[cfg(target_os = "linux")]
6468 pub mod frame;