diff --git a/crates/ec-hw/src/vkdec264.rs b/crates/ec-hw/src/vkdec264.rs index 3fb288f9..b428b754 100644 --- a/crates/ec-hw/src/vkdec264.rs +++ b/crates/ec-hw/src/vkdec264.rs @@ -91,6 +91,7 @@ impl VkH264Decoder { let header = NalHeader::parse(first)?; match header.unit_type { NalUnitType::Sps => { + self.finish_picture()?; let mut rbsp = std::mem::take(&mut self.rbsp); unescape_rbsp(payload, &mut rbsp); let sps = Sps::parse(&rbsp); @@ -233,11 +234,14 @@ impl VkH264Decoder { } let slots = (self.dpb.capacity() as u32 + 1).min(MAX_SLOTS); let (w, h) = (sps.coded_width, sps.coded_height); - let (max_width, max_height, slots) = match &self.session { - Some(s) if w <= s.max_width && h <= s.max_height && slots <= s.slots => return Ok(()), - Some(s) => (w.max(s.max_width), h.max(s.max_height), slots.max(s.slots)), - None => (w, h, slots), - }; + if let Some(s) = &self.session + && s.max_width == w + && s.max_height == h + && slots <= s.slots + { + return Ok(()); + } + self.bump(true); self.current = None; self.dpb.clear(); self.pics.clear(); @@ -245,8 +249,8 @@ impl VkH264Decoder { let h264 = H264DecodeSession::new( &self.gpu, &H264DecodeConfig { - max_width, - max_height, + max_width: w, + max_height: h, max_dpb_slots: slots, profile_idc: sps.profile_idc, }, @@ -255,8 +259,8 @@ impl VkH264Decoder { self.session = Some(Session { h264: Rc::new(RefCell::new(h264)), ring, - max_width, - max_height, + max_width: w, + max_height: h, slots, }); self.params_dirty = true; diff --git a/crates/ec-hw/src/vkdec265.rs b/crates/ec-hw/src/vkdec265.rs index e5e715d0..cb23fb32 100644 --- a/crates/ec-hw/src/vkdec265.rs +++ b/crates/ec-hw/src/vkdec265.rs @@ -95,6 +95,7 @@ impl VkH265Decoder { } } NalUnitType::Sps => { + self.finish_picture()?; let sps = Sps::parse(&nal.rbsp())?; self.dpb.max_reorder = sps.max_num_reorder_pics as usize; self.dpb.max_dec_pic_buffering = sps.max_dec_pic_buffering_minus1 as usize + 1; @@ -234,20 +235,15 @@ impl VkH265Decoder { sps.pic_width_in_luma_samples, sps.pic_height_in_luma_samples, ); - let (max_width, max_height, slots) = match &self.session { - Some(s) - if s.bit_depth == bit_depth - && w <= s.max_width - && h <= s.max_height - && slots <= s.slots => - { - return Ok(()); - } - Some(s) if s.bit_depth == bit_depth => { - (w.max(s.max_width), h.max(s.max_height), slots.max(s.slots)) - } - _ => (w, h, slots), - }; + if let Some(s) = &self.session + && s.bit_depth == bit_depth + && s.max_width == w + && s.max_height == h + && slots <= s.slots + { + return Ok(()); + } + self.bump(true); self.current = None; self.dpb.pictures.clear(); self.outputs.clear(); @@ -255,8 +251,8 @@ impl VkH265Decoder { let h265 = H265DecodeSession::new( &self.gpu, &H265DecodeConfig { - max_width, - max_height, + max_width: w, + max_height: h, max_dpb_slots: slots, bit_depth, }, @@ -266,8 +262,8 @@ impl VkH265Decoder { h265: Rc::new(RefCell::new(h265)), ring, bit_depth, - max_width, - max_height, + max_width: w, + max_height: h, slots, }); self.params_dirty = true; diff --git a/crates/ec-hw/src/vkdec_av1.rs b/crates/ec-hw/src/vkdec_av1.rs index 4482ee9a..2305652b 100644 --- a/crates/ec-hw/src/vkdec_av1.rs +++ b/crates/ec-hw/src/vkdec_av1.rs @@ -219,15 +219,11 @@ impl VkAv1Decoder { fn ensure_session(&mut self, seq: &SequenceHeader, width: u32, height: u32) -> Result<()> { let bit_depth = seq.color_config.bit_depth; + let width = seq.max_frame_width.max(width); + let height = seq.max_frame_height.max(height); let mut session = match self.session.take() { - Some(s) if s.bit_depth == bit_depth && width <= s.width && height <= s.height => s, - old => { - let (width, height) = match &old { - Some(s) if s.bit_depth == bit_depth => { - (width.max(s.width), height.max(s.height)) - } - _ => (width, height), - }; + Some(s) if s.bit_depth == bit_depth && s.width == width && s.height == height => s, + _ => { self.refs = RefSlots::new(); let av1 = Av1DecodeSession::new( &self.gpu,