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