Skip to content

Make GetRTCPPackets and GetRTPHeader nil-safe#431

Merged
kcaffrey merged 1 commit into
pion:mainfrom
kcaffrey:nil-attributes
Jul 24, 2026
Merged

Make GetRTCPPackets and GetRTPHeader nil-safe#431
kcaffrey merged 1 commit into
pion:mainfrom
kcaffrey:nil-attributes

Conversation

@kcaffrey

Copy link
Copy Markdown
Contributor

Allow both GetRTCPPackets() and GetRTPHeader() to be called on nil attributes without panicking. Instead, they will unmarshal but not cache the results when called on a nil receiver.

See the discussion in pion/webrtc#3483 for more background on this change.

Allow both `GetRTCPPackets()` and `GetRTPHeader()` to be called on nil
attributes without panicking. Instead, they will unmarshal but not cache
the results when called on a nil receiver.
@kcaffrey
kcaffrey requested a review from JoTurk July 24, 2026 19:59
@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.15%. Comparing base (a01a583) to head (18f83da).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #431   +/-   ##
=======================================
  Coverage   80.14%   80.15%           
=======================================
  Files          88       88           
  Lines        4623     4625    +2     
=======================================
+ Hits         3705     3707    +2     
  Misses        735      735           
  Partials      183      183           
Flag Coverage Δ
go 80.15% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kcaffrey
kcaffrey merged commit 341ec2d into pion:main Jul 24, 2026
18 checks passed
kcaffrey added a commit to kcaffrey/webrtc that referenced this pull request Jul 24, 2026
Currently an interceptor.Attributes map is allocated for each RTP write.
However, interceptors only strictly need to allocate an attributes map
when wanting to set a value. None of the default interceptors currently
allocate a new map when passed nil on the write path. The
gcc.SendSideBWE interceptor, when TWCC is negotiated, does allocate
attributes for every outbound packet. Thus, by sending nil instead of
allocating a new map, we can save one allocation per `WriteRTP()`

All interceptors in pion/interceptor are already safe with nil
attributes on the write path, and pion/interceptor#431 made
`GetRTPHeader()` and `GetRTCPPackets()` safe to call on nil attributes.
Users with custom interceptors should ensure that attributes is always
checked for nil before calling `Set()`.

The benchmark added in this package shows a reduction of allocations for
a write+read round trip from 8 allocs/op to 7 allocs/op.
kcaffrey added a commit to pion/webrtc that referenced this pull request Jul 24, 2026
Currently an interceptor.Attributes map is allocated for each RTP write.
However, interceptors only strictly need to allocate an attributes map
when wanting to set a value. None of the default interceptors currently
allocate a new map when passed nil on the write path. The
gcc.SendSideBWE interceptor, when TWCC is negotiated, does allocate
attributes for every outbound packet. Thus, by sending nil instead of
allocating a new map, we can save one allocation per `WriteRTP()`
 
All interceptors in pion/interceptor are already safe with nil
attributes on the write path, and pion/interceptor#431 made
`GetRTPHeader()` and `GetRTCPPackets()` safe to call on nil attributes.
Users with custom interceptors should ensure that attributes is always
checked for nil before calling `Set()`.
 
The benchmark added in this package shows a reduction of allocations for
a write+read round trip from 8 allocs/op to 7 allocs/op.
@kcaffrey
kcaffrey deleted the nil-attributes branch July 24, 2026 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants