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!
Hi @JoeTurki , I hope you're doing well. Apologies if I'm interrupting—I just wanted to follow up since you were the last one to respond on the PR. I was wondering if there are any plans to support the missing stats? Any updates would be greatly appreciated. Thanks!
Hello, Thank you for the report, We'll add this to the feature request, No promises. But Probably ready with 4.3 or 4.4.
I think this auto-closed from my PR but I am keeping this open until I've resolved the media-playout stats collection as well. inbound-rtp stats collection (per-SSRC counters for receiver side) is now supported @Carsinalys per https://github.com/pion/webrtc/pull/3221
@Carsinalys you can now get inbound-rtp and media-playout stats. I'll try and add an example of how to get media-playout stats since that requires some setup on the application side (you can look at PR body of https://github.com/pion/webrtc/pull/3234 to get a sense). Just a quick disclaimer this covers Audio media playout stats for now since that is what is supported in the spec for now. Closing this issue but I'll reference this issue in the PR including the media-playout example usage as well. Let us know if there's anything else you have in mind!
#3234
@drshrey thank you a lot, I'll check with next pion release!
I have idea to make PR about ivfwriter, I faced issue when I record audio & video mixed streams duration of audio files is normal, but video duration being scaled by 1.111... because of timebaseDenominator, I'm not aware how better to solve it. First idea in mind is to add more options to have ability redefine timebaseDenominator and timebaseNumerator (for my case it 1000 and 30). Right now I just rewrite file header
I have idea to make PR about ivfwriter, I faced issue when I record audio & video mixed streams duration of audio files is normal, but video duration being scaled by 1.111... because of timebaseDenominator, I'm not aware how better to solve it. First idea in mind is to add more options to have ability redefine timebaseDenominator and timebaseNumerator (for my case it 1000 and 30). Right now I just rewrite file header
This is possible via WithFrameRate it was added recently. https://github.com/pion/webrtc/blob/master/pkg/media/ivfwriter/ivfwriter.go#L356
also we released v4.1.5
I have idea to make PR about ivfwriter, I faced issue when I record audio & video mixed streams duration of audio files is normal, but video duration being scaled by 1.111... because of timebaseDenominator, I'm not aware how better to solve it. First idea in mind is to add more options to have ability redefine timebaseDenominator and timebaseNumerator (for my case it 1000 and 30). Right now I just rewrite file header
This is possible via
WithFrameRateit was added recently. https://github.com/pion/webrtc/blob/master/pkg/media/ivfwriter/ivfwriter.go#L356also we released v4.1.5
Great to see that, thanks a lot!