pub mod stateless;
use std::collections::VecDeque;
use crate::DecodedFormat;
use crate::Resolution;
pub trait SurfacePool<M> {
fn coded_resolution(&self) -> Resolution;
fn set_coded_resolution(&mut self, resolution: Resolution);
fn add_surfaces(&mut self, descriptors: Vec<M>) -> Result<(), anyhow::Error>;
fn num_free_surfaces(&self) -> usize;
fn num_managed_surfaces(&self) -> usize;
fn clear(&mut self);
fn take_free_surface(&mut self) -> Option<Box<dyn AsRef<M>>>;
}
#[derive(Clone)]
pub struct StreamInfo {
pub format: DecodedFormat,
pub coded_resolution: Resolution,
pub display_resolution: Resolution,
pub min_num_surfaces: usize,
}
pub trait DecoderFormatNegotiator<'a, M> {
fn stream_info(&self) -> &StreamInfo;
fn surface_pool(&mut self) -> &mut dyn SurfacePool<M>;
fn try_format(&mut self, format: DecodedFormat) -> anyhow::Result<()>;
}
pub enum DecoderEvent<'a, M> {
FrameReady(Box<dyn DecodedHandle<Descriptor = M>>),
FormatChanged(Box<dyn DecoderFormatNegotiator<'a, M> + 'a>),
}
pub trait DynHandle {
fn dyn_mappable_handle<'a>(&'a self) -> anyhow::Result<Box<dyn MappableHandle + 'a>>;
}
pub trait MappableHandle {
fn read(&mut self, buffer: &mut [u8]) -> anyhow::Result<()>;
fn image_size(&mut self) -> usize;
}
pub trait DecodedHandle {
type Descriptor;
fn dyn_picture<'a>(&'a self) -> Box<dyn DynHandle + 'a>;
fn timestamp(&self) -> u64;
fn coded_resolution(&self) -> Resolution;
fn display_resolution(&self) -> Resolution;
fn is_ready(&self) -> bool;
fn sync(&self) -> anyhow::Result<()>;
fn resource(&self) -> std::cell::Ref<Self::Descriptor>;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BlockingMode {
Blocking,
NonBlocking,
}
impl Default for BlockingMode {
fn default() -> Self {
Self::Blocking
}
}
struct ReadyFramesQueue<T> {
queue: VecDeque<T>,
}
impl<T> Default for ReadyFramesQueue<T> {
fn default() -> Self {
Self {
queue: Default::default(),
}
}
}
impl<T> ReadyFramesQueue<T> {
fn push(&mut self, handle: T) {
self.queue.push_back(handle)
}
}
impl<T> Extend<T> for ReadyFramesQueue<T> {
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
self.queue.extend(iter)
}
}
impl<'a, T> Iterator for &'a mut ReadyFramesQueue<T> {
type Item = T;
fn next(&mut self) -> Option<T> {
self.queue.pop_front()
}
}