This commit is contained in:
unfunny
2026-09-12 23:57:45 -04:00
parent 986c0af682
commit dfe4cc537f
1775 changed files with 246421 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
export type Mid = string;
export type Ssrc = string;
export type MapType = "local" | "remote";
export declare class MediaSsrcHandler {
private readonly ssrcToMid;
findMidBySsrc(ssrc: Ssrc, type: "local" | "remote"): Mid | undefined;
parse(description: string, type: MapType): void;
getSsrcToMidMap(type: MapType): Map<Mid, Ssrc[]>;
}
//# sourceMappingURL=mediaSsrcHandler.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"mediaSsrcHandler.d.ts","sourceRoot":"","sources":["../../../../src/webrtc/stats/media/mediaSsrcHandler.ts"],"names":[],"mappings":"AAkBA,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC;AACzB,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC;AAC1B,MAAM,MAAM,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEzC,qBAAa,gBAAgB;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAqE;IAExF,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,GAAG,QAAQ,GAAG,GAAG,GAAG,SAAS,CAS1E;IAEM,KAAK,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAerD;IAEM,eAAe,CAAC,IAAI,EAAE,OAAO,GAAG,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAEtD;CACJ"}

View File

@@ -0,0 +1,56 @@
import _defineProperty from "@babel/runtime/helpers/defineProperty";
/*
Copyright 2023 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import { parse as parseSdp } from "sdp-transform";
export class MediaSsrcHandler {
constructor() {
_defineProperty(this, "ssrcToMid", {
local: new Map(),
remote: new Map()
});
}
findMidBySsrc(ssrc, type) {
let mid;
this.ssrcToMid[type].forEach((ssrcs, m) => {
if (ssrcs.find(s => s == ssrc)) {
mid = m;
return;
}
});
return mid;
}
parse(description, type) {
const sdp = parseSdp(description);
const ssrcToMid = new Map();
sdp.media.forEach(m => {
if (!!m.mid && m.type === "video" || m.type === "audio") {
const ssrcs = [];
m.ssrcs?.forEach(ssrc => {
if (ssrc.attribute === "cname") {
ssrcs.push(`${ssrc.id}`);
}
});
ssrcToMid.set(`${m.mid}`, ssrcs);
}
});
this.ssrcToMid[type] = ssrcToMid;
}
getSsrcToMidMap(type) {
return this.ssrcToMid[type];
}
}
//# sourceMappingURL=mediaSsrcHandler.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"mediaSsrcHandler.js","names":[],"sources":["../../../../src/webrtc/stats/media/mediaSsrcHandler.ts"],"sourcesContent":["/*\nCopyright 2023 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { parse as parseSdp } from \"sdp-transform\";\n\nexport type Mid = string;\nexport type Ssrc = string;\nexport type MapType = \"local\" | \"remote\";\n\nexport class MediaSsrcHandler {\n private readonly ssrcToMid = { local: new Map<Mid, Ssrc[]>(), remote: new Map<Mid, Ssrc[]>() };\n\n public findMidBySsrc(ssrc: Ssrc, type: \"local\" | \"remote\"): Mid | undefined {\n let mid: Mid | undefined;\n this.ssrcToMid[type].forEach((ssrcs, m) => {\n if (ssrcs.find((s) => s == ssrc)) {\n mid = m;\n return;\n }\n });\n return mid;\n }\n\n public parse(description: string, type: MapType): void {\n const sdp = parseSdp(description);\n const ssrcToMid = new Map<Mid, Ssrc[]>();\n sdp.media.forEach((m) => {\n if ((!!m.mid && m.type === \"video\") || m.type === \"audio\") {\n const ssrcs: Ssrc[] = [];\n m.ssrcs?.forEach((ssrc) => {\n if (ssrc.attribute === \"cname\") {\n ssrcs.push(`${ssrc.id}`);\n }\n });\n ssrcToMid.set(`${m.mid}`, ssrcs);\n }\n });\n this.ssrcToMid[type] = ssrcToMid;\n }\n\n public getSsrcToMidMap(type: MapType): Map<Mid, Ssrc[]> {\n return this.ssrcToMid[type];\n }\n}\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAAS,KAAK,IAAI,QAAQ,QAAQ,eAAe;AAMjD,OAAO,MAAM,gBAAgB,CAAC;EAAA;IAAA,mCACG;MAAE,KAAK,EAAE,IAAI,GAAG,CAAc,CAAC;MAAE,MAAM,EAAE,IAAI,GAAG,CAAc;IAAE,CAAC;EAAA;EAEvF,aAAa,CAAC,IAAU,EAAE,IAAwB,EAAmB;IACxE,IAAI,GAAoB;IACxB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK;MACvC,IAAI,KAAK,CAAC,IAAI,CAAE,CAAC,IAAK,CAAC,IAAI,IAAI,CAAC,EAAE;QAC9B,GAAG,GAAG,CAAC;QACP;MACJ;IACJ,CAAC,CAAC;IACF,OAAO,GAAG;EACd;EAEO,KAAK,CAAC,WAAmB,EAAE,IAAa,EAAQ;IACnD,MAAM,GAAG,GAAG,QAAQ,CAAC,WAAW,CAAC;IACjC,MAAM,SAAS,GAAG,IAAI,GAAG,CAAc,CAAC;IACxC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAE,CAAC,IAAK;MACrB,IAAK,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,IAAI,KAAK,OAAO,IAAK,CAAC,CAAC,IAAI,KAAK,OAAO,EAAE;QACvD,MAAM,KAAa,GAAG,EAAE;QACxB,CAAC,CAAC,KAAK,EAAE,OAAO,CAAE,IAAI,IAAK;UACvB,IAAI,IAAI,CAAC,SAAS,KAAK,OAAO,EAAE;YAC5B,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;UAC5B;QACJ,CAAC,CAAC;QACF,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,KAAK,CAAC;MACpC;IACJ,CAAC,CAAC;IACF,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,SAAS;EACpC;EAEO,eAAe,CAAC,IAAa,EAAoB;IACpD,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;EAC/B;AACJ","ignoreList":[]}

View File

@@ -0,0 +1,12 @@
export type TrackId = string;
export declare class MediaTrackHandler {
private readonly pc;
constructor(pc: RTCPeerConnection);
getLocalTracks(kind: "audio" | "video"): MediaStreamTrack[];
getTackById(trackId: string): MediaStreamTrack | undefined;
getLocalTrackIdByMid(mid: string): string | undefined;
getRemoteTrackIdByMid(mid: string): string | undefined;
getActiveSimulcastStreams(): number;
getTransceiverByTrackId(trackId: TrackId): RTCRtpTransceiver | undefined;
}
//# sourceMappingURL=mediaTrackHandler.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"mediaTrackHandler.d.ts","sourceRoot":"","sources":["../../../../src/webrtc/stats/media/mediaTrackHandler.ts"],"names":[],"mappings":"AAgBA,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC;AAE7B,qBAAa,iBAAiB;IACP,OAAO,CAAC,QAAQ,CAAC,EAAE;IAAtC,YAAoC,EAAE,EAAE,iBAAiB,EAAI;IAEtD,cAAc,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,GAAG,gBAAgB,EAAE,CAWjE;IAEM,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,CAahE;IAEM,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAG3D;IAEM,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAG5D;IAEM,yBAAyB,IAAI,MAAM,CAGzC;IAEM,uBAAuB,CAAC,OAAO,EAAE,OAAO,GAAG,iBAAiB,GAAG,SAAS,CAI9E;CACJ"}

View File

@@ -0,0 +1,56 @@
/*
Copyright 2023 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
export class MediaTrackHandler {
constructor(pc) {
this.pc = pc;
}
getLocalTracks(kind) {
const isNotNullAndKind = track => {
return track !== null && track.kind === kind;
};
return this.pc.getTransceivers().filter(t => t.currentDirection === "sendonly" || t.currentDirection === "sendrecv").filter(t => t.sender !== null).map(t => t.sender).map(s => s.track).filter(isNotNullAndKind);
}
getTackById(trackId) {
return this.pc.getTransceivers().map(t => {
if (t?.sender.track !== null && t.sender.track.id === trackId) {
return t.sender.track;
}
if (t?.receiver.track !== null && t.receiver.track.id === trackId) {
return t.receiver.track;
}
return undefined;
}).find(t => t !== undefined);
}
getLocalTrackIdByMid(mid) {
const transceiver = this.pc.getTransceivers().find(t => t.mid === mid);
return transceiver?.sender?.track?.id;
}
getRemoteTrackIdByMid(mid) {
const transceiver = this.pc.getTransceivers().find(t => t.mid === mid);
return transceiver?.receiver?.track?.id;
}
getActiveSimulcastStreams() {
//@TODO implement this right.. Check how many layer configured
return 3;
}
getTransceiverByTrackId(trackId) {
return this.pc.getTransceivers().find(t => {
return t.receiver.track.id === trackId || t.sender.track !== null && t.sender.track.id === trackId;
});
}
}
//# sourceMappingURL=mediaTrackHandler.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"mediaTrackHandler.js","names":[],"sources":["../../../../src/webrtc/stats/media/mediaTrackHandler.ts"],"sourcesContent":["/*\nCopyright 2023 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nexport type TrackId = string;\n\nexport class MediaTrackHandler {\n public constructor(private readonly pc: RTCPeerConnection) {}\n\n public getLocalTracks(kind: \"audio\" | \"video\"): MediaStreamTrack[] {\n const isNotNullAndKind = (track: MediaStreamTrack | null): boolean => {\n return track !== null && track.kind === kind;\n };\n return this.pc\n .getTransceivers()\n .filter((t) => t.currentDirection === \"sendonly\" || t.currentDirection === \"sendrecv\")\n .filter((t) => t.sender !== null)\n .map((t) => t.sender)\n .map((s) => s.track)\n .filter(isNotNullAndKind) as MediaStreamTrack[];\n }\n\n public getTackById(trackId: string): MediaStreamTrack | undefined {\n return this.pc\n .getTransceivers()\n .map((t) => {\n if (t?.sender.track !== null && t.sender.track.id === trackId) {\n return t.sender.track;\n }\n if (t?.receiver.track !== null && t.receiver.track.id === trackId) {\n return t.receiver.track;\n }\n return undefined;\n })\n .find((t) => t !== undefined);\n }\n\n public getLocalTrackIdByMid(mid: string): string | undefined {\n const transceiver = this.pc.getTransceivers().find((t) => t.mid === mid);\n return transceiver?.sender?.track?.id;\n }\n\n public getRemoteTrackIdByMid(mid: string): string | undefined {\n const transceiver = this.pc.getTransceivers().find((t) => t.mid === mid);\n return transceiver?.receiver?.track?.id;\n }\n\n public getActiveSimulcastStreams(): number {\n //@TODO implement this right.. Check how many layer configured\n return 3;\n }\n\n public getTransceiverByTrackId(trackId: TrackId): RTCRtpTransceiver | undefined {\n return this.pc.getTransceivers().find((t) => {\n return t.receiver.track.id === trackId || (t.sender.track !== null && t.sender.track.id === trackId);\n });\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,OAAO,MAAM,iBAAiB,CAAC;EACpB,WAAW,CAAkB,EAAqB,EAAE;IAAA,KAAvB,EAAqB,GAArB,EAAqB;EAAG;EAErD,cAAc,CAAC,IAAuB,EAAsB;IAC/D,MAAM,gBAAgB,GAAI,KAA8B,IAAc;MAClE,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI;IAChD,CAAC;IACD,OAAO,IAAI,CAAC,EAAE,CACT,eAAe,CAAC,CAAC,CACjB,MAAM,CAAE,CAAC,IAAK,CAAC,CAAC,gBAAgB,KAAK,UAAU,IAAI,CAAC,CAAC,gBAAgB,KAAK,UAAU,CAAC,CACrF,MAAM,CAAE,CAAC,IAAK,CAAC,CAAC,MAAM,KAAK,IAAI,CAAC,CAChC,GAAG,CAAE,CAAC,IAAK,CAAC,CAAC,MAAM,CAAC,CACpB,GAAG,CAAE,CAAC,IAAK,CAAC,CAAC,KAAK,CAAC,CACnB,MAAM,CAAC,gBAAgB,CAAC;EACjC;EAEO,WAAW,CAAC,OAAe,EAAgC;IAC9D,OAAO,IAAI,CAAC,EAAE,CACT,eAAe,CAAC,CAAC,CACjB,GAAG,CAAE,CAAC,IAAK;MACR,IAAI,CAAC,EAAE,MAAM,CAAC,KAAK,KAAK,IAAI,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,OAAO,EAAE;QAC3D,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK;MACzB;MACA,IAAI,CAAC,EAAE,QAAQ,CAAC,KAAK,KAAK,IAAI,IAAI,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,OAAO,EAAE;QAC/D,OAAO,CAAC,CAAC,QAAQ,CAAC,KAAK;MAC3B;MACA,OAAO,SAAS;IACpB,CAAC,CAAC,CACD,IAAI,CAAE,CAAC,IAAK,CAAC,KAAK,SAAS,CAAC;EACrC;EAEO,oBAAoB,CAAC,GAAW,EAAsB;IACzD,MAAM,WAAW,GAAG,IAAI,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC,IAAI,CAAE,CAAC,IAAK,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC;IACxE,OAAO,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE;EACzC;EAEO,qBAAqB,CAAC,GAAW,EAAsB;IAC1D,MAAM,WAAW,GAAG,IAAI,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC,IAAI,CAAE,CAAC,IAAK,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC;IACxE,OAAO,WAAW,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE;EAC3C;EAEO,yBAAyB,GAAW;IACvC;IACA,OAAO,CAAC;EACZ;EAEO,uBAAuB,CAAC,OAAgB,EAAiC;IAC5E,OAAO,IAAI,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC,IAAI,CAAE,CAAC,IAAK;MACzC,OAAO,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,OAAO,IAAK,CAAC,CAAC,MAAM,CAAC,KAAK,KAAK,IAAI,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,OAAQ;IACxG,CAAC,CAAC;EACN;AACJ","ignoreList":[]}

View File

@@ -0,0 +1,86 @@
import { type AudioConcealment } from "../statsReport.ts";
import { type TrackId } from "./mediaTrackHandler.ts";
export interface PacketLoss {
packetsTotal: number;
packetsLost: number;
isDownloadStream: boolean;
}
export interface Bitrate {
/**
* bytes per second
*/
download: number;
/**
* bytes per second
*/
upload: number;
}
export interface ConcealedAudio {
/**
* duration in ms
*/
duration: number;
ratio: number;
}
export interface Resolution {
width: number;
height: number;
}
export type TrackStatsType = "local" | "remote";
export declare class MediaTrackStats {
readonly trackId: TrackId;
readonly type: TrackStatsType;
readonly kind: "audio" | "video";
private loss;
private bitrate;
private resolution;
private audioConcealment;
private framerate;
private jitter;
private codec;
private isAlive;
private isMuted;
private isEnabled;
constructor(trackId: TrackId, type: TrackStatsType, kind: "audio" | "video");
getType(): TrackStatsType;
setLoss(loss: PacketLoss): void;
getLoss(): PacketLoss;
setResolution(resolution: Resolution): void;
getResolution(): Resolution;
setFramerate(framerate: number): void;
getFramerate(): number;
setBitrate(bitrate: Bitrate): void;
getBitrate(): Bitrate;
setCodec(codecShortType: string): boolean;
getCodec(): string;
resetBitrate(): void;
set alive(isAlive: boolean);
/**
* A MediaTrackState is alive if the corresponding MediaStreamTrack track bound to a transceiver and the
* MediaStreamTrack is in state MediaStreamTrack.readyState === live
*/
get alive(): boolean;
set muted(isMuted: boolean);
/**
* A MediaTrackState.isMuted corresponding to MediaStreamTrack.muted.
* But these values only match if MediaTrackState.isAlive.
*/
get muted(): boolean;
set enabled(isEnabled: boolean);
/**
* A MediaTrackState.isEnabled corresponding to MediaStreamTrack.enabled.
* But these values only match if MediaTrackState.isAlive.
*/
get enabled(): boolean;
setJitter(jitter: number): void;
/**
* Jitter in milliseconds
*/
getJitter(): number;
/**
* Audio concealment ration (conceled duration / total duration)
*/
setAudioConcealment(concealedAudioDuration: number, totalAudioDuration: number): void;
getAudioConcealment(): AudioConcealment;
}
//# sourceMappingURL=mediaTrackStats.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"mediaTrackStats.d.ts","sourceRoot":"","sources":["../../../../src/webrtc/stats/media/mediaTrackStats.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEtD,MAAM,WAAW,UAAU;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,OAAO,CAAC;CAC7B;AAED,MAAM,WAAW,OAAO;IACpB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;CAClB;AACD,MAAM,WAAW,cAAc;IAC3B;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB,KAAK,EAAE,MAAM,CAAC;CACjB;AACD,MAAM,WAAW,UAAU;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEhD,qBAAa,eAAe;aAaJ,OAAO,EAAE,OAAO;aAChB,IAAI,EAAE,cAAc;aACpB,IAAI,EAAE,OAAO,GAAG,OAAO;IAd3C,OAAO,CAAC,IAAI,CAA4E;IACxF,OAAO,CAAC,OAAO,CAAuC;IACtD,OAAO,CAAC,UAAU,CAAyC;IAC3D,OAAO,CAAC,gBAAgB,CAAkE;IAC1F,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,KAAK,CAAM;IACnB,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,SAAS,CAAQ;IAEzB,YACoB,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,cAAc,EACpB,IAAI,EAAE,OAAO,GAAG,OAAO,EACvC;IAEG,OAAO,IAAI,cAAc,CAE/B;IAEM,OAAO,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAErC;IAEM,OAAO,IAAI,UAAU,CAE3B;IAEM,aAAa,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAEjD;IAEM,aAAa,IAAI,UAAU,CAEjC;IAEM,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAE3C;IAEM,YAAY,IAAI,MAAM,CAE5B;IAEM,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAExC;IAEM,UAAU,IAAI,OAAO,CAE3B;IAEM,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAG/C;IAEM,QAAQ,IAAI,MAAM,CAExB;IAEM,YAAY,IAAI,IAAI,CAE1B;IAED,IAAW,KAAK,CAAC,OAAO,EAAE,OAAO,EAEhC;IAED;;;OAGG;IACH,IAAW,KAAK,IAAI,OAAO,CAE1B;IAED,IAAW,KAAK,CAAC,OAAO,EAAE,OAAO,EAEhC;IAED;;;OAGG;IACH,IAAW,KAAK,IAAI,OAAO,CAE1B;IAED,IAAW,OAAO,CAAC,SAAS,EAAE,OAAO,EAEpC;IAED;;;OAGG;IACH,IAAW,OAAO,IAAI,OAAO,CAE5B;IAEM,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAErC;IAED;;OAEG;IACI,SAAS,IAAI,MAAM,CAEzB;IAED;;OAEG;IACI,mBAAmB,CAAC,sBAAsB,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAG3F;IAEM,mBAAmB,IAAI,gBAAgB,CAE7C;CACJ"}

View File

@@ -0,0 +1,142 @@
import _defineProperty from "@babel/runtime/helpers/defineProperty";
/*
Copyright 2023 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
export class MediaTrackStats {
constructor(trackId, type, kind) {
_defineProperty(this, "loss", {
packetsTotal: 0,
packetsLost: 0,
isDownloadStream: false
});
_defineProperty(this, "bitrate", {
download: 0,
upload: 0
});
_defineProperty(this, "resolution", {
width: -1,
height: -1
});
_defineProperty(this, "audioConcealment", {
concealedAudio: 0,
totalAudioDuration: 0
});
_defineProperty(this, "framerate", 0);
_defineProperty(this, "jitter", 0);
_defineProperty(this, "codec", "");
_defineProperty(this, "isAlive", true);
_defineProperty(this, "isMuted", false);
_defineProperty(this, "isEnabled", true);
this.trackId = trackId;
this.type = type;
this.kind = kind;
}
getType() {
return this.type;
}
setLoss(loss) {
this.loss = loss;
}
getLoss() {
return this.loss;
}
setResolution(resolution) {
this.resolution = resolution;
}
getResolution() {
return this.resolution;
}
setFramerate(framerate) {
this.framerate = framerate;
}
getFramerate() {
return this.framerate;
}
setBitrate(bitrate) {
this.bitrate = bitrate;
}
getBitrate() {
return this.bitrate;
}
setCodec(codecShortType) {
this.codec = codecShortType;
return true;
}
getCodec() {
return this.codec;
}
resetBitrate() {
this.bitrate = {
download: 0,
upload: 0
};
}
set alive(isAlive) {
this.isAlive = isAlive;
}
/**
* A MediaTrackState is alive if the corresponding MediaStreamTrack track bound to a transceiver and the
* MediaStreamTrack is in state MediaStreamTrack.readyState === live
*/
get alive() {
return this.isAlive;
}
set muted(isMuted) {
this.isMuted = isMuted;
}
/**
* A MediaTrackState.isMuted corresponding to MediaStreamTrack.muted.
* But these values only match if MediaTrackState.isAlive.
*/
get muted() {
return this.isMuted;
}
set enabled(isEnabled) {
this.isEnabled = isEnabled;
}
/**
* A MediaTrackState.isEnabled corresponding to MediaStreamTrack.enabled.
* But these values only match if MediaTrackState.isAlive.
*/
get enabled() {
return this.isEnabled;
}
setJitter(jitter) {
this.jitter = jitter;
}
/**
* Jitter in milliseconds
*/
getJitter() {
return this.jitter;
}
/**
* Audio concealment ration (conceled duration / total duration)
*/
setAudioConcealment(concealedAudioDuration, totalAudioDuration) {
this.audioConcealment.concealedAudio = concealedAudioDuration;
this.audioConcealment.totalAudioDuration = totalAudioDuration;
}
getAudioConcealment() {
return this.audioConcealment;
}
}
//# sourceMappingURL=mediaTrackStats.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,22 @@
import { type TrackID } from "../statsReport.ts";
import { MediaTrackStats } from "./mediaTrackStats.ts";
import { type MediaTrackHandler, type TrackId } from "./mediaTrackHandler.ts";
import { type MediaSsrcHandler } from "./mediaSsrcHandler.ts";
export declare class MediaTrackStatsHandler {
readonly mediaSsrcHandler: MediaSsrcHandler;
readonly mediaTrackHandler: MediaTrackHandler;
private readonly track2stats;
constructor(mediaSsrcHandler: MediaSsrcHandler, mediaTrackHandler: MediaTrackHandler);
/**
* Find tracks by rtc stats
* Argument report is any because the stats api is not consistent:
* For example `trackIdentifier`, `mid` not existing in every implementations
* https://www.w3.org/TR/webrtc-stats/#dom-rtcinboundrtpstreamstats
* https://developer.mozilla.org/en-US/docs/Web/API/RTCInboundRtpStreamStats
*/
findTrack2Stats(report: any, type: "remote" | "local"): MediaTrackStats | undefined;
findLocalVideoTrackStats(report: any): MediaTrackStats | undefined;
getTrack2stats(): Map<TrackID, MediaTrackStats>;
findTransceiverByTrackId(trackID: TrackId): undefined | RTCRtpTransceiver;
}
//# sourceMappingURL=mediaTrackStatsHandler.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"mediaTrackStatsHandler.d.ts","sourceRoot":"","sources":["../../../../src/webrtc/stats/media/mediaTrackStatsHandler.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,qBAAa,sBAAsB;aAIX,gBAAgB,EAAE,gBAAgB;aAClC,iBAAiB,EAAE,iBAAiB;IAJxD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAuC;IAEnE,YACoB,gBAAgB,EAAE,gBAAgB,EAClC,iBAAiB,EAAE,iBAAiB,EACpD;IAEJ;;;;;;OAMG;IACI,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,GAAG,eAAe,GAAG,SAAS,CAqCzF;IAEM,wBAAwB,CAAC,MAAM,EAAE,GAAG,GAAG,eAAe,GAAG,SAAS,CAMxE;IAEM,cAAc,IAAI,GAAG,CAAC,OAAO,EAAE,eAAe,CAAC,CAErD;IAEM,wBAAwB,CAAC,OAAO,EAAE,OAAO,GAAG,SAAS,GAAG,iBAAiB,CAE/E;CACJ"}

View File

@@ -0,0 +1,76 @@
import _defineProperty from "@babel/runtime/helpers/defineProperty";
/*
Copyright 2023 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import { MediaTrackStats } from "./mediaTrackStats.js";
export class MediaTrackStatsHandler {
constructor(mediaSsrcHandler, mediaTrackHandler) {
_defineProperty(this, "track2stats", new Map());
this.mediaSsrcHandler = mediaSsrcHandler;
this.mediaTrackHandler = mediaTrackHandler;
}
/**
* Find tracks by rtc stats
* Argument report is any because the stats api is not consistent:
* For example `trackIdentifier`, `mid` not existing in every implementations
* https://www.w3.org/TR/webrtc-stats/#dom-rtcinboundrtpstreamstats
* https://developer.mozilla.org/en-US/docs/Web/API/RTCInboundRtpStreamStats
*/
findTrack2Stats(report, type) {
let trackID;
if (report.trackIdentifier) {
trackID = report.trackIdentifier;
} else if (report.mid) {
trackID = type === "remote" ? this.mediaTrackHandler.getRemoteTrackIdByMid(report.mid) : this.mediaTrackHandler.getLocalTrackIdByMid(report.mid);
} else if (report.ssrc) {
const mid = this.mediaSsrcHandler.findMidBySsrc(report.ssrc, type);
if (!mid) {
return undefined;
}
trackID = type === "remote" ? this.mediaTrackHandler.getRemoteTrackIdByMid(report.mid) : this.mediaTrackHandler.getLocalTrackIdByMid(report.mid);
}
if (!trackID) {
return undefined;
}
let trackStats = this.track2stats.get(trackID);
if (!trackStats) {
const track = this.mediaTrackHandler.getTackById(trackID);
if (track !== undefined) {
const kind = track.kind === "audio" ? track.kind : "video";
trackStats = new MediaTrackStats(trackID, type, kind);
this.track2stats.set(trackID, trackStats);
} else {
return undefined;
}
}
return trackStats;
}
findLocalVideoTrackStats(report) {
const localVideoTracks = this.mediaTrackHandler.getLocalTracks("video");
if (localVideoTracks.length === 0) {
return undefined;
}
return this.findTrack2Stats(report, "local");
}
getTrack2stats() {
return this.track2stats;
}
findTransceiverByTrackId(trackID) {
return this.mediaTrackHandler.getTransceiverByTrackId(trackID);
}
}
//# sourceMappingURL=mediaTrackStatsHandler.js.map

File diff suppressed because one or more lines are too long