Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more information to PeerConnectionAnalyzer logs #14442

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/utils/webrtc/analyzers/ParticipantAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { PEER_DIRECTION, PeerConnectionAnalyzer } from './PeerConnectionAnalyzer.js'
import {
PEER_DIRECTION,
PEER_TYPE,
PeerConnectionAnalyzer
} from './PeerConnectionAnalyzer.js'
import EmitterMixin from '../../EmitterMixin.js'

/**
Expand Down Expand Up @@ -201,7 +205,7 @@ ParticipantAnalyzer.prototype = {

_startListeningToScreenChanges() {
if (this._localMediaModel) {
this._senderScreenPeerConnectionAnalyzer.setPeerConnection(this._screenPeer.pc, PEER_DIRECTION.SENDER)
this._senderScreenPeerConnectionAnalyzer.setPeerConnection(this._screenPeer.pc, PEER_DIRECTION.SENDER, PEER_TYPE.SCREEN)

this._senderScreenPeerConnectionAnalyzer.on('change:connectionQualityVideo', this._handleConnectionQualityScreenChangeBound)

Expand All @@ -210,7 +214,7 @@ ParticipantAnalyzer.prototype = {
}

if (this._callParticipantModel) {
this._receiverScreenPeerConnectionAnalyzer.setPeerConnection(this._screenPeer.pc, PEER_DIRECTION.RECEIVER)
this._receiverScreenPeerConnectionAnalyzer.setPeerConnection(this._screenPeer.pc, PEER_DIRECTION.RECEIVER, PEER_TYPE.SCREEN)

this._receiverScreenPeerConnectionAnalyzer.on('change:connectionQualityVideo', this._handleConnectionQualityScreenChangeBound)

Expand Down
64 changes: 62 additions & 2 deletions src/utils/webrtc/analyzers/PeerConnectionAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ const PEER_DIRECTION = {
RECEIVER: 1,
}

const PEER_TYPE = {
VIDEO: 0,
SCREEN: 1,
}

/**
* Analyzer for the quality of the connection of an RTCPeerConnection.
*
Expand Down Expand Up @@ -56,6 +61,11 @@ const PEER_DIRECTION = {
function PeerConnectionAnalyzer() {
this._superEmitterMixin()

this._rtcStats = {
audio: [],
video: [],
}

this._packets = {
audio: new AverageStatValue(5, STAT_VALUE_TYPE.CUMULATIVE),
video: new AverageStatValue(5, STAT_VALUE_TYPE.CUMULATIVE),
Expand Down Expand Up @@ -114,6 +124,7 @@ function PeerConnectionAnalyzer() {

this._peerConnection = null
this._peerDirection = null
this._peerType = null

this._getStatsInterval = null

Expand Down Expand Up @@ -154,7 +165,7 @@ PeerConnectionAnalyzer.prototype = {
this._trigger('change:connectionQualityVideo', [connectionQualityVideo])
},

setPeerConnection(peerConnection, peerDirection = null) {
setPeerConnection(peerConnection, peerDirection = null, peerType = PEER_TYPE.VIDEO) {
if (this._peerConnection) {
this._peerConnection.removeEventListener('iceconnectionstatechange', this._handleIceConnectionStateChangedBound)
this._peerConnection.removeEventListener('connectionstatechange', this._handleConnectionStateChangedBound)
Expand All @@ -163,6 +174,7 @@ PeerConnectionAnalyzer.prototype = {

this._peerConnection = peerConnection
this._peerDirection = peerDirection
this._peerType = peerType

this._setConnectionQualityAudio(CONNECTION_QUALITY.UNKNOWN)
this._setConnectionQualityVideo(CONNECTION_QUALITY.UNKNOWN)
Expand Down Expand Up @@ -282,6 +294,17 @@ PeerConnectionAnalyzer.prototype = {
return
}

// Although the last five stats are analyzed a few more RTC stats are
// kept to provide an extended context in the logs.
const NUMBER_OF_RTC_STATS_TO_KEEP = 7

for (const kind of ['audio', 'video']) {
if (this._rtcStats[kind].length === NUMBER_OF_RTC_STATS_TO_KEEP) {
this._rtcStats[kind].shift()
}
this._rtcStats[kind].push([])
}

if (this._peerDirection === PEER_DIRECTION.SENDER) {
this._processSenderStats(stats)
} else if (this._peerDirection === PEER_DIRECTION.RECEIVER) {
Expand Down Expand Up @@ -353,6 +376,8 @@ PeerConnectionAnalyzer.prototype = {
}

if (stat.type === 'outbound-rtp') {
this._rtcStats[stat.kind][this._rtcStats[stat.kind].length - 1].push(stat)

if ('packetsSent' in stat && 'kind' in stat) {
packetsSent[stat.kind] = (packetsSent[stat.kind] === -1) ? stat.packetsSent : packetsSent[stat.kind] + stat.packetsSent

Expand All @@ -361,6 +386,8 @@ PeerConnectionAnalyzer.prototype = {
}
}
} else if (stat.type === 'remote-inbound-rtp') {
this._rtcStats[stat.kind][this._rtcStats[stat.kind].length - 1].push(stat)

if ('packetsReceived' in stat && 'kind' in stat) {
packetsReceived[stat.kind] = (packetsReceived[stat.kind] === -1) ? stat.packetsReceived : packetsReceived[stat.kind] + stat.packetsReceived

Expand Down Expand Up @@ -441,6 +468,8 @@ PeerConnectionAnalyzer.prototype = {
}

if (stat.type === 'inbound-rtp') {
this._rtcStats[stat.kind][this._rtcStats[stat.kind].length - 1].push(stat)

if ('packetsReceived' in stat && 'kind' in stat) {
packetsReceived[stat.kind] = stat.packetsReceived
}
Expand All @@ -450,6 +479,10 @@ PeerConnectionAnalyzer.prototype = {
if ('timestamp' in stat && 'kind' in stat) {
timestamp[stat.kind] = stat.timestamp
}
} else if (stat.type === 'remote-outbound-rtp') {
// Even if the stat is not used in calculations it is logged for
// additional context.
this._rtcStats[stat.kind][this._rtcStats[stat.kind].length - 1].push(stat)
}
}

Expand Down Expand Up @@ -724,8 +757,17 @@ PeerConnectionAnalyzer.prototype = {
return CONNECTION_QUALITY.GOOD
},

_getLogTag(kind) {
let type = kind
if (this._peerType === PEER_TYPE.SCREEN) {
type += ' (screen)'
}

return 'PeerConnectionAnalyzer: ' + type + ': '
},

_logStats(kind, message) {
const tag = 'PeerConnectionAnalyzer: ' + kind + ': '
const tag = this._getLogTag(kind)

if (message) {
console.debug(tag + message)
Expand All @@ -737,14 +779,32 @@ PeerConnectionAnalyzer.prototype = {
console.debug(tag + 'Packets per second: ' + this._packetsPerSecond[kind].toString())
console.debug(tag + 'Round trip time: ' + this._roundTripTime[kind].toString())
console.debug(tag + 'Timestamps: ' + this._timestampsForLogs[kind].toString())

this._logRtcStats(kind)
},

_logRtcStats(kind) {
const tag = this._getLogTag(kind)

for (const rtcStats of this._rtcStats[kind]) {
if (!rtcStats.length) {
console.debug(tag + 'no matching type')
continue
}

for (const rtcStat of rtcStats) {
console.debug(tag + JSON.stringify(rtcStat))
}
}
}

}

EmitterMixin.apply(PeerConnectionAnalyzer.prototype)

export {
CONNECTION_QUALITY,
PEER_DIRECTION,
PEER_TYPE,
PeerConnectionAnalyzer,
}
Loading