| 1 | |
| 2 | |
| 3 | use ec_av1_syntax::NUM_REF_FRAMES; |
| 4 | |
| 5 | |
| 6 | #[derive(Debug, Clone)] |
| 7 | pub(crate) struct RefSlots<S> { |
| 8 | slots: [Option<S>; NUM_REF_FRAMES], |
| 9 | } |
| 10 | |
| 11 | impl<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 | |
| 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 | } |