use std::fmt;
use crate::format::{PixFmt, SampleFmt};
#[derive(Clone)]
pub struct VideoFrame {
pub vframe: Vec<u8>,
pub size: (u32, u32),
pub pix_fmt: PixFmt,
pub ts: u64,
}
impl fmt::Debug for VideoFrame {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
#[allow(unused)]
#[derive(Debug)]
struct VideoFrameDebug {
vframe: usize,
size: (u32, u32),
pix_fmt: PixFmt,
ts: u64,
}
fmt::Debug::fmt(
&VideoFrameDebug {
vframe: self.vframe.len(),
size: self.size,
pix_fmt: self.pix_fmt,
ts: self.ts,
},
f,
)
}
}
impl AsRef<[u8]> for VideoFrame {
fn as_ref(&self) -> &[u8] {
self.vframe.as_ref()
}
}
impl VFrame for VideoFrame {
fn size(&self) -> (u32, u32) {
(self.size.0, self.size.1)
}
fn pix_fmt(&self) -> PixFmt {
self.pix_fmt
}
fn ts(&self) -> u64 {
self.ts
}
}
#[derive(Clone)]
pub struct AudioFrame {
pub aframe: Vec<u8>,
pub nb_samples: i32,
pub sample_rate: i32,
pub nb_channels: i32,
pub sample_fmt: SampleFmt,
pub ts: u64,
}
impl fmt::Debug for AudioFrame {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
#[allow(unused)]
#[derive(Debug)]
struct AudioFrameDebug {
aframe: usize,
nb_samples: i32,
sample_rate: i32,
nb_channels: i32,
sample_fmt: SampleFmt,
ts: u64,
}
fmt::Debug::fmt(
&AudioFrameDebug {
aframe: self.aframe.len(),
nb_samples: self.nb_samples,
sample_rate: self.sample_rate,
nb_channels: self.nb_channels,
sample_fmt: self.sample_fmt,
ts: self.ts,
},
f,
)
}
}
impl AsRef<[u8]> for AudioFrame {
fn as_ref(&self) -> &[u8] {
self.aframe.as_ref()
}
}
impl AFrame for AudioFrame {
fn nb_samples(&self) -> i32 {
self.nb_samples
}
fn sample_rate(&self) -> i32 {
self.sample_rate
}
fn nb_channels(&self) -> i32 {
self.nb_channels
}
fn sample_fmt(&self) -> SampleFmt {
self.sample_fmt
}
fn ts(&self) -> u64 {
self.ts
}
}
pub trait VFrame: AsRef<[u8]> {
fn size(&self) -> (u32, u32);
fn pix_fmt(&self) -> PixFmt;
fn ts(&self) -> u64;
}
pub trait AFrame: AsRef<[u8]> {
fn nb_samples(&self) -> i32;
fn sample_rate(&self) -> i32;
fn nb_channels(&self) -> i32;
fn sample_fmt(&self) -> SampleFmt;
fn ts(&self) -> u64;
}