@apocaliss92/nodelink-js 0.6.6 → 0.6.7

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.
@@ -6433,6 +6433,38 @@ function createRtspFlow(transport, videoType) {
6433
6433
  return new H265Flow(transport);
6434
6434
  }
6435
6435
 
6436
+ // src/baichuan/stream/rtpVideoTimestamp.ts
6437
+ var U32 = 4294967296;
6438
+ var DEFAULT_VIDEO_CLOCK_RATE = 9e4;
6439
+ function deriveRtpVideoTimestamp(state, frameMicroseconds, clockRate = DEFAULT_VIDEO_CLOCK_RATE) {
6440
+ if (frameMicroseconds === null || frameMicroseconds === void 0 || !Number.isFinite(frameMicroseconds)) {
6441
+ return { timestamp: state.timestamp, state };
6442
+ }
6443
+ const curRaw = frameMicroseconds >>> 0;
6444
+ if (state.baseUnwrappedUs === void 0) {
6445
+ return {
6446
+ timestamp: state.timestamp,
6447
+ state: {
6448
+ ...state,
6449
+ unwrappedUs: curRaw,
6450
+ lastRawUs: curRaw,
6451
+ baseUnwrappedUs: curRaw,
6452
+ baseTimestamp: state.timestamp
6453
+ }
6454
+ };
6455
+ }
6456
+ const lastRaw = state.lastRawUs ?? curRaw;
6457
+ let forwardDelta = curRaw - lastRaw >>> 0;
6458
+ if (forwardDelta > U32 / 2) forwardDelta = 0;
6459
+ const unwrappedUs = (state.unwrappedUs ?? curRaw) + forwardDelta;
6460
+ const deltaUs = unwrappedUs - state.baseUnwrappedUs;
6461
+ const timestamp = state.baseTimestamp + Math.round(deltaUs * clockRate / 1e6) >>> 0;
6462
+ return {
6463
+ timestamp,
6464
+ state: { ...state, unwrappedUs, lastRawUs: curRaw, timestamp }
6465
+ };
6466
+ }
6467
+
6436
6468
  // src/baichuan/stream/BaichuanRtspServer.ts
6437
6469
  var AsyncBoundedQueue = class {
6438
6470
  maxItems;
@@ -7005,7 +7037,10 @@ var BaichuanRtspServer = class _BaichuanRtspServer extends EventEmitter4 {
7005
7037
  let useTcpInterleaved = false;
7006
7038
  let clientUdpSocket = null;
7007
7039
  let clientUdpSocketAudio = null;
7040
+ let cleanedUp = false;
7008
7041
  const cleanup = () => {
7042
+ if (cleanedUp) return;
7043
+ cleanedUp = true;
7009
7044
  const sessionDurationMs = Date.now() - connectTime;
7010
7045
  const res = this.clientResources.get(clientId);
7011
7046
  const framesSent = res?.framesSent ?? 0;
@@ -7753,22 +7788,25 @@ var BaichuanRtspServer = class _BaichuanRtspServer extends EventEmitter4 {
7753
7788
  resources.rtpVideoTimestamp = 0;
7754
7789
  if (resources.rtpVideoBaseTimestamp === void 0)
7755
7790
  resources.rtpVideoBaseTimestamp = resources.rtpVideoTimestamp;
7756
- if (resources.rtpVideoBaseMicroseconds === void 0) {
7791
+ const { timestamp, state } = deriveRtpVideoTimestamp(
7792
+ {
7793
+ timestamp: resources.rtpVideoTimestamp,
7794
+ baseTimestamp: resources.rtpVideoBaseTimestamp,
7795
+ unwrappedUs: resources.rtpVideoUnwrappedUs,
7796
+ lastRawUs: resources.rtpVideoLastRawUs,
7797
+ baseUnwrappedUs: resources.rtpVideoBaseUnwrappedUs
7798
+ },
7799
+ frameMicroseconds,
7800
+ videoClockRate
7801
+ );
7802
+ resources.rtpVideoTimestamp = timestamp;
7803
+ resources.rtpVideoBaseTimestamp = state.baseTimestamp;
7804
+ resources.rtpVideoUnwrappedUs = state.unwrappedUs;
7805
+ resources.rtpVideoLastRawUs = state.lastRawUs;
7806
+ resources.rtpVideoBaseUnwrappedUs = state.baseUnwrappedUs;
7807
+ resources.rtpVideoLastTimestamp = timestamp;
7808
+ if (resources.rtpVideoBaseMicroseconds === void 0)
7757
7809
  resources.rtpVideoBaseMicroseconds = frameMicroseconds >>> 0;
7758
- resources.rtpVideoLastTimestamp = resources.rtpVideoTimestamp;
7759
- return;
7760
- }
7761
- const baseUs = resources.rtpVideoBaseMicroseconds >>> 0;
7762
- const curUs = frameMicroseconds >>> 0;
7763
- const deltaUs = curUs - baseUs >>> 0;
7764
- const baseTs = (resources.rtpVideoBaseTimestamp ?? 0) >>> 0;
7765
- let ts = baseTs + Math.round(deltaUs * videoClockRate / 1e6) >>> 0;
7766
- const last = resources.rtpVideoLastTimestamp;
7767
- if (last !== void 0 && ts <= last >>> 0) {
7768
- ts = (last >>> 0) + 1 >>> 0;
7769
- }
7770
- resources.rtpVideoTimestamp = ts;
7771
- resources.rtpVideoLastTimestamp = ts;
7772
7810
  };
7773
7811
  const sendVideoAccessUnit = (videoType, accessUnitAnnexB, advanceTimestamp = true) => {
7774
7812
  const nals = _BaichuanRtspServer.splitAnnexBNals(accessUnitAnnexB);
@@ -26052,4 +26090,4 @@ export {
26052
26090
  tcpReachabilityProbe,
26053
26091
  autoDetectDeviceType
26054
26092
  };
26055
- //# sourceMappingURL=chunk-JQ5NSEVD.js.map
26093
+ //# sourceMappingURL=chunk-T22QCNBR.js.map