webrtc
webrtc copied to clipboard
Add support for emitting inbound-rtp and media-playout stats from PeerConnection.GetStats
What version of Pion are you using?
v4.1.1
Current behaviour
StatsTypeInboundRTP ("inbound-rtp") and StatsTypeMediaPlayout ("media-playout") are defined in stats.go, but they are never instantiated or added to the StatsReport returned by PeerConnection.GetStats().
Calling pc.GetStats() on an actively receiving connection returns:
- ICE / DTLS / SCTP transport stats
- Candidate pair & certificate stats
- Codec stats
- A synthetic peer-connection node
...but no inbound-rtp or media-playout objects, so applications cannot obtain basic per-SSRC metrics (bytes/packets/jitter, etc.) or audio-playout metrics.
Expected behaviour (per WebRTC-Stats spec)
GetStats() should include:
- At least one
InboundRTPStreamStatsentry for every primary SSRC the RTPReceiver is consuming - Optionally an
AudioPlayoutStatsentry (or equivalent) describing local audio playout for that track - Key fields such as
packetsReceived,packetsLost,jitter,bytesReceived,framesDecoded, etc. should be populated
Root cause analysis
PeerConnection.GetStats() only collects from:
- ICEGatherer / ICETransport
- DTLSTransport / SCTPTransport
- DataChannels
- Certificates
- MediaEngine
- A synthetic PeerConnectionStats
No collectStats method exists for:
- RTPReceiver
- RTPSender
- TrackRemote
- Any audio-playout component
Therefore the structs defined in stats.go are never instantiated.
Minimal Repro
package main
import (
"fmt"
"github.com/pion/webrtc/v4"
)
func main() {
pc, _ := webrtc.NewPeerConnection(webrtc.Configuration{})
// Set up remote SDP, receive an audio/video track...
stats := pc.GetStats()
for id, s := range stats {
fmt.Printf("%s → %s\n", id, s.Type())
}
// No item prints "inbound-rtp" or "media-playout"
}
Proposed fix
- Implement
collectStats()on media objectsRTPReceiver.collectStats()→ build anInboundRTPStreamStatsper SSRC- (Complementary
RTPSender.collectStats()forOutboundRTPStreamStatswould also be useful)
- Extend
PeerConnection.GetStats()- Iterate
pc.GetReceivers()/pc.GetSenders()and funnel their stats into the sharedstatsReportCollector
- Iterate
- (Optional) Add playout pipeline hook
- Provide an interface (or a default no-op implementation) for applications to feed
AudioPlayoutStatsdata back into Pion
- Provide an interface (or a default no-op implementation) for applications to feed
Environment
| Item | Value |
|---|---|
| OS | macOS 14.5 / Linux 6.x |
| Go | 1.22 |
| Pion | v4.1.1 & master |
Additional context/references
- W3C WebRTC-Stats spec -
RTCInboundRtpStreamStats - Current upstream issue/PR: none found – opening this ticket to track the feature gap
Thanks for the awesome project!