Skip to content

Commit

Permalink
Merge branch 'master' into Robin/20201211-prometheus
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Raymond committed Dec 14, 2020
2 parents da4eb8c + 96dca78 commit 6309a16
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 28 deletions.
2 changes: 2 additions & 0 deletions cmd/signal/json-rpc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"net/http"
"os"

_ "net/http/pprof"

"github.com/gorilla/websocket"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/sourcegraph/jsonrpc2"
Expand Down
15 changes: 10 additions & 5 deletions examples/echotest/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ <h3>Pion</h3>
onclick="controlRemoteVideo(this)"
value="high"
name="optremotevideos"
checked
/>
High</label
>
Expand Down Expand Up @@ -328,7 +329,8 @@ <h3>Pion</h3>
integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV"
crossorigin="anonymous"
></script>
<script src="https://unpkg.com/[email protected]/dist/ion-sdk.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/ion-sdk.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/json-rpc.min.js"></script>
<script>
const localVideo = document.getElementById("local-video");
const remoteVideo = document.getElementById("remote-video");
Expand All @@ -350,15 +352,18 @@ <h3>Pion</h3>
/* eslint-env browser */
const joinBtns = document.getElementById("start-btns");

const signalLocal = new IonSDK.IonSFUJSONRPCSignal(
const signalLocal = new Signal.IonSFUJSONRPCSignal(
"ws://localhost:7000/ws"
);
const signalRemote = new IonSDK.IonSFUJSONRPCSignal(
const signalRemote = new Signal.IonSFUJSONRPCSignal(
"ws://localhost:7000/ws"
);

const clientLocal = new IonSDK.Client("test session", signalLocal);
const clientRemote = new IonSDK.Client("test session", signalRemote);
const clientLocal = new IonSDK.Client(signalLocal);
const clientRemote = new IonSDK.Client(signalRemote);

signalLocal.onopen = () => clientLocal.join("test session");
signalRemote.onopen = () => clientRemote.join("test session");

let localStream;
const start = (sc) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Race Test
# Gallery Test

Race test provides a demonstration large session negotiation.
Gallery test provides a demonstration large session negotiation.

## Instructions

Expand Down
File renamed without changes.
11 changes: 7 additions & 4 deletions examples/racetest/index.html → examples/gallerytest/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
}
</style>

<title>Pion ion-sfu | Racetest</title>
<title>Pion ion-sfu | Gallery Test</title>
</head>

<body>
Expand Down Expand Up @@ -73,7 +73,8 @@ <h3>Pion</h3>
integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV"
crossorigin="anonymous"
></script>
<script src="https://unpkg.com/[email protected]/dist/ion-sdk.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/ion-sdk.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/json-rpc.min.js"></script>
<script>
const localVideo = document.getElementById("local-video");
const remotesDiv = document.getElementById("remotes");
Expand All @@ -84,15 +85,17 @@ <h3>Pion</h3>

class Peer {
constructor() {
this.signal = new IonSDK.IonSFUJSONRPCSignal(
this.signal = new Signal.IonSFUJSONRPCSignal(
"ws://localhost:7000/ws"
);

const videosDiv = document.createElement("div");
videosDiv.style.display = "flex";
remotesDiv.appendChild(videosDiv);

this.client = new IonSDK.Client("test session", this.signal);
this.client = new IonSDK.Client(this.signal);
this.signal.onopen = () => this.client.join("test session");

this.client.ontrack = (track, stream) => {
if (track.kind === "video") {
const remoteVideo = document.createElement("video");
Expand Down
8 changes: 5 additions & 3 deletions examples/pubsubtest/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ <h3>Pion</h3>
integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV"
crossorigin="anonymous"
></script>
<script src="https://unpkg.com/[email protected]/dist/ion-sdk.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/ion-sdk.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/json-rpc.min.js"></script>
<script>
const localVideo = document.getElementById("local-video");
const remotesDiv = document.getElementById("remotes");
Expand All @@ -150,11 +151,12 @@ <h3>Pion</h3>
],
};

const signalLocal = new IonSDK.IonSFUJSONRPCSignal(
const signalLocal = new Signal.IonSFUJSONRPCSignal(
"ws://localhost:7000/ws"
);

const clientLocal = new IonSDK.Client("test session", signalLocal);
const clientLocal = new IonSDK.Client(signalLocal);
signalLocal.onopen = () => clientLocal.join("test session");

let localStream;
const start = () => {
Expand Down
9 changes: 6 additions & 3 deletions pkg/sfu/downtrack.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (d *DownTrack) SwitchSpatialLayer(targetLayer int) {
if d.currentSpatialLayer != d.simulcast.targetSpatialLayer {
return
}
if err := d.receiver.SubDownTrack(d, targetLayer); err != nil {
if err := d.receiver.SubDownTrack(d, targetLayer); err == nil {
d.simulcast.targetSpatialLayer = targetLayer
}
}
Expand Down Expand Up @@ -240,6 +240,9 @@ func (d *DownTrack) writeSimulcastRTP(pkt rtp.Packet) error {
// Check if packet SSRC is different from before
// if true, the video source changed
if d.lastSSRC != pkt.SSRC {
if d.currentSpatialLayer == d.simulcast.targetSpatialLayer && d.lastSSRC != 0 {
return nil
}
relay := false
// Wait for a keyframe to sync new source
switch d.mime {
Expand Down Expand Up @@ -270,14 +273,14 @@ func (d *DownTrack) writeSimulcastRTP(pkt rtp.Packet) error {
// Packet is not a keyframe, discard it
if !relay {
d.receiver.SendRTCP([]rtcp.Packet{
&rtcp.PictureLossIndication{SenderSSRC: pkt.SSRC, MediaSSRC: pkt.SSRC},
&rtcp.PictureLossIndication{SenderSSRC: d.ssrc, MediaSSRC: pkt.SSRC},
})
return nil
}
// Switch is done remove sender from previous layer
// and update current layer
if d.currentSpatialLayer != d.simulcast.targetSpatialLayer {
d.receiver.DeleteDownTrack(d.currentSpatialLayer, d.peerID)
go d.receiver.DeleteDownTrack(d.currentSpatialLayer, d.peerID)
}
d.currentSpatialLayer = d.simulcast.targetSpatialLayer
}
Expand Down
17 changes: 6 additions & 11 deletions pkg/sfu/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ import (
"github.com/pion/webrtc/v3"
)

const (
maxSize = 1024
)

// Receiver defines a interface for a track receivers
type Receiver interface {
TrackID() string
Expand All @@ -34,7 +30,7 @@ type Receiver interface {

// WebRTCReceiver receives a video track
type WebRTCReceiver struct {
sync.RWMutex
sync.Mutex
rtcpMu sync.RWMutex

peerID string
Expand All @@ -55,7 +51,7 @@ type WebRTCReceiver struct {

// NewWebRTCReceiver creates a new webrtc track receivers
func NewWebRTCReceiver(receiver *webrtc.RTPReceiver, track *webrtc.TrackRemote, pid string) Receiver {
w := &WebRTCReceiver{
return &WebRTCReceiver{
peerID: pid,
receiver: receiver,
trackID: track.ID(),
Expand All @@ -64,8 +60,6 @@ func NewWebRTCReceiver(receiver *webrtc.RTPReceiver, track *webrtc.TrackRemote,
kind: track.Kind(),
isSimulcast: len(track.RID()) > 0,
}

return w
}

func (w *WebRTCReceiver) StreamID() string {
Expand Down Expand Up @@ -128,6 +122,7 @@ func (w *WebRTCReceiver) AddDownTrack(track *DownTrack, bestQualityFirst bool) {
}
}
track.currentSpatialLayer = layer
track.simulcast.targetSpatialLayer = layer
track.trackType = SimulcastDownTrack
} else {
track.trackType = SimpleDownTrack
Expand All @@ -141,7 +136,7 @@ func (w *WebRTCReceiver) AddDownTrack(track *DownTrack, bestQualityFirst bool) {
func (w *WebRTCReceiver) SubDownTrack(track *DownTrack, layer int) error {
w.Lock()
if dts := w.downTracks[layer]; dts != nil {
dts = append(dts, track)
w.downTracks[layer] = append(dts, track)
} else {
w.Unlock()
return errNoReceiverFound
Expand Down Expand Up @@ -215,13 +210,13 @@ func (w *WebRTCReceiver) readRTP(track *webrtc.TrackRemote, layer int) {
continue
}

w.RLock()
w.Lock()
for _, dt := range w.downTracks[layer] {
if err := dt.WriteRTP(pkt); err == io.EOF {
go w.DeleteDownTrack(layer, dt.id)
}
}
w.RUnlock()
w.Unlock()
}
}

Expand Down

0 comments on commit 6309a16

Please sign in to comment.