diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 08e4272a..b0242893 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -23,7 +23,7 @@ jobs: uses: pion/.goassets/.github/workflows/test.reusable.yml@master strategy: matrix: - go: ["1.22", "1.21"] # auto-update/supported-go-version-list + go: ["1.23", "1.22"] # auto-update/supported-go-version-list fail-fast: false with: go-version: ${{ matrix.go }} @@ -33,7 +33,7 @@ jobs: uses: pion/.goassets/.github/workflows/test-i386.reusable.yml@master strategy: matrix: - go: ["1.22", "1.21"] # auto-update/supported-go-version-list + go: ["1.23", "1.22"] # auto-update/supported-go-version-list fail-fast: false with: go-version: ${{ matrix.go }} @@ -41,5 +41,5 @@ jobs: test-wasm: uses: pion/.goassets/.github/workflows/test-wasm.reusable.yml@master with: - go-version: "1.22" # auto-update/latest-go-version + go-version: "1.23" # auto-update/latest-go-version secrets: inherit diff --git a/.golangci.yml b/.golangci.yml index e06de4d3..a3235bec 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,6 +1,9 @@ # SPDX-FileCopyrightText: 2023 The Pion community # SPDX-License-Identifier: MIT +run: + timeout: 5m + linters-settings: govet: enable: @@ -48,7 +51,7 @@ linters: - goconst # Finds repeated strings that could be replaced by a constant - gocritic # The most opinionated Go source code linter - godox # Tool for detection of FIXME, TODO and other comment keywords - - goerr113 # Golang linter to check the errors handling expressions + - err113 # Golang linter to check the errors handling expressions - gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification - gofumpt # Gofumpt checks whether code was gofumpt-ed. - goheader # Checks is file header matches to pattern @@ -83,17 +86,14 @@ linters: - depguard # Go linter that checks if package imports are in a list of acceptable packages - containedctx # containedctx is a linter that detects struct contained context.Context field - cyclop # checks function and package cyclomatic complexity - - exhaustivestruct # Checks if all struct's fields are initialized - funlen # Tool for detection of long functions - gocyclo # Computes and checks the cyclomatic complexity of functions - godot # Check if comments end in a period - gomnd # An analyzer to detect magic numbers. - - ifshort # Checks that your code uses short syntax for if-statements whenever possible - ireturn # Accept Interfaces, Return Concrete Types - lll # Reports long lines - maintidx # maintidx measures the maintainability index of each function. - makezero # Finds slice declarations with non-zero initial length - - maligned # Tool to detect Go structs that would take less memory if their fields were sorted - nakedret # Finds naked returns in functions greater than a specified function length - nestif # Reports deeply nested if statements - nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity diff --git a/go.mod b/go.mod index a8ee764b..395ff2e4 100644 --- a/go.mod +++ b/go.mod @@ -1,12 +1,12 @@ module github.com/pion/interceptor -go 1.19 +go 1.20 require ( github.com/pion/logging v0.2.2 github.com/pion/rtcp v1.2.14 - github.com/pion/rtp v1.8.6 - github.com/pion/transport/v3 v3.0.2 + github.com/pion/rtp v1.8.9 + github.com/pion/transport/v3 v3.0.7 github.com/stretchr/testify v1.9.0 ) diff --git a/go.sum b/go.sum index bccf7b0d..6fec6988 100644 --- a/go.sum +++ b/go.sum @@ -7,65 +7,21 @@ github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA= github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8= github.com/pion/rtcp v1.2.14 h1:KCkGV3vJ+4DAJmvP0vaQShsb0xkRfWkO540Gy102KyE= github.com/pion/rtcp v1.2.14/go.mod h1:sn6qjxvnwyAkkPzPULIbVqSKI5Dv54Rv7VG0kNxh9L4= -github.com/pion/rtp v1.8.6 h1:MTmn/b0aWWsAzux2AmP8WGllusBVw4NPYPVFFd7jUPw= -github.com/pion/rtp v1.8.6/go.mod h1:pBGHaFt/yW7bf1jjWAoUjpSNoDnw98KTMg+jWWvziqU= -github.com/pion/transport/v3 v3.0.2 h1:r+40RJR25S9w3jbA6/5uEPTzcdn7ncyU44RWCbHkLg4= -github.com/pion/transport/v3 v3.0.2/go.mod h1:nIToODoOlb5If2jF9y2Igfx3PFYWfuXi37m0IlWa/D0= +github.com/pion/rtp v1.8.9 h1:E2HX740TZKaqdcPmf4pw6ZZuG8u5RlMMt+l3dxeu6Wk= +github.com/pion/rtp v1.8.9/go.mod h1:pBGHaFt/yW7bf1jjWAoUjpSNoDnw98KTMg+jWWvziqU= +github.com/pion/transport/v3 v3.0.7 h1:iRbMH05BzSNwhILHoBoAPxoB9xQgOaJk+591KC9P1o0= +github.com/pion/transport/v3 v3.0.7/go.mod h1:YleKiTZ4vqNxVwh77Z0zytYi7rXHl7j6uPLGhhz9rwo= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= -golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= -golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= -golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= -golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= -golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/gcc/gcc.go b/pkg/gcc/gcc.go index bf32150e..1db69390 100644 --- a/pkg/gcc/gcc.go +++ b/pkg/gcc/gcc.go @@ -20,10 +20,10 @@ func maxInt(a, b int) int { return b } -func clampInt(b, min, max int) int { - return maxInt(min, minInt(max, b)) +func clampInt(b, minVal, maxVal int) int { + return maxInt(minVal, minInt(maxVal, b)) } -func clampDuration(d, min, max time.Duration) time.Duration { - return time.Duration(clampInt(int(d), int(min), int(max))) +func clampDuration(d, minVal, maxVal time.Duration) time.Duration { + return time.Duration(clampInt(int(d), int(minVal), int(maxVal))) } diff --git a/pkg/gcc/gcc_test.go b/pkg/gcc/gcc_test.go index 428b9bda..149dfd35 100644 --- a/pkg/gcc/gcc_test.go +++ b/pkg/gcc/gcc_test.go @@ -114,10 +114,10 @@ func TestClamp(t *testing.T) { }) t.Run(fmt.Sprintf("duration/%v", i), func(t *testing.T) { x := time.Duration(tt.x) - min := time.Duration(tt.min) - max := time.Duration(tt.max) + minVal := time.Duration(tt.min) + maxVal := time.Duration(tt.max) expected := time.Duration(tt.expected) - assert.Equal(t, expected, clampDuration(x, min, max)) + assert.Equal(t, expected, clampDuration(x, minVal, maxVal)) }) } } diff --git a/pkg/jitterbuffer/priority_queue.go b/pkg/jitterbuffer/priority_queue.go index f6d7d93b..11a8679c 100644 --- a/pkg/jitterbuffer/priority_queue.go +++ b/pkg/jitterbuffer/priority_queue.go @@ -114,6 +114,7 @@ func (q *PriorityQueue) Pop() (*rtp.Packet, error) { return nil, ErrInvalidOperation } val := q.next.val + q.next.val = nil q.length-- q.next = q.next.next return val, nil @@ -126,6 +127,7 @@ func (q *PriorityQueue) PopAt(sqNum uint16) (*rtp.Packet, error) { } if q.next.priority == sqNum { val := q.next.val + q.next.val = nil q.next = q.next.next q.length-- return val, nil @@ -135,6 +137,7 @@ func (q *PriorityQueue) PopAt(sqNum uint16) (*rtp.Packet, error) { for pos != nil { if pos.priority == sqNum { val := pos.val + pos.val = nil prev.next = pos.next if prev.next != nil { prev.next.prev = prev @@ -156,6 +159,7 @@ func (q *PriorityQueue) PopAtTimestamp(timestamp uint32) (*rtp.Packet, error) { } if q.next.val.Timestamp == timestamp { val := q.next.val + q.next.val = nil q.next = q.next.next q.length-- return val, nil @@ -165,6 +169,7 @@ func (q *PriorityQueue) PopAtTimestamp(timestamp uint32) (*rtp.Packet, error) { for pos != nil { if pos.val.Timestamp == timestamp { val := pos.val + pos.val = nil prev.next = pos.next if prev.next != nil { prev.next.prev = prev diff --git a/pkg/jitterbuffer/priority_queue_test.go b/pkg/jitterbuffer/priority_queue_test.go index 7fb2a7a6..8b8d23e1 100644 --- a/pkg/jitterbuffer/priority_queue_test.go +++ b/pkg/jitterbuffer/priority_queue_test.go @@ -4,7 +4,10 @@ package jitterbuffer import ( + "runtime" + "sync/atomic" "testing" + "time" "github.com/pion/rtp" "github.com/stretchr/testify/assert" @@ -136,3 +139,46 @@ func TestPriorityQueue_Clean(t *testing.T) { assert.EqualValues(t, 1, packets.Length()) packets.Clear() } + +func TestPriorityQueue_Unreference(t *testing.T) { + packets := NewQueue() + + var refs int64 + finalizer := func(*rtp.Packet) { + atomic.AddInt64(&refs, -1) + } + + numPkts := 100 + for i := 0; i < numPkts; i++ { + atomic.AddInt64(&refs, 1) + seq := uint16(i) + p := rtp.Packet{ + Header: rtp.Header{ + SequenceNumber: seq, + Timestamp: uint32(i + 42), + }, + Payload: []byte{byte(i)}, + } + runtime.SetFinalizer(&p, finalizer) + packets.Push(&p, seq) + } + for i := 0; i < numPkts-1; i++ { + switch i % 3 { + case 0: + packets.Pop() //nolint + case 1: + packets.PopAt(uint16(i)) //nolint + case 2: + packets.PopAtTimestamp(uint32(i + 42)) //nolint + } + } + + runtime.GC() + time.Sleep(10 * time.Millisecond) + + remainedRefs := atomic.LoadInt64(&refs) + runtime.KeepAlive(packets) + + // only the last packet should be still referenced + assert.Equal(t, int64(1), remainedRefs) +} diff --git a/pkg/jitterbuffer/receiver_interceptor.go b/pkg/jitterbuffer/receiver_interceptor.go index b4c032b9..404db219 100644 --- a/pkg/jitterbuffer/receiver_interceptor.go +++ b/pkg/jitterbuffer/receiver_interceptor.go @@ -64,8 +64,8 @@ func NewInterceptor(opts ...ReceiverInterceptorOption) (*InterceptorFactory, err return &InterceptorFactory{opts}, nil } -// BindRemoteStream lets you modify any incoming RTP packets. It is called once for per RemoteStream. The returned method -// will be called once per rtp packet. +// BindRemoteStream lets you modify any incoming RTP packets. It is called once per +// RemoteStream. The returned method will be called once per rtp packet. func (i *ReceiverInterceptor) BindRemoteStream(_ *interceptor.StreamInfo, reader interceptor.RTPReader) interceptor.RTPReader { return interceptor.RTPReaderFunc(func(b []byte, a interceptor.Attributes) (int, interceptor.Attributes, error) { buf := make([]byte, len(b)) @@ -74,7 +74,7 @@ func (i *ReceiverInterceptor) BindRemoteStream(_ *interceptor.StreamInfo, reader return n, attr, err } packet := &rtp.Packet{} - if err := packet.Unmarshal(buf); err != nil { + if err := packet.Unmarshal(buf[:n]); err != nil { return 0, nil, err } i.m.Lock() diff --git a/pkg/jitterbuffer/receiver_interceptor_test.go b/pkg/jitterbuffer/receiver_interceptor_test.go index 58685966..06145d38 100644 --- a/pkg/jitterbuffer/receiver_interceptor_test.go +++ b/pkg/jitterbuffer/receiver_interceptor_test.go @@ -5,6 +5,7 @@ package jitterbuffer import ( "bytes" + "errors" "testing" "time" @@ -17,8 +18,6 @@ import ( ) func TestBufferStart(t *testing.T) { - buf := bytes.Buffer{} - factory, err := NewInterceptor( Log(logging.NewDefaultLoggerFactory().NewLogger("test")), ) @@ -27,8 +26,6 @@ func TestBufferStart(t *testing.T) { i, err := factory.NewInterceptor("") assert.NoError(t, err) - assert.Zero(t, buf.Len()) - stream := test.NewMockStream(&interceptor.StreamInfo{ SSRC: 123456, ClockRate: 90000, @@ -55,7 +52,6 @@ func TestBufferStart(t *testing.T) { } err = i.Close() assert.NoError(t, err) - assert.Zero(t, buf.Len()) } func TestReceiverBuffersAndPlaysout(t *testing.T) { @@ -96,3 +92,51 @@ func TestReceiverBuffersAndPlaysout(t *testing.T) { err = i.Close() assert.NoError(t, err) } + +type MockRTPReader struct { + readFunc func([]byte, interceptor.Attributes) (int, interceptor.Attributes, error) +} + +func (m *MockRTPReader) Read(data []byte, attrs interceptor.Attributes) (int, interceptor.Attributes, error) { + if m.readFunc != nil { + return m.readFunc(data, attrs) + } + return 0, nil, errors.New("mock function not implemented") +} + +func NewMockRTPReader(readFunc func([]byte, interceptor.Attributes) (int, interceptor.Attributes, error)) *MockRTPReader { + return &MockRTPReader{ + readFunc: readFunc, + } +} + +func TestReceiverInterceptorHonorsBufferLength(t *testing.T) { + buf := []byte{0x80, 0x88, 0xe6, 0xfd, 0x01, 0x01, 0x01, 0x01, 0x01, + 0xde, 0xad, 0xbe, 0xef, 0x01, 0x01, 0x01, 0x01, 0x01} + readBuf := make([]byte, 2048) + copy(readBuf[0:], buf) + copy(readBuf[17:], buf) + factory, err := NewInterceptor( + Log(logging.NewDefaultLoggerFactory().NewLogger("test")), + ) + assert.NoError(t, err) + + i, err := factory.NewInterceptor("") + + rtpReadFn := NewMockRTPReader(func(data []byte, attrs interceptor.Attributes) (int, interceptor.Attributes, error) { + copy(data, readBuf) + return 7, attrs, nil + }) + reader := i.BindRemoteStream(&interceptor.StreamInfo{ + SSRC: 123456, + ClockRate: 90000, + }, rtpReadFn) + + bufLen, _, err := reader.Read(readBuf, interceptor.Attributes{}) + assert.Contains(t, err.Error(), "7 < 12") + assert.Equal(t, 0, bufLen) + + err = i.Close() + assert.NoError(t, err) + +} diff --git a/pkg/nack/receive_log_test.go b/pkg/nack/receive_log_test.go index ef459248..1bbdb8ea 100644 --- a/pkg/nack/receive_log_test.go +++ b/pkg/nack/receive_log_test.go @@ -19,9 +19,9 @@ func TestReceivedBuffer(t *testing.T) { t.Fatalf("%+v", err) } - all := func(min uint16, max uint16) []uint16 { + all := func(minVal uint16, maxVal uint16) []uint16 { result := make([]uint16, 0) - for i := min; i != max+1; i++ { + for i := minVal; i != maxVal+1; i++ { result = append(result, i) } return result diff --git a/pkg/stats/stats_recorder.go b/pkg/stats/stats_recorder.go index a9338ee2..a35d0624 100644 --- a/pkg/stats/stats_recorder.go +++ b/pkg/stats/stats_recorder.go @@ -227,7 +227,7 @@ func (r *recorder) recordIncomingRR(latestStats internalStats, pkt *rtcp.Receive latestStats.RemoteInboundRTPStreamStats.Jitter = float64(report.Jitter) / r.clockRate if report.Delay != 0 && report.LastSenderReport != 0 { - for i := min(r.maxLastSenderReports, len(latestStats.lastSenderReports)) - 1; i >= 0; i-- { + for i := minInt(r.maxLastSenderReports, len(latestStats.lastSenderReports)) - 1; i >= 0; i-- { lastReport := latestStats.lastSenderReports[i] if (lastReport&0x0000FFFFFFFF0000)>>16 == uint64(report.LastSenderReport) { dlsr := time.Duration(float64(report.Delay) / 65536.0 * float64(time.Second)) @@ -248,7 +248,7 @@ func (r *recorder) recordIncomingXR(latestStats internalStats, pkt *rtcp.Extende if xr, ok := report.(*rtcp.DLRRReportBlock); ok { for _, xrReport := range xr.Reports { if xrReport.LastRR != 0 && xrReport.DLRR != 0 { - for i := min(r.maxLastReceiverReferenceTimes, len(latestStats.lastReceiverReferenceTimes)) - 1; i >= 0; i-- { + for i := minInt(r.maxLastReceiverReferenceTimes, len(latestStats.lastReceiverReferenceTimes)) - 1; i >= 0; i-- { lastRR := latestStats.lastReceiverReferenceTimes[i] if (lastRR&0x0000FFFFFFFF0000)>>16 == uint64(xrReport.LastRR) { dlrr := time.Duration(float64(xrReport.DLRR) / 65536.0 * float64(time.Second)) @@ -377,7 +377,7 @@ func (r *recorder) QueueOutgoingRTCP(ts time.Time, pkts []rtcp.Packet, attr inte r.ms.Unlock() } -func min(a, b int) int { +func minInt(a, b int) int { if a < b { return a } diff --git a/pkg/twcc/arrival_time_map.go b/pkg/twcc/arrival_time_map.go index abca1ff5..d3e2a8af 100644 --- a/pkg/twcc/arrival_time_map.go +++ b/pkg/twcc/arrival_time_map.go @@ -170,9 +170,9 @@ func (m *packetArrivalTimeMap) adjustToSize(newSize int) { } m.reallocate(newCapacity) } - if m.capacity() > max(minCapacity, newSize*4) { + if m.capacity() > maxInt(minCapacity, newSize*4) { newCapacity := m.capacity() - for newCapacity >= 2*max(newSize, minCapacity) { + for newCapacity >= 2*maxInt(newSize, minCapacity) { newCapacity /= 2 } m.reallocate(newCapacity) diff --git a/pkg/twcc/twcc.go b/pkg/twcc/twcc.go index c7246f30..6464c77b 100644 --- a/pkg/twcc/twcc.go +++ b/pkg/twcc/twcc.go @@ -307,7 +307,7 @@ func (c *chunk) encode() rtcp.PacketStatusChunk { } } - minCap := min(maxTwoBitCap, len(c.deltas)) + minCap := minInt(maxTwoBitCap, len(c.deltas)) svc := &rtcp.StatusVectorChunk{ SymbolSize: rtcp.TypeTCCSymbolSizeTwoBit, SymbolList: c.deltas[:minCap], @@ -337,14 +337,14 @@ func (c *chunk) reset() { c.hasDifferentTypes = false } -func max(a, b int) int { +func maxInt(a, b int) int { if a > b { return a } return b } -func min(a, b int) int { +func minInt(a, b int) int { if a < b { return a }