Skip to content

Commit 6ce0f6c

Browse files
authored
Merge pull request #6940 from devoldemar/fix/vps_after_sps
Support HEVC VPS coming after SPS
2 parents dec3ee7 + b1c83db commit 6ce0f6c

File tree

1 file changed

+34
-25
lines changed

1 file changed

+34
-25
lines changed

src/demux/video/hevc-video-parser.ts

+34-25
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,10 @@ class HevcVideoParser extends BaseVideoParser {
122122
case 32:
123123
push = true;
124124
if (!track.vps) {
125-
const config = this.readVPS(unit.data);
126-
track.params = { ...config };
125+
if (typeof track.params !== 'object') {
126+
track.params = {};
127+
}
128+
track.params = Object.assign(track.params, this.readVPS(unit.data));
127129
this.initVPS = unit.data;
128130
}
129131
track.vps = [unit.data];
@@ -133,31 +135,35 @@ class HevcVideoParser extends BaseVideoParser {
133135
case 33:
134136
push = true;
135137
spsfound = true;
136-
if (typeof track.params === 'object') {
137-
if (
138-
track.vps !== undefined &&
139-
track.vps[0] !== this.initVPS &&
140-
track.sps !== undefined &&
141-
!this.matchSPS(track.sps[0], unit.data)
142-
) {
143-
this.initVPS = track.vps[0];
144-
track.sps = track.pps = undefined;
145-
}
146-
if (!track.sps) {
147-
const config = this.readSPS(unit.data);
148-
track.width = config.width;
149-
track.height = config.height;
150-
track.pixelRatio = config.pixelRatio;
151-
track.codec = config.codecString;
152-
track.sps = [];
153-
for (const prop in config.params) {
154-
track.params[prop] = config.params[prop];
155-
}
138+
if (
139+
track.vps !== undefined &&
140+
track.vps[0] !== this.initVPS &&
141+
track.sps !== undefined &&
142+
!this.matchSPS(track.sps[0], unit.data)
143+
) {
144+
this.initVPS = track.vps[0];
145+
track.sps = track.pps = undefined;
146+
}
147+
if (!track.sps) {
148+
const config = this.readSPS(unit.data);
149+
track.width = config.width;
150+
track.height = config.height;
151+
track.pixelRatio = config.pixelRatio;
152+
track.codec = config.codecString;
153+
track.sps = [];
154+
if (typeof track.params !== 'object') {
155+
track.params = {};
156156
}
157-
if (track.vps !== undefined && track.vps[0] === this.initVPS) {
158-
track.sps.push(unit.data);
157+
for (const prop in config.params) {
158+
track.params[prop] = config.params[prop];
159159
}
160160
}
161+
if (
162+
(!track.vps && !track.sps.length) ||
163+
(track.vps && track.vps[0] === this.initVPS)
164+
) {
165+
track.sps.push(unit.data);
166+
}
161167
if (!VideoSample) {
162168
VideoSample = this.VideoSample = this.createVideoSample(
163169
true,
@@ -179,7 +185,10 @@ class HevcVideoParser extends BaseVideoParser {
179185
track.params[prop] = config[prop];
180186
}
181187
}
182-
if (track.vps !== undefined && track.vps[0] === this.initVPS) {
188+
if (
189+
(!track.vps && !track.pps.length) ||
190+
(track.vps && track.vps[0] === this.initVPS)
191+
) {
183192
track.pps.push(unit.data);
184193
}
185194
}

0 commit comments

Comments
 (0)