@@ -8,23 +8,9 @@ import Statistics from '../statistics/statistics';
88import RTCUtils from './RTCUtils' ;
99
1010import JitsiTrack from './JitsiTrack' ;
11- import channels from '../../wasm/RTC/channels.js' ;
1211import { decode } from 'punycode' ;
1312
14- let wasmChannels = null ;
15- export async function getWasmModule ( ) {
16- if ( ! wasmChannels ) {
17- wasmChannels = channels ( {
18- locateFile : ( path ) => {
19- if ( path . endsWith ( '.wasm' ) ) {
20- return '/libs/channels.wasm' ;
21- }
22- return path ;
23- }
24- } ) ;
25- }
26- return wasmChannels ;
27- }
13+
2814
2915const ort = require ( 'onnxruntime-web' ) ;
3016ort . env . wasm . wasmPaths = '/libs/dist/' ;
@@ -42,81 +28,15 @@ export let decodingSession = null;
4228 */
4329async function loadDecoder ( ) {
4430 try {
45- decodingSession = await ort . InferenceSession . create ( '/libs/models/Decoder.onnx' , { freeDimensionOverrides : {
46- batch : 1 ,
47- } } ) ;
31+ decodingSession = await ort . InferenceSession . create ( '/libs/models/Decoder.onnx' ) ;
32+ console . log ( "Decoder model has been loaded" ) ;
4833 }
4934 catch ( error ) {
5035 console . error ( "Decoder model could not be loaded!: " , error ) ;
5136 }
5237}
5338loadDecoder ( )
5439
55- /**
56- * Uses wasm binaries that transform HWC channel-order used by Javascript to CHW channel order used by python
57- * @param {data } data Javascript data container
58- * @param {number } width image width
59- * @param {number } height image height
60- * @returns FloatA32Array
61- */
62- export async function js2py ( data , width , height ) {
63- if ( timer == true ) {
64- console . time ( "TIMER loading wasm js2py decoder" ) ;
65- }
66- const Module = await getWasmModule ( ) ;
67- if ( timer == true ) {
68- console . timeEnd ( "TIMER loading wasm js2py decoder" ) ;
69- }
70- const ptr = Module . _malloc ( data . length ) ;
71- Module . HEAPU8 . set ( data , ptr ) ;
72- // Call the C++ reorder function
73- if ( timer == true ) {
74- console . time ( "TIMER Applying js2py decoder" ) ;
75- }
76- Module . _vjs2py ( ptr , width , height ) ;
77- if ( timer == true ) {
78- console . timeEnd ( "TIMER Applying js2py decoder" ) ;
79- }
80- // Read back the result
81- const result = Module . HEAPU8 . subarray ( ptr , ptr + data . length ) ;
82- Module . _free ( ptr ) ;
83- return Float32Array . from ( result ) ;
84- }
85-
86- /**
87- * Uses wasm binaries that transform CHW channel-order used by python to HWC channel order used by javascript
88- * @param {data } data Javascript data container
89- * @param {data } tensorData Tensor data from ort module
90- * @param {number } width image width
91- * @param {number } height image height
92- * @returns data
93- */
94- export async function py2js ( data , tensorData , width , height ) {
95- if ( timer == true ) {
96- console . time ( "TIMER loading wasm py2js decoder" )
97- }
98- const Module = await getWasmModule ( ) ;
99- if ( timer == true ) {
100- console . timeEnd ( "TIMER loading wasm py2js decoder" )
101- }
102- const int8Tensor = Uint8ClampedArray . from ( tensorData )
103- const ptr = Module . _malloc ( int8Tensor . length ) ;
104- Module . HEAPU8 . set ( int8Tensor , ptr ) ;
105- // Call the C++ reorder function
106- if ( timer == true ) {
107- console . time ( "TIMER applying py2js decoder" ) ;
108- }
109- Module . _vpy2js ( ptr , width , height ) ;
110- if ( timer == true ) {
111- console . timeEnd ( "TIMER applying py2js decoder" ) ;
112- }
113- // Read back the result
114- const result = Module . HEAPU8 . subarray ( ptr , ptr + int8Tensor . length ) ;
115- data . set ( result ) ;
116- Module . _free ( ptr ) ;
117- return data ;
118- }
119-
12040/**
12141 * List of container events that we are going to process. _onContainerEventHandler will be added as listener to the
12242 * container for every event in the list.
@@ -269,7 +189,7 @@ export default class JitsiRemoteTrack extends JitsiTrack {
269189 async function processFrame ( ) {
270190 try {
271191 if ( timer == true ) {
272- console . time ( "TIMER decoder" ) ;
192+ console . time ( "TIMER decoder full-elapsed time " ) ;
273193 }
274194 // Getting the current size of the incoming stream
275195 const width = videoTrack . getSettings ( ) . width ;
@@ -281,26 +201,10 @@ export default class JitsiRemoteTrack extends JitsiTrack {
281201 const frame = await imageCapture . grabFrame ( ) ;
282202 ctxEncoded . drawImage ( frame , 0 , 0 , width , height ) ;
283203 //Generating tensor from painted frame to be passed to the onnx model
284- if ( timer == true ) {
285- console . time ( "TIMER imageEncode get decoder" ) ;
286- }
287204 const imageEncode = ctxEncoded . getImageData ( 0 , 0 , width , height ) ;
288- if ( timer == true ) {
289- console . timeEnd ( "TIMER imageEncode get decoder" ) ;
290- }
291205 const imageData = imageEncode . data ;
292- const channels = 4 ;
293- // Channels are reordered as required by the onnx model
294- if ( timer == true ) {
295- console . time ( "TIMER full js2py decoder" ) ;
296- }
297- // let floatArray = await js2py(imageData,width,height);
298- // if(timer==true){
299- // console.timeEnd("TIMER full js2py decoder");
300- // }
301206 let floatArray = Float32Array ( imageData )
302207 // Applying the onnx model
303- // const tensor = new ort.Tensor("float32",floatArray,[1,channels,height,width]);
304208 const tensor = new ort . Tensor ( "float32" , floatArray , [ 1 , height , width , 4 ] ) ;
305209 const input = {
306210 input : tensor
@@ -317,27 +221,13 @@ export default class JitsiRemoteTrack extends JitsiTrack {
317221 // Resizing canvas that will be exported to GUI
318222 canvasDecoded . width = width * 2 ;
319223 canvasDecoded . height = height * 2 ;
320- if ( timer == true ) {
321- console . time ( "TIMER imageDataRestore create decoder" ) ;
322- }
323224 const imageDataRestore = ctxDecoded . createImageData ( canvasDecoded . width , canvasDecoded . height ) ;
324- if ( timer == true ) {
325- console . timeEnd ( "TIMER imageDataRestore create decoder" ) ;
326- }
327225 let dataRestore = imageDataRestore . data ;
328- // Channels are reordered as required by javascript
329- if ( timer == true ) {
330- console . time ( "TIMER full py2js decoder" ) ;
331- }
332- // dataRestore = await py2js(dataRestore,tensorData,canvasDecoded.width,canvasDecoded.height);
333226 dataRestore . set ( tensorData )
334- if ( timer == true ) {
335- console . timeEnd ( "TIMER full py2js decoder" ) ;
336- }
337227 // Setting decoded image in the canvas-sender
338228 ctxDecoded . putImageData ( imageDataRestore , 0 , 0 ) ;
339229 if ( timer == true ) {
340- console . timeEnd ( "TIMER decoder" ) ;
230+ console . timeEnd ( "TIMER decoder full-elapsed time " ) ;
341231 }
342232 }
343233 catch ( error ) {
0 commit comments