forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

ref_slots.rs39 lines, 1.1 KiBHistoryRawDownload
1//! The eight reference slots (AV1 spec 7.20, VP9 spec 8.10), shared by the VA-API and Vulkan decoders.
2
3use ec_av1_syntax::NUM_REF_FRAMES;
4
5/// What each reference slot holds, generic over the decoder's picture type.
6#[derive(Debug, Clone)]
7pub(crate) struct RefSlots<S> {
8 slots: [Option<S>; NUM_REF_FRAMES],
9}
10
11impl<S: Clone> RefSlots<S> {
12 pub(crate) fn new() -> Self {
13 RefSlots {
14 slots: std::array::from_fn(|_| None),
15 }
16 }
17
18 pub(crate) fn get(&self, slot: usize) -> Option<&S> {
19 self.slots.get(slot)?.as_ref()
20 }
21
22 #[cfg_attr(not(target_os = "linux"), allow(dead_code))]
23 pub(crate) fn as_array(&self) -> &[Option<S>; NUM_REF_FRAMES] {
24 &self.slots
25 }
26
27 pub(crate) fn filled(&self) -> impl Iterator<Item = &S> {
28 self.slots.iter().flatten()
29 }
30
31 /// Store `value` in every slot named by the `refresh_frame_flags` bit mask.
32 pub(crate) fn refresh(&mut self, flags: u8, value: Option<S>) {
33 for (slot, entry) in self.slots.iter_mut().enumerate() {
34 if flags & (1 << slot) != 0 {
35 entry.clone_from(&value);
36 }
37 }
38 }
39}