"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DtxBase = void 0;
const crypto_1 = require("crypto");
class DtxBase {
    constructor(ptime, dummyPacket) {
        Object.defineProperty(this, "ptime", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: ptime
        });
        Object.defineProperty(this, "dummyPacket", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: dummyPacket
        });
        Object.defineProperty(this, "id", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: (0, crypto_1.randomUUID)().toString()
        });
        Object.defineProperty(this, "previousTimestamp", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
        Object.defineProperty(this, "fillCount", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: 0
        });
        Object.defineProperty(this, "internalStats", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: {}
        });
    }
    toJSON() {
        return { ...this.internalStats, id: this.id, fillCount: this.fillCount };
    }
    processInput({ frame, eol }) {
        if (eol) {
            this.stop();
            return [{ eol: true }];
        }
        if (frame) {
            if (!this.previousTimestamp) {
                this.previousTimestamp = frame.time;
                this.internalStats["dtx"] = new Date().toISOString();
                return [{ frame }];
            }
            if (frame.time != this.previousTimestamp + this.ptime) {
                const dummyPackets = [];
                for (let time = this.previousTimestamp; time < frame.time; time += this.ptime) {
                    dummyPackets.push({
                        frame: {
                            time,
                            isKeyframe: frame.isKeyframe,
                            data: this.dummyPacket,
                        },
                    });
                    this.fillCount++;
                }
                this.previousTimestamp = frame.time;
                this.internalStats["dtx"] = new Date().toISOString();
                return [...dummyPackets, { frame }];
            }
            else {
                this.previousTimestamp = frame.time;
                this.internalStats["dtx"] = new Date().toISOString();
                return [{ frame }];
            }
        }
        return [];
    }
    stop() {
        this.dummyPacket = undefined;
    }
}
exports.DtxBase = DtxBase;
//# sourceMappingURL=dtx.js.map