Apply go modernize suggestions

This commit is contained in:
philipch07
2025-09-14 17:13:05 -04:00
committed by philipch07
parent 781ff736bf
commit 39d1b3cb9d
6 changed files with 21 additions and 53 deletions

View File

@@ -13,6 +13,7 @@ import (
"errors"
"fmt"
"io"
"slices"
"strconv"
"strings"
"sync"
@@ -1695,10 +1696,8 @@ func (pc *PeerConnection) handleIncomingSSRC(rtpStream io.Reader, ssrc SSRC) err
if track.fecSsrc != nil && ssrc == *track.fecSsrc {
return nil
}
for _, trackSsrc := range track.ssrcs {
if ssrc == trackSsrc {
return nil
}
if slices.Contains(track.ssrcs, ssrc) {
return nil
}
}

View File

@@ -65,12 +65,8 @@ func (reader *H264Reader) read(numToRead int) (data []byte, e error) {
}
reader.readBuffer = append(reader.readBuffer, reader.tmpReadBuf[0:n]...)
}
var numShouldRead int
if numToRead <= len(reader.readBuffer) {
numShouldRead = numToRead
} else {
numShouldRead = len(reader.readBuffer)
}
numShouldRead := min(numToRead, len(reader.readBuffer))
data = reader.readBuffer[0:numShouldRead]
reader.readBuffer = reader.readBuffer[numShouldRead:]

View File

@@ -72,12 +72,8 @@ func (reader *H265Reader) read(numToRead int) (data []byte, e error) {
}
reader.readBuffer = append(reader.readBuffer, reader.tmpReadBuf[0:n]...)
}
var numShouldRead int
if numToRead <= len(reader.readBuffer) {
numShouldRead = numToRead
} else {
numShouldRead = len(reader.readBuffer)
}
numShouldRead := min(numToRead, len(reader.readBuffer))
data = reader.readBuffer[0:numShouldRead]
reader.readBuffer = reader.readBuffer[numShouldRead:]

View File

@@ -6,6 +6,7 @@ package samplebuilder
import (
"fmt"
"runtime"
"slices"
"sync/atomic"
"testing"
"time"
@@ -52,13 +53,7 @@ func (f *fakeDepacketizer) IsPartitionHead(payload []byte) bool {
return true
}
for _, b := range f.headBytes {
if payload[0] == b {
return true
}
}
return false
return slices.Contains(f.headBytes, payload[0])
}
func (f *fakeDepacketizer) IsPartitionTail(marker bool, _ []byte) bool {

View File

@@ -3,6 +3,8 @@
package webrtc
import "slices"
// RTPTransceiverDirection indicates the direction of the RTPTransceiver.
type RTPTransceiverDirection int
@@ -84,10 +86,8 @@ func haveRTPTransceiverDirectionIntersection(
needle []RTPTransceiverDirection,
) bool {
for _, n := range needle {
for _, h := range haystack {
if n == h {
return true
}
if slices.Contains(haystack, n) {
return true
}
}

34
sdp.go
View File

@@ -11,6 +11,7 @@ import (
"fmt"
"net/url"
"regexp"
"slices"
"strconv"
"strings"
"sync/atomic"
@@ -35,10 +36,8 @@ type trackDetails struct {
func trackDetailsForSSRC(trackDetails []trackDetails, ssrc SSRC) *trackDetails {
for i := range trackDetails {
for j := range trackDetails[i].ssrcs {
if trackDetails[i].ssrcs[j] == ssrc {
return &trackDetails[i]
}
if slices.Contains(trackDetails[i].ssrcs, ssrc) {
return &trackDetails[i]
}
}
@@ -51,10 +50,8 @@ func trackDetailsForRID(trackDetails []trackDetails, mid, rid string) *trackDeta
continue
}
for j := range trackDetails[i].rids {
if trackDetails[i].rids[j] == rid {
return &trackDetails[i]
}
if slices.Contains(trackDetails[i].rids, rid) {
return &trackDetails[i]
}
}
@@ -64,13 +61,7 @@ func trackDetailsForRID(trackDetails []trackDetails, mid, rid string) *trackDeta
func filterTrackWithSSRC(incomingTracks []trackDetails, ssrc SSRC) []trackDetails {
filtered := []trackDetails{}
doesTrackHaveSSRC := func(t trackDetails) bool {
for i := range t.ssrcs {
if t.ssrcs[i] == ssrc {
return true
}
}
return false
return slices.Contains(t.ssrcs, ssrc)
}
for i := range incomingTracks {
@@ -268,10 +259,7 @@ func trackDetailsFromSDP(
}
func trackDetailsToRTPReceiveParameters(trackDetails *trackDetails) RTPReceiveParameters {
encodingSize := len(trackDetails.ssrcs)
if len(trackDetails.rids) >= encodingSize {
encodingSize = len(trackDetails.rids)
}
encodingSize := max(len(trackDetails.rids), len(trackDetails.ssrcs))
encodings := make([]RTPDecodingParameters, encodingSize)
for i := range encodings {
@@ -693,13 +681,7 @@ func bundleMatchFromRemote(matchBundleGroup *string) func(mid string) bool {
bundleTags := strings.Split(*matchBundleGroup, " ")
return func(midValue string) bool {
for _, tag := range bundleTags {
if tag == midValue {
return true
}
}
return false
return slices.Contains(bundleTags, midValue)
}
}