Skip to content

Commit

Permalink
Deploying to gh-pages from @ 07bf77b 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
aboba committed Sep 11, 2024
1 parent 99f0a0a commit f9bedd9
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions samples/encode-decode-worker/js/stream_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ let decqueue_aggregate = {

function enc_update(data) {
enc_aggregate.all.push(data);
//self.postMessage({text: 'enc_update called: ' + JSON.stringify(data)});
}

function encqueue_update(duration) {
Expand Down Expand Up @@ -214,7 +215,7 @@ class pipeline {
let config = JSON.parse(chunk.config);
try {
const decoderSupport = await VideoDecoder.isConfigSupported(config);
if (decoderSupport.supported) {
if (decoderSupport.supported) {
this.decoder.configure(decoderSupport.config);
self.postMessage({text: 'Decoder successfully configured:\n' + JSON.stringify(decoderSupport.config)});
} else {
Expand Down Expand Up @@ -252,8 +253,7 @@ class pipeline {
output: (chunk, cfg) => {
if (cfg.decoderConfig) {
cfg.decoderConfig.hardwareAcceleration = config.decHwAcceleration;
cfg.decoderConfig.optimizeForLatency = true;
if (config.latencyPref == 'quality') cfg.decoderConfig.optimizeForLatency = false;
cfg.decoderConfig.optimizeForLatency = (config.latencyMode == "realtime");
const decoderConfig = JSON.stringify(cfg.decoderConfig);
self.postMessage({text: 'Configuration: ' + decoderConfig});
const configChunk =
Expand All @@ -264,14 +264,14 @@ class pipeline {
deltaframeIndex: this.deltaframeIndex,
timestamp: 0,
pt: 0,
config: decoderConfig
config: decoderConfig
};
controller.enqueue(configChunk);
controller.enqueue(configChunk);
}
if (chunk.type != 'config'){
const after = performance.now();
enc_update({output: 1, timestamp: chunk.timestamp, time: after});
}
}
chunk.temporalLayerId = 0;
if (cfg.svc) {
chunk.temporalLayerId = cfg.svc.temporalLayerId;
Expand All @@ -282,7 +282,7 @@ class pipeline {
this.deltaframeIndex = 0;
} else {
this.deltaframeIndex++;
}
}
this.pending_outputs--;
chunk.seqNo = this.seqNo;
chunk.keyframeIndex = this.keyframeIndex;
Expand All @@ -296,11 +296,11 @@ class pipeline {
try {
const encoderSupport = await VideoEncoder.isConfigSupported(config);
if (encoderSupport.supported) {
this.encoder.configure(encoderSupport.config);
self.postMessage({text: 'Encoder successfully configured:\n' + JSON.stringify(encoderSupport.config)});
} else {
self.postMessage({severity: 'fatal', text: 'Config not supported:\n' + JSON.stringify(encoderSupport.config)});
}
this.encoder.configure(encoderSupport.config);
self.postMessage({text: 'Encoder successfully configured:\n' + JSON.stringify(encoderSupport.config)});
} else {
self.postMessage({severity: 'fatal', text: 'Config not supported:\n' + JSON.stringify(encoderSupport.config)});
}
} catch (e) {
self.postMessage({severity: 'fatal', text: `Configuration error: ${e.message}`});
}
Expand All @@ -311,13 +311,13 @@ class pipeline {
const insert_keyframe = (this.frameCounter % config.keyInterval) == 0;
this.frameCounter++;
try {
if (this.encoder.state != "closed") {
if (this.encoder.state == "configured") {
const queue = this.encoder.encodeQueueSize;
encqueue_update(queue);
const before = performance.now();
enc_update({output: 0, timestamp: frame.timestamp, time: before});
this.encoder.encode(frame, { keyFrame: insert_keyframe });
}
}
} catch(e) {
self.postMessage({severity: 'fatal', text: 'Encoder Error: ' + e.message});
}
Expand All @@ -331,7 +331,7 @@ class pipeline {
if (encoder.state != "closed") encoder.close();
if (decoder.state != "closed") decoder.close();
stopped = true;
this.stopped = true;
this.stopped = true;
const len = encqueue_aggregate.all.length;
if (len > 1) {
const enc_stats = enc_report();
Expand All @@ -355,7 +355,7 @@ class pipeline {
started = true;
let duplexStream, readStream, writeStream;
self.postMessage({text: 'Start method called.'});
try {
try {
await this.inputStream
.pipeThrough(this.EncodeVideoStream(self,this.config))
.pipeThrough(this.DecodeVideoStream(self))
Expand Down

0 comments on commit f9bedd9

Please sign in to comment.