Skip to content

Commit

Permalink
Merge pull request #42 from jeronimoek/patch-1
Browse files Browse the repository at this point in the history
Improve buffer
  • Loading branch information
agsh authored Apr 20, 2023
2 parents e0c3f32 + f6d714e commit 4f9783d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/rtsp-ffmpeg.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var FFMpeg = function(options) {
this.resolution = options.resolution;
this.quality = (options.quality === undefined || options.quality === "") ? 3 : options.quality;
this.arguments = options.arguments || [];
this.buff = Buffer.from(''); // Store the entire data image into this variable. This attribute is replaced each time a full image is received from the stream.
this.buffs = []; // Store the entire data image into this variable. This attribute is replaced each time a full image is received from the stream.

this.on('newListener', newListener.bind(this));
this.on('removeListener', removeListener.bind(this));
Expand Down Expand Up @@ -92,14 +92,14 @@ FFMpeg.prototype.start = function() {
//The image can be composed of one or multiple chunk when receiving stream data.
//Store all bytes into an array until we meet flag "FF D9" that mean it's the end of the image then we can send all data in order to display the full image.
if (data.length >1) {
self.buff = Buffer.concat([self.buff, data]);
self.buffs.push(data);

offset = data[data.length-2].toString(16);
offset2 = data[data.length-1].toString(16);

if(offset == "ff" && offset2 == "d9") {
self.emit('data', self.buff);
self.buff = Buffer.from('');
self.emit('data', Buffer.concat(self.buffs));
self.buffs = [];
}
}
});
Expand Down

0 comments on commit 4f9783d

Please sign in to comment.