"use strict";
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MP4Callback = void 0;
const promises_1 = require("fs/promises");
const __1 = require("../..");
const mp4_1 = require("./mp4");
class MP4Callback extends mp4_1.MP4Base {
    constructor(tracks, options = {}) {
        super(tracks, async (output) => {
            const cb = this.cb;
            if (cb) {
                await this.queue.push(() => cb(output));
            }
        }, options);
        Object.defineProperty(this, "cb", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
        Object.defineProperty(this, "queue", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: new __1.PromiseQueue()
        });
        Object.defineProperty(this, "pipe", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: (cb) => {
                this.cb = cb;
                this.start();
            }
        });
        Object.defineProperty(this, "inputAudio", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: (input) => {
                this.processAudioInput(input);
            }
        });
        Object.defineProperty(this, "inputVideo", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: (input) => {
                this.processVideoInput(input);
            }
        });
        Object.defineProperty(this, "destroy", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: () => {
                this.cb = undefined;
                this.queue.cancel();
            }
        });
    }
}
exports.MP4Callback = MP4Callback;
_a = MP4Callback;
Object.defineProperty(MP4Callback, "saveToFileSystem", {
    enumerable: true,
    configurable: true,
    writable: true,
    value: (path) => {
        const queue = new __1.PromiseQueue();
        return async (value) => {
            await queue.push(async () => {
                if (value.data) {
                    await (0, promises_1.appendFile)(path, value.data);
                }
                else if (value.eol) {
                }
            });
        };
    }
});
//# sourceMappingURL=mp4Callback.js.map