From nobody Fri Dec 19 08:06:31 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1744977615096193.90673125972376; Fri, 18 Apr 2025 05:00:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u5jvT-0005VV-1u; Fri, 18 Apr 2025 07:30:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u5jvO-0005SS-Py for qemu-devel@nongnu.org; Fri, 18 Apr 2025 07:30:28 -0400 Received: from [94.136.29.99] (helo=zilli.proxmox.com) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u5jvD-0005nT-Cz for qemu-devel@nongnu.org; Fri, 18 Apr 2025 07:30:26 -0400 Received: by zilli.proxmox.com (Postfix, from userid 1000) id 366791C1682; Fri, 18 Apr 2025 13:29:58 +0200 (CEST) From: Dietmar Maurer To: marcandre.lureau@redhat.com, qemu-devel@nongnu.org Cc: Dietmar Maurer Subject: [PATCH v3 5/9] h264: new vnc option to configure h264 at server side Date: Fri, 18 Apr 2025 13:29:49 +0200 Message-Id: <20250418112953.1744442-6-dietmar@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250418112953.1744442-1-dietmar@proxmox.com> References: <20250418112953.1744442-1-dietmar@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 94.136.29.99 (failed) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=94.136.29.99; envelope-from=dietmar@zilli.proxmox.com; helo=zilli.proxmox.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, NO_DNS_FOR_FROM=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1744977617684019100 Content-Type: text/plain; charset="utf-8" Values can be 'on', 'off', or a space sparated list of allowed gstreamer encoders. - on: automatically select the encoder - off: disbale h264 - encoder-list: select first available encoder from that list. Signed-off-by: Dietmar Maurer --- ui/vnc-enc-h264.c | 30 ++++++++++++++++++++++-------- ui/vnc.c | 25 ++++++++++++++++++++----- ui/vnc.h | 6 +++++- 3 files changed, 47 insertions(+), 14 deletions(-) diff --git a/ui/vnc-enc-h264.c b/ui/vnc-enc-h264.c index 047f4a3128..0f89cafbf6 100644 --- a/ui/vnc-enc-h264.c +++ b/ui/vnc-enc-h264.c @@ -27,13 +27,21 @@ =20 #include =20 -const char *encoder_list[] =3D { "x264enc", "openh264enc", NULL }; - -static const char *get_available_encoder(void) +static char *get_available_encoder(const char *encoder_list) { + g_assert(encoder_list !=3D NULL); + + if (!strcmp(encoder_list, "")) { + /* use default list */ + encoder_list =3D "x264enc openh264enc"; + } + + char *ret =3D NULL; + char **encoder_array =3D g_strsplit(encoder_list, " ", -1); + int i =3D 0; do { - const char *encoder_name =3D encoder_list[i]; + const char *encoder_name =3D encoder_array[i]; if (encoder_name =3D=3D NULL) { break; } @@ -41,12 +49,15 @@ static const char *get_available_encoder(void) encoder_name, "video-encoder"); if (element !=3D NULL) { gst_object_unref(element); - return encoder_name; + ret =3D strdup(encoder_name); + break; } i =3D i + 1; } while (true); =20 - return NULL; + g_strfreev(encoder_array); + + return ret; } =20 static GstElement *create_encoder(const char *encoder_name) @@ -220,11 +231,13 @@ static bool create_encoder_context(VncState *vs, int = w, int h) =20 bool vnc_h264_encoder_init(VncState *vs) { - const char *encoder_name; + char *encoder_name; =20 g_assert(vs->h264 =3D=3D NULL); + g_assert(vs->vd !=3D NULL); + g_assert(vs->vd->h264_encoder_list !=3D NULL); =20 - encoder_name =3D get_available_encoder(); + encoder_name =3D get_available_encoder(vs->vd->h264_encoder_list); if (encoder_name =3D=3D NULL) { VNC_DEBUG("No H264 encoder available.\n"); return -1; @@ -336,6 +349,7 @@ void vnc_h264_clear(VncState *vs) } =20 destroy_encoder_context(vs); + g_free(vs->h264->encoder_name); =20 g_clear_pointer(&vs->h264, g_free); } diff --git a/ui/vnc.c b/ui/vnc.c index badc7912c0..feab4c0043 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -2190,11 +2190,11 @@ static void set_encodings(VncState *vs, int32_t *en= codings, size_t n_encodings) break; #ifdef CONFIG_GSTREAMER case VNC_ENCODING_H264: - if (vnc_h264_encoder_init(vs)) { - vnc_set_feature(vs, VNC_FEATURE_H264); - vs->vnc_encoding =3D enc; - } else { - VNC_DEBUG("vnc_h264_encoder_init failed\n"); + if (vs->vd->h264_encoder_list !=3D NULL) { /* if h264 is enabl= ed */ + if (vnc_h264_encoder_init(vs)) { + vnc_set_feature(vs, VNC_FEATURE_H264); + vs->vnc_encoding =3D enc; + } } break; #endif @@ -3634,6 +3634,9 @@ static QemuOptsList qemu_vnc_opts =3D { },{ .name =3D "power-control", .type =3D QEMU_OPT_BOOL, + },{ + .name =3D "h264", + .type =3D QEMU_OPT_STRING, }, { /* end of list */ } }, @@ -4196,6 +4199,18 @@ void vnc_display_open(const char *id, Error **errp) } #endif =20 +#ifdef CONFIG_GSTREAMER + const char *h264_opt =3D qemu_opt_get(opts, "h264"); + if (!strcmp(h264_opt, "off")) { + vd->h264_encoder_list =3D NULL; /* disable h264 */ + } else if (!strcmp(h264_opt, "on")) { + vd->h264_encoder_list =3D ""; /* use default encoder list */ + } else { + /* assume this is a list of endiers */ + vd->h264_encoder_list =3D h264_opt; + } +#endif + if (vnc_display_setup_auth(&vd->auth, &vd->subauth, vd->tlscreds, password, sasl, false, errp) < 0) { diff --git a/ui/vnc.h b/ui/vnc.h index e97276349e..789b18806b 100644 --- a/ui/vnc.h +++ b/ui/vnc.h @@ -188,6 +188,10 @@ struct VncDisplay VncDisplaySASL sasl; #endif =20 +#ifdef CONFIG_GSTREAMER + const char *h264_encoder_list; +#endif + AudioState *audio_state; }; =20 @@ -239,7 +243,7 @@ typedef struct VncZywrle { /* Number of frames we send after the display is clean. */ #define VNC_H264_KEEP_DIRTY 10 typedef struct VncH264 { - const char *encoder_name; + char *encoder_name; GstElement *pipeline, *source, *gst_encoder, *sink, *convert; size_t width; size_t height; --=20 2.39.5