@caprid/moq-media 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/NOTICE +6 -0
- package/README.md +187 -2
- package/UPSTREAM.json +19 -0
- package/dist/audio-player.d.ts +206 -0
- package/dist/audio-player.d.ts.map +1 -0
- package/dist/audio-player.js +480 -0
- package/dist/audio-player.js.map +1 -0
- package/dist/audio-worklet.d.ts +64 -0
- package/dist/audio-worklet.d.ts.map +1 -0
- package/dist/audio-worklet.js +355 -0
- package/dist/audio-worklet.js.map +1 -0
- package/dist/catalog.d.ts +141 -0
- package/dist/catalog.d.ts.map +1 -0
- package/dist/catalog.js +174 -0
- package/dist/catalog.js.map +1 -0
- package/dist/clock.d.ts +178 -0
- package/dist/clock.d.ts.map +1 -0
- package/dist/clock.js +190 -0
- package/dist/clock.js.map +1 -0
- package/dist/echo-loopback.d.ts +38 -0
- package/dist/echo-loopback.d.ts.map +1 -0
- package/dist/echo-loopback.js +100 -0
- package/dist/echo-loopback.js.map +1 -0
- package/dist/h264.d.ts +4 -0
- package/dist/h264.d.ts.map +1 -0
- package/dist/h264.js +8 -0
- package/dist/h264.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/interrupt.d.ts +35 -0
- package/dist/interrupt.d.ts.map +1 -0
- package/dist/interrupt.js +44 -0
- package/dist/interrupt.js.map +1 -0
- package/dist/loc.d.ts +55 -0
- package/dist/loc.d.ts.map +1 -0
- package/dist/loc.js +74 -0
- package/dist/loc.js.map +1 -0
- package/dist/parse-catalog.d.ts +81 -0
- package/dist/parse-catalog.d.ts.map +1 -0
- package/dist/parse-catalog.js +134 -0
- package/dist/parse-catalog.js.map +1 -0
- package/dist/render-clock.d.ts +38 -0
- package/dist/render-clock.d.ts.map +1 -0
- package/dist/render-clock.js +40 -0
- package/dist/render-clock.js.map +1 -0
- package/dist/sequencer.d.ts +130 -0
- package/dist/sequencer.d.ts.map +1 -0
- package/dist/sequencer.js +599 -0
- package/dist/sequencer.js.map +1 -0
- package/dist/source.d.ts +21 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +54 -0
- package/dist/source.js.map +1 -0
- package/dist/timeline.d.ts +69 -0
- package/dist/timeline.d.ts.map +1 -0
- package/dist/timeline.js +83 -0
- package/dist/timeline.js.map +1 -0
- package/dist/transcript.d.ts +84 -0
- package/dist/transcript.d.ts.map +1 -0
- package/dist/transcript.js +151 -0
- package/dist/transcript.js.map +1 -0
- package/dist/webcodecs.d.ts +32 -0
- package/dist/webcodecs.d.ts.map +1 -0
- package/dist/webcodecs.js +79 -0
- package/dist/webcodecs.js.map +1 -0
- package/package.json +34 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../src/source.ts"],"names":[],"mappings":"AAIA,yEAAyE;AACzE,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAWzD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAE3F;AAED,4CAA4C;AAC5C,MAAM,WAAW,uBAAuB;IACtC,iEAAiE;IACjE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oGAAoG;IACpG,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AACD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,MAAM,EAAE,EAC5B,OAAO,GAAE,uBAA4B,GACpC,MAAM,CAsBR"}
|
package/dist/source.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** MSF source composition, adapted from Video.js parse-source.ts. */
|
|
2
|
+
import { CATALOG_TRACK } from './loc.js';
|
|
3
|
+
const LITERAL_CHAR = /^[a-zA-Z0-9_]$/;
|
|
4
|
+
/** Encode one namespace field or track name into the MSF string form. */
|
|
5
|
+
export function encodeNameComponent(value) {
|
|
6
|
+
if (/[\uD800-\uDFFF]/u.test(value))
|
|
7
|
+
throw new Error('name components must be valid Unicode');
|
|
8
|
+
let out = '';
|
|
9
|
+
for (const byte of new TextEncoder().encode(value)) {
|
|
10
|
+
const char = String.fromCharCode(byte);
|
|
11
|
+
out += LITERAL_CHAR.test(char) ? char : `.${byte.toString(16).padStart(2, '0')}`;
|
|
12
|
+
}
|
|
13
|
+
return out;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The MSF string form of a full track name: each namespace field encoded with {@link encodeNameComponent} and joined
|
|
17
|
+
* with `-`, then `--` and the encoded track name.
|
|
18
|
+
*/
|
|
19
|
+
export function encodeNamespaceName(namespace, trackName) {
|
|
20
|
+
return `${namespace.map(encodeNameComponent).join('-')}--${encodeNameComponent(trackName)}`;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Compose the `moqt://` source URL a MoQ player takes: the relay URL with its scheme switched to `moqt:` (authority,
|
|
24
|
+
* path and query kept), and a `#msf:` fragment naming the namespace and track. The relay URL must be an absolute
|
|
25
|
+
* `https://` or `moqt://` URL with no credentials or fragment; namespace fields must be non-empty.
|
|
26
|
+
*/
|
|
27
|
+
export function composeMoqSource(origin, namespace, options = {}) {
|
|
28
|
+
const authority = /^(https|moqt):\/\/([^/?#]+)/i.exec(origin)?.[2];
|
|
29
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: Reject invalid URL whitespace and controls before parsing.
|
|
30
|
+
if (!authority || /[\u0000-\u0020\u007f\\]/.test(origin))
|
|
31
|
+
throw new Error('relay URL must be an absolute https:// or moqt:// URL');
|
|
32
|
+
if (authority.includes('@'))
|
|
33
|
+
throw new Error('relay URL must not carry credentials');
|
|
34
|
+
if (origin.includes('#'))
|
|
35
|
+
throw new Error('relay URL must not carry a fragment');
|
|
36
|
+
const parsed = new URL(origin);
|
|
37
|
+
if (!parsed.hostname || parsed.username || parsed.password)
|
|
38
|
+
throw new Error('relay URL must have a host and no credentials');
|
|
39
|
+
if (namespace.length === 0 || namespace.includes(''))
|
|
40
|
+
throw new Error('namespace fields must be non-empty');
|
|
41
|
+
const trackName = options.trackName ?? CATALOG_TRACK;
|
|
42
|
+
if (!trackName)
|
|
43
|
+
throw new Error('track name is empty');
|
|
44
|
+
// Preserve the supplied authority, path and query, just as Python's urlsplit does.
|
|
45
|
+
const base = origin
|
|
46
|
+
.replace(/^(https|moqt):/i, 'moqt:')
|
|
47
|
+
.replace(/^([^?]*)\?$/, '$1')
|
|
48
|
+
.replace(/^(moqt:\/\/[^/?]+)(?=\?|$)/, '$1/');
|
|
49
|
+
const token = options.token
|
|
50
|
+
? `&c4m=${encodeURIComponent(options.token).replace(/[!'()*]/g, (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`)}`
|
|
51
|
+
: '';
|
|
52
|
+
return `${base}#msf:${encodeNamespaceName(namespace, trackName)}${token}`;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.js","sourceRoot":"","sources":["../src/source.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,YAAY,GAAG,gBAAgB,CAAC;AACtC,yEAAyE;AACzE,MAAM,UAAU,mBAAmB,CAAC,KAAa;IAC/C,IAAI,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAC7F,IAAI,GAAG,GAAG,EAAE,CAAC;IAEb,KAAK,MAAM,IAAI,IAAI,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACnD,MAAM,IAAI,GAAG,MAAM,CAAC,YAAY,CAAC,IAAI,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AC,QAAQ,CAAC,EAAE,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IAC5G,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,aAAa,CAAC;IACrD,IAAI,CAAC,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACvD,mFAAmF;IACnF,MAAM,IAAI,GAAG,MAAM;SAChB,OAAO,CAAC,iBAAiB,EAAE,OAAO,CAAC;SACnC,OAAO,CAAC,aAAa,EAAE,IAAI,CAAC;SAC5B,OAAO,CAAC,4BAA4B,EAAE,KAAK,CAAC,CAAC;IAChD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK;QACzB,CAAC,CAAC,QAAQ,kBAAkB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,EAAE;QAChI,CAAC,CAAC,EAAE,CAAC;IACP,OAAO,GAAG,IAAI,QAAQ,mBAAmB,CAAC,SAAS,EAAE,SAAS,CAAC,GAAG,KAAK,EAAE,CAAC;AAC5E,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The MSF Media Timeline track (msf-01 §7): records that map media time and a location to wall-clock time. See
|
|
3
|
+
* spec/media-layer.md, "Media Timeline track". Format only: the publisher decides which groups get an entry and when
|
|
4
|
+
* to send a document. {@link createMediaTimeline} holds the retained entries of one broadcast and builds the independent
|
|
5
|
+
* document each new timeline group carries.
|
|
6
|
+
*/
|
|
7
|
+
/** One media timeline record, `[mediaTimeMs, [group, object], wallclockMs]` on the wire (msf-01 §7.1.1). */
|
|
8
|
+
export interface MediaTimelineEntry {
|
|
9
|
+
/** Media time of the first sample in the referenced object, floored to whole milliseconds. */
|
|
10
|
+
mediaTimeMs: number;
|
|
11
|
+
/** Group ID of the referenced object, in the track the timeline indexes. */
|
|
12
|
+
group: number;
|
|
13
|
+
/** Object ID of the referenced object. */
|
|
14
|
+
object: number;
|
|
15
|
+
/** Milliseconds since the Unix epoch when that media was captured; 0 when unknown. */
|
|
16
|
+
wallclockMs: number;
|
|
17
|
+
}
|
|
18
|
+
/** What {@link mediaTimelineEntry} needs to know about one object. */
|
|
19
|
+
export interface MediaTimelineEntryInput {
|
|
20
|
+
/** The object's LOC timestamp, in integer microseconds. */
|
|
21
|
+
timestampUs: number;
|
|
22
|
+
/** The object's group ID. */
|
|
23
|
+
group: number;
|
|
24
|
+
/** The object's ID. Default 0, the group's first object. */
|
|
25
|
+
object?: number;
|
|
26
|
+
/**
|
|
27
|
+
* When that media was captured, in integer Unix-epoch microseconds. Defaults to `timestampUs`, which on the
|
|
28
|
+
* broadcast clock's timeline is that time; 0 means unknown, as msf-01 allows.
|
|
29
|
+
*/
|
|
30
|
+
wallclockUs?: number;
|
|
31
|
+
}
|
|
32
|
+
/** The record for one object of the indexed track. */
|
|
33
|
+
export declare function mediaTimelineEntry(input: MediaTimelineEntryInput): MediaTimelineEntry;
|
|
34
|
+
/**
|
|
35
|
+
* A timeline object's payload: the records in the order given, as compact JSON. The same form serves an independent
|
|
36
|
+
* document (every retained record) and an incremental one (only new ones).
|
|
37
|
+
*/
|
|
38
|
+
export declare function buildMediaTimeline(entries: readonly MediaTimelineEntry[]): Uint8Array;
|
|
39
|
+
/** Options for {@link createMediaTimeline}. */
|
|
40
|
+
export interface MediaTimelineOptions {
|
|
41
|
+
/** How many entries the document keeps; past it, the oldest is dropped. Default 512, about 18 KB. */
|
|
42
|
+
maxEntries?: number;
|
|
43
|
+
}
|
|
44
|
+
/** The retained entries of one broadcast's media timeline, and the independent document they make. */
|
|
45
|
+
export interface MediaTimeline {
|
|
46
|
+
/** The retained entries, oldest first. */
|
|
47
|
+
readonly entries: readonly MediaTimelineEntry[];
|
|
48
|
+
/** The independent document of the retained entries; `[]` before the first. */
|
|
49
|
+
readonly document: Uint8Array;
|
|
50
|
+
/**
|
|
51
|
+
* Record one object, once per group of the indexed track for its first object, when that object was sent; return
|
|
52
|
+
* the document. A rejected argument throws and leaves the timeline unchanged.
|
|
53
|
+
*/
|
|
54
|
+
add(input: MediaTimelineEntryInput): Uint8Array;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Hold one broadcast's media timeline entries, bounded by `maxEntries`. A supervised publisher's next generation is a
|
|
58
|
+
* new broadcast and starts a new timeline.
|
|
59
|
+
*/
|
|
60
|
+
export declare function createMediaTimeline(options?: MediaTimelineOptions): MediaTimeline;
|
|
61
|
+
/**
|
|
62
|
+
* Read a timeline object's payload into its records, in document order.
|
|
63
|
+
*
|
|
64
|
+
* Throws on a payload that is not a UTF-8 JSON array. Records that do not read as a nonnegative safe-integer
|
|
65
|
+
* `[number, [number, number], number]` are skipped, a §7.4 template among them; extra items are ignored.
|
|
66
|
+
* MSF_COMPRESSION payloads are not decompressed.
|
|
67
|
+
*/
|
|
68
|
+
export declare function parseMediaTimeline(payload: Uint8Array): MediaTimelineEntry[];
|
|
69
|
+
//# sourceMappingURL=timeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeline.d.ts","sourceRoot":"","sources":["../src/timeline.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,4GAA4G;AAC5G,MAAM,WAAW,kBAAkB;IACjC,8FAA8F;IAC9F,WAAW,EAAE,MAAM,CAAC;IACpB,4EAA4E;IAC5E,KAAK,EAAE,MAAM,CAAC;IACd,0CAA0C;IAC1C,MAAM,EAAE,MAAM,CAAC;IACf,sFAAsF;IACtF,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,sEAAsE;AACtE,MAAM,WAAW,uBAAuB;IACtC,2DAA2D;IAC3D,WAAW,EAAE,MAAM,CAAC;IACpB,6BAA6B;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,4DAA4D;IAC5D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAOD,sDAAsD;AACtD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,uBAAuB,GAAG,kBAAkB,CAQrF;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,SAAS,kBAAkB,EAAE,GAAG,UAAU,CAOrF;AAED,+CAA+C;AAC/C,MAAM,WAAW,oBAAoB;IACnC,qGAAqG;IACrG,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,sGAAsG;AACtG,MAAM,WAAW,aAAa;IAC5B,0CAA0C;IAC1C,QAAQ,CAAC,OAAO,EAAE,SAAS,kBAAkB,EAAE,CAAC;IAChD,+EAA+E;IAC/E,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;IAC9B;;;OAGG;IACH,GAAG,CAAC,KAAK,EAAE,uBAAuB,GAAG,UAAU,CAAC;CACjD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,oBAAyB,GAAG,aAAa,CAiBrF;AAeD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,UAAU,GAAG,kBAAkB,EAAE,CAI5E"}
|
package/dist/timeline.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The MSF Media Timeline track (msf-01 §7): records that map media time and a location to wall-clock time. See
|
|
3
|
+
* spec/media-layer.md, "Media Timeline track". Format only: the publisher decides which groups get an entry and when
|
|
4
|
+
* to send a document. {@link createMediaTimeline} holds the retained entries of one broadcast and builds the independent
|
|
5
|
+
* document each new timeline group carries.
|
|
6
|
+
*/
|
|
7
|
+
function whole(value, name) {
|
|
8
|
+
if (!Number.isSafeInteger(value) || value < 0)
|
|
9
|
+
throw new RangeError(`${name} must be a nonnegative safe integer`);
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
/** The record for one object of the indexed track. */
|
|
13
|
+
export function mediaTimelineEntry(input) {
|
|
14
|
+
const timestampUs = whole(input.timestampUs, 'timestampUs');
|
|
15
|
+
return {
|
|
16
|
+
mediaTimeMs: Math.floor(timestampUs / 1000),
|
|
17
|
+
group: whole(input.group, 'group'),
|
|
18
|
+
object: whole(input.object ?? 0, 'object'),
|
|
19
|
+
wallclockMs: Math.floor(whole(input.wallclockUs ?? timestampUs, 'wallclockUs') / 1000),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A timeline object's payload: the records in the order given, as compact JSON. The same form serves an independent
|
|
24
|
+
* document (every retained record) and an incremental one (only new ones).
|
|
25
|
+
*/
|
|
26
|
+
export function buildMediaTimeline(entries) {
|
|
27
|
+
const records = entries.map((entry) => [
|
|
28
|
+
whole(entry.mediaTimeMs, 'mediaTimeMs'),
|
|
29
|
+
[whole(entry.group, 'group'), whole(entry.object, 'object')],
|
|
30
|
+
whole(entry.wallclockMs, 'wallclockMs'),
|
|
31
|
+
]);
|
|
32
|
+
return new TextEncoder().encode(JSON.stringify(records));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Hold one broadcast's media timeline entries, bounded by `maxEntries`. A supervised publisher's next generation is a
|
|
36
|
+
* new broadcast and starts a new timeline.
|
|
37
|
+
*/
|
|
38
|
+
export function createMediaTimeline(options = {}) {
|
|
39
|
+
const { maxEntries = 512 } = options;
|
|
40
|
+
if (whole(maxEntries, 'maxEntries') < 1)
|
|
41
|
+
throw new RangeError('maxEntries must be a positive safe integer');
|
|
42
|
+
const entries = [];
|
|
43
|
+
return {
|
|
44
|
+
get entries() {
|
|
45
|
+
return entries.slice();
|
|
46
|
+
},
|
|
47
|
+
get document() {
|
|
48
|
+
return buildMediaTimeline(entries);
|
|
49
|
+
},
|
|
50
|
+
add(input) {
|
|
51
|
+
entries.push(mediaTimelineEntry(input));
|
|
52
|
+
if (entries.length > maxEntries)
|
|
53
|
+
entries.shift();
|
|
54
|
+
return buildMediaTimeline(entries);
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const count = (value) => Number.isSafeInteger(value) && value >= 0 ? value : undefined;
|
|
59
|
+
function parseRecord(record) {
|
|
60
|
+
if (!Array.isArray(record) || record.length < 3 || !Array.isArray(record[1]) || record[1].length < 2)
|
|
61
|
+
return;
|
|
62
|
+
const mediaTimeMs = count(record[0]);
|
|
63
|
+
const group = count(record[1][0]);
|
|
64
|
+
const object = count(record[1][1]);
|
|
65
|
+
const wallclockMs = count(record[2]);
|
|
66
|
+
if (mediaTimeMs === undefined || group === undefined || object === undefined || wallclockMs === undefined)
|
|
67
|
+
return;
|
|
68
|
+
return { mediaTimeMs, group, object, wallclockMs };
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Read a timeline object's payload into its records, in document order.
|
|
72
|
+
*
|
|
73
|
+
* Throws on a payload that is not a UTF-8 JSON array. Records that do not read as a nonnegative safe-integer
|
|
74
|
+
* `[number, [number, number], number]` are skipped, a §7.4 template among them; extra items are ignored.
|
|
75
|
+
* MSF_COMPRESSION payloads are not decompressed.
|
|
76
|
+
*/
|
|
77
|
+
export function parseMediaTimeline(payload) {
|
|
78
|
+
const raw = JSON.parse(new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(payload));
|
|
79
|
+
if (!Array.isArray(raw))
|
|
80
|
+
throw new Error('media timeline is not a JSON array');
|
|
81
|
+
return raw.map(parseRecord).filter((entry) => entry !== undefined);
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=timeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeline.js","sourceRoot":"","sources":["../src/timeline.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA6BH,SAAS,KAAK,CAAC,KAAa,EAAE,IAAY;IACxC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC;QA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K,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IACrC,IAAI,WAAW,KAAK,SAAS,IAAI,KAAK,KAAK,SAAS,IAAI,MAAM,KAAK,SAAS,IAAI,WAAW,KAAK,SAAS;QAAE,OAAO;IAClH,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;AACrD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAmB;IACpD,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,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IAC/E,OAAO,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAA+B,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC;AAClG,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/** The transcript track's default name, listed in the catalog as a data track. */
|
|
2
|
+
export declare const TRANSCRIPT_TRACK = "transcript";
|
|
3
|
+
/** One version of a transcript segment: the text of the named audio track's audio from `fromUs` on. */
|
|
4
|
+
export interface TranscriptSegment {
|
|
5
|
+
/** The segment's number; a later version of the same segment repeats it. */
|
|
6
|
+
seq: number;
|
|
7
|
+
/** The audio track in the same namespace whose audio this is the text of. */
|
|
8
|
+
track: string;
|
|
9
|
+
/** Where the segment's audio starts, in microseconds on the broadcast timeline. */
|
|
10
|
+
fromUs: number;
|
|
11
|
+
/** Where it ends. Absent while the talker does not know yet; a final segment has it. */
|
|
12
|
+
untilUs?: number;
|
|
13
|
+
/** The text, which a later version replaces whole. */
|
|
14
|
+
text: string;
|
|
15
|
+
/** No later version follows. */
|
|
16
|
+
final: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** What {@link buildTranscriptSegment} takes. */
|
|
19
|
+
export interface TranscriptSegmentInput {
|
|
20
|
+
/** The segment's number, repeated by each of its versions. */
|
|
21
|
+
seq: number;
|
|
22
|
+
/** The audio track this is the text of. Default {@link AUDIO_TRACK}. */
|
|
23
|
+
track?: string;
|
|
24
|
+
/** Where the segment's audio starts. */
|
|
25
|
+
fromUs: number;
|
|
26
|
+
/** Where it ends, if known; required when `final`. */
|
|
27
|
+
untilUs?: number;
|
|
28
|
+
/** The text so far. */
|
|
29
|
+
text: string;
|
|
30
|
+
/** No later version follows. Default `false`. */
|
|
31
|
+
final?: boolean;
|
|
32
|
+
}
|
|
33
|
+
/** A segment as a {@link Transcript} holds it: its latest version, and whether an interrupt cut it short. */
|
|
34
|
+
export interface TranscriptLine extends TranscriptSegment {
|
|
35
|
+
/** An interrupt cut the segment's audio short at `untilUs`: the listener heard only the start of the text. */
|
|
36
|
+
cut: boolean;
|
|
37
|
+
}
|
|
38
|
+
/** The range an interrupt cuts, which a parsed `Interrupt` is. */
|
|
39
|
+
export interface TranscriptCutRange {
|
|
40
|
+
/** Cut from this timestamp on. Absent: from the start of the timeline. */
|
|
41
|
+
fromUs?: number;
|
|
42
|
+
/** Cut before this timestamp. */
|
|
43
|
+
untilUs: number;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* What a listener has read of one audio track's transcript: each segment's latest version, less what was cut.
|
|
47
|
+
* `apply` each segment read for the track and `cut` on each interrupt for it; `linesAt` gives what to show as the
|
|
48
|
+
* audio plays. A segment's final version is kept against later ones. Cuts are remembered, so a version that arrives
|
|
49
|
+
* after one is clipped as if it had arrived before. A segment is known by its `seq` within one run of the talker's
|
|
50
|
+
* track, so create a new transcript when the talker starts over.
|
|
51
|
+
*/
|
|
52
|
+
export interface Transcript {
|
|
53
|
+
/**
|
|
54
|
+
* Keep a segment's version, clipped by the cuts so far; `false` if it changed nothing. Ignored: a version of a
|
|
55
|
+
* segment the talker already sent final, a segment that starts inside a range cut earlier (as audio arriving there
|
|
56
|
+
* late is), and an interim version of a segment a cut ended. A cut segment takes the talker's final version,
|
|
57
|
+
* clipped: one whose audio ended before the cut is no longer cut.
|
|
58
|
+
*/
|
|
59
|
+
apply(segment: TranscriptSegment): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Apply an interrupt's range, with the playout position now (`PlayoutClock.position()`). Audio before the position
|
|
62
|
+
* has been heard, so the cut starts at the later of `fromUs` and the position. It drops the segments that start in
|
|
63
|
+
* the cut, and ends the one playing there at its start, final and cut.
|
|
64
|
+
*/
|
|
65
|
+
cut(range: TranscriptCutRange, positionUs?: number): void;
|
|
66
|
+
/** Every segment held, in timeline order. */
|
|
67
|
+
readonly lines: TranscriptLine[];
|
|
68
|
+
/** The segments whose audio has started playing at this position, in timeline order; none while idle. */
|
|
69
|
+
linesAt(positionUs: number | undefined): TranscriptLine[];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* A transcript object's payload: compact JSON, `{"seq":…,"track":…,"fromUs":…,"untilUs":…,"text":…,"final":…}`,
|
|
73
|
+
* without `untilUs` when absent.
|
|
74
|
+
*/
|
|
75
|
+
export declare function buildTranscriptSegment(input: TranscriptSegmentInput): Uint8Array;
|
|
76
|
+
/**
|
|
77
|
+
* Read a transcript object's payload. Throws on a payload that is not a UTF-8 JSON object with a nonnegative
|
|
78
|
+
* safe-integer `seq` and `fromUs`, a non-empty string `track`, a string `text` and a boolean `final`, or whose
|
|
79
|
+
* `untilUs`, when present, is not one after `fromUs`, or that is final without `untilUs`. Other fields are ignored.
|
|
80
|
+
*/
|
|
81
|
+
export declare function parseTranscriptSegment(payload: Uint8Array): TranscriptSegment;
|
|
82
|
+
/** Create an empty {@link Transcript}. */
|
|
83
|
+
export declare function createTranscript(): Transcript;
|
|
84
|
+
//# sourceMappingURL=transcript.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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C;IAC1D,6CAA6C;IAC7C,QAAQ,CAAC,KAAK,EAAE,cAAc,EAAE,CAAC;IACjC,yGAAyG;IACzG,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,cAAc,EAAE,CAAC;CAC3D;AA0BD;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,sBAAsB,GAAG,UAAU,CAOhF;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,UAAU,GAAG,iBAAiB,CAQ7E;AAED,0CAA0C;AAC1C,wBAAgB,gBAAgB,IAAI,UAAU,CA4E7C"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The transcript track: the text of a talker's audio, in segments placed on its timeline. See spec/media-layer.md,
|
|
3
|
+
* "Transcript track". Format only: the talker registers and writes the track, and a listener keeps what it reads in a
|
|
4
|
+
* {@link Transcript}, which drops what an interrupt cuts.
|
|
5
|
+
*/
|
|
6
|
+
import { AUDIO_TRACK } from './loc.js';
|
|
7
|
+
/** The transcript track's default name, listed in the catalog as a data track. */
|
|
8
|
+
export const TRANSCRIPT_TRACK = 'transcript';
|
|
9
|
+
function integer(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(raw) {
|
|
15
|
+
const { seq: rawSeq, track, fromUs: rawFrom, untilUs: rawUntil, text, final } = raw;
|
|
16
|
+
const seq = integer(rawSeq, 'seq');
|
|
17
|
+
if (typeof track !== 'string' || track.length === 0)
|
|
18
|
+
throw new RangeError('track must be a non-empty string');
|
|
19
|
+
if (typeof text !== 'string')
|
|
20
|
+
throw new RangeError('text must be a string');
|
|
21
|
+
if (/[\uD800-\uDFFF]/u.test(track))
|
|
22
|
+
throw new RangeError('track must be valid Unicode');
|
|
23
|
+
if (/[\uD800-\uDFFF]/u.test(text))
|
|
24
|
+
throw new RangeError('text must be valid Unicode');
|
|
25
|
+
if (typeof final !== 'boolean')
|
|
26
|
+
throw new RangeError('final must be a boolean');
|
|
27
|
+
const fromUs = integer(rawFrom, 'fromUs');
|
|
28
|
+
if (rawUntil === undefined) {
|
|
29
|
+
if (final)
|
|
30
|
+
throw new RangeError('a final segment needs untilUs');
|
|
31
|
+
return { seq, track, fromUs, text, final };
|
|
32
|
+
}
|
|
33
|
+
const untilUs = integer(rawUntil, 'untilUs');
|
|
34
|
+
if (untilUs <= fromUs)
|
|
35
|
+
throw new RangeError('untilUs must be after fromUs');
|
|
36
|
+
return { seq, track, fromUs, untilUs, text, final };
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A transcript object's payload: compact JSON, `{"seq":…,"track":…,"fromUs":…,"untilUs":…,"text":…,"final":…}`,
|
|
40
|
+
* without `untilUs` when absent.
|
|
41
|
+
*/
|
|
42
|
+
export function buildTranscriptSegment(input) {
|
|
43
|
+
const segment = checked({
|
|
44
|
+
...input,
|
|
45
|
+
track: input.track === undefined ? AUDIO_TRACK : input.track,
|
|
46
|
+
final: input.final === undefined ? false : input.final,
|
|
47
|
+
});
|
|
48
|
+
return new TextEncoder().encode(JSON.stringify(segment));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Read a transcript object's payload. Throws on a payload that is not a UTF-8 JSON object with a nonnegative
|
|
52
|
+
* safe-integer `seq` and `fromUs`, a non-empty string `track`, a string `text` and a boolean `final`, or whose
|
|
53
|
+
* `untilUs`, when present, is not one after `fromUs`, or that is final without `untilUs`. Other fields are ignored.
|
|
54
|
+
*/
|
|
55
|
+
export function parseTranscriptSegment(payload) {
|
|
56
|
+
const raw = JSON.parse(new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(payload));
|
|
57
|
+
if (typeof raw !== 'object' || raw === null || Array.isArray(raw))
|
|
58
|
+
throw new Error('transcript segment is not a JSON object');
|
|
59
|
+
const { seq, track, fromUs, untilUs, text, final } = raw;
|
|
60
|
+
// A present untilUs must be a number: null is not "absent".
|
|
61
|
+
if ('untilUs' in raw && untilUs === undefined)
|
|
62
|
+
throw new RangeError('untilUs must be a nonnegative safe integer');
|
|
63
|
+
return checked({ seq, track, fromUs, untilUs, text, final });
|
|
64
|
+
}
|
|
65
|
+
/** Create an empty {@link Transcript}. */
|
|
66
|
+
export function createTranscript() {
|
|
67
|
+
const held = new Map();
|
|
68
|
+
const cuts = [];
|
|
69
|
+
// The segments the talker sent final: a line a cut ended is final too, but takes the talker's final version.
|
|
70
|
+
const finals = new Set();
|
|
71
|
+
// Ended where a cut starts: final, since nothing after it plays, and cut.
|
|
72
|
+
const clipped = (line, startUs) => ({
|
|
73
|
+
...line,
|
|
74
|
+
untilUs: startUs,
|
|
75
|
+
final: true,
|
|
76
|
+
cut: true,
|
|
77
|
+
});
|
|
78
|
+
const same = (a, b) => b !== undefined &&
|
|
79
|
+
a.seq === b.seq &&
|
|
80
|
+
a.track === b.track &&
|
|
81
|
+
a.fromUs === b.fromUs &&
|
|
82
|
+
a.untilUs === b.untilUs &&
|
|
83
|
+
a.text === b.text &&
|
|
84
|
+
a.final === b.final &&
|
|
85
|
+
a.cut === b.cut;
|
|
86
|
+
const lines = () => [...held.values()].sort((a, b) => a.fromUs - b.fromUs || a.seq - b.seq).map((line) => ({ ...line }));
|
|
87
|
+
return {
|
|
88
|
+
apply(segment) {
|
|
89
|
+
const previous = held.get(segment.seq);
|
|
90
|
+
if (finals.has(segment.seq) || (previous?.cut && !segment.final))
|
|
91
|
+
return false;
|
|
92
|
+
const { seq, track, fromUs, untilUs, text, final } = segment;
|
|
93
|
+
// Final even if a cut drops it below: no later version may bring the segment back.
|
|
94
|
+
if (final)
|
|
95
|
+
finals.add(seq);
|
|
96
|
+
let line = {
|
|
97
|
+
seq,
|
|
98
|
+
track,
|
|
99
|
+
fromUs,
|
|
100
|
+
...(untilUs === undefined ? {} : { untilUs }),
|
|
101
|
+
text,
|
|
102
|
+
final,
|
|
103
|
+
cut: false,
|
|
104
|
+
};
|
|
105
|
+
for (const cut of [...cuts].sort((a, b) => a.startUs - b.startUs || a.untilUs - b.untilUs)) {
|
|
106
|
+
// Starts inside a cut: never heard. A final version says an earlier one held is wrong.
|
|
107
|
+
if (cut.startUs <= fromUs && fromUs < cut.untilUs)
|
|
108
|
+
return final && held.delete(seq);
|
|
109
|
+
if (fromUs < cut.startUs && (untilUs === undefined || untilUs > cut.startUs)) {
|
|
110
|
+
line = clipped(line, cut.startUs);
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (same(line, previous))
|
|
115
|
+
return false;
|
|
116
|
+
held.set(seq, line);
|
|
117
|
+
return true;
|
|
118
|
+
},
|
|
119
|
+
cut(range, positionUs) {
|
|
120
|
+
const untilUs = integer(range.untilUs, 'untilUs');
|
|
121
|
+
let startUs = range.fromUs === undefined ? 0 : integer(range.fromUs, 'fromUs');
|
|
122
|
+
if (range.fromUs !== undefined && startUs >= untilUs)
|
|
123
|
+
throw new RangeError('fromUs must be before untilUs');
|
|
124
|
+
if (positionUs !== undefined) {
|
|
125
|
+
if (!Number.isFinite(positionUs) || positionUs < 0)
|
|
126
|
+
throw new RangeError('positionUs must be a nonnegative number');
|
|
127
|
+
startUs = Math.max(startUs, Math.floor(positionUs));
|
|
128
|
+
}
|
|
129
|
+
if (startUs >= untilUs)
|
|
130
|
+
return;
|
|
131
|
+
cuts.push({ startUs, untilUs });
|
|
132
|
+
for (const [seq, line] of held) {
|
|
133
|
+
if (line.fromUs >= untilUs)
|
|
134
|
+
continue;
|
|
135
|
+
if (line.fromUs >= startUs)
|
|
136
|
+
held.delete(seq);
|
|
137
|
+
else if (line.untilUs === undefined || line.untilUs > startUs)
|
|
138
|
+
held.set(seq, clipped(line, startUs));
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
get lines() {
|
|
142
|
+
return lines();
|
|
143
|
+
},
|
|
144
|
+
linesAt(positionUs) {
|
|
145
|
+
if (positionUs === undefined)
|
|
146
|
+
return [];
|
|
147
|
+
return lines().filter((line) => line.fromUs <= positionUs);
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=transcript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transcript.js","sourceRoot":"","sources":["../src/transcript.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,kFAAkF;AAClF,MAAM,CAAC,MAAM,gBAAgB,GAAG,YAAY,CAAC;AA2E7C,SAAS,OAAO,CAAC,KAAc,EAAE,IAAY;IAC3C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC;QACxE,MAAM,IAAI,UAAU,CAAC,GAAG,IAAI,qCAAqC,CAAC,CAAC;IACrE,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,OAAO,CAAC,GAA4B;IAC3C,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC;IACpF,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACnC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,kCAAkC,CAAC,CAAC;IAC9G,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,MAAM,IAAI,UAAU,CAAC,uBAAuB,CAAC,CAAC;IAC5E,IAAI,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,6BAA6B,CAAC,CAAC;IACxF,IAAI,kBAAkB,CAAC,IAA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AK,SAAS,EAAE,CAAC;gBAC7B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,UAAU,GAAG,CAAC;oBAChD,MAAM,IAAI,UAAU,CAAC,yCAAyC,CAAC,CAAC;gBAClE,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;YACtD,CAAC;YACD,IAAI,OAAO,IAAI,OAAO;gBAAE,OAAO;YAC/B,IAAI,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;YAChC,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC;gBAC/B,IAAI,IAAI,CAAC,MAAM,IAAI,OAAO;oBAAE,SAAS;gBACrC,IAAI,IAAI,CAAC,MAAM,IAAI,OAAO;oBAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;qBACxC,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS,IAAI,IAAI,CAAC,OAAO,GAAG,OAAO;oBAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;YACvG,CAAC;QACH,CAAC;QACD,IAAI,KAAK;YACP,OAAO,KAAK,EAAE,CAAC;QACjB,CAAC;QACD,OAAO,CAAC,UAAU;YAChB,IAAI,UAAU,KAAK,SAAS;gBAAE,OAAO,EAAE,CAAC;YACxC,OAAO,KAAK,EAAE,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,IAAI,UAAU,CAAC,CAAC;QAC7D,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** WebCodecs input helpers. No runtime dependency on a browser or media engine. */
|
|
2
|
+
import type { AudioTrackInfo, VideoTrackInfo } from './catalog.js';
|
|
3
|
+
import { type LocPropertiesOptions, locProperties } from './loc.js';
|
|
4
|
+
import type { MsfCatalogTrack } from './parse-catalog.js';
|
|
5
|
+
/** Map an AVC WebCodecs decoder config; encoded packets must already be length-prefixed. */
|
|
6
|
+
export declare function videoTrackFromDecoderConfig(config: VideoDecoderConfig): VideoTrackInfo;
|
|
7
|
+
/** Map an Opus decoder config, preserving its channel count and using the LOC/MSF 48 kHz convention. */
|
|
8
|
+
export declare function audioTrackFromDecoderConfig(config: AudioDecoderConfig): AudioTrackInfo;
|
|
9
|
+
/**
|
|
10
|
+
* The decoder config for a catalog's audio track: its codec, sample rate (default 48 kHz) and channel count (default
|
|
11
|
+
* 2), and its init data as the description.
|
|
12
|
+
*/
|
|
13
|
+
export declare function audioDecoderConfigFromTrack(track: MsfCatalogTrack): AudioDecoderConfig;
|
|
14
|
+
/** One encoded frame ready to publish as a LOC object: `write(payload, { properties })`. */
|
|
15
|
+
export interface LocFrame {
|
|
16
|
+
/** Chunk helpers copy these bytes; packet adapters may borrow them. Keep stable until the write completes. */
|
|
17
|
+
payload: Uint8Array;
|
|
18
|
+
/** Presentation time in microseconds, after any timestamp offset. */
|
|
19
|
+
timestampUs: number;
|
|
20
|
+
/** Whether the frame is a key frame; start a new group on one. */
|
|
21
|
+
key: boolean;
|
|
22
|
+
/** The LOC object properties: Timestamp and Timescale, plus decoder configuration on key frames when supplied. */
|
|
23
|
+
properties: ReturnType<typeof locProperties>;
|
|
24
|
+
}
|
|
25
|
+
/** Options for {@link chunkToLocFrame}. Decoder configuration is attached to key chunks only. */
|
|
26
|
+
export interface ChunkToLocFrameOptions extends LocPropertiesOptions {
|
|
27
|
+
/** Added to the chunk timestamp. Use one shared offset across tracks to normalize negative timestamps. */
|
|
28
|
+
timestampOffsetUs?: number;
|
|
29
|
+
}
|
|
30
|
+
/** Copy the chunk's encoded bytes unchanged and attach LOC metadata; no muxing or bitstream conversion. */
|
|
31
|
+
export declare function chunkToLocFrame(chunk: EncodedVideoChunk | EncodedAudioChunk, options?: ChunkToLocFrameOptions): LocFrame;
|
|
32
|
+
//# sourceMappingURL=webcodecs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webcodecs.d.ts","sourceRoot":"","sources":["../src/webcodecs.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnE,OAAO,EAAE,KAAK,oBAAoB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACpE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAS1D,4FAA4F;AAC5F,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,kBAAkB,GAAG,cAAc,CAiBtF;AAED,wGAAwG;AACxG,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,kBAAkB,GAAG,cAAc,CAYtF;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,eAAe,GAAG,kBAAkB,CAYtF;AAED,4FAA4F;AAC5F,MAAM,WAAW,QAAQ;IACvB,8GAA8G;IAC9G,OAAO,EAAE,UAAU,CAAC;IACpB,qEAAqE;IACrE,WAAW,EAAE,MAAM,CAAC;IACpB,kEAAkE;IAClE,GAAG,EAAE,OAAO,CAAC;IACb,kHAAkH;IAClH,UAAU,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;CAC9C;AAED,iGAAiG;AACjG,MAAM,WAAW,sBAAuB,SAAQ,oBAAoB;IAClE,0GAA0G;IAC1G,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,2GAA2G;AAC3G,wBAAgB,eAAe,CAC7B,KAAK,EAAE,iBAAiB,GAAG,iBAAiB,EAC5C,OAAO,GAAE,sBAA2B,GACnC,QAAQ,CAcV"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { avcCodecString } from './h264.js';
|
|
2
|
+
import { locProperties } from './loc.js';
|
|
3
|
+
function copyDescription(description) {
|
|
4
|
+
if (!description || description.byteLength === 0)
|
|
5
|
+
return undefined;
|
|
6
|
+
return ArrayBuffer.isView(description)
|
|
7
|
+
? new Uint8Array(description.buffer, description.byteOffset, description.byteLength).slice()
|
|
8
|
+
: new Uint8Array(description).slice();
|
|
9
|
+
}
|
|
10
|
+
/** Map an AVC WebCodecs decoder config; encoded packets must already be length-prefixed. */
|
|
11
|
+
export function videoTrackFromDecoderConfig(config) {
|
|
12
|
+
if (!/^avc[13]\./.test(config.codec))
|
|
13
|
+
throw new Error('The video adapter currently supports AVC (H.264)');
|
|
14
|
+
const initData = copyDescription(config.description);
|
|
15
|
+
if (!initData || initData.length < 7 || ((initData[4] ?? 0) & 3) !== 3) {
|
|
16
|
+
throw new Error('AVC requires decoderConfig.description with four-byte NAL lengths; Annex B is not supported');
|
|
17
|
+
}
|
|
18
|
+
const codec = config.codec.slice(0, 4) + avcCodecString(initData).slice(4);
|
|
19
|
+
if (!config.codedWidth ||
|
|
20
|
+
!Number.isSafeInteger(config.codedWidth) ||
|
|
21
|
+
config.codedWidth < 1 ||
|
|
22
|
+
!config.codedHeight ||
|
|
23
|
+
!Number.isSafeInteger(config.codedHeight) ||
|
|
24
|
+
config.codedHeight < 1)
|
|
25
|
+
throw new Error('AVC requires positive integer codedWidth and codedHeight');
|
|
26
|
+
return { codec, width: config.codedWidth, height: config.codedHeight, initData };
|
|
27
|
+
}
|
|
28
|
+
/** Map an Opus decoder config, preserving its channel count and using the LOC/MSF 48 kHz convention. */
|
|
29
|
+
export function audioTrackFromDecoderConfig(config) {
|
|
30
|
+
if (config.codec !== 'opus')
|
|
31
|
+
throw new Error('The audio adapter currently supports Opus');
|
|
32
|
+
if (!Number.isSafeInteger(config.numberOfChannels) || config.numberOfChannels < 1) {
|
|
33
|
+
throw new Error('Opus requires a positive channel count');
|
|
34
|
+
}
|
|
35
|
+
const initData = copyDescription(config.description);
|
|
36
|
+
return {
|
|
37
|
+
codec: 'opus',
|
|
38
|
+
samplerate: 48000,
|
|
39
|
+
channelConfig: String(config.numberOfChannels),
|
|
40
|
+
...(initData ? { initData } : {}),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The decoder config for a catalog's audio track: its codec, sample rate (default 48 kHz) and channel count (default
|
|
45
|
+
* 2), and its init data as the description.
|
|
46
|
+
*/
|
|
47
|
+
export function audioDecoderConfigFromTrack(track) {
|
|
48
|
+
if (!track.codec)
|
|
49
|
+
throw new Error(`Track ${track.name} declares no codec`);
|
|
50
|
+
const channels = track.channelConfig === undefined ? 2 : Number(track.channelConfig);
|
|
51
|
+
if (!Number.isSafeInteger(channels) || channels < 1) {
|
|
52
|
+
throw new Error(`Track ${track.name} declares channels ${track.channelConfig} that are not a channel count`);
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
codec: track.codec,
|
|
56
|
+
sampleRate: track.samplerate ?? 48_000,
|
|
57
|
+
numberOfChannels: channels,
|
|
58
|
+
...(track.initData ? { description: track.initData } : {}),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/** Copy the chunk's encoded bytes unchanged and attach LOC metadata; no muxing or bitstream conversion. */
|
|
62
|
+
export function chunkToLocFrame(chunk, options = {}) {
|
|
63
|
+
const offset = options.timestampOffsetUs ?? 0;
|
|
64
|
+
if (!Number.isSafeInteger(offset))
|
|
65
|
+
throw new Error('timestampOffsetUs must be a safe integer');
|
|
66
|
+
if (!Number.isSafeInteger(chunk.timestamp))
|
|
67
|
+
throw new Error('Chunk timestamp must be safe integer microseconds');
|
|
68
|
+
const timestampUs = chunk.timestamp + offset;
|
|
69
|
+
const key = chunk.type === 'key';
|
|
70
|
+
const properties = locProperties(timestampUs, {
|
|
71
|
+
...(options.timescale !== undefined ? { timescale: options.timescale } : {}),
|
|
72
|
+
...(key && options.videoConfig ? { videoConfig: options.videoConfig } : {}),
|
|
73
|
+
...(key && options.audioConfig ? { audioConfig: options.audioConfig } : {}),
|
|
74
|
+
});
|
|
75
|
+
const payload = new Uint8Array(chunk.byteLength);
|
|
76
|
+
chunk.copyTo(payload);
|
|
77
|
+
return { payload, timestampUs, key, properties };
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=webcodecs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webcodecs.js","sourceRoot":"","sources":["../src/webcodecs.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAA6B,aAAa,EAAE,MAAM,UAAU,CAAC;AAGpE,SAAS,eAAe,CAAC,WAAgD;IACvE,IAAI,CAAC,WAAW,IAAI,WAAW,CAAC,UAAU,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IACnE,OAAO,WAAW,CAAC,MAAM,CAAC,WAAW,CAAC;QACpC,CAAC,CAAC,IAAI,UAAU,CAAC,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,UAAU,EAAE,WAAW,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE;QAC5F,CAAC,CAAC,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC,KAAK,EAAE,CAAC;AAC1C,CAAC;AAED,4FAA4F;AAC5F,MAAM,UAAU,2BAA2B,CAAC,MAA0B;IACpE,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IAC1G,MAAM,QAAQ,GAAG,eAAe,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IACrD,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;QACvE,MAAM,IAAI,KAAK,CAAC,6FAA6F,CAAC,CAAC;IACjH,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,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