|
@@ -71,6 +71,52 @@ export class VDecoder extends EventEmitter {
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
+ * @param {*} array array [2,100]
|
|
|
+ */
|
|
|
+ mutiFetch(data) {
|
|
|
+ if (!(isArray(data) && data.length > 0)) {
|
|
|
+ throw new Error("range must is an array and has value");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!(data[0] && "path" in data[0] && "frame" in data[0])) {
|
|
|
+ throw new Error("props path,frame,vid must have");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!this.ready) {
|
|
|
+ throw new Error("decoder is not ready");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const allFetch = data.map((item) => {
|
|
|
+ return fetch(`${item.path}/${item.frame}`).then((response) => {
|
|
|
+ return response.arrayBuffer().then(function (buffer) {
|
|
|
+ return new Uint8Array(buffer);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+ console.log("allFetch", allFetch);
|
|
|
+ return Promise.all(allFetch)
|
|
|
+ .then((data) => {
|
|
|
+ const clip = { id: uuidv4(), data: data };
|
|
|
+ if (data.length > 0) {
|
|
|
+ this.emit("fetchDone", clip);
|
|
|
+ this.cacheBuffer = data.slice();
|
|
|
+ this.tempVideos.push(clip);
|
|
|
+ console.log("[VDecoder]:获取clip,", clip);
|
|
|
+ this.start = Date.now();
|
|
|
+ this.cacheBufferTotal = clip.data.length;
|
|
|
+ this.decodeNext(clip.id);
|
|
|
+ return Promise.resolve(clip);
|
|
|
+ } else {
|
|
|
+ console.warn("[VDecoder]:fetch取帧为空", rangeFetch);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((error) => {
|
|
|
+ console.error("error", error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
* @param {*} rangeArray array [2,100]
|
|
|
*/
|
|
|
fetch({ path, range: rangeArray, decode = true }) {
|
|
@@ -113,7 +159,7 @@ export class VDecoder extends EventEmitter {
|
|
|
}
|
|
|
} else {
|
|
|
// 单例 [i]
|
|
|
- rangeFetch = rangeArray
|
|
|
+ rangeFetch = rangeArray;
|
|
|
console.log("[VDecoder]:single", rangeFetch);
|
|
|
}
|
|
|
|
|
@@ -144,7 +190,7 @@ export class VDecoder extends EventEmitter {
|
|
|
}
|
|
|
})
|
|
|
.catch((error) => {
|
|
|
- console.log("error", error);
|
|
|
+ console.error("error", error);
|
|
|
});
|
|
|
}
|
|
|
/**
|