Cancel stale playback probes and verify Linux QSV support
This commit is contained in:
28
public/js/components/PlaybackProbe.js
Normal file
28
public/js/components/PlaybackProbe.js
Normal file
@ -0,0 +1,28 @@
|
||||
/** Metadata probes belong to the active playback, and share an ordered lease across replacements. */
|
||||
class PlaybackProbe {
|
||||
constructor(fetchImpl = fetch) {
|
||||
this.fetch = fetchImpl;
|
||||
this.sequence = 0;
|
||||
this.leaseId = Array.from(globalThis.crypto.getRandomValues(new Uint8Array(16)),
|
||||
byte => byte.toString(16).padStart(2, '0')).join('');
|
||||
}
|
||||
async read(url, { program = null, userAgent } = {}) {
|
||||
this.cancel();
|
||||
const controller = this.controller = new AbortController();
|
||||
const query = new URLSearchParams({ url, probeLeaseId: this.leaseId, requestSequence: String(++this.sequence) });
|
||||
if (program != null) query.set('program', program);
|
||||
if (userAgent !== undefined) query.set('ua', userAgent);
|
||||
try {
|
||||
const response = await this.fetch('/api/probe?' + query, { signal: controller.signal, credentials: 'same-origin' });
|
||||
const info = await response.json();
|
||||
if (controller.signal.aborted || this.controller !== controller || response.status === 409) {
|
||||
throw Object.assign(new Error('Playback probe was superseded'), { name: 'AbortError' });
|
||||
}
|
||||
if (response.ok === false) throw new Error(info.error || 'Unable to probe stream');
|
||||
return info;
|
||||
} finally { if (this.controller === controller) this.controller = null; }
|
||||
}
|
||||
cancel() { this.controller?.abort(); this.controller = null; }
|
||||
}
|
||||
if (typeof window !== 'undefined') window.PlaybackProbe = PlaybackProbe;
|
||||
if (typeof module !== 'undefined') module.exports = PlaybackProbe;
|
||||
@ -643,7 +643,6 @@ class VideoPlayer {
|
||||
}
|
||||
if (this.playbackGeneration !== playbackGeneration) return;
|
||||
this.currentChannel = channel;
|
||||
const programQuery = channel?.program == null ? '' : '&program=' + encodeURIComponent(channel.program);
|
||||
let probeInfo = null;
|
||||
this.updateTranscodeStatus('hidden');
|
||||
|
||||
@ -661,8 +660,7 @@ class VideoPlayer {
|
||||
if (this.settings.autoTranscode) {
|
||||
console.log('[Player] Auto Transcode enabled. Probing stream...');
|
||||
try {
|
||||
const probeRes = await fetch(`/api/probe?url=${encodeURIComponent(streamUrl)}${programQuery}`);
|
||||
const info = await probeRes.json();
|
||||
const info = await (this.playbackProbe ||= new PlaybackProbe(fetch)).read(streamUrl, { program: channel?.program });
|
||||
if (this.playbackGeneration !== playbackGeneration) return;
|
||||
probeInfo = info;
|
||||
console.log(`[Player] Probe result: video=${info.video}, audio=${info.audio}, ${info.width}x${info.height}, compatible=${info.compatible}`);
|
||||
@ -724,6 +722,7 @@ class VideoPlayer {
|
||||
// Compatible - fall through to normal HLS.js path
|
||||
console.log('[Player] Auto: Using HLS.js (compatible)');
|
||||
} catch (err) {
|
||||
if (err.name === 'AbortError') return;
|
||||
console.warn('[Player] Probe failed, using normal playback:', err.message);
|
||||
// Continue with normal playback on probe failure
|
||||
}
|
||||
@ -753,11 +752,10 @@ class VideoPlayer {
|
||||
// Probe to get video codec for HEVC tag handling
|
||||
let videoCodec = 'unknown';
|
||||
try {
|
||||
const probeRes = await fetch(`/api/probe?url=${encodeURIComponent(streamUrl)}${programQuery}`);
|
||||
const info = await probeRes.json();
|
||||
const info = await (this.playbackProbe ||= new PlaybackProbe(fetch)).read(streamUrl, { program: channel?.program });
|
||||
if (this.playbackGeneration !== playbackGeneration) return;
|
||||
videoCodec = info.video;
|
||||
} catch (e) { console.warn('Probe failed for force audio, assuming h264'); }
|
||||
} catch (e) { if (e.name === 'AbortError') return; console.warn('Probe failed for force audio, assuming h264'); }
|
||||
|
||||
if (this.playbackGeneration !== playbackGeneration) return;
|
||||
const playlistUrl = await this.startTranscodeSession(streamUrl, { program: channel?.program || null, videoMode: 'copy', videoCodec });
|
||||
@ -805,9 +803,9 @@ class VideoPlayer {
|
||||
this.updateTranscodeStatus('remuxing', this.settings.forceRemux ? 'Remux (Force)' : 'Remux (Program)');
|
||||
if (!probeInfo) {
|
||||
try {
|
||||
const response = await fetch(`/api/probe?url=${encodeURIComponent(streamUrl)}${programQuery}`);
|
||||
probeInfo = await response.json();
|
||||
probeInfo = await (this.playbackProbe ||= new PlaybackProbe(fetch)).read(streamUrl, { program: channel?.program });
|
||||
} catch (error) {
|
||||
if (error.name === 'AbortError') return;
|
||||
console.warn('[Player] Remux probe failed:', error.message);
|
||||
}
|
||||
}
|
||||
@ -1115,6 +1113,7 @@ class VideoPlayer {
|
||||
* Stop playback
|
||||
*/
|
||||
stop() {
|
||||
this.playbackProbe?.cancel();
|
||||
this.zapController?.abort();
|
||||
this.zapController = null;
|
||||
this.playbackGeneration = (this.playbackGeneration || 0) + 1;
|
||||
|
||||
Reference in New Issue
Block a user