#![allow(unreachable_pub)]
#![allow(clippy::use_self)]
use std::io::Cursor;
use std::panic;
use wasm_bindgen::prelude::*;
use wee_alloc::WeeAlloc;
use crate::remuxer::ogg_to_ogg::{OggToOgg as OggToOggRemuxer, OggVorbisStreamPassthroughMangler};
use crate::remuxer::Remuxer;
#[global_allocator]
static ALLOC: WeeAlloc = WeeAlloc::INIT;
#[wasm_bindgen(start)]
#[allow(dead_code)] pub fn main() {
#[cfg(feature = "wasm-web-bindings")]
{
panic::set_hook(Box::new(console_error_panic_hook::hook));
console_log::init().ok();
}
}
#[wasm_bindgen]
pub struct OggToOgg {
inner: OggToOggRemuxer<OggVorbisStreamPassthroughMangler>
}
#[wasm_bindgen]
impl OggToOgg {
#[wasm_bindgen(constructor)]
pub fn new_with_defaults() -> Self {
Self {
inner: OggToOggRemuxer::new_with_defaults()
}
}
pub fn remux(&self, buf: &[u8]) -> Result<Box<[u8]>, String> {
let mut sink = Vec::with_capacity(buf.len() / 2);
self.inner
.remux(Cursor::new(buf), &mut sink)
.map_err(|err| err.to_string())?;
Ok(sink.into_boxed_slice())
}
}