werift 0.18.3 → 0.18.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/dtls/src/flight/server/flight2.js +1 -1
- package/lib/dtls/src/flight/server/flight2.js.map +1 -1
- package/lib/rtp/src/container/ebml/ebml.d.ts +5 -6
- package/lib/rtp/src/container/ebml/ebml.js +14 -13
- package/lib/rtp/src/container/ebml/ebml.js.map +1 -1
- package/lib/rtp/src/container/ebml/typedArrayUtils.d.ts +3 -4
- package/lib/rtp/src/container/ebml/typedArrayUtils.js +9 -10
- package/lib/rtp/src/container/ebml/typedArrayUtils.js.map +1 -1
- package/lib/rtp/src/container/index.d.ts +2 -0
- package/lib/rtp/src/{processor/source → container}/index.js +2 -3
- package/lib/rtp/src/container/index.js.map +1 -0
- package/lib/rtp/src/helper.d.ts +4 -0
- package/lib/rtp/src/helper.js +14 -1
- package/lib/rtp/src/helper.js.map +1 -1
- package/lib/rtp/src/index.d.ts +2 -0
- package/lib/rtp/src/index.js +2 -0
- package/lib/rtp/src/index.js.map +1 -1
- package/lib/rtp/src/processor/depacketizer.d.ts +1 -1
- package/lib/rtp/src/processor/depacketizer.js +16 -9
- package/lib/rtp/src/processor/depacketizer.js.map +1 -1
- package/lib/rtp/src/processor/depacketizerCallback.d.ts +14 -6
- package/lib/rtp/src/processor/depacketizerCallback.js +2 -35
- package/lib/rtp/src/processor/depacketizerCallback.js.map +1 -1
- package/lib/rtp/src/processor/dtx.d.ts +1 -0
- package/lib/rtp/src/processor/dtx.js +10 -1
- package/lib/rtp/src/processor/dtx.js.map +1 -1
- package/lib/rtp/src/processor/dtxCallback.d.ts +14 -5
- package/lib/rtp/src/processor/dtxCallback.js +2 -35
- package/lib/rtp/src/processor/dtxCallback.js.map +1 -1
- package/lib/rtp/src/processor/index.d.ts +3 -1
- package/lib/rtp/src/processor/index.js +3 -1
- package/lib/rtp/src/processor/index.js.map +1 -1
- package/lib/rtp/src/processor/interface.d.ts +17 -0
- package/lib/rtp/src/processor/interface.js +57 -0
- package/lib/rtp/src/processor/interface.js.map +1 -1
- package/lib/rtp/src/processor/jitterBuffer.d.ts +1 -2
- package/lib/rtp/src/processor/jitterBuffer.js +3 -1
- package/lib/rtp/src/processor/jitterBuffer.js.map +1 -1
- package/lib/rtp/src/processor/jitterBufferCallback.d.ts +14 -5
- package/lib/rtp/src/processor/jitterBufferCallback.js +2 -35
- package/lib/rtp/src/processor/jitterBufferCallback.js.map +1 -1
- package/lib/rtp/src/processor/jitterBufferTransformer.d.ts +1 -1
- package/lib/rtp/src/processor/lipsync.d.ts +19 -8
- package/lib/rtp/src/processor/lipsync.js +131 -83
- package/lib/rtp/src/processor/lipsync.js.map +1 -1
- package/lib/rtp/src/processor/lipsyncCallback.d.ts +8 -5
- package/lib/rtp/src/processor/lipsyncCallback.js +39 -4
- package/lib/rtp/src/processor/lipsyncCallback.js.map +1 -1
- package/lib/rtp/src/processor/mute.d.ts +17 -4
- package/lib/rtp/src/processor/mute.js +121 -40
- package/lib/rtp/src/processor/mute.js.map +1 -1
- package/lib/rtp/src/processor/muteCallback.d.ts +5 -2
- package/lib/rtp/src/processor/muteCallback.js +23 -7
- package/lib/rtp/src/processor/muteCallback.js.map +1 -1
- package/lib/rtp/src/processor/nack.d.ts +6 -6
- package/lib/rtp/src/processor/nack.js +23 -17
- package/lib/rtp/src/processor/nack.js.map +1 -1
- package/lib/rtp/src/processor/nackHandlerCallback.d.ts +14 -7
- package/lib/rtp/src/processor/nackHandlerCallback.js +2 -29
- package/lib/rtp/src/processor/nackHandlerCallback.js.map +1 -1
- package/lib/rtp/src/processor/ntpTime.d.ts +7 -7
- package/lib/rtp/src/processor/ntpTime.js +27 -29
- package/lib/rtp/src/processor/ntpTime.js.map +1 -1
- package/lib/rtp/src/processor/ntpTimeCallback.d.ts +13 -4
- package/lib/rtp/src/processor/ntpTimeCallback.js +2 -29
- package/lib/rtp/src/processor/ntpTimeCallback.js.map +1 -1
- package/lib/rtp/src/processor/rtcpCallback.d.ts +18 -0
- package/lib/rtp/src/processor/{source/rtcpCallback.js → rtcpCallback.js} +25 -3
- package/lib/rtp/src/processor/rtcpCallback.js.map +1 -0
- package/lib/rtp/src/processor/rtpCallback.d.ts +28 -0
- package/lib/rtp/src/processor/rtpCallback.js +125 -0
- package/lib/rtp/src/processor/rtpCallback.js.map +1 -0
- package/lib/rtp/src/processor/{source/rtpStream.d.ts → rtpStream.d.ts} +1 -1
- package/lib/rtp/src/processor/{source/rtpStream.js → rtpStream.js} +1 -1
- package/lib/rtp/src/processor/rtpStream.js.map +1 -0
- package/lib/rtp/src/processor/rtpTimeCallback.d.ts +13 -5
- package/lib/rtp/src/processor/rtpTimeCallback.js +2 -29
- package/lib/rtp/src/processor/rtpTimeCallback.js.map +1 -1
- package/lib/rtp/src/processor/webm.d.ts +8 -4
- package/lib/rtp/src/processor/webm.js +41 -8
- package/lib/rtp/src/processor/webm.js.map +1 -1
- package/lib/rtp/src/processor/webmCallback.d.ts +6 -5
- package/lib/rtp/src/processor/webmCallback.js +21 -7
- package/lib/rtp/src/processor/webmCallback.js.map +1 -1
- package/lib/webrtc/src/nonstandard/userMedia.d.ts +32 -23
- package/lib/webrtc/src/nonstandard/userMedia.js +49 -131
- package/lib/webrtc/src/nonstandard/userMedia.js.map +1 -1
- package/package.json +1 -1
- package/src/nonstandard/userMedia.ts +69 -75
- package/lib/rtp/src/processor/source/index.d.ts +0 -3
- package/lib/rtp/src/processor/source/index.js.map +0 -1
- package/lib/rtp/src/processor/source/rtcpCallback.d.ts +0 -13
- package/lib/rtp/src/processor/source/rtcpCallback.js.map +0 -1
- package/lib/rtp/src/processor/source/rtpCallback.d.ts +0 -19
- package/lib/rtp/src/processor/source/rtpCallback.js +0 -62
- package/lib/rtp/src/processor/source/rtpCallback.js.map +0 -1
- package/lib/rtp/src/processor/source/rtpStream.js.map +0 -1
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MuteHandlerBase = void 0;
|
|
4
4
|
const crypto_1 = require("crypto");
|
|
5
|
+
const __1 = require("..");
|
|
5
6
|
class MuteHandlerBase {
|
|
6
7
|
constructor(output, props) {
|
|
7
8
|
Object.defineProperty(this, "output", {
|
|
@@ -26,13 +27,13 @@ class MuteHandlerBase {
|
|
|
26
27
|
enumerable: true,
|
|
27
28
|
configurable: true,
|
|
28
29
|
writable: true,
|
|
29
|
-
value:
|
|
30
|
+
value: void 0
|
|
30
31
|
});
|
|
31
|
-
Object.defineProperty(this, "
|
|
32
|
+
Object.defineProperty(this, "index", {
|
|
32
33
|
enumerable: true,
|
|
33
34
|
configurable: true,
|
|
34
35
|
writable: true,
|
|
35
|
-
value:
|
|
36
|
+
value: 0
|
|
36
37
|
});
|
|
37
38
|
Object.defineProperty(this, "ended", {
|
|
38
39
|
enumerable: true,
|
|
@@ -40,7 +41,7 @@ class MuteHandlerBase {
|
|
|
40
41
|
writable: true,
|
|
41
42
|
value: false
|
|
42
43
|
});
|
|
43
|
-
Object.defineProperty(this, "
|
|
44
|
+
Object.defineProperty(this, "baseTime", {
|
|
44
45
|
enumerable: true,
|
|
45
46
|
configurable: true,
|
|
46
47
|
writable: true,
|
|
@@ -52,60 +53,140 @@ class MuteHandlerBase {
|
|
|
52
53
|
writable: true,
|
|
53
54
|
value: void 0
|
|
54
55
|
});
|
|
56
|
+
Object.defineProperty(this, "internalStats", {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
configurable: true,
|
|
59
|
+
writable: true,
|
|
60
|
+
value: {}
|
|
61
|
+
});
|
|
62
|
+
/**ms */
|
|
63
|
+
Object.defineProperty(this, "lastCommittedTime", {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
configurable: true,
|
|
66
|
+
writable: true,
|
|
67
|
+
value: 0
|
|
68
|
+
});
|
|
69
|
+
Object.defineProperty(this, "lastExecutionTime", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
configurable: true,
|
|
72
|
+
writable: true,
|
|
73
|
+
value: 0
|
|
74
|
+
});
|
|
75
|
+
/**ms */
|
|
76
|
+
Object.defineProperty(this, "interval", {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
configurable: true,
|
|
79
|
+
writable: true,
|
|
80
|
+
value: this.props.interval
|
|
81
|
+
});
|
|
82
|
+
Object.defineProperty(this, "bufferDuration", {
|
|
83
|
+
enumerable: true,
|
|
84
|
+
configurable: true,
|
|
85
|
+
writable: true,
|
|
86
|
+
value: this.interval / 2
|
|
87
|
+
});
|
|
88
|
+
Object.defineProperty(this, "bufferLength", {
|
|
89
|
+
enumerable: true,
|
|
90
|
+
configurable: true,
|
|
91
|
+
writable: true,
|
|
92
|
+
value: this.props.bufferLength * 2
|
|
93
|
+
});
|
|
94
|
+
/**ms */
|
|
95
|
+
Object.defineProperty(this, "lastFrameReceivedAt", {
|
|
96
|
+
enumerable: true,
|
|
97
|
+
configurable: true,
|
|
98
|
+
writable: true,
|
|
99
|
+
value: 0
|
|
100
|
+
});
|
|
55
101
|
Object.defineProperty(this, "processInput", {
|
|
56
102
|
enumerable: true,
|
|
57
103
|
configurable: true,
|
|
58
104
|
writable: true,
|
|
59
105
|
value: ({ frame, eol }) => {
|
|
60
|
-
if (
|
|
106
|
+
if (!frame) {
|
|
61
107
|
this.stop();
|
|
62
|
-
return [{ eol
|
|
108
|
+
return [{ eol }];
|
|
109
|
+
}
|
|
110
|
+
if (this.ended) {
|
|
111
|
+
return [];
|
|
63
112
|
}
|
|
64
|
-
if (
|
|
65
|
-
this.
|
|
66
|
-
|
|
67
|
-
|
|
113
|
+
if (this.baseTime == undefined) {
|
|
114
|
+
this.baseTime = frame.time;
|
|
115
|
+
this.currentTimestamp = this.baseTime;
|
|
116
|
+
this.lastExecutionTime = this.baseTime;
|
|
117
|
+
this.lastCommittedTime = this.baseTime;
|
|
118
|
+
this.lastFrameReceivedAt = Date.now();
|
|
119
|
+
}
|
|
120
|
+
// 過去のフレームを捨てる
|
|
121
|
+
if (frame.time < this.lastCommittedTime) {
|
|
122
|
+
return [];
|
|
123
|
+
}
|
|
124
|
+
// NTPの同期ずれが疑われるので捨てる
|
|
125
|
+
const now = Date.now();
|
|
126
|
+
const gap = 5000; // RTCP SR interval;
|
|
127
|
+
const lastCommittedElapsed = frame.time - this.lastCommittedTime;
|
|
128
|
+
const lastFrameReceivedElapsed = now - this.lastFrameReceivedAt;
|
|
129
|
+
if (gap < lastFrameReceivedElapsed && lastCommittedElapsed < gap) {
|
|
130
|
+
this.internalStats["invalidFrameTime"] = {
|
|
131
|
+
count: (this.internalStats["invalidFrameTime"]?.count ?? 0) + 1,
|
|
132
|
+
at: new Date().toISOString(),
|
|
133
|
+
lastCommittedElapsed,
|
|
134
|
+
lastFrameReceivedElapsed,
|
|
135
|
+
};
|
|
136
|
+
return [];
|
|
137
|
+
}
|
|
138
|
+
this.lastFrameReceivedAt = now;
|
|
139
|
+
const elapsed = frame.time - this.baseTime;
|
|
140
|
+
const index = (0, __1.int)(elapsed / this.bufferDuration) % this.bufferLength;
|
|
141
|
+
this.buffer[index].push(frame);
|
|
142
|
+
const lastExecution = frame.time - this.lastExecutionTime;
|
|
143
|
+
if (lastExecution >= this.interval) {
|
|
144
|
+
const times = (0, __1.int)(lastExecution / this.bufferDuration) - 1;
|
|
145
|
+
this.lastExecutionTime = this.currentTimestamp;
|
|
146
|
+
for (let i = 0; i < times; i++) {
|
|
147
|
+
this.executeTask();
|
|
148
|
+
this.lastExecutionTime += this.bufferDuration;
|
|
68
149
|
}
|
|
69
150
|
}
|
|
70
151
|
return [];
|
|
71
152
|
}
|
|
72
153
|
});
|
|
154
|
+
this.buffer = [...new Array(this.bufferLength)].map(() => []);
|
|
73
155
|
}
|
|
74
156
|
toJSON() {
|
|
75
|
-
return { id: this.id };
|
|
157
|
+
return { ...this.internalStats, id: this.id };
|
|
76
158
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
159
|
+
executeTask() {
|
|
160
|
+
const { ptime, dummyPacket } = this.props;
|
|
161
|
+
const buffer = this.buffer[this.index].sort((a, b) => a.time - b.time);
|
|
162
|
+
const last = buffer.at(-1);
|
|
163
|
+
const expect = last
|
|
164
|
+
? last.time +
|
|
165
|
+
// offset
|
|
166
|
+
ptime
|
|
167
|
+
: this.currentTimestamp;
|
|
168
|
+
if (expect < this.currentTimestamp + this.bufferDuration) {
|
|
169
|
+
for (let time = expect; time < this.currentTimestamp + this.bufferDuration; time += ptime) {
|
|
170
|
+
buffer.push({
|
|
171
|
+
time,
|
|
172
|
+
data: dummyPacket,
|
|
173
|
+
isKeyframe: true,
|
|
174
|
+
});
|
|
90
175
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
this.buffer = [];
|
|
104
|
-
this.currentTimestamp += interval;
|
|
105
|
-
}, interval);
|
|
176
|
+
}
|
|
177
|
+
this.currentTimestamp += this.bufferDuration;
|
|
178
|
+
this.internalStats["mute"] = new Date().toISOString();
|
|
179
|
+
this.buffer[this.index] = [];
|
|
180
|
+
buffer.forEach((frame) => {
|
|
181
|
+
this.output({ frame });
|
|
182
|
+
this.lastCommittedTime = frame.time;
|
|
183
|
+
});
|
|
184
|
+
this.index++;
|
|
185
|
+
if (this.index === this.bufferLength) {
|
|
186
|
+
this.index = 0;
|
|
187
|
+
}
|
|
106
188
|
}
|
|
107
189
|
stop() {
|
|
108
|
-
clearInterval(this.intervalId);
|
|
109
190
|
this.ended = true;
|
|
110
191
|
this.buffer = [];
|
|
111
192
|
this.output = undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mute.js","sourceRoot":"","sources":["../../../../../rt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AAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,cAAc,EAAE;YACxD,KACE,IAAI,IAAI,GAAG,MAAM,EACjB,IAAI,GAAG,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,cAAc,EAClD,IAAI,IAAI,KAAK,EACb;gBACA,MAAM,CAAC,IAAI,CAAC;oBACV,IAAI;oBACJ,IAAI,EAAE,WAAW;oBACjB,UAAU,EAAE,IAAI;iBACjB,CAAC,CAAC;aACJ;SACF;QACD,IAAI,CAAC,gBAAgB,IAAI,IAAI,CAAC,cAAc,CAAC;QAC7C,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QAEtD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;QAC7B,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;YACvB,IAAI,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;YACvB,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC,IAAI,CAAC;QACtC,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,YAAY,EAAE;YACpC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;SAChB;IACH,CAAC;IAEO,IAAI;QACV,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,SAAgB,CAAC;IACjC,CAAC;CAyDF;AAzID,0CAyIC","sourcesContent":["import { randomUUID } from \"crypto\";\n\nimport { int } from \"..\";\nimport { CodecFrame, DepacketizerOutput } from \"./depacketizer\";\nimport { Processor } from \"./interface\";\n\nexport type MuteInput = DepacketizerOutput;\n\nexport type MuteOutput = MuteInput;\n\nexport class MuteHandlerBase implements Processor<MuteInput, MuteOutput> {\n readonly id = randomUUID();\n private buffer: CodecFrame[][];\n private index = 0;\n private ended = false;\n private baseTime?: number;\n private currentTimestamp!: number;\n private internalStats = {};\n /**ms */\n private lastCommittedTime = 0;\n private lastExecutionTime = 0;\n /**ms */\n private interval = this.props.interval;\n private bufferDuration: number = this.interval / 2;\n private bufferLength = this.props.bufferLength * 2;\n /**ms */\n private lastFrameReceivedAt = 0;\n\n constructor(\n private output: (o: MuteOutput) => void,\n private props: {\n ptime: number;\n dummyPacket: Buffer;\n /**ms\n * @description intervalごとに無音区間に空パケットを挿入する\n */\n interval: number;\n bufferLength: number;\n }\n ) {\n this.buffer = [...new Array(this.bufferLength)].map(() => []);\n }\n\n toJSON(): Record<string, any> {\n return { ...this.internalStats, id: this.id };\n }\n\n private executeTask() {\n const { ptime, dummyPacket } = this.props;\n\n const buffer = this.buffer[this.index].sort((a, b) => a.time - b.time);\n const last = buffer.at(-1);\n const expect = last\n ? last.time +\n // offset\n ptime\n : this.currentTimestamp;\n\n if (expect < this.currentTimestamp + this.bufferDuration) {\n for (\n let time = expect;\n time < this.currentTimestamp + this.bufferDuration;\n time += ptime\n ) {\n buffer.push({\n time,\n data: dummyPacket,\n isKeyframe: true,\n });\n }\n }\n this.currentTimestamp += this.bufferDuration;\n this.internalStats[\"mute\"] = new Date().toISOString();\n\n this.buffer[this.index] = [];\n buffer.forEach((frame) => {\n this.output({ frame });\n this.lastCommittedTime = frame.time;\n });\n\n this.index++;\n if (this.index === this.bufferLength) {\n this.index = 0;\n }\n }\n\n private stop() {\n this.ended = true;\n this.buffer = [];\n this.output = undefined as any;\n }\n\n processInput = ({ frame, eol }: MuteInput): MuteOutput[] => {\n if (!frame) {\n this.stop();\n return [{ eol }];\n }\n\n if (this.ended) {\n return [];\n }\n\n if (this.baseTime == undefined) {\n this.baseTime = frame.time;\n this.currentTimestamp = this.baseTime;\n this.lastExecutionTime = this.baseTime;\n this.lastCommittedTime = this.baseTime;\n this.lastFrameReceivedAt = Date.now();\n }\n\n // 過去のフレームを捨てる\n if (frame.time < this.lastCommittedTime) {\n return [];\n }\n\n // NTPの同期ずれが疑われるので捨てる\n const now = Date.now();\n const gap = 5000; // RTCP SR interval;\n const lastCommittedElapsed = frame.time - this.lastCommittedTime;\n const lastFrameReceivedElapsed = now - this.lastFrameReceivedAt;\n if (gap < lastFrameReceivedElapsed && lastCommittedElapsed < gap) {\n this.internalStats[\"invalidFrameTime\"] = {\n count: (this.internalStats[\"invalidFrameTime\"]?.count ?? 0) + 1,\n at: new Date().toISOString(),\n lastCommittedElapsed,\n lastFrameReceivedElapsed,\n };\n return [];\n }\n this.lastFrameReceivedAt = now;\n\n const elapsed = frame.time - this.baseTime;\n const index = int(elapsed / this.bufferDuration) % this.bufferLength;\n this.buffer[index].push(frame);\n\n const lastExecution = frame.time - this.lastExecutionTime;\n if (lastExecution >= this.interval) {\n const times = int(lastExecution / this.bufferDuration) - 1;\n this.lastExecutionTime = this.currentTimestamp;\n for (let i = 0; i < times; i++) {\n this.executeTask();\n this.lastExecutionTime += this.bufferDuration;\n }\n }\n\n return [];\n };\n}\n"]}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { SimpleProcessorCallback } from "./interface";
|
|
1
2
|
import { MuteHandlerBase, MuteInput, MuteOutput } from "./mute";
|
|
2
|
-
export declare class MuteCallback extends MuteHandlerBase {
|
|
3
|
+
export declare class MuteCallback extends MuteHandlerBase implements SimpleProcessorCallback<MuteInput, MuteOutput> {
|
|
3
4
|
private cb?;
|
|
5
|
+
destructor?: () => void;
|
|
4
6
|
constructor(props: ConstructorParameters<typeof MuteHandlerBase>[1]);
|
|
5
|
-
pipe: (cb: (input: MuteOutput) => void) => void;
|
|
7
|
+
pipe: (cb: (input: MuteOutput) => void, destructor?: () => void) => this;
|
|
6
8
|
input: (input: MuteInput) => void;
|
|
9
|
+
destroy: () => void;
|
|
7
10
|
}
|
|
@@ -15,12 +15,20 @@ class MuteCallback extends mute_1.MuteHandlerBase {
|
|
|
15
15
|
writable: true,
|
|
16
16
|
value: void 0
|
|
17
17
|
});
|
|
18
|
+
Object.defineProperty(this, "destructor", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
configurable: true,
|
|
21
|
+
writable: true,
|
|
22
|
+
value: void 0
|
|
23
|
+
});
|
|
18
24
|
Object.defineProperty(this, "pipe", {
|
|
19
25
|
enumerable: true,
|
|
20
26
|
configurable: true,
|
|
21
27
|
writable: true,
|
|
22
|
-
value: (cb) => {
|
|
28
|
+
value: (cb, destructor) => {
|
|
23
29
|
this.cb = cb;
|
|
30
|
+
this.destructor = destructor;
|
|
31
|
+
return this;
|
|
24
32
|
}
|
|
25
33
|
});
|
|
26
34
|
Object.defineProperty(this, "input", {
|
|
@@ -28,15 +36,23 @@ class MuteCallback extends mute_1.MuteHandlerBase {
|
|
|
28
36
|
configurable: true,
|
|
29
37
|
writable: true,
|
|
30
38
|
value: (input) => {
|
|
31
|
-
if (!this.cb) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
39
|
for (const output of this.processInput(input)) {
|
|
35
|
-
this.cb
|
|
40
|
+
if (this.cb) {
|
|
41
|
+
this.cb(output);
|
|
42
|
+
}
|
|
36
43
|
}
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(this, "destroy", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
configurable: true,
|
|
49
|
+
writable: true,
|
|
50
|
+
value: () => {
|
|
51
|
+
if (this.destructor) {
|
|
52
|
+
this.destructor();
|
|
53
|
+
this.destructor = undefined;
|
|
39
54
|
}
|
|
55
|
+
this.cb = undefined;
|
|
40
56
|
}
|
|
41
57
|
});
|
|
42
58
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"muteCallback.js","sourceRoot":"","sources":["../../../../../rtp/src/processor/muteCallback.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"muteCallback.js","sourceRoot":"","sources":["../../../../../rtp/src/processor/muteCallback.ts"],"names":[],"mappings":";;;AACA,iCAAgE;AAEhE,MAAa,YACX,SAAQ,sBAAe;IAMvB,YAAY,KAAuD;QACjE,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;YACV,IAAI,IAAI,CAAC,EAAE,EAAE;gBACX,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;aACZ;QACH,CAAC,EAAE,KAAK,CAAC,CAAC;QARZ;;;;;WAAyC;QACzC;;;;;WAAwB;QAUxB;;;;mBAAO,CAAC,EAA+B,EAAE,UAAuB,EAAE,EAAE;gBAClE,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;gBACb,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;gBAC7B,OAAO,IAAI,CAAC;YACd,CAAC;WAAC;QAEF;;;;mBAAQ,CAAC,KAAgB,EAAE,EAAE;gBAC3B,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE;oBAC7C,IAAI,IAAI,CAAC,EAAE,EAAE;wBACX,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;qBACjB;iBACF;YACH,CAAC;WAAC;QAEF;;;;mBAAU,GAAG,EAAE;gBACb,IAAI,IAAI,CAAC,UAAU,EAAE;oBACnB,IAAI,CAAC,UAAU,EAAE,CAAC;oBAClB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;iBAC7B;gBACD,IAAI,CAAC,EAAE,GAAG,SAAS,CAAC;YACtB,CAAC;WAAC;IAtBF,CAAC;CAuBF;AApCD,oCAoCC","sourcesContent":["import { SimpleProcessorCallback } from \"./interface\";\nimport { MuteHandlerBase, MuteInput, MuteOutput } from \"./mute\";\n\nexport class MuteCallback\n extends MuteHandlerBase\n implements SimpleProcessorCallback<MuteInput, MuteOutput>\n{\n private cb?: (input: MuteOutput) => void;\n destructor?: () => void;\n\n constructor(props: ConstructorParameters<typeof MuteHandlerBase>[1]) {\n super((o) => {\n if (this.cb) {\n this.cb(o);\n }\n }, props);\n }\n\n pipe = (cb: (input: MuteOutput) => void, destructor?: () => void) => {\n this.cb = cb;\n this.destructor = destructor;\n return this;\n };\n\n input = (input: MuteInput) => {\n for (const output of this.processInput(input)) {\n if (this.cb) {\n this.cb(output);\n }\n }\n };\n\n destroy = () => {\n if (this.destructor) {\n this.destructor();\n this.destructor = undefined;\n }\n this.cb = undefined;\n };\n}\n"]}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import Event from "rx.mini";
|
|
2
|
-
import { RtcpTransportLayerFeedback } from "
|
|
3
|
-
import { GenericNack } from "../rtcp/rtpfb/nack";
|
|
2
|
+
import { GenericNack, RtcpTransportLayerFeedback } from "..";
|
|
4
3
|
import { Processor } from "./interface";
|
|
5
|
-
import { RtpOutput } from "./
|
|
4
|
+
import { RtpOutput } from "./rtpCallback";
|
|
6
5
|
export type NackHandlerInput = RtpOutput;
|
|
7
6
|
export type NackHandlerOutput = RtpOutput;
|
|
8
7
|
export declare class NackHandlerBase implements Processor<NackHandlerInput, NackHandlerOutput> {
|
|
@@ -10,11 +9,12 @@ export declare class NackHandlerBase implements Processor<NackHandlerInput, Nack
|
|
|
10
9
|
private onNack;
|
|
11
10
|
private newEstSeqNum;
|
|
12
11
|
private _lost;
|
|
13
|
-
private
|
|
12
|
+
private clearNackInterval?;
|
|
14
13
|
private internalStats;
|
|
15
|
-
readonly
|
|
14
|
+
readonly onNackSent: Event<[GenericNack]>;
|
|
15
|
+
readonly onPacketLost: Event<[number]>;
|
|
16
16
|
mediaSourceSsrc?: number;
|
|
17
|
-
retryCount
|
|
17
|
+
readonly retryCount = 10;
|
|
18
18
|
stopped: boolean;
|
|
19
19
|
constructor(senderSsrc: number, onNack: (rtcp: RtcpTransportLayerFeedback) => Promise<void>);
|
|
20
20
|
toJSON(): Record<string, any>;
|
|
@@ -7,9 +7,7 @@ exports.NackHandlerBase = void 0;
|
|
|
7
7
|
const debug_1 = __importDefault(require("debug"));
|
|
8
8
|
const range_1 = __importDefault(require("lodash/range"));
|
|
9
9
|
const rx_mini_1 = __importDefault(require("rx.mini"));
|
|
10
|
-
const
|
|
11
|
-
const rtpfb_1 = require("../rtcp/rtpfb");
|
|
12
|
-
const nack_1 = require("../rtcp/rtpfb/nack");
|
|
10
|
+
const __1 = require("..");
|
|
13
11
|
const log = (0, debug_1.default)("werift-rtp : packages/rtp/src/processor/nack.ts");
|
|
14
12
|
const LOST_SIZE = 30 * 5;
|
|
15
13
|
class NackHandlerBase {
|
|
@@ -38,7 +36,7 @@ class NackHandlerBase {
|
|
|
38
36
|
writable: true,
|
|
39
37
|
value: {}
|
|
40
38
|
});
|
|
41
|
-
Object.defineProperty(this, "
|
|
39
|
+
Object.defineProperty(this, "clearNackInterval", {
|
|
42
40
|
enumerable: true,
|
|
43
41
|
configurable: true,
|
|
44
42
|
writable: true,
|
|
@@ -50,6 +48,12 @@ class NackHandlerBase {
|
|
|
50
48
|
writable: true,
|
|
51
49
|
value: {}
|
|
52
50
|
});
|
|
51
|
+
Object.defineProperty(this, "onNackSent", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
configurable: true,
|
|
54
|
+
writable: true,
|
|
55
|
+
value: new rx_mini_1.default()
|
|
56
|
+
});
|
|
53
57
|
Object.defineProperty(this, "onPacketLost", {
|
|
54
58
|
enumerable: true,
|
|
55
59
|
configurable: true,
|
|
@@ -81,6 +85,7 @@ class NackHandlerBase {
|
|
|
81
85
|
value: (input) => {
|
|
82
86
|
if (input.rtp) {
|
|
83
87
|
this.addPacket(input.rtp);
|
|
88
|
+
this.internalStats["nackHandler"] = new Date().toISOString();
|
|
84
89
|
return [input];
|
|
85
90
|
}
|
|
86
91
|
this.stop();
|
|
@@ -94,28 +99,28 @@ class NackHandlerBase {
|
|
|
94
99
|
value: () => new Promise((r, f) => {
|
|
95
100
|
if (this.lostSeqNumbers.length > 0 && this.mediaSourceSsrc) {
|
|
96
101
|
this.internalStats["count"] = (this.internalStats["count"] ?? 0) + 1;
|
|
97
|
-
const nack = new
|
|
102
|
+
const nack = new __1.GenericNack({
|
|
98
103
|
senderSsrc: this.senderSsrc,
|
|
99
104
|
mediaSourceSsrc: this.mediaSourceSsrc,
|
|
100
105
|
lost: this.lostSeqNumbers,
|
|
101
106
|
});
|
|
102
|
-
const rtcp = new
|
|
107
|
+
const rtcp = new __1.RtcpTransportLayerFeedback({
|
|
103
108
|
feedback: nack,
|
|
104
109
|
});
|
|
105
110
|
this.onNack(rtcp).then(r).catch(f);
|
|
106
111
|
this.updateRetryCount();
|
|
107
|
-
this.
|
|
112
|
+
this.onNackSent.execute(nack);
|
|
108
113
|
}
|
|
109
114
|
})
|
|
110
115
|
});
|
|
111
116
|
}
|
|
112
117
|
toJSON() {
|
|
113
118
|
return {
|
|
119
|
+
...this.internalStats,
|
|
114
120
|
newEstSeqNum: this.newEstSeqNum,
|
|
115
121
|
lostLength: Object.values(this._lost).length,
|
|
116
122
|
senderSsrc: this.senderSsrc,
|
|
117
123
|
mediaSourceSsrc: this.mediaSourceSsrc,
|
|
118
|
-
...this.internalStats,
|
|
119
124
|
};
|
|
120
125
|
}
|
|
121
126
|
get lostSeqNumbers() {
|
|
@@ -126,15 +131,15 @@ class NackHandlerBase {
|
|
|
126
131
|
}
|
|
127
132
|
setLost(seq, count) {
|
|
128
133
|
this._lost[seq] = count;
|
|
129
|
-
if (this.
|
|
134
|
+
if (this.clearNackInterval || this.stopped) {
|
|
130
135
|
return;
|
|
131
136
|
}
|
|
132
|
-
this.
|
|
137
|
+
this.clearNackInterval = __1.timer.setInterval(async () => {
|
|
133
138
|
try {
|
|
134
139
|
await this.sendNack();
|
|
135
140
|
if (!Object.keys(this._lost).length) {
|
|
136
|
-
|
|
137
|
-
this.
|
|
141
|
+
this.clearNackInterval?.();
|
|
142
|
+
this.clearNackInterval = undefined;
|
|
138
143
|
}
|
|
139
144
|
}
|
|
140
145
|
catch (error) {
|
|
@@ -157,12 +162,12 @@ class NackHandlerBase {
|
|
|
157
162
|
this.removeLost(sequenceNumber);
|
|
158
163
|
return;
|
|
159
164
|
}
|
|
160
|
-
if (sequenceNumber === (0,
|
|
165
|
+
if (sequenceNumber === (0, __1.uint16Add)(this.newEstSeqNum, 1)) {
|
|
161
166
|
this.newEstSeqNum = sequenceNumber;
|
|
162
167
|
}
|
|
163
|
-
else if (sequenceNumber > (0,
|
|
168
|
+
else if (sequenceNumber > (0, __1.uint16Add)(this.newEstSeqNum, 1)) {
|
|
164
169
|
// packet lost detected
|
|
165
|
-
(0, range_1.default)((0,
|
|
170
|
+
(0, range_1.default)((0, __1.uint16Add)(this.newEstSeqNum, 1), sequenceNumber).forEach((seq) => {
|
|
166
171
|
this.setLost(seq, 1);
|
|
167
172
|
});
|
|
168
173
|
// this.receiver.sendRtcpPLI(this.mediaSourceSsrc);
|
|
@@ -183,7 +188,8 @@ class NackHandlerBase {
|
|
|
183
188
|
stop() {
|
|
184
189
|
this.stopped = true;
|
|
185
190
|
this._lost = {};
|
|
186
|
-
|
|
191
|
+
this.clearNackInterval?.();
|
|
192
|
+
this.onNackSent.allUnsubscribe();
|
|
187
193
|
this.onPacketLost.allUnsubscribe();
|
|
188
194
|
this.onNack = undefined;
|
|
189
195
|
}
|
|
@@ -192,7 +198,7 @@ class NackHandlerBase {
|
|
|
192
198
|
const count = this._lost[seq]++;
|
|
193
199
|
if (count > this.retryCount) {
|
|
194
200
|
this.removeLost(seq);
|
|
195
|
-
|
|
201
|
+
this.onPacketLost.execute(seq);
|
|
196
202
|
}
|
|
197
203
|
});
|
|
198
204
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nack.js","sourceRoot":"","sources":["../../../../../rtp/src/processor/nack.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,yDAAiC;AACjC,sDAA4B;AAE5B,
|
|
1
|
+
{"version":3,"file":"nack.js","sourceRoot":"","sources":["../../../../../rtp/src/processor/nack.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,yDAAiC;AACjC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from \"debug\";\nimport range from \"lodash/range\";\nimport Event from \"rx.mini\";\n\nimport {\n GenericNack,\n RtcpTransportLayerFeedback,\n RtpPacket,\n timer,\n uint16Add,\n} from \"..\";\nimport { Processor } from \"./interface\";\nimport { RtpOutput } from \"./rtpCallback\";\n\nconst log = debug(\"werift-rtp : packages/rtp/src/processor/nack.ts\");\n\nconst LOST_SIZE = 30 * 5;\n\nexport type NackHandlerInput = RtpOutput;\n\nexport type NackHandlerOutput = RtpOutput;\n\nexport class NackHandlerBase\n implements Processor<NackHandlerInput, NackHandlerOutput>\n{\n private newEstSeqNum = 0;\n private _lost: { [seqNum: number]: number } = {};\n private clearNackInterval?: () => void;\n private internalStats = {};\n\n readonly onNackSent = new Event<[GenericNack]>();\n readonly onPacketLost = new Event<[number]>();\n mediaSourceSsrc?: number;\n readonly retryCount = 10;\n stopped = false;\n\n constructor(\n private senderSsrc: number,\n private onNack: (rtcp: RtcpTransportLayerFeedback) => Promise<void>\n ) {}\n\n toJSON(): Record<string, any> {\n return {\n ...this.internalStats,\n newEstSeqNum: this.newEstSeqNum,\n lostLength: Object.values(this._lost).length,\n senderSsrc: this.senderSsrc,\n mediaSourceSsrc: this.mediaSourceSsrc,\n };\n }\n\n private get lostSeqNumbers() {\n return Object.keys(this._lost).map(Number).sort();\n }\n\n private getLost(seq: number) {\n return this._lost[seq];\n }\n\n private setLost(seq: number, count: number) {\n this._lost[seq] = count;\n\n if (this.clearNackInterval || this.stopped) {\n return;\n }\n this.clearNackInterval = timer.setInterval(async () => {\n try {\n await this.sendNack();\n if (!Object.keys(this._lost).length) {\n this.clearNackInterval?.();\n this.clearNackInterval = undefined;\n }\n } catch (error) {\n log(\"failed to send nack\", error);\n }\n }, 5);\n }\n\n private removeLost(sequenceNumber: number) {\n delete this._lost[sequenceNumber];\n }\n\n processInput = (input: RtpOutput) => {\n if (input.rtp) {\n this.addPacket(input.rtp);\n this.internalStats[\"nackHandler\"] = new Date().toISOString();\n return [input];\n }\n\n this.stop();\n return [input];\n };\n\n private addPacket(packet: RtpPacket) {\n const { sequenceNumber, ssrc } = packet.header;\n this.mediaSourceSsrc = ssrc;\n\n if (this.newEstSeqNum === 0) {\n this.newEstSeqNum = sequenceNumber;\n return;\n }\n\n if (this.getLost(sequenceNumber)) {\n // log(\"packetLoss resolved\", { sequenceNumber });\n this.removeLost(sequenceNumber);\n return;\n }\n\n if (sequenceNumber === uint16Add(this.newEstSeqNum, 1)) {\n this.newEstSeqNum = sequenceNumber;\n } else if (sequenceNumber > uint16Add(this.newEstSeqNum, 1)) {\n // packet lost detected\n range(uint16Add(this.newEstSeqNum, 1), sequenceNumber).forEach((seq) => {\n this.setLost(seq, 1);\n });\n // this.receiver.sendRtcpPLI(this.mediaSourceSsrc);\n\n this.newEstSeqNum = sequenceNumber;\n this.pruneLost();\n }\n }\n\n private pruneLost() {\n if (this.lostSeqNumbers.length > LOST_SIZE) {\n this._lost = Object.entries(this._lost)\n .slice(-LOST_SIZE)\n .reduce((acc, [key, v]) => {\n acc[key] = v;\n return acc;\n }, {} as { [seqNum: number]: number });\n }\n }\n\n private stop() {\n this.stopped = true;\n this._lost = {};\n this.clearNackInterval?.();\n this.onNackSent.allUnsubscribe();\n this.onPacketLost.allUnsubscribe();\n this.onNack = undefined as any;\n }\n\n private updateRetryCount() {\n this.lostSeqNumbers.forEach((seq) => {\n const count = this._lost[seq]++;\n if (count > this.retryCount) {\n this.removeLost(seq);\n this.onPacketLost.execute(seq);\n }\n });\n }\n\n private sendNack = () =>\n new Promise((r, f) => {\n if (this.lostSeqNumbers.length > 0 && this.mediaSourceSsrc) {\n this.internalStats[\"count\"] = (this.internalStats[\"count\"] ?? 0) + 1;\n\n const nack = new GenericNack({\n senderSsrc: this.senderSsrc,\n mediaSourceSsrc: this.mediaSourceSsrc,\n lost: this.lostSeqNumbers,\n });\n\n const rtcp = new RtcpTransportLayerFeedback({\n feedback: nack,\n });\n this.onNack(rtcp).then(r).catch(f);\n\n this.updateRetryCount();\n this.onNackSent.execute(nack);\n }\n });\n}\n"]}
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { NackHandlerBase } from "./nack";
|
|
2
|
+
declare const NackHandlerCallback_base: {
|
|
3
|
+
new (...args: any[]): {
|
|
4
|
+
cb?: ((o: import("./rtpCallback").RtpOutput) => void) | undefined;
|
|
5
|
+
destructor?: (() => void) | undefined;
|
|
6
|
+
pipe: (cb: (o: import("./rtpCallback").RtpOutput) => void, destructor?: (() => void) | undefined) => any;
|
|
7
|
+
input: (input: import("./rtpCallback").RtpOutput) => void;
|
|
8
|
+
destroy: () => void;
|
|
9
|
+
processInput: (input: import("./rtpCallback").RtpOutput) => import("./rtpCallback").RtpOutput[];
|
|
10
|
+
toJSON(): Record<string, any>;
|
|
11
|
+
};
|
|
12
|
+
} & typeof NackHandlerBase;
|
|
13
|
+
export declare class NackHandlerCallback extends NackHandlerCallback_base {
|
|
8
14
|
}
|
|
15
|
+
export {};
|
|
@@ -1,36 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NackHandlerCallback = void 0;
|
|
4
|
+
const interface_1 = require("./interface");
|
|
4
5
|
const nack_1 = require("./nack");
|
|
5
|
-
class NackHandlerCallback extends nack_1.NackHandlerBase {
|
|
6
|
-
constructor(senderSsrc, onNack) {
|
|
7
|
-
super(senderSsrc, onNack);
|
|
8
|
-
Object.defineProperty(this, "cb", {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
configurable: true,
|
|
11
|
-
writable: true,
|
|
12
|
-
value: void 0
|
|
13
|
-
});
|
|
14
|
-
Object.defineProperty(this, "pipe", {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
configurable: true,
|
|
17
|
-
writable: true,
|
|
18
|
-
value: (cb) => {
|
|
19
|
-
this.cb = cb;
|
|
20
|
-
return this;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
Object.defineProperty(this, "input", {
|
|
24
|
-
enumerable: true,
|
|
25
|
-
configurable: true,
|
|
26
|
-
writable: true,
|
|
27
|
-
value: (input) => {
|
|
28
|
-
for (const output of this.processInput(input)) {
|
|
29
|
-
this.cb(output);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}
|
|
6
|
+
class NackHandlerCallback extends (0, interface_1.SimpleProcessorCallbackBase)(nack_1.NackHandlerBase) {
|
|
34
7
|
}
|
|
35
8
|
exports.NackHandlerCallback = NackHandlerCallback;
|
|
36
9
|
//# sourceMappingURL=nackHandlerCallback.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nackHandlerCallback.js","sourceRoot":"","sources":["../../../../../rtp/src/processor/nackHandlerCallback.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"nackHandlerCallback.js","sourceRoot":"","sources":["../../../../../rtp/src/processor/nackHandlerCallback.ts"],"names":[],"mappings":";;;AAAA,2CAA0D;AAC1D,iCAA8E;AAE9E,MAAa,mBAAoB,SAAQ,IAAA,uCAA2B,EAIlE,sBAAe,CAAC;CAAG;AAJrB,kDAIqB","sourcesContent":["import { SimpleProcessorCallbackBase } from \"./interface\";\nimport { NackHandlerBase, NackHandlerInput, NackHandlerOutput } from \"./nack\";\n\nexport class NackHandlerCallback extends SimpleProcessorCallbackBase<\n NackHandlerInput,\n NackHandlerOutput,\n typeof NackHandlerBase\n>(NackHandlerBase) {}\n"]}
|
|
@@ -12,15 +12,15 @@ export interface NtpTimeOutput {
|
|
|
12
12
|
}
|
|
13
13
|
export declare class NtpTimeBase implements Processor<NtpTimeInput, NtpTimeOutput> {
|
|
14
14
|
clockRate: number;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
readonly id: string;
|
|
16
|
+
private baseNtpTimestamp?;
|
|
17
|
+
private baseRtpTimestamp?;
|
|
18
|
+
private latestNtpTimestamp?;
|
|
19
|
+
private latestRtpTimestamp?;
|
|
19
20
|
private currentElapsed;
|
|
20
|
-
buffer
|
|
21
|
+
private buffer;
|
|
21
22
|
private internalStats;
|
|
22
|
-
|
|
23
|
-
payloadType: number;
|
|
23
|
+
started: boolean;
|
|
24
24
|
constructor(clockRate: number);
|
|
25
25
|
toJSON(): Record<string, any>;
|
|
26
26
|
private stop;
|