Skip to content

Commit

Permalink
Fix slice re-use bug and set better defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
mengelbart committed Dec 15, 2021
1 parent b340576 commit b559316
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
19 changes: 13 additions & 6 deletions pkg/gcc/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ func (f *InterceptorFactory) NewInterceptor(id string) (interceptor.Interceptor,
i := &Interceptor{
NoOp: interceptor.NoOp{},
lock: sync.Mutex{},
bitrate: 0,
bitrate: 100_000,
latestStats: &Stats{},
pacer: nil,
FeedbackAdapter: nil,
loss: nil,
Expand All @@ -67,8 +68,8 @@ func (f *InterceptorFactory) NewInterceptor(id string) (interceptor.Interceptor,
}
}

i.pacer = NewLeakyBucketPacer()
i.FeedbackAdapter = NewFeedbackAdapter()
i.pacer = NewLeakyBucketPacer(i.bitrate)
i.loss = newLossBasedBWE(i.bitrate)
i.delay = newDelayBasedBWE(i.bitrate)

Expand Down Expand Up @@ -154,11 +155,15 @@ func (c *Interceptor) BindRTCPReader(reader interceptor.RTCPReader) interceptor.
if err != nil {
return 0, nil, err
}
buf := make([]byte, i)

copy(buf, b[:i])

if attr == nil {
attr = make(interceptor.Attributes)
}

pkts, err := attr.GetRTCPPackets(b[:i])
pkts, err := attr.GetRTCPPackets(buf[:i])
if err != nil {
return 0, nil, err
}
Expand Down Expand Up @@ -195,9 +200,11 @@ func (c *Interceptor) BindLocalStream(info *interceptor.StreamInfo, writer inter
}
attributes.Set(twccExtensionAttributesKey, hdrExtID)
}
co := make([]byte, len(payload))
copy(co, payload)
c.packet <- &packetAndAttributes{
header: *header,
payload: payload,
header: header.Clone(),
payload: co,
attributes: attributes,
}

Expand All @@ -212,7 +219,7 @@ func (c *Interceptor) Close() error {
}

func (c *Interceptor) loop() {
ticker := time.NewTicker(500 * time.Millisecond)
ticker := time.NewTicker(200 * time.Millisecond)
for {
select {
case <-c.close:
Expand Down
4 changes: 2 additions & 2 deletions pkg/gcc/leaky_bucket_pacer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ type LeakyBucketPacer struct {
}

// NewLeakyBucketPacer initializes a new LeakyBucketPacer
func NewLeakyBucketPacer() *LeakyBucketPacer {
func NewLeakyBucketPacer(initialBitrate int) *LeakyBucketPacer {
p := &LeakyBucketPacer{
log: logging.NewDefaultLoggerFactory().NewLogger("pacer"),
f: 1.5,
targetBitrate: 150_000,
targetBitrate: initialBitrate,
pacingInterval: 5 * time.Millisecond,
itemCh: make(chan item),
bitrateCh: make(chan int),
Expand Down
3 changes: 3 additions & 0 deletions pkg/gcc/noop_pacer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ func NewNoOpPacer() *NoOpPacer {
}
}

func (p *NoOpPacer) SetTargetBitrate(int) {
}

// AddStream adds a stream and corresponding writer to the p
func (p *NoOpPacer) AddStream(ssrc uint32, writer interceptor.RTPWriter) {
p.lock.Lock()
Expand Down

0 comments on commit b559316

Please sign in to comment.