Prototype on branch s022-mse-proto (gst_mse backend, vendored script). Co-Authored-By: Claude Opus 5.5 <[email protected]>
82 lines
3.3 KiB
HTML
82 lines
3.3 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<!-- MSE test (S022): a MediaSource with one SourceBuffer, fed mse-clip-mp4.js (fMP4, H.264 + AAC) or, with
|
|
?webm, mse-clip-webm.js (VP9 + Opus) in 32 KiB appendBuffer chunks. The clips are base64 scripts because
|
|
Servo refuses fetch() and XHR of file:// URLs. window.mse holds the state for
|
|
smoke asserts: stage, chunks appended, buffered end, currentTime, errors. -->
|
|
<head><meta charset="utf-8"><title>MSE basic</title>
|
|
<style>
|
|
body { margin: 0; background: #1d3b2a; color: #fff; font: 20px sans-serif; text-align: center; }
|
|
video { display: block; margin: 20px auto; width: 640px; height: 360px; background: #000; }
|
|
#log { font: 16px monospace; white-space: pre; text-align: left; width: 640px; margin: 0 auto; }
|
|
</style></head>
|
|
<body>
|
|
<div id="head">MSE BASIC</div>
|
|
<video id="v" muted></video>
|
|
<div id="log"></div>
|
|
<script>
|
|
const webm = location.search.includes('webm');
|
|
const file = webm ? 'mse-clip-webm.js' : 'mse-clip-mp4.js';
|
|
const mime = webm ? 'video/webm; codecs="vp9, opus"' : 'video/mp4; codecs="avc1.4d401f, mp4a.40.2"';
|
|
const mse = window.mse = { stage: 'start', chunks: 0, buffered: 0, time: 0, errors: [] };
|
|
const log = (line) => { document.getElementById('log').textContent += line + '\n'; };
|
|
const fail = (what) => { mse.errors.push(String(what)); log('ERROR ' + what); };
|
|
|
|
function load(url) {
|
|
return new Promise((resolve, reject) => {
|
|
const script = document.createElement('script');
|
|
script.src = url;
|
|
script.onload = () => resolve(Uint8Array.from(atob(window.MSE_CLIP), (c) => c.charCodeAt(0)).buffer);
|
|
script.onerror = () => reject('load ' + url);
|
|
document.head.appendChild(script);
|
|
});
|
|
}
|
|
|
|
function update() {
|
|
const v = document.getElementById('v');
|
|
mse.time = v.currentTime;
|
|
mse.readyState = v.readyState;
|
|
document.getElementById('head').textContent =
|
|
'MSE ' + mse.stage + ' chunks ' + mse.chunks + ' buffered ' + mse.buffered.toFixed(2) +
|
|
' time ' + mse.time.toFixed(2);
|
|
}
|
|
|
|
async function run() {
|
|
if (!window.MediaSource) { mse.stage = 'no MediaSource'; return; }
|
|
mse.supported = MediaSource.isTypeSupported(mime);
|
|
log('isTypeSupported ' + mse.supported + ' ' + mime);
|
|
const data = await load(file);
|
|
const v = document.getElementById('v');
|
|
const ms = new MediaSource();
|
|
ms.addEventListener('sourceopen', () => {
|
|
mse.stage = 'open';
|
|
log('sourceopen readyState ' + ms.readyState);
|
|
let sb;
|
|
try { sb = ms.addSourceBuffer(mime); } catch (e) { fail(e); return; }
|
|
let offset = 0;
|
|
const next = () => {
|
|
if (sb.buffered.length) mse.buffered = sb.buffered.end(sb.buffered.length - 1);
|
|
if (offset >= data.byteLength) {
|
|
ms.endOfStream();
|
|
mse.stage = 'ended';
|
|
log('endOfStream buffered ' + mse.buffered + ' duration ' + ms.duration);
|
|
v.play().then(() => log('playing'), fail);
|
|
return;
|
|
}
|
|
sb.appendBuffer(data.slice(offset, offset + 32768));
|
|
offset += 32768;
|
|
mse.chunks++;
|
|
};
|
|
sb.addEventListener('updateend', next);
|
|
sb.addEventListener('error', () => fail('SourceBuffer error'));
|
|
next();
|
|
});
|
|
ms.addEventListener('sourceended', () => log('sourceended'));
|
|
v.addEventListener('error', () => fail('video error ' + (v.error && v.error.message)));
|
|
v.src = URL.createObjectURL(ms);
|
|
setInterval(update, 250);
|
|
}
|
|
run().catch(fail);
|
|
</script>
|
|
</body>
|
|
</html>
|