#[cfg(any(target_os = "android", target_os = "macos", target_os = "ios"))]
use super::frame_queue::Frames;
#[cfg(target_os = "android")]
use super::media_codec::Backend;
#[cfg(not(any(target_os = "android", target_os = "macos", target_os = "ios")))]
use super::unavailable::{Backend, Frames};
#[cfg(any(target_os = "macos", target_os = "ios"))]
use super::video_toolbox::Backend;
use super::{
AccessUnit, DecoderCapabilities, DecoderConfig, DecoderError, DecoderStats, FrameInfo,
VideoCodec, VideoFrame, capabilities,
};
pub struct VideoDecoder {
backend: Backend,
}
impl VideoDecoder {
pub fn new(config: DecoderConfig) -> Result<Self, DecoderError> {
Ok(Self {
backend: Backend::new(config)?,
})
}
pub fn capabilities(codec: VideoCodec) -> Result<DecoderCapabilities, DecoderError> {
capabilities::of(codec)
}
pub fn submit(&mut self, unit: AccessUnit<'_>) -> Result<(), DecoderError> {
self.backend.submit(unit)
}
pub fn frames(&self) -> DecodedFrames {
DecodedFrames {
frames: self.backend.frames(),
}
}
}
#[derive(Clone, PartialEq)]
pub struct DecodedFrames {
frames: Frames,
}
impl DecodedFrames {
pub fn next_frame(&self) -> Option<VideoFrame> {
self.frames.next_frame()
}
pub fn latest_frame(&self) -> Option<VideoFrame> {
self.frames.latest_frame()
}
pub async fn wait_for_frame(&self) {
std::future::poll_fn(|context| self.frames.poll_ready(context)).await;
}
pub fn next_report(&self) -> Option<FrameInfo> {
self.frames.next_report()
}
pub fn stats(&self) -> DecoderStats {
self.frames.stats()
}
}