add more debug to diagnose h264
This commit is contained in:
@@ -449,6 +449,8 @@ func HandleCommand(ctx context.Context, env *runtime.Env, envelope map[string]in
|
||||
payload, _ := envelope["payload"].(map[string]interface{})
|
||||
quality := 90
|
||||
codec := ""
|
||||
reason := ""
|
||||
source := ""
|
||||
if payload != nil {
|
||||
if q, ok := payloadInt(payload, "quality"); ok {
|
||||
quality = q
|
||||
@@ -456,8 +458,18 @@ func HandleCommand(ctx context.Context, env *runtime.Env, envelope map[string]in
|
||||
if v, ok := payload["codec"].(string); ok {
|
||||
codec = v
|
||||
}
|
||||
if v, ok := payload["reason"].(string); ok {
|
||||
reason = strings.TrimSpace(v)
|
||||
}
|
||||
if v, ok := payload["source"].(string); ok {
|
||||
source = strings.TrimSpace(v)
|
||||
}
|
||||
}
|
||||
if source != "" || reason != "" {
|
||||
log.Printf("desktop: set quality=%d codec=%s source=%s reason=%s", quality, codec, source, reason)
|
||||
} else {
|
||||
log.Printf("desktop: set quality=%d codec=%s", quality, codec)
|
||||
}
|
||||
capture.SetQualityAndCodec(quality, codec)
|
||||
sendCommandResultSafe(env, cmdID, true, "")
|
||||
return nil
|
||||
|
||||
@@ -486,18 +486,44 @@ import { encodeMsgpack, decodeMsgpack } from "./msgpack-helpers.js";
|
||||
h264TimestampUs = 0;
|
||||
}
|
||||
|
||||
function normalizeFallbackReason(reason) {
|
||||
if (!reason) return "unspecified";
|
||||
if (typeof reason === "string") return reason;
|
||||
if (reason instanceof Error) return reason.message || String(reason);
|
||||
if (typeof reason === "object") {
|
||||
if (typeof reason.message === "string" && reason.message) {
|
||||
return reason.message;
|
||||
}
|
||||
if (typeof reason.name === "string" && reason.name) {
|
||||
return reason.name;
|
||||
}
|
||||
try {
|
||||
return JSON.stringify(reason);
|
||||
} catch {
|
||||
return String(reason);
|
||||
}
|
||||
}
|
||||
return String(reason);
|
||||
}
|
||||
|
||||
function fallbackToJpegCodec(reason) {
|
||||
if (!prefersH264) return;
|
||||
const reasonText = normalizeFallbackReason(reason);
|
||||
prefersH264 = false;
|
||||
h264LowFpsStreak = 0;
|
||||
destroyVideoDecoder();
|
||||
if (codecH264) codecH264.checked = false;
|
||||
localStorage.setItem(codecPrefKey, "0");
|
||||
console.warn("rd: falling back to jpeg codec", reason || "");
|
||||
console.warn("rd: falling back to jpeg codec", reasonText);
|
||||
const q = Number(qualitySlider?.value) || 90;
|
||||
setCodecModeLabel("jpeg", "fallback");
|
||||
if (ws.readyState === WebSocket.OPEN) {
|
||||
sendCmd("desktop_set_quality", { quality: q, codec: "jpeg" });
|
||||
sendCmd("desktop_set_quality", {
|
||||
quality: q,
|
||||
codec: "jpeg",
|
||||
source: "viewer_fallback",
|
||||
reason: reasonText,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -260,12 +260,23 @@ export function handleRemoteDesktopViewerMessage(ws: ServerWebSocket<SocketData>
|
||||
case "desktop_set_quality": {
|
||||
const newQuality = Number(payload.quality) || 90;
|
||||
const newCodec = String(payload.codec || "").toLowerCase();
|
||||
const reason = typeof payload.reason === "string"
|
||||
? payload.reason.slice(0, 512)
|
||||
: "";
|
||||
const source = typeof payload.source === "string"
|
||||
? payload.source.slice(0, 128)
|
||||
: "";
|
||||
if (state.quality !== newQuality || state.codec !== newCodec) {
|
||||
sendDesktopCommand(target, "desktop_set_quality", { quality: newQuality, codec: newCodec });
|
||||
sendDesktopCommand(target, "desktop_set_quality", {
|
||||
quality: newQuality,
|
||||
codec: newCodec,
|
||||
...(reason ? { reason } : {}),
|
||||
...(source ? { source } : {}),
|
||||
});
|
||||
state.quality = newQuality;
|
||||
state.codec = newCodec;
|
||||
rdStreamingState.set(clientId, state);
|
||||
logger.debug(`[rd] set quality=${newQuality} codec=${newCodec || "(default)"}`);
|
||||
logger.debug(`[rd] set quality=${newQuality} codec=${newCodec || "(default)"}${source ? ` source=${source}` : ""}${reason ? ` reason=${reason}` : ""}`);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user