Skip to content

Commit

Permalink
Feat svc simulcast (#266)
Browse files Browse the repository at this point in the history
* WIP: working with seq, ts rewrite.

* WIP: working with single video stream

* WIP: allow working with vp8 simulcast

* WIP: allow re-enable vp8 egress with vp8 short-term memory

* test: add vp8 sim test, packet selector test

* feat: h264 simulcast

* feat: vp9 svc
  • Loading branch information
giangndm authored May 2, 2024
1 parent c42e37b commit 6279d12
Show file tree
Hide file tree
Showing 35 changed files with 3,967 additions and 519 deletions.
12 changes: 11 additions & 1 deletion 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 @@ -11,10 +11,12 @@ members = [
[workspace.dependencies]
sans-io-runtime = { git = "https://github.com/giangndm/sans-io-runtime.git", rev = "9d16b9c224c2d1cd3015c9a2e60f51914c9bd880" }
atm0s-sdn = { git = "https://github.com/giangndm/8xFF-decentralized-sdn.git", rev = "3c2945754926bd014c36e8ec20c228051a45603f" }
tracing-subscriber = { version = "0.3", features = ["env-filter", "std"] }
convert-enum = "0.1"
num_enum = "0.7"
log = "0.4"
smallmap = "1.4"
derivative = "2.2"
derive_more = "0.99"
rand = "0.8"
mockall = "0.12"
2 changes: 1 addition & 1 deletion bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tracing-subscriber = { version = "0.3", features = ["env-filter", "std"] }
tracing-subscriber = { workspace = true }
clap = { version = "4.5", features = ["env", "derive"] }
log = { workspace = true }
rand = { workspace = true }
Expand Down
107 changes: 55 additions & 52 deletions bin/public/whip/whip.demo.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,61 @@
import { WHIPClient } from "./whip.js"
import { WHIPClient } from "./whip.js";

window.start = async () => {
console.log("Will start");
if (window.whip_instance) {
window.whip_instance.stop();
}

if (window.stream_instance) {
window.stream_instance.getTracks().forEach(track => track.stop());
}

//Get mic+cam
const stream = await navigator.mediaDevices.getUserMedia({audio:true, video:true});

document.getElementById("video").srcObject = stream;

//Create peerconnection
const pc = new RTCPeerConnection();

//Send all tracks
for (const track of stream.getTracks()) {
//You could add simulcast too here
pc.addTransceiver(track, {
direction: "sendonly",
streams: [stream],
// sendEncodings: [
// { rid: "0", active: true, scaleResolutionDownBy: 2},
// { rid: "1", active: true, scaleResolutionDownBy: 2},
// { rid: "2", active: true },
// ],
});
}

//Create whip client
const whip = new WHIPClient();

const url = "/whip/endpoint";
const token = document.getElementById("room-id").value;

//Start publishing
whip.publish(pc, url, token);

window.whip_instance = whip;
window.stream_instance = stream;
}
console.log("Will start");
if (window.whip_instance) {
window.whip_instance.stop();
}

if (window.stream_instance) {
window.stream_instance.getTracks().forEach((track) => track.stop());
}

//Get mic+cam
const stream = await navigator.mediaDevices.getUserMedia({
audio: true,
video: true,
});

document.getElementById("video").srcObject = stream;

//Create peerconnection
const pc = new RTCPeerConnection();

//Send all tracks
for (const track of stream.getTracks()) {
//You could add simulcast too here
pc.addTransceiver(track, {
direction: "sendonly",
streams: [stream],
sendEncodings: [
{ rid: "0", active: true },
{ rid: "1", active: true },
{ rid: "2", active: true },
],
});
}

//Create whip client
const whip = new WHIPClient();

const url = "/whip/endpoint";
const token = document.getElementById("room-id").value;

//Start publishing
whip.publish(pc, url, token);

window.whip_instance = whip;
window.stream_instance = stream;
};

window.stop = async () => {
if (window.whip_instance) {
window.whip_instance.stop();
}
if (window.whip_instance) {
window.whip_instance.stop();
}

if (window.stream_instance) {
window.stream_instance.getTracks().forEach(track => track.stop());
}
if (window.stream_instance) {
window.stream_instance.getTracks().forEach((track) => track.stop());
}

document.getElementById("video").srcObject = null;
}
document.getElementById("video").srcObject = null;
};
Loading

0 comments on commit 6279d12

Please sign in to comment.