Bug 260654

Summary: [Nvidia][GStreamer][GTK] Unable to play any video whatsoever
Product: WebKit Reporter: Kdwk <kdwkleung>
Component: WebKitGTKAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: bugs-noreply, cgarcia, ekurzinger, philn
Priority: P2    
Version: WebKit Nightly Build   
Hardware: PC   
OS: Linux   
Attachments:
Description Flags
Videos are now green
none
Compressed dots folder
none
Compressed dots folder (DMABuf renderer)
none
gst-inspect-1.0 nvvp9dec.txt none

Description Kdwk 2023-08-24 05:28:10 PDT
Supersedes https://bugs.webkit.org/show_bug.cgi?id=260456

With Epiphany 45.beta-40-g17c238bbb+/ WebKitGTK 2.41.91, no matter what environment variable set, no video can be played (without crashing).

With no environment variable set, the web view cannot be shown.

With WEBKIT_DISABLE_DMABUF_RENDERER=1, sites with video crash.

With WEBKIT_GST_DMABUF_SINK_DISABLED=1, sites don't crash but videos are black or refuse to be played.

Disabling the GL sink (forgot the environment variable), the video plays for a few seconds then Epiphany receives SIGSEGV, with backtrace that looks like "??()".

GST_PLUGIN_FEATURE_RANK=nvav1dec:MAX,nvh264dec:MAX,nvh265dec:MAX,nvjpegdec:MAX,nvmpeg2videodec:MAX,nvmpeg4videodec:MAX,nvmpegvideodec:MAX,nvvp8dec:MAX,nvvp9dec:MAX does not appear to make any difference.

This only happens in Epiphany Technology Preview/ WebKitGTK 2.41.x, but not in Gnome Web/ WebKitGTK 2.40.x, where video playback works and hardware-accelerated decode works as well.
Comment 1 Kdwk 2023-08-24 05:28:51 PDT
*** Bug 260456 has been marked as a duplicate of this bug. ***
Comment 2 Erik Kurzinger 2023-11-08 12:21:46 PST
Based on the discussion from https://bugs.webkit.org/show_bug.cgi?id=261874 at least part of the problem is that current versions of the NVIDIA driver do not support allocating GBM buffers with the R8 format. However, the next release (550) will support this. So it may be worth re-testing when that goes public later this year.
Comment 3 Kdwk 2024-03-03 18:45:58 PST
Created attachment 470157 [details]
Videos are now green

Erik, I have retested this with the 550.54.14 driver and videos became green instead
Comment 4 Philippe Normand 2024-03-04 13:14:14 PST
It would be interesting to know which format the video decoder outputs and which format the video sink negotiates... Can you share pipeline dumps?
Comment 5 Kdwk 2024-03-05 01:47:59 PST
How can I get that information?
Comment 7 Kdwk 2024-03-05 02:13:01 PST
Created attachment 470179 [details]
Compressed dots folder

Thanks. Here's the compressed dot directory after running the command with youtube.com and playing a few videos there.
Comment 8 Philippe Normand 2024-03-05 02:36:17 PST
So the decoder outputs raw NV12 and for rendering we convert that to DMABufs within WebKit. That might be where the problem is.
Comment 9 Philippe Normand 2024-03-06 12:38:27 PST
> With WEBKIT_GST_DMABUF_SINK_DISABLED=1, sites don't crash but videos are black or refuse to be played.

Is this still happening?
Comment 10 Kdwk 2024-03-07 04:35:03 PST
Currently, with WEBKIT_GST_DMABUF_SINK_DISABLED=1 videos aren't black but simply don't play. Without this environment variable, videos seemingly can play, but they are green.
Comment 11 Kdwk 2024-04-01 21:18:02 PDT
Erik, this issue still persists with Nvidia driver 550. Though GBM buffers with R8 formats are now supported, there remains a problem with converting raw NV12 to DMABufs. Nvidia users cannot view any video in WebKitGTK apps until this is resolved.
Comment 12 Erik Kurzinger 2024-04-04 16:39:50 PDT
> there remains a problem with converting raw NV12 to DMABufs

Could you clarify what you mean by this? With the 550 driver it should be possible to allocate an NV12 GBM buffer and export it as a pair of DMA-BUFs. Note, though, that support for this format in our EGL driver is "external only". So if an NV12 buffer is imported as an EGLImage, that image can only be bound to GL_TEXTURE_EXTERNAL_OES (not, for example, GL_TEXTURE_2D). Could that maybe be the problem?
Comment 13 Kdwk 2024-07-02 07:23:14 PDT
I used flatpak run --command=/bin/bash com.github.kdwk.Spidey to enter the Flatpak runtime then gst-play-1.0 to play local video files. This works fine. 

WebKitGTK 2.45.4/ GStreamer 1.24/
Comment 14 Philippe Normand 2024-07-02 08:31:59 PDT
(In reply to Kdwk from comment #10)
> Currently, with WEBKIT_GST_DMABUF_SINK_DISABLED=1 videos aren't black but
> simply don't play. Without this environment variable, videos seemingly can
> play, but they are green.

If that still happens we'd need gst logs.
Comment 15 Kdwk 2024-07-03 05:48:24 PDT
Created attachment 471804 [details]
Compressed dots folder (DMABuf renderer)

I have the new dots folder when playing videos with the DMABuf renderer. It now shows a black screen instead of green after the update of Nvidia drivers from 550 to 555. Sound works as usual (playback works except video).
Comment 16 Philippe Normand 2024-07-03 06:42:33 PDT
That's not with nvidia decoder, but openh264... try with GST_PLUGIN_FEATURE_RANK=openh264dec:0 ?
Comment 17 Philippe Normand 2024-07-03 06:45:17 PDT
Sorry i was looking at the wrong pipeline :)
What's the output of gst-inspect-1.0 nvvp9dec ?

Having pipeline dump for gst-play would be nice too.
Comment 18 Kdwk 2024-07-03 06:48:25 PDT
Created attachment 471805 [details]
gst-inspect-1.0 nvvp9dec.txt

Here's the output of gst-inspect-1.0 nvvp9dec
Comment 19 Philippe Normand 2024-07-03 07:07:16 PDT
GST_DEBUG="nv*:6,videodec*:6" logs too please
Comment 20 Philippe Normand 2024-07-03 07:08:41 PDT
(In reply to Philippe Normand from comment #8)
> So the decoder outputs raw NV12 and for rendering we convert that to DMABufs
> within WebKit. That might be where the problem is.

Still same issue. Once we understand why the decoder negotiates raw NV12 instead of GLMemories with the sink, the issue will be closer to resolution.
Comment 21 Kdwk 2024-07-03 07:20:30 PDT
(In reply to Philippe Normand from comment #17)

> Having pipeline dump for gst-play would be nice too.

I am unable to get this dump because it keeps insisting the files and directories don't exist.
Comment 22 Kdwk 2024-07-03 07:21:43 PDT
However, gst-play-1.0 keep complaining about 

WARNING A lot of buffers are being dropped.
WARNING debug information: ../libs/gst/base/gstbasesink.c(3147): gst_base_sink_is_too_late (): /GstPlayBin3:playbin/GstPlaySink:playsink/GstBin:vbin/GstAutoVideoSink:videosink/GstGLImageSinkBin:videosink-actual-sink-glimage/GstGLImageSink:sink:
There may be a timestamping problem, or this computer is too slow.
Comment 23 Philippe Normand 2024-07-03 08:10:57 PDT
(In reply to Kdwk from comment #21)
> (In reply to Philippe Normand from comment #17)
> 
> > Having pipeline dump for gst-play would be nice too.
> 
> I am unable to get this dump because it keeps insisting the files and
> directories don't exist.

Are you setting the dangerous env var? See https://docs.webkit.org/Ports/WebKitGTK%20and%20WPE%20WebKit/Multimedia.html#flatpak-apps
Comment 24 Carlos Garcia Campos 2024-07-09 03:20:46 PDT
(In reply to Philippe Normand from comment #20)
> (In reply to Philippe Normand from comment #8)
> > So the decoder outputs raw NV12 and for rendering we convert that to DMABufs
> > within WebKit. That might be where the problem is.
> 
> Still same issue. Once we understand why the decoder negotiates raw NV12
> instead of GLMemories with the sink, the issue will be closer to resolution.

Because we always claim to support NV12?
Comment 25 Philippe Normand 2024-07-09 04:26:05 PDT
Yes...

There's two different issues I think.

- with our GL sink we should ideally behave almost the same as gst-play (with glimagesink) and negotiate GLMemories all the way from decoder to sink.

- with our DMABuf sink I'm not sure how to proceed, but video/x-raw negotiation should be avoided... we'd need a dmabufupload (or maybe glupload can handle GLMemory conversion to DMABuf now) that would convert CUDA or GLMemories from the decoder to DMABufs.
Comment 26 Carlos Garcia Campos 2024-07-09 06:16:40 PDT
(In reply to Philippe Normand from comment #25)
> Yes...
> 
> There's two different issues I think.
> 
> - with our GL sink we should ideally behave almost the same as gst-play
> (with glimagesink) and negotiate GLMemories all the way from decoder to sink.

If you know how to do that...

> - with our DMABuf sink I'm not sure how to proceed, but video/x-raw
> negotiation should be avoided... we'd need a dmabufupload (or maybe glupload
> can handle GLMemory conversion to DMABuf now) that would convert CUDA or
> GLMemories from the decoder to DMABufs.

This is how I think the DMABuf sink works:

We claim to support a fixed list of formats, which are the ones that can be handled by the texture mapper. Then two things can happen:

 1) gst can provide one of the formats as DMABuf: In this case we just import the DMABUf as textures and render them into the texture mapper.

 2) gst can't provide the formats as DMABuf: in this case we receive a raw video frame in one the formats we claimed in caps. We allocate a GBM buffer and upload the video frame there, then we do as if the DMABuf was provided by gst and import it as textures to render them into the texture mapper.

So, in both cases, I wonder what happens if the buffer format (and modifiers) is not supported by the driver. I guess in the first case we will fail to import the DMABuf and in the second case we will fail to allocate the buffer. I guess we should claim to support only the formats supported by the driver, the same way we do in the renderer. Do we know where exactly is failing?

And in case of not getting a DMABuf from gst, is it really more efficient to allocate, upload and then import the DMABuf? Can't we just fallback to GL or non-accelerated video?
Comment 27 Philippe Normand 2024-07-10 01:55:19 PDT
Having the decoder output raw video (in main memory, not GPU) should be avoided, otherwise CPU usage might increase significantly...

Our hand-rolled GBM to DMABuf upload in the player is meant for software decoders...

@Kdwk: Can you get gst logs please? `GST_DEBUG="3,nv*:6`
Comment 28 Philippe Normand 2024-07-10 04:05:01 PDT
Also for testing purpose can you disable the WebProcess sandbox? I suspect it might block access from the nv decoder to the cuda device...