gemercheung 3 năm trước cách đây
mục cha
commit
40a790b70a
4 tập tin đã thay đổi với 89 bổ sung39 xóa
  1. 58 23
      dist/js/video.js
  2. 1 1
      dist/js/video.js.map
  3. 23 8
      src/h264Decoder/VDecoder.js
  4. 7 7
      src/h264Decoder/index.js

+ 58 - 23
dist/js/video.js

@@ -1,6 +1,6 @@
 /**
 * Name: Metaverse
-* Date: 2022/4/24
+* Date: 2022/4/25
 * Author: https://www.4dkankan.com
 * Copyright © 2022 4DAGE Co., Ltd. All rights reserved.
 * Licensed under the GLP license
@@ -2051,6 +2051,10 @@
           switch (message.type) {
             case "pictureReady":
               //   onPictureReady(message);
+              console.log("[VDecoder]::decodeData", Object.assign(message, {
+                clipId: _this2.decodingId
+              }));
+
               _this2.emit("decodeData", Object.assign(message, {
                 clipId: _this2.decodingId
               }));
@@ -2101,7 +2105,7 @@
 
         var url = path;
 
-        if (!(isArray$1(rangeArray) && rangeArray.length === 2)) {
+        if (!(isArray$1(rangeArray) && (rangeArray.length === 1 || rangeArray.length === 2))) {
           throw new Error("range must is an array!");
         }
 
@@ -2110,8 +2114,27 @@
           console.log("flush");
         }
 
-        var rangeFetch = range$1(rangeArray[0], rangeArray[1] + 1); // console.log("url", url);
-        // console.log("rangeFetch", rangeFetch);
+        var rangeFetch = [];
+
+        if (rangeArray[0] < 0 || rangeArray[1] < 0) {
+          console.error("[VDecoder]:range: 非法", "".concat([rangeArray[0], rangeArray[1]]));
+          return;
+        }
+
+        if (rangeArray.length > 1) {
+          // range入口
+          if (rangeArray[0] < rangeArray[1]) {
+            rangeFetch = range$1(rangeArray[0], rangeArray[1] + 1);
+            console.log("[VDecoder]:顺时 +", rangeFetch);
+          } else {
+            rangeFetch = range$1(rangeArray[1], rangeArray[0] + 1).reverse();
+            console.log("[VDecoder]:逆时 -", rangeFetch);
+          }
+        } else {
+          // 单例 [i]
+          rangeFetch = rangeArray;
+          console.log("[VDecoder]:single", rangeFetch);
+        }
 
         var allFetch = rangeFetch.map(function (i) {
           return fetch("".concat(url, "/").concat(i)).then(function (response) {
@@ -2123,23 +2146,31 @@
         return Promise.all(allFetch).then(function (data) {
           var clip = {
             id: v4(),
-            data
+            data: data
           };
 
-          _this3.emit("fetchDone", clip);
+          if (data.length > 0) {
+            _this3.emit("fetchDone", clip);
 
-          _this3.cacheBuffer = data.slice();
+            _this3.cacheBuffer = data.slice();
 
-          _this3.tempVideos.push(clip);
+            _this3.tempVideos.push(clip);
 
-          if (decode) {
-            _this3.start = Date.now();
-            _this3.cacheBufferTotal = clip.data.length;
+            console.log("[VDecoder]:获取clip,", clip);
 
-            _this3.decodeNext(clip.id);
-          }
+            if (decode) {
+              _this3.start = Date.now();
+              _this3.cacheBufferTotal = clip.data.length;
+
+              _this3.decodeNext(clip.id);
+            }
 
-          return Promise.resolve(clip);
+            return Promise.resolve(clip);
+          } else {
+            console.warn("[VDecoder]:fetch取帧为空", rangeFetch);
+          }
+        }).catch(function (error) {
+          console.log("error", error);
         });
       }
       /**
@@ -2170,6 +2201,7 @@
         if (nextFrame) {
           this.decode(nextFrame, tempId);
         } else {
+          console.log("tempVideos", this.tempVideos.length);
           var clip = this.tempVideos.find(function (_ref3) {
             var id = _ref3.id;
             return id === _this4.decodingId;
@@ -2178,10 +2210,12 @@
           if (clip) {
             var fps = 1000 / (Date.now() - this.start) * clip.data.length;
             console.log("Decoded ".concat(clip.data.length, " frames in ").concat(Date.now() - this.start, "ms @ ").concat(fps >> 0, "FPS"));
+          } else {
+            console.warn("不存在clip");
           }
 
-          this.decoding = false;
-          this.decodingId = null;
+          this.decoding = false; // this.decodingId = null;
+
           tempId = 0;
           clip && clip.id && this.emit("decodeDone", clip.id);
         }
@@ -2583,12 +2617,13 @@
     document.body.append(canvas);
   }
 
-  var socket = io("ws://192.168.0.150:3000", {
-    reconnectionDelayMax: 10000
-  });
-  socket.on("connect", function (data) {
-    console.log("socket connect");
-  });
+  // const socket = io("ws://192.168.0.150:3000", {
+  //   reconnectionDelayMax: 10000,
+  // });
+  // socket.on("connect", (data) => {
+  //   console.log("socket connect");
+  // });
+
   var vDecoder = new VDecoder({
     maxChip: 100
   });
@@ -2598,7 +2633,7 @@
     initWebGLCanvas();
     vDecoder.fetch({
       path: "https://laser-data.oss-cn-shenzhen.aliyuncs.com/test-video/1011",
-      range: [0, 66]
+      range: []
     });
     vDecoder.on("fetchDone", function (clip) {
       console.log("fetchDone", clip);

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1 - 1
dist/js/video.js.map


+ 23 - 8
src/h264Decoder/VDecoder.js

@@ -78,7 +78,12 @@ export class VDecoder extends EventEmitter {
       throw new Error("decoder is not ready");
     }
     const url = path;
-    if (!(isArray(rangeArray) && rangeArray.length === 2)) {
+    if (
+      !(
+        isArray(rangeArray) &&
+        (rangeArray.length === 1 || rangeArray.length === 2)
+      )
+    ) {
       throw new Error("range must is an array!");
     }
 
@@ -90,16 +95,26 @@ export class VDecoder extends EventEmitter {
     let rangeFetch = [];
 
     if (rangeArray[0] < 0 || rangeArray[1] < 0) {
-      console.error("[VDecoder]:range: 非法", `${[rangeArray[0], rangeArray[1]]}`);
-      return
+      console.error(
+        "[VDecoder]:range: 非法",
+        `${[rangeArray[0], rangeArray[1]]}`
+      );
+      return;
     }
 
-    if (rangeArray[0] < rangeArray[1]) {
-      rangeFetch = range(rangeArray[0], rangeArray[1] + 1);
-      console.log("[VDecoder]:顺时 +", rangeFetch);
+    if (rangeArray.length > 1) {
+      // range入口
+      if (rangeArray[0] < rangeArray[1]) {
+        rangeFetch = range(rangeArray[0], rangeArray[1] + 1);
+        console.log("[VDecoder]:顺时 +", rangeFetch);
+      } else {
+        rangeFetch = range(rangeArray[1], rangeArray[0] + 1).reverse();
+        console.log("[VDecoder]:逆时 -", rangeFetch);
+      }
     } else {
-      rangeFetch = range(rangeArray[1], rangeArray[0] + 1).reverse();
-      console.log("[VDecoder]:逆时 -", rangeFetch);
+      // 单例 [i]
+      rangeFetch = rangeArray
+      console.log("[VDecoder]:single", rangeFetch);
     }
 
     const allFetch = rangeFetch.map((i) => {

+ 7 - 7
src/h264Decoder/index.js

@@ -5,12 +5,12 @@ import { initWebGLCanvas, draw } from "../video/test.js";
 
 // decoder
 
-const socket = io("ws://192.168.0.150:3000", {
-  reconnectionDelayMax: 10000,
-});
-socket.on("connect", (data) => {
-  console.log("socket connect");
-});
+// const socket = io("ws://192.168.0.150:3000", {
+//   reconnectionDelayMax: 10000,
+// });
+// socket.on("connect", (data) => {
+//   console.log("socket connect");
+// });
 
 const vDecoder = new VDecoder({
   maxChip: 100,
@@ -23,7 +23,7 @@ vDecoder.on("ready", () => {
 
   vDecoder.fetch({
     path: "https://laser-data.oss-cn-shenzhen.aliyuncs.com/test-video/1011",
-    range: [0, 66],
+    range: [],
   });
 
   vDecoder.on("fetchDone", (clip) => {