This repository was archived by the owner on Oct 10, 2023. It is now read-only.
forked from AFathi/live-webrtcsignaling
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpipeline.node.rtcp-reporter-rr.go
83 lines (78 loc) · 1.89 KB
/
pipeline.node.rtcp-reporter-rr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"context"
plogger "github.com/heytribe/go-plogger"
"github.com/heytribe/live-webrtcsignaling/rtcp"
"github.com/heytribe/live-webrtcsignaling/srtp"
)
type PipelineNodeRTCPReporterRR struct {
PipelineNode
// I/O
InRTP chan *srtp.PacketRTP
InRTCP chan *srtp.PacketRTCP
Out chan *rtcp.PacketRR
// private
reporter *rtcp.ReporterRR
ssrc uint32
rate uint32
}
func NewPipelineNodeRTCPReporterRR(ssrc uint32, rate uint32) *PipelineNodeRTCPReporterRR {
n := new(PipelineNodeRTCPReporterRR)
//
n.InRTP = make(chan *srtp.PacketRTP, 1000)
n.InRTCP = make(chan *srtp.PacketRTCP, 1000)
n.Out = make(chan *rtcp.PacketRR, 1000)
//
n.ssrc = ssrc
n.rate = rate
return n
}
/*
* @see https://github.com/versatica/mediasoup/blob/master/worker/src/RTC/RtpStream.cpp
*
*/
func (n *PipelineNodeRTCPReporterRR) Run(ctx context.Context) {
n.Running = true
n.emitStart()
//
log := plogger.FromContextSafe(ctx)
// start reporter
reporter := rtcp.NewReporterRR()
go reporter.Run(ctx, n.ssrc, n.rate)
//
for {
select {
case <-ctx.Done():
n.onStop(ctx)
return
case packet := <-n.InRTP:
select {
case reporter.InRTP <- packet:
default:
log.Warnf("reporter.InRTP is full, dropping packet from n.InRTP")
}
case packet := <-n.InRTCP:
select {
case reporter.InRTCP <- packet:
default:
log.Warnf("reporter.InRTCP is full, dropping packet from n.InRTCP")
}
case packet := <-reporter.Out:
select {
case n.Out <- packet:
default:
log.Warnf("n.Out is full, dropping packet from reporter.Out")
}
case stats := <-reporter.OutStats:
msg := new(PipelineMessageRRStats)
msg.InterarrivalDifference = stats.InterarrivalDifference
msg.InterarrivalJitter = stats.InterarrivalJitter
msg.SSRC = stats.SSRC
select {
case n.Bus <- msg:
default:
log.Warnf("Bus is full, dropping packet stats from reporter.OutStats")
}
}
}
}