Skip to content

Commit 6309a16

Browse files
author
Robin Raymond
committed
Merge branch 'master' into Robin/20201211-prometheus
2 parents da4eb8c + 96dca78 commit 6309a16

8 files changed

Lines changed: 38 additions & 28 deletions

File tree

cmd/signal/json-rpc/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"net/http"
99
"os"
1010

11+
_ "net/http/pprof"
12+
1113
"github.com/gorilla/websocket"
1214
"github.com/prometheus/client_golang/prometheus/promhttp"
1315
"github.com/sourcegraph/jsonrpc2"

examples/echotest/index.html

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ <h3>Pion</h3>
170170
onclick="controlRemoteVideo(this)"
171171
value="high"
172172
name="optremotevideos"
173+
checked
173174
/>
174175
High</label
175176
>
@@ -328,7 +329,8 @@ <h3>Pion</h3>
328329
integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV"
329330
crossorigin="anonymous"
330331
></script>
331-
<script src="https://unpkg.com/ion-sdk-js@1.5.0/dist/ion-sdk.min.js"></script>
332+
<script src="https://unpkg.com/ion-sdk-js@1.5.5/dist/ion-sdk.min.js"></script>
333+
<script src="https://unpkg.com/ion-sdk-js@1.5.5/dist/json-rpc.min.js"></script>
332334
<script>
333335
const localVideo = document.getElementById("local-video");
334336
const remoteVideo = document.getElementById("remote-video");
@@ -350,15 +352,18 @@ <h3>Pion</h3>
350352
/* eslint-env browser */
351353
const joinBtns = document.getElementById("start-btns");
352354

353-
const signalLocal = new IonSDK.IonSFUJSONRPCSignal(
355+
const signalLocal = new Signal.IonSFUJSONRPCSignal(
354356
"ws://localhost:7000/ws"
355357
);
356-
const signalRemote = new IonSDK.IonSFUJSONRPCSignal(
358+
const signalRemote = new Signal.IonSFUJSONRPCSignal(
357359
"ws://localhost:7000/ws"
358360
);
359361

360-
const clientLocal = new IonSDK.Client("test session", signalLocal);
361-
const clientRemote = new IonSDK.Client("test session", signalRemote);
362+
const clientLocal = new IonSDK.Client(signalLocal);
363+
const clientRemote = new IonSDK.Client(signalRemote);
364+
365+
signalLocal.onopen = () => clientLocal.join("test session");
366+
signalRemote.onopen = () => clientRemote.join("test session");
362367

363368
let localStream;
364369
const start = (sc) => {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Race Test
1+
# Gallery Test
22

3-
Race test provides a demonstration large session negotiation.
3+
Gallery test provides a demonstration large session negotiation.
44

55
## Instructions
66

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
}
2323
</style>
2424

25-
<title>Pion ion-sfu | Racetest</title>
25+
<title>Pion ion-sfu | Gallery Test</title>
2626
</head>
2727

2828
<body>
@@ -73,7 +73,8 @@ <h3>Pion</h3>
7373
integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV"
7474
crossorigin="anonymous"
7575
></script>
76-
<script src="https://unpkg.com/ion-sdk-js@1.5.0/dist/ion-sdk.min.js"></script>
76+
<script src="https://unpkg.com/ion-sdk-js@1.5.5/dist/ion-sdk.min.js"></script>
77+
<script src="https://unpkg.com/ion-sdk-js@1.5.5/dist/json-rpc.min.js"></script>
7778
<script>
7879
const localVideo = document.getElementById("local-video");
7980
const remotesDiv = document.getElementById("remotes");
@@ -84,15 +85,17 @@ <h3>Pion</h3>
8485

8586
class Peer {
8687
constructor() {
87-
this.signal = new IonSDK.IonSFUJSONRPCSignal(
88+
this.signal = new Signal.IonSFUJSONRPCSignal(
8889
"ws://localhost:7000/ws"
8990
);
9091

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

95-
this.client = new IonSDK.Client("test session", this.signal);
96+
this.client = new IonSDK.Client(this.signal);
97+
this.signal.onopen = () => this.client.join("test session");
98+
9699
this.client.ontrack = (track, stream) => {
97100
if (track.kind === "video") {
98101
const remoteVideo = document.createElement("video");

examples/pubsubtest/index.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ <h3>Pion</h3>
134134
integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV"
135135
crossorigin="anonymous"
136136
></script>
137-
<script src="https://unpkg.com/ion-sdk-js@1.5.0/dist/ion-sdk.min.js"></script>
137+
<script src="https://unpkg.com/ion-sdk-js@1.5.5/dist/ion-sdk.min.js"></script>
138+
<script src="https://unpkg.com/ion-sdk-js@1.5.5/dist/json-rpc.min.js"></script>
138139
<script>
139140
const localVideo = document.getElementById("local-video");
140141
const remotesDiv = document.getElementById("remotes");
@@ -150,11 +151,12 @@ <h3>Pion</h3>
150151
],
151152
};
152153

153-
const signalLocal = new IonSDK.IonSFUJSONRPCSignal(
154+
const signalLocal = new Signal.IonSFUJSONRPCSignal(
154155
"ws://localhost:7000/ws"
155156
);
156157

157-
const clientLocal = new IonSDK.Client("test session", signalLocal);
158+
const clientLocal = new IonSDK.Client(signalLocal);
159+
signalLocal.onopen = () => clientLocal.join("test session");
158160

159161
let localStream;
160162
const start = () => {

pkg/sfu/downtrack.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func (d *DownTrack) SwitchSpatialLayer(targetLayer int) {
164164
if d.currentSpatialLayer != d.simulcast.targetSpatialLayer {
165165
return
166166
}
167-
if err := d.receiver.SubDownTrack(d, targetLayer); err != nil {
167+
if err := d.receiver.SubDownTrack(d, targetLayer); err == nil {
168168
d.simulcast.targetSpatialLayer = targetLayer
169169
}
170170
}
@@ -240,6 +240,9 @@ func (d *DownTrack) writeSimulcastRTP(pkt rtp.Packet) error {
240240
// Check if packet SSRC is different from before
241241
// if true, the video source changed
242242
if d.lastSSRC != pkt.SSRC {
243+
if d.currentSpatialLayer == d.simulcast.targetSpatialLayer && d.lastSSRC != 0 {
244+
return nil
245+
}
243246
relay := false
244247
// Wait for a keyframe to sync new source
245248
switch d.mime {
@@ -270,14 +273,14 @@ func (d *DownTrack) writeSimulcastRTP(pkt rtp.Packet) error {
270273
// Packet is not a keyframe, discard it
271274
if !relay {
272275
d.receiver.SendRTCP([]rtcp.Packet{
273-
&rtcp.PictureLossIndication{SenderSSRC: pkt.SSRC, MediaSSRC: pkt.SSRC},
276+
&rtcp.PictureLossIndication{SenderSSRC: d.ssrc, MediaSSRC: pkt.SSRC},
274277
})
275278
return nil
276279
}
277280
// Switch is done remove sender from previous layer
278281
// and update current layer
279282
if d.currentSpatialLayer != d.simulcast.targetSpatialLayer {
280-
d.receiver.DeleteDownTrack(d.currentSpatialLayer, d.peerID)
283+
go d.receiver.DeleteDownTrack(d.currentSpatialLayer, d.peerID)
281284
}
282285
d.currentSpatialLayer = d.simulcast.targetSpatialLayer
283286
}

pkg/sfu/receiver.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ import (
1212
"github.com/pion/webrtc/v3"
1313
)
1414

15-
const (
16-
maxSize = 1024
17-
)
18-
1915
// Receiver defines a interface for a track receivers
2016
type Receiver interface {
2117
TrackID() string
@@ -34,7 +30,7 @@ type Receiver interface {
3430

3531
// WebRTCReceiver receives a video track
3632
type WebRTCReceiver struct {
37-
sync.RWMutex
33+
sync.Mutex
3834
rtcpMu sync.RWMutex
3935

4036
peerID string
@@ -55,7 +51,7 @@ type WebRTCReceiver struct {
5551

5652
// NewWebRTCReceiver creates a new webrtc track receivers
5753
func NewWebRTCReceiver(receiver *webrtc.RTPReceiver, track *webrtc.TrackRemote, pid string) Receiver {
58-
w := &WebRTCReceiver{
54+
return &WebRTCReceiver{
5955
peerID: pid,
6056
receiver: receiver,
6157
trackID: track.ID(),
@@ -64,8 +60,6 @@ func NewWebRTCReceiver(receiver *webrtc.RTPReceiver, track *webrtc.TrackRemote,
6460
kind: track.Kind(),
6561
isSimulcast: len(track.RID()) > 0,
6662
}
67-
68-
return w
6963
}
7064

7165
func (w *WebRTCReceiver) StreamID() string {
@@ -128,6 +122,7 @@ func (w *WebRTCReceiver) AddDownTrack(track *DownTrack, bestQualityFirst bool) {
128122
}
129123
}
130124
track.currentSpatialLayer = layer
125+
track.simulcast.targetSpatialLayer = layer
131126
track.trackType = SimulcastDownTrack
132127
} else {
133128
track.trackType = SimpleDownTrack
@@ -141,7 +136,7 @@ func (w *WebRTCReceiver) AddDownTrack(track *DownTrack, bestQualityFirst bool) {
141136
func (w *WebRTCReceiver) SubDownTrack(track *DownTrack, layer int) error {
142137
w.Lock()
143138
if dts := w.downTracks[layer]; dts != nil {
144-
dts = append(dts, track)
139+
w.downTracks[layer] = append(dts, track)
145140
} else {
146141
w.Unlock()
147142
return errNoReceiverFound
@@ -215,13 +210,13 @@ func (w *WebRTCReceiver) readRTP(track *webrtc.TrackRemote, layer int) {
215210
continue
216211
}
217212

218-
w.RLock()
213+
w.Lock()
219214
for _, dt := range w.downTracks[layer] {
220215
if err := dt.WriteRTP(pkt); err == io.EOF {
221216
go w.DeleteDownTrack(layer, dt.id)
222217
}
223218
}
224-
w.RUnlock()
219+
w.Unlock()
225220
}
226221
}
227222

0 commit comments

Comments
 (0)