diff --git a/packages/p2p-media-loader-core/src/p2p/tracker-client.ts b/packages/p2p-media-loader-core/src/p2p/tracker-client.ts index 73e934d7..6f862655 100644 --- a/packages/p2p-media-loader-core/src/p2p/tracker-client.ts +++ b/packages/p2p-media-loader-core/src/p2p/tracker-client.ts @@ -109,9 +109,7 @@ export class P2PTrackerClient { this.settings ); this.logger( - `connected with peer: ${peerItem.peer.id} ${LoggerUtils.getStreamString( - this.stream - )}` + `connected with peer: ${peerItem.peer.id} ${this.streamShortId}` ); this.eventHandlers.onPeerConnected(peerItem.peer); }); diff --git a/packages/p2p-media-loader-core/src/types.d.ts b/packages/p2p-media-loader-core/src/types.d.ts index e03ab496..d555a881 100644 --- a/packages/p2p-media-loader-core/src/types.d.ts +++ b/packages/p2p-media-loader-core/src/types.d.ts @@ -26,7 +26,7 @@ export type Stream = { export type ReadonlyLinkedMap = Pick< LinkedMap, - "has" | "keys" | "values" | "valuesBackwards" | "size" + "has" | "keys" | "values" | "size" >; export type StreamWithSegments< diff --git a/packages/p2p-media-loader-core/src/utils/stream.ts b/packages/p2p-media-loader-core/src/utils/stream.ts index 4b008cad..2266c381 100644 --- a/packages/p2p-media-loader-core/src/utils/stream.ts +++ b/packages/p2p-media-loader-core/src/utils/stream.ts @@ -91,17 +91,25 @@ export function getSegmentPlaybackStatuses( } = timeWindowsSettings; return { - isHighDemand: isInTimeWindow(segment, playback, highDemandTimeWindow), - isHttpDownloadable: isInTimeWindow( + isHighDemand: isSegmentInTimeWindow( + segment, + playback, + highDemandTimeWindow + ), + isHttpDownloadable: isSegmentInTimeWindow( segment, playback, httpDownloadTimeWindow ), - isP2PDownloadable: isInTimeWindow(segment, playback, p2pDownloadTimeWindow), + isP2PDownloadable: isSegmentInTimeWindow( + segment, + playback, + p2pDownloadTimeWindow + ), }; } -function isInTimeWindow( +function isSegmentInTimeWindow( segment: Segment, playback: Playback, timeWindowLength: number diff --git a/packages/p2p-media-loader-shaka/src/segment-manager.ts b/packages/p2p-media-loader-shaka/src/segment-manager.ts index 870b56a5..686b1bc2 100644 --- a/packages/p2p-media-loader-shaka/src/segment-manager.ts +++ b/packages/p2p-media-loader-shaka/src/segment-manager.ts @@ -8,6 +8,8 @@ import { ReadonlyLinkedMap, } from "p2p-media-loader-core"; +const SEGMENT_ID_SCALING_DURATION = 0.5; + export class SegmentManager { private readonly core: Core; private streamInfo: Readonly; @@ -59,7 +61,9 @@ export class SegmentManager { const staleSegmentsIds = new Set(managerStream.segments.keys()); const newSegments: SegmentBase[] = []; for (const reference of segmentReferences) { - const externalId = Math.trunc(reference.getStartTime() * 2); + const externalId = Math.trunc( + reference.getStartTime() / SEGMENT_ID_SCALING_DURATION + ); const segmentLocalId = Utils.getSegmentLocalIdFromReference(reference); if (!managerStream.segments.has(segmentLocalId)) { @@ -140,9 +144,9 @@ function* nSegmentsBackwards( amount: number ) { let i = 0; - for (const segment of segments.valuesBackwards()) { + for (const segment of segments.values()) { if (i >= amount) break; yield segment; - i--; + i++; } }