lox-airplay-sender 0.3.2 → 0.3.4

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.
@@ -31,10 +31,16 @@ class AudioOut extends node_events_1.EventEmitter {
31
31
  typeof startTimeMs === 'number' && Number.isFinite(startTimeMs)
32
32
  ? startTimeMs
33
33
  : undefined;
34
- const wallToMonoOffset = Date.now() - node_perf_hooks_1.performance.now();
35
- // Anchor the RTP clock to a monotonic base to avoid NTP slews.
36
- this.rtpTimeRef = (this.startTimeMs ?? Date.now()) - wallToMonoOffset;
37
- this.monotonicRef = node_perf_hooks_1.performance.now();
34
+ if (config_1.default.use_monotonic_clock) {
35
+ const wallToMonoOffset = Date.now() - node_perf_hooks_1.performance.now();
36
+ // Anchor the RTP clock to a monotonic base to avoid NTP slews.
37
+ this.rtpTimeRef = (this.startTimeMs ?? Date.now()) - wallToMonoOffset;
38
+ this.monotonicRef = node_perf_hooks_1.performance.now();
39
+ }
40
+ else {
41
+ this.rtpTimeRef = this.startTimeMs ?? Date.now();
42
+ this.monotonicRef = 0;
43
+ }
38
44
  devices.on('airtunes_devices', (hasAirTunes) => {
39
45
  this.hasAirTunes = hasAirTunes;
40
46
  });
@@ -47,9 +53,10 @@ class AudioOut extends node_events_1.EventEmitter {
47
53
  packet.timestamp = (0, numUtil_1.low32)(seq * config_1.default.frames_per_packet + 2 * config_1.default.sampling_rate);
48
54
  if (this.hasAirTunes && seq % config_1.default.sync_period === 0) {
49
55
  this.emit('need_sync', seq);
56
+ const nowMs = config_1.default.use_monotonic_clock ? node_perf_hooks_1.performance.now() : Date.now();
50
57
  const expectedTimeMs = this.rtpTimeRef +
51
58
  ((seq * config_1.default.frames_per_packet) / config_1.default.sampling_rate) * 1000;
52
- const deltaMs = Date.now() - expectedTimeMs;
59
+ const deltaMs = nowMs - expectedTimeMs;
53
60
  this.emit('metrics', { type: 'sync', seq, deltaMs, latencyFrames: this.latencyFrames });
54
61
  }
55
62
  this.emit('packet', packet);
@@ -57,7 +64,7 @@ class AudioOut extends node_events_1.EventEmitter {
57
64
  };
58
65
  const frameDurationMs = (config_1.default.frames_per_packet / config_1.default.sampling_rate) * 1000;
59
66
  const syncAudio = () => {
60
- const nowMs = node_perf_hooks_1.performance.now();
67
+ const nowMs = config_1.default.use_monotonic_clock ? node_perf_hooks_1.performance.now() : Date.now();
61
68
  const elapsed = nowMs - this.rtpTimeRef;
62
69
  if (elapsed < 0) {
63
70
  setTimeout(syncAudio, Math.min(config_1.default.stream_latency, Math.abs(elapsed)));
@@ -65,15 +72,17 @@ class AudioOut extends node_events_1.EventEmitter {
65
72
  }
66
73
  let currentSeq = Math.floor((elapsed * config_1.default.sampling_rate) / (config_1.default.frames_per_packet * 1000));
67
74
  // If we're lagging behind significantly, jump forward to avoid long hitches.
68
- const expectedTimeMs = this.rtpTimeRef + currentSeq * frameDurationMs;
69
- const deltaMs = nowMs - expectedTimeMs;
70
- if (deltaMs > config_1.default.jump_forward_threshold_ms) {
71
- const jumpSeq = Math.ceil((config_1.default.jump_forward_lead_ms * config_1.default.sampling_rate) /
72
- (config_1.default.frames_per_packet * 1000));
73
- const newSeq = currentSeq + jumpSeq;
74
- this.rtpTimeRef = nowMs - newSeq * frameDurationMs;
75
- this.lastSeq = newSeq - 1;
76
- currentSeq = newSeq;
75
+ if (config_1.default.jump_forward_enabled) {
76
+ const expectedTimeMs = this.rtpTimeRef + currentSeq * frameDurationMs;
77
+ const deltaMs = nowMs - expectedTimeMs;
78
+ if (deltaMs > config_1.default.jump_forward_threshold_ms) {
79
+ const jumpSeq = Math.ceil((config_1.default.jump_forward_lead_ms * config_1.default.sampling_rate) /
80
+ (config_1.default.frames_per_packet * 1000));
81
+ const newSeq = currentSeq + jumpSeq;
82
+ this.rtpTimeRef = nowMs - newSeq * frameDurationMs;
83
+ this.lastSeq = newSeq - 1;
84
+ currentSeq = newSeq;
85
+ }
77
86
  }
78
87
  for (let i = this.lastSeq + 1; i <= currentSeq; i += 1) {
79
88
  sendPacket(i);
package/dist/core/rtsp.js CHANGED
@@ -1636,7 +1636,8 @@ Client.prototype.processData = function (blob, rawData) {
1636
1636
  ;
1637
1637
  break;
1638
1638
  case SETPROGRESS:
1639
- this.status = this.airplay2 ? FLUSH : PLAYING;
1639
+ // After reporting progress, stay in PLAYING; avoid forcing FLUSH on every update.
1640
+ this.status = PLAYING;
1640
1641
  break;
1641
1642
  case SETDAAP:
1642
1643
  this.status = PLAYING;
@@ -31,10 +31,16 @@ class AudioOut extends node_events_1.EventEmitter {
31
31
  typeof startTimeMs === 'number' && Number.isFinite(startTimeMs)
32
32
  ? startTimeMs
33
33
  : undefined;
34
- const wallToMonoOffset = Date.now() - node_perf_hooks_1.performance.now();
35
- // Anchor the RTP clock to a monotonic base to avoid NTP slews.
36
- this.rtpTimeRef = (this.startTimeMs ?? Date.now()) - wallToMonoOffset;
37
- this.monotonicRef = node_perf_hooks_1.performance.now();
34
+ if (config_1.default.use_monotonic_clock) {
35
+ const wallToMonoOffset = Date.now() - node_perf_hooks_1.performance.now();
36
+ // Anchor the RTP clock to a monotonic base to avoid NTP slews.
37
+ this.rtpTimeRef = (this.startTimeMs ?? Date.now()) - wallToMonoOffset;
38
+ this.monotonicRef = node_perf_hooks_1.performance.now();
39
+ }
40
+ else {
41
+ this.rtpTimeRef = this.startTimeMs ?? Date.now();
42
+ this.monotonicRef = 0;
43
+ }
38
44
  devices.on('airtunes_devices', (hasAirTunes) => {
39
45
  this.hasAirTunes = hasAirTunes;
40
46
  });
@@ -47,9 +53,10 @@ class AudioOut extends node_events_1.EventEmitter {
47
53
  packet.timestamp = (0, numUtil_1.low32)(seq * config_1.default.frames_per_packet + 2 * config_1.default.sampling_rate);
48
54
  if (this.hasAirTunes && seq % config_1.default.sync_period === 0) {
49
55
  this.emit('need_sync', seq);
56
+ const nowMs = config_1.default.use_monotonic_clock ? node_perf_hooks_1.performance.now() : Date.now();
50
57
  const expectedTimeMs = this.rtpTimeRef +
51
58
  ((seq * config_1.default.frames_per_packet) / config_1.default.sampling_rate) * 1000;
52
- const deltaMs = Date.now() - expectedTimeMs;
59
+ const deltaMs = nowMs - expectedTimeMs;
53
60
  this.emit('metrics', { type: 'sync', seq, deltaMs, latencyFrames: this.latencyFrames });
54
61
  }
55
62
  this.emit('packet', packet);
@@ -57,7 +64,7 @@ class AudioOut extends node_events_1.EventEmitter {
57
64
  };
58
65
  const frameDurationMs = (config_1.default.frames_per_packet / config_1.default.sampling_rate) * 1000;
59
66
  const syncAudio = () => {
60
- const nowMs = node_perf_hooks_1.performance.now();
67
+ const nowMs = config_1.default.use_monotonic_clock ? node_perf_hooks_1.performance.now() : Date.now();
61
68
  const elapsed = nowMs - this.rtpTimeRef;
62
69
  if (elapsed < 0) {
63
70
  setTimeout(syncAudio, Math.min(config_1.default.stream_latency, Math.abs(elapsed)));
@@ -65,15 +72,17 @@ class AudioOut extends node_events_1.EventEmitter {
65
72
  }
66
73
  let currentSeq = Math.floor((elapsed * config_1.default.sampling_rate) / (config_1.default.frames_per_packet * 1000));
67
74
  // If we're lagging behind significantly, jump forward to avoid long hitches.
68
- const expectedTimeMs = this.rtpTimeRef + currentSeq * frameDurationMs;
69
- const deltaMs = nowMs - expectedTimeMs;
70
- if (deltaMs > config_1.default.jump_forward_threshold_ms) {
71
- const jumpSeq = Math.ceil((config_1.default.jump_forward_lead_ms * config_1.default.sampling_rate) /
72
- (config_1.default.frames_per_packet * 1000));
73
- const newSeq = currentSeq + jumpSeq;
74
- this.rtpTimeRef = nowMs - newSeq * frameDurationMs;
75
- this.lastSeq = newSeq - 1;
76
- currentSeq = newSeq;
75
+ if (config_1.default.jump_forward_enabled) {
76
+ const expectedTimeMs = this.rtpTimeRef + currentSeq * frameDurationMs;
77
+ const deltaMs = nowMs - expectedTimeMs;
78
+ if (deltaMs > config_1.default.jump_forward_threshold_ms) {
79
+ const jumpSeq = Math.ceil((config_1.default.jump_forward_lead_ms * config_1.default.sampling_rate) /
80
+ (config_1.default.frames_per_packet * 1000));
81
+ const newSeq = currentSeq + jumpSeq;
82
+ this.rtpTimeRef = nowMs - newSeq * frameDurationMs;
83
+ this.lastSeq = newSeq - 1;
84
+ currentSeq = newSeq;
85
+ }
77
86
  }
78
87
  for (let i = this.lastSeq + 1; i <= currentSeq; i += 1) {
79
88
  sendPacket(i);
@@ -1636,7 +1636,8 @@ Client.prototype.processData = function (blob, rawData) {
1636
1636
  ;
1637
1637
  break;
1638
1638
  case SETPROGRESS:
1639
- this.status = this.airplay2 ? FLUSH : PLAYING;
1639
+ // After reporting progress, stay in PLAYING; avoid forcing FLUSH on every update.
1640
+ this.status = PLAYING;
1640
1641
  break;
1641
1642
  case SETDAAP:
1642
1643
  this.status = PLAYING;
@@ -27,6 +27,8 @@ exports.config = {
27
27
  rtsp_retry_jitter_ms: 150,
28
28
  control_sync_base_delay_ms: 2,
29
29
  control_sync_jitter_ms: 3,
30
+ use_monotonic_clock: false,
31
+ jump_forward_enabled: false,
30
32
  jump_forward_threshold_ms: 180,
31
33
  jump_forward_lead_ms: 220,
32
34
  device_magic: (0, numUtil_1.randomInt)(9),
@@ -22,6 +22,8 @@ export interface AirplayConfig {
22
22
  rtsp_retry_jitter_ms: number;
23
23
  control_sync_base_delay_ms: number;
24
24
  control_sync_jitter_ms: number;
25
+ use_monotonic_clock: boolean;
26
+ jump_forward_enabled: boolean;
25
27
  jump_forward_threshold_ms: number;
26
28
  jump_forward_lead_ms: number;
27
29
  device_magic: number;
@@ -27,6 +27,8 @@ exports.config = {
27
27
  rtsp_retry_jitter_ms: 150,
28
28
  control_sync_base_delay_ms: 2,
29
29
  control_sync_jitter_ms: 3,
30
+ use_monotonic_clock: false,
31
+ jump_forward_enabled: false,
30
32
  jump_forward_threshold_ms: 180,
31
33
  jump_forward_lead_ms: 220,
32
34
  device_magic: (0, numUtil_1.randomInt)(9),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lox-airplay-sender",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "AirPlay sender (RAOP/AirPlay 1 + AirPlay 2 auth flows) ",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",