Skip to content

Commit

Permalink
Initial WASM contribute (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
kixelated authored Jan 15, 2025
1 parent 3d4b3a1 commit 877f060
Show file tree
Hide file tree
Showing 66 changed files with 1,505 additions and 677 deletions.
56 changes: 52 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
"moq-karp",
"moq-gst",
"moq-web",
"moq-async",
]
default-members = [
"moq-transfork",
Expand All @@ -15,6 +16,7 @@ default-members = [
"moq-native",
"moq-karp",
"moq-web",
"moq-async",
# "moq-gst", # Requires gstreamer is installed; annoying
]
resolver = "2"
Expand Down
20 changes: 20 additions & 0 deletions moq-async/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "moq-async"
description = "Media over QUIC - Async helpers and utilities"
authors = ["Luke Curley"]
repository = "https://github.com/kixelated/moq-rs"
license = "MIT OR Apache-2.0"

version = "0.1.0"
edition = "2021"

keywords = ["quic", "http3", "webtransport", "media", "live"]
categories = ["multimedia", "network-programming", "web-programming"]

[dependencies]
tracing = "0.1"
tokio = { version = "1.41", features = ["rt"] }
futures = "0.3"

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen-futures = "0.4"
21 changes: 21 additions & 0 deletions moq-async/src/close.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use std::error::Error;

pub trait Close<E: Error + Clone> {
fn close(&mut self, err: E);
}

pub trait OrClose<S: Close<E>, V, E: Error + Clone> {
fn or_close(self, stream: &mut S) -> Result<V, E>;
}

impl<S: Close<E>, V, E: Error + Clone> OrClose<S, V, E> for Result<V, E> {
fn or_close(self, stream: &mut S) -> Result<V, E> {
match self {
Ok(v) => Ok(v),
Err(err) => {
stream.close(err.clone());
Err(err)
}
}
}
}
29 changes: 29 additions & 0 deletions moq-transfork/src/util/futures.rs → moq-async/src/futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ pub trait FuturesExt: Future {
{
Transpose { future: self }
}

fn cloned(self) -> Cloned<Self>
where
Self: Sized,
{
Cloned { future: self }
}
}

impl<F: Future> FuturesExt for F {}
Expand All @@ -35,3 +42,25 @@ where
}
}
}

pub struct Cloned<F> {
future: F,
}

impl<F, T> Future for Cloned<F>
where
F: Future<Output = T>,
T: Clone,
{
type Output = T;

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
// Frankly I have no idea if this is correct; I hate Pin
let future = unsafe { self.map_unchecked_mut(|s| &mut s.future) };

match future.poll(cx) {
Poll::Ready(val) => Poll::Ready(val.clone()),
Poll::Pending => Poll::Pending,
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions moq-gst/src/sink/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ impl MoqSink {
.path_segments()
.expect("missing path")
.collect::<moq_transfork::Path>();

let broadcast = moq_karp::BroadcastProducer::new(session, path).unwrap();
let media = moq_karp::cmaf::Import::new(broadcast);

Expand Down
5 changes: 4 additions & 1 deletion moq-karp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ categories = ["multimedia", "network-programming", "web-programming"]

[dependencies]
moq-transfork = { path = "../moq-transfork", version = "0.8" }
moq-async = { path = "../moq-async", version = "0.1" }

url = "2"
bytes = "1.9"
hex = "0.4"

mp4-atom = { version = "0.3", features = ["tokio", "bytes"] }
mp4-atom = { version = "0.4", features = ["tokio", "bytes"] }

serde = { version = "1", features = ["derive"] }
serde_json = "1"
Expand All @@ -33,6 +34,8 @@ regex = "1"

tokio = { version = "1.43", features = ["macros"] }

web-time = "1"

# CLI only dependencies
moq-native = { path = "../moq-native", version = "0.6", optional = true }
clap = { version = "4", features = ["derive"], optional = true }
Expand Down
7 changes: 3 additions & 4 deletions moq-karp/src/audio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ pub struct Audio {
#[serde_as(as = "DisplayFromStr")]
pub codec: AudioCodec,

pub sample_rate: u16,
pub channel_count: u16,
pub sample_rate: u32,
pub channel_count: u32,

#[serde(skip_serializing_if = "Option::is_none")]
pub bitrate: Option<u32>,
pub bitrate: Option<u64>,
}
Loading

0 comments on commit 877f060

Please sign in to comment.