mirror of
https://github.com/pion/webrtc.git
synced 2025-09-27 03:25:58 +08:00
Apply go modernize suggestions
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -1695,12 +1696,10 @@ 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 {
|
||||
if slices.Contains(track.ssrcs, ssrc) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if the SSRC is not declared in the SDP and there is only one media section,
|
||||
// we attempt to resolve it using this single section
|
||||
|
@@ -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:]
|
||||
|
||||
|
@@ -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:]
|
||||
|
||||
|
@@ -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 {
|
||||
|
@@ -3,6 +3,8 @@
|
||||
|
||||
package webrtc
|
||||
|
||||
import "slices"
|
||||
|
||||
// RTPTransceiverDirection indicates the direction of the RTPTransceiver.
|
||||
type RTPTransceiverDirection int
|
||||
|
||||
@@ -84,12 +86,10 @@ func haveRTPTransceiverDirectionIntersection(
|
||||
needle []RTPTransceiverDirection,
|
||||
) bool {
|
||||
for _, n := range needle {
|
||||
for _, h := range haystack {
|
||||
if n == h {
|
||||
if slices.Contains(haystack, n) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
30
sdp.go
30
sdp.go
@@ -11,6 +11,7 @@ import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
@@ -35,12 +36,10 @@ 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 {
|
||||
if slices.Contains(trackDetails[i].ssrcs, ssrc) {
|
||||
return &trackDetails[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -51,12 +50,10 @@ func trackDetailsForRID(trackDetails []trackDetails, mid, rid string) *trackDeta
|
||||
continue
|
||||
}
|
||||
|
||||
for j := range trackDetails[i].rids {
|
||||
if trackDetails[i].rids[j] == rid {
|
||||
if slices.Contains(trackDetails[i].rids, rid) {
|
||||
return &trackDetails[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user