Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gstreamer shadow capture #3750

Closed
totaam opened this issue Jan 29, 2023 · 9 comments
Closed

gstreamer shadow capture #3750

totaam opened this issue Jan 29, 2023 · 9 comments
Labels
enhancement New feature or request server shadow

Comments

@totaam
Copy link
Collaborator

totaam commented Jan 29, 2023

Based on #3706, provide a codec we can use with a gstreamer pipeline to capture the display(s) via gstreamer.
This should work for:

Main difficulty is going to be the integration of events with the pull interface currently used by the base shadow server class.

Later on we can consider doing the whole pipeline in gstreamer, which will be a lot quicker than extracting the data (assuming we can even get zerocopy buffers out of GStreamer via appsink) then compressing it in xpra... Downside is that we no longer control the encoder flow rate.

@totaam totaam added enhancement New feature or request server shadow labels Jan 29, 2023
totaam added a commit that referenced this issue Jan 29, 2023
@ehfd
Copy link

ehfd commented Jan 30, 2023

MS Windows: dx9screencapsrc or gdiscreencapsrc

For Windows, you should use d3d11screencapturesrc. Both others are officially legacy. Not sure about Mac.

totaam added a commit that referenced this issue Feb 3, 2023
@totaam
Copy link
Collaborator Author

totaam commented Feb 3, 2023

@ehfd yes, that's the one I meant.
gdi, we might as well use our existing capture code and dx9 offers nothing that d3d11 does not have - I have kept it in anyway but I don't think it will be used.

So far, this seems to work pretty well, just needs more work:

  • pass display options to the capture factory, so users can specify what to capture: which monitor / geometry (and try window handle?)
  • there's a bug: the pipeline isn't stopped when the last client disconnects, wasting huge amounts of CPU
  • we set the capture framerate when creating the pipeline, which is not what we want with xpra: we want a pull model, not a push one! (not easy to fix AFAICT)

Perhaps we should use the same gstreamer pipeline for compression (at least as an option) - if that gives us some zero-copy benefits.
We would then lose all sorts of benefits exclusive to xpra, like video region detection, scroll encoding, etc.. but may be worth it when a hardware video encoder is available.

totaam added a commit that referenced this issue Feb 5, 2023
@totaam
Copy link
Collaborator Author

totaam commented Feb 7, 2023

We now have the ability to screencast existing (wayland / X11) desktop sessions that support org.freedesktop.portal.ScreenCast - via gstreamer / pipewire.
Running xpra shadow should now capture the wayland desktop session / monitor selected.

To get a full remote wayland desktop (#387), we need a lot more APIs from org.freedesktop.portal.RemoteDesktop or libei

totaam added a commit that referenced this issue May 10, 2023
totaam added a commit that referenced this issue May 11, 2023
for both the plain encoder and the capture-and-encode one,
also try to find a common encoding, not just 'h264' every time,
expose the 'profile' and other key attributes to the client
@totaam
Copy link
Collaborator Author

totaam commented May 11, 2023

The difficulty is generating pipelines that:

pipeline warning: Internal GStreamer error: code not implemented.  Please file a bug at https://gitlab.freedesktop.org/gstreamer/gstreamer/issues/new.
                   ../gst-libs/gst/video/gstvideofilter.c(296)
                    gst_video_filter_transform ()
                    /GstPipeline
                   pipeline8/GstVideoConvert
                   videoconvert0
invalid video buffer received

It's not clear which buffer uses what format - GST_DEBUG=4 didn't help.


Other issues:

  • framerate - perhaps use a videorate element and tune it based on packet acks?
  • don't use video mode if mmap is available!
  • add option to enable the video mode with x11 shadow server via ximagesrc, using syntax like xpra shadow :100,stream=true?
  • propagate settings and client options: bitrate, b-frames?, fps
  • enable error-resiliency flags when quic is used: quic transport #3376
  • colorspace is wrong - nesting the view shows it is too dark
  • x264enc doesn't honour the quality we set? (no such problems with our own x264 encoder..)
  • handle client decoding errors by restarting the pipeline and / or changing to a different / safer encoder?
  • the pipelines take time to start - perhaps send a start-of-stream draw packet to the client?

Here are some useful links to tune this further:

capsfilter caps=video/x-raw(memory:DMABuf),max-framerate=%F/1 ! \
             glupload ! glcolorconvert ! gldownload ! \
             queue ! \
             vp8enc cpu-used=16 max-quantizer=17 deadline=1 keyframe-mode=disabled threads=%T static-threshold=1000 buffer-size=20000 ! \
             queue ! \
             webmmux
capsfilter caps=video/x-raw,max-framerate=%F/1 ! \
             videoconvert chroma-mode=none dither=none matrix-mode=output-only n-threads=%T ! \
             queue ! \
             vp8enc cpu-used=16 max-quantizer=17 deadline=1 keyframe-mode=disabled threads=%T static-threshold=1000 buffer-size=20000 ! \
             queue ! \
             webmmux

We don't need the muxer, or the queue?

videoconvert !
queue leaky=2 !
x264enc threads={} tune=zerolatency speed-preset=2 bframes=0 !
video/x-h264,profile=high !
queue !
rtph264pay name=pay0 pt=96",
  • other projects hardcode pipelines similar to: pipewiresrc do-timestamp=true ! vaapipostproc ! queue ! vaapih264enc

@ehfd
Copy link

ehfd commented Aug 4, 2023

@totaam Our configuration for the encoder isn't really optimized. Any findings on your side?

@totaam
Copy link
Collaborator Author

totaam commented Aug 4, 2023

@ehfd not yet optimized either: #3706 (comment)
The current thinking is that some kind of manual setup / testing / validation may be needed to get the best out of hardware encoders because of the amount of variation there is between OS / drivers / GPUs / ...
We will try to make it easier to do that.

@ehfd
Copy link

ehfd commented Aug 4, 2023

@m1k1o Adding Neko to the discussion.

@totaam
Copy link
Collaborator Author

totaam commented Jul 5, 2024

5963153 disables d3d11 capture when running under VirtualBox.

@totaam
Copy link
Collaborator Author

totaam commented Jul 5, 2024

Will follow up in #4284

@totaam totaam closed this as completed Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request server shadow
Projects
None yet
Development

No branches or pull requests

2 participants