From 7af8bb93c2cc8358722f2d6ecb97de6fab806599 Mon Sep 17 00:00:00 2001 From: AAA <35992542+TNTcraftHIM@users.noreply.github.com> Date: Fri, 21 Aug 2026 03:01:21 +0800 Subject: [PATCH] fix(native): report the active codec --- native/sender/internal/app/ui/app.js | 12 ++++++++++-- tests/native-hardware-status.test.ts | 5 +++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/native/sender/internal/app/ui/app.js b/native/sender/internal/app/ui/app.js index a5a8ffc..fa71672 100644 --- a/native/sender/internal/app/ui/app.js +++ b/native/sender/internal/app/ui/app.js @@ -193,6 +193,7 @@ async function connectMediaSocket(generation, codec, audio) { } async function startEncoder(generation, codec) { + metrics.codec = codec; const preferred = { codec: codec === "h264" ? "avc1.42c01f" : "vp8", width: WIDTH, @@ -218,7 +219,9 @@ async function startEncoder(generation, codec) { metrics.hardwarePreference = HARDWARE_STATUS.PREFERENCE_ACCEPTED; } metrics.hardwareEvidence = HARDWARE_STATUS.UNVERIFIED; - if (!support.supported) throw new Error("此设备不支持 VP8 720p30 编码"); + if (!support.supported) { + throw new Error(`此设备不支持 ${codecLabel(codec)} 720p30 编码`); + } let activeEncoder; activeEncoder = new VideoEncoder({ output: (chunk) => sendEncodedChunk(generation, activeEncoder, chunk), @@ -592,7 +595,7 @@ function updateDiagnostics() { const height = captureSettings?.height ?? "未知"; const rate = captureSettings?.frameRate ?? "未知"; elements.captureDiagnostic.textContent = `${width} × ${height} · ${rate} FPS`; - elements.encoderDiagnostic.textContent = `VP8 · 3 Mbps 上限 · 单对象 · 硬件偏好 ${hardwarePreferenceLabel(metrics.hardwarePreference)} · 硬件证据 ${hardwareEvidenceLabel(metrics.hardwareEvidence)}`; + elements.encoderDiagnostic.textContent = `${codecLabel(metrics.codec)} · 3 Mbps 上限 · 单对象 · 硬件偏好 ${hardwarePreferenceLabel(metrics.hardwarePreference)} · 硬件证据 ${hardwareEvidenceLabel(metrics.hardwareEvidence)}`; elements.bridgeDiagnostic.textContent = `读取 ${metrics.framesRead} · 提交 ${metrics.framesSubmitted} · 输出 ${metrics.encoderOutputs} · 编码队列丢弃 ${metrics.encoderQueueDrops} · 编码队列峰值 ${metrics.encoderQueuePeak} 帧 · socket 峰值 ${metrics.socketBufferedPeak} B`; const helper = nativeDiagnostics?.media; const queue = helper?.queue; @@ -647,6 +650,7 @@ function selectedCodec() { function emptyMetrics() { return { + codec: "vp8", framesRead: 0, framesSubmitted: 0, encoderOutputs: 0, @@ -659,6 +663,10 @@ function emptyMetrics() { }; } +function codecLabel(codec) { + return codec === "h264" ? "H.264" : "VP8"; +} + function hardwarePreferenceLabel(value) { return { [HARDWARE_STATUS.UNREQUESTED]: "未请求", diff --git a/tests/native-hardware-status.test.ts b/tests/native-hardware-status.test.ts index 95e5ceb..5427c53 100644 --- a/tests/native-hardware-status.test.ts +++ b/tests/native-hardware-status.test.ts @@ -38,6 +38,11 @@ describe("native sender hardware preference contract", () => { expect(senderHTML).toContain(''); expect(senderUI).toContain('elements.codec?.value === "h264" ? "h264" : "vp8"'); expect(senderUI).toContain('codec: codec === "h264" ? "avc1.42c01f" : "vp8"'); + expect(senderUI).toContain("metrics.codec = codec"); + expect(senderUI).toContain("codecLabel(metrics.codec)"); + expect(senderUI).toContain("codecLabel(codec)"); + expect(senderUI).not.toContain("此设备不支持 VP8 720p30 编码"); + expect(senderUI).not.toContain("`VP8 · 3 Mbps 上限"); expect(senderUI).toContain("encoderInstances: 1"); expect(senderUI).toContain("HARDWARE_STATUS.PREFERENCE_ACCEPTED"); expect(senderUI).toContain("HARDWARE_STATUS.FALLBACK");