Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
peaBerberian committed Aug 31, 2023
1 parent 3a7df03 commit 926b484
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 44 deletions.
7 changes: 4 additions & 3 deletions src/compat/eme/custom_media_keys/old_webkit_media_keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ export interface IOldWebkitHTMLMediaElement extends HTMLVideoElement {
* @returns {Boolean}
*/
export function isOldWebkitMediaElement(
element : HTMLMediaElement|IOldWebkitHTMLMediaElement
element : unknown
) : element is IOldWebkitHTMLMediaElement {
return typeof (element as IOldWebkitHTMLMediaElement)
.webkitGenerateKeyRequest === "function";
return typeof (
element as IOldWebkitHTMLMediaElement
)?.webkitGenerateKeyRequest === "function";
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/compat/eme/eme-api-implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function getEmeApiImplementation(
implementation = "webkit";
} else {
// This is for Chrome with unprefixed EME api
if (isOldWebkitMediaElement(HTMLVideoElement.prototype)) {
if (isOldWebkitMediaElement(globalScope.HTMLVideoElement?.prototype)) {
onEncrypted = createCompatibleEventListener(["needkey"]);
const callbacks = getOldKitWebKitMediaKeyCallbacks();
isTypeSupported = callbacks.isTypeSupported;
Expand Down
4 changes: 2 additions & 2 deletions src/core/init/create_content_time_boundaries_observer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import log from "../../log";
import Manifest, {
IPeriodMetadata,
Period,
} from "../../manifest";
import { IPlayerError } from "../../public_types";
import {
Expand All @@ -14,7 +14,7 @@ import ContentTimeBoundariesObserver from "./utils/content_time_boundaries_obser

export interface IContentTimeBoundariesObserverCallbacks {
onWarning: (evt: IPlayerError) => void;
onPeriodChanged: (period: IPeriodMetadata) => void;
onPeriodChanged: (period: Period) => void;
}

/**
Expand Down
21 changes: 19 additions & 2 deletions src/core/init/multi_thread_content_initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,25 @@ export default class MultiThreadContentInitializer extends ContentInitializer {
if (this._mainThreadMediaSource?.id !== msgData.mediaSourceId) {
return;
}
this._mainThreadMediaSource.addSourceBuffer(msgData.value.sourceBufferType,
msgData.value.codec);
const sbInterface = this._mainThreadMediaSource.addSourceBuffer(
msgData.value.sourceBufferType,
msgData.value.codec);
sbInterface.addEventListener("sourceBufferError", () => {
sendMessage(this._settings.worker, {
type: "source-buffer-error",
mediaSourceId: msgData.mediaSourceId,
sourceBufferType: msgData.value.sourceBufferType,
value: null,
});
}, this._initCanceller.signal);
sbInterface.addEventListener("sourceBufferUpdateEnd", () => {
sendMessage(this._settings.worker, {
type: "source-buffer-success",
mediaSourceId: msgData.mediaSourceId,
sourceBufferType: msgData.value.sourceBufferType,
value: null,
});
}, this._initCanceller.signal);
}
break;

Expand Down
9 changes: 4 additions & 5 deletions src/core/init/utils/content_time_boundaries_observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import { MediaError } from "../../../errors";
import Manifest, {
Adaptation,
IPeriodMetadata,
IRepresentationIndex,
Period,
} from "../../../manifest";
Expand Down Expand Up @@ -187,7 +186,7 @@ export default class ContentTimeBoundariesObserver
*/
public onRepresentationChange(
bufferType : IBufferType,
period : IPeriodMetadata
period : Period
) : void {
this._addActivelyLoadedPeriod(period, bufferType);
}
Expand Down Expand Up @@ -257,7 +256,7 @@ export default class ContentTimeBoundariesObserver
}

private _addActivelyLoadedPeriod(
period : IPeriodMetadata,
period : Period,
bufferType : IBufferType
) : void {
const streamInfo = this._lazilyCreateActiveStreamInfo(bufferType);
Expand Down Expand Up @@ -382,7 +381,7 @@ export interface IContentTimeBoundariesObserverEvent {
/** Triggered when a minor error is encountered. */
warning : IPlayerError;
/** Triggered when a new `Period` is currently playing. */
periodChange : IPeriodMetadata;
periodChange : Period;
/**
* Triggered when the duration of the currently-playing content became known
* or changed.
Expand Down Expand Up @@ -637,7 +636,7 @@ interface IActiveStreamsInfo {
* The first chronological Period in that list is the active one for
* the current type.
*/
activePeriods : SortedList<IPeriodMetadata>;
activePeriods : SortedList<Period>;
/**
* If `true` the last segment for the last currently known Period has been
* pushed for the current Adaptation and Representation choice.
Expand Down
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 log from "../../../../log";
import { getLoggableSegmentId } from "../../../../manifest";
import assertUnreachable from "../../../../utils/assert_unreachable";
Expand Down Expand Up @@ -180,19 +179,10 @@ export default class AudioVideoSegmentBuffer extends SegmentBuffer {
const onError = this._onPendingTaskError.bind(this);
const reCheck = this._flush.bind(this);

// Some browsers (happened with firefox 66) sometimes "forget" to send us
// `update` or `updateend` events.
// In that case, we're completely unable to continue the queue here and
// stay locked in a waiting state.
// This interval is here to check at regular intervals if the underlying
// SourceBuffer is currently updating.
const { SOURCE_BUFFER_FLUSHING_INTERVAL } = config.getCurrent();
const intervalId = setInterval(reCheck, SOURCE_BUFFER_FLUSHING_INTERVAL);
this._sourceBuffer.addEventListener("sourceBufferError", onError);
this._sourceBuffer.addEventListener("sourceBufferUpdateEnd", reCheck);

this._canceller.signal.register(() => {
clearInterval(intervalId);
this._sourceBuffer.removeEventListener("sourceBufferError", onError);
this._sourceBuffer.removeEventListener("sourceBufferUpdateEnd", reCheck);
});
Expand Down Expand Up @@ -525,10 +515,20 @@ export default class AudioVideoSegmentBuffer extends SegmentBuffer {
!this._isLastInitSegment(data.initSegmentUniqueId))
{
// Push initialization segment before the media segment
const segmentData = this._initSegmentsMap.get(data.initSegmentUniqueId);
let segmentData = this._initSegmentsMap.get(data.initSegmentUniqueId);
if (segmentData === undefined) {
throw new Error("Invalid initialization segment uniqueId");
}
// XXX TODO
// Initialization segments have to be cloned for now
const dst = new ArrayBuffer(segmentData.byteLength);
const tmpU8 = new Uint8Array(dst);
tmpU8.set(
segmentData instanceof ArrayBuffer ?
new Uint8Array(segmentData) :
new Uint8Array(segmentData.buffer)
);
segmentData = tmpU8;
dataToPush.push(segmentData);
this._lastInitSegmentUniqueId = data.initSegmentUniqueId;
}
Expand Down
18 changes: 9 additions & 9 deletions src/main/send_message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ export interface ISourceBufferOperationSuccessMainMessage {
* `CreateSourceBufferWorkerMessage`.
*/
sourceBufferType: SourceBufferType;
value: {
buffered: Float64Array;
};
value: null;
}

export interface ISourceBufferErrorMainMessage {
Expand All @@ -181,12 +179,14 @@ export interface ISourceBufferErrorMainMessage {
mediaSourceId: string;
/** Identify the SourceBuffer in question. */
sourceBufferType: SourceBufferType;
value: {
/** The error's message. */
message: string;
/** If `true` the error is due to the fact that the buffer is full. */
isBufferFull: boolean;
};
value: null;
// XXX TODO
// {
// /** The error's message. */
// message: string;
// /** If `true` the error is due to the fact that the buffer is full. */
// isBufferFull: boolean;
// }
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/transports/dash/manifest_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ export default function generateManifestParser(
return Promise.reject(cancelSignal.cancellationError);
}
const warnings : IPlayerError[] = [];
// options.representationFilter = (rep, ctxt) => {
// if (ctxt.trackType === "video") {
// return (rep.bitrate ?? 2100000) <= 2100000;
// }
// return true;
// };
options.representationFilter = (rep, ctxt) => {
if (ctxt.trackType === "video") {
return (rep.bitrate ?? 2100000) <= 2100000;
}
return true;
};
const manifest = new Manifest(parserResponse.value.parsed, options, warnings);
return { manifest, url, warnings };
}
Expand Down
5 changes: 2 additions & 3 deletions src/worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
} from "../main";
import Manifest, {
Adaptation,
IPeriodMetadata,
Period,
Representation,
} from "../manifest";
Expand Down Expand Up @@ -206,11 +205,11 @@ function startCurrentContent(val : IStartContentMessageValue) {
sendMessage({ type: "warning",
contentId,
value: formatErrorForSender(err) }),
onPeriodChanged: (period: IPeriodMetadata) => {
onPeriodChanged: (period: Period) => {
sendMessage({
type: "activePeriodChanged",
contentId,
value: { period },
value: { period: period.getMetadataSnapshot() },
});
},
},
Expand Down
3 changes: 2 additions & 1 deletion src/worker/send_message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export default function sendMessage(
} else {
// TypeScript made a mistake here, and 2busy2fix
/* eslint-disable-next-line */
(postMessage as any)(msg, transferables);
// XXX TODO add transferables urgently
(postMessage as any)(msg);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/worker/worker_content_initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export default class WorkerSideContentInitializer {
sendMessage({
type: "manifest-update",
contentId,
value: { manifest, updates },
value: { manifest: manifest.getMetadataSnapshot(), updates },
});
}, contentCanceller.signal);
unbindRejectOnCancellation();
Expand Down

0 comments on commit 926b484

Please sign in to comment.