mirror of
https://github.com/pion/webrtc.git
synced 2025-10-05 15:16:52 +08:00
Apply go modernize suggestions
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -1695,12 +1696,10 @@ func (pc *PeerConnection) handleIncomingSSRC(rtpStream io.Reader, ssrc SSRC) err
|
|||||||
if track.fecSsrc != nil && ssrc == *track.fecSsrc {
|
if track.fecSsrc != nil && ssrc == *track.fecSsrc {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for _, trackSsrc := range track.ssrcs {
|
if slices.Contains(track.ssrcs, ssrc) {
|
||||||
if ssrc == trackSsrc {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// if the SSRC is not declared in the SDP and there is only one media section,
|
// 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
|
// 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]...)
|
reader.readBuffer = append(reader.readBuffer, reader.tmpReadBuf[0:n]...)
|
||||||
}
|
}
|
||||||
var numShouldRead int
|
|
||||||
if numToRead <= len(reader.readBuffer) {
|
numShouldRead := min(numToRead, len(reader.readBuffer))
|
||||||
numShouldRead = numToRead
|
|
||||||
} else {
|
|
||||||
numShouldRead = len(reader.readBuffer)
|
|
||||||
}
|
|
||||||
data = reader.readBuffer[0:numShouldRead]
|
data = reader.readBuffer[0:numShouldRead]
|
||||||
reader.readBuffer = reader.readBuffer[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]...)
|
reader.readBuffer = append(reader.readBuffer, reader.tmpReadBuf[0:n]...)
|
||||||
}
|
}
|
||||||
var numShouldRead int
|
|
||||||
if numToRead <= len(reader.readBuffer) {
|
numShouldRead := min(numToRead, len(reader.readBuffer))
|
||||||
numShouldRead = numToRead
|
|
||||||
} else {
|
|
||||||
numShouldRead = len(reader.readBuffer)
|
|
||||||
}
|
|
||||||
data = reader.readBuffer[0:numShouldRead]
|
data = reader.readBuffer[0:numShouldRead]
|
||||||
reader.readBuffer = reader.readBuffer[numShouldRead:]
|
reader.readBuffer = reader.readBuffer[numShouldRead:]
|
||||||
|
|
||||||
|
@@ -6,6 +6,7 @@ package samplebuilder
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"slices"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@@ -52,13 +53,7 @@ func (f *fakeDepacketizer) IsPartitionHead(payload []byte) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, b := range f.headBytes {
|
return slices.Contains(f.headBytes, payload[0])
|
||||||
if payload[0] == b {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *fakeDepacketizer) IsPartitionTail(marker bool, _ []byte) bool {
|
func (f *fakeDepacketizer) IsPartitionTail(marker bool, _ []byte) bool {
|
||||||
|
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
package webrtc
|
package webrtc
|
||||||
|
|
||||||
|
import "slices"
|
||||||
|
|
||||||
// RTPTransceiverDirection indicates the direction of the RTPTransceiver.
|
// RTPTransceiverDirection indicates the direction of the RTPTransceiver.
|
||||||
type RTPTransceiverDirection int
|
type RTPTransceiverDirection int
|
||||||
|
|
||||||
@@ -84,12 +86,10 @@ func haveRTPTransceiverDirectionIntersection(
|
|||||||
needle []RTPTransceiverDirection,
|
needle []RTPTransceiverDirection,
|
||||||
) bool {
|
) bool {
|
||||||
for _, n := range needle {
|
for _, n := range needle {
|
||||||
for _, h := range haystack {
|
if slices.Contains(haystack, n) {
|
||||||
if n == h {
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
30
sdp.go
30
sdp.go
@@ -11,6 +11,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
@@ -35,12 +36,10 @@ type trackDetails struct {
|
|||||||
|
|
||||||
func trackDetailsForSSRC(trackDetails []trackDetails, ssrc SSRC) *trackDetails {
|
func trackDetailsForSSRC(trackDetails []trackDetails, ssrc SSRC) *trackDetails {
|
||||||
for i := range trackDetails {
|
for i := range trackDetails {
|
||||||
for j := range trackDetails[i].ssrcs {
|
if slices.Contains(trackDetails[i].ssrcs, ssrc) {
|
||||||
if trackDetails[i].ssrcs[j] == ssrc {
|
|
||||||
return &trackDetails[i]
|
return &trackDetails[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -51,12 +50,10 @@ func trackDetailsForRID(trackDetails []trackDetails, mid, rid string) *trackDeta
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
for j := range trackDetails[i].rids {
|
if slices.Contains(trackDetails[i].rids, rid) {
|
||||||
if trackDetails[i].rids[j] == rid {
|
|
||||||
return &trackDetails[i]
|
return &trackDetails[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -64,13 +61,7 @@ func trackDetailsForRID(trackDetails []trackDetails, mid, rid string) *trackDeta
|
|||||||
func filterTrackWithSSRC(incomingTracks []trackDetails, ssrc SSRC) []trackDetails {
|
func filterTrackWithSSRC(incomingTracks []trackDetails, ssrc SSRC) []trackDetails {
|
||||||
filtered := []trackDetails{}
|
filtered := []trackDetails{}
|
||||||
doesTrackHaveSSRC := func(t trackDetails) bool {
|
doesTrackHaveSSRC := func(t trackDetails) bool {
|
||||||
for i := range t.ssrcs {
|
return slices.Contains(t.ssrcs, ssrc)
|
||||||
if t.ssrcs[i] == ssrc {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range incomingTracks {
|
for i := range incomingTracks {
|
||||||
@@ -268,10 +259,7 @@ func trackDetailsFromSDP(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func trackDetailsToRTPReceiveParameters(trackDetails *trackDetails) RTPReceiveParameters {
|
func trackDetailsToRTPReceiveParameters(trackDetails *trackDetails) RTPReceiveParameters {
|
||||||
encodingSize := len(trackDetails.ssrcs)
|
encodingSize := max(len(trackDetails.rids), len(trackDetails.ssrcs))
|
||||||
if len(trackDetails.rids) >= encodingSize {
|
|
||||||
encodingSize = len(trackDetails.rids)
|
|
||||||
}
|
|
||||||
|
|
||||||
encodings := make([]RTPDecodingParameters, encodingSize)
|
encodings := make([]RTPDecodingParameters, encodingSize)
|
||||||
for i := range encodings {
|
for i := range encodings {
|
||||||
@@ -693,13 +681,7 @@ func bundleMatchFromRemote(matchBundleGroup *string) func(mid string) bool {
|
|||||||
bundleTags := strings.Split(*matchBundleGroup, " ")
|
bundleTags := strings.Split(*matchBundleGroup, " ")
|
||||||
|
|
||||||
return func(midValue string) bool {
|
return func(midValue string) bool {
|
||||||
for _, tag := range bundleTags {
|
return slices.Contains(bundleTags, midValue)
|
||||||
if tag == midValue {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user