From 7126f7aa12898c38f6565306477bbca678ee561e Mon Sep 17 00:00:00 2001 From: Trek H Date: Fri, 24 Jan 2020 20:02:17 +1030 Subject: [PATCH] mjpeg-player: mtsdemuxer functionality change Changed MTSDemuxer's 'append' function to 'demux' because it is not appending. Updated MTSDemuxer so that it doesn't store the stream after demuxing it, it simply demuxes the data that it's given and returns the demuxed data. Any PES packets that were truncated are kept to be tried at the next call to demux. --- cmd/mjpeg-player/hlsjs/mts-demuxer.js | 52 ++++++++++----------------- 1 file changed, 19 insertions(+), 33 deletions(-) diff --git a/cmd/mjpeg-player/hlsjs/mts-demuxer.js b/cmd/mjpeg-player/hlsjs/mts-demuxer.js index 22ac59ca..5fe7c351 100644 --- a/cmd/mjpeg-player/hlsjs/mts-demuxer.js +++ b/cmd/mjpeg-player/hlsjs/mts-demuxer.js @@ -1,12 +1,9 @@ /* -NAME - mts-demuxer.js - AUTHOR Trek Hopton LICENSE - This file is Copyright (C) 2019 the Australian Ocean Lab (AusOcean) + This file is Copyright (C) 2020 the Australian Ocean Lab (AusOcean) It is free software: you can redistribute it and/or modify them under the terms of the GNU General Public License as published by the @@ -36,10 +33,6 @@ class MTSDemuxer { init() { this.pmtParsed = false; this._pmtId = -1; - - this._videoTrack = MTSDemuxer.createTrack('video'); - this._audioTrack = MTSDemuxer.createTrack('audio'); - this._id3Track = MTSDemuxer.createTrack('id3'); } // createTrack creates and returns a track model. @@ -55,15 +48,6 @@ class MTSDemuxer { }; } - // _getTracks returns this MTSDemuxer's tracks. - _getTracks() { - return { - video: this._videoTrack, - audio: this._audioTrack, - id3: this._id3Track - }; - } - // _syncOffset scans the first 'maxScanWindow' bytes and returns an offset to the beginning of the first three MTS packets, // or -1 if three are not found. // A TS fragment should contain at least 3 TS packets, a PAT, a PMT, and one PID, each starting with 0x47. @@ -81,20 +65,20 @@ class MTSDemuxer { return -1; } - append(data) { + demux(data) { let start, len = data.length, pusi, pid, afc, offset, pes, unknownPIDs = false; let pmtParsed = this.pmtParsed, - videoTrack = this._videoTrack, - audioTrack = this._audioTrack, - id3Track = this._id3Track, - videoId = videoTrack.pid, - audioId = audioTrack.pid, - id3Id = id3Track.pid, + videoTrack = MTSDemuxer.createTrack('video'), + audioTrack = MTSDemuxer.createTrack('audio'), + id3Track = MTSDemuxer.createTrack('id3'), + videoId, + audioId, + id3Id, pmtId = this._pmtId, - videoData = videoTrack.pesData, - audioData = audioTrack.pesData, - id3Data = id3Track.pesData, + videoData = this.videoPesData, + audioData = this.audioPesData, + id3Data = this.id3PesData, parsePAT = this._parsePAT, parsePMT = this._parsePMT, parsePES = this._parsePES; @@ -209,27 +193,29 @@ class MTSDemuxer { // Try to parse last PES packets. if (videoData && (pes = parsePES(videoData)) && pes.pts !== undefined) { videoTrack.data.push(pes.data); - videoTrack.pesData = null; + this.videoPesData = null; } else { // Either pesPkts null or PES truncated, keep it for next frag parsing. - videoTrack.pesData = videoData; + this.videoPesData = videoData; } if (audioData && (pes = parsePES(audioData)) && pes.pts !== undefined) { audioTrack.data.push(pes.data); - audioTrack.pesData = null; + this.audioPesData = null; } else { // Either pesPkts null or PES truncated, keep it for next frag parsing. - audioTrack.pesData = audioData; + this.audioPesData = audioData; } if (id3Data && (pes = parsePES(id3Data)) && pes.pts !== undefined) { id3Track.data.push(pes.data); - id3Track.pesData = null; + this.id3PesData = null; } else { // Either pesPkts null or PES truncated, keep it for next frag parsing. - id3Track.pesData = id3Data; + this.id3PesData = id3Data; } + + return videoTrack; } _parsePAT(data, offset) {