The RTCCodecStats
dictionary of the WebRTC API provides statistics about a codec used by RTP streams that are being sent or received by the associated RTCPeerConnection
object.
These statistics can be obtained by iterating the RTCStatsReport
object returned by RTCPeerConnection.getStats()
until you find an entry with the type
of codec
.
The codec statistics can be correlated with the inbound or outbound stream statistics (both local and remote) by matching their codecId
property to the codec's id
. For example, if RTCInboundRtpStreamStats.codecId
matches an RTCCodecStats.id
in the same report, then we know that the codec is being used on this peer connection's inbound stream. If no stream codecId
references a codec statistic, then that codec statistic object is deleted — if the codec is used again, the statistics object will be recreated with the same id
.
Codec objects may be referenced by multiple RTP streams in media sections using the same transport. In fact, user agents are expected to consolidate information into a single "codec" entry per payload type per transport (unless sdpFmtpLine is different when sending or receiving, in which case, different codecs will be needed for encoding and decoding). Note that other transports will use their own distinct RTCCodecStats
objects.