jv4-demuxer
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "jv4-demuxer", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -13,3 +13,2 @@ import { EventEmitter } from "eventemitter3"; | ||
super(); | ||
this.demux(); | ||
} | ||
@@ -24,3 +23,2 @@ audioReadable: ReadableStream<EncodedAudioChunkInit> = new ReadableStream({ | ||
videoEncoderConfig?: VideoEncoderConfig; | ||
abstract demux(): void; | ||
abstract pull(): Promise<void>; | ||
@@ -32,3 +30,4 @@ gotAudio?: (data: EncodedAudioChunkInit) => void; | ||
this.gotAudio = resolve; | ||
if (!!this.gotAudio) this.pull().catch(reject); | ||
//只调用一次pull | ||
if (!!this.gotVideo) this.pull().catch(reject); | ||
}); | ||
@@ -39,5 +38,6 @@ } | ||
this.gotVideo = resolve; | ||
if (!!this.gotVideo) this.pull().catch(reject); | ||
//只调用一次pull | ||
if (!!this.gotAudio) this.pull().catch(reject); | ||
}); | ||
} | ||
} |
@@ -13,10 +13,11 @@ import { BaseDemuxer, DemuxEvent } from "./base"; | ||
header?: Uint8Array; | ||
reader?: ReadableStreamDefaultReader<FlvTag>; | ||
demux() { | ||
async readTag(): Promise<{ | ||
type: number; | ||
data: Uint8Array; | ||
timestamp: number; | ||
}> { | ||
const t = new Uint8Array(15); //复用15个字节,前面4个字节是上一个tag的长度,跳过 | ||
const tmp8 = new Uint8Array(4); | ||
const dv = new DataView(tmp8.buffer); | ||
const readTag = async ( | ||
controller: ReadableStreamDefaultController<FlvTag> | ||
) => { | ||
this.readTag = async () => { | ||
await this.source.read(t); | ||
@@ -34,12 +35,9 @@ const type = t[4]; //tag类型,8是音频,9是视频,18是script | ||
} | ||
return this.source | ||
.read(length) | ||
.then((data) => { | ||
controller.enqueue({ type, data: data.slice(), timestamp }); | ||
}) | ||
.catch((err) => controller.error(err)); | ||
const data = await this.source.read(length); | ||
return { type, data: data.slice(), timestamp }; | ||
}; | ||
console.time("flv"); | ||
this.source.read(9).then((data) => { | ||
await this.source.read(9).then((data) => { | ||
this.header = data; | ||
console.log(data) | ||
if ( | ||
@@ -53,12 +51,7 @@ data[0] != "F".charCodeAt(0) || | ||
console.timeEnd("flv"); | ||
this.reader = new ReadableStream<FlvTag>({ | ||
start: async (controller) => { | ||
return readTag(controller); | ||
}, | ||
pull: readTag, | ||
}).getReader(); | ||
}); | ||
return this.readTag(); | ||
} | ||
async pull(): Promise<void> { | ||
const { value, done } = await this.reader!.read(); | ||
const value = await this.readTag(); | ||
if (value) { | ||
@@ -101,3 +94,3 @@ switch (value.type) { | ||
codec: | ||
{ 7: "h264", 12: "h265" }[value.data[0] & 0xf] || "unknown", | ||
{ 7: "avc", 12: "hevc" }[value.data[0] & 0xf] || "unknown", | ||
width: 0, | ||
@@ -104,0 +97,0 @@ height: 0, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
6214
155