From b4474e3d76726244fbaa13e8d68d9af7becf2cd0 Mon Sep 17 00:00:00 2001 From: Rafael Gieschke Date: Mon, 14 Oct 2024 18:28:41 +0200 Subject: [PATCH] HACK: force H.264 with WebCodecs --- spice_auto.html | 14 ++++++++++++++ src/display.js | 29 +++++++++++++++++++++++++++++ src/enums.js | 4 ++-- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/spice_auto.html b/spice_auto.html index beb5b7a..2150e07 100644 --- a/spice_auto.html +++ b/spice_auto.html @@ -197,6 +197,20 @@ +
diff --git a/src/display.js b/src/display.js index f20d6b4..a6647ca 100644 --- a/src/display.js +++ b/src/display.js @@ -1204,6 +1204,35 @@ function new_video_cluster(stream, msg) function process_video_stream_data(stream, msg) { + if (stream.start_time == 0) { + const context = document.querySelector("canvas").getContext("2d"); + const decoder = stream.decoder = new VideoDecoder({ + output(frame) { + context.drawImage(frame, 0, 0, frame.displayWidth, frame.displayHeight); + frame.close(); + }, + error(v) { + console.error(v); + }, + }); + decoder.configure({ + codec: "avc1.640028", + codedWidth: 1920, + codedHeight: 1080, + optimizeForLatency: true, + avc: { + format: "annexb", + }, + }); + } + stream.decoder.decode( + new EncodedVideoChunk({ + timestamp: stream.start_time, + type: "key", + data: msg.data, + }) + ); + if (stream.start_time == 0) { stream.start_time = msg.base.multi_media_time; diff --git a/src/enums.js b/src/enums.js index db13584..879999b 100644 --- a/src/enums.js +++ b/src/enums.js @@ -196,7 +196,7 @@ export var Constants = { SPICE_DISPLAY_CAP_GL_SCANOUT : 7, SPICE_DISPLAY_CAP_MULTI_CODEC : 8, SPICE_DISPLAY_CAP_CODEC_MJPEG : 9, - SPICE_DISPLAY_CAP_CODEC_VP8 : 10, + SPICE_DISPLAY_CAP_CODEC_VP8 : 11, SPICE_AUDIO_DATA_MODE_INVALID : 0, SPICE_AUDIO_DATA_MODE_RAW : 1, @@ -332,7 +332,7 @@ export var Constants = { SPICE_CURSOR_TYPE_COLOR32 : 6, SPICE_VIDEO_CODEC_TYPE_MJPEG : 1, - SPICE_VIDEO_CODEC_TYPE_VP8 : 2, + SPICE_VIDEO_CODEC_TYPE_VP8 : 3, VD_AGENT_PROTOCOL : 1, VD_AGENT_MAX_DATA_SIZE : 2048,