import type { IMediaElement } from "../../compat/browser_compatibility_types";
import type { IAdaptiveRepresentationSelectorArguments } from "../../core/types";
import type { IManifestMetadata } from "../../manifest";
import MainMediaSourceInterface from "../../mse/main_media_source_interface";
import type { IMediaElementPlaybackObserver } from "../../playback_observer";
import type { ICmcdOptions, IInitialManifest, IKeySystemOption, IRepresentationFilter, IManifestLoader, ISegmentLoader } from "../../public_types";
import type { ITransportOptions } from "../../transports";
import type { IReadOnlySharedReference } from "../../utils/reference";
import type CoreInterface from "../core_interface/types";
import type IContentDecryptor from "../decrypt";
import type { ITextDisplayerOptions } from "./types";
import { ContentInitializer } from "./types";
import type { IInitialTimeOptions } from "./utils/get_initial_time";
import RebufferingController from "./utils/rebuffering_controller";
/**
 * @class MediaSourceContentInitializer
 */
export default class MediaSourceContentInitializer extends ContentInitializer {
    /** Constructor settings associated to this `MediaSourceContentInitializer`. */
    private _settings;
    /**
     * The Core may be sending messages as soon as we're preparing the content but
     * the `MediaSourceContentInitializer` is only able to handle all of them only
     * once `start`ed.
     *
     * As such `_queuedCoreMessages` is set to an Array  when `prepare` has been
     * called but not `start` yet, and contains all core messages that have to
     * be processed when `start` is called.
     *
     * It is set to `null` when there's no need to rely on that queue (either not
     * yet `prepare`d or already `start`ed).
     */
    private _queuedCoreMessages;
    /**
     * Information relative to the current loaded content.
     *
     * `null` when no content is prepared yet.
     */
    private _currentContentInfo;
    /**
     * `TaskCanceller` allowing to abort everything that the
     * `MediaSourceContentInitializer` is doing.
     */
    private _initCanceller;
    /**
     * `TaskCanceller` allowing to abort and clean-up every task and resource
     * linked to the current `MediaSource` instance.
     *
     * It may be triggered either at content stop (and thus at the same time than
     * the `_initCanceller`) or when reloading the content.
     */
    private _currentMediaSourceCanceller;
    private _awaitingRequests;
    /**
     * Create a new `MediaSourceContentInitializer`, associated to the given
     * settings.
     * @param {Object} settings
     */
    constructor(settings: IInitializeArguments);
    /**
     * Perform non-destructive preparation steps, to prepare a future content.
     */
    prepare(): void;
    /**
     * Update URL of the Manifest.
     * @param {Array.<string>|undefined} urls - URLs to reach that Manifest from
     * the most prioritized URL to the least prioritized URL.
     * @param {boolean} refreshNow - If `true` the resource in question (e.g.
     * DASH's MPD) will be refreshed immediately.
     */
    updateContentUrls(urls: string[] | undefined, refreshNow: boolean): void;
    /**
     * @param {HTMLMediaElement} mediaElement
     * @param {Object} playbackObserver
     */
    start(mediaElement: IMediaElement, playbackObserver: IMediaElementPlaybackObserver): void;
    dispose(reason: string | undefined): void;
    private _onFatalError;
    private _initializeContentDecryption;
    /**
     * Retrieves all unknown codecs from the current manifest, checks these unknown codecs
     * to determine if they are supported, updates the manifest with the support
     * status of these codecs, and forwards the list of supported codecs to core.
     * @param manifest
     */
    private _updateCodecSupport;
    private _reload;
    /**
     * Start-up modules and mechanisms (initial seek, auto-play etc.) needed each
     * time a content is loaded AND re-loaded on a `HTMLMediaElement`, when the
     * manifest is known.
     *
     * Note that this does not include reacting to incoming core messages nor
     * sending them, those actions have to be handled separately.
     *
     * @param {Object} parameters
     * @param {Object} cancelSignal
     * @returns {Object|null} - Playback Observer created for this content. `null`
     * only if playback initialization failed (most likely because it has been
     * cancelled).
     */
    private _setUpModulesOnNewMediaSource;
    /**
     * Initialize content playback if and only if those conditions are filled:
     *   - The Manifest is fetched and stored in `this._currentContentInfo`.
     *   - `drmInitializationStatus` indicates that DRM matters are initialized.
     *   - `mediaSourceStatus` indicates that the MediaSource is attached to the
     *     `mediaElement`.
     *
     * In other cases, this method will do nothing.
     *
     * To call when any of those conditions might become `true`, to start-up
     * playback.
     *
     * @param {Object} parameters
     * @returns {boolean} - Returns `true` if all conditions where met for
     * playback start.
     */
    private _startPlaybackIfReady;
    /**
     * Handles core messages asking to create a MediaSource.
     * @param {Object} msg - The core's message received.
     * @param {HTMLMediaElement} mediaElement - HTMLMediaElement on which the
     * content plays.
     * @param {Object} coreInterface - The interface to the core.
     */
    private _onCreateMediaSourceMessage;
}
export interface IMediaSourceContentInitializerContentInfos {
    /**
     * "contentId", which is the identifier for the currently loaded content.
     * Allows to ensure that the Core is referencing the current content, not
     * a previously stopped one.
     */
    contentId: string;
    /**
     * Current parsed Manifest.
     * `null` if not fetched / parsed yet.
     */
    manifest: IManifestMetadata | null;
    /**
     * Current MediaSource linked to the content.
     *
     * `null` if no MediaSource is currently created for the content.
     */
    mediaSourceInfo: {
        type: "main";
        mediaSource: MainMediaSourceInterface;
    } | {
        type: "core";
        mediaSourceId: string;
    } | null;
    /**
     * Current `RebufferingController` linked to the content, allowing to
     * detect and handle rebuffering situations.
     *
     * `null` if none is currently created for the content.
     */
    rebufferingController: RebufferingController | null;
    /**
     * The initial position to seek to in seconds once the content is loadeed.
     * `undefined` if unknown yet.
     */
    initialTime: number | undefined;
    /**
     * Whether to automatically play once the content is loaded.
     * `undefined` if unknown yet.
     */
    autoPlay: boolean | undefined;
    /**
     * Set to `true` once the initial play (or skipping the initial play when
     * autoplay is not enabled) has been done.
     * Set to `false` when it hasn't been done yet.
     *
     * Set to `null` when those considerations are not taken yet.
     */
    initialPlayPerformed: IReadOnlySharedReference<boolean> | null;
    /**
     * Set to the initialized `ContentDecryptor` instance linked to that content.
     *
     * Set to `null` when those considerations are not taken.
     */
    contentDecryptor: IContentDecryptor | null;
    /**
     * If `true`, MSE API should be used in the core part of the RxPlayer (in the
     * WebWorker).
     * If `false`, they should be relied on on main thread.
     */
    useMseInWorker: boolean;
}
/** Arguments to give to the `InitializeOnMediaSource` function. */
export interface IInitializeArguments {
    /**
     * The `MediaSourceContentInitializer` will interact with the RxPlayer's core
     * logic (the one loading media data) by exchanging messages through an
     * interface called the `CoreInterface`.
     *
     * This `CoreInterface` allows to abstract its actual current implementation.
     * E.g., the core logic could be running in a WebWorker or in main thread, in
     * which cases message exchanging mechanisms would be different.
     */
    coreInterface: CoreInterface;
    /**
     * If `true`, MSE API should be used in the core part of the RxPlayer (in the
     * WebWorker).
     * If `false`, they should be relied on on main thread.
     *
     * This might depend on both browser capabilities and preferences. It is
     * assumed that the caller perform all those checks, the `ContentInitializer`
     * won't check again the validity of this value.
     */
    useMseInWorker: boolean;
    /** Options concerning the ABR logic. */
    adaptiveOptions: IAdaptiveRepresentationSelectorArguments;
    /** `true` if we should play when loaded. */
    autoPlay: boolean;
    /** Options concerning the media buffers. */
    bufferOptions: {
        /** Buffer "goal" at which we stop downloading new segments. */
        wantedBufferAhead: IReadOnlySharedReference<number>;
        /** Buffer maximum size in kiloBytes at which we stop downloading */
        maxVideoBufferSize: IReadOnlySharedReference<number>;
        /** Max buffer size after the current position, in seconds (we GC further up). */
        maxBufferAhead: IReadOnlySharedReference<number>;
        /** Max buffer size before the current position, in seconds (we GC further down). */
        maxBufferBehind: IReadOnlySharedReference<number>;
        /**
         * Enable/Disable fastSwitching: allow to replace lower-quality segments by
         * higher-quality ones to have a faster transition.
         */
        enableFastSwitching: boolean;
        /** Behavior when a new video and/or audio codec is encountered. */
        onCodecSwitch: "continue" | "reload";
    };
    /**
     * When set to an object, enable "Common Media Client Data", or "CMCD".
     */
    cmcd?: ICmcdOptions | undefined;
    /**
     * If `true`, the RxPlayer can enable its "Representation avoidance"
     * mechanism, where it avoid loading Representation that it suspect
     * have issues being decoded on the current device.
     */
    enableRepresentationAvoidance: boolean;
    /** Every encryption configuration set. */
    keySystems: IKeySystemOption[];
    /** `true` to play low-latency contents optimally. */
    lowLatencyMode: boolean;
    /**
     * The type of "transport" wanted, e.g. "dash" or "smooth".
     */
    transport: string;
    /** Options relative to the streaming protocol. */
    transportOptions: Omit<ITransportOptions, "representationFilter" | "manifestLoader" | "segmentLoader"> & {
        manifestLoader: undefined | {
            fn?: IManifestLoader | undefined;
            workerId?: string | undefined;
        };
        segmentLoader: undefined | {
            fn?: ISegmentLoader | undefined;
            workerId?: string | undefined;
        };
        representationFilter: undefined | {
            fn?: IRepresentationFilter | undefined;
            eval?: string | undefined;
            workerId?: string | undefined;
        };
    };
    /** Settings linked to Manifest requests. */
    manifestRequestSettings: {
        /** Maximum number of time a request on error will be retried. */
        maxRetry: number | undefined;
        /**
         * Timeout after which request are aborted and, depending on other options,
         * retried.
         * To set to `-1` for no timeout.
         * `undefined` will lead to a default, large, timeout being used.
         */
        requestTimeout: number | undefined;
        /**
         * Connection timeout, in milliseconds, after which the request is canceled
         * if the responses headers has not being received.
         * Do not set or set to "undefined" to disable it.
         */
        connectionTimeout: number | undefined;
        /** Limit the frequency of Manifest updates. */
        minimumManifestUpdateInterval: number;
        /**
         * Potential first Manifest to rely on, allowing to skip the initial Manifest
         * request.
         */
        initialManifest: IInitialManifest | undefined;
    };
    /** Configuration for the segment requesting logic. */
    segmentRequestOptions: {
        lowLatencyMode: boolean;
        /**
         * Amount of time after which a request should be aborted.
         * `undefined` indicates that a default value is wanted.
         * `-1` indicates no timeout.
         */
        requestTimeout: number | undefined;
        /**
         * Amount of time, in milliseconds, after which a request that hasn't receive
         * the headers and status code should be aborted and optionnaly retried,
         * depending on the maxRetry configuration.
         */
        connectionTimeout: number | undefined;
        /** Maximum number of time a request on error will be retried. */
        maxRetry: number | undefined;
    };
    /** Emit the playback rate (speed) set by the user. */
    speed: IReadOnlySharedReference<number>;
    /** The configured starting position. */
    startAt?: IInitialTimeOptions | undefined;
    /** Configuration specific to the text track. */
    textTrackOptions: ITextDisplayerOptions;
    /** URL of the Manifest. `undefined` if unknown or not pertinent. */
    url: string | undefined;
}
//# sourceMappingURL=media_source_content_initializer.d.ts.map