Skip to content

Instantly share code, notes, and snippets.

@sayap
Last active August 30, 2022 07:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sayap/f343bff7700d45b555aea7e581097314 to your computer and use it in GitHub Desktop.
Save sayap/f343bff7700d45b555aea7e581097314 to your computer and use it in GitHub Desktop.
diff --git a/src/plugins/screencast/screencaststream.cpp b/src/plugins/screencast/screencaststream.cpp
index 6f25b563a..a38261e9e 100644
--- a/src/plugins/screencast/screencaststream.cpp
+++ b/src/plugins/screencast/screencaststream.cpp
@@ -107,13 +107,17 @@ void ScreenCastStream::newStreamParams()
SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta,
SPA_PARAM_META_type, SPA_POD_Id(SPA_META_VideoDamage),
SPA_PARAM_META_size, SPA_POD_CHOICE_RANGE_Int(sizeof(struct spa_meta_region) * videoDamageRegionCount, sizeof(struct spa_meta_region) * 1, sizeof(struct spa_meta_region) * videoDamageRegionCount)),
+ (spa_pod *)spa_pod_builder_add_object(&pod_builder,
+ SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta,
+ SPA_PARAM_META_type, SPA_POD_Id(SPA_META_VideoCrop),
+ SPA_PARAM_META_size, SPA_POD_Int(sizeof(struct spa_meta_region))),
(spa_pod *)spa_pod_builder_add_object(&pod_builder,
SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta,
SPA_PARAM_META_type, SPA_POD_Id(SPA_META_Header),
SPA_PARAM_META_size, SPA_POD_Int(sizeof(struct spa_meta_header))),
};
- pw_stream_update_params(pwStream, params, 4);
+ pw_stream_update_params(pwStream, params, 5);
}
void ScreenCastStream::onStreamParamChanged(void *data, uint32_t id, const struct spa_pod *format)
@@ -446,6 +450,7 @@ void ScreenCastStream::recordFrame(const QRegion &damagedRegion)
addDamage(spa_buffer, damagedRegion | QRect({0, 0}, size));
addHeader(spa_buffer);
+ addVideoCrop(spa_buffer);
tryEnqueue(buffer);
}
@@ -465,6 +470,17 @@ void ScreenCastStream::addHeader(spa_buffer *spaBuffer)
}
}
+void ScreenCastStream::addVideoCrop(spa_buffer *spaBuffer)
+{
+ spa_meta_region *spaVideoCrop = (spa_meta_region *)spa_buffer_find_meta_data(spaBuffer, SPA_META_VideoCrop, sizeof(spaVideoCrop));
+ if (spaVideoCrop) {
+ spaVideoCrop->region.position.x = 0;
+ spaVideoCrop->region.position.y = 0;
+ spaVideoCrop->region.size.width = m_resolution.width();
+ spaVideoCrop->region.size.height = m_resolution.height();
+ }
+}
+
void ScreenCastStream::addDamage(spa_buffer *spaBuffer, const QRegion &damagedRegion)
{
if (spa_meta *vdMeta = spa_buffer_find_meta(spaBuffer, SPA_META_VideoDamage)) {
@@ -525,6 +541,7 @@ void ScreenCastStream::recordCursor()
sendCursorData(Cursors::self()->currentCursor(),
(spa_meta_cursor *)spa_buffer_find_meta_data(spa_buffer, SPA_META_Cursor, sizeof(spa_meta_cursor)));
addHeader(spa_buffer);
+ addVideoCrop(spa_buffer);
addDamage(spa_buffer, {});
enqueue();
}
diff --git a/src/plugins/screencast/screencaststream.h b/src/plugins/screencast/screencaststream.h
index 872d01b02..6dbf755f3 100644
--- a/src/plugins/screencast/screencaststream.h
+++ b/src/plugins/screencast/screencaststream.h
@@ -80,6 +80,7 @@ private:
void coreFailed(const QString &errorMessage);
void sendCursorData(Cursor *cursor, spa_meta_cursor *spa_cursor);
void addHeader(spa_buffer *spaBuffer);
+ void addVideoCrop(spa_buffer *spaBuffer);
void addDamage(spa_buffer *spaBuffer, const QRegion &damagedRegion);
void newStreamParams();
void tryEnqueue(pw_buffer *buffer);
@kanwarplaha
Copy link

kanwarplaha commented Jul 18, 2022

Hi, not a newbie but not an expert either. Is this a patch for kwin? Do I have to download the entire kwin source code, apply this patch, and then build it?

If you can explain a bit more that would help with zoom + wayland + KDE + screenshare.

Forgot to add that I'd like to try this on Ubintu/Debian based systems :)

Thanks.

@sayap
Copy link
Author

sayap commented Jul 19, 2022

Correct, you have to download kwin source (v5.25.3, either source tarball or git tag), apply the patch, and then use cmake to build and install.

Not sure what's the best way to do this on Ubuntu/Debian. On Gentoo, it is as simple as putting the .diff into directory /etc/portage/patches/kde-plasma/kwin-5.25.3 😀

@kanwarplaha
Copy link

kanwarplaha commented Jul 19, 2022

Thanks @sayap. I may also boot into Arch and try. Just haven't got to gentoo yet though have tried it few times 😄 🐧

Btw, are you sharing this diff patch with Kwin team upstream too?

@kanwarplaha
Copy link

Hey @sayap have another question. I am going to download a gentoo-based distribution, MocaccinoOS and try your patch. So I'd like to know that after applying the patch to kwin, do I need any special settings in Zoom or environment for wayland + screensharing to work?

Thanks.

@sayap
Copy link
Author

sayap commented Jul 20, 2022

Zoom has this silly check about the distribution, so I also have this:

# cat /etc/os-release
NAME="Manjaro Linux"
ID=manjaro
PRETTY_NAME="Manjaro Linux"
ANSI_COLOR="1;32"
HOME_URL="https://www.gentoo.org/"
SUPPORT_URL="https://www.gentoo.org/support/"
BUG_REPORT_URL="https://bugs.gentoo.org/"`

Then, you just need to start zoom with:

$ XDG_CURRENT_DESKTOP=gnome zoom

and wayland + screensharing should work fine.

@kanwarplaha
Copy link

kanwarplaha commented Jul 20, 2022 via email

@kanwarplaha
Copy link

kanwarplaha commented Jul 22, 2022

Hey @sayap I actually recompiled kwin on openSUSE and patched screencaststream.cpp and screencaststream.h as per your diff.

Then, I ran "XDG_CURRENT_DESKTOP=gnome zoom". As openSUSE is one of the "supported" distros for zoom, I didn't have to change /etc/os-release.

However, although I can now see the KDE specific share window that lists all screens etc, when shared it still shows a blank (black) screen to the participant(s).

Checking systemctl status I can see that xdg-desktop-portal-kde has started streaming:
Jul 22 18:26:56 xxxxxx xdg-desktop-portal-kde[6697]: start streaming Stream(QMap(("size", QVariant(QSize, QSize(3840, 2400)))("source_type", QVariant(uint, 1))), 107) QPoint(583,2160)

Not sure what else I might be missing :)

What can I share from my system if you can help me get it working?

Thanks!

@kanwarplaha
Copy link

Well, funny story :)

After sharing the screen once with "blank" share, if I click "New Share" from the zoom toolbar and select the same source, it works. How crazy is that?

Btw, the same behaviour is seen when sharing from Zoom PWA as well i.e.

  1. Click Share screen in Zoom
  2. The KDE share screen appears
  3. Select a source and click Share
  4. There's a second KDE share screen window that appears
  5. Select a source and click Share
  6. Now it works

I guess there's still a glitch somewhere, possibly between plasma-xdg-desktop-portal and Zoom requesting a stream to share, but it works for now with this repetitive steps that I must take.

If you have any insight, that would be awesome.

Cheers.

@sayap
Copy link
Author

sayap commented Jul 22, 2022

Heh, interesting. I did experience once where initially the receiving side only got a blank black screen, but once the sending side started to do something on the shared window (e.g. scrolling), then the receiving side can see the shared window.

No idea about the glitch you experienced, but good to know that you found a workaround, as crazy as it is :)

Is Zoom PWA the same thing as Zoom web? With Zoom web, there are indeed multiple share screen prompts, firstly from the browser, and then from KDE. Wayland screen sharing with Zoom web has been working for quite some time already, but my whole chromium browser would freeze for minutes intermittently when doing that. The Zoom web experience is generally worse anyway, so 🤷‍♂️

Currently, I have:

  • patched kwin 5.25.3
  • xdg-desktop-portal-kde 5.25.3
  • xdg-desktop-portal 1.14.5 (just upgraded, 1.14.4 works fine too)
  • pipewire 0.3.56 (just upgraded, was using pipewire-0.3.55-r1 with some cherry-picked fixes from gentoo official repo)

@kanwarplaha
Copy link

kanwarplaha commented Jul 22, 2022 via email

@kanwarplaha
Copy link

kanwarplaha commented Jul 22, 2022 via email

@Indomitable
Copy link

Hey is this patch submitted as PR to kwin?

@sayap
Copy link
Author

sayap commented Aug 30, 2022

I think this patch is no longer necessary with Zoom 5.11.9.

@kanwarplaha
Copy link

That's right! I tested on 5.11.10 (latest update) and it works .... except for the odd case of zoom toolbar showing in the middle of the screen 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment