@caprid/moq-media 0.0.0 → 0.1.1

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 (77) hide show
  1. package/LICENSE +20 -0
  2. package/NOTICE +33 -0
  3. package/README.md +187 -2
  4. package/UPSTREAM.json +19 -0
  5. package/dist/audio-player.d.ts +218 -0
  6. package/dist/audio-player.d.ts.map +1 -0
  7. package/dist/audio-player.js +649 -0
  8. package/dist/audio-player.js.map +1 -0
  9. package/dist/audio-worklet.d.ts +64 -0
  10. package/dist/audio-worklet.d.ts.map +1 -0
  11. package/dist/audio-worklet.js +355 -0
  12. package/dist/audio-worklet.js.map +1 -0
  13. package/dist/catalog.d.ts +141 -0
  14. package/dist/catalog.d.ts.map +1 -0
  15. package/dist/catalog.js +174 -0
  16. package/dist/catalog.js.map +1 -0
  17. package/dist/clock.d.ts +178 -0
  18. package/dist/clock.d.ts.map +1 -0
  19. package/dist/clock.js +190 -0
  20. package/dist/clock.js.map +1 -0
  21. package/dist/echo-loopback.d.ts +38 -0
  22. package/dist/echo-loopback.d.ts.map +1 -0
  23. package/dist/echo-loopback.js +100 -0
  24. package/dist/echo-loopback.js.map +1 -0
  25. package/dist/h264.d.ts +4 -0
  26. package/dist/h264.d.ts.map +1 -0
  27. package/dist/h264.js +8 -0
  28. package/dist/h264.js.map +1 -0
  29. package/dist/index.d.ts +15 -0
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +15 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/interrupt.d.ts +35 -0
  34. package/dist/interrupt.d.ts.map +1 -0
  35. package/dist/interrupt.js +44 -0
  36. package/dist/interrupt.js.map +1 -0
  37. package/dist/loc.d.ts +55 -0
  38. package/dist/loc.d.ts.map +1 -0
  39. package/dist/loc.js +74 -0
  40. package/dist/loc.js.map +1 -0
  41. package/dist/opus-decoder-wasm.d.ts +5 -0
  42. package/dist/opus-decoder-wasm.d.ts.map +1 -0
  43. package/dist/opus-decoder-wasm.js +9 -0
  44. package/dist/opus-decoder-wasm.js.map +1 -0
  45. package/dist/opus-decoder.d.ts +24 -0
  46. package/dist/opus-decoder.d.ts.map +1 -0
  47. package/dist/opus-decoder.js +130 -0
  48. package/dist/opus-decoder.js.map +1 -0
  49. package/dist/parse-catalog.d.ts +81 -0
  50. package/dist/parse-catalog.d.ts.map +1 -0
  51. package/dist/parse-catalog.js +134 -0
  52. package/dist/parse-catalog.js.map +1 -0
  53. package/dist/render-clock.d.ts +38 -0
  54. package/dist/render-clock.d.ts.map +1 -0
  55. package/dist/render-clock.js +40 -0
  56. package/dist/render-clock.js.map +1 -0
  57. package/dist/sequencer.d.ts +130 -0
  58. package/dist/sequencer.d.ts.map +1 -0
  59. package/dist/sequencer.js +599 -0
  60. package/dist/sequencer.js.map +1 -0
  61. package/dist/source.d.ts +21 -0
  62. package/dist/source.d.ts.map +1 -0
  63. package/dist/source.js +54 -0
  64. package/dist/source.js.map +1 -0
  65. package/dist/timeline.d.ts +69 -0
  66. package/dist/timeline.d.ts.map +1 -0
  67. package/dist/timeline.js +83 -0
  68. package/dist/timeline.js.map +1 -0
  69. package/dist/transcript.d.ts +84 -0
  70. package/dist/transcript.d.ts.map +1 -0
  71. package/dist/transcript.js +151 -0
  72. package/dist/transcript.js.map +1 -0
  73. package/dist/webcodecs.d.ts +32 -0
  74. package/dist/webcodecs.d.ts.map +1 -0
  75. package/dist/webcodecs.js +79 -0
  76. package/dist/webcodecs.js.map +1 -0
  77. package/package.json +34 -4
@@ -0,0 +1,100 @@
1
+ // Full-band stereo at the highest bitrate: this hop never leaves the machine, so its Opus pass should be transparent.
2
+ const transparent = (sdp, offer) => sdp?.replace(/(a=fmtp:\d+ .*useinbandfec=1)/, `$1;stereo=1;${offer ? 'sprop-stereo=1;' : ''}maxaveragebitrate=510000`);
3
+ function within(promise, ms, what) {
4
+ let timer;
5
+ return Promise.race([
6
+ promise,
7
+ new Promise((_, reject) => {
8
+ timer = setTimeout(() => reject(new Error(`The echo-cancellation loopback ${what} within ${ms} ms`)), ms);
9
+ }),
10
+ ]).finally(() => clearTimeout(timer));
11
+ }
12
+ /**
13
+ * Play `node` through a local WebRTC loopback so Chromium's echo canceller hears it. The node is connected to the
14
+ * loopback only once it is up; disconnect it from the context's destination yourself, or it plays twice. Rejects if
15
+ * the loopback cannot connect. It adds the WebRTC receiver's own buffering, which no API reports as output latency:
16
+ * set the audio player's `outputDelayUs` if video must stay in sync with it.
17
+ */
18
+ export async function createEchoCancellationLoopback(context, node, options = {}) {
19
+ const { RTCPeerConnection, MediaStream, Audio } = globalThis;
20
+ const timeoutMs = options.timeoutMs ?? 5_000;
21
+ const destination = context.createMediaStreamDestination();
22
+ destination.channelCount = 2;
23
+ const stream = destination.stream;
24
+ const sender = new RTCPeerConnection();
25
+ const receiver = new RTCPeerConnection();
26
+ const element = new Audio();
27
+ element.autoplay = true;
28
+ const close = () => {
29
+ element.srcObject = null;
30
+ sender.close();
31
+ receiver.close();
32
+ };
33
+ try {
34
+ sender.onicecandidate = ({ candidate }) => {
35
+ if (candidate)
36
+ receiver.addIceCandidate(candidate).catch(() => { });
37
+ };
38
+ receiver.onicecandidate = ({ candidate }) => {
39
+ if (candidate)
40
+ sender.addIceCandidate(candidate).catch(() => { });
41
+ };
42
+ const received = new Promise((resolve) => {
43
+ receiver.ontrack = ({ track }) => resolve(track);
44
+ });
45
+ const connected = new Promise((resolve, reject) => {
46
+ const check = () => {
47
+ if (receiver.connectionState === 'connected')
48
+ resolve();
49
+ else if (receiver.connectionState === 'failed' || receiver.connectionState === 'closed') {
50
+ reject(new Error(`The echo-cancellation loopback ${receiver.connectionState}`));
51
+ }
52
+ };
53
+ receiver.addEventListener('connectionstatechange', check);
54
+ check();
55
+ });
56
+ for (const track of stream.getAudioTracks())
57
+ sender.addTrack(track, stream);
58
+ const offer = await sender.createOffer();
59
+ const offerSdp = { type: 'offer', sdp: transparent(offer.sdp, true) };
60
+ await sender.setLocalDescription(offerSdp);
61
+ await receiver.setRemoteDescription(offerSdp);
62
+ const answer = await receiver.createAnswer();
63
+ const answerSdp = { type: 'answer', sdp: transparent(answer.sdp, false) };
64
+ await receiver.setLocalDescription(answerSdp);
65
+ await sender.setRemoteDescription(answerSdp);
66
+ const track = await within(received, timeoutMs, 'received no track');
67
+ await within(connected, timeoutMs, 'did not connect');
68
+ element.srcObject = new MediaStream([track]);
69
+ if (options.sinkId)
70
+ await element.setSinkId?.(options.sinkId);
71
+ // Autoplay may still be blocked; the context itself needed a gesture, so this one usually succeeds.
72
+ await element.play().catch(() => { });
73
+ }
74
+ catch (error) {
75
+ close();
76
+ throw error;
77
+ }
78
+ node.connect(destination);
79
+ let closed = false;
80
+ return {
81
+ async setSinkId(sinkId) {
82
+ if (!element.setSinkId)
83
+ throw new Error('This browser cannot choose an output device for a media element');
84
+ await element.setSinkId(sinkId);
85
+ },
86
+ close() {
87
+ if (closed)
88
+ return;
89
+ closed = true;
90
+ try {
91
+ node.disconnect(destination);
92
+ }
93
+ catch {
94
+ // Already disconnected.
95
+ }
96
+ close();
97
+ },
98
+ };
99
+ }
100
+ //# sourceMappingURL=echo-loopback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"echo-loopback.js","sourceRoot":"","sources":["../src/echo-loopback.ts"],"names":[],"mappings":"AAwEA,sHAAsH;AACtH,MAAM,WAAW,GAAG,CAAC,GAAuB,EAAE,KAAc,EAAE,EAAE,CAC9D,GAAG,EAAE,OAAO,CACV,+BAA+B,EAC/B,eAAe,KAAK,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,0BAA0B,CACxE,CAAC;AAEJ,SAAS,MAAM,CAAI,OAAmB,EAAE,EAAU,EAAE,IAAY;IAC9D,IAAI,KAAgD,CAAC;IACrD,OAAO,OAAO,CAAC,IAAI,CAAC;QAClB,OAAO;QACP,IAAI,OAAO,CAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;YAC/B,KAAK,GAAG,UAAU,CAAC,GAAG,EA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AO;YACnB,MAAM,GAAG,IAAI,CAAC;YACd,IAAI,CAAC;gBACH,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;YAC/B,CAAC;YAAC,MAAM,CAAC;gBACP,wBAAwB;YAC1B,CAAC;YACD,KAAK,EAAE,CAAC;QACV,CAAC;KACF,CAAC;AACJ,CAAC"}
package/dist/h264.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ /** Codec derivation follows Video.js avc-codec.ts. Encoders supply the configuration record. */
2
+ /** Read profile, constraint flags and level; this inspects the header, not SPS bitstream semantics. */
3
+ export declare function avcCodecString(avcc: Uint8Array): string;
4
+ //# sourceMappingURL=h264.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"h264.d.ts","sourceRoot":"","sources":["../src/h264.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAEhG,uGAAuG;AACvG,wBAAgB,cAAc,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAGvD"}
package/dist/h264.js ADDED
@@ -0,0 +1,8 @@
1
+ /** Codec derivation follows Video.js avc-codec.ts. Encoders supply the configuration record. */
2
+ /** Read profile, constraint flags and level; this inspects the header, not SPS bitstream semantics. */
3
+ export function avcCodecString(avcc) {
4
+ if (avcc.length < 4 || avcc[0] !== 1)
5
+ throw new Error('not an AVCDecoderConfigurationRecord');
6
+ return `avc1.${Array.from(avcc.subarray(1, 4), (byte) => byte.toString(16).padStart(2, '0').toUpperCase()).join('')}`;
7
+ }
8
+ //# sourceMappingURL=h264.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"h264.js","sourceRoot":"","sources":["../src/h264.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAEhG,uGAAuG;AACvG,MAAM,UAAU,cAAc,CAAC,IAAgB;IAC7C,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAC9F,OAAO,QAAQ,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;AACxH,CAAC"}
@@ -0,0 +1,15 @@
1
+ export { type AudioCutRange, type AudioInputClock, type AudioInputOptions, type AudioInputStats, type AudioPlayer, type AudioPlayerContext, type AudioPlayerFrame, type AudioPlayerGainNode, type AudioPlayerInput, type AudioPlayerNode, type AudioPlayerOptions, createAudioPlayer, opusPacketDurationUs, } from './audio-player.js';
2
+ export { type AudioTrackInfo, buildMsfCatalog, buildMsfEndCatalog, type DataTrackInfo, type MediaTimelineTrackInfo, type MediaTrackInfo, MSF_CATALOG_VERSION, type MsfCatalogInput, type MsfEndCatalogInput, type VideoTrackInfo, } from './catalog.js';
3
+ export { AUDIO_ONLY_TARGET_LATENCY_US, type BroadcastClock, type BroadcastClockOptions, createBroadcastClock, createPlayoutClock, type MicrosecondClock, type PlayoutClock, type PlayoutClockOptions, type PlayoutDecision, type PlayoutDrop, type PlayoutMode, type PlayoutShow, type PlayoutWait, type SampleTimeline, type SampleTimelineOptions, type SourceTimeline, type SourceTimelineOptions, } from './clock.js';
4
+ export { createEchoCancellationLoopback, type EchoCancellationContext, type EchoCancellationLoopback, type EchoCancellationLoopbackOptions, } from './echo-loopback.js';
5
+ export { avcCodecString } from './h264.js';
6
+ export { buildInterrupt, INTERRUPT_TRACK, type Interrupt, type InterruptInput, parseInterrupt } from './interrupt.js';
7
+ export { AUDIO_TRACK, CATALOG_TRACK, LOC_AUDIO_CONFIG, LOC_DOCUMENT, LOC_TIMESCALE, LOC_TIMESTAMP, LOC_VIDEO_CONFIG, type LocPropertiesOptions, type LocTimestampOptions, locProperties, locTimestampUs, locTrackProperties, MEDIA_TIMELINE_TRACK, MICROSECONDS_PER_SECOND, MSF_DOCUMENT, VIDEO_TRACK, } from './loc.js';
8
+ export { groupMsfTracks, type MsfCatalog, type MsfCatalogTrack, type MsfTrackGroup, type ParseMsfCatalogOptions, parseMsfCatalog, } from './parse-catalog.js';
9
+ export { createRenderClock, type RenderClock, type RenderClockOptions, type RenderObservation, } from './render-clock.js';
10
+ export { createFrameSequencer, type FrameDiscontinuity, type FrameSequencer, type FrameSequencerOptions, type FrameSequencerStats, type MissingGroups, type SequencedFrame, type SequencerPoll, } from './sequencer.js';
11
+ export { type ComposeMoqSourceOptions, composeMoqSource, encodeNameComponent, encodeNamespaceName } from './source.js';
12
+ export { buildMediaTimeline, createMediaTimeline, type MediaTimeline, type MediaTimelineEntry, type MediaTimelineEntryInput, type MediaTimelineOptions, mediaTimelineEntry, parseMediaTimeline, } from './timeline.js';
13
+ export { buildTranscriptSegment, createTranscript, parseTranscriptSegment, TRANSCRIPT_TRACK, type Transcript, type TranscriptCutRange, type TranscriptLine, type TranscriptSegment, type TranscriptSegmentInput, } from './transcript.js';
14
+ export { audioDecoderConfigFromTrack, audioTrackFromDecoderConfig, type ChunkToLocFrameOptions, chunkToLocFrame, type LocFrame, videoTrackFromDecoderConfig, } from './webcodecs.js';
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,KAAK,cAAc,EACnB,eAAe,E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BAAkB,EACvB,KAAK,iBAAiB,GACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,oBAAoB,EACpB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,aAAa,GACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,uBAAuB,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACvH,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EACzB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,sBAAsB,EACtB,gBAAgB,EAChB,sBAAsB,EACtB,gBAAgB,EAChB,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,GAC5B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,2BAA2B,EAC3B,2BAA2B,EAC3B,KAAK,sBAAsB,EAC3B,eAAe,EACf,KAAK,QAAQ,EACb,2BAA2B,GAC5B,MAAM,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ export { createAudioPlayer, opusPacketDurationUs, } from './audio-player.js';
2
+ export { buildMsfCatalog, buildMsfEndCatalog, MSF_CATALOG_VERSION, } from './catalog.js';
3
+ export { AUDIO_ONLY_TARGET_LATENCY_US, createBroadcastClock, createPlayoutClock, } from './clock.js';
4
+ export { createEchoCancellationLoopback, } from './echo-loopback.js';
5
+ export { avcCodecString } from './h264.js';
6
+ export { buildInterrupt, INTERRUPT_TRACK, parseInterrupt } from './interrupt.js';
7
+ export { AUDIO_TRACK, CATALOG_TRACK, LOC_AUDIO_CONFIG, LOC_DOCUMENT, LOC_TIMESCALE, LOC_TIMESTAMP, LOC_VIDEO_CONFIG, locProperties, locTimestampUs, locTrackProperties, MEDIA_TIMELINE_TRACK, MICROSECONDS_PER_SECOND, MSF_DOCUMENT, VIDEO_TRACK, } from './loc.js';
8
+ export { groupMsfTracks, parseMsfCatalog, } from './parse-catalog.js';
9
+ export { createRenderClock, } from './render-clock.js';
10
+ export { createFrameSequencer, } from './sequencer.js';
11
+ export { composeMoqSource, encodeNameComponent, encodeNamespaceName } from './source.js';
12
+ export { buildMediaTimeline, createMediaTimeline, mediaTimelineEntry, parseMediaTimeline, } from './timeline.js';
13
+ export { buildTranscriptSegment, createTranscript, parseTranscriptSegment, TRANSCRIPT_TRACK, } from './transcript.js';
14
+ export { audioDecoderConfigFromTrack, audioTrackFromDecoderConfig, chunkToLocFrame, videoTrackFromDecoderConfig, } from './webcodecs.js';
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAYL,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEL,eAAe,EACf,kBAAkB,EAIlB,mBAAmB,GAIpB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,4BAA4B,EAG5B,oBAAoB,EACpB,kBAAkB,GAanB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,8BAA8B,GAI/B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,eAAe,EAAuC,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACtH,OAAO,EACL,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,aAAa,EACb,gBAAgB,EAGhB,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,oBAAoB,EACpB,uBAAuB,EACvB,YAAY,EACZ,WAAW,GACZ,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,cAAc,EAKd,eAAe,GAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,iBAAiB,GAIlB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,oBAAoB,GAQrB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAgC,gBAAgB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACvH,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EAKnB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,sBAAsB,EACtB,gBAAgB,EAChB,sBAAsB,EACtB,gBAAgB,GAMjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,2BAA2B,EAC3B,2BAA2B,EAE3B,eAAe,EAEf,2BAA2B,GAC5B,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,35 @@
1
+ /** The interrupt track's default name, listed in the catalog as a data track. */
2
+ export declare const INTERRUPT_TRACK = "interrupt";
3
+ /**
4
+ * One interrupt: drop the named audio track's audio in a timeline range. It has the shape of the audio player's
5
+ * `AudioCutRange`, so `input.cut(interrupt)` applies it.
6
+ */
7
+ export interface Interrupt {
8
+ /** The audio track in the same namespace whose audio to drop. */
9
+ track: string;
10
+ /** Drop from this timestamp on, in microseconds on the broadcast timeline. Absent: from the oldest audio held. */
11
+ fromUs?: number;
12
+ /**
13
+ * Drop before this timestamp: the end of the last audio the talker sent. Frames that arrive later inside the range
14
+ * are dropped too, so the talker's next audio must start at or after it.
15
+ */
16
+ untilUs: number;
17
+ }
18
+ /** What {@link buildInterrupt} takes. */
19
+ export interface InterruptInput {
20
+ /** The audio track whose audio to drop. Default {@link AUDIO_TRACK}. */
21
+ track?: string;
22
+ /** Drop from this timestamp on. Absent: from the oldest audio a listener holds. */
23
+ fromUs?: number;
24
+ /** Drop before this timestamp: the end of the last audio sent. */
25
+ untilUs: number;
26
+ }
27
+ /** An interrupt object's payload: compact JSON, `{"track":…,"fromUs":…,"untilUs":…}`, without `fromUs` when absent. */
28
+ export declare function buildInterrupt(input: InterruptInput): Uint8Array;
29
+ /**
30
+ * Read an interrupt object's payload. Throws on a payload that is not a UTF-8 JSON object with a non-empty string
31
+ * `track` and a nonnegative safe-integer `untilUs`, or whose `fromUs`, when present, is not one before `untilUs`.
32
+ * Other fields are ignored.
33
+ */
34
+ export declare function parseInterrupt(payload: Uint8Array): Interrupt;
35
+ //# sourceMappingURL=interrupt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interrupt.d.ts","sourceRoot":"","sources":["../src/interrupt.ts"],"names":[],"mappings":"AAOA,iFAAiF;AACjF,eAAO,MAAM,eAAe,cAAc,CAAC;AAE3C;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,iEAAiE;IACjE,KAAK,EAAE,MAAM,CAAC;IACd,kHAAkH;IAClH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,yCAAyC;AACzC,MAAM,WAAW,cAAc;IAC7B,wEAAwE;IACxE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,mFAAmF;IACnF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kEAAkE;IAClE,OAAO,EAAE,MAAM,CAAC;CACjB;AAkBD,uHAAuH;AACvH,wBAAgB,cAAc,CAAC,KAAK,EAAE,cAAc,GAAG,UAAU,CAGhE;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,UAAU,GAAG,SAAS,CAK7D"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * The interrupt track: how a talker that stops mid-utterance tells its listeners to drop the audio they already hold.
3
+ * See spec/media-layer.md, "Interrupt track". Format only: the talker registers and writes the track, and a listener
4
+ * hands what it reads to the audio player's `cut`.
5
+ */
6
+ import { AUDIO_TRACK } from './loc.js';
7
+ /** The interrupt track's default name, listed in the catalog as a data track. */
8
+ export const INTERRUPT_TRACK = 'interrupt';
9
+ function timestamp(value, name) {
10
+ if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < 0)
11
+ throw new RangeError(`${name} must be a nonnegative safe integer`);
12
+ return value;
13
+ }
14
+ function checked(track, fromUs, untilUs) {
15
+ if (typeof track !== 'string' || track.length === 0)
16
+ throw new RangeError('track must be a non-empty string');
17
+ if (/[\uD800-\uDFFF]/u.test(track))
18
+ throw new RangeError('track must be valid Unicode');
19
+ const until = timestamp(untilUs, 'untilUs');
20
+ if (fromUs === undefined)
21
+ return { track, untilUs: until };
22
+ const from = timestamp(fromUs, 'fromUs');
23
+ if (from >= until)
24
+ throw new RangeError('fromUs must be before untilUs');
25
+ return { track, fromUs: from, untilUs: until };
26
+ }
27
+ /** An interrupt object's payload: compact JSON, `{"track":…,"fromUs":…,"untilUs":…}`, without `fromUs` when absent. */
28
+ export function buildInterrupt(input) {
29
+ const interrupt = checked(input.track === undefined ? AUDIO_TRACK : input.track, input.fromUs, input.untilUs);
30
+ return new TextEncoder().encode(JSON.stringify(interrupt));
31
+ }
32
+ /**
33
+ * Read an interrupt object's payload. Throws on a payload that is not a UTF-8 JSON object with a non-empty string
34
+ * `track` and a nonnegative safe-integer `untilUs`, or whose `fromUs`, when present, is not one before `untilUs`.
35
+ * Other fields are ignored.
36
+ */
37
+ export function parseInterrupt(payload) {
38
+ const raw = JSON.parse(new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(payload));
39
+ if (typeof raw !== 'object' || raw === null || Array.isArray(raw))
40
+ throw new Error('interrupt is not a JSON object');
41
+ const { track, fromUs, untilUs } = raw;
42
+ return checked(track, fromUs, untilUs);
43
+ }
44
+ //# sourceMappingURL=interrupt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interrupt.js","sourceRoot":"","sources":["../src/interrupt.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,iF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G,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC;AAC7D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,OAAmB;IAChD,MAAM,GAAG,GAAY,IAAI,CAAC,KAAK,CAAC,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IAC5G,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACrH,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAA8B,CAAC;IAClE,OAAO,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AACzC,CAAC"}
package/dist/loc.d.ts ADDED
@@ -0,0 +1,55 @@
1
+ /** LOC draft-04 property helpers, independent of transport and encoders. */
2
+ import type { KeyValuePair } from '@caprid/moq-core';
3
+ /** The LOC draft these helpers implement. */
4
+ export declare const LOC_DOCUMENT = "draft-ietf-moq-loc-04";
5
+ /** The MSF draft the catalog helpers implement. */
6
+ export declare const MSF_DOCUMENT = "draft-ietf-moq-msf-01";
7
+ /** LOC Timestamp object property type: the object's presentation time in timescale ticks. */
8
+ export declare const LOC_TIMESTAMP = 16;
9
+ /** LOC Timescale property type: ticks per second, on the track and on each object. */
10
+ export declare const LOC_TIMESCALE = 8;
11
+ /** LOC Video Config object property type: codec configuration bytes, such as an avcC record. */
12
+ export declare const LOC_VIDEO_CONFIG = 13;
13
+ /** LOC Audio Config object property type: codec configuration bytes, such as an AAC AudioSpecificConfig. */
14
+ export declare const LOC_AUDIO_CONFIG = 15;
15
+ /** The default timescale: microsecond ticks, matching WebCodecs timestamps. */
16
+ export declare const MICROSECONDS_PER_SECOND = 1000000;
17
+ /** Default track name for the MSF catalog. */
18
+ export declare const CATALOG_TRACK = "catalog";
19
+ /** Default track name for the catalog's video track. */
20
+ export declare const VIDEO_TRACK = "video";
21
+ /** Default track name for the catalog's audio track. */
22
+ export declare const AUDIO_TRACK = "audio";
23
+ /** Default track name for the catalog's Media Timeline track (msf-01 §7). */
24
+ export declare const MEDIA_TIMELINE_TRACK = "timeline";
25
+ /**
26
+ * Track properties declaring a LOC timescale, for `registerTrack`'s `trackProperties`. The timescale must be a
27
+ * positive safe integer; the default is microseconds.
28
+ */
29
+ export declare function locTrackProperties(timescale?: number): KeyValuePair[];
30
+ /** Options for {@link locProperties}. */
31
+ export interface LocPropertiesOptions {
32
+ /** Ticks per second for the emitted Timestamp; a positive safe integer. Default {@link MICROSECONDS_PER_SECOND}. */
33
+ timescale?: number;
34
+ /** Supply decoder configuration on keyframes only. */
35
+ videoConfig?: Uint8Array;
36
+ /** Audio decoder configuration, emitted as Audio Config. Supply it on keyframes only. */
37
+ audioConfig?: Uint8Array;
38
+ }
39
+ /** Convert microseconds to ticks, rounding ties upward, and attach LOC properties. */
40
+ export declare function locProperties(timestampUs: number, options?: LocPropertiesOptions): KeyValuePair[];
41
+ /**
42
+ * Options for {@link locTimestampUs}: where else the track's timescale may be declared. The MSF catalog's `timescale`
43
+ * (msf-01 §5.2.21) is not one of them: MSF never ties it to the LOC Timestamp.
44
+ */
45
+ export interface LocTimestampOptions {
46
+ /** The track's properties, as `SUBSCRIBE_OK` carries them (`subscription.subscribed`'s `trackProperties`). */
47
+ trackProperties?: readonly KeyValuePair[];
48
+ }
49
+ /**
50
+ * An object's LOC Timestamp in microseconds, or `undefined` when it has none. Scales by the first usable Timescale on
51
+ * the object, then in the track properties, rounding ties upward. With none, the Timestamp is
52
+ * already microseconds: LOC's wall-clock time since the Unix epoch.
53
+ */
54
+ export declare function locTimestampUs(properties: readonly KeyValuePair[], options?: LocTimestampOptions): number | undefined;
55
+ //# sourceMappingURL=loc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loc.d.ts","sourceRoot":"","sources":["../src/loc.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD,6CAA6C;AAC7C,eAAO,MAAM,YAAY,0BAA0B,CAAC;AACpD,mDAAmD;AACnD,eAAO,MAAM,YAAY,0BAA0B,CAAC;AACpD,6FAA6F;AAC7F,eAAO,MAAM,aAAa,KAAO,CAAC;AAClC,sFAAsF;AACtF,eAAO,MAAM,aAAa,IAAO,CAAC;AAClC,gGAAgG;AAChG,eAAO,MAAM,gBAAgB,KAAO,CAAC;AACrC,4GAA4G;AAC5G,eAAO,MAAM,gBAAgB,KAAO,CAAC;AACrC,+EAA+E;AAC/E,eAAO,MAAM,uBAAuB,UAAY,CAAC;AACjD,8CAA8C;AAC9C,eAAO,MAAM,aAAa,YAAY,CAAC;AACvC,wDAAwD;AACxD,eAAO,MAAM,WAAW,UAAU,CAAC;AACnC,wDAAwD;AACxD,eAAO,MAAM,WAAW,UAAU,CAAC;AACnC,6EAA6E;AAC7E,eAAO,MAAM,oBAAoB,aAAa,CAAC;AAQ/C;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,SAA0B,GAAG,YAAY,EAAE,CAGtF;AAED,yCAAyC;AACzC,MAAM,WAAW,oBAAoB;IACnC,oHAAoH;IACpH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sDAAsD;IACtD,WAAW,CAAC,EAAE,UAAU,CAAC;IACzB,yFAAyF;IACzF,WAAW,CAAC,EAAE,UAAU,CAAC;CAC1B;AAED,sFAAsF;AACtF,wBAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB,GAAG,YAAY,EAAE,CAgBrG;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,8GAA8G;IAC9G,eAAe,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;CAC3C;AAYD;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,UAAU,EAAE,SAAS,YAAY,EAAE,EACnC,OAAO,GAAE,mBAAwB,GAChC,MAAM,GAAG,SAAS,CAOpB"}
package/dist/loc.js ADDED
@@ -0,0 +1,74 @@
1
+ /** The LOC draft these helpers implement. */
2
+ export const LOC_DOCUMENT = 'draft-ietf-moq-loc-04';
3
+ /** The MSF draft the catalog helpers implement. */
4
+ export const MSF_DOCUMENT = 'draft-ietf-moq-msf-01';
5
+ /** LOC Timestamp object property type: the object's presentation time in timescale ticks. */
6
+ export const LOC_TIMESTAMP = 0x10;
7
+ /** LOC Timescale property type: ticks per second, on the track and on each object. */
8
+ export const LOC_TIMESCALE = 0x08;
9
+ /** LOC Video Config object property type: codec configuration bytes, such as an avcC record. */
10
+ export const LOC_VIDEO_CONFIG = 0x0d;
11
+ /** LOC Audio Config object property type: codec configuration bytes, such as an AAC AudioSpecificConfig. */
12
+ export const LOC_AUDIO_CONFIG = 0x0f;
13
+ /** The default timescale: microsecond ticks, matching WebCodecs timestamps. */
14
+ export const MICROSECONDS_PER_SECOND = 1_000_000;
15
+ /** Default track name for the MSF catalog. */
16
+ export const CATALOG_TRACK = 'catalog';
17
+ /** Default track name for the catalog's video track. */
18
+ export const VIDEO_TRACK = 'video';
19
+ /** Default track name for the catalog's audio track. */
20
+ export const AUDIO_TRACK = 'audio';
21
+ /** Default track name for the catalog's Media Timeline track (msf-01 §7). */
22
+ export const MEDIA_TIMELINE_TRACK = 'timeline';
23
+ function integer(value, name, positive = false) {
24
+ if (!Number.isSafeInteger(value) || value < (positive ? 1 : 0)) {
25
+ throw new RangeError(`${name} must be a ${positive ? 'positive' : 'nonnegative'} safe integer`);
26
+ }
27
+ }
28
+ /**
29
+ * Track properties declaring a LOC timescale, for `registerTrack`'s `trackProperties`. The timescale must be a
30
+ * positive safe integer; the default is microseconds.
31
+ */
32
+ export function locTrackProperties(timescale = MICROSECONDS_PER_SECOND) {
33
+ integer(timescale, 'timescale', true);
34
+ return [{ type: LOC_TIMESCALE, value: timescale }];
35
+ }
36
+ /** Convert microseconds to ticks, rounding ties upward, and attach LOC properties. */
37
+ export function locProperties(timestampUs, options = {}) {
38
+ const timescale = options.timescale ?? MICROSECONDS_PER_SECOND;
39
+ integer(timestampUs, 'timestampUs');
40
+ integer(timescale, 'timescale', true);
41
+ // Intermediate products can exceed Number.MAX_SAFE_INTEGER even when the result does not.
42
+ const timestamp = Number((BigInt(timestampUs) * BigInt(timescale) + 500000n) / 1000000n);
43
+ integer(timestamp, 'timestamp');
44
+ const properties = [
45
+ { type: LOC_TIMESTAMP, value: timestamp },
46
+ { type: LOC_TIMESCALE, value: timescale },
47
+ ];
48
+ if (options.videoConfig !== undefined)
49
+ properties.push({ type: LOC_VIDEO_CONFIG, value: options.videoConfig.slice() });
50
+ if (options.audioConfig !== undefined)
51
+ properties.push({ type: LOC_AUDIO_CONFIG, value: options.audioConfig.slice() });
52
+ return properties;
53
+ }
54
+ const usableTimescale = (value) => typeof value === 'number' && Number.isSafeInteger(value) && value > 0;
55
+ function timescaleOf(properties) {
56
+ const value = properties?.find((property) => property.type === LOC_TIMESCALE && usableTimescale(property.value))?.value;
57
+ return value;
58
+ }
59
+ /**
60
+ * An object's LOC Timestamp in microseconds, or `undefined` when it has none. Scales by the first usable Timescale on
61
+ * the object, then in the track properties, rounding ties upward. With none, the Timestamp is
62
+ * already microseconds: LOC's wall-clock time since the Unix epoch.
63
+ */
64
+ export function locTimestampUs(properties, options = {}) {
65
+ const value = properties.find((property) => property.type === LOC_TIMESTAMP)?.value;
66
+ if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < 0)
67
+ return undefined;
68
+ const timescale = timescaleOf(properties) ?? timescaleOf(options.trackProperties);
69
+ if (timescale === undefined || timescale === MICROSECONDS_PER_SECOND)
70
+ return value;
71
+ const scaled = Number((BigInt(value) * 2000000n + BigInt(timescale)) / (2n * BigInt(timescale)));
72
+ return Number.isSafeInteger(scaled) ? scaled : undefined;
73
+ }
74
+ //# sourceMappingURL=loc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loc.js","sourceRoot":"","sources":["../src/loc.ts"],"names":[],"mappings":"AAGA,6CAA6C;AAC7C,MAAM,CAAC,MAAM,YAAY,GAAG,uBAAuB,CAAC;AACpD,mDAAmD;AACnD,MAAM,CAAC,MAAM,YAAY,GAAG,uBAAuB,CAAC;AACpD,6FAA6F;AAC7F,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAC;AAClC,sFAAsF;AACtF,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAC;AAClC,gGAAgG;AAChG,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC;AACrC,4GAA4G;AAC5G,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC;AACrC,+EAA+E;AAC/E,MAAM,CAAC,MAAM,uBAAuB,GAAG,SAAS,CAAC;AACjD,8CAA8C;AAC9C,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC;AACvC,wDAAwD;AACxD,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC;AACnC,wDAAwD;AACxD,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC;AACnC,6EAA6E;AAC7E,MAAM,CAAC,MAAM,oBAAoB,GAAG,UAAU,CAAC;AAE/C,SAAS,OAAO,CAAC,KAAa,EAAE,IAAY,EAAE,QAAQ,GAAG,KAAK;IAC5D,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/D,MAAM,IAAI,UAAU,CAAC,GAAG,IAAI,cAAc,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,aAAa,eAAe,CAAC,CAAC;IAClG,CAAC;AACH,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