Skip to content

Commit

Permalink
Add size judgment to gop cache
Browse files Browse the repository at this point in the history
  • Loading branch information
illuspas committed Dec 3, 2024
1 parent e7be993 commit fb08b3e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
3 changes: 1 addition & 2 deletions src/protocol/rtmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,6 @@ export default class Rtmp {
let payload = this.parserPacket.payload.subarray(offset, this.parserPacket.header.length);

let invokeMessage = AMF.decodeAmf0Cmd(payload);
logger.debug(`handle invoke message ${invokeMessage.cmd}`);
switch (invokeMessage.cmd) {
case "connect":
this.onConnect(invokeMessage);
Expand All @@ -682,7 +681,7 @@ export default class Rtmp {
this.onDeleteStream(invokeMessage);
break;
default:
logger.debug(`unhandle invoke message ${invokeMessage.cmd}`);
logger.trace(`unhandle invoke message ${invokeMessage.cmd}`);
break;
}
}
Expand Down
36 changes: 17 additions & 19 deletions src/server/broadcast_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ export default class BroadcastServer {
this.flvMetaData = null;
this.flvAudioHeader = null;
this.flvVideoHeader = null;
this.rtmpMetaData = null;
this.rtmpAudioHeader = null;
this.rtmpVideoHeader = null;
this.flvGopCache?.clear();
this.rtmpGopCache?.clear();
}
};

Expand All @@ -132,43 +137,36 @@ export default class BroadcastServer {
this.rtmpAudioHeader = Buffer.from(rtmpMessage);
break;
case 1:
if (this.flvGopCache !== null) {
this.flvGopCache.add(flvMessage);
}
if (this.rtmpGopCache !== null) {
this.rtmpGopCache.add(rtmpMessage);
}
this.flvGopCache?.add(flvMessage);
this.rtmpGopCache?.add(rtmpMessage);
break;
case 2:
this.flvVideoHeader = Buffer.from(flvMessage);
this.rtmpVideoHeader = Buffer.from(rtmpMessage);
break;
case 3:
if (this.flvGopCache !== null) {
this.flvGopCache.clear();
}
if (this.rtmpGopCache !== null) {
this.rtmpGopCache.clear();
}
this.flvGopCache?.clear();
this.rtmpGopCache?.clear();
this.flvGopCache = new Set();
this.rtmpGopCache = new Set();
this.flvGopCache.add(flvMessage);
this.rtmpGopCache.add(rtmpMessage);
break;
case 4:
if (this.flvGopCache !== null) {
this.flvGopCache.add(flvMessage);
}
if (this.rtmpGopCache !== null) {
this.rtmpGopCache.add(rtmpMessage);
}
this.flvGopCache?.add(flvMessage);
this.rtmpGopCache?.add(rtmpMessage);
break;
case 5:
this.flvMetaData = Buffer.from(flvMessage);
this.rtmpMetaData = Buffer.from(rtmpMessage);
break;
}

if (this.flvGopCache && this.flvGopCache.size > 4096) {
this.flvGopCache.clear();
}
if (this.rtmpGopCache && this.rtmpGopCache.size > 4096) {
this.rtmpGopCache.clear();
}
this.subscribers.forEach((v, k) => {
switch (v.protocol) {
case "flv":
Expand Down
5 changes: 5 additions & 0 deletions src/server/http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ export default class NodeHttpServer {
allowHTTP1: true
};

app.all("*", (req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
req.method === "OPTIONS" ? res.sendStatus(200) : next();
});

app.all("/:app/:name.flv", this.handleFlv);

this.server1 = http.createServer(app);
Expand Down

0 comments on commit fb08b3e

Please sign in to comment.