@@ -42,6 +42,7 @@ let decqueue_aggregate = {
42
42
43
43
function enc_update ( data ) {
44
44
enc_aggregate . all . push ( data ) ;
45
+ //self.postMessage({text: 'enc_update called: ' + JSON.stringify(data)});
45
46
}
46
47
47
48
function encqueue_update ( duration ) {
@@ -214,7 +215,7 @@ class pipeline {
214
215
let config = JSON . parse ( chunk . config ) ;
215
216
try {
216
217
const decoderSupport = await VideoDecoder . isConfigSupported ( config ) ;
217
- if ( decoderSupport . supported ) {
218
+ if ( decoderSupport . supported ) {
218
219
this . decoder . configure ( decoderSupport . config ) ;
219
220
self . postMessage ( { text : 'Decoder successfully configured:\n' + JSON . stringify ( decoderSupport . config ) } ) ;
220
221
} else {
@@ -252,8 +253,7 @@ class pipeline {
252
253
output : ( chunk , cfg ) => {
253
254
if ( cfg . decoderConfig ) {
254
255
cfg . decoderConfig . hardwareAcceleration = config . decHwAcceleration ;
255
- cfg . decoderConfig . optimizeForLatency = true ;
256
- if ( config . latencyPref == 'quality' ) cfg . decoderConfig . optimizeForLatency = false ;
256
+ cfg . decoderConfig . optimizeForLatency = ( config . latencyMode == "realtime" ) ;
257
257
const decoderConfig = JSON . stringify ( cfg . decoderConfig ) ;
258
258
self . postMessage ( { text : 'Configuration: ' + decoderConfig } ) ;
259
259
const configChunk =
@@ -264,14 +264,14 @@ class pipeline {
264
264
deltaframeIndex : this . deltaframeIndex ,
265
265
timestamp : 0 ,
266
266
pt : 0 ,
267
- config : decoderConfig
267
+ config : decoderConfig
268
268
} ;
269
- controller . enqueue ( configChunk ) ;
269
+ controller . enqueue ( configChunk ) ;
270
270
}
271
271
if ( chunk . type != 'config' ) {
272
272
const after = performance . now ( ) ;
273
273
enc_update ( { output : 1 , timestamp : chunk . timestamp , time : after } ) ;
274
- }
274
+ }
275
275
chunk . temporalLayerId = 0 ;
276
276
if ( cfg . svc ) {
277
277
chunk . temporalLayerId = cfg . svc . temporalLayerId ;
@@ -282,7 +282,7 @@ class pipeline {
282
282
this . deltaframeIndex = 0 ;
283
283
} else {
284
284
this . deltaframeIndex ++ ;
285
- }
285
+ }
286
286
this . pending_outputs -- ;
287
287
chunk . seqNo = this . seqNo ;
288
288
chunk . keyframeIndex = this . keyframeIndex ;
@@ -296,11 +296,11 @@ class pipeline {
296
296
try {
297
297
const encoderSupport = await VideoEncoder . isConfigSupported ( config ) ;
298
298
if ( encoderSupport . supported ) {
299
- this . encoder . configure ( encoderSupport . config ) ;
300
- self . postMessage ( { text : 'Encoder successfully configured:\n' + JSON . stringify ( encoderSupport . config ) } ) ;
301
- } else {
302
- self . postMessage ( { severity : 'fatal' , text : 'Config not supported:\n' + JSON . stringify ( encoderSupport . config ) } ) ;
303
- }
299
+ this . encoder . configure ( encoderSupport . config ) ;
300
+ self . postMessage ( { text : 'Encoder successfully configured:\n' + JSON . stringify ( encoderSupport . config ) } ) ;
301
+ } else {
302
+ self . postMessage ( { severity : 'fatal' , text : 'Config not supported:\n' + JSON . stringify ( encoderSupport . config ) } ) ;
303
+ }
304
304
} catch ( e ) {
305
305
self . postMessage ( { severity : 'fatal' , text : `Configuration error: ${ e . message } ` } ) ;
306
306
}
@@ -311,13 +311,13 @@ class pipeline {
311
311
const insert_keyframe = ( this . frameCounter % config . keyInterval ) == 0 ;
312
312
this . frameCounter ++ ;
313
313
try {
314
- if ( this . encoder . state != "closed ") {
314
+ if ( this . encoder . state == "configured ") {
315
315
const queue = this . encoder . encodeQueueSize ;
316
316
encqueue_update ( queue ) ;
317
317
const before = performance . now ( ) ;
318
318
enc_update ( { output : 0 , timestamp : frame . timestamp , time : before } ) ;
319
319
this . encoder . encode ( frame , { keyFrame : insert_keyframe } ) ;
320
- }
320
+ }
321
321
} catch ( e ) {
322
322
self . postMessage ( { severity : 'fatal' , text : 'Encoder Error: ' + e . message } ) ;
323
323
}
@@ -331,7 +331,7 @@ class pipeline {
331
331
if ( encoder . state != "closed" ) encoder . close ( ) ;
332
332
if ( decoder . state != "closed" ) decoder . close ( ) ;
333
333
stopped = true ;
334
- this . stopped = true ;
334
+ this . stopped = true ;
335
335
const len = encqueue_aggregate . all . length ;
336
336
if ( len > 1 ) {
337
337
const enc_stats = enc_report ( ) ;
@@ -355,7 +355,7 @@ class pipeline {
355
355
started = true ;
356
356
let duplexStream , readStream , writeStream ;
357
357
self . postMessage ( { text : 'Start method called.' } ) ;
358
- try {
358
+ try {
359
359
await this . inputStream
360
360
. pipeThrough ( this . EncodeVideoStream ( self , this . config ) )
361
361
. pipeThrough ( this . DecodeVideoStream ( self ) )
0 commit comments