use crate::format::{MediaType, PixelFormat, SampleFormat};
use crate::rational::Rational;
use crate::time::TimeBase;
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct CodecId(pub String);
impl CodecId {
pub fn new(s: impl Into<String>) -> Self {
Self(s.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
}
impl From<&str> for CodecId {
fn from(s: &str) -> Self {
Self(s.to_owned())
}
}
impl std::fmt::Display for CodecId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Clone, Debug)]
pub struct CodecParameters {
pub codec_id: CodecId,
pub media_type: MediaType,
pub sample_rate: Option<u32>,
pub channels: Option<u16>,
pub sample_format: Option<SampleFormat>,
pub width: Option<u32>,
pub height: Option<u32>,
pub pixel_format: Option<PixelFormat>,
pub frame_rate: Option<Rational>,
pub extradata: Vec<u8>,
pub bit_rate: Option<u64>,
}
impl CodecParameters {
pub fn audio(codec_id: CodecId) -> Self {
Self {
codec_id,
media_type: MediaType::Audio,
sample_rate: None,
channels: None,
sample_format: None,
width: None,
height: None,
pixel_format: None,
frame_rate: None,
extradata: Vec::new(),
bit_rate: None,
}
}
pub fn matches_core(&self, other: &CodecParameters) -> bool {
self.codec_id == other.codec_id
&& self.sample_rate == other.sample_rate
&& self.channels == other.channels
&& self.sample_format == other.sample_format
&& self.width == other.width
&& self.height == other.height
&& self.pixel_format == other.pixel_format
}
pub fn video(codec_id: CodecId) -> Self {
Self {
codec_id,
media_type: MediaType::Video,
sample_rate: None,
channels: None,
sample_format: None,
width: None,
height: None,
pixel_format: None,
frame_rate: None,
extradata: Vec::new(),
bit_rate: None,
}
}
}
#[derive(Clone, Debug)]
pub struct StreamInfo {
pub index: u32,
pub time_base: TimeBase,
pub duration: Option<i64>,
pub start_time: Option<i64>,
pub params: CodecParameters,
}