lox-airplay-sender 0.3.1 → 0.3.2
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/core/audioOut.d.ts
CHANGED
package/dist/core/audioOut.js
CHANGED
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const node_events_1 = require("node:events");
|
|
7
|
+
const node_perf_hooks_1 = require("node:perf_hooks");
|
|
7
8
|
const config_1 = __importDefault(require("../utils/config"));
|
|
8
9
|
const numUtil_1 = require("../utils/numUtil");
|
|
9
10
|
const SEQ_NUM_WRAP = Math.pow(2, 16);
|
|
@@ -14,7 +15,8 @@ const SEQ_NUM_WRAP = Math.pow(2, 16);
|
|
|
14
15
|
class AudioOut extends node_events_1.EventEmitter {
|
|
15
16
|
lastSeq = -1;
|
|
16
17
|
hasAirTunes = false;
|
|
17
|
-
rtpTimeRef =
|
|
18
|
+
rtpTimeRef = 0;
|
|
19
|
+
monotonicRef = 0;
|
|
18
20
|
startTimeMs;
|
|
19
21
|
latencyFrames = 0;
|
|
20
22
|
latencyApplied = false;
|
|
@@ -29,7 +31,10 @@ class AudioOut extends node_events_1.EventEmitter {
|
|
|
29
31
|
typeof startTimeMs === 'number' && Number.isFinite(startTimeMs)
|
|
30
32
|
? startTimeMs
|
|
31
33
|
: undefined;
|
|
32
|
-
|
|
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();
|
|
33
38
|
devices.on('airtunes_devices', (hasAirTunes) => {
|
|
34
39
|
this.hasAirTunes = hasAirTunes;
|
|
35
40
|
});
|
|
@@ -50,13 +55,26 @@ class AudioOut extends node_events_1.EventEmitter {
|
|
|
50
55
|
this.emit('packet', packet);
|
|
51
56
|
packet.release();
|
|
52
57
|
};
|
|
58
|
+
const frameDurationMs = (config_1.default.frames_per_packet / config_1.default.sampling_rate) * 1000;
|
|
53
59
|
const syncAudio = () => {
|
|
54
|
-
const
|
|
60
|
+
const nowMs = node_perf_hooks_1.performance.now();
|
|
61
|
+
const elapsed = nowMs - this.rtpTimeRef;
|
|
55
62
|
if (elapsed < 0) {
|
|
56
63
|
setTimeout(syncAudio, Math.min(config_1.default.stream_latency, Math.abs(elapsed)));
|
|
57
64
|
return;
|
|
58
65
|
}
|
|
59
|
-
|
|
66
|
+
let currentSeq = Math.floor((elapsed * config_1.default.sampling_rate) / (config_1.default.frames_per_packet * 1000));
|
|
67
|
+
// 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;
|
|
77
|
+
}
|
|
60
78
|
for (let i = this.lastSeq + 1; i <= currentSeq; i += 1) {
|
|
61
79
|
sendPacket(i);
|
|
62
80
|
}
|
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const node_events_1 = require("node:events");
|
|
7
|
+
const node_perf_hooks_1 = require("node:perf_hooks");
|
|
7
8
|
const config_1 = __importDefault(require("../utils/config"));
|
|
8
9
|
const numUtil_1 = require("../utils/numUtil");
|
|
9
10
|
const SEQ_NUM_WRAP = Math.pow(2, 16);
|
|
@@ -14,7 +15,8 @@ const SEQ_NUM_WRAP = Math.pow(2, 16);
|
|
|
14
15
|
class AudioOut extends node_events_1.EventEmitter {
|
|
15
16
|
lastSeq = -1;
|
|
16
17
|
hasAirTunes = false;
|
|
17
|
-
rtpTimeRef =
|
|
18
|
+
rtpTimeRef = 0;
|
|
19
|
+
monotonicRef = 0;
|
|
18
20
|
startTimeMs;
|
|
19
21
|
latencyFrames = 0;
|
|
20
22
|
latencyApplied = false;
|
|
@@ -29,7 +31,10 @@ class AudioOut extends node_events_1.EventEmitter {
|
|
|
29
31
|
typeof startTimeMs === 'number' && Number.isFinite(startTimeMs)
|
|
30
32
|
? startTimeMs
|
|
31
33
|
: undefined;
|
|
32
|
-
|
|
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();
|
|
33
38
|
devices.on('airtunes_devices', (hasAirTunes) => {
|
|
34
39
|
this.hasAirTunes = hasAirTunes;
|
|
35
40
|
});
|
|
@@ -50,13 +55,26 @@ class AudioOut extends node_events_1.EventEmitter {
|
|
|
50
55
|
this.emit('packet', packet);
|
|
51
56
|
packet.release();
|
|
52
57
|
};
|
|
58
|
+
const frameDurationMs = (config_1.default.frames_per_packet / config_1.default.sampling_rate) * 1000;
|
|
53
59
|
const syncAudio = () => {
|
|
54
|
-
const
|
|
60
|
+
const nowMs = node_perf_hooks_1.performance.now();
|
|
61
|
+
const elapsed = nowMs - this.rtpTimeRef;
|
|
55
62
|
if (elapsed < 0) {
|
|
56
63
|
setTimeout(syncAudio, Math.min(config_1.default.stream_latency, Math.abs(elapsed)));
|
|
57
64
|
return;
|
|
58
65
|
}
|
|
59
|
-
|
|
66
|
+
let currentSeq = Math.floor((elapsed * config_1.default.sampling_rate) / (config_1.default.frames_per_packet * 1000));
|
|
67
|
+
// 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;
|
|
77
|
+
}
|
|
60
78
|
for (let i = this.lastSeq + 1; i <= currentSeq; i += 1) {
|
|
61
79
|
sendPacket(i);
|
|
62
80
|
}
|
package/dist/esm/utils/config.js
CHANGED
|
@@ -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
|
+
jump_forward_threshold_ms: 180,
|
|
31
|
+
jump_forward_lead_ms: 220,
|
|
30
32
|
device_magic: (0, numUtil_1.randomInt)(9),
|
|
31
33
|
ntp_epoch: 0x83aa7e80,
|
|
32
34
|
iv_base64: 'ePRBLI0XN5ArFaaz7ncNZw',
|
package/dist/utils/config.d.ts
CHANGED
|
@@ -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
|
+
jump_forward_threshold_ms: number;
|
|
26
|
+
jump_forward_lead_ms: number;
|
|
25
27
|
device_magic: number;
|
|
26
28
|
ntp_epoch: number;
|
|
27
29
|
iv_base64: string;
|
package/dist/utils/config.js
CHANGED
|
@@ -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
|
+
jump_forward_threshold_ms: 180,
|
|
31
|
+
jump_forward_lead_ms: 220,
|
|
30
32
|
device_magic: (0, numUtil_1.randomInt)(9),
|
|
31
33
|
ntp_epoch: 0x83aa7e80,
|
|
32
34
|
iv_base64: 'ePRBLI0XN5ArFaaz7ncNZw',
|