/*!
 * Copyright (c) 2026-present, Vanilagy and contributors
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 */
import { Muxer } from '../muxer.js';
import { Output, OutputAudioTrack, OutputSubtitleTrack, OutputTrack, OutputVideoTrack } from '../output.js';
import { Rational } from '../misc.js';
import { IsobmffOutputFormat } from '../output-format.js';
import { SubtitleConfig, SubtitleCue, SubtitleMetadata } from '../subtitles.js';
import { EncodedPacket, PacketType } from '../packet.js';
export declare const GLOBAL_TIMESCALE = 57600;
export type Sample = {
    timestamp: number;
    decodeTimestamp: number;
    duration: number;
    data: Uint8Array | null;
    size: number;
    type: PacketType;
    timescaleUnitsToNextSample: number;
};
type Chunk = {
    /** The lowest presentation timestamp in this chunk */
    startTimestamp: number;
    samples: Sample[];
    offset: number | null;
    moofOffset: number | null;
};
export type IsobmffTrackData = {
    muxer: IsobmffMuxer;
    timescale: number;
    samples: Sample[];
    sampleQueue: Sample[];
    timestampProcessingQueue: Sample[];
    timeToSampleTable: {
        sampleCount: number;
        sampleDelta: number;
    }[];
    compositionTimeOffsetTable: {
        sampleCount: number;
        sampleCompositionTimeOffset: number;
    }[];
    lastTimescaleUnits: number | null;
    lastSample: Sample | null;
    startTimestampOffset: number | null;
    finalizedChunks: Chunk[];
    currentChunk: Chunk | null;
    compactlyCodedChunkTable: {
        firstChunk: number;
        samplesPerChunk: number;
    }[];
    closed: boolean;
} & ({
    track: OutputVideoTrack;
    type: 'video';
    info: {
        width: number;
        height: number;
        pixelAspectRatio: Rational;
        decoderConfig: VideoDecoderConfig;
        /**
         * The "Annex B transformation" involves converting the raw packet data from Annex B to
         * "MP4" (length-prefixed) format.
         * https://stackoverflow.com/questions/24884827
         */
        requiresAnnexBTransformation: boolean;
    };
} | {
    track: OutputAudioTrack;
    type: 'audio';
    info: {
        numberOfChannels: number;
        sampleRate: number;
        decoderConfig: AudioDecoderConfig;
        /**
         * The "PCM transformation" is making every sample in the sample table be exactly one PCM audio sample long.
         * Some players expect this for PCM audio.
         */
        requiresPcmTransformation: boolean;
        expectedNextPcmPacketTimestamp: number | null;
        /**
         * The "ADTS stripping" involves removing the ADTS header from each AAC packet. SOBMFF stores raw AAC data, not
         * ADTS-wrapped data.
         */
        requiresAdtsStripping: boolean;
        firstPacket: EncodedPacket;
    };
} | {
    track: OutputSubtitleTrack;
    type: 'subtitle';
    info: {
        config: SubtitleConfig;
    };
    lastCueEndTimestamp: number;
    cueQueue: SubtitleCue[];
    nextSourceId: number;
    cueToSourceId: WeakMap<SubtitleCue, number>;
});
export type IsobmffVideoTrackData = IsobmffTrackData & {
    type: 'video';
};
export type IsobmffAudioTrackData = IsobmffTrackData & {
    type: 'audio';
};
export type IsobmffSubtitleTrackData = IsobmffTrackData & {
    type: 'subtitle';
};
export type IsobmffMetadata = {
    name?: string;
};
export declare const getTrackMetadata: (trackData: IsobmffTrackData) => IsobmffMetadata;
export declare const intoTimescale: (timeInSeconds: number, timescale: number, round?: boolean) => number;
export declare class IsobmffMuxer extends Muxer {
    format: IsobmffOutputFormat;
    private writer;
    private boxWriter;
    private initWriter;
    private initBoxWriter;
    private fastStart;
    isFragmented: boolean;
    isQuickTime: boolean;
    isCmaf: boolean;
    private auxTarget;
    private auxWriter;
    private auxBoxWriter;
    private mdat;
    private ftypSize;
    trackDatas: IsobmffTrackData[];
    private allTracksKnown;
    creationTime: number;
    private finalizedChunks;
    private nextFragmentNumber;
    private maxWrittenTimestamp;
    minWrittenTimestamp: number;
    maxWrittenEndTimestamp: number;
    private minimumFragmentDuration;
    private segmentHeaderSize;
    constructor(output: Output, format: IsobmffOutputFormat);
    start(): Promise<void>;
    private allTracksAreKnown;
    getMimeType(): Promise<string>;
    private getVideoTrackData;
    private getAudioTrackData;
    private getSubtitleTrackData;
    addEncodedVideoPacket(track: OutputVideoTrack, packet: EncodedPacket, meta?: EncodedVideoChunkMetadata): Promise<void>;
    addEncodedAudioPacket(track: OutputAudioTrack, packet: EncodedPacket, meta?: EncodedAudioChunkMetadata): Promise<void>;
    private padWithSilence;
    addSubtitleCue(track: OutputSubtitleTrack, cue: SubtitleCue, meta?: SubtitleMetadata): Promise<void>;
    private processWebVTTCues;
    private createSampleForTrack;
    private processTimestamps;
    private registerSample;
    private addSampleToTrack;
    private finalizeCurrentChunk;
    private interleaveSamples;
    private finalizeFragment;
    private registerSampleFastStartReserve;
    private computeSampleTableSizeUpperBound;
    onTrackClose(track: OutputTrack): Promise<void>;
    /** Finalizes the file, making it ready for use. Must be called after all video and audio chunks have been added. */
    finalize(): Promise<void>;
}
export {};
//# sourceMappingURL=isobmff-muxer.d.ts.map