Bug 210101

Summary: [GTK][Stable] When using wayland webkit wants to take over the alsa device
Product: WebKit Reporter: Haelwenn (lanodan) Monnier <contact+bugs.webkit.org>
Component: WebKitGTKAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: bugs-noreply, pnormand
Priority: P2    
Version: WebKit Local Build   
Hardware: Unspecified   
OS: Unspecified   

Description Haelwenn (lanodan) Monnier 2020-04-07 02:23:06 PDT
Setup:
- ALSA (with OSS compatibility) no asound.conf
- Wayland compositor: sway (happens in other wlroots-based ones)

I haven't tested in other setups, the WebKitGTK browser is irrelevant, I also have this issue in MiniBrowser. There is also another issue with graphics but no idea what's wrong in it and could be an Xwayland issue (as it works fine in pure X11).

I get the following behaviour:

## When something is already using the soundcard

$ GST_DEBUG=*:3 badwolf https://hacktivis.me/kopimi/videos/talks%26confs/Internet%20is%20Coming/internet-is-coming-1.mp4
Running Badwolf version: 0.5.1+gf35b0b8
Buildtime WebKit version: 2.28.0
Runtime WebKit version: 2.28.0
webkit-web-extension directory set to: /home/haelwenn/.local/share/badwolf/webkit-web-extension

** (badwolf:10327): WARNING **: 10:59:52.728: GApplication is required for xdg-desktop-portal access in the WebKit sandbox. Actions that require xdg-desktop-portal will be broken.
0:00:00.020510525     2      0x10f40a0 WARN     GST_ELEMENT_FACTORY gstelementfactory.c:462:gst_element_factory_make: no such element factory "fdkaacdec"!
0:00:00.804653237     2 0x7f93340401e0 WARN                    alsa conf.c:4972:parse_args: alsalib error: Unknown parameter AES0
0:00:00.804699143     2 0x7f93340401e0 WARN                    alsa conf.c:5132:snd_config_expand: alsalib error: Parse arguments error: No such file or directory
0:00:00.804714632     2 0x7f93340401e0 WARN                    alsa pcm.c:2642:snd_pcm_open_noupdate: alsalib error: Unknown PCM default:{AES0 0x02 AES1 0x82 AES2 0x00 AES3 0x02}
0:00:00.814366361     2 0x7f93340401e0 WARN                glwindow gstglwindow.c:288:gst_gl_window_new: Could not create window. user specified (null), creating dummy window
0:00:01.566806585     2 0x7f931c133000 WARN                 qtdemux qtdemux.c:3237:qtdemux_parse_trex:<qtdemux0> failed to find fragment defaults for stream 1
0:00:01.568251810     2 0x7f931c133000 WARN                 qtdemux qtdemux.c:3237:qtdemux_parse_trex:<qtdemux0> failed to find fragment defaults for stream 2
0:00:01.821981602     2      0x10f40a0 FIXME                    bin gstbin.c:4349:gst_bin_query: implement duration caching in GstBin again

Result ⇒ no sound

$ GDK_BACKEND=x11 GST_DEBUG=*:3 badwolf https://hacktivis.me/kopimi/videos/talks%26confs/Internet%20is%20Coming/internet-is-coming-1.mp4
Running Badwolf version: 0.5.1+gf35b0b8
Buildtime WebKit version: 2.28.0
Runtime WebKit version: 2.28.0
webkit-web-extension directory set to: /home/haelwenn/.local/share/badwolf/webkit-web-extension

** (badwolf:14125): WARNING **: 11:13:25.293: GApplication is required for xdg-desktop-portal access in the WebKit sandbox. Actions that require xdg-desktop-portal will be broken.
0:00:00.020024943     2      0x1529360 WARN     GST_ELEMENT_FACTORY gstelementfactory.c:462:gst_element_factory_make: no such element factory "fdkaacdec"!
0:00:00.729785910     2 0x7f338403f8a0 WARN                    alsa conf.c:4972:parse_args: alsalib error: Unknown parameter AES0
0:00:00.729817660     2 0x7f338403f8a0 WARN                    alsa conf.c:5132:snd_config_expand: alsalib error: Parse arguments error: No such file or directory
0:00:00.729830604     2 0x7f338403f8a0 WARN                    alsa pcm.c:2642:snd_pcm_open_noupdate: alsalib error: Unknown PCM default:{AES0 0x02 AES1 0x82 AES2 0x00 AES3 0x02}
0:00:01.573696944     2 0x7f3328134280 WARN                 qtdemux qtdemux.c:3237:qtdemux_parse_trex:<qtdemux0> failed to find fragment defaults for stream 1
0:00:01.575109348     2 0x7f3328134280 WARN                 qtdemux qtdemux.c:3237:qtdemux_parse_trex:<qtdemux0> failed to find fragment defaults for stream 2
0:00:01.823436788     2      0x1529360 FIXME                    bin gstbin.c:4349:gst_bin_query: implement duration caching in GstBin again

Result ⇒ sound (but no graphics)


## When nothing is using the sound card

$ GST_DEBUG=*:3 badwolf https://hacktivis.me/kopimi/videos/talks%26confs/Internet%20is%20Coming/internet-is-coming-1.mp4
Running Badwolf version: 0.5.1+gf35b0b8
Buildtime WebKit version: 2.28.0
Runtime WebKit version: 2.28.0
webkit-web-extension directory set to: /home/haelwenn/.local/share/badwolf/webkit-web-extension

** (badwolf:15040): WARNING **: 11:16:45.342: GApplication is required for xdg-desktop-portal access in the WebKit sandbox. Actions that require xdg-desktop-portal will be broken.
0:00:00.017133729     2       0xee6410 WARN     GST_ELEMENT_FACTORY gstelementfactory.c:462:gst_element_factory_make: no such element factory "fdkaacdec"!
0:00:00.563284104     2      0x13b35e0 WARN                    alsa conf.c:4972:parse_args: alsalib error: Unknown parameter AES0
0:00:00.563332165     2      0x13b35e0 WARN                    alsa conf.c:5132:snd_config_expand: alsalib error: Parse arguments error: No such file or directory
0:00:00.563351080     2      0x13b35e0 WARN                    alsa pcm.c:2642:snd_pcm_open_noupdate: alsalib error: Unknown PCM default:{AES0 0x02 AES1 0x82 AES2 0x00 AES3 0x02}
0:00:00.573912688     2      0x13b35e0 WARN                glwindow gstglwindow.c:288:gst_gl_window_new: Could not create window. user specified (null), creating dummy window
0:00:01.300522239     2 0x7f8994138c00 WARN                 qtdemux qtdemux.c:3237:qtdemux_parse_trex:<qtdemux0> failed to find fragment defaults for stream 1
0:00:01.302049328     2 0x7f8994138c00 WARN                 qtdemux qtdemux.c:3237:qtdemux_parse_trex:<qtdemux0> failed to find fragment defaults for stream 2
0:00:01.543702775     2       0xee6410 FIXME                    bin gstbin.c:4349:gst_bin_query: implement duration caching in GstBin again

Result ⇒ sound (and graphics)

$ GDK_BACKEND=x11 GST_DEBUG=*:3 badwolf https://hacktivis.me/kopimi/videos/talks%26confs/Internet%20is%20Coming/internet-is-coming-1.mp4
Running Badwolf version: 0.5.1+gf35b0b8
Buildtime WebKit version: 2.28.0
Runtime WebKit version: 2.28.0
webkit-web-extension directory set to: /home/haelwenn/.local/share/badwolf/webkit-web-extension

** (badwolf:15411): WARNING **: 11:17:33.015: GApplication is required for xdg-desktop-portal access in the WebKit sandbox. Actions that require xdg-desktop-portal will be broken.
0:00:00.021947285     2      0x1aab760 WARN     GST_ELEMENT_FACTORY gstelementfactory.c:462:gst_element_factory_make: no such element factory "fdkaacdec"!
0:00:00.681498803     2 0x7f62b803f4a0 WARN                    alsa conf.c:4972:parse_args: alsalib error: Unknown parameter AES0
0:00:00.681531816     2 0x7f62b803f4a0 WARN                    alsa conf.c:5132:snd_config_expand: alsalib error: Parse arguments error: No such file or directory
0:00:00.681542846     2 0x7f62b803f4a0 WARN                    alsa pcm.c:2642:snd_pcm_open_noupdate: alsalib error: Unknown PCM default:{AES0 0x02 AES1 0x82 AES2 0x00 AES3 0x02}
0:00:01.457733394     2 0x7f6254133680 WARN                 qtdemux qtdemux.c:3237:qtdemux_parse_trex:<qtdemux0> failed to find fragment defaults for stream 1
0:00:01.459187487     2 0x7f6254133680 WARN                 qtdemux qtdemux.c:3237:qtdemux_parse_trex:<qtdemux0> failed to find fragment defaults for stream 2
0:00:01.684510874     2      0x1aab760 FIXME                    bin gstbin.c:4349:gst_bin_query: implement duration caching in GstBin again

Result ⇒ sound (but no graphics)
Comment 1 Philippe Normand 2020-04-07 04:01:02 PDT
These issues don't happen when you use gst-play-1.0 ?
Comment 2 Haelwenn (lanodan) Monnier 2020-04-07 08:08:25 PDT
(In reply to Philippe Normand from comment #1)
> These issues don't happen when you use gst-play-1.0 ?

Yeah, they're specific to webkit as far as I can tell.
Comment 3 Philippe Normand 2020-04-07 09:53:50 PDT
I don't understand... In WebKit we don't have any specific audio sink yet.

Relying directly on ALSA is a bit old-school. Any chance you could switch to... Pulseaudio?
Comment 4 Haelwenn (lanodan) Monnier 2020-04-07 10:58:03 PDT
(In reply to Philippe Normand from comment #3)
> I don't understand... In WebKit we don't have any specific audio sink yet.
> 
> Relying directly on ALSA is a bit old-school. Any chance you could switch
> to... Pulseaudio?

Nah, in my experiences pulseaudio has been a major pain in the last ten years, from general stability issues to a configuration so large you can end up without sound for a number of reasons that only seems to grow over the years.
ALSA has occasional issues like this one but they can be (hot)fixed quite quickly.
Comment 5 Philippe Normand 2020-04-08 05:15:26 PDT
Cool. If you want to debug this, you're welcome to.
Comment 6 Haelwenn (lanodan) Monnier 2020-07-05 22:42:37 PDT
I found a fix to make it work.

The reason is from the usage of `--unshare-ipc` in the bubblewrap sandbox when wayland is used which I tried at first with these two commands:

$ bwrap  --proc /proc --dev /dev --ro-bind $PWD/theday.wav{,} --ro-bind /lib64{,} --ro-bind /bin{,} --ro-bind /usr{,} --ro-bind /etc/asound.conf{,} --dev-bind /dev/dsp{,} --dev-bind-try /dev/snd/{,} --ro-bind /etc{,} --unshare-ipc aplay theday.wav
ALSA lib /var/tmp/portage/media-libs/alsa-lib-1.2.2-r1/work/alsa-lib-1.2.2/src/pcm/pcm_dmix.c:1089:(snd_pcm_dmix_open) unable to open slave
aplay: main:830: audio open error: Device or resource busy
$ bwrap  --proc /proc --dev /dev --ro-bind $PWD/theday.wav{,} --ro-bind /lib64{,} --ro-bind /bin{,} --ro-bind /usr{,} --ro-bind /etc/asound.conf{,} --dev-bind /dev/dsp{,} --dev-bind-try /dev/snd/{,} --ro-bind /etc{,} aplay theday.wav
Playing WAVE 'theday.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo



And I tested it against WebKitGTK with applying the following patch:

diff --git a/Source/WebKit/UIProcess/Launcher/glib/BubblewrapLauncher.cpp b/Source/WebKit/UIProcess/Launcher/glib/BubblewrapLauncher.cpp
--- a/Source/WebKit/UIProcess/Launcher/glib/BubblewrapLauncher.cpp
+++ b/Source/WebKit/UIProcess/Launcher/glib/BubblewrapLauncher.cpp
@@ -797,7 +797,7 @@ GRefPtr<GSubprocess> bubblewrapSpawn(GSubprocessLauncher* launcher, const Proces
 #if PLATFORM(WAYLAND) && USE(EGL)
         if (PlatformDisplay::sharedDisplay().type() == PlatformDisplay::Type::Wayland) {
             bindWayland(sandboxArgs);
-            sandboxArgs.append("--unshare-ipc");
+            //sandboxArgs.append("--unshare-ipc");
         } else
 #endif
             bindX11(sandboxArgs);