From b2c1763197fad0eb22e8dc0b3ee126ce27a997e3 Mon Sep 17 00:00:00 2001 From: Michael Scherle Date: Mon, 1 Sep 2025 09:09:20 +0200 Subject: [PATCH] gstreamer-encoder: Fix DMA-BUF file descriptor duplication and improve logging format --- server/dcc-send.cpp | 2 +- server/gstreamer-encoder.c | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/server/dcc-send.cpp b/server/dcc-send.cpp index 31c37dc6..56002d71 100644 --- a/server/dcc-send.cpp +++ b/server/dcc-send.cpp @@ -1807,7 +1807,7 @@ static void red_marshall_gl_draw_stream(DisplayChannelClient *dcc, delete dmabuf_data; return; } - dmabuf_data->drm_dma_buf_fd[i] = scanout->fd[i]; + dmabuf_data->drm_dma_buf_fd[i] = dup(scanout->fd[i]); dmabuf_data->stride[i] = (int)scanout->stride[i]; dmabuf_data->offset[i] = (size_t)scanout->offset[i]; } diff --git a/server/gstreamer-encoder.c b/server/gstreamer-encoder.c index 95c12a47..c8e3fdea 100644 --- a/server/gstreamer-encoder.c +++ b/server/gstreamer-encoder.c @@ -991,7 +991,7 @@ static const gchar *get_encode_gpu(){ static gchar *find_best_hw_plugin(const gchar *codec_name) { - char plugins[][20] = {"msdk", "va", "vaapi"}; + char plugins[][20] = {"va","msdk", "vaapi"}; gchar *feature_name; int i; const gchar *encode_gpu = get_encode_gpu(); @@ -1006,7 +1006,7 @@ static gchar *find_best_hw_plugin(const gchar *codec_name) return feature_name; } g_free(feature_name); - if(i == 1 && codec_name){ + if(codec_name){ feature_name = g_strconcat(plugins[i], codec_name, "lpenc", NULL); if (gst_features_lookup(feature_name)) { return feature_name; @@ -1723,10 +1723,11 @@ spice_gst_encoder_configure_pipeline(SpiceGstEncoder *encoder, encoder->spice_format != spice_format || encoder->drm_format != drm_format) && (width > 0 && height > 0)) { spice_debug("video format change: width %d -> %d, height %d -> %d," - "spice format %d -> %d, drm format %u -> %u", + "spice format %d -> %d, drm format %u -> %u, gst-format %s -> %s", encoder->width, width, encoder->height, height, encoder->spice_format, spice_format, - encoder->drm_format, drm_format); + encoder->drm_format, drm_format, gst_video_format_to_string(encoder->format->gst_format), + gst_video_format_to_string(format->gst_format)); encoder->format = format; encoder->spice_format = spice_format; @@ -1865,17 +1866,15 @@ spice_gst_encoder_encode_dmabuf(VideoEncoder *video_encoder, for (int i = 0; i < dmabuf_data->num_planes; i++) { gsize size = dmabuf_data->stride[i] * dmabuf_data->height; GstMemory *mem - = gst_dmabuf_allocator_alloc_with_flags(encoder->allocator, + = gst_dmabuf_allocator_alloc(encoder->allocator, dmabuf_data->drm_dma_buf_fd[i], - size, - GST_FD_MEMORY_FLAG_DONT_CLOSE); + size); if (!mem) { gst_buffer_unref(buffer); return rc; } gst_buffer_append_memory(buffer, mem); } - gst_buffer_add_video_meta_full(buffer, GST_VIDEO_FRAME_FLAG_NONE, encoder->format->gst_format,