use std::fmt;
#[cfg(feature = "exp-subtitle-codecs")]
use crate::codecs::CodecInfo;
use crate::common::FourCc;
#[cfg(feature = "exp-subtitle-codecs")]
use crate::errors::Result;
#[cfg(feature = "exp-subtitle-codecs")]
use crate::packet::{Packet, PacketRef};
#[cfg(feature = "exp-subtitle-codecs")]
use crate::subtitle::GenericSubtitleBufferRef;
#[repr(transparent)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct SubtitleCodecId(u32);
pub const CODEC_ID_NULL_SUBTITLE: SubtitleCodecId = SubtitleCodecId(0x0);
impl SubtitleCodecId {
pub const fn new(cc: FourCc) -> SubtitleCodecId {
Self(0x8000_0000 | u32::from_be_bytes(cc.get()))
}
}
impl Default for SubtitleCodecId {
fn default() -> Self {
CODEC_ID_NULL_SUBTITLE
}
}
impl From<FourCc> for SubtitleCodecId {
fn from(value: FourCc) -> Self {
SubtitleCodecId::new(value)
}
}
impl fmt::Display for SubtitleCodecId {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:#x}", self.0)
}
}
#[derive(Clone, Debug, Default)]
pub struct SubtitleCodecParameters {
pub codec: SubtitleCodecId,
pub extra_data: Option<Box<[u8]>>,
}
impl SubtitleCodecParameters {
pub fn new() -> SubtitleCodecParameters {
SubtitleCodecParameters { codec: CODEC_ID_NULL_SUBTITLE, extra_data: None }
}
pub fn for_codec(&mut self, codec: SubtitleCodecId) -> &mut Self {
self.codec = codec;
self
}
pub fn with_extra_data(&mut self, data: Box<[u8]>) -> &mut Self {
self.extra_data = Some(data);
self
}
}
#[cfg(feature = "exp-subtitle-codecs")]
#[non_exhaustive]
#[derive(Copy, Clone, Debug, Default)]
pub struct SubtitleDecoderOptions {
}
#[cfg(feature = "exp-subtitle-codecs")]
pub trait SubtitleDecoder: Send + Sync {
fn reset(&mut self);
fn codec_info(&self) -> &CodecInfo;
fn codec_params(&self) -> &SubtitleCodecParameters;
fn decode(&mut self, packet: &Packet) -> Result<GenericSubtitleBufferRef<'_>> {
self.decode_ref(&packet.as_packet_ref())
}
fn decode_ref(&mut self, packet: &PacketRef<'_>) -> Result<GenericSubtitleBufferRef<'_>>;
fn last_decoded(&self) -> GenericSubtitleBufferRef<'_>;
}
pub mod well_known {
use super::SubtitleCodecId;
pub const CODEC_ID_TEXT_UTF8: SubtitleCodecId = SubtitleCodecId(0x100);
pub const CODEC_ID_SSA: SubtitleCodecId = SubtitleCodecId(0x200);
pub const CODEC_ID_ASS: SubtitleCodecId = SubtitleCodecId(0x201);
pub const CODEC_ID_SAMI: SubtitleCodecId = SubtitleCodecId(0x202);
pub const CODEC_ID_SRT: SubtitleCodecId = SubtitleCodecId(0x203);
pub const CODEC_ID_WEBVTT: SubtitleCodecId = SubtitleCodecId(0x204);
pub const CODEC_ID_DVBSUB: SubtitleCodecId = SubtitleCodecId(0x205);
pub const CODEC_ID_HDMV_TEXTST: SubtitleCodecId = SubtitleCodecId(0x206);
pub const CODEC_ID_MOV_TEXT: SubtitleCodecId = SubtitleCodecId(0x207);
pub const CODEC_ID_BMP: SubtitleCodecId = SubtitleCodecId(0x300);
pub const CODEC_ID_VOBSUB: SubtitleCodecId = SubtitleCodecId(0x301);
pub const CODEC_ID_HDMV_PGS: SubtitleCodecId = SubtitleCodecId(0x302);
pub const CODEC_ID_KATE: SubtitleCodecId = SubtitleCodecId(0x400);
}