import { BufferedSeekingInput } from "../BufferedSeekingInput.js";
import { EFMedia } from "../../EFMedia.js";
import { Task } from "@lit/task";
const makeAudioInputTask = (host) => {
	return new Task(host, {
		args: () => [host.audioInitSegmentFetchTask.value, host.audioSegmentFetchTask.value],
		onError: (error) => {
			console.error("audioInputTask error", error);
		},
		onComplete: (_value) => {},
		task: async (_, { signal }) => {
			const initSegment = await host.audioInitSegmentFetchTask.taskComplete;
			signal.throwIfAborted();
			const segment = await host.audioSegmentFetchTask.taskComplete;
			signal.throwIfAborted();
			if (!initSegment || !segment) throw new Error("Init segment or segment is not available");
			const mediaEngine = await host.mediaEngineTask.taskComplete;
			const audioRendition = mediaEngine?.audioRendition;
			const startTimeOffsetMs = audioRendition?.startTimeOffsetMs;
			const arrayBuffer = await new Blob([initSegment, segment]).arrayBuffer();
			signal.throwIfAborted();
			return new BufferedSeekingInput(arrayBuffer, {
				videoBufferSize: EFMedia.VIDEO_SAMPLE_BUFFER_SIZE,
				audioBufferSize: EFMedia.AUDIO_SAMPLE_BUFFER_SIZE,
				startTimeOffsetMs
			});
		}
	});
};
export { makeAudioInputTask };
