Skip to content

Commit

Permalink
feat: pause count, freeze count, jitter buffer delay
Browse files Browse the repository at this point in the history
  • Loading branch information
eswarclynn committed Feb 23, 2024
1 parent 6d34209 commit 17811c5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export abstract class BaseStatsAnalytics {
protected abstract handleStatsUpdate(hmsStats: HMSWebrtcStats): void;
}

type TempPublishStats = HMSTrackStats & { availableOutgoingBitrate?: number };
type TempPublishStats = HMSTrackStats & { availableOutgoingBitrate?: number; calculatedJitterBufferDelay?: number };

export abstract class RunningTrackAnalytics {
readonly sampleWindowSize: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@ export class SubscribeStatsAnalytics extends BaseStatsAnalytics {
Object.keys(remoteTracksStats).forEach(trackID => {
const trackStats = remoteTracksStats[trackID];
const track = this.store.getTrackById(trackID);
const calculatedJitterBufferDelay =
trackStats.jitterBufferDelay &&
trackStats.jitterBufferEmittedCount &&
trackStats.jitterBufferDelay / trackStats.jitterBufferEmittedCount;
if (this.trackAnalytics.has(trackID)) {
this.trackAnalytics.get(trackID)?.pushTempStat({ ...trackStats });
this.trackAnalytics.get(trackID)?.pushTempStat({ ...trackStats, calculatedJitterBufferDelay });
} else {
if (track) {
const trackAnalytics = new RunningRemoteTrackAnalytics({
Expand All @@ -59,7 +63,7 @@ export class SubscribeStatsAnalytics extends BaseStatsAnalytics {
ssrc: trackStats.ssrc.toString(),
kind: trackStats.kind,
});
trackAnalytics.pushTempStat({ ...trackStats });
trackAnalytics.pushTempStat({ ...trackStats, calculatedJitterBufferDelay });
this.trackAnalytics.set(trackID, trackAnalytics);
}
}
Expand Down Expand Up @@ -103,6 +107,11 @@ class RunningRemoteTrackAnalytics extends RunningTrackAnalytics {
avg_frames_decoded_per_sec: this.calculateDifferenceAverage('framesDecoded'),
frame_width: this.calculateAverage('frameWidth'),
frame_height: this.calculateAverage('frameHeight'),
pause_count: this.calculateDifferenceForSample('pauseCount'),
pause_duration_seconds: this.calculateDifferenceForSample('totalPausesDuration'),
freeze_count: this.calculateDifferenceForSample('freezeCount'),
freeze_duration_seconds: this.calculateDifferenceForSample('totalFreezesDuration'),
avg_jitter_buffer_delay: this.calculateAverage('calculatedJitterBufferDelay'),
}),
);
} else {
Expand Down
6 changes: 6 additions & 0 deletions packages/hms-video-store/src/interfaces/webrtc-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ export interface MissingInboundStats extends RTCInboundRtpStreamStats, MissingCo
fecPacketsDiscarded?: number;
fecPacketsReceived?: number;
totalSamplesDuration?: number;
pauseCount?: number;
totalPausesDuration?: number;
freezeCount?: number;
totalFreezesDuration?: number;
jitterBufferDelay?: number;
jitterBufferEmittedCount?: number;
}

export type PeerConnectionType = 'publish' | 'subscribe';
Expand Down

0 comments on commit 17811c5

Please sign in to comment.