Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of segments at the discontinuities that do not start with a keyframe #5659

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions src/controller/stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1111,9 +1111,11 @@ export default class StreamController
}

// Avoid buffering if backtracking this fragment
const notFirstFragment = frag.sn !== details?.startSN;
if (video && remuxResult.independent !== false) {
if (details) {
if (video && details && frag.sn !== 'initSegment') {
const prevFrag = details.fragments[frag.sn - 1 - details.startSN];
const isFirstFragment = frag.sn === details.startSN;
const isFirstInDiscontinuity = !prevFrag || frag.cc > prevFrag.cc;
if (remuxResult.independent !== false) {
const { startPTS, endPTS, startDTS, endDTS } = video;
if (part) {
part.elementaryStreams[video.type] = {
Expand All @@ -1123,7 +1125,12 @@ export default class StreamController
endDTS,
};
} else {
if (video.firstKeyFrame && video.independent && chunkMeta.id === 1) {
if (
video.firstKeyFrame &&
video.independent &&
chunkMeta.id === 1 &&
!isFirstInDiscontinuity
) {
this.couldBacktrack = true;
}
if (video.dropped && video.independent) {
Expand All @@ -1137,11 +1144,15 @@ export default class StreamController
? video.firstKeyFramePTS
: startPTS;
if (
notFirstFragment &&
targetBufferTime < startTime - this.config.maxBufferHole
!isFirstFragment &&
targetBufferTime < startTime - this.config.maxBufferHole &&
!isFirstInDiscontinuity
) {
this.backtrack(frag);
return;
} else if (isFirstInDiscontinuity) {
// Mark segment with a gap to avoid loop loading
frag.gap = true;
}
// Set video stream start to fragment start so that truncated samples do not distort the timeline, and mark it partial
frag.setElementaryStreamInfo(
Expand All @@ -1165,10 +1176,13 @@ export default class StreamController
this.backtrackFragment = frag;
}
this.bufferFragmentData(video, frag, part, chunkMeta);
} else if (isFirstFragment || isFirstInDiscontinuity) {
// Mark segment with a gap to avoid loop loading
frag.gap = true;
} else {
this.backtrack(frag);
return;
}
} else if (notFirstFragment && remuxResult.independent === false) {
this.backtrack(frag);
return;
}

if (audio) {
Expand Down
9 changes: 7 additions & 2 deletions src/loader/fragment-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ export default class FragmentLoader {
this.loader.destroy();
}
if (frag.gap) {
reject(createGapLoadError(frag));
return;
if (frag.tagList.some((tags) => tags[0] === 'GAP')) {
reject(createGapLoadError(frag));
return;
} else {
// Reset temporary treatment as GAP tag
frag.gap = false;
}
}
const loader =
(this.loader =
Expand Down