Skip to content

Add support for emitting inbound-rtp and media-playout stats from PeerConnection.GetStats #3134

@Carsinalys

Description

@Carsinalys

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:

  1. At least one InboundRTPStreamStats entry for every primary SSRC the RTPReceiver is consuming
  2. Optionally an AudioPlayoutStats entry (or equivalent) describing local audio playout for that track
  3. 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

  1. Implement collectStats() on media objects
    • RTPReceiver.collectStats() → build an InboundRTPStreamStats per SSRC
    • (Complementary RTPSender.collectStats() for OutboundRTPStreamStats would also be useful)
  2. Extend PeerConnection.GetStats()
    • Iterate pc.GetReceivers() / pc.GetSenders() and funnel their stats into the shared statsReportCollector
  3. (Optional) Add playout pipeline hook
    • Provide an interface (or a default no-op implementation) for applications to feed AudioPlayoutStats data back into Pion

Environment

Item Value
OS macOS 14.5 / Linux 6.x
Go 1.22
Pion v4.1.1 & master

Additional context/references

Thanks for the awesome project!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions