Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jv4-demuxer

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jv4-demuxer - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

2

package.json
{
"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,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc