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

Colorspace appears to change frequently #3837

Closed
EmanH opened this issue Apr 28, 2023 · 28 comments · Fixed by Xpra-org/xpra-html5#248
Closed

Colorspace appears to change frequently #3837

EmanH opened this issue Apr 28, 2023 · 28 comments · Fixed by Xpra-org/xpra-html5#248

Comments

@EmanH
Copy link
Contributor

EmanH commented Apr 28, 2023

I'm running a java app and launching/streaming it with xpra from within an Ubuntu 20.04/22.04 docker container (using the html5 client).

It works ok, except for a troublesome change of color depth every time we interact with the app.

See the example here: https://youtu.be/Yxq6-KH2AOc

Observe the light-blue flickering before changing to darker blue. This is something XPRA is doing. The darker blue is the true color, and the lighter blue seems to be a compressed image where some of the pixel depth information is lost maybe? It also effects light greys in other parts of the UI.

I've tried playing around with various encodings, compression settings, quality settings, with opengl, without opengl, pixel-depth settings, etc. Nothing I can try, changes this.

I've tried a couple different base docker images, current one is based on:

FROM nvidia/opengl:1.0-glvnd-runtime-ubuntu20.04

# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive \
    JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64

RUN apt-get update && \
    apt-get install -y software-properties-common apt-transport-https wget && \
    wget -qO - https://xpra.org/gpg.asc | gpg --dearmor -o /usr/share/keyrings/xpra-archive-keyring.gpg && \
    echo "deb [signed-by=/usr/share/keyrings/xpra-archive-keyring.gpg] https://xpra.org/ $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/xpra.list && \
    apt-get update && \
    apt-get install -y xpra xpra-html5 xvfb xterm libjs-jquery libjs-jquery-ui fonts-material-design-icons-iconfont && \
    apt-get clean && \ 
    rm -rf /var/lib/apt/lists/*

RUN apt-get update && \
    apt-get install -y openjdk-8-jre openjdk-8-jdk

After trying every parameter I could think of that might be relevent, I've come to the conclusion it might be an XPRA Bug.

@totaam, we'd be stoked if you could comment on what you think this might be, and any ideas we could try to resolve it? Thanks so much!

@totaam
Copy link
Collaborator

totaam commented Apr 28, 2023

Does this also happen with the python client?
Is the java application relevant here? Can you reproduce with just an image viewer showing the same picture?

@EmanH
Copy link
Contributor Author

EmanH commented May 8, 2023

@totaam I can't reproduce when streaming over a VNC connection, so I don't think the java application is relevant. Will try the python client.

@EmanH
Copy link
Contributor Author

EmanH commented May 8, 2023

Launching the application using xpra launcher from the host machine works a charm. No color depth issues. So it seems the issue relates to the HTML client. Earlier I was using v3 of XPRA and was getting a bandwidth streaming warning until switching to the latest version. Perhaps that is still the root cause.

Not sure why there would be a bandwidth issue, as everything is running on localhost. Maybe it's related to docker?

@EmanH
Copy link
Contributor Author

EmanH commented May 8, 2023

I tried running the html client from the host machine, but the color depth quality issue came back.

@totaam
Copy link
Collaborator

totaam commented May 8, 2023

from the host machine works a charm. No color depth issues

Right, so the problem is with the html5 client

Not sure why there would be a bandwidth issue, as everything is running on localhost. Maybe it's related to docker?

The bandwidth warnings show up when there are latency spikes - docker containers can end up introducing measurable latency. If connecting locally, you should be using mmap to bypass this issue.

Perhaps that is still the root cause.

Not really, only indirectly.

This sounds like the browser is decoding jpeg or webp screen updates with a different colorspace / color range than what it should be using.
What browsers have you tried? Do they all have this issue?

@EmanH
Copy link
Contributor Author

EmanH commented May 9, 2023

Might be onto something with the browser decoding. I was using chrome/edge. Firefox doesn't have the colorspace/range issue, but it shows a significantly reduced quality image for those renders. https://youtu.be/dKOlNEK-cEk

@EmanH
Copy link
Contributor Author

EmanH commented May 9, 2023

Despite setting --quality=100 --encoding=h264, Firefox still shows pixelated clusters when interacting with the app. Do you think this is still a browser decoding issue?

@totaam
Copy link
Collaborator

totaam commented May 9, 2023

Do you think this is still a browser decoding issue?

If it only happens with the html5 client, then yes that's where the problem is.

@EmanH
Copy link
Contributor Author

EmanH commented May 9, 2023

@totaam ok, any tips to debugging further? I'll try playing around with the html5 client source.

@totaam
Copy link
Collaborator

totaam commented May 9, 2023

@EmanH run your server with -d compress and see from the server log which screen updates correspond to the colour issues.

@EmanH
Copy link
Contributor Author

EmanH commented May 22, 2023

@totaam Setting an encoding on the client-side has solved the issue. Previously I was just setting the encoding server-side. h264 and webp are both working well.

@totaam
Copy link
Collaborator

totaam commented May 22, 2023

@EmanH that is very much the wrong thing to do.
But since you didn't figure out which ones cause problems... you will be stuck with a sub-optimal solution.

@EmanH
Copy link
Contributor Author

EmanH commented May 22, 2023

@totaam I wonder why it doesn't have the effect when I set h264 or webp from the server, but it does when setting it in the client?

@EmanH
Copy link
Contributor Author

EmanH commented May 22, 2023

@totaam Setting video encoders explicitly to nvec also fixes the issue. This works:

xpra start --start=bash /app/start.sh --video-encoders=nvenc --bind-tcp=0.0.0.0:14501 --clipboard=yes --clipboard-direction=both --daemon=no --file-transfer=on

@totaam
Copy link
Collaborator

totaam commented May 22, 2023

None of that helps, figuring out which specific encoding(s) display with colorspace issues would.

@EmanH
Copy link
Contributor Author

EmanH commented May 22, 2023

@totaam Yeah fair enough. -d compress or -d encoder doesn't seem to log anything additional for me, idk? But intercepting packets in the html client, I can see the encodings are coming through as a mix of webp, rgb24 and h264. When the color goes off I'm pretty certain it is the h264 packets.

@totaam
Copy link
Collaborator

totaam commented May 22, 2023

-d compress will definitely send a message to the server log for every screen update that is sent.

If it is h264 packets that cause the problems then we need to know if all server encoders are affected (ie: --video-encoders=x264 vs --video-encoders=nvenc - in which case the Python client would also be affected by this bug and the solution would likely be server side) and if the reverse is True with other browsers.

Perhaps we need to give a hint when calling VideoDecoder.configure to enable full-range colorspace.
Either the defaults are different with Firefox, or the offscreen decode worker makes it behave differently.

@EmanH
Copy link
Contributor Author

EmanH commented May 24, 2023

@totaam The issue was only occuring with nvenc x264, and have confirmed that passing in colorSpace: new VideoColorSpace({fullRange: true}) to the videoDecoder.configure() call resolves the issue.
I tested and was able to replicate the issue and resolution on Chrome, Firefox and Edge.

Have opened this PR: Xpra-org/xpra-html5#248

@totaam
Copy link
Collaborator

totaam commented May 24, 2023

Is it the case that different browsers use different defaults or that nvenc uses "full-range" whilst other encoders do not?
If the former then fine, if the latter then we either need to also fix the encoders to use full-range, or pass a flag down to the client so that it knows what range to use when decoding.
(I haven't noticed this with the Python client but perhaps I wasn't careful enough when running the color tests)

@EmanH
Copy link
Contributor Author

EmanH commented May 24, 2023

My bad, I mean x264 was the one causing trouble

@EmanH
Copy link
Contributor Author

EmanH commented May 24, 2023

Firefox was still having an issue, but appears to handle it differently. Yeah, I'd guess x264 uses the full range while nvenc doesn't?

@totaam
Copy link
Collaborator

totaam commented May 25, 2023

It could also be related to the colorspace conversion module used on Debian, which only recently got a libyuv package, so xpra on Ubuntu 20.04 is probably using swscale instead.
Until I know more about exactly where the color range is being misinterpreted, I cannot merge your PR as this could make things worse in terms of fixing this properly.
You can see the video encoding settings used for each window with:

xpra info | grep client.window

(look for csc and encoder)

@totaam totaam changed the title Color depth appears to change frequently Colorspace appears to change frequently Jul 24, 2023
@totaam
Copy link
Collaborator

totaam commented Jan 11, 2024

I've merged the PR, but I am still hoping to enhance the draw packets with better information about colourspace so that the server can specify which type of range to use client-side.

@totaam
Copy link
Collaborator

totaam commented Jan 24, 2024

We still have work to do on colourspaces.
Here's a link to some docs:

@totaam
Copy link
Collaborator

totaam commented May 17, 2024

I know what we're doing wrong, we're not populating "Annex E" data so the decoders are guessing what colorspace is used, some get it wrong.
The xpra client knows what settings are usually used, but this isn't correct either.
We should provide the correct metadata values, both in the stream itself and in the xpra video stream metadata.

@totaam totaam reopened this May 17, 2024
totaam added a commit that referenced this issue May 17, 2024
for backwards compatibility, the client must expose the ranges it supports for each encoding,
if it does not, then we assume the old defaults
@totaam
Copy link
Collaborator

totaam commented May 17, 2024

Much improved by the commit above.

Still TODO:

  • review all the tickets related to colorspace
  • figure out how to set / get the range for openh264 encoder and decoder
  • nvenc, nvjpeg, nvdec
  • test with older versions

totaam added a commit that referenced this issue May 18, 2024
keep it that way for now since I can't find how to get the range information in the decoder API
@totaam
Copy link
Collaborator

totaam commented Jun 1, 2024

Not sure how I missed it before, but with my current test config I can see colourspace issues with webp (ie: running VirtualBox on Fedora 40). Easily reproducible with:

xpra control :6 request-update png all "*"
xpra control :6 request-update webp all "*"

All the other encodings look OK, but webp is washed out. Like it's painting studio range colours without stretching them.

totaam added a commit that referenced this issue Jun 7, 2024
totaam added a commit that referenced this issue Jun 13, 2024
it sems that img.range is not set by the decoder?
totaam added a commit that referenced this issue Jun 14, 2024
and does not care what the client can and cannot handle, just make sure we use the video compression as it is meant to be used and let the client figure it out
totaam added a commit that referenced this issue Jun 14, 2024
so we can just deal with the shader selection, metadata updates, etc - all in one place
totaam added a commit that referenced this issue Jun 19, 2024
somehow the images decoded seem to have 'studio' range
totaam added a commit that referenced this issue Jun 19, 2024
somehow the images decoded seem to have 'studio' range
@totaam
Copy link
Collaborator

totaam commented Jul 24, 2024

Likely fixed in aaabd5b - feel free to re-open if I've missed something.

@totaam totaam closed this as completed Jul 24, 2024
totaam added a commit that referenced this issue Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants