#![forbid(unsafe_code)]
use crate::error::DecodeError;
use mediaway_common::{
CodecKind, GpuDeviceHandle, Packet, PixelFormat, Rational, StreamInfo, VideoFrame,
};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
#[non_exhaustive]
pub enum VideoOutputPreference {
#[default]
ZeroCopyGpu,
CpuFramesOk,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct VideoDecoderConfig {
pub codec: CodecKind,
pub width: u32,
pub height: u32,
pub time_base: Rational,
pub pixel_format: PixelFormat,
pub output: VideoOutputPreference,
pub gpu_device: Option<GpuDeviceHandle>,
pub extra_data: mediaway_common::Bytes,
}
impl VideoDecoderConfig {
#[must_use]
pub const fn h264(width: u32, height: u32, time_base: Rational) -> Self {
Self {
codec: CodecKind::H264,
width,
height,
time_base,
pixel_format: PixelFormat::Nv12,
output: VideoOutputPreference::ZeroCopyGpu,
gpu_device: None,
extra_data: mediaway_common::Bytes::new(),
}
}
#[must_use]
pub const fn hevc(width: u32, height: u32, time_base: Rational) -> Self {
Self {
codec: CodecKind::Hevc,
width,
height,
time_base,
pixel_format: PixelFormat::Nv12,
output: VideoOutputPreference::ZeroCopyGpu,
gpu_device: None,
extra_data: mediaway_common::Bytes::new(),
}
}
#[must_use]
pub const fn av1(width: u32, height: u32, time_base: Rational) -> Self {
Self {
codec: CodecKind::Av1,
width,
height,
time_base,
pixel_format: PixelFormat::Nv12,
output: VideoOutputPreference::ZeroCopyGpu,
gpu_device: None,
extra_data: mediaway_common::Bytes::new(),
}
}
#[must_use]
pub const fn vp9(width: u32, height: u32, time_base: Rational) -> Self {
Self {
codec: CodecKind::Vp9,
width,
height,
time_base,
pixel_format: PixelFormat::Nv12,
output: VideoOutputPreference::ZeroCopyGpu,
gpu_device: None,
extra_data: mediaway_common::Bytes::new(),
}
}
}
pub trait VideoDecoder {
fn stream_info(&self) -> &StreamInfo;
fn push_packet(&mut self, packet: &Packet) -> Result<(), DecodeError>;
fn poll_frame(&mut self) -> Result<Option<VideoFrame>, DecodeError>;
fn flush(&mut self) -> Result<(), DecodeError>;
}