Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions pkg/flexfec/flexfec_decoder_03.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func (d *fecDecoder) recoverPacket(fec *fecPacketState) (rtp.Packet, error) {
if err != nil {
return rtp.Packet{}, fmt.Errorf("marshal protected packet: %w", err)
}
for i := 0; i < minInt(int(payloadLength), len(packet)-12); i++ {
for i := 0; i < min(int(payloadLength), len(packet)-12); i++ {
payloadRecovery[i] ^= packet[12+i]
}
}
Expand Down Expand Up @@ -407,23 +407,7 @@ func parseFlexFEC03Header(data []byte) (flexFec, error) {
}

func seqDiff(a, b uint16) uint16 {
return minUInt16(a-b, b-a)
}

func minInt(a, b int) int {
if a < b {
return a
}

return b
}

func minUInt16(a, b uint16) uint16 {
if a < b {
return a
}

return b
return min(a-b, b-a)
}

func abs(x int) int {
Expand Down
4 changes: 2 additions & 2 deletions pkg/gcc/adaptive_threshold.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (a *adaptiveThreshold) compare(estimate, _ time.Duration) (usage, time.Dura
if a.numDeltas < 2 {
return usageNormal, estimate, a.max
}
t := time.Duration(minInt(a.numDeltas, maxDeltas)) * estimate
t := time.Duration(min(a.numDeltas, maxDeltas)) * estimate
use := usageNormal
if t > a.thresh {
use = usageOver
Expand Down Expand Up @@ -96,7 +96,7 @@ func (a *adaptiveThreshold) update(estimate time.Duration) {
}
maxTimeDelta := 100 * time.Millisecond
timeDelta := time.Duration(
minInt(int(now.Sub(a.lastUpdate).Milliseconds()), int(maxTimeDelta.Milliseconds())),
min(int(now.Sub(a.lastUpdate).Milliseconds()), int(maxTimeDelta.Milliseconds())),
) * time.Millisecond
d := absEstimate - a.thresh
add := k * float64(d.Milliseconds()) * float64(timeDelta.Milliseconds())
Expand Down
10 changes: 1 addition & 9 deletions pkg/gcc/gcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ package gcc

import "time"

func minInt(a, b int) int {
if a < b {
return a
}

return b
}

func maxInt(a, b int) int {
if a > b {
return a
Expand All @@ -23,7 +15,7 @@ func maxInt(a, b int) int {
}

func clampInt(b, minVal, maxVal int) int {
return maxInt(minVal, minInt(maxVal, b))
return maxInt(minVal, min(maxVal, b))
}

func clampDuration(d, minVal, maxVal time.Duration) time.Duration {
Expand Down
29 changes: 0 additions & 29 deletions pkg/gcc/gcc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,6 @@ import (
"github.com/stretchr/testify/assert"
)

func TestMinInt(t *testing.T) {
tests := []struct {
expected int
a, b int
}{
{
expected: 0,
a: 0,
b: 100,
},
{
expected: 10,
a: 10,
b: 10,
},
{
expected: 1,
a: 10,
b: 1,
},
}
for i, tt := range tests {
tt := tt
t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
assert.Equal(t, tt.expected, minInt(tt.a, tt.b))
})
}
}

func TestMaxInt(t *testing.T) {
tests := []struct {
expected int
Expand Down
2 changes: 1 addition & 1 deletion pkg/gcc/loss_based_bwe.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (e *lossBasedBandwidthEstimator) getEstimate(wantedRate int) LossStats {
if e.bitrate <= 0 {
e.bitrate = clampInt(wantedRate, e.minBitrate, e.maxBitrate)
}
e.bitrate = minInt(wantedRate, e.bitrate)
e.bitrate = min(wantedRate, e.bitrate)

return LossStats{
TargetBitrate: e.bitrate,
Expand Down
4 changes: 2 additions & 2 deletions pkg/gcc/send_side_bwe.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (e *SendSideBWE) WriteRTCP(pkts []rtcp.Packet, _ interceptor.Attributes) er
}
pendingTime := feedbackSentTime.Sub(ack.Arrival)
rtt := now.Sub(ack.Departure) - pendingTime
feedbackMinRTT = time.Duration(minInt(int(rtt), int(feedbackMinRTT)))
feedbackMinRTT = time.Duration(min(int(rtt), int(feedbackMinRTT)))
}
if feedbackMinRTT < math.MaxInt {
e.delayController.updateRTT(feedbackMinRTT)
Expand Down Expand Up @@ -283,7 +283,7 @@ func (e *SendSideBWE) onDelayUpdate(delayStats DelayStats) {

lossStats := e.lossController.getEstimate(delayStats.TargetBitrate)
bitrateChanged := false
bitrate := minInt(delayStats.TargetBitrate, lossStats.TargetBitrate)
bitrate := min(delayStats.TargetBitrate, lossStats.TargetBitrate)
if bitrate != e.latestBitrate {
bitrateChanged = true
e.latestBitrate = bitrate
Expand Down
12 changes: 2 additions & 10 deletions pkg/stats/stats_recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,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 := minInt(r.maxLastSenderReports, len(latestStats.lastSenderReports)) - 1; i >= 0; i-- {
for i := min(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))
Expand All @@ -272,7 +272,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 := minInt(r.maxLastReceiverReferenceTimes, len(latestStats.lastReceiverReferenceTimes)) - 1; i >= 0; i-- {
for i := min(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))
Expand Down Expand Up @@ -407,11 +407,3 @@ func (r *recorder) QueueOutgoingRTCP(ts time.Time, pkts []rtcp.Packet, attr inte
})
r.ms.Unlock()
}

func minInt(a, b int) int {
if a < b {
return a
}

return b
}
2 changes: 1 addition & 1 deletion pkg/twcc/arrival_time_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (m *packetArrivalTimeMap) EraseTo(sequenceNumber int64) {
// RemoveOldPackets removes packets from the beginning of the map as long as they are before
// sequenceNumber and with an age older than arrivalTimeLimit.
func (m *packetArrivalTimeMap) RemoveOldPackets(sequenceNumber int64, arrivalTimeLimit int64) {
checkTo := min64(sequenceNumber, m.endSequenceNumber)
checkTo := min(sequenceNumber, m.endSequenceNumber)
for m.beginSequenceNumber < checkTo && m.get(m.beginSequenceNumber) <= arrivalTimeLimit {
m.beginSequenceNumber++
}
Expand Down
18 changes: 1 addition & 17 deletions pkg/twcc/twcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func (c *chunk) encode() rtcp.PacketStatusChunk {
}
}

minCap := minInt(maxTwoBitCap, len(c.deltas))
minCap := min(maxTwoBitCap, len(c.deltas))
svc := &rtcp.StatusVectorChunk{
SymbolSize: rtcp.TypeTCCSymbolSizeTwoBit,
SymbolList: c.deltas[:minCap],
Expand Down Expand Up @@ -356,26 +356,10 @@ func maxInt(a, b int) int {
return b
}

func minInt(a, b int) int {
if a < b {
return a
}

return b
}

func max64(a, b int64) int64 {
if a > b {
return a
}

return b
}

func min64(a, b int64) int64 {
if a < b {
return a
}

return b
}
Loading