make rendering abstract (so that a webgl renderer will actually be possible)
This commit is contained in:
parent
b44a55f10d
commit
a6734667de
3 changed files with 167 additions and 156 deletions
|
@ -1,10 +1,11 @@
|
|||
// shared interface to allow gl later :)
|
||||
export class Canvas2DRenderer {
|
||||
private canvas: OffscreenCanvas;
|
||||
import { CanvasRenderer } from "./canvas_renderer";
|
||||
|
||||
// renderer for the streamplayer that uses the canvas2d apis
|
||||
export class Canvas2DRenderer extends CanvasRenderer {
|
||||
private ctx: OffscreenCanvasRenderingContext2D;
|
||||
|
||||
constructor(c: OffscreenCanvas) {
|
||||
this.canvas = c;
|
||||
super(c);
|
||||
this.ctx = this.canvas.getContext("2d")!;
|
||||
}
|
||||
|
||||
|
|
10
client/src/streamplayer/worker/canvas_renderer.ts
Normal file
10
client/src/streamplayer/worker/canvas_renderer.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
// mixin thing
|
||||
export abstract class CanvasRenderer {
|
||||
protected canvas: OffscreenCanvas;
|
||||
|
||||
constructor(c: OffscreenCanvas) {
|
||||
this.canvas = c;
|
||||
}
|
||||
|
||||
abstract draw(frame: VideoFrame): void;
|
||||
}
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
import { NALUStream, SPS, Slice } from "h264-interp-utils";
|
||||
import {
|
||||
PlayerInputMessage,
|
||||
|
@ -6,11 +5,11 @@ import {
|
|||
PlayerInitMessage,
|
||||
PlayerVideoDataMessage,
|
||||
} from "./stream_worker_messages";
|
||||
import { Canvas2DRenderer } from "./canvas_2d_renderer";
|
||||
import { CanvasRenderer } from "./canvas_renderer";
|
||||
|
||||
// player logic
|
||||
export class VideoStreamPlayer {
|
||||
private renderer: Canvas2DRenderer | null = null;
|
||||
private renderer: CanvasRenderer | null = null;
|
||||
private pendingFrame: VideoFrame | null = null;
|
||||
private decoder: VideoDecoder | null = null;
|
||||
private streamInitSPS: SPS | null = null;
|
||||
|
@ -130,7 +129,9 @@ export class VideoStreamPlayer {
|
|||
|
||||
if (!supportedConfig.supported) {
|
||||
await this.shutdownDecoder();
|
||||
throw new Error("I give up, the browser doesn't like no preference either.");
|
||||
throw new Error(
|
||||
"I give up, the browser doesn't like no preference either."
|
||||
);
|
||||
}
|
||||
|
||||
configMessage.usingHwDecode = false;
|
||||
|
@ -161,8 +162,7 @@ export class VideoStreamPlayer {
|
|||
return this.renderer !== null;
|
||||
}
|
||||
|
||||
setRenderer(r: Canvas2DRenderer) {
|
||||
setRenderer(r: CanvasRenderer) {
|
||||
this.renderer = r;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in a new issue