Skip to content

Commit 701c265

Browse files
committed
Tided up how latency stats are displayed in stats panel
1 parent 989a62a commit 701c265

File tree

9 files changed

+418
-207
lines changed

9 files changed

+418
-207
lines changed

Extras/FrontendTests/tests/peerconnection.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ test('Test latency calculation', {
120120
let latencyInfo: LatencyInfo = await page.evaluate(() => {
121121
return new Promise((resolve) => {
122122
window.pixelStreaming.addEventListener("latencyCalculated", (e: LatencyCalculatedEvent) => {
123-
if(e.data.latencyInfo && e.data.latencyInfo.senderLatencyMs) {
123+
if(e.data.latencyInfo && e.data.latencyInfo.senderLatencyMs && e.data.latencyInfo.rttMs) {
124124
resolve(e.data.latencyInfo);
125125
}
126126
});

Extras/JSStreamer/src/streamer.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export class Streamer extends EventEmitter {
184184
}
185185
const tranceiverOptions: RTCRtpTransceiverInit = {
186186
streams: [this.localStream],
187-
direction: 'sendonly',
187+
direction: 'sendrecv',
188188
sendEncodings: [
189189
{
190190
maxBitrate: this.settings.WebRTC.MaxBitrate,
@@ -224,8 +224,10 @@ export class Streamer extends EventEmitter {
224224
dataChannel: dataChannel
225225
};
226226

227+
const offerOptions: RTCOfferOptions = { offerToReceiveAudio: true, offerToReceiveVideo: true }
228+
227229
peerConnection
228-
.createOffer()
230+
.createOffer(offerOptions)
229231
.then((offer) => {
230232

231233
if(offer.sdp == undefined) {

Frontend/library/src/PeerConnectionController/AggregatedStats.ts

Lines changed: 90 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { InboundTrackStats } from './InboundTrackStats';
55
import { DataChannelStats } from './DataChannelStats';
66
import { CandidateStat } from './CandidateStat';
77
import { CandidatePairStats } from './CandidatePairStats';
8-
import { OutBoundRTPStats, OutBoundVideoStats } from './OutBoundRTPStats';
8+
import { RemoteOutboundRTPStats, OutboundRTPStats } from './OutBoundRTPStats';
99
import { SessionStats } from './SessionStats';
1010
import { StreamStats } from './StreamStats';
1111
import { CodecStats } from './CodecStats';
@@ -19,10 +19,13 @@ export class AggregatedStats {
1919
inboundVideoStats: InboundVideoStats;
2020
inboundAudioStats: InboundAudioStats;
2121
candidatePairs: Array<CandidatePairStats>;
22-
DataChannelStats: DataChannelStats;
22+
datachannelStats: DataChannelStats;
2323
localCandidates: Array<CandidateStat>;
2424
remoteCandidates: Array<CandidateStat>;
25-
outBoundVideoStats: OutBoundVideoStats;
25+
outboundVideoStats: OutboundRTPStats;
26+
outboundAudioStats: OutboundRTPStats;
27+
remoteOutboundVideoStats: RemoteOutboundRTPStats;
28+
remoteOutboundAudioStats: RemoteOutboundRTPStats;
2629
sessionStats: SessionStats;
2730
streamStats: StreamStats;
2831
codecs: Map<string, CodecStats>;
@@ -31,8 +34,11 @@ export class AggregatedStats {
3134
constructor() {
3235
this.inboundVideoStats = new InboundVideoStats();
3336
this.inboundAudioStats = new InboundAudioStats();
34-
this.DataChannelStats = new DataChannelStats();
35-
this.outBoundVideoStats = new OutBoundVideoStats();
37+
this.datachannelStats = new DataChannelStats();
38+
this.outboundVideoStats = new OutboundRTPStats();
39+
this.outboundAudioStats = new OutboundRTPStats();
40+
this.remoteOutboundAudioStats = new RemoteOutboundRTPStats();
41+
this.remoteOutboundVideoStats = new RemoteOutboundRTPStats();
3642
this.sessionStats = new SessionStats();
3743
this.streamStats = new StreamStats();
3844
this.codecs = new Map<string, CodecStats>();
@@ -63,7 +69,7 @@ export class AggregatedStats {
6369
this.handleDataChannel(stat);
6470
break;
6571
case 'inbound-rtp':
66-
this.handleInBoundRTP(stat);
72+
this.handleInboundRTP(stat);
6773
break;
6874
case 'local-candidate':
6975
this.handleLocalCandidate(stat);
@@ -73,6 +79,7 @@ export class AggregatedStats {
7379
case 'media-playout':
7480
break;
7581
case 'outbound-rtp':
82+
this.handleLocalOutbound(stat);
7683
break;
7784
case 'peer-connection':
7885
break;
@@ -82,7 +89,7 @@ export class AggregatedStats {
8289
case 'remote-inbound-rtp':
8390
break;
8491
case 'remote-outbound-rtp':
85-
this.handleRemoteOutBound(stat);
92+
this.handleRemoteOutbound(stat);
8693
break;
8794
case 'track':
8895
this.handleTrack(stat);
@@ -124,16 +131,16 @@ export class AggregatedStats {
124131
* @param stat - the stats coming in from the data channel
125132
*/
126133
handleDataChannel(stat: DataChannelStats) {
127-
this.DataChannelStats.bytesReceived = stat.bytesReceived;
128-
this.DataChannelStats.bytesSent = stat.bytesSent;
129-
this.DataChannelStats.dataChannelIdentifier = stat.dataChannelIdentifier;
130-
this.DataChannelStats.id = stat.id;
131-
this.DataChannelStats.label = stat.label;
132-
this.DataChannelStats.messagesReceived = stat.messagesReceived;
133-
this.DataChannelStats.messagesSent = stat.messagesSent;
134-
this.DataChannelStats.protocol = stat.protocol;
135-
this.DataChannelStats.state = stat.state;
136-
this.DataChannelStats.timestamp = stat.timestamp;
134+
this.datachannelStats.bytesReceived = stat.bytesReceived;
135+
this.datachannelStats.bytesSent = stat.bytesSent;
136+
this.datachannelStats.dataChannelIdentifier = stat.dataChannelIdentifier;
137+
this.datachannelStats.id = stat.id;
138+
this.datachannelStats.label = stat.label;
139+
this.datachannelStats.messagesReceived = stat.messagesReceived;
140+
this.datachannelStats.messagesSent = stat.messagesSent;
141+
this.datachannelStats.protocol = stat.protocol;
142+
this.datachannelStats.state = stat.state;
143+
this.datachannelStats.timestamp = stat.timestamp;
137144
}
138145

139146
/**
@@ -158,23 +165,23 @@ export class AggregatedStats {
158165
* @param stat - ice candidate stats
159166
*/
160167
handleRemoteCandidate(stat: CandidateStat) {
161-
const RemoteCandidate = new CandidateStat();
162-
RemoteCandidate.label = 'remote-candidate';
163-
RemoteCandidate.address = stat.address;
164-
RemoteCandidate.port = stat.port;
165-
RemoteCandidate.protocol = stat.protocol;
166-
RemoteCandidate.id = stat.id;
167-
RemoteCandidate.candidateType = stat.candidateType;
168-
RemoteCandidate.relayProtocol = stat.relayProtocol;
169-
RemoteCandidate.transportId = stat.transportId;
170-
this.remoteCandidates.push(RemoteCandidate);
168+
const remoteCandidate = new CandidateStat();
169+
remoteCandidate.label = 'remote-candidate';
170+
remoteCandidate.address = stat.address;
171+
remoteCandidate.port = stat.port;
172+
remoteCandidate.protocol = stat.protocol;
173+
remoteCandidate.id = stat.id;
174+
remoteCandidate.candidateType = stat.candidateType;
175+
remoteCandidate.relayProtocol = stat.relayProtocol;
176+
remoteCandidate.transportId = stat.transportId;
177+
this.remoteCandidates.push(remoteCandidate);
171178
}
172179

173180
/**
174181
* Process the Inbound RTP Audio and Video Data
175182
* @param stat - inbound rtp stats
176183
*/
177-
handleInBoundRTP(stat: InboundRTPStats) {
184+
handleInboundRTP(stat: InboundRTPStats) {
178185
switch (stat.kind) {
179186
case 'video':
180187
// Calculate bitrate between stat updates
@@ -215,25 +222,63 @@ export class AggregatedStats {
215222
}
216223

217224
/**
218-
* Process the outbound RTP Audio and Video Data
219-
* @param stat - remote outbound stats
225+
* Process the "local" outbound RTP Audio and Video stats.
226+
* @param stat - local outbound rtp stats
220227
*/
221-
handleRemoteOutBound(stat: OutBoundRTPStats) {
222-
switch (stat.kind) {
223-
case 'video':
224-
this.outBoundVideoStats.bytesSent = stat.bytesSent;
225-
this.outBoundVideoStats.id = stat.id;
226-
this.outBoundVideoStats.localId = stat.localId;
227-
this.outBoundVideoStats.packetsSent = stat.packetsSent;
228-
this.outBoundVideoStats.remoteTimestamp = stat.remoteTimestamp;
229-
this.outBoundVideoStats.timestamp = stat.timestamp;
230-
break;
231-
case 'audio':
232-
break;
228+
handleLocalOutbound(stat: OutboundRTPStats) {
229+
const localOutboundStats: OutboundRTPStats =
230+
stat.kind === 'audio' ? this.outboundAudioStats : this.outboundVideoStats;
231+
localOutboundStats.active = stat.active;
232+
localOutboundStats.codecId = stat.codecId;
233+
localOutboundStats.bytesSent = stat.bytesSent;
234+
localOutboundStats.frameHeight = stat.frameHeight;
235+
localOutboundStats.frameWidth = stat.frameWidth;
236+
localOutboundStats.framesEncoded = stat.framesEncoded;
237+
localOutboundStats.framesPerSecond = stat.framesPerSecond;
238+
localOutboundStats.headerBytesSent = stat.headerBytesSent;
239+
localOutboundStats.id = stat.id;
240+
localOutboundStats.keyFramesEncoded = stat.keyFramesEncoded;
241+
localOutboundStats.kind = stat.kind;
242+
localOutboundStats.mediaSourceId = stat.mediaSourceId;
243+
localOutboundStats.mid = stat.mid;
244+
localOutboundStats.nackCount = stat.nackCount;
245+
localOutboundStats.packetsSent = stat.packetsSent;
246+
localOutboundStats.qpSum = stat.qpSum;
247+
localOutboundStats.qualityLimitationDurations = stat.qualityLimitationDurations;
248+
localOutboundStats.qualityLimitationReason = stat.qualityLimitationReason;
249+
localOutboundStats.remoteId = stat.remoteId;
250+
localOutboundStats.retransmittedBytesSent = stat.retransmittedBytesSent;
251+
localOutboundStats.rid = stat.rid;
252+
localOutboundStats.scalabilityMode = stat.scalabilityMode;
253+
localOutboundStats.ssrc = stat.ssrc;
254+
localOutboundStats.targetBitrate = stat.targetBitrate;
255+
localOutboundStats.timestamp = stat.timestamp;
256+
localOutboundStats.totalEncodeTime = stat.totalEncodeTime;
257+
localOutboundStats.totalEncodeBytesTarget = stat.totalEncodeBytesTarget;
258+
localOutboundStats.totalPacketSendDelay = stat.totalPacketSendDelay;
259+
localOutboundStats.transportId = stat.transportId;
260+
}
233261

234-
default:
235-
break;
236-
}
262+
/**
263+
* Process the "remote" outbound RTP Audio and Video stats.
264+
* @param stat - remote outbound rtp stats
265+
*/
266+
handleRemoteOutbound(stat: RemoteOutboundRTPStats) {
267+
const remoteOutboundStats: RemoteOutboundRTPStats =
268+
stat.kind === 'audio' ? this.remoteOutboundAudioStats : this.remoteOutboundVideoStats;
269+
remoteOutboundStats.bytesSent = stat.bytesSent;
270+
remoteOutboundStats.codecId = stat.codecId;
271+
remoteOutboundStats.id = stat.id;
272+
remoteOutboundStats.kind = stat.kind;
273+
remoteOutboundStats.localId = stat.localId;
274+
remoteOutboundStats.packetsSent = stat.packetsSent;
275+
remoteOutboundStats.remoteTimestamp = stat.remoteTimestamp;
276+
remoteOutboundStats.reportsSent = stat.reportsSent;
277+
remoteOutboundStats.roundTripTimeMeasurements = stat.roundTripTimeMeasurements;
278+
remoteOutboundStats.ssrc = stat.ssrc;
279+
remoteOutboundStats.timestamp = stat.timestamp;
280+
remoteOutboundStats.totalRoundTripTime = stat.totalRoundTripTime;
281+
remoteOutboundStats.transportId = stat.transportId;
237282
}
238283

239284
/**

0 commit comments

Comments
 (0)