Skip to content

Commit

Permalink
Tabs > spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
kixelated committed Dec 8, 2024
1 parent 6ad1b3a commit 519e420
Show file tree
Hide file tree
Showing 12 changed files with 539 additions and 560 deletions.
3 changes: 3 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# i die on this hill
hard_tabs = true
max_width = 120
18 changes: 9 additions & 9 deletions web-codecs/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ use wasm_bindgen::prelude::*;

#[derive(Debug, thiserror::Error, Clone)]
pub enum Error {
#[error("dropped")]
Dropped,
#[error("dropped")]
Dropped,

#[error("invalid dimensions")]
InvalidDimensions,
#[error("invalid dimensions")]
InvalidDimensions,

#[error("unknown error: {0:?}")]
Unknown(JsValue),
#[error("unknown error: {0:?}")]
Unknown(JsValue),
}

impl From<JsValue> for Error {
fn from(e: JsValue) -> Self {
Self::Unknown(e)
}
fn from(e: JsValue) -> Self {
Self::Unknown(e)
}
}

pub type Result<T> = std::result::Result<T, Error>;
50 changes: 25 additions & 25 deletions web-codecs/src/frame.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
use bytes::{Bytes, BytesMut};

pub struct EncodedFrame {
pub payload: Bytes,
pub timestamp: f64,
pub keyframe: bool,
pub payload: Bytes,
pub timestamp: f64,
pub keyframe: bool,
}

impl From<web_sys::EncodedVideoChunk> for EncodedFrame {
fn from(chunk: web_sys::EncodedVideoChunk) -> Self {
let size = chunk.byte_length() as usize;
fn from(chunk: web_sys::EncodedVideoChunk) -> Self {
let size = chunk.byte_length() as usize;

let mut payload = BytesMut::with_capacity(size);
payload.resize(size, 0);
chunk.copy_to_with_u8_slice(&mut payload).unwrap();
let mut payload = BytesMut::with_capacity(size);
payload.resize(size, 0);
chunk.copy_to_with_u8_slice(&mut payload).unwrap();

Self {
payload: payload.freeze(),
timestamp: chunk.timestamp(),
keyframe: chunk.type_() == web_sys::EncodedVideoChunkType::Key,
}
}
Self {
payload: payload.freeze(),
timestamp: chunk.timestamp(),
keyframe: chunk.type_() == web_sys::EncodedVideoChunkType::Key,
}
}
}

impl From<web_sys::EncodedAudioChunk> for EncodedFrame {
fn from(chunk: web_sys::EncodedAudioChunk) -> Self {
let size = chunk.byte_length() as usize;
fn from(chunk: web_sys::EncodedAudioChunk) -> Self {
let size = chunk.byte_length() as usize;

let mut payload = BytesMut::with_capacity(size);
payload.resize(size, 0);
chunk.copy_to_with_u8_slice(&mut payload).unwrap();
let mut payload = BytesMut::with_capacity(size);
payload.resize(size, 0);
chunk.copy_to_with_u8_slice(&mut payload).unwrap();

Self {
payload: payload.freeze(),
timestamp: chunk.timestamp(),
keyframe: chunk.type_() == web_sys::EncodedAudioChunkType::Key,
}
}
Self {
payload: payload.freeze(),
timestamp: chunk.timestamp(),
keyframe: chunk.type_() == web_sys::EncodedAudioChunkType::Key,
}
}
}
70 changes: 35 additions & 35 deletions web-codecs/src/video/color.rs
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
#[derive(Debug, Clone)]
pub struct VideoColorSpaceConfig {
inner: web_sys::VideoColorSpaceInit,
inner: web_sys::VideoColorSpaceInit,
}

impl Default for VideoColorSpaceConfig {
fn default() -> Self {
Self::new()
}
fn default() -> Self {
Self::new()
}
}

impl VideoColorSpaceConfig {
pub fn new() -> Self {
Self {
inner: web_sys::VideoColorSpaceInit::new(),
}
}

pub fn full_range(self, enabled: bool) -> Self {
self.inner.set_full_range(enabled);
self
}

pub fn matrix(self, matrix: VideoMatrixCoefficients) -> Self {
self.inner.set_matrix(matrix);
self
}

pub fn primaries(self, primaries: VideoColorPrimaries) -> Self {
self.inner.set_primaries(primaries);
self
}

pub fn transfer(self, transfer: VideoTransferCharacteristics) -> Self {
self.inner.set_transfer(transfer);
self
}
pub fn new() -> Self {
Self {
inner: web_sys::VideoColorSpaceInit::new(),
}
}

pub fn full_range(self, enabled: bool) -> Self {
self.inner.set_full_range(enabled);
self
}

pub fn matrix(self, matrix: VideoMatrixCoefficients) -> Self {
self.inner.set_matrix(matrix);
self
}

pub fn primaries(self, primaries: VideoColorPrimaries) -> Self {
self.inner.set_primaries(primaries);
self
}

pub fn transfer(self, transfer: VideoTransferCharacteristics) -> Self {
self.inner.set_transfer(transfer);
self
}
}

impl From<&VideoColorSpaceConfig> for web_sys::VideoColorSpaceInit {
fn from(this: &VideoColorSpaceConfig) -> Self {
this.inner.clone()
}
fn from(this: &VideoColorSpaceConfig) -> Self {
this.inner.clone()
}
}

impl From<web_sys::VideoColorSpaceInit> for VideoColorSpaceConfig {
fn from(inner: web_sys::VideoColorSpaceInit) -> Self {
Self { inner }
}
fn from(inner: web_sys::VideoColorSpaceInit) -> Self {
Self { inner }
}
}

pub type VideoMatrixCoefficients = web_sys::VideoMatrixCoefficients;
Expand Down
Loading

0 comments on commit 519e420

Please sign in to comment.