Browse Source

Merge branch 'myrtc' of http://192.168.0.115:3000/xushiting/Metaverse into myrtc

# Conflicts:
#	src/Workers.js
#	src/v2Decoder/index.js
xushiting 3 years ago
parent
commit
6389fa3c80
2 changed files with 64 additions and 32 deletions
  1. 18 6
      src/Workers.js
  2. 46 26
      src/v2Decoder/index.js

+ 18 - 6
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 宏块 有效长段
@@ -1044,8 +1046,8 @@ export default class Workers {
     this.calcSendTimeDiff(_e);
 
     // console.log("hey", Date.now() - _e);
-    const copyIDR = b;
-    
+
+    // console.log("zh----", fCnt, b);
     if (b !== 255) {
       console.log("gemer1", {
         byteLength: e.byteLength,
@@ -1319,7 +1321,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),

+ 46 - 26
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;
@@ -428,7 +439,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,
@@ -439,30 +450,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({
@@ -472,7 +483,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!!!!')
@@ -564,7 +575,7 @@ if ("function" === typeof importScripts) {
       }
       return false;
     }
-    
+
     this.procBufItem(this.readPtr);
 
     // if (this.getNumOfPktToBeDec() > this.prevBufNum) {
@@ -734,7 +745,7 @@ if ("function" === typeof importScripts) {
     printConsole.log("Going to open decoder " + String(Date.now()));
     var ret0 = Module._openDecoder(0, decoder_type, LOG_LEVEL_WASM);
     if (ret0 == 0) {
-      self.decoder.startDecoding();                                                                     //开始解码
+      self.decoder.startDecoding();                                                                     //开始解码
       self.postMessage({
         t: MessageEvent.WASMReady,
         wasm_ready: true,
@@ -783,10 +794,10 @@ if ("function" === typeof importScripts) {
     // return data.isIDR && media.byteLength !=0
     let flag =  isIDR && mediaLen != 0;
     if(flag){
-      console.log('metaverse---------鏄疘Frame');
+      console.log('metaverse---------是IFrame');
     }
     else{
-      console.log('metaverse---------涓嶆槸IFrame');
+      console.log('metaverse---------不是IFrame');
     }
     return flag;
   };
@@ -795,10 +806,10 @@ if ("function" === typeof importScripts) {
     // return !data.isIDR && media.byteLength !=0
     let flag = !isIDR && mediaLen != 0;
     if(flag){
-      console.log('metaverse---------鏄疨Frame');
+      console.log('metaverse---------是PFrame');
     }
     else{
-      console.log('metaverse---------涓嶆槸PFrame');
+      console.log('metaverse---------不是PFrame');
     }
     return flag;
   };
@@ -807,10 +818,10 @@ if ("function" === typeof importScripts) {
     // return media.byteLength == 0 && meta.byteLength !=0
     let flag = mediaLen == 0 && metaLen != 0;
     if(flag){
-      console.log('metaverse---------鏄疨ureMeta');
+      console.log('metaverse---------是PureMeta');
     }
     else{
-      console.log('metaverse---------涓嶆槸PureMeta');
+      console.log('metaverse---------不是PureMeta');
     }
     return flag;
   };
@@ -836,17 +847,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;
   };
 
@@ -865,7 +876,7 @@ if ("function" === typeof importScripts) {
     var media;
     
     if (data.cached) {
-      media = IFrameCacheBuffer[JSON.stringify(data.position)][key]; 
+      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);
@@ -881,7 +892,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);
@@ -931,10 +942,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(