gemercheung 3 years ago
parent
commit
c8897001fa
5 changed files with 42 additions and 31 deletions
  1. 2 2
      dist/index.html
  2. 1 1
      src/ActionsHandler.js
  3. 10 10
      src/Workers.js
  4. 2 0
      src/XMaterialComponent.js
  5. 27 18
      src/h264Decoder/VDecoder.js

+ 2 - 2
dist/index.html

@@ -38,12 +38,12 @@
     <script src="./libs/nipplejs.min.js"></script>
     <script src="./shader.js"></script>
 
-    <script src="https://cdn.bootcdn.net/ajax/libs/vConsole/3.9.0/vconsole.min.js"></script>
+    <!-- <script src="https://cdn.bootcdn.net/ajax/libs/vConsole/3.9.0/vconsole.min.js"></script>
     <script>
         // init vConsole
         var vConsole = new VConsole();
         console.log('Hello world');
-    </script>
+    </script> -->
 
     <!-- <script src="./webrtc//adapter-7.4.0.min.js"></script>
     <script src="./webrtc/srs.sdk.js"></script> -->

+ 1 - 1
src/ActionsHandler.js

@@ -26,7 +26,7 @@ export default class ActionsHandler {
         //xst
         window.workerReady = false
         this.vDecoder = new VDecoder({   
-            maxChip: 3,
+            maxChip: 2,
           });
         window.vDecoder = this.vDecoder
         this.init()

+ 10 - 10
src/Workers.js

@@ -545,16 +545,16 @@ export default class Workers {
         
         this.decoderWorker = new Worker(URL.createObjectURL(t));
  
-        this.decoderWorker.postMessage({
-            t: 9,
-            url: WASM_URLS[WASM_Version],
-            jitterLength: DECODER_PASSIVE_JITTER
-        });
-        window.decoderWorker = this.decoderWorker;
-        this.decoderWorker.postMessage({
-            t: 1,
-            config: e
-        });
+        // this.decoderWorker.postMessage({
+        //     t: 9,
+        //     url: WASM_URLS[WASM_Version],
+        //     jitterLength: DECODER_PASSIVE_JITTER
+        // });
+        // window.decoderWorker = this.decoderWorker;
+        // this.decoderWorker.postMessage({
+        //     t: 1,
+        //     config: e
+        // });
 
         return new Promise(resolve=>{
             this.decoderWorker.onmessage = n=>{

+ 2 - 0
src/XMaterialComponent.js

@@ -351,6 +351,8 @@ export default class XMaterialComponent {
                 VideoTexture.update(stream)
                 VideoTexture.updateSamplingMode(BABYLON.Texture.BILINEAR_SAMPLINGMODE)
             }
+            stream = null;
+            data= null;
 
             //(o = this._videoRawYUVTexArray.getVideoYUVTex(videosResOriArrayIndex)) == null || o.update(stream),
             //(a = this._videoRawYUVTexArray.getVideoYUVTex(videosResOriArrayIndex)) == null || a.updateSamplingMode(BABYLON.Texture.BILINEAR_SAMPLINGMODE)

+ 27 - 18
src/h264Decoder/VDecoder.js

@@ -48,15 +48,23 @@ export class VDecoder extends EventEmitter {
       switch (message.type) {
         case "pictureReady":
           //   onPictureReady(message);
-          // console.log(
-          //   "[VDecoder]::decodeData",
-          //   Object.assign(message, { clipId: this.decodingId })
-          // );
+          console.log(
+            "[VDecoder]::decodeData",
+            Object.assign(message, { clipId: this.decodingId })
+          );
+          const { renderStateId } = e.data;
           this.emit(
             "decodeData",
             Object.assign(message, { clipId: this.decodingId })
           );
 
+          this.worker.postMessage({
+            type: "release",
+            renderStateId: renderStateId,
+          });
+
+          console.log("[VDecoder]::decodeData:release",renderStateId);
+
           if (this.decoding && this.decodingId) {
             this.decodeNext(this.decodingId);
           }
@@ -218,29 +226,30 @@ export class VDecoder extends EventEmitter {
     if (nextFrame) {
       this.decode(nextFrame, tempId);
     } else {
-      console.log("tempVideos", this.tempVideos.length);
-      const clip = this.tempVideos.find(({ id }) => id === this.decodingId);
-      if (clip) {
-        const fps = (1000 / (Date.now() - this.start)) * clip.data.length;
-        console.log(
-          `Decoded ${clip.data.length} frames in ${
-            Date.now() - this.start
-          }ms @ ${fps >> 0}FPS`
-        );
-      } else {
-        console.warn("不存在clip");
-      }
+      // console.log("tempVideos", this.tempVideos.length);
+      // const clip = this.tempVideos.find(({ id }) => id === this.decodingId);
+      // if (clip) {
+      //   const fps = (1000 / (Date.now() - this.start)) * clip.data.length;
+      //   console.log(
+      //     `Decoded ${clip.data.length} frames in ${
+      //       Date.now() - this.start
+      //     }ms @ ${fps >> 0}FPS`
+      //   );
+      // } else {
+      //   console.warn("不存在clip");
+      // }
 
       this.decoding = false;
       // this.decodingId = null;
       tempId = 0;
-      clip && clip.id && this.emit("decodeDone", clip.id);
+      // clip && clip.id && this.emit("decodeDone", clip.id);
     }
   }
   flush() {
     this.tempVideos = [];
     this.cacheBufferTotal = null;
-    console.warn('flush')
+
+    console.warn("flush");
   }
 
   preloader(preload) {}