werift 0.18.2 → 0.18.3

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.
Files changed (96) hide show
  1. package/lib/common/src/promise.d.ts +1 -0
  2. package/lib/common/src/promise.js +3 -0
  3. package/lib/common/src/promise.js.map +1 -1
  4. package/lib/rtp/src/index.d.ts +1 -0
  5. package/lib/rtp/src/index.js +1 -0
  6. package/lib/rtp/src/index.js.map +1 -1
  7. package/lib/rtp/src/processor/depacketizer.d.ts +4 -1
  8. package/lib/rtp/src/processor/depacketizer.js +38 -7
  9. package/lib/rtp/src/processor/depacketizer.js.map +1 -1
  10. package/lib/rtp/src/processor/depacketizerCallback.d.ts +1 -1
  11. package/lib/rtp/src/processor/depacketizerCallback.js +6 -0
  12. package/lib/rtp/src/processor/depacketizerCallback.js.map +1 -1
  13. package/lib/rtp/src/processor/dtx.d.ts +16 -0
  14. package/lib/rtp/src/processor/dtx.js +78 -0
  15. package/lib/rtp/src/processor/dtx.js.map +1 -0
  16. package/lib/rtp/src/processor/dtxCallback.d.ts +6 -0
  17. package/lib/rtp/src/processor/dtxCallback.js +42 -0
  18. package/lib/rtp/src/processor/dtxCallback.js.map +1 -0
  19. package/lib/rtp/src/processor/index.d.ts +5 -0
  20. package/lib/rtp/src/processor/index.js +5 -0
  21. package/lib/rtp/src/processor/index.js.map +1 -1
  22. package/lib/rtp/src/processor/interface.d.ts +2 -0
  23. package/lib/rtp/src/processor/interface.js.map +1 -1
  24. package/lib/rtp/src/processor/jitterBuffer.d.ts +8 -0
  25. package/lib/rtp/src/processor/jitterBuffer.js +31 -17
  26. package/lib/rtp/src/processor/jitterBuffer.js.map +1 -1
  27. package/lib/rtp/src/processor/jitterBufferCallback.d.ts +2 -4
  28. package/lib/rtp/src/processor/jitterBufferCallback.js +8 -8
  29. package/lib/rtp/src/processor/jitterBufferCallback.js.map +1 -1
  30. package/lib/rtp/src/processor/lipsync.d.ts +21 -12
  31. package/lib/rtp/src/processor/lipsync.js +70 -21
  32. package/lib/rtp/src/processor/lipsync.js.map +1 -1
  33. package/lib/rtp/src/processor/lipsyncCallback.d.ts +2 -2
  34. package/lib/rtp/src/processor/lipsyncCallback.js.map +1 -1
  35. package/lib/rtp/src/processor/mute.d.ts +25 -0
  36. package/lib/rtp/src/processor/mute.js +115 -0
  37. package/lib/rtp/src/processor/mute.js.map +1 -0
  38. package/lib/rtp/src/processor/muteCallback.d.ts +7 -0
  39. package/lib/rtp/src/processor/muteCallback.js +45 -0
  40. package/lib/rtp/src/processor/muteCallback.js.map +1 -0
  41. package/lib/rtp/src/processor/nack.d.ts +4 -2
  42. package/lib/rtp/src/processor/nack.js +24 -6
  43. package/lib/rtp/src/processor/nack.js.map +1 -1
  44. package/lib/rtp/src/processor/ntpTime.d.ts +18 -7
  45. package/lib/rtp/src/processor/ntpTime.js +120 -37
  46. package/lib/rtp/src/processor/ntpTime.js.map +1 -1
  47. package/lib/rtp/src/processor/ntpTimeCallback.d.ts +1 -2
  48. package/lib/rtp/src/processor/ntpTimeCallback.js +3 -3
  49. package/lib/rtp/src/processor/ntpTimeCallback.js.map +1 -1
  50. package/lib/rtp/src/processor/rtpTime.d.ts +6 -1
  51. package/lib/rtp/src/processor/rtpTime.js +13 -2
  52. package/lib/rtp/src/processor/rtpTime.js.map +1 -1
  53. package/lib/rtp/src/processor/source/rtcpCallback.js +2 -0
  54. package/lib/rtp/src/processor/source/rtcpCallback.js.map +1 -1
  55. package/lib/rtp/src/processor/source/rtpCallback.js +2 -0
  56. package/lib/rtp/src/processor/source/rtpCallback.js.map +1 -1
  57. package/lib/rtp/src/processor/webm.d.ts +4 -1
  58. package/lib/rtp/src/processor/webm.js +35 -10
  59. package/lib/rtp/src/processor/webm.js.map +1 -1
  60. package/lib/rtp/src/rtcp/rr.d.ts +9 -0
  61. package/lib/rtp/src/rtcp/rr.js +11 -0
  62. package/lib/rtp/src/rtcp/rr.js.map +1 -1
  63. package/lib/rtp/src/rtcp/sr.d.ts +21 -0
  64. package/lib/rtp/src/rtcp/sr.js +21 -3
  65. package/lib/rtp/src/rtcp/sr.js.map +1 -1
  66. package/lib/rtp/src/rtp/headerExtension.d.ts +26 -0
  67. package/lib/rtp/src/rtp/headerExtension.js +72 -0
  68. package/lib/rtp/src/rtp/headerExtension.js.map +1 -0
  69. package/lib/webrtc/src/media/extension/rtpExtension.d.ts +1 -8
  70. package/lib/webrtc/src/media/extension/rtpExtension.js +14 -15
  71. package/lib/webrtc/src/media/extension/rtpExtension.js.map +1 -1
  72. package/lib/webrtc/src/media/router.d.ts +1 -4
  73. package/lib/webrtc/src/media/router.js +11 -39
  74. package/lib/webrtc/src/media/router.js.map +1 -1
  75. package/lib/webrtc/src/media/rtpReceiver.js +1 -2
  76. package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
  77. package/lib/webrtc/src/media/rtpSender.js +12 -16
  78. package/lib/webrtc/src/media/rtpSender.js.map +1 -1
  79. package/lib/webrtc/src/peerConnection.d.ts +3 -0
  80. package/lib/webrtc/src/peerConnection.js +3 -0
  81. package/lib/webrtc/src/peerConnection.js.map +1 -1
  82. package/lib/webrtc/src/transport/dtls.js +11 -5
  83. package/lib/webrtc/src/transport/dtls.js.map +1 -1
  84. package/package.json +1 -1
  85. package/src/media/extension/rtpExtension.ts +7 -11
  86. package/src/media/router.ts +3 -33
  87. package/src/media/rtpReceiver.ts +4 -2
  88. package/src/media/rtpSender.ts +15 -19
  89. package/src/peerConnection.ts +4 -0
  90. package/src/transport/dtls.ts +13 -8
  91. package/lib/rtp/src/processor_old/base.d.ts +0 -18
  92. package/lib/rtp/src/processor_old/base.js +0 -51
  93. package/lib/rtp/src/processor_old/base.js.map +0 -1
  94. package/lib/rtp/src/processor_old/lipsync.d.ts +0 -30
  95. package/lib/rtp/src/processor_old/lipsync.js +0 -119
  96. package/lib/rtp/src/processor_old/lipsync.js.map +0 -1
@@ -7,4 +7,5 @@ export declare class PromiseQueue {
7
7
  running: boolean;
8
8
  push: <T>(promise: () => Promise<T>) => Promise<T>;
9
9
  private run;
10
+ cancel(): void;
10
11
  }
@@ -44,6 +44,9 @@ class PromiseQueue {
44
44
  this.running = false;
45
45
  }
46
46
  }
47
+ cancel() {
48
+ this.queue = [];
49
+ }
47
50
  }
48
51
  exports.PromiseQueue = PromiseQueue;
49
52
  //# sourceMappingURL=promise.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"promise.js","sourceRoot":"","sources":["../../../../common/src/promise.ts"],"names":[],"mappings":";;;AAAA,MAAa,YAAY;IAAzB;QACE;;;;mBAIM,EAAE;WAAC;QACT;;;;mBAAU,KAAK;WAAC;QAEhB;;;;mBAAO,CAAI,OAAyB,EAAE,EAAE,CACtC,IAAI,OAAO,CAAI,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;gBACtB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;gBACjD,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;oBACjB,IAAI,CAAC,GAAG,EAAE,CAAC;iBACZ;YACH,CAAC,CAAC;WAAC;IAmBP,CAAC;IAjBS,KAAK,CAAC,GAAG;QACf,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QAChC,IAAI,IAAI,EAAE;YACR,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;YAEpB,IAAI;gBACF,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;gBACjC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;aAChB;YAAC,OAAO,KAAK,EAAE;gBACd,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;aACpB;YAED,IAAI,CAAC,GAAG,EAAE,CAAC;SACZ;aAAM;YACL,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;SACtB;IACH,CAAC;CACF;AAjCD,oCAiCC","sourcesContent":["export class PromiseQueue {\n queue: {\n promise: () => Promise<unknown>;\n done: (...args: any[]) => void;\n failed: (...args: any[]) => void;\n }[] = [];\n running = false;\n\n push = <T>(promise: () => Promise<T>) =>\n new Promise<T>((r, f) => {\n this.queue.push({ promise, done: r, failed: f });\n if (!this.running) {\n this.run();\n }\n });\n\n private async run() {\n const task = this.queue.shift();\n if (task) {\n this.running = true;\n\n try {\n const res = await task.promise();\n task.done(res);\n } catch (error) {\n task.failed(error);\n }\n\n this.run();\n } else {\n this.running = false;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"promise.js","sourceRoot":"","sources":["../../../../common/src/promise.ts"],"names":[],"mappings":";;;AAAA,MAAa,YAAY;IAAzB;QACE;;;;mBAIM,EAAE;WAAC;QACT;;;;mBAAU,KAAK;WAAC;QAEhB;;;;mBAAO,CAAI,OAAyB,EAAE,EAAE,CACtC,IAAI,OAAO,CAAI,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;gBACtB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;gBACjD,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;oBACjB,IAAI,CAAC,GAAG,EAAE,CAAC;iBACZ;YACH,CAAC,CAAC;WAAC;IAuBP,CAAC;IArBS,KAAK,CAAC,GAAG;QACf,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QAChC,IAAI,IAAI,EAAE;YACR,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;YAEpB,IAAI;gBACF,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;gBACjC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;aAChB;YAAC,OAAO,KAAK,EAAE;gBACd,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;aACpB;YAED,IAAI,CAAC,GAAG,EAAE,CAAC;SACZ;aAAM;YACL,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;SACtB;IACH,CAAC;IAED,MAAM;QACJ,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;IAClB,CAAC;CACF;AArCD,oCAqCC","sourcesContent":["export class PromiseQueue {\n queue: {\n promise: () => Promise<unknown>;\n done: (...args: any[]) => void;\n failed: (...args: any[]) => void;\n }[] = [];\n running = false;\n\n push = <T>(promise: () => Promise<T>) =>\n new Promise<T>((r, f) => {\n this.queue.push({ promise, done: r, failed: f });\n if (!this.running) {\n this.run();\n }\n });\n\n private async run() {\n const task = this.queue.shift();\n if (task) {\n this.running = true;\n\n try {\n const res = await task.promise();\n task.done(res);\n } catch (error) {\n task.failed(error);\n }\n\n this.run();\n } else {\n this.running = false;\n }\n }\n\n cancel() {\n this.queue = [];\n }\n}\n"]}
@@ -13,6 +13,7 @@ export * from "./rtcp/rtpfb/nack";
13
13
  export * from "./rtcp/rtpfb/twcc";
14
14
  export * from "./rtcp/sdes";
15
15
  export * from "./rtcp/sr";
16
+ export * from "./rtp/headerExtension";
16
17
  export * from "./rtp/red/encoder";
17
18
  export * from "./rtp/red/handler";
18
19
  export * from "./rtp/red/packet";
@@ -29,6 +29,7 @@ __exportStar(require("./rtcp/rtpfb/nack"), exports);
29
29
  __exportStar(require("./rtcp/rtpfb/twcc"), exports);
30
30
  __exportStar(require("./rtcp/sdes"), exports);
31
31
  __exportStar(require("./rtcp/sr"), exports);
32
+ __exportStar(require("./rtp/headerExtension"), exports);
32
33
  __exportStar(require("./rtp/red/encoder"), exports);
33
34
  __exportStar(require("./rtp/red/handler"), exports);
34
35
  __exportStar(require("./rtp/red/packet"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../rtp/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kBAAgB;AAChB,mDAAiC;AACjC,0CAAwB;AACxB,8CAA4B;AAC5B,gDAA8B;AAC9B,8CAA4B;AAC5B,oEAAkD;AAClD,mDAAiC;AACjC,4CAA0B;AAC1B,8CAA4B;AAC5B,+CAA6B;AAC7B,oDAAkC;AAClC,oDAAkC;AAClC,8CAA4B;AAC5B,4CAA0B;AAC1B,oDAAkC;AAClC,oDAAkC;AAClC,mDAAiC;AACjC,4CAA0B;AAC1B,4CAA0B;AAC1B,+CAA6B;AAC7B,8CAA4B","sourcesContent":["import \"buffer\";\nexport * from \"../../common/src\";\nexport * from \"./codec\";\nexport * from \"./processor\";\nexport * from \"./rtcp/header\";\nexport * from \"./rtcp/psfb\";\nexport * from \"./rtcp/psfb/pictureLossIndication\";\nexport * from \"./rtcp/psfb/remb\";\nexport * from \"./rtcp/rr\";\nexport * from \"./rtcp/rtcp\";\nexport * from \"./rtcp/rtpfb\";\nexport * from \"./rtcp/rtpfb/nack\";\nexport * from \"./rtcp/rtpfb/twcc\";\nexport * from \"./rtcp/sdes\";\nexport * from \"./rtcp/sr\";\nexport * from \"./rtp/red/encoder\";\nexport * from \"./rtp/red/handler\";\nexport * from \"./rtp/red/packet\";\nexport * from \"./rtp/rtp\";\nexport * from \"./rtp/rtx\";\nexport * from \"./srtp/srtcp\";\nexport * from \"./srtp/srtp\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../rtp/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kBAAgB;AAChB,mDAAiC;AACjC,0CAAwB;AACxB,8CAA4B;AAC5B,gDAA8B;AAC9B,8CAA4B;AAC5B,oEAAkD;AAClD,mDAAiC;AACjC,4CAA0B;AAC1B,8CAA4B;AAC5B,+CAA6B;AAC7B,oDAAkC;AAClC,oDAAkC;AAClC,8CAA4B;AAC5B,4CAA0B;AAC1B,wDAAsC;AACtC,oDAAkC;AAClC,oDAAkC;AAClC,mDAAiC;AACjC,4CAA0B;AAC1B,4CAA0B;AAC1B,+CAA6B;AAC7B,8CAA4B","sourcesContent":["import \"buffer\";\nexport * from \"../../common/src\";\nexport * from \"./codec\";\nexport * from \"./processor\";\nexport * from \"./rtcp/header\";\nexport * from \"./rtcp/psfb\";\nexport * from \"./rtcp/psfb/pictureLossIndication\";\nexport * from \"./rtcp/psfb/remb\";\nexport * from \"./rtcp/rr\";\nexport * from \"./rtcp/rtcp\";\nexport * from \"./rtcp/rtpfb\";\nexport * from \"./rtcp/rtpfb/nack\";\nexport * from \"./rtcp/rtpfb/twcc\";\nexport * from \"./rtcp/sdes\";\nexport * from \"./rtcp/sr\";\nexport * from \"./rtp/headerExtension\";\nexport * from \"./rtp/red/encoder\";\nexport * from \"./rtp/red/handler\";\nexport * from \"./rtp/red/packet\";\nexport * from \"./rtp/rtp\";\nexport * from \"./rtp/rtx\";\nexport * from \"./srtp/srtcp\";\nexport * from \"./srtp/srtp\";\n"]}
@@ -30,10 +30,13 @@ export declare class DepacketizeBase implements Processor<DepacketizerInput, Dep
30
30
  private lastSeqNum?;
31
31
  private frameBroken;
32
32
  private keyframeReceived;
33
- sequence: number;
33
+ count: number;
34
34
  readonly onNeedKeyFrame: Event<any[]>;
35
+ private internalStats;
35
36
  constructor(codec: string, options?: DepacketizerOptions);
37
+ toJSON(): Record<string, any>;
36
38
  processInput(input: DepacketizerInput): DepacketizerOutput[];
39
+ private stop;
37
40
  private clearBuffer;
38
41
  private checkFinalPacket;
39
42
  }
@@ -49,7 +49,7 @@ class DepacketizeBase {
49
49
  writable: true,
50
50
  value: false
51
51
  });
52
- Object.defineProperty(this, "sequence", {
52
+ Object.defineProperty(this, "count", {
53
53
  enumerable: true,
54
54
  configurable: true,
55
55
  writable: true,
@@ -61,12 +61,27 @@ class DepacketizeBase {
61
61
  writable: true,
62
62
  value: new rx_mini_1.default()
63
63
  });
64
+ Object.defineProperty(this, "internalStats", {
65
+ enumerable: true,
66
+ configurable: true,
67
+ writable: true,
68
+ value: {}
69
+ });
70
+ }
71
+ toJSON() {
72
+ return {
73
+ bufferingLength: this.buffering.length,
74
+ lastSeqNum: this.lastSeqNum,
75
+ count: this.count,
76
+ stats: this.internalStats,
77
+ };
64
78
  }
65
79
  processInput(input) {
66
80
  const output = [];
67
81
  if (!input.rtp) {
68
82
  if (input.eol) {
69
83
  output.push({ eol: true });
84
+ this.stop();
70
85
  }
71
86
  return output;
72
87
  }
@@ -89,7 +104,7 @@ class DepacketizeBase {
89
104
  data,
90
105
  isKeyframe,
91
106
  time,
92
- sequence: this.sequence++,
107
+ sequence: this.count++,
93
108
  rtpSeq: sequence,
94
109
  timestamp,
95
110
  },
@@ -102,7 +117,7 @@ class DepacketizeBase {
102
117
  return output;
103
118
  }
104
119
  catch (error) {
105
- log("error", error, input);
120
+ log("error", error, { input, codec: this.codec });
106
121
  this.clearBuffer();
107
122
  }
108
123
  }
@@ -115,7 +130,7 @@ class DepacketizeBase {
115
130
  data,
116
131
  isKeyframe,
117
132
  time: input.time,
118
- sequence: this.sequence++,
133
+ sequence: this.count++,
119
134
  rtpSeq: sequence,
120
135
  timestamp,
121
136
  },
@@ -123,11 +138,15 @@ class DepacketizeBase {
123
138
  return output;
124
139
  }
125
140
  catch (error) {
126
- log("error", error, input);
141
+ log("error", error, { input, codec: this.codec });
127
142
  }
128
143
  }
129
144
  return [];
130
145
  }
146
+ stop() {
147
+ this.clearBuffer();
148
+ this.onNeedKeyFrame.allUnsubscribe();
149
+ }
131
150
  clearBuffer() {
132
151
  this.buffering.forEach((b) => b.rtp.clear());
133
152
  this.buffering = [];
@@ -140,11 +159,23 @@ class DepacketizeBase {
140
159
  if (this.lastSeqNum != undefined) {
141
160
  const expect = (0, __1.uint16Add)(this.lastSeqNum, 1);
142
161
  if ((0, __1.uint16Gt)(expect, sequenceNumber)) {
143
- log("unexpect", { expect, sequenceNumber });
162
+ this.internalStats["unExpect"] = {
163
+ expect,
164
+ sequenceNumber,
165
+ codec: this.codec,
166
+ at: new Date().toISOString(),
167
+ count: (this.internalStats["unExpect"]?.count ?? 0) + 1,
168
+ };
144
169
  return false;
145
170
  }
146
171
  if ((0, __1.uint16Gt)(sequenceNumber, expect)) {
147
- log("packet lost happened", { expect, sequenceNumber });
172
+ this.internalStats["packetLost"] = {
173
+ expect,
174
+ sequenceNumber,
175
+ codec: this.codec,
176
+ at: new Date().toISOString(),
177
+ count: (this.internalStats["packetLost"]?.count ?? 0) + 1,
178
+ };
148
179
  this.frameBroken = true;
149
180
  this.clearBuffer();
150
181
  }
@@ -1 +1 @@
1
- {"version":3,"file":"depacketizer.js","sourceRoot":"","sources":["../../../../../rtp/src/processor/depacketizer.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,sDAA4B;AAE5B,0BAA+D;AAC/D,oCAAiD;AACjD,sCAAsC;AAGtC,MAAM,IAAI,GAAG,yDAAyD,CAAC;AACvE,MAAM,GAAG,GAAG,IAAA,eAAK,EAAC,IAAI,CAAC,CAAC;AA2BxB,MAAa,eAAe;IAU1B,YACU,KAAa,EACb,UAA+B,EAAE;;;;;mBADjC;;;;;;mBACA;;QATV;;;;mBAAyC,EAAE;WAAC;QAC5C;;;;;WAA4B;QAC5B;;;;mBAAsB,KAAK;WAAC;QAC5B;;;;mBAA2B,KAAK;WAAC;QACjC;;;;mBAAW,CAAC;WAAC;QACb;;;;mBAA0B,IAAI,iBAAK,EAAE;WAAC;IAKnC,CAAC;IAEJ,YAAY,CAAC,KAAwB;QACnC,MAAM,MAAM,GAAyB,EAAE,CAAC;QACxC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE;YACd,IAAI,KAAK,CAAC,GAAG,EAAE;gBACb,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;aAC5B;YACD,OAAO,MAAM,CAAC;SACf;QAED,IAAI,IAAI,CAAC,OAAO,CAAC,uBAAuB,EAAE;YACxC,MAAM,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;YAC7C,IAAI,OAAO,EAAE;gBACX,IAAI;oBACF,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,SA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;gBACxD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;gBACxB,IAAI,CAAC,WAAW,EAAE,CAAC;aACpB;SACF;QAED,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;QACnC,IAAI,CAAC,UAAU,GAAG,cAAc,CAAC;QAEjC,IAAI,WAA+B,CAAC;QACpC,KAAK,MAAM,CAAC,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,IAAI,IAAA,kBAAS,EAAC,IAAI,CAAC,SAAS,CAAC,EAAE;YACpD,IAAI,IAAI,CAAC,OAAO,CAAC,uBAAuB,CAAC,GAAI,CAAC,MAAM,CAAC,EAAE;gBACrD,WAAW,GAAG,CAAC,CAAC;gBAChB,MAAM;aACP;SACF;QACD,IAAI,WAAW,IAAI,SAAS,EAAE;YAC5B,OAAO,KAAK,CAAC;SACd;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AArID,0CAqIC","sourcesContent":["import debug from \"debug\";\nimport Event from \"rx.mini\";\n\nimport { RtpHeader, RtpPacket, uint16Add, uint16Gt } from \"..\";\nimport { dePacketizeRtpPackets } from \"../codec\";\nimport { enumerate } from \"../helper\";\nimport { Processor } from \"./interface\";\n\nconst path = `werift-rtp : packages/rtp/src/processor/depacketizer.ts`;\nconst log = debug(path);\n\nexport type DepacketizerInput = {\n rtp?: RtpPacket;\n /**ms */\n time?: number;\n eol?: boolean;\n};\n\nexport interface DepacketizerOutput {\n frame?: CodecFrame;\n eol?: boolean;\n}\n\nexport interface CodecFrame {\n data: Buffer;\n isKeyframe: boolean;\n /**ms */\n time: number;\n [key: string]: any;\n}\n\nexport interface DepacketizerOptions {\n isFinalPacketInSequence?: (header: RtpHeader) => boolean;\n waitForKeyframe?: boolean;\n}\n\nexport class DepacketizeBase\n implements Processor<DepacketizerInput, DepacketizerOutput>\n{\n private buffering: DepacketizerInput[] = [];\n private lastSeqNum?: number;\n private frameBroken = false;\n private keyframeReceived = false;\n sequence = 0;\n readonly onNeedKeyFrame = new Event();\n\n constructor(\n private codec: string,\n private options: DepacketizerOptions = {}\n ) {}\n\n processInput(input: DepacketizerInput): DepacketizerOutput[] {\n const output: DepacketizerOutput[] = [];\n if (!input.rtp) {\n if (input.eol) {\n output.push({ eol: true });\n }\n return output;\n }\n\n if (this.options.isFinalPacketInSequence) {\n const isFinal = this.checkFinalPacket(input);\n if (isFinal) {\n try {\n const { data, isKeyframe, sequence, timestamp } =\n dePacketizeRtpPackets(\n this.codec,\n this.buffering.map((b) => b.rtp!)\n );\n\n if (isKeyframe) {\n this.keyframeReceived = true;\n }\n\n if (this.options.waitForKeyframe && this.keyframeReceived === false) {\n this.onNeedKeyFrame.execute();\n return [];\n }\n\n if (!this.frameBroken) {\n const time = this.buffering.at(-1)?.time ?? 0;\n output.push({\n frame: {\n data,\n isKeyframe,\n time,\n sequence: this.sequence++,\n rtpSeq: sequence,\n timestamp,\n },\n });\n }\n\n if (this.frameBroken) {\n this.frameBroken = false;\n }\n\n this.clearBuffer();\n\n return output;\n } catch (error) {\n log(\"error\", error, input);\n this.clearBuffer();\n }\n }\n } else {\n try {\n const { data, isKeyframe, sequence, timestamp } = dePacketizeRtpPackets(\n this.codec,\n [input.rtp]\n );\n output.push({\n frame: {\n data,\n isKeyframe,\n time: input.time!,\n sequence: this.sequence++,\n rtpSeq: sequence,\n timestamp,\n },\n });\n return output;\n } catch (error) {\n log(\"error\", error, input);\n }\n }\n return [];\n }\n\n private clearBuffer() {\n this.buffering.forEach((b) => b.rtp!.clear());\n this.buffering = [];\n }\n\n private checkFinalPacket({ rtp, time }: DepacketizerInput): boolean {\n if (!this.options.isFinalPacketInSequence) {\n throw new Error(\"isFinalPacketInSequence not exist\");\n }\n\n const { sequenceNumber } = rtp!.header;\n if (this.lastSeqNum != undefined) {\n const expect = uint16Add(this.lastSeqNum, 1);\n if (uint16Gt(expect, sequenceNumber)) {\n log(\"unexpect\", { expect, sequenceNumber });\n return false;\n }\n if (uint16Gt(sequenceNumber, expect)) {\n log(\"packet lost happened\", { expect, sequenceNumber });\n this.frameBroken = true;\n this.clearBuffer();\n }\n }\n\n this.buffering.push({ rtp, time });\n this.lastSeqNum = sequenceNumber;\n\n let finalPacket: number | undefined;\n for (const [i, { rtp }] of enumerate(this.buffering)) {\n if (this.options.isFinalPacketInSequence(rtp!.header)) {\n finalPacket = i;\n break;\n }\n }\n if (finalPacket == undefined) {\n return false;\n }\n\n return true;\n }\n}\n"]}
1
+ {"version":3,"file":"depacketizer.js","sourceRoot":"","sources":["../../../../../rtp/src/processor/depacketizer.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,sDAA4B;AAE5B,0BAA+D;AAC/D,oCAAiD;AACjD,sCAAsC;AAGtC,MAAM,IAAI,GAAG,yDAAyD,CAAC;AACvE,MAAM,GAAG,GAAG,IAAA,eAAK,EAAC,IAAI,CAAC,CAAC;AA2BxB,MAAa,eAAe;IAW1B,YACU,KAAa,EACb,UAA+B,EAAE;;;;;mBADjC;;;;;;mBACA;;QAVV;;;;mBAAyC,EAAE;WAAC;QAC5C;;;;;WAA4B;QAC5B;;;;mBAAsB,KAAK;WAAC;QAC5B;;;;mBAA2B,KAAK;WAAC;QACjC;;;;mBAAQ,CAAC;WAAC;QACV;;;;mBAA0B,IAAI,iBAAK,EAAE;WAAC;QACtC;;;;mBAAwB,EAAE;WAAC;IAKxB,CAAC;IAEJ,MAAM;QACJ,OAAO;YACL,eAAe,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM;YACtC,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,KAAK,EAAE,IAAI,CAAC,aAAa;SAC1B,CAAC;IACJ,CAAC;IAED,YAAY,CAAC,KAAwB;QACnC,MAAM,MAAM,GAAyB,EAAE,CAAC;QACxC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE;YACd,IAAI,KAAK,CAAC,GAAG,EAAE;gBACb,MAAM,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C,EAAE,EAAE,GAAG,EAAE,CAAC,IAAI,IAAA,kBAAS,EAAC,IAAI,CAAC,SAAS,CAAC,EAAE;YACpD,IAAI,IAAI,CAAC,OAAO,CAAC,uBAAuB,CAAC,GAAI,CAAC,MAAM,CAAC,EAAE;gBACrD,WAAW,GAAG,CAAC,CAAC;gBAChB,MAAM;aACP;SACF;QACD,IAAI,WAAW,IAAI,SAAS,EAAE;YAC5B,OAAO,KAAK,CAAC;SACd;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAjKD,0CAiKC","sourcesContent":["import debug from \"debug\";\nimport Event from \"rx.mini\";\n\nimport { RtpHeader, RtpPacket, uint16Add, uint16Gt } from \"..\";\nimport { dePacketizeRtpPackets } from \"../codec\";\nimport { enumerate } from \"../helper\";\nimport { Processor } from \"./interface\";\n\nconst path = `werift-rtp : packages/rtp/src/processor/depacketizer.ts`;\nconst log = debug(path);\n\nexport type DepacketizerInput = {\n rtp?: RtpPacket;\n /**ms */\n time?: number;\n eol?: boolean;\n};\n\nexport interface DepacketizerOutput {\n frame?: CodecFrame;\n eol?: boolean;\n}\n\nexport interface CodecFrame {\n data: Buffer;\n isKeyframe: boolean;\n /**ms */\n time: number;\n [key: string]: any;\n}\n\nexport interface DepacketizerOptions {\n isFinalPacketInSequence?: (header: RtpHeader) => boolean;\n waitForKeyframe?: boolean;\n}\n\nexport class DepacketizeBase\n implements Processor<DepacketizerInput, DepacketizerOutput>\n{\n private buffering: DepacketizerInput[] = [];\n private lastSeqNum?: number;\n private frameBroken = false;\n private keyframeReceived = false;\n count = 0;\n readonly onNeedKeyFrame = new Event();\n private internalStats = {};\n\n constructor(\n private codec: string,\n private options: DepacketizerOptions = {}\n ) {}\n\n toJSON(): Record<string, any> {\n return {\n bufferingLength: this.buffering.length,\n lastSeqNum: this.lastSeqNum,\n count: this.count,\n stats: this.internalStats,\n };\n }\n\n processInput(input: DepacketizerInput): DepacketizerOutput[] {\n const output: DepacketizerOutput[] = [];\n if (!input.rtp) {\n if (input.eol) {\n output.push({ eol: true });\n this.stop();\n }\n return output;\n }\n\n if (this.options.isFinalPacketInSequence) {\n const isFinal = this.checkFinalPacket(input);\n if (isFinal) {\n try {\n const { data, isKeyframe, sequence, timestamp } =\n dePacketizeRtpPackets(\n this.codec,\n this.buffering.map((b) => b.rtp!)\n );\n\n if (isKeyframe) {\n this.keyframeReceived = true;\n }\n\n if (this.options.waitForKeyframe && this.keyframeReceived === false) {\n this.onNeedKeyFrame.execute();\n return [];\n }\n\n if (!this.frameBroken) {\n const time = this.buffering.at(-1)?.time ?? 0;\n output.push({\n frame: {\n data,\n isKeyframe,\n time,\n sequence: this.count++,\n rtpSeq: sequence,\n timestamp,\n },\n });\n }\n\n if (this.frameBroken) {\n this.frameBroken = false;\n }\n\n this.clearBuffer();\n\n return output;\n } catch (error) {\n log(\"error\", error, { input, codec: this.codec });\n this.clearBuffer();\n }\n }\n } else {\n try {\n const { data, isKeyframe, sequence, timestamp } = dePacketizeRtpPackets(\n this.codec,\n [input.rtp]\n );\n output.push({\n frame: {\n data,\n isKeyframe,\n time: input.time!,\n sequence: this.count++,\n rtpSeq: sequence,\n timestamp,\n },\n });\n return output;\n } catch (error) {\n log(\"error\", error, { input, codec: this.codec });\n }\n }\n return [];\n }\n\n private stop() {\n this.clearBuffer();\n this.onNeedKeyFrame.allUnsubscribe();\n }\n\n private clearBuffer() {\n this.buffering.forEach((b) => b.rtp!.clear());\n this.buffering = [];\n }\n\n private checkFinalPacket({ rtp, time }: DepacketizerInput): boolean {\n if (!this.options.isFinalPacketInSequence) {\n throw new Error(\"isFinalPacketInSequence not exist\");\n }\n\n const { sequenceNumber } = rtp!.header;\n if (this.lastSeqNum != undefined) {\n const expect = uint16Add(this.lastSeqNum, 1);\n if (uint16Gt(expect, sequenceNumber)) {\n this.internalStats[\"unExpect\"] = {\n expect,\n sequenceNumber,\n codec: this.codec,\n at: new Date().toISOString(),\n count: (this.internalStats[\"unExpect\"]?.count ?? 0) + 1,\n };\n return false;\n }\n if (uint16Gt(sequenceNumber, expect)) {\n this.internalStats[\"packetLost\"] = {\n expect,\n sequenceNumber,\n codec: this.codec,\n at: new Date().toISOString(),\n count: (this.internalStats[\"packetLost\"]?.count ?? 0) + 1,\n };\n this.frameBroken = true;\n this.clearBuffer();\n }\n }\n\n this.buffering.push({ rtp, time });\n this.lastSeqNum = sequenceNumber;\n\n let finalPacket: number | undefined;\n for (const [i, { rtp }] of enumerate(this.buffering)) {\n if (this.options.isFinalPacketInSequence(rtp!.header)) {\n finalPacket = i;\n break;\n }\n }\n if (finalPacket == undefined) {\n return false;\n }\n\n return true;\n }\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { DepacketizeBase, DepacketizerInput, DepacketizerOptions, DepacketizerOutput } from "./depacketizer";
2
2
  export declare class DepacketizeCallback extends DepacketizeBase {
3
- private cb;
3
+ private cb?;
4
4
  constructor(codec: string, options?: DepacketizerOptions);
5
5
  pipe: (cb: (input: DepacketizerOutput) => void) => this;
6
6
  input: (input: DepacketizerInput) => void;
@@ -25,9 +25,15 @@ class DepacketizeCallback extends depacketizer_1.DepacketizeBase {
25
25
  configurable: true,
26
26
  writable: true,
27
27
  value: (input) => {
28
+ if (!this.cb) {
29
+ return;
30
+ }
28
31
  for (const output of this.processInput(input)) {
29
32
  this.cb(output);
30
33
  }
34
+ if (input.eol) {
35
+ this.cb = undefined;
36
+ }
31
37
  }
32
38
  });
33
39
  }
@@ -1 +1 @@
1
- {"version":3,"file":"depacketizerCallback.js","sourceRoot":"","sources":["../../../../../rtp/src/processor/depacketizerCallback.ts"],"names":[],"mappings":";;;AAAA,iDAKwB;AAExB,MAAa,mBAAoB,SAAQ,8BAAe;IAGtD,YAAY,KAAa,EAAE,UAA+B,EAAE;QAC1D,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAHxB;;;;;WAAiD;QAMjD;;;;mBAAO,CAAC,EAAuC,EAAE,EAAE;gBACjD,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;gBACb,OAAO,IAAI,CAAC;YACd,CAAC;WAAC;QAEF;;;;mBAAQ,CAAC,KAAwB,EAAE,EAAE;gBACnC,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE;oBAC7C,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;iBACjB;YACH,CAAC;WAAC;IAXF,CAAC;CAYF;AAjBD,kDAiBC","sourcesContent":["import {\n DepacketizeBase,\n DepacketizerInput,\n DepacketizerOptions,\n DepacketizerOutput,\n} from \"./depacketizer\";\n\nexport class DepacketizeCallback extends DepacketizeBase {\n private cb!: (input: DepacketizerOutput) => void;\n\n constructor(codec: string, options: DepacketizerOptions = {}) {\n super(codec, options);\n }\n\n pipe = (cb: (input: DepacketizerOutput) => void) => {\n this.cb = cb;\n return this;\n };\n\n input = (input: DepacketizerInput) => {\n for (const output of this.processInput(input)) {\n this.cb(output);\n }\n };\n}\n"]}
1
+ {"version":3,"file":"depacketizerCallback.js","sourceRoot":"","sources":["../../../../../rtp/src/processor/depacketizerCallback.ts"],"names":[],"mappings":";;;AAAA,iDAKwB;AAExB,MAAa,mBAAoB,SAAQ,8BAAe;IAGtD,YAAY,KAAa,EAAE,UAA+B,EAAE;QAC1D,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAHxB;;;;;WAAiD;QAMjD;;;;mBAAO,CAAC,EAAuC,EAAE,EAAE;gBACjD,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;gBACb,OAAO,IAAI,CAAC;YACd,CAAC;WAAC;QAEF;;;;mBAAQ,CAAC,KAAwB,EAAE,EAAE;gBACnC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE;oBACZ,OAAO;iBACR;gBACD,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE;oBAC7C,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;iBACjB;gBACD,IAAI,KAAK,CAAC,GAAG,EAAE;oBACb,IAAI,CAAC,EAAE,GAAG,SAAS,CAAC;iBACrB;YACH,CAAC;WAAC;IAjBF,CAAC;CAkBF;AAvBD,kDAuBC","sourcesContent":["import {\n DepacketizeBase,\n DepacketizerInput,\n DepacketizerOptions,\n DepacketizerOutput,\n} from \"./depacketizer\";\n\nexport class DepacketizeCallback extends DepacketizeBase {\n private cb?: (input: DepacketizerOutput) => void;\n\n constructor(codec: string, options: DepacketizerOptions = {}) {\n super(codec, options);\n }\n\n pipe = (cb: (input: DepacketizerOutput) => void) => {\n this.cb = cb;\n return this;\n };\n\n input = (input: DepacketizerInput) => {\n if (!this.cb) {\n return;\n }\n for (const output of this.processInput(input)) {\n this.cb(output);\n }\n if (input.eol) {\n this.cb = undefined;\n }\n };\n}\n"]}
@@ -0,0 +1,16 @@
1
+ /// <reference types="node" />
2
+ import { DepacketizerOutput } from "./depacketizer";
3
+ import { Processor } from "./interface";
4
+ export type DtxInput = DepacketizerOutput;
5
+ export type DtxOutput = DtxInput;
6
+ export declare class DtxBase implements Processor<DtxInput, DtxOutput> {
7
+ ptime: number;
8
+ private dummyPacket;
9
+ readonly id: string;
10
+ previousTimestamp?: number;
11
+ private fillCount;
12
+ constructor(ptime: number, dummyPacket: Buffer);
13
+ toJSON(): Record<string, any>;
14
+ processInput({ frame, eol }: DtxInput): DtxOutput[];
15
+ private stop;
16
+ }
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DtxBase = void 0;
4
+ const crypto_1 = require("crypto");
5
+ class DtxBase {
6
+ constructor(ptime, dummyPacket) {
7
+ Object.defineProperty(this, "ptime", {
8
+ enumerable: true,
9
+ configurable: true,
10
+ writable: true,
11
+ value: ptime
12
+ });
13
+ Object.defineProperty(this, "dummyPacket", {
14
+ enumerable: true,
15
+ configurable: true,
16
+ writable: true,
17
+ value: dummyPacket
18
+ });
19
+ Object.defineProperty(this, "id", {
20
+ enumerable: true,
21
+ configurable: true,
22
+ writable: true,
23
+ value: (0, crypto_1.randomUUID)()
24
+ });
25
+ Object.defineProperty(this, "previousTimestamp", {
26
+ enumerable: true,
27
+ configurable: true,
28
+ writable: true,
29
+ value: void 0
30
+ });
31
+ Object.defineProperty(this, "fillCount", {
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true,
35
+ value: 0
36
+ });
37
+ }
38
+ toJSON() {
39
+ return { id: this.id, fillCount: this.fillCount };
40
+ }
41
+ processInput({ frame, eol }) {
42
+ if (eol) {
43
+ this.stop();
44
+ return [{ eol: true }];
45
+ }
46
+ if (frame) {
47
+ if (!this.previousTimestamp) {
48
+ this.previousTimestamp = frame.time;
49
+ return [{ frame }];
50
+ }
51
+ if (frame.time != this.previousTimestamp + this.ptime) {
52
+ const dummyPackets = [];
53
+ for (let time = this.previousTimestamp; time < frame.time; time += this.ptime) {
54
+ dummyPackets.push({
55
+ frame: {
56
+ time,
57
+ isKeyframe: frame.isKeyframe,
58
+ data: this.dummyPacket,
59
+ },
60
+ });
61
+ this.fillCount++;
62
+ }
63
+ this.previousTimestamp = frame.time;
64
+ return [...dummyPackets, { frame }];
65
+ }
66
+ else {
67
+ this.previousTimestamp = frame.time;
68
+ return [{ frame }];
69
+ }
70
+ }
71
+ return [];
72
+ }
73
+ stop() {
74
+ this.dummyPacket = undefined;
75
+ }
76
+ }
77
+ exports.DtxBase = DtxBase;
78
+ //# sourceMappingURL=dtx.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dtx.js","sourceRoot":"","sources":["../../../../../rtp/src/processor/dtx.ts"],"names":[],"mappings":";;;AAAA,mCAAoC;AASpC,MAAa,OAAO;IAIlB,YAAmB,KAAa,EAAU,WAAmB;;;;;mBAA1C;;;;;;mBAAuB;;QAH1C;;;;mBAAc,IAAA,mBAAU,GAAE;WAAC;QAC3B;;;;;WAA2B;QAC3B;;;;mBAAoB,CAAC;WAAC;IAC0C,CAAC;IAEjE,MAAM;QACJ,OAAO,EAAE,EAAE,EAAE,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IACtC,CAAC;CACF;AArDD,0BAqDC","sourcesContent":["import { randomUUID } from \"crypto\";\n\nimport { CodecFrame, DepacketizerOutput } from \"./depacketizer\";\nimport { Processor } from \"./interface\";\n\nexport type DtxInput = DepacketizerOutput;\n\nexport type DtxOutput = DtxInput;\n\nexport class DtxBase implements Processor<DtxInput, DtxOutput> {\n readonly id = randomUUID();\n previousTimestamp?: number;\n private fillCount = 0;\n constructor(public ptime: number, private dummyPacket: Buffer) {}\n\n toJSON(): Record<string, any> {\n return { id: this.id, fillCount: this.fillCount };\n }\n\n processInput({ frame, eol }: DtxInput): DtxOutput[] {\n if (eol) {\n this.stop();\n return [{ eol: true }];\n }\n\n if (frame) {\n if (!this.previousTimestamp) {\n this.previousTimestamp = frame.time;\n return [{ frame }];\n }\n\n if (frame.time != this.previousTimestamp + this.ptime) {\n const dummyPackets: { frame: CodecFrame }[] = [];\n for (\n let time = this.previousTimestamp;\n time < frame.time;\n time += this.ptime\n ) {\n dummyPackets.push({\n frame: {\n time,\n isKeyframe: frame.isKeyframe,\n data: this.dummyPacket,\n },\n });\n this.fillCount++;\n }\n\n this.previousTimestamp = frame.time;\n return [...dummyPackets, { frame }];\n } else {\n this.previousTimestamp = frame.time;\n return [{ frame }];\n }\n }\n\n return [];\n }\n\n private stop() {\n this.dummyPacket = undefined as any;\n }\n}\n"]}
@@ -0,0 +1,6 @@
1
+ import { DtxBase, DtxInput, DtxOutput } from "./dtx";
2
+ export declare class DtxCallback extends DtxBase {
3
+ private cb?;
4
+ pipe: (cb: (input: DtxOutput) => void) => this;
5
+ input: (input: DtxInput) => void;
6
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DtxCallback = void 0;
4
+ const dtx_1 = require("./dtx");
5
+ class DtxCallback extends dtx_1.DtxBase {
6
+ constructor() {
7
+ super(...arguments);
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
+ if (!this.cb) {
29
+ return;
30
+ }
31
+ for (const output of this.processInput(input)) {
32
+ this.cb(output);
33
+ }
34
+ if (input.eol) {
35
+ this.cb = undefined;
36
+ }
37
+ }
38
+ });
39
+ }
40
+ }
41
+ exports.DtxCallback = DtxCallback;
42
+ //# sourceMappingURL=dtxCallback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dtxCallback.js","sourceRoot":"","sources":["../../../../../rtp/src/processor/dtxCallback.ts"],"names":[],"mappings":";;;AAAA,+BAAqD;AAErD,MAAa,WAAY,SAAQ,aAAO;IAAxC;;QACE;;;;;WAAwC;QAExC;;;;mBAAO,CAAC,EAA8B,EAAE,EAAE;gBACxC,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;gBACb,OAAO,IAAI,CAAC;YACd,CAAC;WAAC;QAEF;;;;mBAAQ,CAAC,KAAe,EAAE,EAAE;gBAC1B,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE;oBACZ,OAAO;iBACR;gBACD,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE;oBAC7C,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;iBACjB;gBACD,IAAI,KAAK,CAAC,GAAG,EAAE;oBACb,IAAI,CAAC,EAAE,GAAG,SAAS,CAAC;iBACrB;YACH,CAAC;WAAC;IACJ,CAAC;CAAA;AAnBD,kCAmBC","sourcesContent":["import { DtxBase, DtxInput, DtxOutput } from \"./dtx\";\n\nexport class DtxCallback extends DtxBase {\n private cb?: (input: DtxOutput) => void;\n\n pipe = (cb: (input: DtxOutput) => void) => {\n this.cb = cb;\n return this;\n };\n\n input = (input: DtxInput) => {\n if (!this.cb) {\n return;\n }\n for (const output of this.processInput(input)) {\n this.cb(output);\n }\n if (input.eol) {\n this.cb = undefined;\n }\n };\n}\n"]}
@@ -1,11 +1,16 @@
1
1
  export * from "./depacketizer";
2
2
  export * from "./depacketizerCallback";
3
3
  export * from "./depacketizerTransformer";
4
+ export * from "./dtx";
5
+ export * from "./dtxCallback";
6
+ export * from "./interface";
4
7
  export * from "./jitterBuffer";
5
8
  export * from "./jitterBufferCallback";
6
9
  export * from "./jitterBufferTransformer";
7
10
  export * from "./lipsync";
8
11
  export * from "./lipsyncCallback";
12
+ export * from "./mute";
13
+ export * from "./muteCallback";
9
14
  export * from "./nack";
10
15
  export * from "./nackHandlerCallback";
11
16
  export * from "./ntpTime";
@@ -17,11 +17,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./depacketizer"), exports);
18
18
  __exportStar(require("./depacketizerCallback"), exports);
19
19
  __exportStar(require("./depacketizerTransformer"), exports);
20
+ __exportStar(require("./dtx"), exports);
21
+ __exportStar(require("./dtxCallback"), exports);
22
+ __exportStar(require("./interface"), exports);
20
23
  __exportStar(require("./jitterBuffer"), exports);
21
24
  __exportStar(require("./jitterBufferCallback"), exports);
22
25
  __exportStar(require("./jitterBufferTransformer"), exports);
23
26
  __exportStar(require("./lipsync"), exports);
24
27
  __exportStar(require("./lipsyncCallback"), exports);
28
+ __exportStar(require("./mute"), exports);
29
+ __exportStar(require("./muteCallback"), exports);
25
30
  __exportStar(require("./nack"), exports);
26
31
  __exportStar(require("./nackHandlerCallback"), exports);
27
32
  __exportStar(require("./ntpTime"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../rtp/src/processor/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,yDAAuC;AACvC,4DAA0C;AAC1C,iDAA+B;AAC/B,yDAAuC;AACvC,4DAA0C;AAC1C,4CAA0B;AAC1B,oDAAkC;AAClC,yCAAuB;AACvB,wDAAsC;AACtC,4CAA0B;AAC1B,oDAAkC;AAClC,4CAA0B;AAC1B,oDAAkC;AAClC,2CAAyB;AACzB,yCAAuB;AACvB,iDAA+B;AAC/B,+CAA6B","sourcesContent":["export * from \"./depacketizer\";\nexport * from \"./depacketizerCallback\";\nexport * from \"./depacketizerTransformer\";\nexport * from \"./jitterBuffer\";\nexport * from \"./jitterBufferCallback\";\nexport * from \"./jitterBufferTransformer\";\nexport * from \"./lipsync\";\nexport * from \"./lipsyncCallback\";\nexport * from \"./nack\";\nexport * from \"./nackHandlerCallback\";\nexport * from \"./ntpTime\";\nexport * from \"./ntpTimeCallback\";\nexport * from \"./rtpTime\";\nexport * from \"./rtpTimeCallback\";\nexport * from \"./source\";\nexport * from \"./webm\";\nexport * from \"./webmCallback\";\nexport * from \"./webmStream\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../rtp/src/processor/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,yDAAuC;AACvC,4DAA0C;AAC1C,wCAAsB;AACtB,gDAA8B;AAC9B,8CAA4B;AAC5B,iDAA+B;AAC/B,yDAAuC;AACvC,4DAA0C;AAC1C,4CAA0B;AAC1B,oDAAkC;AAClC,yCAAuB;AACvB,iDAA+B;AAC/B,yCAAuB;AACvB,wDAAsC;AACtC,4CAA0B;AAC1B,oDAAkC;AAClC,4CAA0B;AAC1B,oDAAkC;AAClC,2CAAyB;AACzB,yCAAuB;AACvB,iDAA+B;AAC/B,+CAA6B","sourcesContent":["export * from \"./depacketizer\";\nexport * from \"./depacketizerCallback\";\nexport * from \"./depacketizerTransformer\";\nexport * from \"./dtx\";\nexport * from \"./dtxCallback\";\nexport * from \"./interface\";\nexport * from \"./jitterBuffer\";\nexport * from \"./jitterBufferCallback\";\nexport * from \"./jitterBufferTransformer\";\nexport * from \"./lipsync\";\nexport * from \"./lipsyncCallback\";\nexport * from \"./mute\";\nexport * from \"./muteCallback\";\nexport * from \"./nack\";\nexport * from \"./nackHandlerCallback\";\nexport * from \"./ntpTime\";\nexport * from \"./ntpTimeCallback\";\nexport * from \"./rtpTime\";\nexport * from \"./rtpTimeCallback\";\nexport * from \"./source\";\nexport * from \"./webm\";\nexport * from \"./webmCallback\";\nexport * from \"./webmStream\";\n"]}
@@ -1,7 +1,9 @@
1
1
  export interface Processor<Input, Output> {
2
2
  processInput: (input: Input) => Output[];
3
+ toJSON(): Record<string, any>;
3
4
  }
4
5
  export interface AVProcessor<Input> {
5
6
  processAudioInput: (input: Input) => void;
6
7
  processVideoInput: (input: Input) => void;
8
+ toJSON(): Record<string, any>;
7
9
  }
@@ -1 +1 @@
1
- {"version":3,"file":"interface.js","sourceRoot":"","sources":["../../../../../rtp/src/processor/interface.ts"],"names":[],"mappings":"","sourcesContent":["export interface Processor<Input, Output> {\n processInput: (input: Input) => Output[];\n}\n\nexport interface AVProcessor<Input> {\n processAudioInput: (input: Input) => void;\n processVideoInput: (input: Input) => void;\n}\n"]}
1
+ {"version":3,"file":"interface.js","sourceRoot":"","sources":["../../../../../rtp/src/processor/interface.ts"],"names":[],"mappings":"","sourcesContent":["export interface Processor<Input, Output> {\n processInput: (input: Input) => Output[];\n toJSON(): Record<string, any>;\n}\n\nexport interface AVProcessor<Input> {\n processAudioInput: (input: Input) => void;\n processVideoInput: (input: Input) => void;\n toJSON(): Record<string, any>;\n}\n"]}
@@ -14,7 +14,15 @@ export declare class JitterBufferBase implements Processor<JitterBufferInput, Ji
14
14
  private presentSeqNum?;
15
15
  private rtpBuffer;
16
16
  private get expectNextSeqNum();
17
+ private internalStats;
17
18
  constructor(clockRate: number, options?: Partial<JitterBufferOptions>);
19
+ toJSON(): {
20
+ rtpBufferLength: number;
21
+ presentSeqNum: number | undefined;
22
+ expectNextSeqNum: number;
23
+ stats: {};
24
+ };
25
+ private stop;
18
26
  processInput(input: JitterBufferInput): JitterBufferOutput[];
19
27
  private processRtp;
20
28
  private pushRtpBuffer;
@@ -1,13 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.JitterBufferBase = void 0;
7
- const debug_1 = __importDefault(require("debug"));
8
4
  const __1 = require("..");
9
- const srcPath = `werift-rtp : packages/rtp/src/processor/jitterBuffer.ts`;
10
- const log = (0, debug_1.default)(srcPath);
11
5
  class JitterBufferBase {
12
6
  get expectNextSeqNum() {
13
7
  return (0, __1.uint16Add)(this.presentSeqNum, 1);
@@ -38,11 +32,28 @@ class JitterBufferBase {
38
32
  writable: true,
39
33
  value: {}
40
34
  });
35
+ Object.defineProperty(this, "internalStats", {
36
+ enumerable: true,
37
+ configurable: true,
38
+ writable: true,
39
+ value: {}
40
+ });
41
41
  this.options = {
42
42
  latency: options.latency ?? 200,
43
43
  bufferSize: options.bufferSize ?? 10000,
44
44
  };
45
45
  }
46
+ toJSON() {
47
+ return {
48
+ rtpBufferLength: Object.values(this.rtpBuffer).length,
49
+ presentSeqNum: this.presentSeqNum,
50
+ expectNextSeqNum: this.expectNextSeqNum,
51
+ stats: this.internalStats,
52
+ };
53
+ }
54
+ stop() {
55
+ this.rtpBuffer = {};
56
+ }
46
57
  processInput(input) {
47
58
  const output = [];
48
59
  if (!input.rtp) {
@@ -52,6 +63,7 @@ class JitterBufferBase {
52
63
  output.push({ rtp });
53
64
  }
54
65
  output.push({ eol: true });
66
+ this.stop();
55
67
  }
56
68
  return output;
57
69
  }
@@ -89,7 +101,11 @@ class JitterBufferBase {
89
101
  }
90
102
  // duplicate
91
103
  if ((0, __1.uint16Gte)(this.presentSeqNum, sequenceNumber)) {
92
- log("duplicate", { sequenceNumber });
104
+ this.internalStats["duplicate"] = {
105
+ count: (this.internalStats["duplicate"]?.count ?? 0) + 1,
106
+ sequenceNumber,
107
+ timestamp: new Date().toISOString(),
108
+ };
93
109
  return { nothing: undefined };
94
110
  }
95
111
  // expect
@@ -112,10 +128,12 @@ class JitterBufferBase {
112
128
  }
113
129
  pushRtpBuffer(rtp) {
114
130
  if (Object.values(this.rtpBuffer).length > this.options.bufferSize) {
115
- log("buffer over flow");
131
+ this.internalStats["buffer_overflow"] = {
132
+ count: (this.internalStats["buffer_overflow"]?.count ?? 0) + 1,
133
+ timestamp: new Date().toISOString(),
134
+ };
116
135
  return;
117
136
  }
118
- // log("pushRtpBuffer", { seq: rtp.header.sequenceNumber });
119
137
  this.rtpBuffer[rtp.header.sequenceNumber] = rtp;
120
138
  }
121
139
  resolveBuffer(seqNumFrom) {
@@ -130,12 +148,6 @@ class JitterBufferBase {
130
148
  break;
131
149
  }
132
150
  }
133
- // if (resolve.length > 0) {
134
- // log(
135
- // "resolveBuffer",
136
- // resolve.map((r) => r.header.sequenceNumber)
137
- // );
138
- // }
139
151
  return resolve;
140
152
  }
141
153
  sortAndClearBuffer(rtpBuffer) {
@@ -162,12 +174,14 @@ class JitterBufferBase {
162
174
  }
163
175
  const elapsedSec = (0, __1.uint32Add)(baseTimestamp, -timestamp) / this.clockRate;
164
176
  if (elapsedSec * 1000 > this.options.latency) {
165
- log("timeout packet", {
177
+ this.internalStats["timeout_packet"] = {
178
+ count: (this.internalStats["timeout_packet"]?.count ?? 0) + 1,
179
+ at: new Date().toISOString(),
166
180
  sequenceNumber,
167
181
  elapsedSec,
168
182
  baseTimestamp,
169
183
  timestamp,
170
- });
184
+ };
171
185
  if (latestTimeoutSeqNum == undefined) {
172
186
  latestTimeoutSeqNum = sequenceNumber;
173
187
  }