Skip to content

Commit

Permalink
Fix bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
i-zolotarenko committed Dec 20, 2023
1 parent d1d8a62 commit 3509712
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 28 deletions.
7 changes: 6 additions & 1 deletion packages/p2p-media-loader-core/src/hybrid-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ export class HybridLoader {
if (statuses.isHighDemand) {
if (request?.type === "http" && request.status === "loading") continue;

const isP2PLoadingRequest =
request?.status === "loading" && request.type === "p2p";

if (this.requests.executingHttpCount < simultaneousHttpDownloads) {
if (isP2PLoadingRequest) request.abortFromEngine();
void this.loadThroughHttp(segment);
continue;
}
Expand All @@ -196,11 +200,12 @@ export class HybridLoader {
this.abortLastHttpLoadingInQueueAfterItem(queue, segment) &&
this.requests.executingHttpCount < simultaneousHttpDownloads
) {
if (isP2PLoadingRequest) request.abortFromEngine();
void this.loadThroughHttp(segment);
continue;
}

if (request?.type === "p2p" && request.status === "loading") continue;
if (isP2PLoadingRequest) continue;

if (this.requests.executingP2PCount < simultaneousP2PDownloads) {
void this.loadThroughP2P(segment);
Expand Down
9 changes: 0 additions & 9 deletions packages/p2p-media-loader-core/src/linked-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,6 @@ export class LinkedMap<K, V extends object> {
}
}

*valuesBackwards(key?: K) {
let value = key ? this.map.get(key) : this._last;
if (value === undefined) return;
while (value?.item !== undefined) {
yield value.item[1];
value = value.prev;
}
}

*keys(): Generator<K> {
let value = this._first;
if (value === undefined) return;
Expand Down
5 changes: 5 additions & 0 deletions packages/p2p-media-loader-core/src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ export class Request {
abortFromProcessQueue() {
this.throwErrorIfNotLoadingStatus();
this._status = "aborted";
this.logger(
`${this.currentAttempt?.type} ${this.segment.externalId} aborted`
);
this._abortRequestCallback?.("abort");
this._abortRequestCallback = undefined;
this.currentAttempt = undefined;
Expand All @@ -205,6 +208,7 @@ export class Request {
this._status = "failed";
const error = new RequestError("bytes-receiving-timeout");
this._abortRequestCallback?.(error.type);
this.logger(`${this.type} ${this.segment.externalId} failed ${error.type}`);

this.currentAttempt.error = error;
this._failedAttempts.push(this.currentAttempt);
Expand All @@ -217,6 +221,7 @@ export class Request {
if (!this.currentAttempt) return;

this._status = "failed";
this.logger(`${this.type} ${this.segment.externalId} failed ${error.type}`);
this.currentAttempt.error = error;
this._failedAttempts.push(this.currentAttempt);
this.notReceivingBytesTimeout.clear();
Expand Down
7 changes: 0 additions & 7 deletions packages/p2p-media-loader-core/src/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Segment, Stream } from "../types";
import { QueueItem } from "./queue";
import { SegmentPlaybackStatuses } from "./stream";

export function getStreamString(stream: Stream) {
Expand All @@ -21,9 +20,3 @@ export function getSegmentPlaybackStatusesString(
if (isP2PDownloadable) return "p2p-window";
return "-";
}

export function getQueueItemString(item: QueueItem) {
const { segment, statuses } = item;
const statusString = getSegmentPlaybackStatusesString(statuses);
return `${segment.externalId} ${statusString}`;
}
7 changes: 1 addition & 6 deletions packages/p2p-media-loader-shaka/src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,7 @@ export class Engine {
const { p2pml } = request;
if (!p2pml) return shaka.net.HttpFetchPlugin.parse(...args);

const loader = new Loader(
p2pml.shaka,
p2pml.core,
p2pml.streamInfo,
p2pml.segmentManager
);
const loader = new Loader(p2pml.shaka, p2pml.core, p2pml.streamInfo);
return loader.load(...args);
};
NetworkingEngine.registerScheme("http", handleLoading);
Expand Down
4 changes: 1 addition & 3 deletions packages/p2p-media-loader-shaka/src/loading-handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as Utils from "./stream-utils";
import { SegmentManager } from "./segment-manager";
import { StreamInfo } from "./types";
import { Shaka, Stream } from "./types";
import {
Expand All @@ -19,8 +18,7 @@ export class Loader {
constructor(
private readonly shaka: Shaka,
private readonly core: Core<Stream>,
readonly streamInfo: StreamInfo,
private readonly segmentManager: SegmentManager
readonly streamInfo: StreamInfo
) {}

private defaultLoad() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ export class ManifestParserDecorator implements shaka.extern.ManifestParser {
) {
return reference;
}
prevFirstItemReference = firstItemReference;
prevLastItemReference = lastItemReference;

// Segment index have been updated
segmentManager.updateStreamSegments(stream, references);
this.debug(`Stream ${stream.id} is updated`);
prevFirstItemReference = firstItemReference;
prevLastItemReference = lastItemReference;
} catch (err) {
// This catch is intentionally left blank.
// [...segmentIndex] throws an error when segmentIndex inner array is empty
Expand Down

0 comments on commit 3509712

Please sign in to comment.