lox-airplay-sender 0.3.3 → 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,7 +53,7 @@ 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);
50
- const nowMs = node_perf_hooks_1.performance.now();
56
+ const nowMs = config_1.default.use_monotonic_clock ? node_perf_hooks_1.performance.now() : Date.now();
51
57
  const expectedTimeMs = this.rtpTimeRef +
52
58
  ((seq * config_1.default.frames_per_packet) / config_1.default.sampling_rate) * 1000;
53
59
  const deltaMs = nowMs - expectedTimeMs;
@@ -58,7 +64,7 @@ class AudioOut extends node_events_1.EventEmitter {
58
64
  };
59
65
  const frameDurationMs = (config_1.default.frames_per_packet / config_1.default.sampling_rate) * 1000;
60
66
  const syncAudio = () => {
61
- 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();
62
68
  const elapsed = nowMs - this.rtpTimeRef;
63
69
  if (elapsed < 0) {
64
70
  setTimeout(syncAudio, Math.min(config_1.default.stream_latency, Math.abs(elapsed)));
@@ -66,15 +72,17 @@ class AudioOut extends node_events_1.EventEmitter {
66
72
  }
67
73
  let currentSeq = Math.floor((elapsed * config_1.default.sampling_rate) / (config_1.default.frames_per_packet * 1000));
68
74
  // If we're lagging behind significantly, jump forward to avoid long hitches.
69
- const expectedTimeMs = this.rtpTimeRef + currentSeq * frameDurationMs;
70
- const deltaMs = nowMs - expectedTimeMs;
71
- if (deltaMs > config_1.default.jump_forward_threshold_ms) {
72
- const jumpSeq = Math.ceil((config_1.default.jump_forward_lead_ms * config_1.default.sampling_rate) /
73
- (config_1.default.frames_per_packet * 1000));
74
- const newSeq = currentSeq + jumpSeq;
75
- this.rtpTimeRef = nowMs - newSeq * frameDurationMs;
76
- this.lastSeq = newSeq - 1;
77
- 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
+ }
78
86
  }
79
87
  for (let i = this.lastSeq + 1; i <= currentSeq; i += 1) {
80
88
  sendPacket(i);
@@ -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,7 +53,7 @@ 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);
50
- const nowMs = node_perf_hooks_1.performance.now();
56
+ const nowMs = config_1.default.use_monotonic_clock ? node_perf_hooks_1.performance.now() : Date.now();
51
57
  const expectedTimeMs = this.rtpTimeRef +
52
58
  ((seq * config_1.default.frames_per_packet) / config_1.default.sampling_rate) * 1000;
53
59
  const deltaMs = nowMs - expectedTimeMs;
@@ -58,7 +64,7 @@ class AudioOut extends node_events_1.EventEmitter {
58
64
  };
59
65
  const frameDurationMs = (config_1.default.frames_per_packet / config_1.default.sampling_rate) * 1000;
60
66
  const syncAudio = () => {
61
- 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();
62
68
  const elapsed = nowMs - this.rtpTimeRef;
63
69
  if (elapsed < 0) {
64
70
  setTimeout(syncAudio, Math.min(config_1.default.stream_latency, Math.abs(elapsed)));
@@ -66,15 +72,17 @@ class AudioOut extends node_events_1.EventEmitter {
66
72
  }
67
73
  let currentSeq = Math.floor((elapsed * config_1.default.sampling_rate) / (config_1.default.frames_per_packet * 1000));
68
74
  // If we're lagging behind significantly, jump forward to avoid long hitches.
69
- const expectedTimeMs = this.rtpTimeRef + currentSeq * frameDurationMs;
70
- const deltaMs = nowMs - expectedTimeMs;
71
- if (deltaMs > config_1.default.jump_forward_threshold_ms) {
72
- const jumpSeq = Math.ceil((config_1.default.jump_forward_lead_ms * config_1.default.sampling_rate) /
73
- (config_1.default.frames_per_packet * 1000));
74
- const newSeq = currentSeq + jumpSeq;
75
- this.rtpTimeRef = nowMs - newSeq * frameDurationMs;
76
- this.lastSeq = newSeq - 1;
77
- 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
+ }
78
86
  }
79
87
  for (let i = this.lastSeq + 1; i <= currentSeq; i += 1) {
80
88
  sendPacket(i);
@@ -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.3",
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",