fix(native): report the active codec

This commit is contained in:
AAA authored and GitHub committed 2026-08-21 03:01:21 +08:00
1 parent de7426b944
commit 7af8bb93c2
2 files changed
+15 -2

No files matched your search

+10 -2
View File
@@ -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]: "未请求",
+5
View File
@@ -38,6 +38,11 @@ describe("native sender hardware preference contract", () => {
expect(senderHTML).toContain('<option value="vp8">VP8 (default)</option>');
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");