Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/sandbox/templates/spf-moq-player/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ <h1>MoQ Player</h1>
<p>
<code>&lt;simple-moq-video&gt;</code> inside the real <code>&lt;live-video-player&gt;</code> shell and skin — the
MoQ engine driving actual Video.js controls. Defaults to a <strong>loopback relay</strong>: an in-page MSF
publisher speaking draft-20 bytes over an in-memory transport, so playback works with no server. Point at a real
publisher speaking draft-22 bytes over an in-memory transport, so playback works with no server. Point at a real
relay with a full MSF URL (<code>?relay=moqt://…%23msf:…</code> — percent-encode the <code>#</code>, or the
browser reads it as this page's fragment), or compose one from parts: relay host, broadcast path (what your token
was issued for, e.g. <code>mattypoo/room/42</code>), and an optional JWT — the same
Expand Down
14 changes: 11 additions & 3 deletions apps/sandbox/templates/spf-moq-player/loopback-relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ const LOC_TIMESTAMP = 0x10;

/**
* The vi64 varint of draft-15+ (§8.1) — leading ones on the first byte give the encoded length minus one, so an L-byte
* encoding carries 7L value bits. NOT the QUIC RFC 9000 varint.
* encoding of up to 8 bytes carries 7L value bits, and the 9-byte form (first byte 0xFF) a full 64. NOT the QUIC RFC
* 9000 varint. Encoding stops at 8 bytes: their 56 bits hold every safe integer (up to `Number.MAX_SAFE_INTEGER`), and
* anything else is rejected rather than mis-encoded — a double can hold some larger integers exactly, such as 2^56.
*/
function varintByteLength(value: number): number {
if (!Number.isSafeInteger(value) || value < 0)
throw new RangeError(`varint: ${value} is not a safe unsigned integer`);

for (let length = 1; length < 8; length++) {
if (value < 2 ** (7 * length)) return length;
}
Expand Down Expand Up @@ -684,8 +689,11 @@ export function createLoopbackRelay({ onLog }: LoopbackRelayOptions = {}): Loopb
}

const { value, done } = await reader.read();
// Cancellation *is* the stream lifecycle (§6.4.2.3): the subscriber
// aborting its sending direction ends the subscription.
// A FIN only means the subscriber will send nothing more (§6.4.2.2),
// yet this loopback ends the subscription on it as well as on a
// cancellation (§6.4.2.3), which lands in the catch below. The player
// cancels with a reset and FINs only after the publisher has, so the
// shortcut never cuts a live subscription short.
if (done) break;

const merged = new Uint8Array(buffer.length + value.length);
Expand Down
2 changes: 1 addition & 1 deletion packages/spf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
},
"dependencies": {
"@caprid/moq-core": "^0.1.1",
"@caprid/moq-media": "^0.1.1",
"@caprid/moq-media": "0.1.0",
"@videojs/media": "workspace:*",
"@videojs/utils": "workspace:*",
"signal-polyfill": "^0.2.2"
Expand Down
5 changes: 1 addition & 4 deletions packages/spf/src/playback/actors/dom/audio-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,7 @@ const MAX_PLAYBACK_RATE = 2;
const createDefaultAudioPlayer: CreateAudioPlayer = async (context) => {
if (!context.baseContext) throw new Error('audio renderer context has no baseContext to host the AudioWorklet');

// WebCodecs, not the core's WebAssembly libopus: that decoder is single-stream and ignores the OpusHead
// channel mapping, so a multistream (above stereo) track the catalog allows would decode as noise. A lost
// frame plays as silence instead of being concealed.
return createCoreAudioPlayer({ context: context.baseContext, lossConcealment: false });
return createCoreAudioPlayer({ context: context.baseContext });
};

export function createAudioRendererActor(options: CreateAudioRendererOptions): AudioRendererActor {
Expand Down
10 changes: 0 additions & 10 deletions packages/spf/src/playback/actors/dom/tests/audio-renderer.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { createAudioPlayer as createCoreAudioPlayer } from '@caprid/moq-media';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vite-plus/test';

import type { JitterFrame } from '../../track-subscriber';
Expand All @@ -11,12 +10,6 @@ import {
createAudioRendererActor,
} from '../audio-renderer';

vi.mock('@caprid/moq-media', async (importOriginal) => {
const original = await importOriginal<typeof import('@caprid/moq-media')>();

return { ...original, createAudioPlayer: vi.fn(original.createAudioPlayer) };
});

const FRAME_US = 20_000;
const JITTER_TARGET_US = 60_000;
const TICK_MS = 10;
Expand Down Expand Up @@ -579,9 +572,6 @@ describe('createAudioRendererActor', () => {

await vi.advanceTimersByTimeAsync(0);
expect(addModule).toHaveBeenCalledTimes(1);
// WebCodecs decoding: the core's WebAssembly libopus ignores a multistream
// OpusHead's channel mapping.
expect(createCoreAudioPlayer).toHaveBeenCalledWith({ context: baseContext, lossConcealment: false });
expect(renderer.snapshot.get().context.error).toBe(workletUnavailable);
renderer.destroy();

Expand Down
18 changes: 12 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading