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

When listing segments needed, stop filtering the current range #1421

Merged
merged 1 commit into from
Apr 3, 2024
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
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
Loading