Blame SOURCES/0001-vnc-pipewire-stream-Handle-stride-mismatch.patch

359730
From 78c5bcb181fe2b0b9fc17eea696feac8b504df54 Mon Sep 17 00:00:00 2001
359730
From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
359730
Date: Thu, 7 May 2020 15:48:22 +0200
359730
Subject: [PATCH] vnc/pipewire-stream: Handle stride mismatch
359730
359730
The VNC server framebuffer assumes a particular stride; but there is no
359730
guarantee that we'll get the same from PipeWire. Handle this gracefully
359730
by coping row by row instead of the whole buffer.
359730
---
359730
 src/grd-vnc-pipewire-stream.c | 23 +++++++++++++++--------
359730
 1 file changed, 15 insertions(+), 8 deletions(-)
359730
359730
diff --git a/src/grd-vnc-pipewire-stream.c b/src/grd-vnc-pipewire-stream.c
359730
index 88c07be..261292a 100644
359730
--- a/src/grd-vnc-pipewire-stream.c
359730
+++ b/src/grd-vnc-pipewire-stream.c
359730
@@ -187,8 +187,6 @@ on_stream_param_changed (void                 *user_data,
359730
   struct spa_pod_builder pod_builder;
359730
   int width;
359730
   int height;
359730
-  int stride;
359730
-  int size;
359730
   const struct spa_pod *params[3];
359730
 
359730
   if (!format || id != SPA_PARAM_Format)
359730
@@ -203,14 +201,9 @@ on_stream_param_changed (void                 *user_data,
359730
 
359730
   grd_session_vnc_queue_resize_framebuffer (stream->session, width, height);
359730
 
359730
-  stride = grd_session_vnc_get_framebuffer_stride (stream->session);
359730
-  size = stride * height;
359730
-
359730
   params[0] = spa_pod_builder_add_object (
359730
     &pod_builder,
359730
     SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers,
359730
-    SPA_PARAM_BUFFERS_size, SPA_POD_Int (size),
359730
-    SPA_PARAM_BUFFERS_stride, SPA_POD_Int (stride),
359730
     SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int (8, 1, 8),
359730
     0);
359730
 
359730
@@ -319,6 +312,10 @@ process_buffer (GrdVncPipeWireStream *stream,
359730
   size_t size;
359730
   uint8_t *map;
359730
   void *src_data;
359730
+  int src_stride;
359730
+  int dst_stride;
359730
+  int height;
359730
+  int y;
359730
   struct spa_meta_cursor *spa_meta_cursor;
359730
   g_autofree GrdVncFrame *frame = NULL;
359730
 
359730
@@ -359,7 +356,17 @@ process_buffer (GrdVncPipeWireStream *stream,
359730
       return NULL;
359730
     }
359730
 
359730
-  frame->data = g_memdup (src_data, buffer->datas[0].maxsize);
359730
+  src_stride = buffer->datas[0].chunk->stride;
359730
+  dst_stride = grd_session_vnc_get_framebuffer_stride (stream->session);
359730
+  height = stream->spa_format.size.height;
359730
+
359730
+  frame->data = g_malloc (height * dst_stride);
359730
+  for (y = 0; y < height; y++)
359730
+    {
359730
+      memcpy (((uint8_t *) frame->data) + y * dst_stride,
359730
+              ((uint8_t *) src_data) + y * src_stride,
359730
+              dst_stride);
359730
+    }
359730
 
359730
   if (map)
359730
     {
359730
-- 
359730
2.26.2
359730