#![allow(unused)]
use std::{marker::PhantomData, time::{Duration, Instant}, fmt::Debug};
use crate::{platform::platform_impl::{ImplAudioFrame, ImplVideoFrame}, util::*};
#[derive(Copy, Clone, Debug)]
pub enum AudioSampleRate {
Hz8000,
Hz16000,
Hz24000,
Hz48000,
}
#[derive(Copy, Clone, Debug)]
pub enum AudioChannelCount {
Mono,
Stereo
}
pub enum AudioChannelData<'data> {
F32(AudioChannelDataSamples<'data, f32>),
I32(AudioChannelDataSamples<'data, i32>),
I16(AudioChannelDataSamples<'data, i16>),
}
pub struct AudioChannelDataSamples<'data, T> {
pub(crate) data: *const u8,
pub(crate) stride: usize,
pub(crate) length: usize,
pub(crate) phantom_lifetime: PhantomData<&'data T>,
}
impl<T: Copy> AudioChannelDataSamples<'_, T> {
pub fn get(&self, n: usize) -> T {
let ptr = self.data.wrapping_add(self.stride * n);
unsafe { *(ptr as *const T) }
}
pub fn length(&self) -> usize {
self.length
}
}
pub enum AudioBufferError {
UnsupportedFormat,
InvalidChannel,
Other(String)
}
pub(crate) trait AudioCaptureFrame {
fn sample_rate(&self) -> AudioSampleRate;
fn channel_count(&self) -> AudioChannelCount;
fn audio_channel_buffer(&mut self, channel: usize) -> Result<AudioChannelData<'_>, AudioBufferError>;
fn duration(&self) -> Duration;
fn origin_time(&self) -> Duration;
fn frame_id(&self) -> u64;
}
pub struct AudioFrame {
pub(crate) impl_audio_frame: ImplAudioFrame,
}
unsafe impl Send for AudioFrame {}
unsafe impl Sync for AudioFrame {}
impl Debug for AudioFrame {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("AudioFrame").finish()
}
}
impl AudioFrame {
pub fn sample_rate(&self) -> AudioSampleRate {
self.impl_audio_frame.sample_rate()
}
pub fn channel_count(&self) -> AudioChannelCount {
self.impl_audio_frame.channel_count()
}
pub fn audio_channel_buffer(&mut self, channel: usize) -> Result<AudioChannelData<'_>, AudioBufferError> {
self.impl_audio_frame.audio_channel_buffer(channel)
}
pub fn duration(&self) -> Duration {
self.impl_audio_frame.duration()
}
pub fn origin_time(&self) -> Duration {
self.impl_audio_frame.duration()
}
pub fn frame_id(&self) -> u64 {
self.impl_audio_frame.frame_id()
}
}
pub(crate) trait VideoCaptureFrame {
fn size(&self) -> Size;
fn dpi(&self) -> f64;
fn duration(&self) -> Duration;
fn origin_time(&self) -> Duration;
fn capture_time(&self) -> Instant;
fn frame_id(&self) -> u64;
fn content_rect(&self) -> Rect;
}
pub struct VideoFrame {
pub(crate) impl_video_frame: ImplVideoFrame,
}
unsafe impl Send for VideoFrame {}
unsafe impl Sync for VideoFrame {}
impl VideoFrame {
pub fn frame_id(&self) -> u64 {
self.impl_video_frame.frame_id()
}
pub fn capture_time(&self) -> Instant {
self.impl_video_frame.capture_time()
}
pub fn origin_time(&self) -> Duration {
self.impl_video_frame.origin_time()
}
pub fn size(&self) -> Size {
self.impl_video_frame.size()
}
pub fn dpi(&self) -> f64 {
self.impl_video_frame.dpi()
}
pub fn content_rect(&self) -> Rect {
self.impl_video_frame.content_rect()
}
}
impl Debug for VideoFrame {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("VideoFrame").finish()
}
}