werift 0.25.1 → 0.25.2

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 (81) hide show
  1. package/lib/index.mjs +4101 -1781
  2. package/lib/nonstandard/index.mjs +3582 -1221
  3. package/lib/polyfill/dom.mjs +16711 -17852
  4. package/lib/polyfill/index.mjs +16711 -17852
  5. package/lib/rtp/src/codec/av1.d.ts +61 -1
  6. package/lib/rtp/src/codec/av1.js +332 -33
  7. package/lib/rtp/src/codec/av1.js.map +1 -1
  8. package/lib/rtp/src/codec/base.d.ts +49 -1
  9. package/lib/rtp/src/codec/base.js +81 -1
  10. package/lib/rtp/src/codec/base.js.map +1 -1
  11. package/lib/rtp/src/codec/g711.d.ts +37 -0
  12. package/lib/rtp/src/codec/g711.js +109 -0
  13. package/lib/rtp/src/codec/g711.js.map +1 -0
  14. package/lib/rtp/src/codec/g722.d.ts +31 -0
  15. package/lib/rtp/src/codec/g722.js +82 -0
  16. package/lib/rtp/src/codec/g722.js.map +1 -0
  17. package/lib/rtp/src/codec/h264.d.ts +81 -7
  18. package/lib/rtp/src/codec/h264.js +382 -21
  19. package/lib/rtp/src/codec/h264.js.map +1 -1
  20. package/lib/rtp/src/codec/h265.d.ts +101 -0
  21. package/lib/rtp/src/codec/h265.js +615 -0
  22. package/lib/rtp/src/codec/h265.js.map +1 -0
  23. package/lib/rtp/src/codec/index.d.ts +6 -1
  24. package/lib/rtp/src/codec/index.js +25 -0
  25. package/lib/rtp/src/codec/index.js.map +1 -1
  26. package/lib/rtp/src/codec/mp4a.d.ts +88 -0
  27. package/lib/rtp/src/codec/mp4a.js +386 -0
  28. package/lib/rtp/src/codec/mp4a.js.map +1 -0
  29. package/lib/rtp/src/codec/opus.d.ts +14 -2
  30. package/lib/rtp/src/codec/opus.js +32 -2
  31. package/lib/rtp/src/codec/opus.js.map +1 -1
  32. package/lib/rtp/src/codec/telephoneEvent.d.ts +102 -0
  33. package/lib/rtp/src/codec/telephoneEvent.js +176 -0
  34. package/lib/rtp/src/codec/telephoneEvent.js.map +1 -0
  35. package/lib/rtp/src/codec/vp8.d.ts +26 -1
  36. package/lib/rtp/src/codec/vp8.js +76 -2
  37. package/lib/rtp/src/codec/vp8.js.map +1 -1
  38. package/lib/rtp/src/codec/vp9.d.ts +25 -1
  39. package/lib/rtp/src/codec/vp9.js +64 -2
  40. package/lib/rtp/src/codec/vp9.js.map +1 -1
  41. package/lib/rtp/src/const.d.ts +1 -0
  42. package/lib/rtp/src/const.js +5 -0
  43. package/lib/rtp/src/const.js.map +1 -0
  44. package/lib/rtp/src/extra/container/mp4/container.js +4 -1
  45. package/lib/rtp/src/extra/container/mp4/container.js.map +1 -1
  46. package/lib/rtp/src/extra/container/mp4/h264.d.ts +26 -0
  47. package/lib/rtp/src/extra/container/mp4/h264.js +54 -0
  48. package/lib/rtp/src/extra/container/mp4/h264.js.map +1 -1
  49. package/lib/rtp/src/extra/processor/mp4.d.ts +16 -0
  50. package/lib/rtp/src/extra/processor/mp4.js +54 -20
  51. package/lib/rtp/src/extra/processor/mp4.js.map +1 -1
  52. package/lib/rtp/src/index.d.ts +1 -0
  53. package/lib/rtp/src/index.js +1 -0
  54. package/lib/rtp/src/index.js.map +1 -1
  55. package/lib/rtp/src/rtp/mediaClock.d.ts +283 -0
  56. package/lib/rtp/src/rtp/mediaClock.js +655 -0
  57. package/lib/rtp/src/rtp/mediaClock.js.map +1 -0
  58. package/lib/rtp/src/util.d.ts +59 -6
  59. package/lib/rtp/src/util.js +88 -10
  60. package/lib/rtp/src/util.js.map +1 -1
  61. package/lib/webrtc/src/media/codec.d.ts +18 -0
  62. package/lib/webrtc/src/media/codec.js +43 -2
  63. package/lib/webrtc/src/media/codec.js.map +1 -1
  64. package/lib/webrtc/src/media/codecCompatibility.d.ts +5 -0
  65. package/lib/webrtc/src/media/codecCompatibility.js +15 -4
  66. package/lib/webrtc/src/media/codecCompatibility.js.map +1 -1
  67. package/lib/webrtc/src/nonstandard/dummyMedia.js +20 -6
  68. package/lib/webrtc/src/nonstandard/dummyMedia.js.map +1 -1
  69. package/lib/webrtc/src/nonstandard/userMedia/packetizer.d.ts +2 -2
  70. package/lib/webrtc/src/nonstandard/userMedia/packetizer.js +61 -306
  71. package/lib/webrtc/src/nonstandard/userMedia/packetizer.js.map +1 -1
  72. package/lib/webrtc/src/nonstandard/userMedia.d.ts +2 -0
  73. package/lib/webrtc/src/nonstandard/userMedia.js +41 -7
  74. package/lib/webrtc/src/nonstandard/userMedia.js.map +1 -1
  75. package/lib/webrtc/src/peerConnection.js +3 -1
  76. package/lib/webrtc/src/peerConnection.js.map +1 -1
  77. package/lib/webrtc/src/sdpManager.js +3 -2
  78. package/lib/webrtc/src/sdpManager.js.map +1 -1
  79. package/lib/webrtc/src/transceiverManager.js +2 -1
  80. package/lib/webrtc/src/transceiverManager.js.map +1 -1
  81. package/package.json +1 -1
@@ -0,0 +1,283 @@
1
+ import { Event } from "../../../common/src";
2
+ export interface RtpMediaTimelineOptions {
3
+ /** RTP clock rate in Hz (e.g. 48000 for Opus, 90000 for video). */
4
+ clockRate: number;
5
+ /**
6
+ * Samples per frame. May be fractional (e.g. 90000 / 29.97).
7
+ * Exactly one of `frameSamples` / `frameDurationMs` must be given.
8
+ */
9
+ frameSamples?: number;
10
+ /** Frame duration in milliseconds. May be fractional. */
11
+ frameDurationMs?: number;
12
+ /** RTP timestamp of frame 0. Default: random32(). */
13
+ initialTimestamp?: number;
14
+ }
15
+ /** Wall-clock anchor that maps a monotonic time to a frame index. */
16
+ export interface RtpMediaTimelineAnchor {
17
+ /** Monotonic time (ms) of `frameIndex`'s deadline. */
18
+ time: number;
19
+ frameIndex: number;
20
+ }
21
+ export interface RtpMediaClockTick {
22
+ /** Slot number N of this tick. */
23
+ frameIndex: number;
24
+ /** RTP timestamp of the slot (uint32, wrapped). */
25
+ timestamp: number;
26
+ /** Samples elapsed since the previous tick, including skipped slots. */
27
+ elapsedSamples: number;
28
+ /** Slots that were skipped instead of being emitted (normally 0). */
29
+ skippedFrames: number;
30
+ /** Scheduled monotonic time (ms) of this slot. */
31
+ deadline: number;
32
+ /** `now - deadline` in ms. */
33
+ lateness: number;
34
+ }
35
+ /**
36
+ * Pure, deterministic RTP media timeline.
37
+ *
38
+ * All values are computed absolutely from the frame index, so no error
39
+ * accumulates no matter how long the timeline runs.
40
+ */
41
+ export declare class RtpMediaTimeline {
42
+ readonly clockRate: number;
43
+ readonly frameSamples: number;
44
+ readonly frameDurationMs: number;
45
+ readonly initialTimestamp: number;
46
+ constructor(options: RtpMediaTimelineOptions);
47
+ /** `round(N * frameSamples)`: samples elapsed from frame 0 to frame N. */
48
+ elapsedSamples(frameIndex: number): number;
49
+ /** `(initialTimestamp + elapsedSamples(N)) mod 2^32` */
50
+ timestamp(frameIndex: number): number;
51
+ /** `anchor.time + (N - anchor.frameIndex) * frameDurationMs` */
52
+ deadline(anchor: RtpMediaTimelineAnchor, frameIndex: number): number;
53
+ /** Latest slot whose deadline has been reached at `now`. */
54
+ latestFrameIndex(anchor: RtpMediaTimelineAnchor, now: number): number;
55
+ /**
56
+ * Resolves the tick to emit at `now`.
57
+ *
58
+ * Returns `undefined` when the deadline of `nextFrameIndex` has not been
59
+ * reached yet. When several slots have elapsed, `stallPolicy: "skip"`
60
+ * (default) returns only the latest reached slot and reports the slots in
61
+ * between as `skippedFrames`; `"delay"` returns `nextFrameIndex` with its
62
+ * original deadline, so `lateness` shows how far behind the clock is.
63
+ * `skippedFrames` and `elapsedSamples` are counted from `lastFrameIndex`
64
+ * (or from `baseFrameIndex` before the first tick), so a `nextFrameIndex`
65
+ * moved forward (e.g. by `resume()`) is reported as skipped too.
66
+ */
67
+ resolveTick({ anchor, nextFrameIndex, lastFrameIndex, baseFrameIndex, now, stallPolicy, }: {
68
+ anchor: RtpMediaTimelineAnchor;
69
+ nextFrameIndex: number;
70
+ /** Frame index of the previous tick, if any. */
71
+ lastFrameIndex?: number;
72
+ /**
73
+ * First slot of the timeline, used as the counting origin while there is no
74
+ * previous tick. Default: `nextFrameIndex`.
75
+ */
76
+ baseFrameIndex?: number;
77
+ now: number;
78
+ stallPolicy?: RtpMediaClockStallPolicy;
79
+ }): RtpMediaClockTick | undefined;
80
+ }
81
+ export interface RtpMediaClockScheduler {
82
+ setTimeout(cb: () => void, ms: number): unknown;
83
+ clearTimeout(handle: unknown): void;
84
+ }
85
+ /**
86
+ * What to do when the clock falls behind by one frame or more.
87
+ *
88
+ * - `"skip"`: jump to the latest reached slot. The slots in between are
89
+ * reported as `skippedFrames` and appear as a timestamp gap. RTP time stays
90
+ * aligned with real time. Suited to audio and to live video that encodes the
91
+ * latest captured frame on each tick.
92
+ * - `"delay"`: never skip a slot. The late slot is emitted immediately and the
93
+ * timeline is re-anchored to `now`, so the stall is absorbed as added latency
94
+ * instead of a gap or a burst. Suited to already-encoded video (or any source
95
+ * where every frame must be sent) at a constant frame rate.
96
+ */
97
+ export type RtpMediaClockStallPolicy = "skip" | "delay";
98
+ export interface RtpMediaClockOptions extends RtpMediaTimelineOptions {
99
+ /** Default: `"skip"`. */
100
+ stallPolicy?: RtpMediaClockStallPolicy;
101
+ /** Monotonic time source in ms. Default: `performance.now()`. */
102
+ now?: () => number;
103
+ /** Timer implementation. Default: global setTimeout / clearTimeout. */
104
+ scheduler?: RtpMediaClockScheduler;
105
+ /** Call `unref()` on timer handles (Node.js only). Default: false. */
106
+ unref?: boolean;
107
+ /** Aborting the signal is equivalent to `stop()`. */
108
+ signal?: AbortSignal;
109
+ }
110
+ export interface RtpMediaClockResumeOptions {
111
+ /**
112
+ * `false`: the paused wall-clock time is reflected as a timestamp gap, the
113
+ * same as a scheduler stall.
114
+ * `true`: the pause is collapsed and the timeline advances by one frame.
115
+ *
116
+ * Default: `false` for `stallPolicy: "skip"`, `true` for `"delay"`.
117
+ */
118
+ continuous?: boolean;
119
+ }
120
+ export type RtpMediaClockState = "idle" | "running" | "paused" | "stopped";
121
+ /**
122
+ * Monotonic real-time RTP media clock / pacer.
123
+ *
124
+ * - Each slot N is scheduled at the absolute deadline
125
+ * `origin + N * frameDurationMs`, so timer lateness never accumulates.
126
+ * - When the event loop stalls past several deadlines, `onTick` fires once.
127
+ * With `stallPolicy: "skip"` (default) it fires for the latest reached slot;
128
+ * the slots in between are reported via `skippedFrames` and appear as a
129
+ * timestamp gap. With `"delay"` it fires for the next slot and re-anchors
130
+ * the timeline, so no slot is skipped. Late ticks are never burst.
131
+ * - `onTick` subscribers are invoked synchronously after the internal state
132
+ * (including the next timer) has been updated. Returned promises are not
133
+ * awaited; backpressure is out of scope.
134
+ * - `resume()` re-anchors the origin to the resume time and emits a tick
135
+ * immediately. With `"skip"` the paused time is reflected as a timestamp gap
136
+ * by default; pass `{ continuous: true }` to collapse it (default for
137
+ * `"delay"`).
138
+ *
139
+ * This is an opt-in utility for media sources. `RTCRtpSender.sendRtp()` never
140
+ * rewrites RTP timestamps based on send time.
141
+ */
142
+ export declare class RtpMediaClock {
143
+ readonly timeline: RtpMediaTimeline;
144
+ readonly onTick: Event<[RtpMediaClockTick]>;
145
+ readonly stallPolicy: RtpMediaClockStallPolicy;
146
+ private readonly now;
147
+ private readonly scheduler;
148
+ private readonly unref;
149
+ private readonly signal?;
150
+ private _state;
151
+ private anchor;
152
+ private nextFrameIndex;
153
+ private _lastTick?;
154
+ private timerHandle?;
155
+ constructor(options: RtpMediaClockOptions);
156
+ get state(): RtpMediaClockState;
157
+ get clockRate(): number;
158
+ /** The most recently emitted tick. */
159
+ get lastTick(): RtpMediaClockTick | undefined;
160
+ /** RTP timestamp of the latest tick, or of frame 0 before the first tick. */
161
+ get timestamp(): number;
162
+ start(onTick?: (tick: RtpMediaClockTick) => void): void;
163
+ pause(): void;
164
+ resume(options?: RtpMediaClockResumeOptions): void;
165
+ stop(): void;
166
+ private handleAbort;
167
+ private schedule;
168
+ private clearTimer;
169
+ private handleTimer;
170
+ }
171
+ export interface RtpMediaPacerOptions {
172
+ /** RTP clock rate in Hz (e.g. 90000 for video). */
173
+ clockRate: number;
174
+ /** RTP timestamp of the first pushed frame's `pts`. Default: random32(). */
175
+ initialTimestamp?: number;
176
+ /**
177
+ * Initial playout delay (ms) of the first frame. For streaming sources it
178
+ * absorbs arrival jitter / bursts up to this amount without re-anchoring.
179
+ * Default: 0.
180
+ */
181
+ latencyMs?: number;
182
+ /** Monotonic time source in ms. Default: `performance.now()`. */
183
+ now?: () => number;
184
+ /** Timer implementation. Default: global setTimeout / clearTimeout. */
185
+ scheduler?: RtpMediaClockScheduler;
186
+ /** Call `unref()` on timer handles (Node.js only). Default: false. */
187
+ unref?: boolean;
188
+ /** Aborting the signal is equivalent to `stop()`. */
189
+ signal?: AbortSignal;
190
+ }
191
+ export interface RtpMediaPacerFrameTiming {
192
+ /**
193
+ * Presentation time in `clockRate` units (e.g. container PTS rescaled to
194
+ * 90 kHz). Becomes the RTP timestamp. May be fractional.
195
+ */
196
+ pts: number;
197
+ /**
198
+ * Decode time in `clockRate` units; frames are paced by it and must be pushed
199
+ * in non-decreasing `dts` order. Default: `pts` (no B-frames).
200
+ */
201
+ dts?: number;
202
+ }
203
+ export interface RtpMediaPacerTick<T> {
204
+ frame: T;
205
+ /** Number of frames emitted before this one. */
206
+ frameIndex: number;
207
+ /** RTP timestamp derived from `pts` (uint32, wrapped). */
208
+ timestamp: number;
209
+ pts: number;
210
+ dts: number;
211
+ /** Scheduled monotonic time (ms) of this frame. */
212
+ deadline: number;
213
+ /** `now - deadline` in ms. */
214
+ lateness: number;
215
+ /** Total time (ms) the timeline has been shifted by stalls and pauses. */
216
+ delay: number;
217
+ }
218
+ /**
219
+ * Monotonic real-time pacer for frames with their own timestamps, such as
220
+ * variable-frame-rate encoded video. Works both for sources that are read
221
+ * ahead (demuxed files) and for streaming sources that deliver frames in real
222
+ * time with jitter (live encoders, pipes, network ingest).
223
+ *
224
+ * - Frame k is emitted at the absolute deadline
225
+ * `anchor.time + (dts(k) - anchor.dts) * 1000 / clockRate`, so timer
226
+ * lateness never accumulates. The RTP timestamp is
227
+ * `initialTimestamp + (pts(k) - pts(first frame))`, which keeps the source's
228
+ * frame spacing (including B-frame reordering).
229
+ * - Frames are never skipped. When the emitted frame and the next queued frame
230
+ * are both overdue (a stall, or a producer that pushes a late batch), only
231
+ * the emitted frame is sent and the timeline is re-anchored to `now`, so the
232
+ * stall becomes added latency (`delay`) instead of a burst. A frame pushed
233
+ * after its deadline while the queue is empty is emitted immediately.
234
+ * - For streaming sources, frames arriving early (bursts) wait for their
235
+ * deadline and frames arriving late are sent at once, so `delay` grows only
236
+ * up to the worst arrival lateness seen, never cumulatively. `latencyMs`
237
+ * reserves headroom for that jitter up front.
238
+ * - `resume()` emits the next frame immediately if it became due while paused
239
+ * and re-anchors to it; the paused time is added to `delay`.
240
+ * - `onTick` subscribers are invoked synchronously after the internal state has
241
+ * been updated. Returned promises are not awaited; use `queueLength` for
242
+ * backpressure on the producer side.
243
+ */
244
+ export declare class RtpMediaPacer<T = Buffer> {
245
+ readonly clockRate: number;
246
+ readonly initialTimestamp: number;
247
+ readonly onTick: Event<[RtpMediaPacerTick<T>]>;
248
+ private readonly now;
249
+ private readonly scheduler;
250
+ private readonly unref;
251
+ private readonly signal?;
252
+ private readonly latencyMs;
253
+ private _state;
254
+ private queue;
255
+ private firstPts?;
256
+ private lastPushedDts?;
257
+ /** maps a dts to a monotonic time; undefined until the first emission */
258
+ private anchor?;
259
+ private frameIndex;
260
+ private _delay;
261
+ private _lastTick?;
262
+ private timerHandle?;
263
+ constructor(options: RtpMediaPacerOptions);
264
+ get state(): RtpMediaClockState;
265
+ /** Frames pushed but not emitted yet. */
266
+ get queueLength(): number;
267
+ /** The most recently emitted tick. */
268
+ get lastTick(): RtpMediaPacerTick<T> | undefined;
269
+ /** Total time (ms) the timeline has been shifted so far. */
270
+ get delay(): number;
271
+ /** Queues a frame. Frames may be pushed before `start()`. */
272
+ push(frame: T, timing: RtpMediaPacerFrameTiming): void;
273
+ start(onTick?: (tick: RtpMediaPacerTick<T>) => void): void;
274
+ pause(): void;
275
+ resume(): void;
276
+ stop(): void;
277
+ private handleAbort;
278
+ private deadline;
279
+ private reanchor;
280
+ private scheduleNext;
281
+ private clearTimer;
282
+ private handleTimer;
283
+ }