mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-12-03 02:37:06 +03:00
Choosing Manual after an unsaved Disabled or Auto sent `""`, which counts as no change, so BaseSection reset the form to the saved value and the field snapped back to the saved option. Manual now stays selected when the form falls back to the saved value, and it starts from the saved manual args when there are any, otherwise from an empty box.
383 lines
12 KiB
TypeScript
383 lines
12 KiB
TypeScript
/**
|
|
* Hardware acceleration args widget -- MEDIUM tier.
|
|
*
|
|
* Global hwaccel offers Auto (writes "auto") and Disabled (writes []).
|
|
* Cameras offer Disabled next to "Inherit from global setting".
|
|
*/
|
|
|
|
import { readFileSync } from "node:fs";
|
|
import { resolve, dirname } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { test, expect, type FrigateApp } from "../../fixtures/frigate-test";
|
|
import {
|
|
configFactory,
|
|
type DeepPartial,
|
|
} from "../../fixtures/mock-data/config";
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
const CONFIG_SCHEMA = JSON.parse(
|
|
readFileSync(
|
|
resolve(__dirname, "../../fixtures/mock-data/config-schema.json"),
|
|
"utf-8",
|
|
),
|
|
);
|
|
|
|
const MANUAL_WARNING = "Manual hardware acceleration arguments are not";
|
|
|
|
async function openSettings(
|
|
app: FrigateApp,
|
|
url: string,
|
|
overrides: DeepPartial<ReturnType<typeof configFactory>> = {},
|
|
) {
|
|
const { page } = app;
|
|
const config = configFactory(overrides);
|
|
let lastSaved: unknown = null;
|
|
|
|
await page.route("**/api/config/schema.json", (route) =>
|
|
route.fulfill({ json: CONFIG_SCHEMA }),
|
|
);
|
|
await page.route("**/api/config", (route) => route.fulfill({ json: config }));
|
|
await page.route("**/api/config/raw_paths", (route) =>
|
|
route.fulfill({ json: { cameras: {}, go2rtc: { streams: {} } } }),
|
|
);
|
|
await page.route("**/api/config/set", async (route) => {
|
|
lastSaved = route.request().postDataJSON();
|
|
await route.fulfill({ json: { success: true, require_restart: false } });
|
|
});
|
|
await page.route("**/api/ffmpeg/presets", (route) =>
|
|
route.fulfill({
|
|
json: {
|
|
hwaccel_args: ["preset-vaapi", "preset-nvidia"],
|
|
input_args: ["preset-rtsp-generic"],
|
|
output_args: { record: ["preset-record-generic"], detect: [] },
|
|
},
|
|
}),
|
|
);
|
|
|
|
await app.goto(url);
|
|
return { saved: () => lastSaved };
|
|
}
|
|
|
|
const radio = (app: FrigateApp, field: string, mode: string) =>
|
|
app.page.locator(`[id="${field}-${mode}"]`);
|
|
|
|
const manualInput = (app: FrigateApp, field = "root_hwaccel_args") =>
|
|
app.page.locator(`input[id="${field}"]`);
|
|
|
|
const save = (app: FrigateApp) =>
|
|
app.page.getByRole("button", { name: "Save", exact: true });
|
|
|
|
test.describe("hwaccel args widget @medium", () => {
|
|
test("global resolved preset shows Preset, Auto saves the literal auto", async ({
|
|
frigateApp,
|
|
}) => {
|
|
const capture = await openSettings(
|
|
frigateApp,
|
|
"/settings?page=globalFfmpeg",
|
|
);
|
|
|
|
await expect(
|
|
radio(frigateApp, "root_hwaccel_args", "preset"),
|
|
).toBeChecked();
|
|
await radio(frigateApp, "root_hwaccel_args", "auto").click();
|
|
await expect(
|
|
frigateApp.page.getByText("Frigate detects Nvidia or VAAPI hardware"),
|
|
).toBeVisible();
|
|
|
|
await save(frigateApp).click();
|
|
await expect
|
|
.poll(capture.saved, { timeout: 5_000 })
|
|
.toMatchObject({ config_data: { ffmpeg: { hwaccel_args: "auto" } } });
|
|
});
|
|
|
|
test("global Disabled saves an empty list", async ({ frigateApp }) => {
|
|
const capture = await openSettings(
|
|
frigateApp,
|
|
"/settings?page=globalFfmpeg",
|
|
);
|
|
|
|
await radio(frigateApp, "root_hwaccel_args", "disabled").click();
|
|
await save(frigateApp).click();
|
|
await expect
|
|
.poll(capture.saved, { timeout: 5_000 })
|
|
.toMatchObject({ config_data: { ffmpeg: { hwaccel_args: [] } } });
|
|
});
|
|
|
|
test("global empty list shows Disabled", async ({ frigateApp }) => {
|
|
await openSettings(frigateApp, "/settings?page=globalFfmpeg", {
|
|
ffmpeg: { hwaccel_args: [] },
|
|
});
|
|
|
|
await expect(
|
|
radio(frigateApp, "root_hwaccel_args", "disabled"),
|
|
).toBeChecked();
|
|
});
|
|
|
|
test("global empty string shows Disabled", async ({ frigateApp }) => {
|
|
await openSettings(frigateApp, "/settings?page=globalFfmpeg", {
|
|
ffmpeg: { hwaccel_args: "" },
|
|
});
|
|
|
|
await expect(
|
|
radio(frigateApp, "root_hwaccel_args", "disabled"),
|
|
).toBeChecked();
|
|
await expect(frigateApp.page.getByText(MANUAL_WARNING)).toHaveCount(0);
|
|
});
|
|
|
|
test("clearing manual args keeps Manual selected", async ({ frigateApp }) => {
|
|
await openSettings(frigateApp, "/settings?page=globalFfmpeg", {
|
|
ffmpeg: { hwaccel_args: "-hwaccel vaapi" },
|
|
});
|
|
|
|
const manual = radio(frigateApp, "root_hwaccel_args", "manual");
|
|
await expect(manual).toBeChecked();
|
|
await frigateApp.page.locator('input[id="root_hwaccel_args"]').fill("");
|
|
|
|
await expect(manual).toBeChecked();
|
|
await expect(manualInput(frigateApp)).toHaveValue("");
|
|
});
|
|
|
|
test("saved Disabled switches to Manual and saves typed args", async ({
|
|
frigateApp,
|
|
}) => {
|
|
const capture = await openSettings(
|
|
frigateApp,
|
|
"/settings?page=globalFfmpeg",
|
|
{ ffmpeg: { hwaccel_args: [] } },
|
|
);
|
|
|
|
const manual = radio(frigateApp, "root_hwaccel_args", "manual");
|
|
await manual.click();
|
|
await expect(manual).toBeChecked();
|
|
await manualInput(frigateApp).fill("-hwaccel none");
|
|
await expect(manual).toBeChecked();
|
|
|
|
await save(frigateApp).click();
|
|
await expect.poll(capture.saved, { timeout: 5_000 }).toMatchObject({
|
|
config_data: { ffmpeg: { hwaccel_args: "-hwaccel none" } },
|
|
});
|
|
});
|
|
|
|
test("Preset then Disabled then Manual stays on Manual", async ({
|
|
frigateApp,
|
|
}) => {
|
|
await openSettings(frigateApp, "/settings?page=globalFfmpeg");
|
|
|
|
await radio(frigateApp, "root_hwaccel_args", "disabled").click();
|
|
const manual = radio(frigateApp, "root_hwaccel_args", "manual");
|
|
await manual.click();
|
|
|
|
await expect(manual).toBeChecked();
|
|
await expect(manualInput(frigateApp)).toHaveValue("");
|
|
});
|
|
|
|
test("Auto then Manual starts with an empty box", async ({ frigateApp }) => {
|
|
await openSettings(frigateApp, "/settings?page=globalFfmpeg");
|
|
|
|
await radio(frigateApp, "root_hwaccel_args", "auto").click();
|
|
const manual = radio(frigateApp, "root_hwaccel_args", "manual");
|
|
await manual.click();
|
|
|
|
await expect(manual).toBeChecked();
|
|
await expect(manualInput(frigateApp)).toHaveValue("");
|
|
});
|
|
|
|
test("switching back to Manual shows the saved manual args", async ({
|
|
frigateApp,
|
|
}) => {
|
|
await openSettings(frigateApp, "/settings?page=globalFfmpeg", {
|
|
ffmpeg: { hwaccel_args: "-hwaccel vaapi" },
|
|
});
|
|
|
|
const manual = radio(frigateApp, "root_hwaccel_args", "manual");
|
|
for (const from of ["preset", "disabled", "auto"]) {
|
|
await radio(frigateApp, "root_hwaccel_args", from).click();
|
|
await manual.click();
|
|
|
|
await expect(manual).toBeChecked();
|
|
await expect(manualInput(frigateApp)).toHaveValue("-hwaccel vaapi");
|
|
}
|
|
});
|
|
|
|
test("Disabled keeps the side-by-side layout", async ({ frigateApp }) => {
|
|
test.skip(frigateApp.isMobile, "the layout stacks on narrow screens");
|
|
await openSettings(frigateApp, "/settings?page=globalFfmpeg");
|
|
|
|
const label = frigateApp.page
|
|
.getByText("Hardware acceleration arguments", { exact: true })
|
|
.first();
|
|
const auto = radio(frigateApp, "root_hwaccel_args", "auto");
|
|
const before = await auto.boundingBox();
|
|
|
|
await radio(frigateApp, "root_hwaccel_args", "disabled").click();
|
|
await expect(
|
|
radio(frigateApp, "root_hwaccel_args", "disabled"),
|
|
).toBeChecked();
|
|
|
|
const labelBox = await label.boundingBox();
|
|
const after = await auto.boundingBox();
|
|
expect(after!.x).toBeGreaterThan(labelBox!.x + labelBox!.width);
|
|
expect(after!.x).toBeCloseTo(before!.x, 0);
|
|
});
|
|
|
|
test("camera Disabled overrides the global preset", async ({
|
|
frigateApp,
|
|
}) => {
|
|
const capture = await openSettings(
|
|
frigateApp,
|
|
"/settings?page=cameraFfmpeg&camera=front_door",
|
|
);
|
|
|
|
await expect(
|
|
radio(frigateApp, "root_hwaccel_args", "inherit"),
|
|
).toBeChecked();
|
|
await expect(radio(frigateApp, "root_hwaccel_args", "auto")).toHaveCount(0);
|
|
|
|
await radio(frigateApp, "root_hwaccel_args", "disabled").click();
|
|
await save(frigateApp).click();
|
|
await expect.poll(capture.saved, { timeout: 5_000 }).toMatchObject({
|
|
config_data: {
|
|
cameras: { front_door: { ffmpeg: { hwaccel_args: [] } } },
|
|
},
|
|
});
|
|
});
|
|
|
|
test("camera with an explicit empty list shows Disabled", async ({
|
|
frigateApp,
|
|
}) => {
|
|
await openSettings(
|
|
frigateApp,
|
|
"/settings?page=cameraFfmpeg&camera=front_door",
|
|
{ cameras: { front_door: { ffmpeg: { hwaccel_args: [] } } } },
|
|
);
|
|
|
|
await expect(
|
|
radio(frigateApp, "root_hwaccel_args", "disabled"),
|
|
).toBeChecked();
|
|
});
|
|
|
|
test("camera with an empty string shows Disabled", async ({ frigateApp }) => {
|
|
await openSettings(
|
|
frigateApp,
|
|
"/settings?page=cameraFfmpeg&camera=front_door",
|
|
{ cameras: { front_door: { ffmpeg: { hwaccel_args: "" } } } },
|
|
);
|
|
|
|
await expect(
|
|
radio(frigateApp, "root_hwaccel_args", "disabled"),
|
|
).toBeChecked();
|
|
await expect(
|
|
frigateApp.page.getByText("Frigate detects Nvidia or VAAPI hardware"),
|
|
).toHaveCount(0);
|
|
});
|
|
|
|
test("camera saved Disabled switches to Preset", async ({ frigateApp }) => {
|
|
await openSettings(
|
|
frigateApp,
|
|
"/settings?page=cameraFfmpeg&camera=front_door",
|
|
{ cameras: { front_door: { ffmpeg: { hwaccel_args: [] } } } },
|
|
);
|
|
|
|
const preset = radio(frigateApp, "root_hwaccel_args", "preset");
|
|
await preset.click();
|
|
|
|
await expect(preset).toBeChecked();
|
|
await expect(
|
|
frigateApp.page.locator('button[id="root_hwaccel_args"]'),
|
|
).toContainText("VAAPI");
|
|
});
|
|
|
|
test("a mode choice does not follow to another camera", async ({
|
|
frigateApp,
|
|
}) => {
|
|
await openSettings(
|
|
frigateApp,
|
|
"/settings?page=cameraFfmpeg&camera=front_door",
|
|
);
|
|
|
|
// Both cameras hold the global preset, so only the key separates them.
|
|
const preset = radio(frigateApp, "root_hwaccel_args", "preset");
|
|
await preset.click();
|
|
await expect(preset).toBeChecked();
|
|
await frigateApp.page
|
|
.getByRole("button", { name: "Select a camera" })
|
|
.click();
|
|
await frigateApp.page.getByRole("switch", { name: "Backyard" }).click();
|
|
|
|
await expect(
|
|
radio(frigateApp, "root_hwaccel_args", "inherit"),
|
|
).toBeChecked();
|
|
});
|
|
|
|
test("camera Disabled then Inherit leaves nothing to save", async ({
|
|
frigateApp,
|
|
}) => {
|
|
await openSettings(
|
|
frigateApp,
|
|
"/settings?page=cameraFfmpeg&camera=front_door",
|
|
);
|
|
|
|
const inherit = radio(frigateApp, "root_hwaccel_args", "inherit");
|
|
await expect(inherit).toBeChecked();
|
|
await radio(frigateApp, "root_hwaccel_args", "disabled").click();
|
|
await expect(save(frigateApp)).toBeEnabled();
|
|
await inherit.click();
|
|
|
|
await expect(inherit).toBeChecked();
|
|
await expect(save(frigateApp)).toBeDisabled();
|
|
});
|
|
|
|
test("global export Same as FFmpeg saves auto without the detect hint", async ({
|
|
frigateApp,
|
|
}) => {
|
|
const capture = await openSettings(
|
|
frigateApp,
|
|
"/settings?page=globalRecording",
|
|
);
|
|
|
|
await frigateApp.page
|
|
.getByRole("button", { name: /Advanced/ })
|
|
.first()
|
|
.click();
|
|
const sameAsFfmpeg = radio(frigateApp, "root_export_hwaccel_args", "auto");
|
|
await expect(
|
|
frigateApp.page.getByText("Same as FFmpeg hardware acceleration"),
|
|
).toBeVisible();
|
|
await sameAsFfmpeg.click();
|
|
await expect(sameAsFfmpeg).toBeChecked();
|
|
await expect(
|
|
frigateApp.page.getByText("Frigate detects Nvidia or VAAPI hardware"),
|
|
).toHaveCount(0);
|
|
|
|
await save(frigateApp).click();
|
|
await expect.poll(capture.saved, { timeout: 5_000 }).toMatchObject({
|
|
config_data: { record: { export: { hwaccel_args: "auto" } } },
|
|
});
|
|
});
|
|
|
|
test("camera export following a Disabled camera shows Inherit", async ({
|
|
frigateApp,
|
|
}) => {
|
|
await openSettings(
|
|
frigateApp,
|
|
"/settings?page=cameraRecording&camera=front_door",
|
|
{
|
|
cameras: {
|
|
front_door: {
|
|
ffmpeg: { hwaccel_args: [] },
|
|
record: { export: { hwaccel_args: [] } },
|
|
},
|
|
},
|
|
},
|
|
);
|
|
|
|
await frigateApp.page
|
|
.getByRole("button", { name: /Advanced/ })
|
|
.first()
|
|
.click();
|
|
await expect(
|
|
radio(frigateApp, "root_export_hwaccel_args", "inherit"),
|
|
).toBeChecked();
|
|
});
|
|
});
|