1 Star 0 Fork 0

我的身份要低调/h264Analysis

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
UnitCache.js 2.29 KB
一键复制 编辑 原始数据 按行查看 历史
我的身份要低调 提交于 2022-03-27 11:07 +08:00 . add file
// import { writeLog } from "./Log.js";
import { writeErrLog } from "./Log.js";
/**
* 对buffer进行切割
*/
export default class UnitCache {
constructor() {
// this.spliceUnits = [];
this.cacheBuf = [];
}
put(buf) {
/**
* 拼接两个unit8Array
*/
const target = new Uint8Array(buf);
if (this.cacheBuf.byteLength) {
const source = this.cacheBuf;
this.cacheBuf = new Uint8Array(newUnit8.byteLength + this.cacheBuf.byteLength);
this.cacheBuf.set(source, 0);
this.cacheBuf.set(target, source.byteLength);
} else {
this.cacheBuf = target;
}
// 00 00 00 01 或者 00 00 01 分割码
/**
* 1.找数值为00的
* 2.判断相邻的两个或者三个字节是否满足条件
*/
let index = 0;
let subCodeStartIndexs = [];
while (index < this.cacheBuf.byteLength) {
if (this.cacheBuf[index] === 0 && this.cacheBuf[index + 1] === 0) {
if (this.cacheBuf[index + 2] === 1) {
// writeLog("00 00 01:" + index);
subCodeStartIndexs.push({
index,
len: 3
});
index += 3;
} else if (this.cacheBuf[index + 2] === 0 && this.cacheBuf[index + 3] === 1) {
// writeLog("00 00 00 01:" + index);
subCodeStartIndexs.push({
index,
len: 4
});
index += 4;
} else {
index++;
}
} else {
index++;
}
}
let spliceUnits = [];
const indexsLength = subCodeStartIndexs.length;
for (let index = 0; index < indexsLength; index++) {
const sub = subCodeStartIndexs[index];
const nextSub = subCodeStartIndexs[index + 1];
if (nextSub) {
const slice = this.cacheBuf.subarray(sub.index + sub.len, nextSub.index);
spliceUnits.push(slice);
}
}
this.cacheBuf = this.cacheBuf.subarray(subCodeStartIndexs[indexsLength - 1]);
return spliceUnits;
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/sunkingsss/h264-analysis.git
git@gitee.com:sunkingsss/h264-analysis.git
sunkingsss
h264-analysis
h264Analysis
master

搜索帮助