Skip to content

Commit

Permalink
Merge pull request #1411 from canalplus/misc/await-before-push-reattempt
Browse files Browse the repository at this point in the history
[v3] Await some delay before re-attempting to push a segment following an error
  • Loading branch information
peaBerberian authored Mar 26, 2024
2 parents 2ce9cf6 + b5461dc commit 21aa959
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/core/stream/adaptation/adaptation_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ export default function AdaptationStream<T>(
inbandEvent: callbacks.inbandEvent,
warning: callbacks.warning,
error(err : unknown) {
if (TaskCanceller.isCancellationError(err) && adapStreamCanceller.isUsed()) {
return;
}
adapStreamCanceller.cancel();
callbacks.error(err);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

import { MediaError } from "../../../../errors";
import sleep from "../../../../utils/sleep";
import { CancellationError, CancellationSignal } from "../../../../utils/task_canceller";
import { IReadOnlyPlaybackObserver } from "../../../api";
import {
Expand Down Expand Up @@ -64,6 +65,11 @@ export default async function appendSegmentToBuffer<T>(
const currentPos = position.pending ?? position.last;
try {
await forceGarbageCollection(currentPos, segmentBuffer, cancellationSignal);
await sleep(200);
if (cancellationSignal.cancellationError !== null) {
throw cancellationSignal.cancellationError;
}

await segmentBuffer.pushChunk(dataInfos, cancellationSignal);
} catch (err2) {
const reason = err2 instanceof Error ? err2.toString() :
Expand Down

0 comments on commit 21aa959

Please sign in to comment.