@camstack/addon-pipeline 1.2.75 → 1.2.77

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 (31) hide show
  1. package/dist/{addon-utils-a_36HH_N.js → addon-utils-bZcwLaVW.js} +1 -1
  2. package/dist/audio-analyzer/index.js +2 -2
  3. package/dist/audio-analyzer/index.mjs +1 -1
  4. package/dist/detection-pipeline/index.js +4 -4
  5. package/dist/detection-pipeline/index.mjs +2 -2
  6. package/dist/{dist-6ZJCV0jY.js → dist-DQZzL0Ri.js} +452 -42
  7. package/dist/{dist-T_8jMw7d.mjs → dist-HhcoV-Ky.mjs} +452 -42
  8. package/dist/{event-loop-stall-monitor-Cjof8vA1.js → event-loop-stall-monitor-CBOo1oh_.js} +1 -1
  9. package/dist/{event-loop-stall-monitor-XeGmL4xr.mjs → event-loop-stall-monitor-CqBEWGSZ.mjs} +1 -1
  10. package/dist/{lazy-sharp-DvwPafeP.js → lazy-sharp-DIC1rpea.js} +1 -1
  11. package/dist/motion-wasm/index.js +2 -2
  12. package/dist/motion-wasm/index.mjs +1 -1
  13. package/dist/pipeline-runner/index.js +278 -15
  14. package/dist/pipeline-runner/index.mjs +277 -14
  15. package/dist/recorder/index.js +368 -18
  16. package/dist/recorder/index.mjs +367 -17
  17. package/dist/session-decode/decode-worker-child.js +2 -2
  18. package/dist/session-decode/decode-worker-child.mjs +1 -1
  19. package/dist/stream-broker/_stub.js +2 -2
  20. package/dist/stream-broker/{_virtual_mf-localSharedImportMap___mfe_internal__addon_stream_broker_widgets-H2OTmgR6.mjs → _virtual_mf-localSharedImportMap___mfe_internal__addon_stream_broker_widgets-De_xzvjU.mjs} +3 -3
  21. package/dist/stream-broker/_virtual_mf___mfe_internal__addon_stream_broker_widgets__loadShare___mf_0_camstack_mf_1_types__loadShare__.js-DHJSxHH1.mjs +26 -0
  22. package/dist/stream-broker/_virtual_mf___mfe_internal__addon_stream_broker_widgets__loadShare___mf_0_camstack_mf_1_ui_mf_2_library__loadShare__.js-Dg08SxUW.mjs +26 -0
  23. package/dist/stream-broker/{hostInit-4XDN_Nt0.mjs → hostInit-CDS5frmk.mjs} +3 -3
  24. package/dist/stream-broker/index.js +306 -71
  25. package/dist/stream-broker/index.mjs +306 -71
  26. package/dist/stream-broker/remoteEntry.js +1 -1
  27. package/dist/{worker-protocol-SqED7Y9i.mjs → worker-protocol-BNlLGLBV.mjs} +1 -1
  28. package/dist/{worker-protocol-B0cbTXyw.js → worker-protocol-DZVGVAPU.js} +1 -1
  29. package/package.json +1 -1
  30. package/dist/stream-broker/_virtual_mf___mfe_internal__addon_stream_broker_widgets__loadShare___mf_0_camstack_mf_1_types__loadShare__.js-RYTOS6B-.mjs +0 -26
  31. package/dist/stream-broker/_virtual_mf___mfe_internal__addon_stream_broker_widgets__loadShare___mf_0_camstack_mf_1_ui_mf_2_library__loadShare__.js-DfsLsn2e.mjs +0 -26
@@ -2,7 +2,7 @@ Object.defineProperties(exports, {
2
2
  __esModule: { value: true },
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
- const require_dist = require("../dist-6ZJCV0jY.js");
5
+ const require_dist = require("../dist-DQZzL0Ri.js");
6
6
  const require_remote_restream = require("../remote-restream-BYbAsgUf.js");
7
7
  let node_crypto = require("node:crypto");
8
8
  node_crypto = require_dist.__toESM(node_crypto, 1);
@@ -973,7 +973,93 @@ var DerivedStreamFeeder = class extends FfmpegPushReader {
973
973
  * deleted, and with it the two hacks this module needed to bend it into shape:
974
974
  * a sink-retargeting string surgery on the tail of the arg list, and a fake
975
975
  * `inputFormat` chosen only to defeat smart-copy.
976
+ *
977
+ * ## The audio rule, and the outage that wrote it
978
+ *
979
+ * A derived stream is a self-contained MPEG-TS, so its audio must travel
980
+ * IN-BAND — `passthrough` (`-an`, right for WebRTC, where werift carries audio
981
+ * out of band) silently drops the track. That was fixed on 2026-07-17 by
982
+ * remapping `passthrough` → `-c:a copy`, and the track stayed missing anyway,
983
+ * because a copy has to survive TWO hops and it only clears the first:
984
+ *
985
+ * 1. the MPEG-TS MUXER. Measured with ffmpeg 7.1: a `pcm_mulaw` track copied
986
+ * into `-f mpegts` does not fail the invocation. ffmpeg logs
987
+ * `Stream 1, codec pcm_mulaw, is muxed as a private data stream and may
988
+ * not be recognized upon reading` and writes stream_type `0x06` — which
989
+ * is why the derived stream looked perfectly healthy: video never
990
+ * stopped;
991
+ * 2. {@link MpegTsDemux}, which adopts an elementary audio PID only for
992
+ * stream_type `0x0f` (AAC) or `0x03`/`0x04` (MP2). `0x06` is not audio to
993
+ * it, so no audio packet was ever forwarded, `onAudioInfo` never fired,
994
+ * the derived broker never learned it had audio, and its probe read
995
+ * `audio: null` forever.
996
+ *
997
+ * Every camera in this fleet speaks G.711 (PCMU/PCMA), so the copy could never
998
+ * work for any of them: no `derived:*` stream has EVER carried audio, and
999
+ * camera 618 — whose `low` (motion, and therefore audio) profile is mapped to
1000
+ * a derived stream — went silent the day it was remapped.
1001
+ *
1002
+ * So the carrier decides, explicitly and loudly, not the profile: source audio
1003
+ * is COPIED when it is already AAC, and RE-ENCODED to AAC otherwise (including
1004
+ * when the source codec is unknown — the safe direction, since an unknown that
1005
+ * guesses `copy` mutes the camera). The decision is returned to the caller so
1006
+ * it can be logged per camera; it is never taken silently.
1007
+ */
1008
+ /**
1009
+ * Audio codecs that survive BOTH hops of the derived carrier untouched: a
1010
+ * standard MPEG-TS stream type AND a stream type {@link MpegTsDemux} adopts.
1011
+ *
1012
+ * AAC only, deliberately. MP2 clears both hops as a container matter, but the
1013
+ * broker's push-audio path has no MP2 decode (`StreamBroker.pushAudioInfo` →
1014
+ * `buildAudioCodecSessionConfigFromPush` handles `aac`/`opus`), so a copied
1015
+ * MP2 track would arrive as an announced-but-undecodable stream — a second way
1016
+ * to be silent, with a track descriptor to make it look fine.
1017
+ */
1018
+ var TS_COPYABLE_AUDIO_CODECS = new Set(["aac"]);
1019
+ /**
1020
+ * The AAC re-encode used when the source cannot be copied. Mono, and
1021
+ * deliberately WITHOUT a forced sample rate: a G.711 camera mic is 8 kHz, and
1022
+ * upsampling it to the 48 kHz camera preset would spend bitrate on nothing.
1023
+ * ffmpeg's native AAC encoder accepts 8 kHz, the ADTS header carries whatever
1024
+ * rate came out, and `parseAdtsAudioParams` reads it back for the broker.
976
1025
  */
1026
+ var DERIVED_AAC_RECODE = {
1027
+ codec: "aac",
1028
+ channels: 1
1029
+ };
1030
+ /** `true` when this profile audio means "carry whatever the source has". */
1031
+ function wantsSourceAudio(audio) {
1032
+ return audio === "passthrough" || audio.codec === "copy";
1033
+ }
1034
+ /**
1035
+ * Decide the derived stream's audio from the profile's intent and the SOURCE's
1036
+ * observed codec. Pure; see this module's header for why `copy` is not the
1037
+ * default answer to "carry the source's audio".
1038
+ *
1039
+ * `sourceAudioCodec` is matched case-insensitively (`BrokerStats.audio.codec`
1040
+ * is upper-cased, SDP spellings are not).
1041
+ */
1042
+ function resolveDerivedAudio(profileAudio, sourceAudioCodec) {
1043
+ if (!wantsSourceAudio(profileAudio)) return {
1044
+ audio: profileAudio,
1045
+ decision: { kind: "profile" }
1046
+ };
1047
+ const observed = sourceAudioCodec?.toLowerCase() ?? null;
1048
+ if (observed !== null && TS_COPYABLE_AUDIO_CODECS.has(observed)) return {
1049
+ audio: { codec: "copy" },
1050
+ decision: {
1051
+ kind: "copy",
1052
+ sourceCodec: observed
1053
+ }
1054
+ };
1055
+ return {
1056
+ audio: DERIVED_AAC_RECODE,
1057
+ decision: {
1058
+ kind: "recode-aac",
1059
+ sourceCodec: observed
1060
+ }
1061
+ };
1062
+ }
977
1063
  /**
978
1064
  * Build the ffmpeg argv that reads a source loopback RTSP url, transcodes it
979
1065
  * per `profile`, and writes `-f mpegts pipe:1` (what the feeder's `MpegTsDemux`
@@ -982,37 +1068,33 @@ var DerivedStreamFeeder = class extends FfmpegPushReader {
982
1068
  * Two things are specific to a derived stream and are expressed as first-class
983
1069
  * builder inputs rather than post-hoc edits:
984
1070
  *
985
- * - `forceReencode` — a derived stream ALWAYS applies its profile; that is its
986
- * entire reason to exist. Without it the builder's smart-copy would elide
987
- * the encode whenever the source already spoke the target codec. A `copy`
988
- * profile still copies (a legitimate derived remux).
989
- * - audio `copy` in place of `passthrough` — a derived stream is a
990
- * self-contained MPEG-TS, so its audio MUST travel in-band. `passthrough`
991
- * means `-an`, which is right for WebRTC (werift carries audio out-of-band)
992
- * but silently DROPS the track here.
993
- *
994
- * `decodeHwAccel` is threaded from the caller. It used to be hardcoded `null`;
995
- * the derived source is a local loopback restream, but decoding 4K in software
996
- * to re-encode it is exactly the cost the hub's working vaapi exists to avoid.
997
- * The caller resolves it through `resolveEgressDecodeHwAccel`, and the shared
998
- * `FfmpegProcess` retries in software — loudly — if the hardware child dies.
1071
+ * - `forceReencode` — a derived stream ALWAYS applies its video profile; that
1072
+ * is its entire reason to exist. Without it the builder's smart-copy would
1073
+ * elide the encode whenever the source already spoke the target codec. A
1074
+ * `copy` profile still copies (a legitimate derived remux).
1075
+ * - the audio plan from {@link resolveDerivedAudio} in place of the profile's
1076
+ * own — the MPEG-TS carrier, not the operator, decides whether the source
1077
+ * track can be copied.
999
1078
  */
1000
- function buildDerivedTranscodeArgs(profile, loopbackUrl, decodeHwAccel = null) {
1001
- const audio = profile.audio === "passthrough" ? { codec: "copy" } : profile.audio;
1002
- return require_dist.buildFfmpegArgs(require_dist.invocationFromEncodeProfile({
1003
- profile: {
1004
- ...profile,
1005
- audio
1006
- },
1007
- sourceCodec: "h264",
1008
- forceReencode: true,
1009
- sourceUrl: loopbackUrl,
1010
- sink: {
1011
- kind: "stdout",
1012
- container: "mpegts"
1013
- },
1014
- decodeHwAccel
1015
- }));
1079
+ function buildDerivedTranscodeArgs(input) {
1080
+ const audio = resolveDerivedAudio(input.profile.audio, input.sourceAudioCodec);
1081
+ return {
1082
+ args: require_dist.buildFfmpegArgs(require_dist.invocationFromEncodeProfile({
1083
+ profile: {
1084
+ ...input.profile,
1085
+ audio: audio.audio
1086
+ },
1087
+ sourceCodec: "h264",
1088
+ forceReencode: true,
1089
+ sourceUrl: input.loopbackUrl,
1090
+ sink: {
1091
+ kind: "stdout",
1092
+ container: "mpegts"
1093
+ },
1094
+ decodeHwAccel: input.decodeHwAccel ?? null
1095
+ })),
1096
+ audio
1097
+ };
1016
1098
  }
1017
1099
  /**
1018
1100
  * Ceiling for a configured pre-roll.
@@ -17957,7 +18039,19 @@ var StreamBrokerManager = class StreamBrokerManager {
17957
18039
  loopbackUrl = entry.url;
17958
18040
  release = async () => {};
17959
18041
  }
17960
- const args = buildDerivedTranscodeArgs(encodeProfile, loopbackUrl);
18042
+ const sourceAudioCodec = this.observedSourceAudioCodec(deviceId, source);
18043
+ const { args, audio } = buildDerivedTranscodeArgs({
18044
+ profile: encodeProfile,
18045
+ loopbackUrl,
18046
+ sourceAudioCodec
18047
+ });
18048
+ if (audio.decision.kind === "recode-aac") this.logger.info("derived audio re-encoded to AAC — MPEG-TS cannot copy this source codec", {
18049
+ tags: { deviceId },
18050
+ meta: {
18051
+ camStreamId,
18052
+ sourceAudioCodec: audio.decision.sourceCodec ?? "unknown"
18053
+ }
18054
+ });
17961
18055
  const feeder = new DerivedStreamFeeder({
17962
18056
  ffmpegPath: this.ffmpegConfig.binaryPath,
17963
18057
  args,
@@ -17992,6 +18086,21 @@ var StreamBrokerManager = class StreamBrokerManager {
17992
18086
  };
17993
18087
  }
17994
18088
  /**
18089
+ * The audio codec the derived stream's SOURCE broker has actually observed,
18090
+ * or `null` when there is nothing to read (source not resolved, broker not
18091
+ * created yet, cold dial, no audio track).
18092
+ *
18093
+ * Only ever an input to "can this track be COPIED into the derived MPEG-TS".
18094
+ * `null` resolves to the AAC re-encode, so every failure of this read lands
18095
+ * on the branch that still produces audible audio — the read can never mute
18096
+ * a camera, which is the direction that cost 618 four silent days.
18097
+ */
18098
+ observedSourceAudioCodec(deviceId, source) {
18099
+ const camStreamId = source.kind === "camStream" ? source.camStreamId : this.assignments.get(deviceId)?.map[source.profile] ?? null;
18100
+ if (camStreamId === null) return null;
18101
+ return this.brokers.get(brokerIdFor(deviceId, camStreamId))?.getStats().audio?.codec ?? null;
18102
+ }
18103
+ /**
17995
18104
  * Whether a stream is warmed BY DEFAULT (no explicit override): the device's
17996
18105
  * `high` profile, on a non-battery camera, from a source that is worth
17997
18106
  * keeping hot. Single source of truth used by both the broker-config default
@@ -22285,7 +22394,10 @@ var ControlMessageSchema = require_dist.discriminatedUnion("t", [
22285
22394
  m: require_dist._enum(["fine", "coarse"]).optional(),
22286
22395
  v: require_dist.number().optional()
22287
22396
  }),
22288
- require_dist.object({ t: require_dist.literal("scrubAck") }),
22397
+ require_dist.object({
22398
+ t: require_dist.literal("scrubAck"),
22399
+ seq: require_dist.number().optional()
22400
+ }),
22289
22401
  require_dist.object({
22290
22402
  t: require_dist.literal("warm"),
22291
22403
  epoch: require_dist.number(),
@@ -22330,7 +22442,8 @@ var ServerMessageSchema = require_dist.discriminatedUnion("t", [
22330
22442
  }),
22331
22443
  require_dist.object({
22332
22444
  t: require_dist.literal("position"),
22333
- epochMs: require_dist.number()
22445
+ epochMs: require_dist.number(),
22446
+ seq: require_dist.number().optional()
22334
22447
  }),
22335
22448
  require_dist.object({
22336
22449
  t: require_dist.literal("liveProfile"),
@@ -22537,6 +22650,7 @@ var ScrubDragStats = class {
22537
22650
  wholeReads = 0;
22538
22651
  readBytes = 0;
22539
22652
  parks = 0;
22653
+ ackTimeouts = 0;
22540
22654
  failures = 0;
22541
22655
  firstPushMs = null;
22542
22656
  creditEndedAt = null;
@@ -22583,6 +22697,10 @@ var ScrubDragStats = class {
22583
22697
  recordPark() {
22584
22698
  this.parks += 1;
22585
22699
  }
22700
+ /** Pushes written off after the ack timeout — dropped work, never silent. */
22701
+ recordAckTimeout(pushes) {
22702
+ this.ackTimeouts += pushes;
22703
+ }
22586
22704
  /** A swallowed `scrubTick` throw — the branch where a dark failure hides. */
22587
22705
  recordFailure() {
22588
22706
  this.failures += 1;
@@ -22632,6 +22750,7 @@ var ScrubDragStats = class {
22632
22750
  travel: this.travel,
22633
22751
  bytes: this.bytes,
22634
22752
  parks: this.parks,
22753
+ ackTimeouts: this.ackTimeouts,
22635
22754
  failures: this.failures,
22636
22755
  creditEndedAt: this.creditEndedAt,
22637
22756
  acks: ack.n,
@@ -22738,16 +22857,37 @@ var SCRUB_PREFETCH_DIR_THRESHOLD = 2;
22738
22857
  */
22739
22858
  var SCRUB_SWEEP_WINDOW_MS = 4e3;
22740
22859
  /**
22741
- * Receiver-credit cap for scrub pushes: at most this many keyframes may be
22742
- * OUTSTANDING (pushed onto the track but not yet acknowledged as RENDERED by
22743
- * the viewer via `scrubAck`). The coalescing window above shapes the INPUT; on
22744
- * a thin pipe it is not backpressure — pushing a ~45 KB keyframe every 60 ms
22745
- * floods a link that delivers one every 500 ms, RTP drops, and nothing paints.
22746
- * Backpressure is the receiver's: a push spends a credit, a rendered frame
22747
- * restores one, and with zero credit the newest target PARKS on
22748
- * `scrubPendingEpochMs` until an ack arrives a timer never releases work.
22860
+ * Receiver-credit cap for scrub pushes: at most this many PUSHES may be
22861
+ * OUTSTANDING (on the track, not yet acknowledged by the viewer via
22862
+ * `scrubAck`). The coalescing window above shapes the INPUT; on a thin pipe it
22863
+ * is not backpressure — pushing a ~45 KB keyframe every 60 ms floods a link
22864
+ * that delivers one every 500 ms, RTP drops, and nothing paints. Backpressure
22865
+ * is the receiver's: a push spends a credit, the first ack naming it restores
22866
+ * that credit, and with zero credit the newest target PARKS on
22867
+ * `scrubPendingEpochMs` until an ack (or {@link SCRUB_ACK_TIMEOUT_MS}) arrives.
22868
+ *
22869
+ * THE UNIT IS THE PUSH, NOT THE FRAME — and getting that wrong is what made a
22870
+ * slowed drag die. A push carries one AU in `jump` mode but a whole sweep (~25
22871
+ * AUs at 25 fps over a 1 s step) in `sweep` mode, while the viewer emits ONE
22872
+ * position per push. Charging one credit per push and repaying one per FRAME
22873
+ * meant two sweeps drained the cap against a viewer that could only ever send
22874
+ * two acks: the drag parked permanently at the exact moment the operator
22875
+ * slowed down to look at something.
22749
22876
  */
22750
22877
  var SCRUB_CREDIT_CAP = 2;
22878
+ /**
22879
+ * How long an outstanding push may go unacknowledged before the feeder writes
22880
+ * it off and takes its credit back.
22881
+ *
22882
+ * The credit gate is released by an ack and by nothing else — which is right
22883
+ * while acks flow and fatal when one is lost: the drag parks with no timer to
22884
+ * release it, and `beginScrub` (the only other reset) is a documented no-op
22885
+ * mid-drag. Generous on purpose: this is not pacing, it is the bound that
22886
+ * makes a lost ack cost one stalled tick instead of the rest of the gesture.
22887
+ * Every write-off is logged and counted (`ackTimeouts` on the drag census) —
22888
+ * dropped work is never silent.
22889
+ */
22890
+ var SCRUB_ACK_TIMEOUT_MS = 2e3;
22751
22891
  /** Minimum gap between two lines of the same pathological kind, per drag. */
22752
22892
  var SCRUB_PATHOLOGY_LOG_INTERVAL_MS = 1e3;
22753
22893
  /**
@@ -22845,13 +22985,27 @@ var RecordedFeeder = class {
22845
22985
  /** Remaining receiver credit for scrub pushes — see {@link SCRUB_CREDIT_CAP}. */
22846
22986
  scrubCredit = SCRUB_CREDIT_CAP;
22847
22987
  /**
22848
- * Frames still unrendered, per outstanding PUSH, oldest first. A jump enqueues
22849
- * `1`; a sweep enqueues however many predicted frames it put on the wire. Each
22850
- * `scrubAck` settles one frame off the head, and the credit that push spent
22851
- * comes back only when the head reaches zero — so a sweep cannot be refunded
22852
- * once per frame for the single credit it cost.
22988
+ * The pushes on the wire and not yet settled, OLDEST FIRST (and therefore
22989
+ * ascending in both `seq` and `pushedAtMs` every settle and every write-off
22990
+ * takes a prefix). One entry per push, whatever it carried: the first
22991
+ * `scrubAck` naming it returns its credit.
22853
22992
  */
22854
22993
  scrubOutstanding = [];
22994
+ /**
22995
+ * The push sequence the viewer echoes on `scrubAck`. Monotonic for the life of
22996
+ * the feeder — see {@link OutstandingPush} for why it must NOT restart per
22997
+ * drag.
22998
+ */
22999
+ scrubPushSeq = 0;
23000
+ /**
23001
+ * The write-off timer for the oldest outstanding push
23002
+ * ({@link SCRUB_ACK_TIMEOUT_MS}). Separate from `scrubTimer` on purpose: that
23003
+ * one is the coalescing slot, and an ack arriving while this is pending must
23004
+ * be able to schedule a leading-edge tick without waiting on it.
23005
+ */
23006
+ scrubAckTimer = null;
23007
+ /** One `scrub-feeder:ack-timeout` line per drag — the count is on the census. */
23008
+ scrubAckTimeoutLogged = false;
22855
23009
  /** The newest un-processed drag target (null when the tick cycle has drained). */
22856
23010
  scrubPendingEpochMs = null;
22857
23011
  /** The mapping hint that came with the newest target (latest-wins with it). */
@@ -22952,6 +23106,7 @@ var RecordedFeeder = class {
22952
23106
  this.scrubSegment = null;
22953
23107
  this.scrubCursor = null;
22954
23108
  this.scrubOutstanding = [];
23109
+ this.clearScrubAckTimeout();
22955
23110
  this.scrubPendingHint = null;
22956
23111
  this.scrubPrevTarget = null;
22957
23112
  this.scrubDirRun = 0;
@@ -23207,6 +23362,8 @@ var RecordedFeeder = class {
23207
23362
  this.scrubNoFootageLogged = false;
23208
23363
  this.scrubParkLogged = false;
23209
23364
  this.scrubOutstanding = [];
23365
+ this.clearScrubAckTimeout();
23366
+ this.scrubAckTimeoutLogged = false;
23210
23367
  this.scrubPendingHint = null;
23211
23368
  this.scrubStartedAtMs = performance.now();
23212
23369
  this.scrubStats = new ScrubDragStats(this.scrubStartedAtMs);
@@ -23233,28 +23390,97 @@ var RecordedFeeder = class {
23233
23390
  if (this.scrubTimer === null) this.scrubTimer = setTimeout(() => void this.scrubTick(), 0);
23234
23391
  }
23235
23392
  /**
23236
- * Receiver credit: the viewer RENDERED a scrub frame. Restores one push
23237
- * credit (cappedover-acking never banks a burst) and, when a target sat
23238
- * parked on an exhausted budget, resumes the tick. This not any timer — is
23239
- * what paces scrub pushes to what the link actually delivers.
23393
+ * Receiver credit: the viewer received a pushed scrub frame. Settles the push
23394
+ * `seq` namesand every older one still outstanding, since the channel is
23395
+ * ordered restores their credit (capped: over-acking never banks a burst)
23396
+ * and, when a target sat parked on an exhausted budget, resumes the tick.
23397
+ * This — not any timer — is what paces scrub pushes to what the link
23398
+ * actually delivers; {@link SCRUB_ACK_TIMEOUT_MS} is only the bound for when
23399
+ * an ack never comes.
23400
+ *
23401
+ * THE UNIT IS THE PUSH. A sweep puts ~25 AUs on the wire under ONE position
23402
+ * message, so a viewer without `requestVideoFrameCallback` can only ever send
23403
+ * ONE ack for it; the old per-FRAME settle waited for 25 and the drag parked
23404
+ * forever the moment the operator slowed down. A viewer WITH rvfc sends one
23405
+ * ack per rendered frame instead — those surplus acks all name the same
23406
+ * settled `seq` and are no-ops, which is what `seq` is for.
23407
+ *
23408
+ * A `seq` no outstanding push matches (a late ack from a drag that already
23409
+ * ended) banks nothing. An ack without `seq` comes from a viewer older than
23410
+ * the field: it settles the oldest outstanding push, which can only repay too
23411
+ * early — never strand the drag.
23240
23412
  */
23241
- scrubAck() {
23413
+ scrubAck(seq) {
23242
23414
  if (this.disposed) return;
23415
+ const settled = seq === void 0 ? this.scrubOutstanding.length > 0 ? 1 : 0 : this.scrubOutstanding.filter((p) => p.seq <= seq).length;
23416
+ if (settled === 0) return;
23417
+ const now = performance.now();
23418
+ for (const push of this.scrubOutstanding.slice(0, settled)) this.scrubStats?.recordAckRtt(Math.round(now - push.pushedAtMs));
23419
+ this.scrubOutstanding = this.scrubOutstanding.slice(settled);
23420
+ this.scrubCredit = Math.min(SCRUB_CREDIT_CAP, this.scrubCredit + settled);
23421
+ this.resumeScrubTick();
23422
+ }
23423
+ /**
23424
+ * Resume a parked drag: the newest target is still pending and the coalescing
23425
+ * slot is free, so run a leading-edge tick. Never touches a LIVE slot — a
23426
+ * pending re-arm is this tick cycle's own coalescing window and pre-empting it
23427
+ * would push faster than {@link SCRUB_COALESCE_MS}.
23428
+ */
23429
+ resumeScrubTick() {
23430
+ if (this.scrubbing && this.scrubPendingEpochMs !== null && this.scrubTimer === null) this.scrubTimer = setTimeout(() => void this.scrubTick(), 0);
23431
+ }
23432
+ /**
23433
+ * Arm the write-off timer for the OLDEST outstanding push, if one is not
23434
+ * already pending. Newer entries are always due later, so a timer armed for
23435
+ * an entry that gets settled first simply fires early and re-arms — one
23436
+ * harmless wakeup, no bookkeeping.
23437
+ */
23438
+ armScrubAckTimeout() {
23439
+ if (this.scrubAckTimer !== null) return;
23243
23440
  const head = this.scrubOutstanding[0];
23244
23441
  if (head === void 0) return;
23442
+ const dueInMs = Math.max(0, SCRUB_ACK_TIMEOUT_MS - (performance.now() - head.pushedAtMs));
23443
+ this.scrubAckTimer = setTimeout(() => {
23444
+ this.scrubAckTimer = null;
23445
+ this.expireScrubAcks();
23446
+ }, dueInMs);
23447
+ }
23448
+ /** Drop the ack timer (drag exit / teardown). */
23449
+ clearScrubAckTimeout() {
23450
+ if (this.scrubAckTimer === null) return;
23451
+ clearTimeout(this.scrubAckTimer);
23452
+ this.scrubAckTimer = null;
23453
+ }
23454
+ /**
23455
+ * Write off every push that has waited longer than
23456
+ * {@link SCRUB_ACK_TIMEOUT_MS}, give its credit back, and resume the drag.
23457
+ *
23458
+ * This is DROPPED WORK — a frame the viewer may never have painted — so it is
23459
+ * counted on the census every time and logged once per drag. Without it a
23460
+ * single lost ack ends the gesture: the gate is released by acks alone, and
23461
+ * `beginScrub` (its only other reset) is a no-op mid-drag.
23462
+ */
23463
+ expireScrubAcks() {
23464
+ if (this.disposed || !this.scrubbing) return;
23245
23465
  const now = performance.now();
23246
- if (head.firstAckAtMs === null) this.scrubStats?.recordAckRtt(Math.round(now - head.pushedAtMs));
23247
- if (head.frames > 1) {
23248
- this.scrubOutstanding = [{
23249
- frames: head.frames - 1,
23250
- pushedAtMs: head.pushedAtMs,
23251
- firstAckAtMs: head.firstAckAtMs ?? now
23252
- }, ...this.scrubOutstanding.slice(1)];
23253
- return;
23466
+ const expired = this.scrubOutstanding.filter((p) => now - p.pushedAtMs >= SCRUB_ACK_TIMEOUT_MS).length;
23467
+ if (expired > 0) {
23468
+ const frames = this.scrubOutstanding.slice(0, expired).reduce((sum, p) => sum + p.frames, 0);
23469
+ this.scrubOutstanding = this.scrubOutstanding.slice(expired);
23470
+ this.scrubCredit = Math.min(SCRUB_CREDIT_CAP, this.scrubCredit + expired);
23471
+ this.scrubStats?.recordAckTimeout(expired);
23472
+ if (!this.scrubAckTimeoutLogged) {
23473
+ this.scrubAckTimeoutLogged = true;
23474
+ this.deps.onLog?.("scrub-feeder:ack-timeout", {
23475
+ pushes: expired,
23476
+ frames,
23477
+ timeoutMs: SCRUB_ACK_TIMEOUT_MS,
23478
+ pendingEpochMs: this.scrubPendingEpochMs
23479
+ });
23480
+ }
23481
+ this.resumeScrubTick();
23254
23482
  }
23255
- this.scrubOutstanding = this.scrubOutstanding.slice(1);
23256
- this.scrubCredit = Math.min(SCRUB_CREDIT_CAP, this.scrubCredit + 1);
23257
- if (this.scrubbing && this.scrubPendingEpochMs !== null && this.scrubTimer === null) this.scrubTimer = setTimeout(() => void this.scrubTick(), 0);
23483
+ this.armScrubAckTimeout();
23258
23484
  }
23259
23485
  /**
23260
23486
  * One coalesced feeder-scrub push. Captures the newest pending target + the
@@ -23427,12 +23653,14 @@ var RecordedFeeder = class {
23427
23653
  else if (crossesFragment && this.clockHasAdvanced) this.clock.markSeek();
23428
23654
  for (const au of aus) this.deps.sink.pushAccessUnit(au.data, this.clock.stamp(au.ptsMs), au.codec);
23429
23655
  const pushedAtMs = performance.now();
23656
+ const pushSeq = ++this.scrubPushSeq;
23430
23657
  this.scrubOutstanding = [...this.scrubOutstanding, {
23658
+ seq: pushSeq,
23431
23659
  frames: jumpTravel.length + aus.length,
23432
- pushedAtMs,
23433
- firstAckAtMs: null
23660
+ pushedAtMs
23434
23661
  }];
23435
23662
  this.scrubCredit -= 1;
23663
+ this.armScrubAckTimeout();
23436
23664
  this.clockHasAdvanced = true;
23437
23665
  let runBytes = 0;
23438
23666
  for (const s of jumpTravel) runBytes += s.au.data.length;
@@ -23479,7 +23707,7 @@ var RecordedFeeder = class {
23479
23707
  tickMs: Math.round(pushedAtMs - tickStartMs)
23480
23708
  });
23481
23709
  }
23482
- this.deps.onPosition(this.clampIntoSegment(seg, effTarget));
23710
+ this.deps.onPosition(this.clampIntoSegment(seg, effTarget), pushSeq);
23483
23711
  this.maybeScrubPrefetch(seg, effTarget, gen);
23484
23712
  } catch (err) {
23485
23713
  this.scrubStats?.recordFailure();
@@ -24192,6 +24420,7 @@ var RecordedFeeder = class {
24192
24420
  this.scrubNoFootageLogged = false;
24193
24421
  this.scrubParkLogged = false;
24194
24422
  this.scrubOutstanding = [];
24423
+ this.clearScrubAckTimeout();
24195
24424
  this.scrubPendingHint = null;
24196
24425
  if (this.scrubTimer) {
24197
24426
  clearTimeout(this.scrubTimer);
@@ -24271,7 +24500,7 @@ var TimelineSession = class {
24271
24500
  break;
24272
24501
  }
24273
24502
  case "scrubAck":
24274
- if (this.mode === "recorded") this.feeder?.scrubAck();
24503
+ if (this.mode === "recorded") this.feeder?.scrubAck(msg.seq);
24275
24504
  break;
24276
24505
  case "setRate":
24277
24506
  this.rate = msg.rate;
@@ -24319,12 +24548,18 @@ var TimelineSession = class {
24319
24548
  state
24320
24549
  }));
24321
24550
  }
24322
- /** Emit seam: the broker wires the feeder's onPosition callback to this. */
24323
- _emitPosition(epochMs) {
24551
+ /** Emit seam: the broker wires the feeder's onPosition callback to this.
24552
+ * `pushSeq` rides along only on the position a scrub push emitted — the
24553
+ * viewer echoes it on `scrubAck` so the credit is repaid to the right push. */
24554
+ _emitPosition(epochMs, pushSeq) {
24324
24555
  this.lastPositionMs = epochMs;
24325
- this.deps.session.sendControl(serializeServerMessage({
24556
+ this.deps.session.sendControl(serializeServerMessage(pushSeq === void 0 ? {
24326
24557
  t: "position",
24327
24558
  epochMs
24559
+ } : {
24560
+ t: "position",
24561
+ epochMs,
24562
+ seq: pushSeq
24328
24563
  }));
24329
24564
  }
24330
24565
  emitLiveProfile() {
@@ -33002,7 +33237,7 @@ var BrokerWebrtcServer = class {
33002
33237
  } });
33003
33238
  timeline._emitState(s);
33004
33239
  },
33005
- onPosition: (epochMs) => timeline._emitPosition(epochMs),
33240
+ onPosition: (epochMs, pushSeq) => timeline._emitPosition(epochMs, pushSeq),
33006
33241
  onLog: (msg, data) => sessionLogger.info(msg, {
33007
33242
  tags: { deviceId },
33008
33243
  meta: {