Skip to content

Commit

Permalink
Remove LinkedMap class
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlika committed Jan 10, 2024
1 parent f2bf765 commit fa35c6c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 101 deletions.
5 changes: 2 additions & 3 deletions packages/p2p-media-loader-core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
StreamDetails,
} from "./types";
import * as StreamUtils from "./utils/stream";
import { LinkedMap } from "./linked-map";
import { BandwidthCalculator } from "./bandwidth-calculator";
import { EngineCallbacks } from "./requests/engine-request";
import { SegmentsMemoryStorage } from "./segments-storage";
Expand Down Expand Up @@ -67,7 +66,7 @@ export class Core<TStream extends Stream = Stream> {
if (this.streams.has(stream.localId)) return;
this.streams.set(stream.localId, {
...stream,
segments: new LinkedMap<string, Segment>(),
segments: new Map<string, Segment>(),
});
}

Expand All @@ -81,7 +80,7 @@ export class Core<TStream extends Stream = Stream> {

addSegments?.forEach((s) => {
const segment = { ...s, stream };
stream.segments.addToEnd(segment.localId, segment);
stream.segments.set(segment.localId, segment);
});
removeSegmentIds?.forEach((id) => stream.segments.delete(id));
this.mainStreamLoader?.updateStream(stream);
Expand Down
82 changes: 0 additions & 82 deletions packages/p2p-media-loader-core/src/linked-map.ts

This file was deleted.

13 changes: 2 additions & 11 deletions packages/p2p-media-loader-core/src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { LinkedMap } from "./linked-map";
import { RequestAttempt } from "./requests/request";
import { BandwidthCalculator } from "./bandwidth-calculator";

Expand All @@ -25,23 +24,15 @@ export type Stream = {
readonly index: number;
};

export type ReadonlyLinkedMap<K, V extends object> = Pick<
LinkedMap<K, V>,
"has" | "keys" | "values" | "valuesBackwards" | "size"
>;

export type StreamWithSegments<
TStream extends Stream = Stream,
TMap extends ReadonlyLinkedMap<string, SegmentBase> = LinkedMap<
string,
Segment
>,
TMap extends ReadonlyMap<string, SegmentBase> = Map<string, Segment>,
> = TStream & {
readonly segments: TMap;
};

export type StreamWithReadonlySegments<TStream extends Stream = Stream> =
StreamWithSegments<TStream, ReadonlyLinkedMap<string, SegmentBase>>;
StreamWithSegments<TStream, ReadonlyMap<string, SegmentBase>>;

export type SegmentResponse = {
data: ArrayBuffer;
Expand Down
15 changes: 12 additions & 3 deletions packages/p2p-media-loader-core/src/utils/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,19 @@ export function* generateQueue(
settings: PlaybackTimeWindowsSettings
): Generator<QueueItem, void> {
const { localId: requestedSegmentId, stream } = lastRequestedSegment;
const queueSegments = stream.segments.values(requestedSegmentId);

const first = queueSegments.next().value;
if (!first) return;
const requestedSegment = stream.segments.get(requestedSegmentId);
if (!requestedSegment) return;

const queueSegments = stream.segments.values();

let first: Segment | undefined;

while (first !== requestedSegment) {
first = queueSegments.next().value;
}

if (!first) return; // should never happen

const firstStatuses = getSegmentPlaybackStatuses(first, playback, settings);
if (isNotActualStatuses(firstStatuses)) {
Expand Down
3 changes: 1 addition & 2 deletions packages/p2p-media-loader-shaka/src/segment-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
StreamWithReadonlySegments,
SegmentBase,
StreamType,
ReadonlyLinkedMap,
} from "p2p-media-loader-core";

// The minimum time interval (in seconds) between segments to assign unique IDs.
Expand Down Expand Up @@ -143,7 +142,7 @@ function* itemsBackwards<T>(items: T[]) {
}

function* nSegmentsBackwards(
segments: ReadonlyLinkedMap<string, SegmentBase>,
segments: ReadonlyMap<string, SegmentBase>,
amount: number
) {
let i = 0;
Expand Down

0 comments on commit fa35c6c

Please sign in to comment.