gemercheung 3 år sedan
förälder
incheckning
2ad0c7995c
3 ändrade filer med 58 tillägg och 27 borttagningar
  1. 17 5
      src/Workers.js
  2. 3 3
      src/main.js
  3. 38 19
      src/v2Decoder/index.js

+ 17 - 5
src/Workers.js

@@ -12,12 +12,13 @@ let USER_ID = "987412365",
   FRAME_COMPOSE_LENGTH = 5;
 
 let testFrame = -1;
+let testBuffer = new Uint8Array(1024 * 1024 * 10);
+let testBufferLength = 0;
 
 Number.prototype.padLeft = function (n, str) {
-  return Array(n - String(this).length + 1).join(str || '0') + this;
+  return Array(n - String(this).length + 1).join(str || "0") + this;
 };
 
-
 import CircularArray from "./CircularArray.js";
 import SecondArray from "./SecondArray.js";
 import v2Decoder from "./v2Decoder/index.js";
@@ -764,6 +765,7 @@ export default class Workers {
             }
             const _ = "wasm:" + d;
             this._rtcp.sendStringData(_);
+            console.log('meta——丢帧'+data.metadata);//.newUserStates[0].playerState.user.camera.yaw);
             break;
           }
           case 9: {
@@ -1035,7 +1037,7 @@ export default class Workers {
       _e = o.getUint32(20), // calcSendTimeDiff 与时间有关
       et = o.getUint16(24), // 大多数为 0,待定 与inPanoMode 开关有关系
       tt = o.getUint16(26), // 0 / 1 待定  与用户状态有关
-      rt = o.getUint32(28), // 0 cachedKey
+      rt = o.getUint32(28), // 0 cachedKey 3, 5, 7
       it = o.getUint32(c - 4), // ?同步I帧或大小slice steam切片 按开始大小 $是总大小
       nt = j + $, // ?cnt  宏块 总包大小
       ot = e.byteLength - c, // cnt 宏块 有效长段
@@ -1045,7 +1047,7 @@ export default class Workers {
 
     // console.log("hey", Date.now() - _e);
 
-    console.log("zh----", fCnt, b);
+    // console.log("zh----", fCnt, b);
     if (b !== 255) {
       console.log("gemer1", {
         byteLength: e.byteLength,
@@ -1316,7 +1318,17 @@ export default class Workers {
           // console.error("IT", fCnt, JSON.stringify(Rt));
           console.error("traceIds", fCnt, Rt.traceIds.length);
           // console.log("IT-fCnt", It.data);
-          console.log("testFrame", testFrame);
+          // const clip = It.data.subarray(It.metaLen, It.metaLen + It.mediaLen);
+          // console.log("testFrame", testFrame);
+          // testBuffer.set(clip, testBufferLength);
+          // testBufferLength += clip.byteLength;
+          // if (testFrame > 90) {
+          //   this.downloadBlob(
+          //     testBuffer.subarray(0, testBufferLength),
+          //     `origin.h264`,
+          //     "application/octet-stream"
+          //   );
+          // }
 
           // this.downloadBlob(
           //   It.data.subarray(It.metaLen, It.metaLen + It.mediaLen),

+ 3 - 3
src/main.js

@@ -34,9 +34,9 @@ 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://meta-socket.4dage.com/ws",
+            // wsServerUrl: 'wss://uat-eks.xverse.cn/ws',
+             wsServerUrl: "ws://localhost:6688/ws",
+            //wsServerUrl: "wss://meta-socket.4dage.com/ws",
             appId: "10016",
             token: " ",
             nickname: nickname,

+ 38 - 19
src/v2Decoder/index.js

@@ -2,6 +2,7 @@
 /* eslint-disable no-undef */
 const CACHE_BUF_LENGTH = 16;
 const YUV_BUF_LENGTH = 16;
+let testLastestTime = 0;
 if ("function" === typeof importScripts) {
   const startTime = Date.now();
   // self.importScripts('https://static.xverse.cn/wasm/zx_test_exclusive/v2/libxv265dec.js')
@@ -336,7 +337,7 @@ if ("function" === typeof importScripts) {
     if (this.isSlotEmpty(index)) {
       //lost
       // debugger
-      console.log("[xmedia] return on SLOT EMPTY, prev: %s", prevSeq)
+      console.log("[xmedia] return on SLOT EMPTY, prev: %s", prevSeq);
       this.consumerWaitingIDR = true;
       this.consumerPrevPts = this.seqAdd(this.consumerPrevPts, 1, 65536);
       return true;
@@ -345,7 +346,10 @@ if ("function" === typeof importScripts) {
     if (!this.slotHasMedia(index)) {
       // pure meta
       // debugger
-      console.log("[xmedia] return on meta, prev: %s, cur: %s", mediaArray[index].pts)
+      console.log(
+        "[xmedia] return on meta, prev: %s, cur: %s",
+        mediaArray[index].pts
+      );
       this.consumerPrevPts = mediaArray[index].pts;
       return true;
     }
@@ -375,7 +379,14 @@ if ("function" === typeof importScripts) {
       }
     }
 
-    console.log("[xmedia] return finally, prev: %s, cur: %s", this.prevSeq, this.consumerCurrPts);
+    console.log(
+      "[xmedia] return finally, prev: %s, cur: %s",
+      this.prevSeq,
+      this.consumerCurrPts,
+      Date.now() - testLastestTime
+    );
+
+    testLastestTime = String(Date.now()).slice();
     this.consumerPrevPts = this.consumerCurrPts;
 
     this.consumerWaitingIDR = false;
@@ -424,7 +435,7 @@ if ("function" === typeof importScripts) {
     // console.log("procBufItem", index, mediaArray[index]);
 
     if (this.slotHasContent(index) && !needToSkip) {
-      console.log("[xmedia] %s ------------ 001", mediaArray[index].pts)
+      console.log("[xmedia] %s ------------ 001", mediaArray[index].pts);
       let objData = {
         media: mediaArray[index].media,
         frameCnt: mediaArray[index].pts,
@@ -435,30 +446,30 @@ if ("function" === typeof importScripts) {
 
       // -------------------
       if (this.checkPktOrderInConsumer(index)) {
-        console.log("[xmedia] %s ------------ 002", mediaArray[index].pts)
+        console.log("[xmedia] %s ------------ 002", mediaArray[index].pts);
         this.decodeFrame(objData);
       }
 
       if (mediaArray[index].isIDR) {
-        console.log("[xmedia] %s ------------ 003", mediaArray[index].pts)
+        console.log("[xmedia] %s ------------ 003", mediaArray[index].pts);
         // console.log("mediaArray[index].isIDR: this.skipFrameUntilI = false")
         this.skipFrameUntilI = false;
       }
     } else {
-      console.log("[xmedia] %s ------------ 004", mediaArray[index].pts)
+      console.log("[xmedia] %s ------------ 004", mediaArray[index].pts);
       if (this.slotHasMedia(index)) {
-        console.log("[xmedia] %s ------------ 005", mediaArray[index].pts)
+        console.log("[xmedia] %s ------------ 005", mediaArray[index].pts);
         //need to skip, waiting I Frame
         //dropCache++
         this.dropPkt += 1;
         // MARKER META1META2
         // self.postMessage({ t: MessageEvent.OnlyEmitSignal, meta_only: true, meta: mediaArray[index].meta, metadata: mediaArray[index].metadata })
       } else {
-        console.log("[xmedia] %s ------------ 006", mediaArray[index].pts)
+        console.log("[xmedia] %s ------------ 006", mediaArray[index].pts);
         // no media
         if (mediaArray[index].meta != null) {
           this.checkPktOrderInConsumer(index);
-          console.log("[xmedia] %s ------------ 007", mediaArray[index].pts)
+          console.log("[xmedia] %s ------------ 007", mediaArray[index].pts);
           // Still frame
           console.log("[send signal]", mediaArray[index].pts);
           self.postMessage({
@@ -468,7 +479,7 @@ if ("function" === typeof importScripts) {
             metadata: mediaArray[index].metadata,
           });
         } else {
-          console.log("[xmedia] %s ------------ 008", mediaArray[index].pts)
+          console.log("[xmedia] %s ------------ 008", mediaArray[index].pts);
           // Lost_rcv++
           // console.log("lost_rcv++: this.skipFrameUntilI = true")
           // console.info('[xmedia] FFFFF This code should not be executed!!!!')
@@ -560,7 +571,7 @@ if ("function" === typeof importScripts) {
       }
       return false;
     }
-    
+
     this.procBufItem(this.readPtr);
 
     // if (this.getNumOfPktToBeDec() > this.prevBufNum) {
@@ -811,17 +822,17 @@ if ("function" === typeof importScripts) {
       // console.log("[xmedia] 000-2 isIDR: %s, mediaLen: %s", isIDR, mediaLen)
       // console.log("[xmedia] 000-3 this.isPFrame(isIDR, mediaLen): %s", this.isPFrame(isIDR, mediaLen))
       if (this.isPFrame(isIDR, mediaLen)) {
-        console.log("[xmedia] 001: isPFrame TRUE")
+        console.log("[xmedia] 001: isPFrame TRUE");
         this.packetsDrop += 1;
         // MARKER META1META2
         dropPkt = true;
       }
       if (this.isIFrame(isIDR, mediaLen)) {
-        console.log("[xmedia] 002: isIFrame TRUE")
+        console.log("[xmedia] 002: isIFrame TRUE");
         this.isFirstFrame = false;
       }
     }
-    console.log("[xmedia] 003: dropPkt: %s", dropPkt)
+    console.log("[xmedia] 003: dropPkt: %s", dropPkt);
     return dropPkt;
   };
 
@@ -841,7 +852,6 @@ if ("function" === typeof importScripts) {
 
     if (data.cached) {
       media = IFrameCacheBuffer[JSON.stringify(data.position)][key];
-     
     } else if (data.cacheRequest) {
       media = data.data.subarray(data.metaLen, data.metaLen + data.mediaLen);
       self.decoder.cacheFrame(data);
@@ -858,7 +868,7 @@ if ("function" === typeof importScripts) {
       if (this.isPFrame(data.isIDR, media.byteLength)) {
         // MARKER META1META2
         this.packetsDrop += 1;
-       console.log('fk1')
+        console.log("fk1");
         return;
       }
       this.prevSeq = this.seqDiff(pts, 1, 65536);
@@ -908,10 +918,19 @@ if ("function" === typeof importScripts) {
         this.packetsLost -= 1;
         // this.packetdisorder +=1
       }
-      console.log("[xmedia] disorder frame received. preSeq: %s, pts: %s", this.prevSeq, pts)
+      console.log(
+        "[xmedia] disorder frame received. preSeq: %s, pts: %s",
+        this.prevSeq,
+        pts
+      );
       if (this.seqDiff(this.prevSeq, pts, 65536) < this.getNumOfPktToBeDec()) {
         // slot for pts is not handled yet. just put it back:
-        console.log('put disorder frame to enc_queue, pkt:%s, prevPts: %s, numOfPktToBeDec: %s', pts, this.prevSeq, this.getNumOfPktToBeDec())
+        console.log(
+          "put disorder frame to enc_queue, pkt:%s, prevPts: %s, numOfPktToBeDec: %s",
+          pts,
+          this.prevSeq,
+          this.getNumOfPktToBeDec()
+        );
       } else {
         //dropDisorder++
         console.error(