#[cfg(all(feature = "web", target_arch = "wasm32"))]
mod browser;
mod job;
#[cfg(all(feature = "native", not(target_arch = "wasm32")))]
mod native;
use std::sync::Arc;
#[cfg(all(feature = "web", target_arch = "wasm32"))]
pub use browser::Browser;
pub use job::Job;
pub(crate) use job::Placement;
pub(crate) use job::Wiring;
pub(crate) use job::{Key, Shaping};
#[cfg(all(feature = "native", not(target_arch = "wasm32")))]
pub use native::Native;
use crate::Encoding;
pub use crate::resource::Request;
use crate::{Error, Pending, Result};
pub const TIMESCALE: u32 = 90_000;
pub trait Encoder {
fn encode(&mut self, nv12: Vec<u8>, time: u64, key: bool) -> Pending<Vec<Unit>>;
fn finish(&mut self) -> Pending<Vec<Unit>>;
}
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct Unit {
pub time: u64,
pub key: bool,
pub annex_b: Vec<u8>,
}
pub trait Host: Send + Sync + 'static {
fn rasterize(&self, run: &TextRun) -> Result<Raster>;
fn measure(&self, run: &TextRun) -> Result<[f32; 2]> {
self.rasterize(run).map(|raster| raster.size.map(|v| v as f32))
}
fn spawn(&self, job: Job) -> Pending<Vec<u8>> {
Pending::ready(Ok(job.run()))
}
fn fetch(&self, request: &Request) -> Pending<Vec<u8>> {
let _ = request;
Pending::ready(Err(Error::Unsupported("this host does not fetch".into())))
}
fn encoder(&self, encoding: &Encoding) -> crate::Result<Box<dyn Encoder>> {
let _ = encoding;
Err(Error::Unsupported("this host encodes no video".into()))
}
}
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
pub struct TextRun {
pub text: Arc<str>,
pub font: Arc<str>,
pub size_px: u32,
pub max_width: Option<u32>,
}
#[derive(Clone, PartialEq, Debug)]
pub struct Raster {
pub size: [u32; 2],
pub coverage: Vec<u8>,
pub baseline: f32,
}