mirror of
https://github.com/R0m1k3/xtremflow.git
synced 2026-10-22 22:48:04 +02:00
perf(player): switch to Buffer-First strategy to eliminate chaotic startup and micro-cuts
This commit is contained in:
1 parent
118887ab6f
commit
893ae7b03a
3 files changed
+69
-38
No files matched your search
+34
-14
@@ -255,23 +255,32 @@
|
|||||||
const hls = new Hls({
|
const hls = new Hls({
|
||||||
maxBufferLength: 120,
|
maxBufferLength: 120,
|
||||||
enableWorker: true,
|
enableWorker: true,
|
||||||
liveSyncDurationCount: 6, // Slightly more buffer for micro-cut protection
|
liveSyncDurationCount: 10, // Buffer-First: 10 segments safety margin
|
||||||
nudgeOffset: 0.6, // More aggressive jump over corrupted frames
|
liveMaxLatencyDurationCount: 20,
|
||||||
nudgeMaxRetries: 25,
|
nudgeOffset: 0.8, // More aggressive jump over corrupted frames
|
||||||
maxLiveSyncPlaybackRate: 1.15,
|
nudgeMaxRetries: 30,
|
||||||
// Turbo-Start specific
|
maxLiveSyncPlaybackRate: 1.1, // Slower catch-up to avoid chaos
|
||||||
startLevel: 0,
|
// Stabilization
|
||||||
initialLiveManifestSize: 1,
|
initialLiveManifestSize: 3, // Wait for more segments before starting
|
||||||
abrEwmaDefaultEstimate: 700000,
|
abrEwmaDefaultEstimate: 1000000,
|
||||||
manifestLoadingRetryDelay: 500,
|
manifestLoadingRetryDelay: 1000,
|
||||||
levelLoadingRetryDelay: 500
|
levelLoadingRetryDelay: 1000
|
||||||
});
|
});
|
||||||
window.hlsInstance = hls;
|
window.hlsInstance = hls;
|
||||||
hls.loadSource(url);
|
hls.loadSource(url);
|
||||||
hls.attachMedia(video);
|
hls.attachMedia(video);
|
||||||
hls.on(Hls.Events.MANIFEST_PARSED, () => {
|
hls.on(Hls.Events.MANIFEST_PARSED, () => {
|
||||||
hideLoading();
|
hideLoading();
|
||||||
video.play().catch(() => playOverlay.style.display = 'flex');
|
// Wait for a small buffer before playing to avoid chaos
|
||||||
|
const checkBuffer = setInterval(() => {
|
||||||
|
if (video.buffered.length > 0) {
|
||||||
|
const bufferEnd = video.buffered.end(0);
|
||||||
|
if (bufferEnd > 1.5) { // 1.5s buffer-first
|
||||||
|
clearInterval(checkBuffer);
|
||||||
|
video.play().catch(() => playOverlay.style.display = 'flex');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 200);
|
||||||
});
|
});
|
||||||
hls.on(Hls.Events.LEVEL_LOADED, (e, d) => {
|
hls.on(Hls.Events.LEVEL_LOADED, (e, d) => {
|
||||||
if (d.details && d.details.totalduration > injectedDuration) window.currentHlsDuration = d.details.totalduration;
|
if (d.details && d.details.totalduration > injectedDuration) window.currentHlsDuration = d.details.totalduration;
|
||||||
@@ -292,12 +301,23 @@
|
|||||||
if (!mpegts.isSupported()) return false;
|
if (!mpegts.isSupported()) return false;
|
||||||
const player = mpegts.createPlayer({ type: 'mpegts', isLive: isLive, url: url }, {
|
const player = mpegts.createPlayer({ type: 'mpegts', isLive: isLive, url: url }, {
|
||||||
enableWorker: true,
|
enableWorker: true,
|
||||||
stashInitialSize: 256 * 1024, // Optimized Turbo Start
|
stashInitialSize: 512 * 1024, // Buffer-First: 512KB
|
||||||
maxStashSize: 20 * 1024 * 1024 // 20MB buffer capacity
|
enableStashBuffer: true,
|
||||||
|
liveBufferLatencyChasing: false, // Avoid chaotic catch-up
|
||||||
|
maxStashSize: 30 * 1024 * 1024
|
||||||
});
|
});
|
||||||
player.attachMediaElement(video);
|
player.attachMediaElement(video);
|
||||||
player.load();
|
player.load();
|
||||||
player.play().catch(() => playOverlay.style.display = 'flex');
|
|
||||||
|
// Wait for buffer to fill slightly before playing
|
||||||
|
const checkBuffer = setInterval(() => {
|
||||||
|
if (video.buffered.length > 0) {
|
||||||
|
if (video.buffered.end(0) > 1.0) {
|
||||||
|
clearInterval(checkBuffer);
|
||||||
|
player.play().catch(() => playOverlay.style.display = 'flex');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 200);
|
||||||
|
|
||||||
player.on(mpegts.Events.ERROR, (type, detail) => {
|
player.on(mpegts.Events.ERROR, (type, detail) => {
|
||||||
log('MpegTS Error: ' + type + ' - ' + detail);
|
log('MpegTS Error: ' + type + ' - ' + detail);
|
||||||
|
|||||||
+10
-8
@@ -296,19 +296,21 @@
|
|||||||
url: url
|
url: url
|
||||||
}, {
|
}, {
|
||||||
enableWorker: true,
|
enableWorker: true,
|
||||||
stashInitialSize: 256 * 1024, // Optimized Turbo Start: 256KB initial buffer
|
stashInitialSize: 512 * 1024,
|
||||||
enableStashBuffer: true,
|
enableStashBuffer: true,
|
||||||
liveBufferLatencyChasing: true,
|
liveBufferLatencyChasing: false,
|
||||||
liveBufferLatencyChasingOnPaused: true,
|
maxStashSize: 30 * 1024 * 1024
|
||||||
liveBufferLatencyMaxLatency: 10.0,
|
|
||||||
liveBufferLatencyMinLatency: 2.0,
|
|
||||||
lazyLoad: false,
|
|
||||||
maxStashSize: 20 * 1024 * 1024
|
|
||||||
});
|
});
|
||||||
|
|
||||||
player.attachMediaElement(video);
|
player.attachMediaElement(video);
|
||||||
player.load();
|
player.load();
|
||||||
player.play().catch(() => playOverlay.style.display = 'flex');
|
|
||||||
|
const checkBuffer = setInterval(() => {
|
||||||
|
if (video.buffered.length > 0 && video.buffered.end(0) > 1.0) {
|
||||||
|
clearInterval(checkBuffer);
|
||||||
|
player.play().catch(() => playOverlay.style.display = 'flex');
|
||||||
|
}
|
||||||
|
}, 200);
|
||||||
|
|
||||||
player.on(mpegts.Events.ERROR, (type, detail, info) => {
|
player.on(mpegts.Events.ERROR, (type, detail, info) => {
|
||||||
log('MpegTS Error: ' + type + ' - ' + detail);
|
log('MpegTS Error: ' + type + ' - ' + detail);
|
||||||
|
|||||||
+25
-16
@@ -233,25 +233,27 @@
|
|||||||
const hls = new Hls({
|
const hls = new Hls({
|
||||||
maxBufferLength: 60,
|
maxBufferLength: 60,
|
||||||
maxMaxBufferLength: 120,
|
maxMaxBufferLength: 120,
|
||||||
liveSyncDurationCount: 5, // Balanced sync
|
liveSyncDurationCount: 10, // Buffer-First safety
|
||||||
liveMaxLatencyDurationCount: 20,
|
liveMaxLatencyDurationCount: 20,
|
||||||
enableWorker: true,
|
enableWorker: true,
|
||||||
lowLatencyMode: false, // Disabled for stability against micro-cuts
|
lowLatencyMode: false,
|
||||||
// Robustness
|
nudgeOffset: 0.8,
|
||||||
nudgeOffset: 0.6, // More aggressive jump over corrupted frames
|
nudgeMaxRetries: 30,
|
||||||
nudgeMaxRetries: 25,
|
maxLiveSyncPlaybackRate: 1.1,
|
||||||
maxLiveSyncPlaybackRate: 1.2,
|
initialLiveManifestSize: 3,
|
||||||
// Turbo-Start specific
|
abrEwmaDefaultEstimate: 1000000,
|
||||||
startLevel: 0,
|
manifestLoadingRetryDelay: 1000,
|
||||||
initialLiveManifestSize: 1,
|
levelLoadingRetryDelay: 1000
|
||||||
abrEwmaDefaultEstimate: 700000,
|
|
||||||
manifestLoadingRetryDelay: 500,
|
|
||||||
levelLoadingRetryDelay: 500
|
|
||||||
});
|
});
|
||||||
hls.loadSource(streamUrl);
|
hls.loadSource(streamUrl);
|
||||||
hls.attachMedia(video);
|
hls.attachMedia(video);
|
||||||
hls.on(Hls.Events.MANIFEST_PARSED, () => {
|
hls.on(Hls.Events.MANIFEST_PARSED, () => {
|
||||||
video.play().catch(e => playOverlay.style.display = 'flex');
|
const checkBuffer = setInterval(() => {
|
||||||
|
if (video.buffered.length > 0 && video.buffered.end(0) > 1.5) {
|
||||||
|
clearInterval(checkBuffer);
|
||||||
|
video.play().catch(e => playOverlay.style.display = 'flex');
|
||||||
|
}
|
||||||
|
}, 200);
|
||||||
});
|
});
|
||||||
hls.on(Hls.Events.ERROR, (e, d) => {
|
hls.on(Hls.Events.ERROR, (e, d) => {
|
||||||
if (d.fatal) {
|
if (d.fatal) {
|
||||||
@@ -271,13 +273,20 @@
|
|||||||
url: streamUrl
|
url: streamUrl
|
||||||
}, {
|
}, {
|
||||||
enableWorker: true,
|
enableWorker: true,
|
||||||
stashInitialSize: 128 * 1024, // Turbo Start: 128KB initial buffer
|
stashInitialSize: 512 * 1024,
|
||||||
enableStashBuffer: true,
|
enableStashBuffer: true,
|
||||||
maxStashSize: 20 * 1024 * 1024 // 20MB Max for stability
|
liveBufferLatencyChasing: false,
|
||||||
|
maxStashSize: 30 * 1024 * 1024
|
||||||
});
|
});
|
||||||
player.attachMediaElement(video);
|
player.attachMediaElement(video);
|
||||||
player.load();
|
player.load();
|
||||||
player.play().catch(e => playOverlay.style.display = 'flex');
|
|
||||||
|
const checkBuffer = setInterval(() => {
|
||||||
|
if (video.buffered.length > 0 && video.buffered.end(0) > 1.0) {
|
||||||
|
clearInterval(checkBuffer);
|
||||||
|
player.play().catch(e => playOverlay.style.display = 'flex');
|
||||||
|
}
|
||||||
|
}, 200);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user