@blockcast/mmt-container 0.1.0-main.c71423b8a4e4 → 0.1.0-main.ce3c8aeb7f68
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/dist/align.d.ts +6 -2
- package/dist/align.d.ts.map +1 -1
- package/dist/align.js.map +2 -2
- package/dist/audio-ring-buffer.js +23 -36
- package/dist/audio-ring-buffer.js.map +1 -1
- package/dist/browser-runtime.js +6865 -6485
- package/dist/browser-runtime.js.map +4 -4
- package/dist/carp-catalog.d.ts +3 -1
- package/dist/carp-catalog.d.ts.map +1 -1
- package/dist/carp-catalog.js +21 -2
- package/dist/carp-catalog.js.map +4 -4
- package/dist/catalog-fec-params.js +10 -0
- package/dist/catalog-fec-params.js.map +4 -4
- package/dist/cmaf-block-assembler.d.ts +42 -0
- package/dist/cmaf-block-assembler.d.ts.map +1 -1
- package/dist/cmaf-block-assembler.js +542 -535
- package/dist/cmaf-block-assembler.js.map +2 -2
- package/dist/cmaf-group-batcher.js +27 -46
- package/dist/cmaf-group-batcher.js.map +2 -2
- package/dist/cmcd-producer.js +45 -66
- package/dist/cmcd-producer.js.map +1 -1
- package/dist/fec-manager.d.ts +13 -1
- package/dist/fec-manager.d.ts.map +1 -1
- package/dist/fec-manager.js +1151 -871
- package/dist/fec-manager.js.map +2 -2
- package/dist/fec-starvation-detector.js +25 -40
- package/dist/fec-starvation-detector.js.map +1 -1
- package/dist/fec-worker-setup.js +242 -225
- package/dist/fec-worker-setup.js.map +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +2 -2
- package/dist/iso-bmff-timing.js +63 -88
- package/dist/iso-bmff-timing.js.map +1 -1
- package/dist/loc.js +7 -4
- package/dist/loc.js.map +1 -1
- package/dist/manifest-auth-plan.js +292 -311
- package/dist/manifest-auth-plan.js.map +1 -1
- package/dist/media-router.d.ts +0 -99
- package/dist/media-router.d.ts.map +1 -1
- package/dist/media-router.js +270 -504
- package/dist/media-router.js.map +3 -3
- package/dist/mfu-reassembler.js +597 -607
- package/dist/mfu-reassembler.js.map +3 -3
- package/dist/mmtp-container-parser.d.ts +37 -0
- package/dist/mmtp-container-parser.d.ts.map +1 -1
- package/dist/mmtp-container-parser.js +1531 -1522
- package/dist/mmtp-container-parser.js.map +3 -3
- package/dist/mmtp-container-parser.no-modules.js +179 -102
- package/dist/mmtp-container-parser.no-modules.js.map +3 -3
- package/dist/mmtp-decode-pipeline.js +1641 -1651
- package/dist/mmtp-decode-pipeline.js.map +3 -3
- package/dist/mmtp-router.d.ts +34 -0
- package/dist/mmtp-router.d.ts.map +1 -1
- package/dist/mmtp-router.js +3676 -3390
- package/dist/mmtp-router.js.map +3 -3
- package/dist/mmtp-to-cmaf.d.ts +7 -1
- package/dist/mmtp-to-cmaf.d.ts.map +1 -1
- package/dist/mmtp-to-cmaf.js +109 -134
- package/dist/mmtp-to-cmaf.js.map +2 -2
- package/dist/multicast-input.d.ts +7 -35
- package/dist/multicast-input.d.ts.map +1 -1
- package/dist/multicast-input.js +21 -2
- package/dist/multicast-input.js.map +4 -4
- package/dist/multicast-manager.d.ts +10 -1
- package/dist/multicast-manager.d.ts.map +1 -1
- package/dist/multicast-manager.js +5584 -4961
- package/dist/multicast-manager.js.map +4 -4
- package/dist/multicast-transport.d.ts +7 -0
- package/dist/multicast-transport.d.ts.map +1 -1
- package/dist/multicast-transport.js +369 -421
- package/dist/multicast-transport.js.map +4 -4
- package/dist/multicast-unwrap.js +53 -30
- package/dist/multicast-unwrap.js.map +2 -2
- package/dist/no-modules.js +2096 -2097
- package/dist/no-modules.js.map +3 -3
- package/dist/sample-combiner.js +118 -139
- package/dist/sample-combiner.js.map +1 -1
- package/dist/signaling.js.map +2 -2
- package/dist/source-auth.js +353 -382
- package/dist/source-auth.js.map +1 -1
- package/dist/switching-set-alignment.js +14 -29
- package/dist/switching-set-alignment.js.map +1 -1
- package/dist/timestamp-codec.js +17 -11
- package/dist/timestamp-codec.js.map +2 -2
- package/dist/track-pipeline-setup.js +105 -125
- package/dist/track-pipeline-setup.js.map +1 -1
- package/dist/track-pipeline.js +107 -127
- package/dist/track-pipeline.js.map +1 -1
- package/dist/track-session.d.ts +16 -0
- package/dist/track-session.d.ts.map +1 -1
- package/dist/track-session.js +230 -243
- package/dist/track-session.js.map +2 -2
- package/dist/transport-pool.js +24 -38
- package/dist/transport-pool.js.map +1 -1
- package/dist/wasm-mfu-reassembler.d.ts +6 -1
- package/dist/wasm-mfu-reassembler.d.ts.map +1 -1
- package/dist/wasm-mfu-reassembler.js +127 -144
- package/dist/wasm-mfu-reassembler.js.map +2 -2
- package/dist/wasm-mmtp-container-parser.js +1659 -1650
- package/dist/wasm-mmtp-container-parser.js.map +3 -3
- package/node_modules/@blockcast/fec-worker/README.md +5 -1
- package/node_modules/@blockcast/fec-worker/dist/fec-worker-client.d.ts +8 -2
- package/node_modules/@blockcast/fec-worker/dist/fec-worker-client.d.ts.map +1 -1
- package/node_modules/@blockcast/fec-worker/dist/fec-worker-client.js +89 -16
- package/node_modules/@blockcast/fec-worker/dist/fec-worker-client.js.map +1 -1
- package/node_modules/@blockcast/fec-worker/dist/fec-worker-types.d.ts +48 -3
- package/node_modules/@blockcast/fec-worker/dist/fec-worker-types.d.ts.map +1 -1
- package/node_modules/@blockcast/fec-worker/dist/fec-worker.js +55 -8
- package/node_modules/@blockcast/fec-worker/dist/fec-worker.js.map +2 -2
- package/node_modules/@blockcast/fec-worker/dist/index.d.ts +1 -1
- package/node_modules/@blockcast/fec-worker/dist/index.d.ts.map +1 -1
- package/node_modules/@blockcast/fec-worker/dist/index.js.map +1 -1
- package/node_modules/@blockcast/fec-worker/src/fec-worker-client.ts +97 -17
- package/node_modules/@blockcast/fec-worker/src/fec-worker-types.ts +46 -2
- package/node_modules/@blockcast/fec-worker/src/fec-worker.ts +78 -10
- package/node_modules/@blockcast/fec-worker/src/index.ts +2 -0
- package/node_modules/@blockcast/mmt-base/README.md +1 -0
- package/node_modules/@blockcast/mmt-base/dist/mmtp.d.ts +52 -0
- package/node_modules/@blockcast/mmt-base/dist/mmtp.d.ts.map +1 -1
- package/node_modules/@blockcast/mmt-base/dist/mmtp.js +142 -37
- package/node_modules/@blockcast/mmt-base/dist/mmtp.js.map +1 -1
- package/node_modules/@blockcast/mmt-base/src/mmtp.ts +158 -37
- package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/README.md +1 -0
- package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/mmtp.d.ts +52 -0
- package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/mmtp.d.ts.map +1 -1
- package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/mmtp.js +142 -37
- package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/mmtp.js.map +1 -1
- package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/src/mmtp.ts +158 -37
- package/package.json +7 -6
- package/schemas/catalog.schema.json +1 -1
- package/src/align.ts +6 -2
- package/src/carp-catalog.ts +13 -3
- package/src/cmaf-block-assembler.ts +90 -81
- package/src/fec-manager.ts +530 -146
- package/src/index.ts +2 -2
- package/src/media-router.ts +0 -397
- package/src/mmtp-container-parser.ts +97 -21
- package/src/mmtp-router.ts +302 -125
- package/src/mmtp-to-cmaf.ts +21 -7
- package/src/multicast-input.ts +23 -3
- package/src/multicast-manager.ts +83 -11
- package/src/multicast-transport.ts +56 -17
- package/src/track-session.ts +16 -0
- package/src/wasm-mfu-reassembler.ts +40 -24
- package/test-vectors/catalog/README.md +2 -0
- package/test-vectors/catalog/negative/multicast-packet-id-signaling.json +26 -0
- package/test-vectors/catalog-validation.json +11 -0
package/dist/mmtp-to-cmaf.d.ts
CHANGED
|
@@ -155,7 +155,13 @@ export declare class MmtpToCmaf {
|
|
|
155
155
|
compositionTimeOffset?: number;
|
|
156
156
|
}>, baseDecodeTime: number, trackId?: number): Uint8Array;
|
|
157
157
|
/** Set audio timescale to match the init segment's mdhd timescale.
|
|
158
|
-
* Call after appending the real encoder init (FT=0 ftyp+moov).
|
|
158
|
+
* Call after appending the real encoder init (FT=0 ftyp+moov).
|
|
159
|
+
* Fails closed on a value the mdhd uint32 cannot hold, as the video paths
|
|
160
|
+
* already do. wrapAudioSample rescales the authored composition offset by
|
|
161
|
+
* this value, so the two failure modes are both silent: a 0 multiplies
|
|
162
|
+
* every authored offset to 0 — indistinguishable from a feed that authored
|
|
163
|
+
* none — while a value above uint32 scales the trun to a timescale the
|
|
164
|
+
* mdhd cannot declare, since it is emitted with setUint32 modulo 2^32. */
|
|
159
165
|
setAudioTimescale(timescale: number): void;
|
|
160
166
|
/** Convert a raw audio sample to an fMP4 moof+mdat segment. */
|
|
161
167
|
wrapAudioSample(data: Uint8Array, timestamp: number, sampleDuration?: number, compositionTimeOffset?: number): Uint8Array;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mmtp-to-cmaf.d.ts","sourceRoot":"","sources":["../src/mmtp-to-cmaf.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAyGH;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,KAAK,CAAC;IACb,IAAI,EAAE,UAAU,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,OAAO,CAAA;IACjB,qBAAqB,CAAC,EAAE,MAAM,CAAA;CAC/B,CAAC,EACF,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,MAAM,EAChB,OAAO,SAAI,GACV,UAAU,CA6DZ;AAID;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,CAuFhG;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAA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CAAA;QAChB,qBAAqB,CAAC,EAAE,MAAM,CAAA;KAC/B,CAAC,EACF,cAAc,EAAE,MAAM,EACtB,OAAO,SAAI,GACV,UAAU;IAmBb;;;;qFAIiF;IACjF,KAAK;CAUN"}
|
package/dist/mmtp-to-cmaf.js
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
var __typeError = (msg) => {
|
|
2
|
-
throw TypeError(msg);
|
|
3
|
-
};
|
|
4
|
-
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
-
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
-
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
-
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
-
var __privateWrapper = (obj, member, setter, getter) => ({
|
|
9
|
-
set _(value) {
|
|
10
|
-
__privateSet(obj, member, value, setter);
|
|
11
|
-
},
|
|
12
|
-
get _() {
|
|
13
|
-
return __privateGet(obj, member, getter);
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
|
|
17
1
|
// src/mmtp-to-cmaf.ts
|
|
18
2
|
function box(type, ...children) {
|
|
19
3
|
let size = 8;
|
|
@@ -384,6 +368,7 @@ function buildVideoInitSegment(avcC, width, height, timescale = 1e6, trackId = 1
|
|
|
384
368
|
function buildAudioInitSegment(sampleRate, channels, asc, timescale, trackId = 1) {
|
|
385
369
|
assertTrackId(trackId, "audio trackId");
|
|
386
370
|
const ts = timescale ?? sampleRate;
|
|
371
|
+
assertTimescale(ts, "audio timescale");
|
|
387
372
|
if (!asc) {
|
|
388
373
|
const freqTable = [96e3, 88200, 64e3, 48e3, 44100, 32e3, 24e3, 22050, 16e3, 12e3, 11025, 8e3, 7350];
|
|
389
374
|
const fi = freqTable.indexOf(sampleRate);
|
|
@@ -524,57 +509,43 @@ function buildAudioInitSegment(sampleRate, channels, asc, timescale, trackId = 1
|
|
|
524
509
|
result.set(moov, ftyp.length);
|
|
525
510
|
return result;
|
|
526
511
|
}
|
|
527
|
-
var _videoSeq, _audioSeq, _videoInitSegment, _videoInitTrackId, _audioInitSegment, _lastVideoTimestamp, _frameDuration, _videoBaseTs, _audioBaseTs, _videoTrackId, _videoTimescale, _MmtpToCmaf_instances, videoFrameDuration_get, _audioTimescale, _audioSampleCount, _aacFrameSamples;
|
|
528
512
|
var MmtpToCmaf = class {
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
__privateAdd(this, _videoTrackId, 1);
|
|
566
|
-
__privateAdd(this, _videoTimescale, 1e6);
|
|
567
|
-
// Audio timescale from init segment (default 1M µs; real FFmpeg init uses sampleRate).
|
|
568
|
-
// Set by buildAudioInit or setAudioTimescale.
|
|
569
|
-
__privateAdd(this, _audioTimescale, 1e6);
|
|
570
|
-
// Audio sample counter for drift-free baseMediaDecodeTime.
|
|
571
|
-
// AAC frames are exactly 1024 samples at sampleRate. Using sequential
|
|
572
|
-
// counter × 1024 avoids floating-point rounding drift from timestamp conversion.
|
|
573
|
-
__privateAdd(this, _audioSampleCount, 0);
|
|
574
|
-
/** AAC access-unit length in samples. ISO/IEC 14496-3: an AAC-LC frame is
|
|
575
|
-
* exactly 1024 samples at every sample rate — it is not rate-dependent. */
|
|
576
|
-
__privateAdd(this, _aacFrameSamples, 1024);
|
|
577
|
-
}
|
|
513
|
+
#videoSeq = 1;
|
|
514
|
+
#audioSeq = 1;
|
|
515
|
+
#videoInitSegment = null;
|
|
516
|
+
// Known only for locally-built init segments. Wire-supplied MPU metadata is
|
|
517
|
+
// intentionally opaque here, so setVideoTrackParams remains the API that
|
|
518
|
+
// lets a caller declare its track geometry before wrapping samples.
|
|
519
|
+
#videoInitTrackId = null;
|
|
520
|
+
#audioInitSegment = null;
|
|
521
|
+
#lastVideoTimestamp = 0;
|
|
522
|
+
// Sticky sample duration in video timescale units, updated from caller-
|
|
523
|
+
// supplied durations or adjacent-timestamp deltas. null means "nothing
|
|
524
|
+
// observed yet", in which case #videoFrameDuration derives ~30fps from the
|
|
525
|
+
// configured timescale (33333 at the 1_000_000 default, i.e. unchanged).
|
|
526
|
+
#frameDuration = null;
|
|
527
|
+
// Per-track rebase: each track anchors on its OWN first sample so
|
|
528
|
+
// baseMediaDecodeTime is never negative. A shared base was wrong — if the
|
|
529
|
+
// first sample of one track arrives later than the other's first sample,
|
|
530
|
+
// the earlier track computes `timestamp - sharedBase` as a negative number,
|
|
531
|
+
// which serializes into tfdt as a huge unsigned uint64 (~2^64 - 46) and
|
|
532
|
+
// Chromium rejects the segment with CHUNK_DEMUXER_ERROR_APPEND_FAILED,
|
|
533
|
+
// closing the MediaSource and detaching all SourceBuffers.
|
|
534
|
+
// For A/V alignment, choose a COMMON anchor: set when the first sample of
|
|
535
|
+
// EITHER track arrives, but only if that sample's timestamp is <= any
|
|
536
|
+
// subsequent track's first sample. Implementation: each track rebases to
|
|
537
|
+
// the minimum timestamp seen across tracks on their respective first sample.
|
|
538
|
+
#videoBaseTs = -1;
|
|
539
|
+
#audioBaseTs = -1;
|
|
540
|
+
// Video track geometry. These pair with the video init segment's tkhd
|
|
541
|
+
// track_ID and mdhd/mvhd timescale: every moof this converter emits must
|
|
542
|
+
// reference the same track at the same rate or the browser either drops the
|
|
543
|
+
// fragment (unknown track) or plays it at the wrong rate. They are
|
|
544
|
+
// configuration rather than stream state, so — unlike the sequence numbers
|
|
545
|
+
// and time bases above — reset() deliberately preserves them, matching the
|
|
546
|
+
// fact that reset() also preserves #videoInitSegment.
|
|
547
|
+
#videoTrackId = 1;
|
|
548
|
+
#videoTimescale = 1e6;
|
|
578
549
|
/**
|
|
579
550
|
* Point the single-sample video wrappers at a specific track and rate.
|
|
580
551
|
*
|
|
@@ -590,40 +561,40 @@ var MmtpToCmaf = class {
|
|
|
590
561
|
setVideoTrackParams(trackId, timescale) {
|
|
591
562
|
assertTrackId(trackId, "video trackId");
|
|
592
563
|
assertTimescale(timescale, "video timescale");
|
|
593
|
-
if (trackId !==
|
|
564
|
+
if (trackId !== this.#videoTrackId && this.#videoInitTrackId !== null) {
|
|
594
565
|
throw new Error(
|
|
595
|
-
`video track ID cannot change from ${
|
|
566
|
+
`video track ID cannot change from ${this.#videoTrackId} to ${trackId} after a video init has been cached; replace the init atomically`
|
|
596
567
|
);
|
|
597
568
|
}
|
|
598
|
-
if (timescale !==
|
|
569
|
+
if (timescale !== this.#videoTimescale && this.#videoBaseTs >= 0) {
|
|
599
570
|
throw new Error(
|
|
600
|
-
`video timescale cannot change from ${
|
|
571
|
+
`video timescale cannot change from ${this.#videoTimescale} to ${timescale} after video samples have been wrapped; call reset() first`
|
|
601
572
|
);
|
|
602
573
|
}
|
|
603
|
-
|
|
604
|
-
|
|
574
|
+
this.#videoTrackId = trackId;
|
|
575
|
+
this.#videoTimescale = timescale;
|
|
605
576
|
}
|
|
606
577
|
/** Set init segment from MPU metadata packet (fragment_type=0).
|
|
607
578
|
* These are complete ftyp+moov bytes from FFmpeg — use directly. */
|
|
608
579
|
setInitSegmentFromMpu(data, isAudio) {
|
|
609
580
|
if (isAudio) {
|
|
610
|
-
|
|
581
|
+
this.#audioInitSegment = data;
|
|
611
582
|
} else {
|
|
612
|
-
|
|
613
|
-
|
|
583
|
+
this.#videoInitSegment = data;
|
|
584
|
+
this.#videoInitTrackId = null;
|
|
614
585
|
}
|
|
615
586
|
}
|
|
616
587
|
/** Build init segment from codec config (catalog path — no MPU metadata available).
|
|
617
588
|
* Passing timescale/trackId also configures the wrappers via
|
|
618
589
|
* setVideoTrackParams, so init and media segments cannot disagree. */
|
|
619
590
|
buildVideoInit(avcC, width, height, timescale, trackId) {
|
|
620
|
-
const nextTimescale = timescale ??
|
|
621
|
-
const nextTrackId = trackId ??
|
|
591
|
+
const nextTimescale = timescale ?? this.#videoTimescale;
|
|
592
|
+
const nextTrackId = trackId ?? this.#videoTrackId;
|
|
622
593
|
assertTrackId(nextTrackId, "video trackId");
|
|
623
594
|
assertTimescale(nextTimescale, "video timescale");
|
|
624
|
-
if (nextTimescale !==
|
|
595
|
+
if (nextTimescale !== this.#videoTimescale && this.#videoBaseTs >= 0) {
|
|
625
596
|
throw new Error(
|
|
626
|
-
`video timescale cannot change from ${
|
|
597
|
+
`video timescale cannot change from ${this.#videoTimescale} to ${nextTimescale} after video samples have been wrapped; call reset() first`
|
|
627
598
|
);
|
|
628
599
|
}
|
|
629
600
|
const init = buildVideoInitSegment(
|
|
@@ -633,21 +604,22 @@ var MmtpToCmaf = class {
|
|
|
633
604
|
nextTimescale,
|
|
634
605
|
nextTrackId
|
|
635
606
|
);
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
607
|
+
this.#videoTimescale = nextTimescale;
|
|
608
|
+
this.#videoTrackId = nextTrackId;
|
|
609
|
+
this.#videoInitSegment = init;
|
|
610
|
+
this.#videoInitTrackId = nextTrackId;
|
|
640
611
|
}
|
|
641
612
|
buildAudioInit(sampleRate, channels, asc, timescale) {
|
|
642
613
|
const ts = timescale ?? sampleRate;
|
|
643
|
-
|
|
644
|
-
|
|
614
|
+
const init = buildAudioInitSegment(sampleRate, channels, asc, ts);
|
|
615
|
+
this.#audioTimescale = ts;
|
|
616
|
+
this.#audioInitSegment = init;
|
|
645
617
|
}
|
|
646
618
|
get videoInitSegment() {
|
|
647
|
-
return
|
|
619
|
+
return this.#videoInitSegment;
|
|
648
620
|
}
|
|
649
621
|
get audioInitSegment() {
|
|
650
|
-
return
|
|
622
|
+
return this.#audioInitSegment;
|
|
651
623
|
}
|
|
652
624
|
/** Convert a raw video sample to an fMP4 moof+mdat segment. */
|
|
653
625
|
wrapVideoSample(data, timestamp, keyframe, duration, compositionTimeOffset) {
|
|
@@ -671,29 +643,33 @@ var MmtpToCmaf = class {
|
|
|
671
643
|
wrapVideoSampleWithTiming(data, timestamp, keyframe, duration, compositionTimeOffset) {
|
|
672
644
|
assertCompositionTimeOffsets([{ compositionTimeOffset }]);
|
|
673
645
|
if (duration !== void 0 && Number.isFinite(duration) && duration > 0) {
|
|
674
|
-
|
|
675
|
-
} else if (
|
|
676
|
-
const delta = timestamp -
|
|
677
|
-
if (delta > 0 && delta <
|
|
646
|
+
this.#frameDuration = Math.round(duration);
|
|
647
|
+
} else if (this.#lastVideoTimestamp > 0 && timestamp > this.#lastVideoTimestamp) {
|
|
648
|
+
const delta = timestamp - this.#lastVideoTimestamp;
|
|
649
|
+
if (delta > 0 && delta < this.#videoTimescale) this.#frameDuration = delta;
|
|
678
650
|
}
|
|
679
|
-
|
|
680
|
-
if (
|
|
681
|
-
const relTs = timestamp -
|
|
682
|
-
const frameDuration =
|
|
651
|
+
this.#lastVideoTimestamp = timestamp;
|
|
652
|
+
if (this.#videoBaseTs < 0) this.#videoBaseTs = timestamp;
|
|
653
|
+
const relTs = timestamp - this.#videoBaseTs;
|
|
654
|
+
const frameDuration = this.#videoFrameDuration;
|
|
683
655
|
return Object.freeze({
|
|
684
656
|
segment: encodeDataSegment(
|
|
685
657
|
data,
|
|
686
658
|
relTs,
|
|
687
659
|
frameDuration,
|
|
688
660
|
keyframe,
|
|
689
|
-
|
|
690
|
-
|
|
661
|
+
this.#videoSeq++,
|
|
662
|
+
this.#videoTrackId,
|
|
691
663
|
compositionTimeOffset
|
|
692
664
|
),
|
|
693
665
|
mediaTimestamp: relTs,
|
|
694
666
|
duration: frameDuration
|
|
695
667
|
});
|
|
696
668
|
}
|
|
669
|
+
/** Sticky duration if one has been observed, else ~30fps at the current rate. */
|
|
670
|
+
get #videoFrameDuration() {
|
|
671
|
+
return this.#frameDuration ?? Math.max(1, Math.round(this.#videoTimescale / 30));
|
|
672
|
+
}
|
|
697
673
|
/** Convert an append-safe video batch using the caller-owned timeline.
|
|
698
674
|
* Durations, baseDecodeTime, and compositionTimeOffset are in the
|
|
699
675
|
* configured video timescale. compositionTimeOffset is the signed PTS-DTS
|
|
@@ -701,31 +677,48 @@ var MmtpToCmaf = class {
|
|
|
701
677
|
* An explicit trackId is range-checked before #videoSeq++ for the same
|
|
702
678
|
* reason as wrapAudioSamples: the encoder's own check fires too late to
|
|
703
679
|
* keep the sequence ungapped. */
|
|
704
|
-
wrapVideoSamples(samples, baseDecodeTime, trackId =
|
|
680
|
+
wrapVideoSamples(samples, baseDecodeTime, trackId = this.#videoTrackId) {
|
|
705
681
|
assertTrackId(trackId, "video trackId");
|
|
706
682
|
assertCompositionTimeOffsets(samples);
|
|
707
|
-
return encodeMultiSampleSegment(samples, baseDecodeTime,
|
|
683
|
+
return encodeMultiSampleSegment(samples, baseDecodeTime, this.#videoSeq++, trackId);
|
|
708
684
|
}
|
|
685
|
+
// Audio timescale from init segment (default 1M µs; real FFmpeg init uses sampleRate).
|
|
686
|
+
// Set by buildAudioInit or setAudioTimescale.
|
|
687
|
+
#audioTimescale = 1e6;
|
|
709
688
|
/** Set audio timescale to match the init segment's mdhd timescale.
|
|
710
|
-
* Call after appending the real encoder init (FT=0 ftyp+moov).
|
|
689
|
+
* Call after appending the real encoder init (FT=0 ftyp+moov).
|
|
690
|
+
* Fails closed on a value the mdhd uint32 cannot hold, as the video paths
|
|
691
|
+
* already do. wrapAudioSample rescales the authored composition offset by
|
|
692
|
+
* this value, so the two failure modes are both silent: a 0 multiplies
|
|
693
|
+
* every authored offset to 0 — indistinguishable from a feed that authored
|
|
694
|
+
* none — while a value above uint32 scales the trun to a timescale the
|
|
695
|
+
* mdhd cannot declare, since it is emitted with setUint32 modulo 2^32. */
|
|
711
696
|
setAudioTimescale(timescale) {
|
|
712
|
-
|
|
697
|
+
assertTimescale(timescale, "audio timescale");
|
|
698
|
+
this.#audioTimescale = timescale;
|
|
713
699
|
}
|
|
700
|
+
// Audio sample counter for drift-free baseMediaDecodeTime.
|
|
701
|
+
// AAC frames are exactly 1024 samples at sampleRate. Using sequential
|
|
702
|
+
// counter × 1024 avoids floating-point rounding drift from timestamp conversion.
|
|
703
|
+
#audioSampleCount = 0;
|
|
704
|
+
/** AAC access-unit length in samples. ISO/IEC 14496-3: an AAC-LC frame is
|
|
705
|
+
* exactly 1024 samples at every sample rate — it is not rate-dependent. */
|
|
706
|
+
#aacFrameSamples = 1024;
|
|
714
707
|
/** Convert a raw audio sample to an fMP4 moof+mdat segment. */
|
|
715
708
|
wrapAudioSample(data, timestamp, sampleDuration = 21333, compositionTimeOffset) {
|
|
716
709
|
assertCompositionTimeOffsets([{ compositionTimeOffset }]);
|
|
717
710
|
const sampleData = normalizeAacSampleForCmaf(data);
|
|
718
|
-
if (
|
|
719
|
-
const samplesPerFrame =
|
|
720
|
-
const scaledTs =
|
|
721
|
-
|
|
722
|
-
const scaledCompositionTimeOffset = compositionTimeOffset === void 0 ||
|
|
711
|
+
if (this.#audioBaseTs < 0) this.#audioBaseTs = timestamp;
|
|
712
|
+
const samplesPerFrame = this.#audioTimescale !== 1e6 ? this.#aacFrameSamples : sampleDuration;
|
|
713
|
+
const scaledTs = this.#audioTimescale !== 1e6 ? this.#audioSampleCount * samplesPerFrame : timestamp - this.#audioBaseTs;
|
|
714
|
+
this.#audioSampleCount++;
|
|
715
|
+
const scaledCompositionTimeOffset = compositionTimeOffset === void 0 || this.#audioTimescale === 1e6 ? compositionTimeOffset : Math.round(compositionTimeOffset * this.#audioTimescale / 1e6);
|
|
723
716
|
return encodeDataSegment(
|
|
724
717
|
sampleData,
|
|
725
718
|
scaledTs,
|
|
726
719
|
samplesPerFrame,
|
|
727
720
|
true,
|
|
728
|
-
|
|
721
|
+
this.#audioSeq++,
|
|
729
722
|
1,
|
|
730
723
|
scaledCompositionTimeOffset
|
|
731
724
|
);
|
|
@@ -742,7 +735,7 @@ var MmtpToCmaf = class {
|
|
|
742
735
|
compositionTimeOffset: sample.compositionTimeOffset
|
|
743
736
|
})),
|
|
744
737
|
baseDecodeTime,
|
|
745
|
-
|
|
738
|
+
this.#audioSeq++,
|
|
746
739
|
trackId
|
|
747
740
|
);
|
|
748
741
|
}
|
|
@@ -752,34 +745,16 @@ var MmtpToCmaf = class {
|
|
|
752
745
|
* Clearing the timescale-denominated timing state also re-opens the video
|
|
753
746
|
* rate for change — this is the sanctioned way to retarget mid-subscription. */
|
|
754
747
|
reset() {
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
748
|
+
this.#videoSeq = 1;
|
|
749
|
+
this.#audioSeq = 1;
|
|
750
|
+
this.#audioSampleCount = 0;
|
|
751
|
+
this.#lastVideoTimestamp = 0;
|
|
752
|
+
this.#frameDuration = null;
|
|
753
|
+
this.#videoBaseTs = -1;
|
|
754
|
+
this.#audioBaseTs = -1;
|
|
755
|
+
this.#audioTimescale = 1e6;
|
|
763
756
|
}
|
|
764
757
|
};
|
|
765
|
-
_videoSeq = new WeakMap();
|
|
766
|
-
_audioSeq = new WeakMap();
|
|
767
|
-
_videoInitSegment = new WeakMap();
|
|
768
|
-
_videoInitTrackId = new WeakMap();
|
|
769
|
-
_audioInitSegment = new WeakMap();
|
|
770
|
-
_lastVideoTimestamp = new WeakMap();
|
|
771
|
-
_frameDuration = new WeakMap();
|
|
772
|
-
_videoBaseTs = new WeakMap();
|
|
773
|
-
_audioBaseTs = new WeakMap();
|
|
774
|
-
_videoTrackId = new WeakMap();
|
|
775
|
-
_videoTimescale = new WeakMap();
|
|
776
|
-
_MmtpToCmaf_instances = new WeakSet();
|
|
777
|
-
videoFrameDuration_get = function() {
|
|
778
|
-
return __privateGet(this, _frameDuration) ?? Math.max(1, Math.round(__privateGet(this, _videoTimescale) / 30));
|
|
779
|
-
};
|
|
780
|
-
_audioTimescale = new WeakMap();
|
|
781
|
-
_audioSampleCount = new WeakMap();
|
|
782
|
-
_aacFrameSamples = new WeakMap();
|
|
783
758
|
export {
|
|
784
759
|
MmtpToCmaf,
|
|
785
760
|
buildAudioInitSegment,
|