#![forbid(unsafe_code)]
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub struct EncodedVideoChunks {
timestamps_us: Vec<f64>,
keyframes: Vec<bool>,
payloads: Vec<Vec<u8>>,
description: Option<Vec<u8>>,
}
impl EncodedVideoChunks {
#[must_use]
pub const fn new(
timestamps_us: Vec<f64>,
keyframes: Vec<bool>,
payloads: Vec<Vec<u8>>,
description: Option<Vec<u8>>,
) -> Self {
Self {
timestamps_us,
keyframes,
payloads,
description,
}
}
}
#[wasm_bindgen]
impl EncodedVideoChunks {
#[wasm_bindgen(getter)]
#[allow(
clippy::cast_possible_truncation,
reason = "test/smoke chunk counts are tiny"
)]
pub fn chunk_count(&self) -> u32 {
self.payloads.len() as u32
}
pub fn timestamp_us(&self, index: u32) -> f64 {
self.timestamps_us[index as usize]
}
pub fn is_key(&self, index: u32) -> bool {
self.keyframes[index as usize]
}
pub fn data(&self, index: u32) -> Vec<u8> {
self.payloads[index as usize].clone() }
#[wasm_bindgen(getter)]
pub fn description(&self) -> Option<Vec<u8>> {
self.description.clone() }
}
#[cfg(test)]
#[path = "chunks_tests.rs"]
mod tests;