Skip to content
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ coverage/
*.sublime-project
*.tmproj
.vscode/
.codex
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"build:es5": "rollup -c --format umd",
"build:docs": "typedoc index.ts",
"test": "vitest",
"test:coverage": "vitest --coverage",
"test:coverage": "vitest --run --coverage",
"lint": "eslint . && prettier --check .",
"eslint": "eslint --fix .",
"prettier": "prettier --write --ignore-unknown .",
Expand Down
4 changes: 2 additions & 2 deletions src/Util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ describe('Util', () => {
const time0 = Util.time();
await new Promise(resolve => setTimeout(resolve, 100));
const time100 = Util.time();
expect(time100).toBeGreaterThanOrEqual(time0 + 100);
expect(time100).toBeGreaterThanOrEqual(time0 + 95);

const unixTime = Util.unixTime();
expect(unixTime).toBeGreaterThanOrEqual(Math.floor(performance.timeOrigin + time0 + 100));
expect(unixTime).toBeGreaterThanOrEqual(Math.floor(performance.timeOrigin + time0 + 95));
expect(unixTime).toBeGreaterThanOrEqual(Math.floor(performance.timeOrigin + time100));
});
});
Expand Down
15 changes: 13 additions & 2 deletions src/stats/PlayerStats.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ describe('PlayerStats', () => {
stats.protocol = 'HLS';
stats.bufferAmount = 1000;
stats.playbackRate = 1.5;
stats.recvByteRate = 50_000;
stats.audioByteRate = 60;
stats.videoByteRate = 1500;
stats.waitingData = true;
stats.stallCount = 3;
stats.videoTrackId = 1;
Expand All @@ -37,13 +38,23 @@ describe('PlayerStats', () => {
br: 1500,
bs: true,
bl: 1000,
mtp: 50_000,
mtp: 1560,
pr: 1.5,
sf: 'h',
su: true
});
});

it('should set mtp from dataByteRate when audio and video byte rates are missing', () => {
const stats = new PlayerStats();
stats.dataByteRate = 512;

const url = new URL('https://example.com/live/chunk.ts');
const cmcd = stats.toCmcd(url, 99);

expect(cmcd.mtp).toBe(512);
});

it('should select the correct object type and bitrate for audio track', () => {
const stats = new PlayerStats();
stats.audioTrackId = 2;
Expand Down
10 changes: 6 additions & 4 deletions src/stats/PlayerStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ export class PlayerStats extends Loggable {
playbackSpeed?: number;
playbackRate?: number;

recvByteRate?: number; // Bps in reception
sendByteRate?: number; // Bps in sending
audioByteRate?: number; // current audio Bps
videoByteRate?: number; // current video Bps
dataByteRate?: number; // current data Bps

videoTrackId?: number; // video track selected
videoTrackBandwidth?: number; // video bandwidth currently playing
Expand Down Expand Up @@ -86,8 +87,9 @@ export class PlayerStats extends Loggable {
if (this.bufferAmount != null) {
cmcd.bl = this.bufferAmount; // Buffer Length
}
if (this.recvByteRate != null) {
cmcd.mtp = this.recvByteRate; // Measured mtp CMCD throughput
if (this.audioByteRate != null || this.videoByteRate != null || this.dataByteRate != null) {
// Measured mtp CMCD throughput
cmcd.mtp = (this.audioByteRate ?? 0) + (this.videoByteRate ?? 0) + (this.dataByteRate ?? 0);
}
if (playBack != null) {
cmcd.pr = Number(playBack.toFixed(2)); // Playback Rate
Expand Down
Loading