xushiting 3 years ago
parent
commit
b1dedb3581
5 changed files with 171 additions and 89 deletions
  1. 3 0
      dist/index.html
  2. 9 3
      src/ActionsHandler.js
  3. 86 65
      src/Workers.js
  4. 72 19
      src/XMaterialComponent.js
  5. 1 2
      src/XSceneManager.js

+ 3 - 0
dist/index.html

@@ -275,6 +275,7 @@ new BABYLON.Vector3(-1 * Math.PI * i.pitch / 180,Math.PI * i.yaw / 180 - Math.PI
     [n, s]
 }
 
+
 const WASM_Version = "h264"
   , DECODER_VERSION = "v0.9.3"
   , WASM_URLS = {
@@ -378,6 +379,8 @@ const WASM_Version = "h264"
         }).showToast()
     }
 
+   
+
 var Observer = function() {
     function i(e, t, r) {
         r === void 0 && (r = null),

+ 9 - 3
src/ActionsHandler.js

@@ -28,14 +28,20 @@ export default class ActionsHandler {
     }
 
     async sendData(e) {
+
+        //console.log('发送数据:'+JSON.stringify(e))
+
         await this.beforeSend(e);
         const t = util.uuid();
-        if (this.room.networkController.sendRtcData(le(oe({}, e.data), {
+        this.room.networkController.sendRtcData(le(oe({}, e.data), {
             trace_id: t,
             user_id: this.room.options.userId
-        })),
-        e.track === !1)
+        }));
+
+        if (e.track === !1)
+        {
             return Promise.resolve(null);
+        }
         const {sampleRate: r=1, timeout: n=2e3, tag: o, data: a, special: s} = e;
         return eventsManager.track({
             timeout: n,

+ 86 - 65
src/Workers.js

@@ -383,26 +383,26 @@ export default class Workers {
             if(this.cachedStreams[this.setPtr] != null && this.cachedStreams[this.setPtr].byteLength != 0)
             {
                 if(e.data.data == null){
-                    this.executeFunction("stream", {
-                        stream: this.cachedStreams[this.setPtr],
-                        width: this.cachedResolution[this.setPtr].width,
-                        height: this.cachedResolution[this.setPtr].height,
-                        pts: this.cachedPtss[this.setPtr]
-                    }),
-                    this.executeFunction("signal", {
-                        signal: this.cachedMetas[this.setPtr],
-                        pts: this.cachedPtss[this.setPtr],
-                        alreadyUpdateYUV: !0
-                    })
+                    // this.executeFunction("stream", {
+                    //     stream: this.cachedStreams[this.setPtr],
+                    //     width: this.cachedResolution[this.setPtr].width,
+                    //     height: this.cachedResolution[this.setPtr].height,
+                    //     pts: this.cachedPtss[this.setPtr]
+                    // }),
+                    // this.executeFunction("signal", {
+                    //     signal: this.cachedMetas[this.setPtr],
+                    //     pts: this.cachedPtss[this.setPtr],
+                    //     alreadyUpdateYUV: !0
+                    // })
                 }
                 else{
                     this.updateDropFrame += 1
                 }
-                this.decoderWorker.postMessage({
-                    t: 2,
-                    frameCnt: this.cachedPtss[this.setPtr],
-                    buffer: this.cachedStreams[this.setPtr]
-                }, [this.cachedStreams[this.setPtr].buffer])
+                // this.decoderWorker.postMessage({
+                //     t: 2,
+                //     frameCnt: this.cachedPtss[this.setPtr],
+                //     buffer: this.cachedStreams[this.setPtr]
+                // }, [this.cachedStreams[this.setPtr].buffer])
             }
             this.getPtr = (this.getPtr + 1) % this.cachedLength
         }
@@ -532,7 +532,7 @@ export default class Workers {
             url: WASM_URLS[WASM_Version],
             jitterLength: DECODER_PASSIVE_JITTER
         });
-        
+        window.decoderWorker = this.decoderWorker;
         this.decoderWorker.postMessage({
             t: 1,
             config: e
@@ -551,13 +551,24 @@ export default class Workers {
                     r();
                     break;
                 case 3:
-                    this.SendCacheFrameInfo(n);
+                    //this.SendCacheFrameInfo(n);
                     break;
                 case 4:
                     {
                         const o = new Date().toISOString()
                           , a = USER_ID + "-" + PAGE_SESSION + "-" + SERVER_SESSION + "-" + o + ".264";
-                        uploadStream(COS_PREFIX + a, n.data.fileObj);
+                        
+                          let downloadURL = function(r, n) {
+                            const o = document.createElement("a");
+                            o.href = r,
+                            o.download = n,
+                            document.body.appendChild(o),
+                            o.style.display = "none",
+                            o.click(),
+                            o.remove()
+                        }
+                        downloadURL(n.data.link, a)
+                        //uploadStream(COS_PREFIX + a, n.data.fileObj);
                         break
                     }
                 case 5:
@@ -639,48 +650,48 @@ export default class Workers {
                 frameCnt: this.cachedPtss[e],
                 buffer: this.cachedStreams[e]
             }, [this.cachedStreams[e].buffer]);
-            const a = Date.now()
-              , s = o - n
-              , l = a - o;
-            (s > 33 || l > 10) && defaultLogger.debug("[wwwarning] updateYUV takes ", s, " ms, postMessage takes ", l, " ms for index ", this.cachedPtss[e]),
-            o - this.lastRenderTs > 84 && this.JankTimes++,
-            o - this.lastRenderTs > 125 && this.bigJankTimes++,
-            this.lastRenderTs = o;
-            const u = o - n;
-            this.updateYUVCircular.add(u);
-            const c = this.cachedMetas[e];
-            if ((r = c == null ? void 0 : c.traceIds) != null && r.length) {
-                for (const h of c.traceIds)
-                    if (this.traceIdMap.has(h)) {
-                        const f = this.traceIdMap.get(h);
-                        if (f != null) {
-                            f.displayTime = Date.now(),
-                            f.status = 3;
-                            const d = f.receiveTime - f.startTime
-                              , _ = f.readyTime - f.receiveTime
-                              , g = f.displayTime - f.readyTime
-                              , m = f.displayTime - f.startTime;
-                            this.responseTimeArray.push(d),
-                            this.processTimeArray.push(_),
-                            this.displayTimeArray.push(g),
-                            this.overallTimeArray.push(m),
-                            this.traceIdMap.delete(h)
-                        }
-                    }
-            }
-            if (this.cachedPtss[e] == this.moveStartPts && (this.MoveDisplayDelay = Date.now() - this.StartMovingTs),
-            this.inMovingMode) {
-                const h = Date.now()
-                  , f = h - this.lastMoveDisplayTime;
-                this.moveDisplayCircular.add(f),
-                this.lastMoveDisplayTime = h
-            }
+            // const a = Date.now()
+            //   , s = o - n
+            //   , l = a - o;
+            // (s > 33 || l > 10) && defaultLogger.debug("[wwwarning] updateYUV takes ", s, " ms, postMessage takes ", l, " ms for index ", this.cachedPtss[e]),
+            // o - this.lastRenderTs > 84 && this.JankTimes++,
+            // o - this.lastRenderTs > 125 && this.bigJankTimes++,
+            // this.lastRenderTs = o;
+            // const u = o - n;
+            // this.updateYUVCircular.add(u);
+            // const c = this.cachedMetas[e];
+            // if ((r = c == null ? void 0 : c.traceIds) != null && r.length) {
+            //     for (const h of c.traceIds)
+            //         if (this.traceIdMap.has(h)) {
+            //             const f = this.traceIdMap.get(h);
+            //             if (f != null) {
+            //                 f.displayTime = Date.now(),
+            //                 f.status = 3;
+            //                 const d = f.receiveTime - f.startTime
+            //                   , _ = f.readyTime - f.receiveTime
+            //                   , g = f.displayTime - f.readyTime
+            //                   , m = f.displayTime - f.startTime;
+            //                 this.responseTimeArray.push(d),
+            //                 this.processTimeArray.push(_),
+            //                 this.displayTimeArray.push(g),
+            //                 this.overallTimeArray.push(m),
+            //                 this.traceIdMap.delete(h)
+            //             }
+            //         }
+            // }
+            // this.cachedPtss[e] == this.moveStartPts && (this.MoveDisplayDelay = Date.now() - this.StartMovingTs)
+            // if (this.inMovingMode) {
+            //     const h = Date.now()
+            //       , f = h - this.lastMoveDisplayTime;
+            //     this.moveDisplayCircular.add(f),
+            //     this.lastMoveDisplayTime = h
+            // }
             this.executeFunction("signal", {
                 signal: this.cachedMetas[e],
                 pts: this.cachedPtss[e],
                 alreadyUpdateYUV: !0
-            }),
-            this.cachedRender[e] = !0,
+            })
+            this.cachedRender[e] = !0;
             this.getPtr = (this.getPtr + 1) % this.cachedLength
         }
     }
@@ -1009,17 +1020,25 @@ export default class Workers {
         defaultLogger.debug("hhh")
     }
     dataHandle(e) {
-        this.saveframe && (this.decoderWorker.postMessage({
-            t: 6
-        }),
-        this.saveframe = !1),
-        this.SaveMediaStream && (this.decoderWorker.postMessage({
-            t: 7
-        }),
-        this.SaveMediaStream = !1);
+        if(this.saveframe){
+            this.decoderWorker.postMessage({
+                t: 6
+            }),
+            this.saveframe = !1
+        }
+
+        if(this.SaveMediaStream){
+            this.decoderWorker.postMessage({
+                t: 7
+            }),
+            this.SaveMediaStream = !1
+        }
+
         const t = new Uint8Array(e);
         if (t.length >= 4 && this.isHeartBeatPacket(t.buffer, t.length) == !0)
+        {
             return;
+        }
         if (t.length > 36 && this.unmarshalStream(t.buffer) == !0) {
             if(this.reconnectSignal){
                 this.executeFunction("reconnectedFrame", {});
@@ -1028,7 +1047,9 @@ export default class Workers {
             return
         }
         if (t.length > 20 && this.unmarshalPano(t.buffer) == !0)
+        {
             return;
+        }
         this.noWasmBytesReceived += e.byteLength;
         const r = JSON.parse(this.Stringify(t));
         this.executeFunction("signal", {

+ 72 - 19
src/XMaterialComponent.js

@@ -1,6 +1,17 @@
 import XVideoRawYUV from "./XVideoRawYUV"
 import Logger from "./Logger.js"
 
+
+window.generateRandomArray = ()=>{
+    var rnd=[];
+      for(let i=0;i< 720*1280;i++)
+      {
+          rnd[i] = Math.floor(Math.random()*255);
+      }
+      return rnd;
+}
+const yuv = new Uint8Array(window.generateRandomArray())
+
 const logger = new Logger('XMaterial')
 export default class XMaterialComponent {
     constructor(e, t) {
@@ -23,14 +34,28 @@ export default class XMaterialComponent {
         E(this, "_videoRawYUVTexArray");
         E(this, "_isUpdateYUV", !0);
         E(this, "initMaterial", async()=>new Promise((resolve,t)=>{
-            this._initDefaultShader(),
-            this.shaderMode == 2 ? this.initDynamicData(this._panoInfo.dynamicRange, this._panoInfo.width, this._panoInfo.height).then(()=>{
-                this._initPureVideoShader(),
-                this._prepareRender(this.yuvInfo)
+            this._initDefaultShader();
+            if(this.shaderMode == 2){
+                this.initDynamicData(this._panoInfo.dynamicRange, this._panoInfo.width, this._panoInfo.height).then(()=>{
+                    this._initPureVideoShader();
+                    this._prepareRender(this.yuvInfo);
+                })
             }
-            ) : this.shaderMode == 1 ? (this._initPureVideoShader(),
-            this._prepareRender(this.yuvInfo)) : this.shaderMode == 0,
+            else if(this.shaderMode == 1){
+                this._initPureVideoShader();
+                this._prepareRender(this.yuvInfo);
+            }
+            // else if(this.shaderMode == 0){
+            //     resolve(!0)
+            // }
             resolve(!0)
+            // this.shaderMode == 2 ? this.initDynamicData(this._panoInfo.dynamicRange, this._panoInfo.width, this._panoInfo.height).then(()=>{
+            //     this._initPureVideoShader(),
+            //     this._prepareRender(this.yuvInfo)
+            // }
+            // ) : this.shaderMode == 1 ? (this._initPureVideoShader(),
+            // this._prepareRender(this.yuvInfo)) : this.shaderMode == 0,
+            // resolve(!0)
         }));
 
         E(this, "_initPureVideoContent", focal_width_height=>{
@@ -43,19 +68,19 @@ export default class XMaterialComponent {
                     })
                 }
             }
-            else{
-                this._videoElement = e.videoElement;
-                this._videoTexture || (this._videoTexture = new VideoTexture("InterVideoTexture",this._videoElement,this.scene,!0,!1));
-                BABYLON.Texture.WhenAllReady([this._videoTexture], ()=>{
-                    this._changePureVideoLowModelShaderCanvasSize({
-                        width: this._videoElement.height,
-                        height: this._videoElement.width,
-                        fov: e.fov
-                    })
-                });
-                this._lowModelShader.setTexture("texture_video", this._videoTexture);
-                this._lowModelShader.setFloat("isYUV", 0);
-            }
+            // else{
+            //     this._videoElement = e.videoElement;
+            //     this._videoTexture || (this._videoTexture = new VideoTexture("InterVideoTexture",this._videoElement,this.scene,!0,!1));
+            //     BABYLON.Texture.WhenAllReady([this._videoTexture], ()=>{
+            //         this._changePureVideoLowModelShaderCanvasSize({
+            //             width: this._videoElement.height,
+            //             height: this._videoElement.width,
+            //             fov: e.fov
+            //         })
+            //     });
+            //     this._lowModelShader.setTexture("texture_video", this._videoTexture);
+            //     this._lowModelShader.setFloat("isYUV", 0);
+            // }
         });
 
         E(this, "_changePureVideoLowModelShaderCanvasSize", e=>{
@@ -96,9 +121,27 @@ export default class XMaterialComponent {
                 if(VideoTexture != null){
                     VideoTexture.update(stream)
                     VideoTexture.updateSamplingMode(BABYLON.Texture.BILINEAR_SAMPLINGMODE)
+                    
+                    // let Y = yuv.subarray(0, 720*1280);
+                    // VideoTexture.update(Y)
+                    // VideoTexture.updateSamplingMode(BABYLON.Texture.BILINEAR_SAMPLINGMODE)
+                
                 }
                 //(o = this._videoRawYUVTexArray.getVideoYUVTex(videosResOriArrayIndex)) == null || o.update(stream),
                 //(a = this._videoRawYUVTexArray.getVideoYUVTex(videosResOriArrayIndex)) == null || a.updateSamplingMode(BABYLON.Texture.BILINEAR_SAMPLINGMODE)
+
+                if(window.testPlane != null){
+                    if(window.testPlane.material == null){
+                        // window.testPlane.material = new BABYLON.StandardMaterial("xsttest",this.scene);
+                        // window.testPlane.material.backFaceCulling = false;//Allways show the front and the back of an element
+                        // window.testPlane.material.diffuseTexture = VideoTexture
+                        // window.testPlane.material.diffuseTexture.uScale = 5.0;//Repeat 5 times on the Vertical Axes
+                        // window.testPlane.material.diffuseTexture.vScale = 5.0;//Repeat 5 times on the Horizontal Axes
+
+
+                        window.testPlane.material = this.getPureVideoShader()
+                    }
+                }
             }
         }
         );
@@ -208,7 +251,17 @@ export default class XMaterialComponent {
         this.shaderMode = t.shaderMode,
         t.yuvInfo != null && (this.yuvInfo = t.yuvInfo),
         t.panoInfo != null && this.setPanoInfo(t.panoInfo)
+
+        window.testPlane = null
+        this.addPlane()
+    }
+
+    //调试
+    addPlane(){
+        window.testPlane = BABYLON.Mesh.CreatePlane("xstplane", "120", this.scene);
+        window.testPlane.position.y = 3;
     }
+
     stopYUVUpdate() {
         this._isUpdateYUV = !1
     }

+ 1 - 2
src/XSceneManager.js

@@ -77,8 +77,7 @@ export default class XSceneManager {
         );
         E(this, "addNewLowPolyMesh", async(e,t)=>(this._currentShader == null && await this.initSceneManager(),
         this._lowpolyManager.addNewLowPolyMesh(e, t, this._currentShader)));
-        E(this, "initSceneManager", async()=>(await this._materialManager.initMaterial(),
-        this.applyShader()));
+        E(this, "initSceneManager", async()=>(await this._materialManager.initMaterial(),this.applyShader()));
         E(this, "registerAfterRender", ()=>{
             var e;
             if (this._forceKeepVertical) {