mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-12-02 18:27:08 +03:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1c056d11c8 |
@@ -12,17 +12,11 @@ import NavPath from "@site/src/components/NavPath";
|
||||
|
||||
It is highly recommended to use an integrated or discrete GPU for hardware acceleration video decoding in Frigate.
|
||||
|
||||
Some types of hardware acceleration are detected and used automatically, but you may need to update your configuration to enable hardware accelerated decoding in ffmpeg.
|
||||
|
||||
By default (**Auto** in the UI, `hwaccel_args: auto` in YAML), Frigate uses `preset-nvidia` if an Nvidia GPU is usable, otherwise `preset-vaapi` if VAAPI is usable, otherwise no hardware acceleration. Other presets, including Intel QuickSync, must be set explicitly.
|
||||
|
||||
To verify that hardware acceleration is working:
|
||||
Some types of hardware acceleration are detected and used automatically, but you may need to update your configuration to enable hardware accelerated decoding in ffmpeg. To verify that hardware acceleration is working:
|
||||
|
||||
- Check the logs: A message will either say that hardware acceleration was automatically detected, or there will be a warning that no hardware acceleration was automatically detected
|
||||
- If hardware acceleration is specified in the config, verification can be done by ensuring the logs are free from errors. There is no CPU fallback for hardware acceleration.
|
||||
|
||||
To turn hardware decoding off, set **Hardware acceleration arguments** to **Disabled** in the UI, or `hwaccel_args: []` in YAML.
|
||||
|
||||
Frigate supports presets for optimal hardware accelerated video decoding:
|
||||
|
||||
**AMD**
|
||||
|
||||
Vendored
+34
-28
@@ -4346,7 +4346,7 @@ paths:
|
||||
security:
|
||||
- frigateAdminAuth: []
|
||||
x-required-role: admin
|
||||
/notices/{notice_id}/acknowledge:
|
||||
/notices/acknowledge:
|
||||
post:
|
||||
tags:
|
||||
- Notices
|
||||
@@ -4358,14 +4358,13 @@ paths:
|
||||
|
||||
Config and stream check rows and the update notice never repeat, so they
|
||||
can only be muted.
|
||||
operationId: acknowledge_notice_notices__notice_id__acknowledge_post
|
||||
parameters:
|
||||
- name: notice_id
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
title: Notice Id
|
||||
operationId: acknowledge_notice_notices_acknowledge_post
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/NoticeIdBody'
|
||||
responses:
|
||||
'200':
|
||||
description: Successful Response
|
||||
@@ -4381,7 +4380,7 @@ paths:
|
||||
security:
|
||||
- frigateAdminAuth: []
|
||||
x-required-role: admin
|
||||
/notices/{notice_id}/mute:
|
||||
/notices/mute:
|
||||
post:
|
||||
tags:
|
||||
- Notices
|
||||
@@ -4390,14 +4389,13 @@ paths:
|
||||
**Access:** Admin role required.
|
||||
|
||||
Hide a notice or a config or stream check row for good.
|
||||
operationId: mute_notice_notices__notice_id__mute_post
|
||||
parameters:
|
||||
- name: notice_id
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
title: Notice Id
|
||||
operationId: mute_notice_notices_mute_post
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/NoticeIdBody'
|
||||
responses:
|
||||
'200':
|
||||
description: Successful Response
|
||||
@@ -4413,8 +4411,8 @@ paths:
|
||||
security:
|
||||
- frigateAdminAuth: []
|
||||
x-required-role: admin
|
||||
/notices/{notice_id}/hidden:
|
||||
delete:
|
||||
/notices/unhide:
|
||||
post:
|
||||
tags:
|
||||
- Notices
|
||||
summary: Unhide Notice
|
||||
@@ -4422,14 +4420,13 @@ paths:
|
||||
**Access:** Admin role required.
|
||||
|
||||
Show an acknowledged or muted notice or check row again.
|
||||
operationId: unhide_notice_notices__notice_id__hidden_delete
|
||||
parameters:
|
||||
- name: notice_id
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
title: Notice Id
|
||||
operationId: unhide_notice_notices_unhide_post
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/NoticeIdBody'
|
||||
responses:
|
||||
'200':
|
||||
description: Successful Response
|
||||
@@ -9324,6 +9321,15 @@ components:
|
||||
- status
|
||||
title: MotionSearchStatusResponse
|
||||
description: Response containing job status and results.
|
||||
NoticeIdBody:
|
||||
properties:
|
||||
id:
|
||||
type: string
|
||||
title: Notice or check row id
|
||||
type: object
|
||||
required:
|
||||
- id
|
||||
title: NoticeIdBody
|
||||
PlaybackSourceEnum:
|
||||
type: string
|
||||
enum:
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class NoticeIdBody(BaseModel):
|
||||
id: str = Field(title="Notice or check row id")
|
||||
+13
-11
@@ -6,6 +6,7 @@ from fastapi import APIRouter, Depends, Request
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from frigate.api.auth import require_role
|
||||
from frigate.api.defs.request.notice_body import NoticeIdBody
|
||||
from frigate.api.defs.tags import Tags
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -48,18 +49,19 @@ def unhide_all_notices(request: Request) -> JSONResponse:
|
||||
return JSONResponse(content={"success": True, "message": "Notices shown again"})
|
||||
|
||||
|
||||
# model notice ids contain a slash, so the id is a path parameter
|
||||
# the id goes in the body because nginx merges slashes and resolves dot segments
|
||||
# in the path after decoding it
|
||||
@router.post(
|
||||
"/notices/{notice_id:path}/acknowledge",
|
||||
"/notices/acknowledge",
|
||||
dependencies=[Depends(require_role(["admin"]))],
|
||||
)
|
||||
def acknowledge_notice(request: Request, notice_id: str) -> JSONResponse:
|
||||
def acknowledge_notice(request: Request, body: NoticeIdBody) -> JSONResponse:
|
||||
"""Hide a notice until it happens again.
|
||||
|
||||
Config and stream check rows and the update notice never repeat, so they
|
||||
can only be muted.
|
||||
"""
|
||||
if not request.app.notice_registry.acknowledge(notice_id):
|
||||
if not request.app.notice_registry.acknowledge(body.id):
|
||||
return JSONResponse(
|
||||
content={"success": False, "message": "Notice not found"},
|
||||
status_code=404,
|
||||
@@ -69,12 +71,12 @@ def acknowledge_notice(request: Request, notice_id: str) -> JSONResponse:
|
||||
|
||||
|
||||
@router.post(
|
||||
"/notices/{notice_id:path}/mute",
|
||||
"/notices/mute",
|
||||
dependencies=[Depends(require_role(["admin"]))],
|
||||
)
|
||||
def mute_notice(request: Request, notice_id: str) -> JSONResponse:
|
||||
def mute_notice(request: Request, body: NoticeIdBody) -> JSONResponse:
|
||||
"""Hide a notice or a config or stream check row for good."""
|
||||
if not request.app.notice_registry.mute(notice_id):
|
||||
if not request.app.notice_registry.mute(body.id):
|
||||
return JSONResponse(
|
||||
content={"success": False, "message": "Notice not found"},
|
||||
status_code=404,
|
||||
@@ -83,13 +85,13 @@ def mute_notice(request: Request, notice_id: str) -> JSONResponse:
|
||||
return JSONResponse(content={"success": True, "message": "Notice muted"})
|
||||
|
||||
|
||||
@router.delete(
|
||||
"/notices/{notice_id:path}/hidden",
|
||||
@router.post(
|
||||
"/notices/unhide",
|
||||
dependencies=[Depends(require_role(["admin"]))],
|
||||
)
|
||||
def unhide_notice(request: Request, notice_id: str) -> JSONResponse:
|
||||
def unhide_notice(request: Request, body: NoticeIdBody) -> JSONResponse:
|
||||
"""Show an acknowledged or muted notice or check row again."""
|
||||
if not request.app.notice_registry.unhide(notice_id):
|
||||
if not request.app.notice_registry.unhide(body.id):
|
||||
return JSONResponse(
|
||||
content={"success": False, "message": "Notice not found"},
|
||||
status_code=404,
|
||||
|
||||
@@ -59,7 +59,9 @@ class TestHttpNotices(BaseTestHttp):
|
||||
)
|
||||
|
||||
with self.client() as client:
|
||||
response = client.post("/notices/detector_stuck:ov/acknowledge")
|
||||
response = client.post(
|
||||
"/notices/acknowledge", json={"id": "detector_stuck:ov"}
|
||||
)
|
||||
listed = client.get("/notices").json()
|
||||
hidden = client.get("/notices", params={"include_hidden": True}).json()
|
||||
|
||||
@@ -70,7 +72,7 @@ class TestHttpNotices(BaseTestHttp):
|
||||
|
||||
def test_acknowledging_a_check_is_404(self):
|
||||
with self.client() as client:
|
||||
response = client.post(f"/notices/{CONFIG_CHECK}/acknowledge")
|
||||
response = client.post("/notices/acknowledge", json={"id": CONFIG_CHECK})
|
||||
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
@@ -81,32 +83,49 @@ class TestHttpNotices(BaseTestHttp):
|
||||
|
||||
with self.client() as client:
|
||||
response = client.post(
|
||||
"/notices/model_download_failed:yolo/model.onnx/mute"
|
||||
"/notices/mute", json={"id": "model_download_failed:yolo/model.onnx"}
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(self.registry.active(), [])
|
||||
|
||||
def test_ids_that_path_handling_would_mangle(self):
|
||||
scopes = ["zmq:tcp://wildcat-test:5555", "openvino:GPU#2", "a/../b?c%2F"]
|
||||
for scope in scopes:
|
||||
self.registry.raise_notice("detector_stuck", scope=scope, params={})
|
||||
|
||||
with self.client() as client:
|
||||
responses = [
|
||||
client.post(
|
||||
"/notices/acknowledge", json={"id": f"detector_stuck:{scope}"}
|
||||
)
|
||||
for scope in scopes
|
||||
]
|
||||
|
||||
self.assertEqual([r.status_code for r in responses], [200] * 3)
|
||||
self.assertEqual(self.registry.active(), [])
|
||||
|
||||
def test_unknown_ids_are_404(self):
|
||||
with self.client() as client:
|
||||
responses = [
|
||||
client.post("/notices/nope/acknowledge"),
|
||||
client.post("/notices/nope/mute"),
|
||||
client.delete("/notices/nope/hidden"),
|
||||
client.post("/notices/acknowledge", json={"id": "nope"}),
|
||||
client.post("/notices/mute", json={"id": "nope"}),
|
||||
client.post("/notices/unhide", json={"id": "nope"}),
|
||||
]
|
||||
|
||||
self.assertEqual([r.status_code for r in responses], [404, 404, 404])
|
||||
|
||||
def test_requires_admin(self):
|
||||
viewer = {"remote-user": "viewer", "remote-role": "viewer"}
|
||||
ov = {"id": "detector_stuck:ov"}
|
||||
|
||||
with TestClient(self.app) as client:
|
||||
responses = [
|
||||
client.get("/notices", headers=viewer),
|
||||
client.get("/notices/muted_checks", headers=viewer),
|
||||
client.post("/notices/detector_stuck:ov/acknowledge", headers=viewer),
|
||||
client.post("/notices/detector_stuck:ov/mute", headers=viewer),
|
||||
client.delete("/notices/detector_stuck:ov/hidden", headers=viewer),
|
||||
client.post("/notices/acknowledge", json=ov, headers=viewer),
|
||||
client.post("/notices/mute", json=ov, headers=viewer),
|
||||
client.post("/notices/unhide", json=ov, headers=viewer),
|
||||
client.delete("/notices/hidden", headers=viewer),
|
||||
]
|
||||
|
||||
@@ -114,8 +133,8 @@ class TestHttpNotices(BaseTestHttp):
|
||||
|
||||
def test_muted_checks_are_listed_once(self):
|
||||
with self.client() as client:
|
||||
first = client.post(f"/notices/{CONFIG_CHECK}/mute")
|
||||
again = client.post(f"/notices/{CONFIG_CHECK}/mute")
|
||||
first = client.post("/notices/mute", json={"id": CONFIG_CHECK})
|
||||
again = client.post("/notices/mute", json={"id": CONFIG_CHECK})
|
||||
listed = client.get("/notices/muted_checks").json()
|
||||
hidden = client.get("/notices", params={"include_hidden": True}).json()
|
||||
|
||||
@@ -134,8 +153,8 @@ class TestHttpNotices(BaseTestHttp):
|
||||
self.registry.mute(CONFIG_CHECK)
|
||||
|
||||
with self.client() as client:
|
||||
notice = client.delete("/notices/detector_stuck:ov/hidden")
|
||||
check = client.delete(f"/notices/{CONFIG_CHECK}/hidden")
|
||||
notice = client.post("/notices/unhide", json={"id": "detector_stuck:ov"})
|
||||
check = client.post("/notices/unhide", json={"id": CONFIG_CHECK})
|
||||
listed = client.get("/notices").json()
|
||||
checks = client.get("/notices/muted_checks").json()
|
||||
|
||||
|
||||
@@ -1,382 +0,0 @@
|
||||
/**
|
||||
* 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();
|
||||
});
|
||||
});
|
||||
@@ -57,12 +57,12 @@ const EVENT_NOTICE = {
|
||||
muted_at: null,
|
||||
};
|
||||
|
||||
// a repeated device gets a '#2' suffix, which a raw URL would cut off as a fragment
|
||||
const SUFFIXED_NOTICE = {
|
||||
// nginx would merge the slashes if this id went in the URL path
|
||||
const ZMQ_NOTICE = {
|
||||
...EVENT_NOTICE,
|
||||
id: "detector_stuck:openvino:GPU#2",
|
||||
scope: "openvino:GPU#2",
|
||||
params: { detector: "openvino:GPU#2" },
|
||||
id: "detector_stuck:zmq:tcp://host:5555",
|
||||
scope: "zmq:tcp://host:5555",
|
||||
params: { detector: "zmq:tcp://host:5555" },
|
||||
};
|
||||
|
||||
test.describe("System — Health tab @medium", () => {
|
||||
@@ -103,17 +103,17 @@ test.describe("System — Health tab @medium", () => {
|
||||
|
||||
for (const action of ["acknowledge", "mute"] as const) {
|
||||
test(`${action} posts and removes the row`, async ({ frigateApp }) => {
|
||||
const path = `/api/notices/${encodeURIComponent(SUFFIXED_NOTICE.id)}/${action}`;
|
||||
const path = `/api/notices/${action}`;
|
||||
await frigateApp.installDefaults({
|
||||
config: RESTREAMED,
|
||||
stats: QUIET_STATS,
|
||||
notices: [SUFFIXED_NOTICE],
|
||||
notices: [ZMQ_NOTICE],
|
||||
});
|
||||
|
||||
// the list shrinks after the POST so the refetch shows the row gone
|
||||
let hidden = false;
|
||||
await frigateApp.page.route("**/api/notices", (route) =>
|
||||
route.fulfill({ json: hidden ? [] : [SUFFIXED_NOTICE] }),
|
||||
route.fulfill({ json: hidden ? [] : [ZMQ_NOTICE] }),
|
||||
);
|
||||
await frigateApp.page.route(
|
||||
(url) => url.pathname.endsWith(path),
|
||||
@@ -126,10 +126,12 @@ test.describe("System — Health tab @medium", () => {
|
||||
await frigateApp.goto("/system#health");
|
||||
const request = frigateApp.page.waitForRequest(
|
||||
(req) =>
|
||||
new URL(req.url()).pathname.endsWith(path) && req.method() === "POST",
|
||||
new URL(req.url()).pathname.endsWith(path) &&
|
||||
req.method() === "POST" &&
|
||||
req.postDataJSON()?.id === ZMQ_NOTICE.id,
|
||||
);
|
||||
await frigateApp.page
|
||||
.getByTestId(`health-problem-notice:${SUFFIXED_NOTICE.id}`)
|
||||
.getByTestId(`health-problem-notice:${ZMQ_NOTICE.id}`)
|
||||
.getByRole("button", {
|
||||
name: action === "mute" ? "Mute" : "Acknowledge",
|
||||
exact: true,
|
||||
@@ -272,7 +274,7 @@ test.describe("System — Health tab @medium", () => {
|
||||
url.searchParams.get("include_hidden") === "true",
|
||||
(route) => route.fulfill({ json: [MUTED_NOTICE] }),
|
||||
);
|
||||
const path = `/api/notices/${encodeURIComponent(MUTED_NOTICE.id)}/hidden`;
|
||||
const path = "/api/notices/unhide";
|
||||
await frigateApp.page.route(
|
||||
(url) => url.pathname.endsWith(path),
|
||||
(route) => route.fulfill({ json: { success: true } }),
|
||||
@@ -285,7 +287,9 @@ test.describe("System — Health tab @medium", () => {
|
||||
|
||||
const request = frigateApp.page.waitForRequest(
|
||||
(req) =>
|
||||
new URL(req.url()).pathname.endsWith(path) && req.method() === "DELETE",
|
||||
new URL(req.url()).pathname.endsWith(path) &&
|
||||
req.method() === "POST" &&
|
||||
req.postDataJSON()?.id === MUTED_NOTICE.id,
|
||||
);
|
||||
await frigateApp.page
|
||||
.getByTestId(
|
||||
@@ -1356,7 +1360,7 @@ test.describe("System — Health notices sources @medium", () => {
|
||||
|
||||
// the list gains the mute after the POST so the refetch hides the row
|
||||
let muted = false;
|
||||
const path = `/api/notices/${encodeURIComponent(id)}/mute`;
|
||||
const path = "/api/notices/mute";
|
||||
await frigateApp.page.route(
|
||||
(url) => url.pathname.endsWith(path),
|
||||
(route) => {
|
||||
@@ -1376,7 +1380,9 @@ test.describe("System — Health notices sources @medium", () => {
|
||||
);
|
||||
const request = frigateApp.page.waitForRequest(
|
||||
(req) =>
|
||||
new URL(req.url()).pathname.endsWith(path) && req.method() === "POST",
|
||||
new URL(req.url()).pathname.endsWith(path) &&
|
||||
req.method() === "POST" &&
|
||||
req.postDataJSON()?.id === id,
|
||||
);
|
||||
await row.getByRole("button", { name: "Mute", exact: true }).click();
|
||||
await request;
|
||||
|
||||
@@ -1608,10 +1608,6 @@
|
||||
"manual": "Manual arguments",
|
||||
"inherit": "Inherit from camera setting",
|
||||
"none": "None",
|
||||
"auto": "Auto",
|
||||
"autoDescription": "Frigate detects Nvidia or VAAPI hardware. After saving, this field shows the detected preset, or Disabled if none is found. Other hardware needs a preset.",
|
||||
"disabled": "Disabled",
|
||||
"sameAsFfmpeg": "Same as FFmpeg hardware acceleration",
|
||||
"sameAsRecord": "Same as record output arguments",
|
||||
"useGlobalSetting": "Inherit from global setting",
|
||||
"selectPreset": "Select preset",
|
||||
|
||||
@@ -15,8 +15,6 @@ const ffmpegArgsWidget = (
|
||||
"ui:widget": "FfmpegArgsWidget",
|
||||
"ui:options": {
|
||||
suppressMultiSchema: true,
|
||||
// A list value renders through a different anyOf branch and layout
|
||||
forceSplitLayout: true,
|
||||
ffmpegPresetField: presetField,
|
||||
...extraOptions,
|
||||
},
|
||||
@@ -25,6 +23,7 @@ const ffmpegArgsWidget = (
|
||||
const recordSubArgsWidget = () =>
|
||||
ffmpegArgsWidget("output_args.record_sub", {
|
||||
allowInherit: true,
|
||||
forceSplitLayout: true,
|
||||
unsetLabelKey: "configForm.ffmpegArgs.sameAsRecord",
|
||||
});
|
||||
|
||||
@@ -46,9 +45,7 @@ const ffmpeg: SectionConfigOverrides = {
|
||||
return value.length > 0;
|
||||
}
|
||||
if (typeof value === "string") {
|
||||
return (
|
||||
value !== "" && value !== "auto" && !value.startsWith("preset-")
|
||||
);
|
||||
return !value.startsWith("preset-");
|
||||
}
|
||||
return false;
|
||||
},
|
||||
@@ -149,11 +146,13 @@ const ffmpeg: SectionConfigOverrides = {
|
||||
hwaccel_args: ffmpegArgsWidget("hwaccel_args", {
|
||||
allowInherit: true,
|
||||
hideDescription: true,
|
||||
forceSplitLayout: true,
|
||||
showArrayItemDescription: true,
|
||||
}),
|
||||
input_args: ffmpegArgsWidget("input_args", {
|
||||
allowInherit: true,
|
||||
hideDescription: true,
|
||||
forceSplitLayout: true,
|
||||
showArrayItemDescription: true,
|
||||
}),
|
||||
output_args: {
|
||||
|
||||
@@ -87,11 +87,8 @@ const record: SectionConfigOverrides = {
|
||||
"ui:widget": "FfmpegArgsWidget",
|
||||
"ui:options": {
|
||||
suppressMultiSchema: true,
|
||||
forceSplitLayout: true,
|
||||
ffmpegPresetField: "hwaccel_args",
|
||||
ffmpegGlobalFieldPath: "export.hwaccel_args",
|
||||
unsetLabelKey: "configForm.ffmpegArgs.sameAsFfmpeg",
|
||||
cameraFallbackPath: "ffmpeg.hwaccel_args",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { WidgetProps } from "@rjsf/utils";
|
||||
import useSWR from "swr";
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import get from "lodash/get";
|
||||
import isEqual from "lodash/isEqual";
|
||||
@@ -24,15 +24,7 @@ type FfmpegPresetResponse = {
|
||||
};
|
||||
};
|
||||
|
||||
type FfmpegArgsMode =
|
||||
"preset" | "manual" | "inherit" | "none" | "auto" | "disabled";
|
||||
|
||||
// RJSF remounts the widget when the value flips between a string and a list,
|
||||
// so the user's mode choice lives outside the component. It applies only
|
||||
// while the value is still the one it was made for, so a save or undo that
|
||||
// changes the value hands the mode back to detection.
|
||||
const chosenModes = new Map<string, { mode: FfmpegArgsMode; value: unknown }>();
|
||||
const chosenModeClears = new Map<string, ReturnType<typeof setTimeout>>();
|
||||
type FfmpegArgsMode = "preset" | "manual" | "inherit" | "none";
|
||||
|
||||
type PresetField =
|
||||
| "hwaccel_args"
|
||||
@@ -73,26 +65,15 @@ const resolveMode = (
|
||||
presets: string[],
|
||||
defaultMode: FfmpegArgsMode,
|
||||
allowInherit: boolean,
|
||||
hwaccelModes: boolean,
|
||||
): FfmpegArgsMode => {
|
||||
if (value === null || value === undefined) {
|
||||
if (allowInherit) return "inherit";
|
||||
return hwaccelModes ? "auto" : "none";
|
||||
return allowInherit ? "inherit" : "none";
|
||||
}
|
||||
|
||||
if (allowInherit && Array.isArray(value) && value.length === 0) {
|
||||
return "inherit";
|
||||
}
|
||||
|
||||
if (hwaccelModes) {
|
||||
// An empty string is how auto-detection reports no hardware, and the
|
||||
// backend runs no hwaccel for it either way.
|
||||
if (value === "" || (Array.isArray(value) && value.length === 0)) {
|
||||
return "disabled";
|
||||
}
|
||||
if (value === "auto") return "auto";
|
||||
}
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
return "manual";
|
||||
}
|
||||
@@ -148,9 +129,6 @@ export function FfmpegArgsWidget(props: WidgetProps) {
|
||||
// while living at export.hwaccel_args inside the record section.
|
||||
const globalFieldPath =
|
||||
(options?.ffmpegGlobalFieldPath as string | undefined) ?? presetField;
|
||||
// Camera-config path the backend falls back to when this camera field is
|
||||
// unset, used alongside the global value to detect inheritance.
|
||||
const cameraFallbackPath = options?.cameraFallbackPath as string | undefined;
|
||||
const allowInherit = options?.allowInherit === true;
|
||||
const unsetLabelKey = options?.unsetLabelKey as string | undefined;
|
||||
const hideDescription = options?.hideDescription === true;
|
||||
@@ -161,11 +139,6 @@ export function FfmpegArgsWidget(props: WidgetProps) {
|
||||
const isInputScoped = id.includes("_inputs_");
|
||||
const showUseGlobalSetting = isCameraLevel && !isInputScoped && !allowInherit;
|
||||
|
||||
// Hardware acceleration offers Auto and Disabled in place of None. Auto
|
||||
// sends the literal "auto" because the form holds the resolved value, so a
|
||||
// delete could target a key that is absent from the YAML.
|
||||
const hwaccelModes = presetField === "hwaccel_args" && !allowInherit;
|
||||
|
||||
// Extract the global value for this specific field to detect inheritance
|
||||
const globalFieldValue = useMemo(() => {
|
||||
if (
|
||||
@@ -191,48 +164,21 @@ export function FfmpegArgsWidget(props: WidgetProps) {
|
||||
const canUsePresets = presetOptions.length > 0;
|
||||
const defaultMode: FfmpegArgsMode = canUsePresets ? "preset" : "manual";
|
||||
|
||||
const cameraFallbackValue = useMemo(
|
||||
() =>
|
||||
cameraFallbackPath && formContext?.fullCameraConfig
|
||||
? get(formContext.fullCameraConfig, cameraFallbackPath)
|
||||
: undefined,
|
||||
[cameraFallbackPath, formContext?.fullCameraConfig],
|
||||
);
|
||||
|
||||
// A camera value equal to what it would resolve to when unset counts as
|
||||
// inherited (i.e. the camera does not override it).
|
||||
const isInherited = useCallback(
|
||||
(candidate: unknown) => {
|
||||
if (!showUseGlobalSetting) return false;
|
||||
if (candidate === undefined || candidate === null) return true;
|
||||
return [globalFieldValue, cameraFallbackValue].some(
|
||||
(inherited) =>
|
||||
inherited !== undefined &&
|
||||
inherited !== null &&
|
||||
isEqual(candidate, inherited),
|
||||
);
|
||||
},
|
||||
[showUseGlobalSetting, globalFieldValue, cameraFallbackValue],
|
||||
);
|
||||
|
||||
const isInheritedFromGlobal = isInherited(value);
|
||||
|
||||
const savedValue =
|
||||
globalFieldPath && formContext?.baselineFormData
|
||||
? get(formContext.baselineFormData, globalFieldPath)
|
||||
: undefined;
|
||||
// Detect if this field's value is effectively inherited from the global
|
||||
// config (i.e. the camera does not override it).
|
||||
const isInheritedFromGlobal = useMemo(() => {
|
||||
if (!showUseGlobalSetting) return false;
|
||||
if (value === undefined || value === null) return true;
|
||||
if (globalFieldValue === undefined || globalFieldValue === null)
|
||||
return false;
|
||||
return isEqual(value, globalFieldValue);
|
||||
}, [showUseGlobalSetting, value, globalFieldValue]);
|
||||
|
||||
const detectedMode = useMemo(() => {
|
||||
if (showUseGlobalSetting && isInheritedFromGlobal) {
|
||||
return "inherit" as FfmpegArgsMode;
|
||||
}
|
||||
return resolveMode(
|
||||
value,
|
||||
presetOptions,
|
||||
defaultMode,
|
||||
allowInherit,
|
||||
hwaccelModes,
|
||||
);
|
||||
return resolveMode(value, presetOptions, defaultMode, allowInherit);
|
||||
}, [
|
||||
showUseGlobalSetting,
|
||||
isInheritedFromGlobal,
|
||||
@@ -240,54 +186,25 @@ export function FfmpegArgsWidget(props: WidgetProps) {
|
||||
presetOptions,
|
||||
defaultMode,
|
||||
allowInherit,
|
||||
hwaccelModes,
|
||||
]);
|
||||
|
||||
const modeKey = [
|
||||
formContext?.level,
|
||||
formContext?.cameraName,
|
||||
formContext?.sectionPath,
|
||||
formContext?.isProfile,
|
||||
id,
|
||||
].join(":");
|
||||
const [mode, setMode] = useState<FfmpegArgsMode>(detectedMode);
|
||||
|
||||
// An empty manual box is no change, so the form falls back to the saved
|
||||
// value while Manual stays chosen.
|
||||
const chosenMode = useCallback(
|
||||
(current: unknown) => {
|
||||
const chosen = chosenModes.get(modeKey);
|
||||
if (!chosen) return undefined;
|
||||
const emptyManual = chosen.mode === "manual" && chosen.value === "";
|
||||
return isEqual(chosen.value, current) ||
|
||||
(emptyManual && isEqual(current, savedValue))
|
||||
? chosen.mode
|
||||
: undefined;
|
||||
},
|
||||
[modeKey, savedValue],
|
||||
);
|
||||
// Track whether the user has explicitly changed mode to prevent the
|
||||
// detected-mode sync from snapping back (e.g. when a user-selected
|
||||
// preset happens to match the global value).
|
||||
const userSetModeRef = useRef(false);
|
||||
|
||||
// A remount mounts the replacement before the timer fires, so only leaving
|
||||
// the page clears the choice.
|
||||
const formIsClean = !formContext?.hasChanges;
|
||||
|
||||
// Reset tracking when the widget identity changes (camera switch)
|
||||
// or when the form returns to a clean state (after a successful save).
|
||||
useEffect(() => {
|
||||
clearTimeout(chosenModeClears.get(modeKey));
|
||||
return () => {
|
||||
chosenModeClears.set(
|
||||
modeKey,
|
||||
setTimeout(() => chosenModes.delete(modeKey)),
|
||||
);
|
||||
};
|
||||
}, [modeKey]);
|
||||
|
||||
const [mode, setMode] = useState<FfmpegArgsMode>(
|
||||
() => chosenMode(value) ?? detectedMode,
|
||||
);
|
||||
userSetModeRef.current = false;
|
||||
}, [id, formIsClean]);
|
||||
|
||||
useEffect(() => {
|
||||
const chosen = chosenMode(value);
|
||||
if (chosen) {
|
||||
setMode(chosen);
|
||||
return;
|
||||
}
|
||||
if (userSetModeRef.current) return;
|
||||
|
||||
if (!canUsePresets && detectedMode === "preset") {
|
||||
setMode("manual");
|
||||
@@ -295,38 +212,20 @@ export function FfmpegArgsWidget(props: WidgetProps) {
|
||||
}
|
||||
|
||||
setMode(detectedMode);
|
||||
}, [canUsePresets, chosenMode, detectedMode, value]);
|
||||
|
||||
const choose = useCallback(
|
||||
(nextMode: FfmpegArgsMode, nextValue: unknown) => {
|
||||
chosenModes.set(modeKey, { mode: nextMode, value: nextValue });
|
||||
setMode(nextMode);
|
||||
onChange(nextValue);
|
||||
},
|
||||
[modeKey, onChange],
|
||||
);
|
||||
}, [canUsePresets, detectedMode]);
|
||||
|
||||
const handleModeChange = useCallback(
|
||||
(nextMode: FfmpegArgsMode) => {
|
||||
// Restoring an inherited saved value leaves the form clean. Sending
|
||||
// undefined would delete a key that may be absent from the YAML.
|
||||
userSetModeRef.current = true;
|
||||
setMode(nextMode);
|
||||
|
||||
if (nextMode === "inherit") {
|
||||
choose(nextMode, isInherited(savedValue) ? savedValue : undefined);
|
||||
onChange(undefined);
|
||||
return;
|
||||
}
|
||||
|
||||
if (nextMode === "none") {
|
||||
choose(nextMode, undefined);
|
||||
return;
|
||||
}
|
||||
|
||||
if (nextMode === "auto") {
|
||||
choose(nextMode, "auto");
|
||||
return;
|
||||
}
|
||||
|
||||
if (nextMode === "disabled") {
|
||||
choose(nextMode, []);
|
||||
onChange(undefined);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -337,58 +236,38 @@ export function FfmpegArgsWidget(props: WidgetProps) {
|
||||
? currentValue
|
||||
: presetOptions[0];
|
||||
if (presetValue) {
|
||||
choose(nextMode, presetValue);
|
||||
} else {
|
||||
setMode(nextMode);
|
||||
onChange(presetValue);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Start from the saved manual args, if any, so a switch back to Manual
|
||||
// shows them instead of an empty box.
|
||||
if (mode === "preset" || mode === "auto" || mode === "disabled") {
|
||||
const savedIsManual =
|
||||
resolveMode(
|
||||
savedValue,
|
||||
presetOptions,
|
||||
defaultMode,
|
||||
allowInherit,
|
||||
hwaccelModes,
|
||||
) === "manual";
|
||||
choose(nextMode, savedIsManual ? normalizeManualText(savedValue) : "");
|
||||
if (mode === "preset") {
|
||||
onChange("");
|
||||
return;
|
||||
}
|
||||
|
||||
choose(nextMode, normalizeManualText(value));
|
||||
const manualText = normalizeManualText(value);
|
||||
onChange(manualText);
|
||||
},
|
||||
[
|
||||
allowInherit,
|
||||
choose,
|
||||
defaultMode,
|
||||
hwaccelModes,
|
||||
isInherited,
|
||||
mode,
|
||||
presetOptions,
|
||||
savedValue,
|
||||
value,
|
||||
],
|
||||
[mode, onChange, presetOptions, value],
|
||||
);
|
||||
|
||||
const handlePresetChange = useCallback(
|
||||
(preset: string) => choose("preset", preset),
|
||||
[choose],
|
||||
(preset: string) => {
|
||||
onChange(preset);
|
||||
},
|
||||
[onChange],
|
||||
);
|
||||
|
||||
const handleManualChange = useCallback(
|
||||
(event: React.ChangeEvent<HTMLInputElement>) =>
|
||||
choose("manual", event.target.value),
|
||||
[choose],
|
||||
(event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const newText = event.target.value;
|
||||
onChange(newText);
|
||||
},
|
||||
[onChange],
|
||||
);
|
||||
|
||||
const manualValue =
|
||||
mode === "manual" && chosenModes.get(modeKey)?.value === ""
|
||||
? ""
|
||||
: normalizeManualText(value);
|
||||
const manualValue = normalizeManualText(value);
|
||||
const presetValue =
|
||||
typeof value === "string" && presetOptions.includes(value) ? value : "";
|
||||
const fallbackDescriptionKey = useMemo(() => {
|
||||
@@ -438,48 +317,6 @@ export function FfmpegArgsWidget(props: WidgetProps) {
|
||||
? schema.description
|
||||
: translatedDescription;
|
||||
|
||||
const unsetMode: FfmpegArgsMode =
|
||||
showUseGlobalSetting || allowInherit
|
||||
? "inherit"
|
||||
: hwaccelModes
|
||||
? "auto"
|
||||
: "none";
|
||||
const unsetLabel = showUseGlobalSetting
|
||||
? t("configForm.ffmpegArgs.useGlobalSetting", { ns: "views/settings" })
|
||||
: allowInherit
|
||||
? t(unsetLabelKey ?? "configForm.ffmpegArgs.inherit", {
|
||||
ns: "views/settings",
|
||||
})
|
||||
: hwaccelModes
|
||||
? t(unsetLabelKey ?? "configForm.ffmpegArgs.auto", {
|
||||
ns: "views/settings",
|
||||
})
|
||||
: t(unsetLabelKey ?? "configForm.ffmpegArgs.none", {
|
||||
ns: "views/settings",
|
||||
});
|
||||
|
||||
const renderOption = (
|
||||
optionMode: FfmpegArgsMode,
|
||||
label: string,
|
||||
optionDisabled = false,
|
||||
) => (
|
||||
<div className="flex items-center space-x-2">
|
||||
<RadioGroupItem
|
||||
value={optionMode}
|
||||
id={`${id}-${optionMode}`}
|
||||
disabled={disabled || readonly || optionDisabled}
|
||||
className={
|
||||
mode === optionMode
|
||||
? "bg-selected from-selected/50 to-selected/90 text-selected"
|
||||
: "bg-secondary from-secondary/50 to-secondary/90 text-secondary"
|
||||
}
|
||||
/>
|
||||
<label htmlFor={`${id}-${optionMode}`} className="cursor-pointer text-sm">
|
||||
{label}
|
||||
</label>
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<RadioGroup
|
||||
@@ -487,33 +324,95 @@ export function FfmpegArgsWidget(props: WidgetProps) {
|
||||
onValueChange={(next) => handleModeChange(next as FfmpegArgsMode)}
|
||||
className="gap-3"
|
||||
>
|
||||
{renderOption(unsetMode, unsetLabel)}
|
||||
{hwaccelModes &&
|
||||
renderOption(
|
||||
"disabled",
|
||||
t("configForm.ffmpegArgs.disabled", { ns: "views/settings" }),
|
||||
)}
|
||||
{renderOption(
|
||||
"preset",
|
||||
t("configForm.ffmpegArgs.preset", { ns: "views/settings" }),
|
||||
!canUsePresets,
|
||||
)}
|
||||
{renderOption(
|
||||
"manual",
|
||||
t("configForm.ffmpegArgs.manual", { ns: "views/settings" }),
|
||||
{showUseGlobalSetting ? (
|
||||
<div className="flex items-center space-x-2">
|
||||
<RadioGroupItem
|
||||
value="inherit"
|
||||
id={`${id}-inherit`}
|
||||
disabled={disabled || readonly}
|
||||
className={
|
||||
mode === "inherit"
|
||||
? "bg-selected from-selected/50 to-selected/90 text-selected"
|
||||
: "bg-secondary from-secondary/50 to-secondary/90 text-secondary"
|
||||
}
|
||||
/>
|
||||
<label htmlFor={`${id}-inherit`} className="cursor-pointer text-sm">
|
||||
{t("configForm.ffmpegArgs.useGlobalSetting", {
|
||||
ns: "views/settings",
|
||||
})}
|
||||
</label>
|
||||
</div>
|
||||
) : allowInherit ? (
|
||||
<div className="flex items-center space-x-2">
|
||||
<RadioGroupItem
|
||||
value="inherit"
|
||||
id={`${id}-inherit`}
|
||||
disabled={disabled || readonly}
|
||||
className={
|
||||
mode === "inherit"
|
||||
? "bg-selected from-selected/50 to-selected/90 text-selected"
|
||||
: "bg-secondary from-secondary/50 to-secondary/90 text-secondary"
|
||||
}
|
||||
/>
|
||||
<label htmlFor={`${id}-inherit`} className="cursor-pointer text-sm">
|
||||
{t(unsetLabelKey ?? "configForm.ffmpegArgs.inherit", {
|
||||
ns: "views/settings",
|
||||
})}
|
||||
</label>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex items-center space-x-2">
|
||||
<RadioGroupItem
|
||||
value="none"
|
||||
id={`${id}-none`}
|
||||
disabled={disabled || readonly}
|
||||
className={
|
||||
mode === "none"
|
||||
? "bg-selected from-selected/50 to-selected/90 text-selected"
|
||||
: "bg-secondary from-secondary/50 to-secondary/90 text-secondary"
|
||||
}
|
||||
/>
|
||||
<label htmlFor={`${id}-none`} className="cursor-pointer text-sm">
|
||||
{t(unsetLabelKey ?? "configForm.ffmpegArgs.none", {
|
||||
ns: "views/settings",
|
||||
})}
|
||||
</label>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex items-center space-x-2">
|
||||
<RadioGroupItem
|
||||
value="preset"
|
||||
id={`${id}-preset`}
|
||||
disabled={disabled || readonly || !canUsePresets}
|
||||
className={
|
||||
mode === "preset"
|
||||
? "bg-selected from-selected/50 to-selected/90 text-selected"
|
||||
: "bg-secondary from-secondary/50 to-secondary/90 text-secondary"
|
||||
}
|
||||
/>
|
||||
<label htmlFor={`${id}-preset`} className="cursor-pointer text-sm">
|
||||
{t("configForm.ffmpegArgs.preset", { ns: "views/settings" })}
|
||||
</label>
|
||||
</div>
|
||||
<div className="flex items-center space-x-2">
|
||||
<RadioGroupItem
|
||||
value="manual"
|
||||
id={`${id}-manual`}
|
||||
disabled={disabled || readonly}
|
||||
className={
|
||||
mode === "manual"
|
||||
? "bg-selected from-selected/50 to-selected/90 text-selected"
|
||||
: "bg-secondary from-secondary/50 to-secondary/90 text-secondary"
|
||||
}
|
||||
/>
|
||||
<label htmlFor={`${id}-manual`} className="cursor-pointer text-sm">
|
||||
{t("configForm.ffmpegArgs.manual", { ns: "views/settings" })}
|
||||
</label>
|
||||
</div>
|
||||
</RadioGroup>
|
||||
|
||||
{mode === "auto" && !unsetLabelKey ? (
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{t("configForm.ffmpegArgs.autoDescription", {
|
||||
ns: "views/settings",
|
||||
})}
|
||||
</p>
|
||||
) : mode === "auto" ||
|
||||
mode === "inherit" ||
|
||||
mode === "none" ||
|
||||
mode === "disabled" ? null : mode === "preset" && canUsePresets ? (
|
||||
{mode === "inherit" || mode === "none" ? null : mode === "preset" &&
|
||||
canUsePresets ? (
|
||||
<Select
|
||||
value={presetValue}
|
||||
onValueChange={handlePresetChange}
|
||||
|
||||
@@ -58,7 +58,7 @@ export function useHealthProblems(
|
||||
|
||||
const muteCheck = useCallback(
|
||||
async (id: string) => {
|
||||
await axios.post(`notices/${encodeURIComponent(id)}/mute`);
|
||||
await axios.post("notices/mute", { id });
|
||||
mutateMutedChecks();
|
||||
},
|
||||
[mutateMutedChecks],
|
||||
@@ -66,7 +66,7 @@ export function useHealthProblems(
|
||||
|
||||
const unmuteCheck = useCallback(
|
||||
async (id: string) => {
|
||||
await axios.delete(`notices/${encodeURIComponent(id)}/hidden`);
|
||||
await axios.post("notices/unhide", { id });
|
||||
mutateMutedChecks();
|
||||
},
|
||||
[mutateMutedChecks],
|
||||
|
||||
@@ -60,17 +60,15 @@ export function useNotices(showHidden: boolean) {
|
||||
);
|
||||
|
||||
const acknowledge = useCallback(
|
||||
(id: string) =>
|
||||
act(axios.post(`notices/${encodeURIComponent(id)}/acknowledge`)),
|
||||
(id: string) => act(axios.post("notices/acknowledge", { id })),
|
||||
[act],
|
||||
);
|
||||
const mute = useCallback(
|
||||
(id: string) => act(axios.post(`notices/${encodeURIComponent(id)}/mute`)),
|
||||
(id: string) => act(axios.post("notices/mute", { id })),
|
||||
[act],
|
||||
);
|
||||
const unhide = useCallback(
|
||||
(id: string) =>
|
||||
act(axios.delete(`notices/${encodeURIComponent(id)}/hidden`)),
|
||||
(id: string) => act(axios.post("notices/unhide", { id })),
|
||||
[act],
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user