use webm_sys as ffi;
pub mod mux {
mod segment;
mod writer;
pub use crate::ffi::mux::TrackNum;
pub use segment::{Segment, SegmentBuilder};
pub use writer::Writer;
use crate::ffi;
use std::num::NonZeroU64;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct VideoTrack(NonZeroU64);
impl From<VideoTrack> for TrackNum {
#[inline]
fn from(track: VideoTrack) -> Self {
track.0.get()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct AudioTrack(NonZeroU64);
impl From<AudioTrack> for TrackNum {
#[inline]
fn from(track: AudioTrack) -> Self {
track.0.get()
}
}
pub trait Track {
#[must_use]
fn is_audio(&self) -> bool {
false
}
#[must_use]
fn is_video(&self) -> bool {
false
}
#[must_use]
fn track_number(&self) -> TrackNum;
}
impl Track for VideoTrack {
#[inline]
fn is_video(&self) -> bool {
true
}
#[inline]
fn track_number(&self) -> TrackNum {
self.0.get()
}
}
impl Track for AudioTrack {
#[inline]
fn is_audio(&self) -> bool {
true
}
#[inline]
fn track_number(&self) -> TrackNum {
self.0.get()
}
}
#[derive(Eq, PartialEq, Clone, Copy, Debug)]
#[repr(u32)]
pub enum AudioCodecId {
Opus = ffi::mux::OPUS_CODEC_ID,
Vorbis = ffi::mux::VORBIS_CODEC_ID,
}
impl AudioCodecId {
const fn get_id(self) -> u32 {
self as u32
}
}
#[derive(Eq, PartialEq, Clone, Copy, Debug)]
#[repr(u32)]
pub enum VideoCodecId {
VP8 = ffi::mux::VP8_CODEC_ID,
VP9 = ffi::mux::VP9_CODEC_ID,
AV1 = ffi::mux::AV1_CODEC_ID,
}
impl VideoCodecId {
const fn get_id(self) -> u32 {
self as u32
}
}
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
BadParam,
Unknown,
}
impl Error {
pub(crate) fn check_code(code: ffi::mux::ResultCode) -> Result<(), Self> {
match code {
ffi::mux::ResultCode::Ok => Ok(()),
ffi::mux::ResultCode::BadParam => Err(Self::BadParam),
ffi::mux::ResultCode::UnknownLibwebmError => Err(Self::Unknown),
}
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::BadParam => f.write_str("Bad parameter"),
Self::Unknown => f.write_str("Unknown error"),
}
}
}
impl std::error::Error for Error {}
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq)]
pub struct ColorSubsampling {
pub chroma_horizontal: u8,
pub chroma_vertical: u8,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ColorRange {
#[default]
Unspecified = 0,
Broadcast = 1,
Full = 2,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SegmentMode {
Live,
File,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u64)]
pub enum TransferCharacteristics {
Bt709 = 1,
Unspecified = 2,
Bt470M = 4,
Bt470Bg = 5,
Bt601 = 6,
Smpte240M = 7,
Linear = 8,
Log100 = 9,
Log316 = 10,
Iec61966_2_4 = 11,
Bt1361 = 12,
Iec61966_2_1 = 13,
Bt2020_10bit = 14,
Bt2020_12bit = 15,
Smpte2084 = 16,
Smpte428 = 17,
AribStdB67 = 18,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u64)]
pub enum ColorPrimaries {
Bt709 = 1,
Unspecified = 2,
Bt470M = 4,
Bt470Bg = 5,
Bt601 = 6,
Smpte240M = 7,
Film = 8,
Bt2020 = 9,
Smpte428 = 10,
Smpte431 = 11,
Smpte432 = 12,
Ebu3213 = 22,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u64)]
pub enum MatrixCoefficients {
Identity = 0,
Bt709 = 1,
Unspecified = 2,
Fcc = 4,
Bt470Bg = 5,
Bt601 = 6,
Smpte240M = 7,
YCgCo = 8,
Bt2020Ncl = 9,
Bt2020Cl = 10,
Smpte2085 = 11,
ChromaNcl = 12,
ChromaCl = 13,
ICtCp = 14,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Chromaticity {
pub x: f32,
pub y: f32,
}
impl Chromaticity {
pub const D65: Self = Self {
x: 0.3127,
y: 0.3290,
};
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct DisplayPrimaries {
pub red: Chromaticity,
pub green: Chromaticity,
pub blue: Chromaticity,
}
impl DisplayPrimaries {
pub const BT_709: Self = Self {
red: Chromaticity { x: 0.64, y: 0.33 },
green: Chromaticity { x: 0.30, y: 0.60 },
blue: Chromaticity { x: 0.15, y: 0.06 },
};
pub const BT_2020: Self = Self {
red: Chromaticity { x: 0.708, y: 0.292 },
green: Chromaticity { x: 0.170, y: 0.797 },
blue: Chromaticity { x: 0.131, y: 0.046 },
};
pub const DCI_P3: Self = Self {
red: Chromaticity { x: 0.680, y: 0.320 },
green: Chromaticity { x: 0.265, y: 0.690 },
blue: Chromaticity { x: 0.150, y: 0.060 },
};
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct MasteringDisplayMetadata {
pub luminance_max: f32,
pub luminance_min: f32,
pub primaries: DisplayPrimaries,
pub white_point: Chromaticity,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct HdrMetadata {
pub max_cll: u64,
pub max_fall: u64,
pub mastering_metadata: Option<MasteringDisplayMetadata>,
}
}