Skip to content

Commit

Permalink
Merge pull request #1421 from canalplus/fix/maxVideoBufferSize-optimist
Browse files Browse the repository at this point in the history
When listing segments needed, stop filtering the current range
  • Loading branch information
peaBerberian authored Apr 3, 2024
2 parents f24fe55 + e80f51b commit 75eb852
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 54 deletions.
55 changes: 2 additions & 53 deletions src/core/stream/representation/utils/get_buffer_status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/

import config from "../../../../config";
import type {
IManifest,
IAdaptation,
Expand All @@ -24,14 +23,10 @@ import type {
import type { IReadOnlyPlaybackObserver } from "../../../../playback_observer";
import isNullOrUndefined from "../../../../utils/is_null_or_undefined";
import type {
IBufferedChunk,
ISignalCompleteSegmentOperation,
SegmentSink,
} from "../../../segment_sinks";
import SegmentSinksStore, {
ChunkStatus,
SegmentSinkOperation,
} from "../../../segment_sinks";
import SegmentSinksStore, { SegmentSinkOperation } from "../../../segment_sinks";
import type {
IBufferDiscontinuity,
IRepresentationStreamPlaybackObservation,
Expand Down Expand Up @@ -140,10 +135,7 @@ export default function getBufferStatus(
.map((operation) => operation.value);

/** Data on every segments buffered around `neededRange`. */
const bufferedSegments = getPlayableBufferedSegments(
{ start: Math.max(neededRange.start - 0.5, 0), end: neededRange.end + 0.5 },
segmentSink.getLastKnownInventory(),
);
const bufferedSegments = segmentSink.getLastKnownInventory();
let currentPlaybackTime = playbackObserver.getCurrentTime();
if (currentPlaybackTime === undefined) {
// We're in a WebWorker, just consider the last known position
Expand Down Expand Up @@ -313,46 +305,3 @@ function isPeriodTheCurrentAndLastOne(
period.id === manifest.periods[manifest.periods.length - 1]?.id
);
}

/**
* From the given SegmentInventory, filters the "playable" (in a supported codec
* and not known to be undecipherable) buffered Segment Objects which overlap
* with the given range.
* @param {Object} neededRange
* @param {Array.<Object>} segmentInventory
* @returns {Array.<Object>}
*/
function getPlayableBufferedSegments(
neededRange: { start: number; end: number },
segmentInventory: IBufferedChunk[],
): IBufferedChunk[] {
const { MINIMUM_SEGMENT_SIZE } = config.getCurrent();
const segmentRoundingError = Math.max(1 / 60, MINIMUM_SEGMENT_SIZE);
const minEnd = neededRange.start + segmentRoundingError;
const maxStart = neededRange.end - segmentRoundingError;

const overlappingChunks: IBufferedChunk[] = [];
for (let i = segmentInventory.length - 1; i >= 0; i--) {
const eltInventory = segmentInventory[i];

const { representation } = eltInventory.infos;
if (
eltInventory.status === ChunkStatus.Complete &&
representation.decipherable !== false &&
representation.isSupported !== false
) {
const inventorySegment = eltInventory.infos.segment;
const eltInventoryStart = inventorySegment.time / inventorySegment.timescale;
const eltInventoryEnd = !inventorySegment.complete
? eltInventory.end
: eltInventoryStart + inventorySegment.duration / inventorySegment.timescale;
if (
(eltInventoryEnd > minEnd && eltInventoryStart < maxStart) ||
(eltInventory.end > minEnd && eltInventory.start < maxStart)
) {
overlappingChunks.unshift(eltInventory);
}
}
}
return overlappingChunks;
}
3 changes: 2 additions & 1 deletion src/core/stream/representation/utils/get_needed_segments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import type {
IBufferedHistoryEntry,
IChunkContext,
} from "../../../segment_sinks";
import { ChunkStatus } from "../../../segment_sinks/inventory/segment_inventory";

interface IContentContext {
adaptation: IAdaptation;
Expand Down Expand Up @@ -243,7 +244,7 @@ export default function getNeededSegments({
// periods, we should consider a segment as already downloaded if
// it is from same period (but can be from different adaptation or
// representation)
if (areFromSamePeriod) {
if (completeSeg.status === ChunkStatus.Complete && areFromSamePeriod) {
const completeSegInfos = completeSeg.infos.segment;
if (
time - completeSegInfos.time > -ROUNDING_ERROR &&
Expand Down

0 comments on commit 75eb852

Please sign in to comment.