gemercheung 3 年之前
父节点
当前提交
7f0008cc2a
共有 7 个文件被更改,包括 864 次插入693 次删除
  1. 2 2
      src/Socket.js
  2. 1 1
      src/Workers-bk.js
  3. 134 88
      src/Workers.js
  4. 3 3
      src/XSceneManager.js
  5. 2 2
      src/main.js
  6. 0 0
      src/v2Decoder/decoder-origin.js
  7. 722 597
      src/v2Decoder/index.js

+ 2 - 2
src/Socket.js

@@ -28,7 +28,7 @@ export default class Socket extends EventEmitter {
             const t = JSON.stringify(e);
             e.id !== "heartbeat" && logger.info("send ws frame", t);
             this._ws.send(t)
-            console.log('socket发送数据:'+t)
+            // console.log('socket发送数据:'+t)
         }
         );
         E(this, "startGame", ()=>{
@@ -164,7 +164,7 @@ export default class Socket extends EventEmitter {
             let r = null;
             try {
                 r = JSON.parse(t.data)
-                console.log('接收socket数据:'+t.data)
+                // console.log('接收socket数据:'+t.data)
             } catch (o) {
                 logger.error(o);
                 return

+ 1 - 1
src/Workers-bk.js

@@ -1297,7 +1297,7 @@ export default class Workers {
     }
     this.noWasmBytesReceived += e.byteLength;
     const o = JSON.parse(this.Stringify(i));
-    console.log("接受webrtc请求:" + JSON.stringify(o));
+    // console.log("接受webrtc请求:" + JSON.stringify(o));
     this.executeFunction("signal", {
       signal: o,
       pts: -1,

+ 134 - 88
src/Workers.js

@@ -58,16 +58,16 @@ export default class Workers {
       (this.bigJankTimes = 0),
       (this.DecodeJankTimes = 0),
       (this.bigDecodeJankTimes = 0),
-      (this.saveframe = !1),
-      (this.SaveMediaStream = !1),
+      (this.saveframe = false),
+      (this.SaveMediaStream = false),
       (this.packetsLost = 0),
-      (this.showAllReceivedMetadata = !1),
+      (this.showAllReceivedMetadata = false),
       (this.firstMediaArraval = 0),
-      (this.firstMediaReceived = !1),
+      (this.firstMediaReceived = false),
       (this.firstYUVDecoded = 0),
       (this.firstRender = 0),
-      (this.firstYUVReceived = !1),
-      (this.reconnectSignal = !1),
+      (this.firstYUVReceived = false),
+      (this.reconnectSignal = false),
       (this.serverFrameSlow = 0),
       (this.serverFrameFast = 0),
       (this.clientFrameSlow = 0),
@@ -75,7 +75,7 @@ export default class Workers {
       (this.lastServerTS = 0),
       (this.lastClientTS = 0),
       (this.lastSeq = 0),
-      (this.lastIsPureMeta = !1),
+      (this.lastIsPureMeta = false),
       (this.lastHBPacketTs = 0),
       (this.HBPacketInterval = 0),
       (this.lastHBPacketSrvSentTs = 0),
@@ -84,22 +84,22 @@ export default class Workers {
       (this.cachedStreams = new Array(this.cachedLength)),
       (this.cachedMetas = new Array(this.cachedLength)),
       (this.cachedPtss = new Array(this.cachedLength)),
-      (this.cachedRender = Array(this.cachedLength).fill(!1)),
+      (this.cachedRender = Array(this.cachedLength).fill(false)),
       (this.cachedResolution = new Array(this.cachedLength)),
       (this.getPtr = 0),
       (this.setPtr = 0),
       (this.receiveIframes = 0),
       (this.decodeIframes = 0),
       (this.prevSenderTs = -1),
-      (this.serverSendTimeArray = new CircularArray(120, !1, [])),
-      (this.inPanoMode = !1),
+      (this.serverSendTimeArray = new CircularArray(120, false, [])),
+      (this.inPanoMode = false),
       (this.PanoStatus = {
         x: 0,
         y: 0,
         z: 0,
         tiles: [],
       }),
-      (this.DynamicPanoTest = !1),
+      (this.DynamicPanoTest = false),
       (this.PanoMask = new ArrayBuffer(8)),
       (this.PanoView = new DataView(this.PanoMask)),
       (this.userId_test = ""),
@@ -120,15 +120,15 @@ export default class Workers {
       (this.joyStickResponseMiss = 0),
       (this.joyStickProcessMiss = 0),
       (this.joyStickDisplayMiss = 0),
-      (this.updateYUVCircular = new CircularArray(120, !1, [])),
+      (this.updateYUVCircular = new CircularArray(120, false, [])),
       (this.updateDropFrame = 0),
-      (this.metaParseAraay = []),
+      (this.metaParseArray = []),
       (this.responseMoveMiss = 0),
       (this.processMoveMiss = 0),
       (this.displayMoveMiss = 0),
       (this.MovingTraceId = ""),
       (this.PendingMovingTraceId = ""),
-      (this.inMovingMode = !1),
+      (this.inMovingMode = false),
       (this.StartMovingTs = 0),
       (this.PendingStartMovingTs = 0),
       (this.moveEvent = ""),
@@ -140,35 +140,39 @@ export default class Workers {
       (this.lastMoveResponseTime = 0),
       (this.lastMoveProcessTime = 0),
       (this.lastMoveDisplayTime = 0),
-      (this.moveResponseCircular = new CircularArray(120, !0, [
+      (this.moveResponseCircular = new CircularArray(120, true, [
         STUCK_STAGE_GOOD,
         STUCK_STAGE_WELL,
         STUCK_STAGE_FAIR,
         STUCK_STAGE_BAD,
       ])),
-      (this.moveProcessCircular = new CircularArray(120, !0, [
+      (this.moveProcessCircular = new CircularArray(120, true, [
         STUCK_STAGE_GOOD,
         STUCK_STAGE_WELL,
         STUCK_STAGE_FAIR,
         STUCK_STAGE_BAD,
       ])),
-      (this.moveDisplayCircular = new CircularArray(120, !0, [
+      (this.moveDisplayCircular = new CircularArray(120, true, [
         STUCK_STAGE_GOOD,
         STUCK_STAGE_WELL,
         STUCK_STAGE_FAIR,
         STUCK_STAGE_BAD,
       ])),
       (this.moveStartPts = -1),
-      (this.frameServerCircular = new CircularArray(120, !1, [])),
-      (this.srvMetaIntervalCircular = new CircularArray(120, !1, [])),
-      (this.srvMediaIntervalCircular = new CircularArray(120, !1, [])),
-      (this.srvHBMetaIntervalCircular = new CircularArray(120, !1, [])),
-      (this.srvHBMetaIntervalSrvSentCircular = new CircularArray(120, !1, [])),
-      (this.frameClientCircular = new CircularArray(120, !1, [])),
+      (this.frameServerCircular = new CircularArray(120, false, [])),
+      (this.srvMetaIntervalCircular = new CircularArray(120, false, [])),
+      (this.srvMediaIntervalCircular = new CircularArray(120, false, [])),
+      (this.srvHBMetaIntervalCircular = new CircularArray(120, false, [])),
+      (this.srvHBMetaIntervalSrvSentCircular = new CircularArray(
+        120,
+        false,
+        []
+      )),
+      (this.frameClientCircular = new CircularArray(120, false, [])),
       (this.unmarshalStreamExecutionArray = new SecondArray()),
       (this.receiveYUVExecutionArray = new SecondArray()),
       (this.postMessageWaitArray = new SecondArray()),
-      (this.firstUpdateYUV = !0),
+      (this.firstUpdateYUV = true),
       (this.functionMap = new Map()),
       (this.WASM_VERSION = "WASM-1.1"),
       (this.frameHistory = []),
@@ -303,7 +307,7 @@ export default class Workers {
         o != null && ((o.receiveTime = Date.now()), (o.status = 1));
       }
       if (i == this.PendingMovingTraceId) {
-        (this.inMovingMode = !0),
+        (this.inMovingMode = true),
           (this.MovingTraceId = this.PendingMovingTraceId),
           (this.StartMovingTs = this.PendingStartMovingTs),
           (this.PendingMovingTraceId = ""),
@@ -474,10 +478,11 @@ export default class Workers {
         metric: "firstRenderAt",
         value: j,
         group: "joinRoom",
-      }),
-        (this.firstYUVReceived = !0),
-        (this.lastRenderTs = Date.now());
+      });
+      this.firstYUVReceived = true;
+      this.lastRenderTs = Date.now();
     }
+
     if (
       !this.cachedRender[this.setPtr] &&
       this.cachedMetas[this.setPtr] != null
@@ -497,12 +502,16 @@ export default class Workers {
           this.executeFunction("signal", {
             signal: this.cachedMetas[this.setPtr],
             pts: this.cachedPtss[this.setPtr],
-            alreadyUpdateYUV: !0,
+            alreadyUpdateYUV: true,
           });
         } else {
           this.updateDropFrame += 1;
         }
 
+        //重新decode cache ptr
+
+        console.log("this.cachedStreams", this.cachedStreams, this.setPtr);
+
         this.decoderWorker.postMessage(
           {
             t: 2,
@@ -540,11 +549,12 @@ export default class Workers {
     this.cachedStreams[c] = e.data.data;
     this.cachedMetas[c] = e.data.metadata;
     this.cachedPtss[c] = e.data.pts;
-    this.cachedRender[c] = !1;
+    this.cachedRender[c] = false;
     this.cachedResolution[c] = {
       width: e.data.width,
       height: e.data.height,
     };
+    
     this.setPtr = (this.setPtr + 1) % this.cachedLength;
     const _ = Date.now() - i;
     this.receiveYUVExecutionArray.add(_);
@@ -622,20 +632,20 @@ export default class Workers {
       data: e.data.data,
       metadata: e.data.metadata,
       tileId: e.data.tileId,
-      finished: !0,
+      finished: true,
       matchAngle: o,
     });
   }
   enable_decoder_queue_logging() {
     this.decoderWorker.postMessage({
       t: 100,
-      status: !0,
+      status: true,
     });
   }
   disable_decoder_queue_logging() {
     this.decoderWorker.postMessage({
       t: 100,
-      status: !1,
+      status: false,
     });
   }
 
@@ -707,13 +717,13 @@ export default class Workers {
             break;
           }
           case 5:
-            console.log(
-              "接受webrtc请求(来自worker):" + JSON.stringify(s.data.metadata)
-            );
+            // console.log(
+            //   "接受webrtc请求(来自worker):" + JSON.stringify(s.data.metadata)
+            // );
             this.executeFunction("signal", {
               signal: s.data.metadata,
               pts: -1,
-              alreadyUpdateYUV: !1,
+              alreadyUpdateYUV: false,
             });
             break;
           case 6:
@@ -776,7 +786,7 @@ export default class Workers {
           value: $,
           group: "joinRoom",
         }),
-          (this.firstUpdateYUV = !1);
+          (this.firstUpdateYUV = false);
       }
       this.cachedStreams[e] != null &&
         this.executeFunction("stream", {
@@ -785,6 +795,7 @@ export default class Workers {
           height: this.cachedResolution[e].height,
           pts: this.cachedPtss[e],
         });
+
       const c = Date.now();
       this.cachedStreams[e] != null &&
         this.decoderWorker.postMessage(
@@ -854,24 +865,32 @@ export default class Workers {
           _e = $ - this.lastMoveDisplayTime;
         this.moveDisplayCircular.add(_e), (this.lastMoveDisplayTime = $);
       }
-      console.log(
-        "接受webrtc请求(定时执行UpdateYUV):" +
-          JSON.stringify(this.cachedMetas[e])
-      );
+      // console.log(
+      //   "接受webrtc请求(定时执行UpdateYUV):" +
+      //     JSON.stringify(this.cachedMetas[e])
+      // );
+      // console.log('回传',{
+      //   signal: this.cachedMetas[e],
+      //   pts: this.cachedPtss[e],
+      //   alreadyUpdateYUV: true,
+      // })
       this.executeFunction("signal", {
         signal: this.cachedMetas[e],
         pts: this.cachedPtss[e],
-        alreadyUpdateYUV: !0,
-      }),
-        (this.cachedRender[e] = !0),
-        (this.getPtr = (this.getPtr + 1) % this.cachedLength);
+        alreadyUpdateYUV: true,
+      });
+      this.cachedRender[e] = true;
+      this.getPtr = (this.getPtr + 1) % this.cachedLength;
     }
   }
   unmarshalPano(e) {
+    return false;
+  }
+  unmarshalPanobk(e) {
     const i = new DataView(e),
       o = i.getUint32(0);
-    if (o == 1723558763) return !0;
-    if (o != 2296221069) return !1;
+    if (o == 1723558763) return true;
+    if (o != 2296221069) return false;
     console.log("Receive Pano Message"), i.getUint16(4);
     const s = i.getUint16(6),
       c = i.getUint32(8),
@@ -919,11 +938,11 @@ export default class Workers {
           (this.panoCacheSize = k),
           (this.cachePanoTileID = c);
     }
-    return !0;
+    return true;
   }
   clearMoveArray() {
     (this.MovingTraceId = ""),
-      (this.inMovingMode = !1),
+      (this.inMovingMode = false),
       (this.StartMovingTs = 0),
       (this.MoveToFrameCnt = 0),
       (this.MoveResponseDelay = 0),
@@ -962,25 +981,27 @@ export default class Workers {
     this.serverSendTimeArray.add(i), (this.prevSenderTs = e);
   }
   // new unmarshalStream
-  unmarshalStream(e) {
+  unmarshalStreamBk(e) {
     console.log("e", e);
 
     return true;
   }
   // backup main unmarshalStreamBk
-  unmarshalStreamBk(e) {
+  unmarshalStream(e) {
     var lt, ft, ht, pt, dt, _t, mt, vt, yt, Et;
     const i = Date.now(),
       o = new DataView(e);
 
-    if (o.getUint32(0) != 1437227610) return !1;
+    if (o.getUint32(0) != 1437227610) return false;  // flag auth
+
+
     o.getUint16(4);
     const c = o.getUint16(6),
       d = o.getUint16(8),
       _ = d,
       b = o.getUint16(10);
-    let k = !1;
-    b == 1 && (k = !0);
+    let k = false;
+    b == 1 && (k = true);
     const j = o.getUint32(12),
       $ = o.getUint32(16),
       _e = o.getUint32(20),
@@ -991,10 +1012,9 @@ export default class Workers {
       nt = j + $,
       ot = e.byteLength - c,
       at = new Uint8Array(e, c, ot);
+
     this.calcSendTimeDiff(_e);
 
-    // console.log("rt", rt);
-    // console.log("$", $);
     console.log("流--", e.byteLength);
     // debugger;
     const down = Date.now();
@@ -1004,7 +1024,7 @@ export default class Workers {
         defaultLogger.error(
           "Stream Protocal Violation: receive illegal stream in Pano mode"
         ),
-        !0
+        true
       );
     if (ot === nt) {
       this.receivedMedia++;
@@ -1018,6 +1038,7 @@ export default class Workers {
         : gt - this.lastClientTS < 16 && this.clientFrameFast++;
       const St = $ === 0,
         xt = _e - this.lastServerTS;
+
       this.lastServerTS != 0 &&
         ((d + 65536 - this.lastSeq) % 65536 === 1 &&
           this.lastIsPureMeta == St &&
@@ -1030,15 +1051,20 @@ export default class Workers {
         (this.lastIsPureMeta = St),
         (this.lastServerTS = _e),
         (this.lastClientTS = gt);
-      const bt = At.subarray(0, j),
-        Rt = Date.now(),
-        Mt = JSON.parse(this.Stringify(bt)),
-        Pt = Date.now();
-      this.showAllReceivedMetadata && console.log(_e, gt, Mt),
-        this.metaParseAraay.push(Pt - Rt),
-        (lt = Mt.traceIds) != null &&
-          lt.length &&
-          this.processMetaWithTraceId(Mt),
+
+      const bt = At.subarray(0, j);
+      const Rt = Date.now();
+      const Mt = JSON.parse(this.Stringify(bt)); // json 与帧map的坐标数据
+      const Pt = Date.now();
+
+      this.showAllReceivedMetadata && console.log(_e, gt, Mt);
+
+      // console.log("Pt - Rt", Pt - Rt, Pt, Rt);
+      this.metaParseArray.push(Pt - Rt);
+
+      (lt = Mt.traceIds) != null &&
+        lt.length &&
+        this.processMetaWithTraceId(Mt),
         $ != 0 &&
           this.moveStartPts == -1 &&
           this.inMovingMode &&
@@ -1051,7 +1077,9 @@ export default class Workers {
             this.moveStartPts,
             this.MoveResponseDelay
           ));
+
       const It = this.getIsMoving(Mt);
+
       if (
         (this.inMovingMode &&
           It == 0 &&
@@ -1080,6 +1108,8 @@ export default class Workers {
               : pt.player) == null
             ? void 0
             : dt.position);
+
+      //封装格式
       const Dt = {
         t: 0,
         data: At,
@@ -1094,14 +1124,15 @@ export default class Workers {
         cachedKey: rt,
         position: st,
       };
+      // console.warn('Dt',Dt);
       if (this.inPanoMode) {
         // console.log('接受webrtc请求:'+JSON.stringify(Mt));
         this.executeFunction("signal", {
           signal: Mt,
           pts: -1,
-          alreadyUpdateYUV: !0,
+          alreadyUpdateYUV: true,
         });
-        return !0;
+        return true;
       }
 
       if (
@@ -1114,8 +1145,13 @@ export default class Workers {
           metric: "firstMediaArravalAt",
           value: Ct,
           group: "joinRoom",
-        }),
-          (this.firstMediaReceived = !0);
+        });
+        this.downloadBlob(
+          [At.buffer],
+          `first.h264`,
+          "application/octet-stream"
+        );
+        this.firstMediaReceived = true;
       }
     } else {
       const At = this.hasFrmCntInCache(_);
@@ -1129,6 +1165,7 @@ export default class Workers {
             0,
             nt
           );
+
           (this.cacheFrameComposes[At].frameCnt = -1),
             (this.cacheFrameComposes[At].size = 0),
             (this.cacheFrameComposes[At].startReceiveTime = 0),
@@ -1146,12 +1183,14 @@ export default class Workers {
               this.frameClientCircular.add(St - this.lastClientTS)),
             (this.lastServerTS = _e),
             (this.lastClientTS = St);
+
           const xt = gt.subarray(0, j),
             bt = Date.now(),
             Rt = JSON.parse(this.Stringify(xt)),
             Mt = Date.now();
+
           this.showAllReceivedMetadata && console.log(_e, St, Rt),
-            this.metaParseAraay.push(Mt - bt),
+            this.metaParseArray.push(Mt - bt),
             (_t = Rt.traceIds) != null &&
               _t.length &&
               this.processMetaWithTraceId(Rt),
@@ -1190,6 +1229,7 @@ export default class Workers {
                   : yt.player) == null
                 ? void 0
                 : Et.position);
+
           const It = {
             t: 0,
             data: gt,
@@ -1204,14 +1244,20 @@ export default class Workers {
             cachedKey: rt,
             position: st,
           };
+          //有效Iframe
+          console.error("IT", It);
+          console.log("It.data", It.data);
+
+          // this.downloadBlob([At.buffer], `${It.frameCnt}.gt.h264`, "application/octet-stream");
+
           if (this.inPanoMode) {
-            console.log("接受webrtc请求:" + JSON.stringify(Rt));
+            // console.log("接受webrtc请求:" + JSON.stringify(Rt));
             this.executeFunction("signal", {
               signal: Rt,
               pts: -1,
-              alreadyUpdateYUV: !0,
+              alreadyUpdateYUV: true,
             });
-            return !0;
+            return true;
           }
           if (
             (this.decoderWorker.postMessage(It, [gt.buffer]),
@@ -1226,7 +1272,7 @@ export default class Workers {
               value: Dt,
               group: "joinRoom",
             }),
-              (this.firstMediaReceived = !0);
+              (this.firstMediaReceived = true);
           }
         } else
           this.cacheFrameComposes[At].size > nt &&
@@ -1254,13 +1300,13 @@ export default class Workers {
       }
     }
     const ct = Date.now() - i;
-    return this.unmarshalStreamExecutionArray.add(ct), !0;
+    return this.unmarshalStreamExecutionArray.add(ct), true;
   }
   reset() {
     defaultLogger.debug("Worker reset is called"),
       (this.cacheFrameCnt = 0),
       (this.receivedMedia = 0),
-      (this.reconnectSignal = !0),
+      (this.reconnectSignal = true),
       this.decoderWorker.postMessage({
         t: 4,
       });
@@ -1274,7 +1320,7 @@ export default class Workers {
       this.decoderWorker.postMessage({
         t: 6,
       });
-      this.saveframe = !1;
+      this.saveframe = false;
     }
 
     if (this.SaveMediaStream) {
@@ -1282,23 +1328,23 @@ export default class Workers {
       this.decoderWorker.postMessage({
         t: 7,
       }),
-        (this.SaveMediaStream = !1);
+        (this.SaveMediaStream = false);
     }
 
     const i = new Uint8Array(e);
-    if (i.length >= 4 && this.isHeartBeatPacket(i.buffer, i.length) == !0) {
-      console.log("接受webrtc请求:心跳");
+    if (i.length >= 4 && this.isHeartBeatPacket(i.buffer, i.length) == true) {
+      // console.log("接受webrtc请求:心跳");
       return;
     }
-    if (i.length > 36 && this.unmarshalStream(i.buffer) == !0) {
+    if (i.length > 36 && this.unmarshalStream(i.buffer) == true) {
       this.reconnectSignal &&
         (this.executeFunction("reconnectedFrame", {}),
-        (this.reconnectSignal = !1));
-      console.log("接受webrtc请求:视频流");
+        (this.reconnectSignal = false));
+      // console.log("接受webrtc请求:视频流");
       return;
     }
-    if (i.length > 20 && this.unmarshalPano(i.buffer) == !0) {
-      console.log("接受webrtc请求:全景图");
+    if (i.length > 20 && this.unmarshalPano(i.buffer) == true) {
+      // console.log("接受webrtc请求:全景图");
       return;
     }
     this.noWasmBytesReceived += e.byteLength;
@@ -1307,7 +1353,7 @@ export default class Workers {
     this.executeFunction("signal", {
       signal: o,
       pts: -1,
-      alreadyUpdateYUV: !0,
+      alreadyUpdateYUV: true,
     });
   }
   changePanoMode(e) {

+ 3 - 3
src/XSceneManager.js

@@ -121,9 +121,9 @@ export default class XSceneManager {
         this.scene.clearCachedVertexData(),
         this.scene.cleanCachedTextureBuffer(),
         // 周恩光加 调试用工具栏
-        this.scene.debugLayer.show({
-            embedMode: true,
-        })
+        // this.scene.debugLayer.show({
+        //     embedMode: true,
+        // })
         this.urlTransformer = t.urlTransformer || (s=>Promise.resolve(s)),
         t.logger && defaultLog.setLogger(t.logger),
         this.gl = e.getContext("webgl2", {

+ 2 - 2
src/main.js

@@ -34,8 +34,8 @@ const l = async()=>{
             avatarId: 'KGe_Boy',
             roomId: 'e629ef3e-022d-4e64-8654-703bb96410eb',
             userId: nickname,
-            // wsServerUrl: 'wss://uat-eks.xverse.cn/ws',
-            wsServerUrl: "ws://localhost:6688/ws",
+            wsServerUrl: 'wss://uat-eks.xverse.cn/ws',
+            // wsServerUrl: "ws://localhost:6688/ws",
             // wsServerUrl: "wss://meta-socket.4dage.com/ws",
             appId: "10016",
             token: " ",

dist/libs/decoder-1.js → src/v2Decoder/decoder-origin.js


文件差异内容过多而无法显示
+ 722 - 597
src/v2Decoder/index.js