mirror of https://bitbucket.org/ausocean/av.git
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.
This commit is contained in:
parent
1b7e817266
commit
7126f7aa12
|
@ -1,12 +1,9 @@
|
||||||
/*
|
/*
|
||||||
NAME
|
|
||||||
mts-demuxer.js
|
|
||||||
|
|
||||||
AUTHOR
|
AUTHOR
|
||||||
Trek Hopton <trek@ausocean.org>
|
Trek Hopton <trek@ausocean.org>
|
||||||
|
|
||||||
LICENSE
|
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
|
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
|
under the terms of the GNU General Public License as published by the
|
||||||
|
@ -36,10 +33,6 @@ class MTSDemuxer {
|
||||||
init() {
|
init() {
|
||||||
this.pmtParsed = false;
|
this.pmtParsed = false;
|
||||||
this._pmtId = -1;
|
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.
|
// 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,
|
// _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.
|
// 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.
|
// 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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
append(data) {
|
demux(data) {
|
||||||
let start, len = data.length, pusi, pid, afc, offset, pes,
|
let start, len = data.length, pusi, pid, afc, offset, pes,
|
||||||
unknownPIDs = false;
|
unknownPIDs = false;
|
||||||
let pmtParsed = this.pmtParsed,
|
let pmtParsed = this.pmtParsed,
|
||||||
videoTrack = this._videoTrack,
|
videoTrack = MTSDemuxer.createTrack('video'),
|
||||||
audioTrack = this._audioTrack,
|
audioTrack = MTSDemuxer.createTrack('audio'),
|
||||||
id3Track = this._id3Track,
|
id3Track = MTSDemuxer.createTrack('id3'),
|
||||||
videoId = videoTrack.pid,
|
videoId,
|
||||||
audioId = audioTrack.pid,
|
audioId,
|
||||||
id3Id = id3Track.pid,
|
id3Id,
|
||||||
pmtId = this._pmtId,
|
pmtId = this._pmtId,
|
||||||
videoData = videoTrack.pesData,
|
videoData = this.videoPesData,
|
||||||
audioData = audioTrack.pesData,
|
audioData = this.audioPesData,
|
||||||
id3Data = id3Track.pesData,
|
id3Data = this.id3PesData,
|
||||||
parsePAT = this._parsePAT,
|
parsePAT = this._parsePAT,
|
||||||
parsePMT = this._parsePMT,
|
parsePMT = this._parsePMT,
|
||||||
parsePES = this._parsePES;
|
parsePES = this._parsePES;
|
||||||
|
@ -209,27 +193,29 @@ class MTSDemuxer {
|
||||||
// Try to parse last PES packets.
|
// Try to parse last PES packets.
|
||||||
if (videoData && (pes = parsePES(videoData)) && pes.pts !== undefined) {
|
if (videoData && (pes = parsePES(videoData)) && pes.pts !== undefined) {
|
||||||
videoTrack.data.push(pes.data);
|
videoTrack.data.push(pes.data);
|
||||||
videoTrack.pesData = null;
|
this.videoPesData = null;
|
||||||
} else {
|
} else {
|
||||||
// Either pesPkts null or PES truncated, keep it for next frag parsing.
|
// 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) {
|
if (audioData && (pes = parsePES(audioData)) && pes.pts !== undefined) {
|
||||||
audioTrack.data.push(pes.data);
|
audioTrack.data.push(pes.data);
|
||||||
audioTrack.pesData = null;
|
this.audioPesData = null;
|
||||||
} else {
|
} else {
|
||||||
// Either pesPkts null or PES truncated, keep it for next frag parsing.
|
// 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) {
|
if (id3Data && (pes = parsePES(id3Data)) && pes.pts !== undefined) {
|
||||||
id3Track.data.push(pes.data);
|
id3Track.data.push(pes.data);
|
||||||
id3Track.pesData = null;
|
this.id3PesData = null;
|
||||||
} else {
|
} else {
|
||||||
// Either pesPkts null or PES truncated, keep it for next frag parsing.
|
// Either pesPkts null or PES truncated, keep it for next frag parsing.
|
||||||
id3Track.pesData = id3Data;
|
this.id3PesData = id3Data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return videoTrack;
|
||||||
}
|
}
|
||||||
|
|
||||||
_parsePAT(data, offset) {
|
_parsePAT(data, offset) {
|
||||||
|
|
Loading…
Reference in New Issue