Skip to content

Commit

Permalink
Merge pull request #6940 from devoldemar/fix/vps_after_sps
Browse files Browse the repository at this point in the history
Support HEVC VPS coming after SPS
  • Loading branch information
robwalch authored Jan 4, 2025
2 parents dec3ee7 + b1c83db commit 6ce0f6c
Showing 1 changed file with 34 additions and 25 deletions.
59 changes: 34 additions & 25 deletions src/demux/video/hevc-video-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ class HevcVideoParser extends BaseVideoParser {
case 32:
push = true;
if (!track.vps) {
const config = this.readVPS(unit.data);
track.params = { ...config };
if (typeof track.params !== 'object') {
track.params = {};
}
track.params = Object.assign(track.params, this.readVPS(unit.data));
this.initVPS = unit.data;
}
track.vps = [unit.data];
Expand All @@ -133,31 +135,35 @@ class HevcVideoParser extends BaseVideoParser {
case 33:
push = true;
spsfound = true;
if (typeof track.params === 'object') {
if (
track.vps !== undefined &&
track.vps[0] !== this.initVPS &&
track.sps !== undefined &&
!this.matchSPS(track.sps[0], unit.data)
) {
this.initVPS = track.vps[0];
track.sps = track.pps = undefined;
}
if (!track.sps) {
const config = this.readSPS(unit.data);
track.width = config.width;
track.height = config.height;
track.pixelRatio = config.pixelRatio;
track.codec = config.codecString;
track.sps = [];
for (const prop in config.params) {
track.params[prop] = config.params[prop];
}
if (
track.vps !== undefined &&
track.vps[0] !== this.initVPS &&
track.sps !== undefined &&
!this.matchSPS(track.sps[0], unit.data)
) {
this.initVPS = track.vps[0];
track.sps = track.pps = undefined;
}
if (!track.sps) {
const config = this.readSPS(unit.data);
track.width = config.width;
track.height = config.height;
track.pixelRatio = config.pixelRatio;
track.codec = config.codecString;
track.sps = [];
if (typeof track.params !== 'object') {
track.params = {};
}
if (track.vps !== undefined && track.vps[0] === this.initVPS) {
track.sps.push(unit.data);
for (const prop in config.params) {
track.params[prop] = config.params[prop];
}
}
if (
(!track.vps && !track.sps.length) ||
(track.vps && track.vps[0] === this.initVPS)
) {
track.sps.push(unit.data);
}
if (!VideoSample) {
VideoSample = this.VideoSample = this.createVideoSample(
true,
Expand All @@ -179,7 +185,10 @@ class HevcVideoParser extends BaseVideoParser {
track.params[prop] = config[prop];
}
}
if (track.vps !== undefined && track.vps[0] === this.initVPS) {
if (
(!track.vps && !track.pps.length) ||
(track.vps && track.vps[0] === this.initVPS)
) {
track.pps.push(unit.data);
}
}
Expand Down

0 comments on commit 6ce0f6c

Please sign in to comment.