Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions pkg/rfc8888/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type packet struct {
arrival time.Time
ssrc uint32
sequenceNumber uint16
ecn uint8
ecn rtcp.ECN
}

// BindRTCPWriter lets you modify any outgoing RTCP packets. It is called once per PeerConnection. The returned method
Expand Down Expand Up @@ -112,11 +112,20 @@ func (s *SenderInterceptor) BindRemoteStream(
return 0, nil, err
}

var ecn rtcp.ECN
if e, hasECN := attr["ECN"]; hasECN {
if ecnT, ok := e.(byte); ok {
ecn = rtcp.ECN(ecnT)
} else {
s.log.Error("ECN entry in attributes map is not of type byte")
}
}

p := packet{
arrival: s.now(),
ssrc: header.SSRC,
sequenceNumber: header.SequenceNumber,
ecn: 0, // ECN is not supported (yet).
ecn: ecn,
}
s.packetChan <- p

Expand Down
4 changes: 2 additions & 2 deletions pkg/rfc8888/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

type packetReport struct {
arrivalTime time.Time
ecn uint8
ecn rtcp.ECN
}

// Recorder records incoming RTP packets and their arrival times. Recorder can
Expand All @@ -30,7 +30,7 @@ func NewRecorder() *Recorder {
}

// AddPacket writes a packet to the underlying stream.
func (r *Recorder) AddPacket(ts time.Time, ssrc uint32, seq uint16, ecn uint8) {
func (r *Recorder) AddPacket(ts time.Time, ssrc uint32, seq uint16, ecn rtcp.ECN) {
stream, ok := r.streams[ssrc]
if !ok {
stream = newStreamLog(ssrc)
Expand Down
6 changes: 3 additions & 3 deletions pkg/rfc8888/stream_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func newStreamLog(ssrc uint32) *streamLog {
}
}

func (l *streamLog) add(ts time.Time, sequenceNumber uint16, ecn uint8) {
func (l *streamLog) add(ts time.Time, sequenceNumber uint16, ecn rtcp.ECN) {
unwrappedSequenceNumber := l.sequence.Unwrap(sequenceNumber)
if !l.init {
l.init = true
Expand Down Expand Up @@ -68,7 +68,7 @@ func (l *streamLog) metricsAfter(reference time.Time, maxReportBlocks int64) rtc
gapDetected := false
for i := offset; i <= l.lastSequenceNumberReceived; i++ { //nolint:varnamelen // i int64
received := false
ecn := uint8(0)
ecn := rtcp.ECNNonECT
ato := uint16(0)
if report, ok := l.log[i]; ok {
received = true
Expand All @@ -77,7 +77,7 @@ func (l *streamLog) metricsAfter(reference time.Time, maxReportBlocks int64) rtc
}
metricBlocks[i-offset] = rtcp.CCFeedbackMetricBlock{
Received: received,
ECN: rtcp.ECN(ecn),
ECN: ecn,
ArrivalTimeOffset: ato,
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/rfc8888/stream_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func TestStreamLogAdd(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
sl := newStreamLog(0)
for _, input := range test.inputs {
sl.add(input.ts, input.nr, input.ecn)
sl.add(input.ts, input.nr, rtcp.ECN(input.ecn))
}
assert.Equal(t, test.expectedNext, sl.nextSequenceNumberToReport)
assert.Equal(t, test.expectedLast, sl.lastSequenceNumberReceived)
Expand Down Expand Up @@ -552,7 +552,7 @@ func TestStreamLogMetricsAfter(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
sl := newStreamLog(0)
for _, input := range test.inputs {
sl.add(input.ts, input.nr, input.ecn)
sl.add(input.ts, input.nr, rtcp.ECN(input.ecn))
}

assert.Equal(t, test.expectedNextBefore, sl.nextSequenceNumberToReport)
Expand All @@ -572,11 +572,11 @@ func TestStreamLogMetricsAfter(t *testing.T) {

func TestRemoveOldestPackets(t *testing.T) {
sl := newStreamLog(0)
sl.add(time.Time{}.Add(time.Second), 1, 0)
sl.add(time.Time{}.Add(time.Second), 1, rtcp.ECN(0))
now := time.Now().Add(10 * time.Second)
for i := 2; i < 16386; i++ {
now = now.Add(10 * time.Millisecond)
sl.add(now, uint16(i), 0) //nolint:gosec // G115
sl.add(now, uint16(i), rtcp.ECN(0)) //nolint:gosec // G115
}
metrics := sl.metricsAfter(now, maxReportsPerReportBlock)
assert.Equal(t, uint16(2), metrics.BeginSequence)
Expand Down
Loading