Fix the video renderer.
This commit is contained in:
parent
6511bcb55a
commit
0240af66cd
|
@ -1 +0,0 @@
|
||||||
50e151a79d06af6b9289180af319ca974e227d9ec58c30362c9304e56df3e3ea
|
|
|
@ -0,0 +1 @@
|
||||||
|
fingerprint.hex
|
|
@ -1 +0,0 @@
|
||||||
642ab03bc58c48ed614e6523d93c2455d8223aedfbdcba7f502ca0ea08590921
|
|
|
@ -3,6 +3,8 @@ import * as Stream from "../stream"
|
||||||
import * as MP4 from "../mp4"
|
import * as MP4 from "../mp4"
|
||||||
|
|
||||||
import Video from "../video/index"
|
import Video from "../video/index"
|
||||||
|
|
||||||
|
// @ts-ignore bundler embeds data
|
||||||
import fingerprint from 'bundle-text:./fingerprint.hex';
|
import fingerprint from 'bundle-text:./fingerprint.hex';
|
||||||
|
|
||||||
///<reference path="./types/webtransport.d.ts"/>
|
///<reference path="./types/webtransport.d.ts"/>
|
||||||
|
@ -46,7 +48,7 @@ export class Player {
|
||||||
async connect(url: string): Promise<WebTransport> {
|
async connect(url: string): Promise<WebTransport> {
|
||||||
// Convert the hex to binary.
|
// Convert the hex to binary.
|
||||||
let hash = [];
|
let hash = [];
|
||||||
for (let c = 0; c < fingerprint.length; c += 2) {
|
for (let c = 0; c < fingerprint.length-1; c += 2) {
|
||||||
hash.push(parseInt(fingerprint.substring(c, c+2), 16));
|
hash.push(parseInt(fingerprint.substring(c, c+2), 16));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,11 +7,14 @@ export class Renderer {
|
||||||
sync: DOMHighResTimeStamp; // the wall clock value for timestamp 0
|
sync: DOMHighResTimeStamp; // the wall clock value for timestamp 0
|
||||||
last?: number; // the timestamp of the last rendered frame
|
last?: number; // the timestamp of the last rendered frame
|
||||||
|
|
||||||
|
maxDuration: number; // the maximum duration allowed in the buffer
|
||||||
|
|
||||||
constructor(config: Message.Config) {
|
constructor(config: Message.Config) {
|
||||||
this.canvas = config.canvas;
|
this.canvas = config.canvas;
|
||||||
this.queue = [];
|
this.queue = [];
|
||||||
this.render = 0;
|
this.render = 0;
|
||||||
this.sync = 0;
|
this.sync = 0;
|
||||||
|
this.maxDuration = 10 * 1000
|
||||||
}
|
}
|
||||||
|
|
||||||
push(frame: VideoFrame) {
|
push(frame: VideoFrame) {
|
||||||
|
@ -27,14 +30,36 @@ export class Renderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert the frame into the queue sorted by timestamp.
|
// Insert the frame into the queue sorted by timestamp.
|
||||||
// TODO loop backwards for better performance
|
let low = 0
|
||||||
let index = this.queue.findIndex(other => {
|
let high = this.queue.length;
|
||||||
return frame.timestamp < other.timestamp;
|
|
||||||
})
|
|
||||||
|
|
||||||
// Insert into the queue.
|
// Fast path because we normally append to the end.
|
||||||
this.queue.splice(index, 0, frame)
|
if (this.queue.length > 0 && this.queue[this.queue.length].timestamp <= frame.timestamp) {
|
||||||
|
this.queue.push(frame)
|
||||||
|
} else {
|
||||||
|
// Do a full binary search
|
||||||
|
while (low < high) {
|
||||||
|
var mid = (low + high) >>> 1;
|
||||||
|
if (this.queue[mid].timestamp < frame.timestamp) low = mid + 1;
|
||||||
|
else high = mid;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.queue.splice(low, 0, frame)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trim the max size of the buffer
|
||||||
|
const last = this.queue[this.queue.length-1].timestamp
|
||||||
|
while (1) {
|
||||||
|
const first = this.queue[0]
|
||||||
|
if (first.timestamp + this.maxDuration >= last) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
first.close()
|
||||||
|
this.queue.shift()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Queue up to render the next frame.
|
||||||
if (!this.render) {
|
if (!this.render) {
|
||||||
this.render = self.requestAnimationFrame(this.draw.bind(this))
|
this.render = self.requestAnimationFrame(this.draw.bind(this))
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,8 +56,6 @@ func run(ctx context.Context) (err error) {
|
||||||
hash := sha256.Sum256(tlsCert.Certificate[0])
|
hash := sha256.Sum256(tlsCert.Certificate[0])
|
||||||
fingerprint := hex.EncodeToString(hash[:])
|
fingerprint := hex.EncodeToString(hash[:])
|
||||||
|
|
||||||
fmt.Println(fingerprint)
|
|
||||||
|
|
||||||
webConfig := web.Config{
|
webConfig := web.Config{
|
||||||
Addr: *addr,
|
Addr: *addr,
|
||||||
CertFile: *cert,
|
CertFile: *cert,
|
||||||
|
|
Loading…
Reference in New Issue