Skip to content

Add FIR, BWE bitrate, and quality-limitation to TrackStats#159

Open
lkang-nuro wants to merge 1 commit into
mainfrom
lkang/track-stats-ra-metrics
Open

Add FIR, BWE bitrate, and quality-limitation to TrackStats#159
lkang-nuro wants to merge 1 commit into
mainfrom
lkang/track-stats-ra-metrics

Conversation

@lkang-nuro

Copy link
Copy Markdown
Contributor

Summary

Extends RTCSender.GetTrackStats so downstream RealtimeAnalytics metrics have real sources, without changing audio behavior.

  • FIRCount — copied from the Pion stats interceptor's OutboundRTPStreamStats (feeds ra_webrtc_fir_count).
  • AvailableOutgoingBitrate — latest GCC estimate (connection-level), stored by the Start loop. TargetBitrate — the per-track allocated share pushed to the encoder, stored in updateBitrate (feed ra_webrtc_available_outgoing_bitrate_bps / ra_webrtc_target_bitrate_bps).
  • QualityLimitation{CPU,Bandwidth}Seconds — synthesized per ≈100ms tick in accumulateQualityLimitation, since pion provides no encoder feedback (feed ra_video_encoder_quality_limitation_{cpu,bandwidth}_seconds):
    • bandwidth-limited when the GCC estimate sits below the configured max bitrate;
    • CPU-limited when the encode loop falls behind (buffer eviction, tracked via encodeOverruns);
    • when GCC has no max cap, bandwidth-limited cannot be inferred and stays zero.

Out of scope

Audio send-side stats (ra_audio_*) are deferred. Audio tracks remain published externally via LiveKit and are not added to the sender's PeerConnection, so audio behavior is unchanged from main.

Testing

  • go build ./..., go vet ./...
  • go test ./sender/... (incl. new BitrateFields, QualityLimitation cpu/bandwidth, and FIRCount assertions)
  • go test -race -run 'GetTrackStats|AddAudioTrack|SetupPeerConnection|QualityLimitation' ./sender/...
  • golangci-lint run ./sender/... — 0 issues

🤖 Generated with Claude Code

@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.65517% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 46.63%. Comparing base (39c6229) to head (b878ed8).

Files with missing lines Patch % Lines
sender/rtc_sender.go 89.65% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #159      +/-   ##
==========================================
+ Coverage   46.03%   46.63%   +0.60%     
==========================================
  Files          18       18              
  Lines        1803     1829      +26     
==========================================
+ Hits          830      853      +23     
- Misses        905      907       +2     
- Partials       68       69       +1     
Flag Coverage Δ
go 46.63% <89.65%> (+0.60%) ⬆️

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.

Extend RTCSender.GetTrackStats so downstream RealtimeAnalytics
metrics have real sources:

- FIRCount: copied from the Pion stats interceptor's
  OutboundRTPStreamStats.
- AvailableOutgoingBitrate: latest GCC estimate (connection-level),
  stored by the Start loop. TargetBitrate: the per-track allocated
  share pushed to the encoder, stored in updateBitrate.
- QualityLimitation{CPU,Bandwidth}Seconds: synthesized per ~100ms
  tick in accumulateQualityLimitation, since pion provides no
  encoder feedback. Bandwidth-limited when the GCC estimate sits
  below the configured max bitrate; CPU-limited when the encode
  loop falls behind (buffer eviction, tracked via encodeOverruns).
  When GCC has no max cap, bandwidth-limited cannot be inferred
  and stays zero.

Audio send-side stats are out of scope for now; audio tracks
remain published externally via LiveKit and are not added to the
sender's PeerConnection.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@lkang-nuro lkang-nuro force-pushed the lkang/track-stats-ra-metrics branch from 89d7b56 to b878ed8 Compare June 25, 2026 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant