Repository: pion/interceptor
Pull request #60 (2021-09-08 18:23:36)

Lengthen some acronyms
`seqNr` isn't one I commonly see. `arrivalTime` just to match the RFC a bit more. 

Feel free to push back @mengelbart if you disagree! I am just confirming that everything works before merging pion/webrtc

codecov[bot]: # [Codecov](https://codecov.io/gh/pion/interceptor/pull/60?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion) Report
> Merging [#60](https://codecov.io/gh/pion/interceptor/pull/60?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion) (7b48066) into [master](https://codecov.io/gh/pion/interceptor/commit/b8d8ea428337cd93050c161e359ae8e04327b5c2?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion) (b8d8ea4) will **not change** coverage.
> The diff coverage is `95.45%`.

[![Impacted file tree graph](https://codecov.io/gh/pion/interceptor/pull/60/graphs/tree.svg?width=650&height=150&src=pr&token=FNH9xUG6AX&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion)](https://codecov.io/gh/pion/interceptor/pull/60?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion)

```diff
@@           Coverage Diff           @@
##           master      #60   +/-   ##
=======================================
  Coverage   81.23%   81.23%           
=======================================
  Files          24       24           
  Lines         810      810           
=======================================
  Hits          658      658           
  Misses        101      101           
  Partials       51       51           
```

| Flag | Coverage Δ | |
|---|---|---|
| go | `81.23% <95.45%> (ø)` | |
| wasm | `?` | |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/pion/interceptor/pull/60?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion) | Coverage Δ | |
|---|---|---|
| [pkg/twcc/twcc.go](https://codecov.io/gh/pion/interceptor/pull/60/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion#diff-cGtnL3R3Y2MvdHdjYy5nbw==) | `92.56% <93.33%> (ø)` | |
| [pkg/twcc/header\_extension.go](https://codecov.io/gh/pion/interceptor/pull/60/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion#diff-cGtnL3R3Y2MvaGVhZGVyX2V4dGVuc2lvbi5nbw==) | `62.50% <100.00%> (ø)` | |
| [pkg/twcc/sender\_interceptor.go](https://codecov.io/gh/pion/interceptor/pull/60/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion#diff-cGtnL3R3Y2Mvc2VuZGVyX2ludGVyY2VwdG9yLmdv) | `79.71% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pion/interceptor/pull/60?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pion/interceptor/pull/60?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion). Last update [b8d8ea4...7b48066](https://codecov.io/gh/pion/interceptor/pull/60?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pion).


Patch:
diff --git a/pkg/twcc/header_extension.go b/pkg/twcc/header_extension.go
index d1254b1..7db444d 100644
--- a/pkg/twcc/header_extension.go
+++ b/pkg/twcc/header_extension.go
@@ -34,9 +34,9 @@ func (h *HeaderExtensionInterceptor) BindLocalStream(info *interceptor.StreamInf
 		return writer
 	}
 	return interceptor.RTPWriterFunc(func(header *rtp.Header, payload []byte, attributes interceptor.Attributes) (int, error) {
-		seqNr := atomic.AddUint32(&h.nextSequenceNr, 1) - 1
+		sequenceNumber := atomic.AddUint32(&h.nextSequenceNr, 1) - 1
 
-		tcc, err := (&rtp.TransportCCExtension{TransportSequence: uint16(seqNr)}).Marshal()
+		tcc, err := (&rtp.TransportCCExtension{TransportSequence: uint16(sequenceNumber)}).Marshal()
 		if err != nil {
 			return 0, err
 		}
diff --git a/pkg/twcc/sender_interceptor.go b/pkg/twcc/sender_interceptor.go
index cb2ab0b..d74bc63 100644
--- a/pkg/twcc/sender_interceptor.go
+++ b/pkg/twcc/sender_interceptor.go
@@ -78,10 +78,10 @@ func (s *SenderInterceptor) BindRTCPWriter(writer interceptor.RTCPWriter) interc
 }
 
 type packet struct {
-	hdr   *rtp.Header
-	seqNr uint16
-	ts    int64
-	ssrc  uint32
+	hdr            *rtp.Header
+	sequenceNumber uint16
+	arrivalTime    int64
+	ssrc           uint32
 }
 
 // BindRemoteStream lets you modify any incoming RTP packets. It is called once for per RemoteStream. The returned method
@@ -115,10 +115,10 @@ func (s *SenderInterceptor) BindRemoteStream(info *interceptor.StreamInfo, reade
 			}
 
 			s.packetChan <- packet{
-				hdr:   &p.Header,
-				seqNr: tccExt.TransportSequence,
-				ts:    time.Now().UnixNano(),
-				ssrc:  info.SSRC,
+				hdr:            &p.Header,
+				sequenceNumber: tccExt.TransportSequence,
+				arrivalTime:    time.Now().UnixNano(),
+				ssrc:           info.SSRC,
 			}
 		}
 
@@ -158,7 +158,7 @@ func (s *SenderInterceptor) loop(w interceptor.RTCPWriter) {
 		case <-s.close:
 			return
 		case p := <-s.packetChan:
-			s.recorder.Record(p.ssrc, p.seqNr, p.ts/1e6) // ns -> ms: divide by 1e6
+			s.recorder.Record(p.ssrc, p.sequenceNumber, p.arrivalTime/1e6) // ns -> ms: divide by 1e6
 
 		case <-ticker.C:
 			// build and send twcc
diff --git a/pkg/twcc/twcc.go b/pkg/twcc/twcc.go
index 37b8e2a..175e410 100644
--- a/pkg/twcc/twcc.go
+++ b/pkg/twcc/twcc.go
@@ -8,8 +8,8 @@ import (
 )
 
 type pktInfo struct {
-	seqNr     uint32
-	timestamp int64
+	sequenceNumber uint32
+	timestamp      int64
 }
 
 // Recorder records incoming RTP packets and their delays and creates
@@ -18,8 +18,8 @@ type pktInfo struct {
 type Recorder struct {
 	receivedPackets []pktInfo
 
-	cycles    uint32
-	lastSeqNr uint16
+	cycles             uint32
+	lastSequenceNumber uint16
 
 	senderSSRC uint32
 	mediaSSRC  uint32
@@ -35,17 +35,17 @@ func NewRecorder(senderSSRC uint32) *Recorder {
 	}
 }
 
-// Record marks a packet with mediaSSRC and a transport wide sequence number seqNr as received at arrivalTime.
-func (r *Recorder) Record(mediaSSRC uint32, seqNr uint16, arrivalTimeMS int64) {
+// Record marks a packet with mediaSSRC and a transport wide sequence number sequenceNumber as received at arrivalTime.
+func (r *Recorder) Record(mediaSSRC uint32, sequenceNumber uint16, arrivalTimeMS int64) {
 	r.mediaSSRC = mediaSSRC
-	if seqNr < 0x0fff && (r.lastSeqNr&0xffff) > 0xf000 {
+	if sequenceNumber < 0x0fff && (r.lastSequenceNumber&0xffff) > 0xf000 {
 		r.cycles += 1 << 16
 	}
 	r.receivedPackets = append(r.receivedPackets, pktInfo{
-		seqNr:     r.cycles | uint32(seqNr),
-		timestamp: arrivalTimeMS,
+		sequenceNumber: r.cycles | uint32(sequenceNumber),
+		timestamp:      arrivalTimeMS,
 	})
-	r.lastSeqNr = seqNr
+	r.lastSequenceNumber = sequenceNumber
 }
 
 // BuildFeedbackPacket creates a new RTCP packet containing a TWCC feedback report.
@@ -56,18 +56,18 @@ func (r *Recorder) BuildFeedbackPacket() []rtcp.Packet {
 	}
 
 	sort.Slice(r.receivedPackets, func(i, j int) bool {
-		return r.receivedPackets[i].seqNr < r.receivedPackets[j].seqNr
+		return r.receivedPackets[i].sequenceNumber < r.receivedPackets[j].sequenceNumber
 	})
-	tlcc.setBase(uint16(r.receivedPackets[0].seqNr&0xffff), r.receivedPackets[0].timestamp*1000)
+	tlcc.setBase(uint16(r.receivedPackets[0].sequenceNumber&0xffff), r.receivedPackets[0].timestamp*1000)
 
 	var pkts []rtcp.Packet
 	for _, pkt := range r.receivedPackets {
-		built := tlcc.addReceived(uint16(pkt.seqNr&0xffff), pkt.timestamp*1000)
+		built := tlcc.addReceived(uint16(pkt.sequenceNumber&0xffff), pkt.timestamp*1000)
 		if !built {
 			pkts = append(pkts, tlcc.getRTCP())
 			r.fbPktCnt++
 			tlcc = newFeedback(r.senderSSRC, r.mediaSSRC, r.fbPktCnt)
-			tlcc.addReceived(uint16(pkt.seqNr&0xffff), pkt.timestamp*1000)
+			tlcc.addReceived(uint16(pkt.sequenceNumber&0xffff), pkt.timestamp*1000)
 		}
 	}
 	r.receivedPackets = []pktInfo{}
@@ -79,16 +79,16 @@ func (r *Recorder) BuildFeedbackPacket() []rtcp.Packet {
 }
 
 type feedback struct {
-	rtcp             *rtcp.TransportLayerCC
-	baseSeqNr        uint16
-	refTimestamp64MS int64
-	lastTimestampUS  int64
-	nextSeqNr        uint16
-	seqNrCount       uint16
-	len              int
-	lastChunk        chunk
-	chunks           []rtcp.PacketStatusChunk
-	deltas           []*rtcp.RecvDelta
+	rtcp                *rtcp.TransportLayerCC
+	baseSequenceNumber  uint16
+	refTimestamp64MS    int64
+	lastTimestampUS     int64
+	nextSequenceNumber  uint16
+	sequenceNumberCount uint16
+	len                 int
+	lastChunk           chunk
+	chunks              []rtcp.PacketStatusChunk
+	deltas              []*rtcp.RecvDelta
 }
 
 func newFeedback(senderSSRC, mediaSSRC uint32, count uint8) *feedback {
@@ -101,17 +101,17 @@ func newFeedback(senderSSRC, mediaSSRC uint32, count uint8) *feedback {
 	}
 }
 
-func (f *feedback) setBase(seqNr uint16, timeUS int64) {
-	f.baseSeqNr = seqNr
-	f.nextSeqNr = f.baseSeqNr
+func (f *feedback) setBase(sequenceNumber uint16, timeUS int64) {
+	f.baseSequenceNumber = sequenceNumber
+	f.nextSequenceNumber = f.baseSequenceNumber
 	f.refTimestamp64MS = timeUS / 64e3
 	f.lastTimestampUS = f.refTimestamp64MS * 64e3
 }
 
 func (f *feedback) getRTCP() *rtcp.TransportLayerCC {
-	f.rtcp.PacketStatusCount = f.seqNrCount
+	f.rtcp.PacketStatusCount = f.sequenceNumberCount
 	f.rtcp.ReferenceTime = uint32(f.refTimestamp64MS)
-	f.rtcp.BaseSequenceNumber = f.baseSeqNr
+	f.rtcp.BaseSequenceNumber = f.baseSequenceNumber
 	if len(f.lastChunk.deltas) > 0 {
 		f.chunks = append(f.chunks, f.lastChunk.encode())
 		f.rtcp.PacketChunks = append(f.rtcp.PacketChunks, f.chunks...)
@@ -133,7 +133,7 @@ func (f *feedback) getRTCP() *rtcp.TransportLayerCC {
 	return f.rtcp
 }
 
-func (f *feedback) addReceived(seqNr uint16, timestampUS int64) bool {
+func (f *feedback) addReceived(sequenceNumber uint16, timestampUS int64) bool {
 	deltaUS := timestampUS - f.lastTimestampUS
 	delta250US := deltaUS / 250
 	delta16 := uint16(delta250US)
@@ -141,12 +141,12 @@ func (f *feedback) addReceived(seqNr uint16, timestampUS int64) bool {
 		return false
 	}
 
-	for ; f.nextSeqNr != seqNr; f.nextSeqNr++ {
+	for ; f.nextSequenceNumber != sequenceNumber; f.nextSequenceNumber++ {
 		if !f.lastChunk.canAdd(rtcp.TypeTCCPacketNotReceived) {
 			f.chunks = append(f.chunks, f.lastChunk.encode())
 		}
 		f.lastChunk.add(rtcp.TypeTCCPacketNotReceived)
-		f.seqNrCount++
+		f.sequenceNumberCount++
 	}
 
 	var recvDelta uint16
@@ -168,8 +168,8 @@ func (f *feedback) addReceived(seqNr uint16, timestampUS int64) bool {
 		Delta: delta250US,
 	})
 	f.lastTimestampUS = timestampUS
-	f.seqNrCount++
-	f.nextSeqNr++
+	f.sequenceNumberCount++
+	f.nextSequenceNumber++
 	return true
 }
 


Test patch:
diff --git a/pkg/twcc/sender_interceptor_test.go b/pkg/twcc/sender_interceptor_test.go
index 61a024f..503e1d8 100644
--- a/pkg/twcc/sender_interceptor_test.go
+++ b/pkg/twcc/sender_interceptor_test.go
@@ -138,7 +138,7 @@ func TestSenderInterceptor(t *testing.T) {
 			assert.NoError(t, stream.Close())
 		}()
 
-		seqNrToDelay := map[int]int{
+		sequenceNumberToDelay := map[int]int{
 			0:  0,
 			1:  10,
 			4:  100,
@@ -148,7 +148,7 @@ func TestSenderInterceptor(t *testing.T) {
 			30: 300,
 		}
 		for _, i := range []int{0, 1, 4, 8, 9, 10, 30} {
-			d := seqNrToDelay[i]
+			d := sequenceNumberToDelay[i]
 			time.Sleep(time.Duration(d) * time.Millisecond)
 
 			hdr := rtp.Header{}
diff --git a/pkg/twcc/twcc_test.go b/pkg/twcc/twcc_test.go
index 91961be..41f66ec 100644
--- a/pkg/twcc/twcc_test.go
+++ b/pkg/twcc/twcc_test.go
@@ -167,12 +167,12 @@ func Test_feedback(t *testing.T) {
 		got := f.addReceived(1, 1023*1000)
 
 		assert.True(t, got)
-		assert.Equal(t, uint16(2), f.nextSeqNr)
+		assert.Equal(t, uint16(2), f.nextSequenceNumber)
 		assert.Equal(t, int64(15), f.refTimestamp64MS)
 
 		got = f.addReceived(4, 1086*1000)
 		assert.True(t, got)
-		assert.Equal(t, uint16(5), f.nextSeqNr)
+		assert.Equal(t, uint16(5), f.nextSequenceNumber)
 		assert.Equal(t, int64(15), f.refTimestamp64MS)
 
 		assert.True(t, f.lastChunk.hasDifferentTypes)
@@ -315,10 +315,10 @@ func Test_feedback(t *testing.T) {
 
 	t.Run("get RTCP", func(t *testing.T) {
 		testcases := []struct {
-			arrivalTS     int64
-			seqNr         uint16
-			wantRefTime   uint32
-			wantBaseSeqNr uint16
+			arrivalTS              int64
+			sequenceNumber         uint16
+			wantRefTime            uint32
+			wantBaseSequenceNumber uint16
 		}{
 			{320, 1, 5, 1},
 			{1000, 2, 15, 2},
@@ -328,11 +328,11 @@ func Test_feedback(t *testing.T) {
 
 			t.Run("set correct base seq and time", func(t *testing.T) {
 				f := newFeedback(0, 0, 0)
-				f.setBase(tt.seqNr, tt.arrivalTS*1000)
+				f.setBase(tt.sequenceNumber, tt.arrivalTS*1000)
 
 				got := f.getRTCP()
 				assert.Equal(t, tt.wantRefTime, got.ReferenceTime)
-				assert.Equal(t, tt.wantBaseSeqNr, got.BaseSequenceNumber)
+				assert.Equal(t, tt.wantBaseSequenceNumber, got.BaseSequenceNumber)
 			})
 		}
 	})