Advertisement
71GA

Untitled

Dec 15th, 2021
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.02 KB | None | 0 0
  1. PIPEWIRE -- audio
  2.  
  3. > **Source:** https://wiki.debian.org/PipeWire
  4.  
  5. Package `pipewire` can be used to replace `pulseaudio`.
  6.  
  7. Additionally, package `pipewire-audio-client-libraries` allow applications that access `jack` or `alsa` directly to output via the `pipewire` server!
  8.  
  9. This allows harmonious interoperability between different sound servers.
  10.  
  11. > **Attention:**
  12. > `pipewire` on Debian 11 is not yet ready (I tested it), so we should avoid it if possible. Therefore we will only install it so that we can use web screen sharing and that is it! At this point we should not yet use it as a replacement for `pulseaudio`, `alsa`, `jack` and `bluez`.
  13.  
  14. ## Installation
  15.  
  16. Install the main `pipewire` package:
  17.  
  18. ```
  19. sudo apt install pipewire libpipewire-0.3-0
  20. ```
  21.  
  22. Install the packages needed on `sway` *(`sway` is built on top of `wlroot`)*:
  23.  
  24. ```
  25. sudo apt install xdg-desktop-portal-wlr xdg-desktop-portal
  26. ```
  27.  
  28. > **Note:**
  29. > This is considered experimental for Debian 11. It may break certain applications, lack certain functionality, or not work at all. But it needs to be done, because `pipewire` is the only way to use full screen sharing on `wayland`.
  30.  
  31. > **Note:**
  32. > Transition to `pipewire` brings potential benefits like lower CPU usage, better support for bluetooth devices, and better integration between applications using `jack` and `pulseaudio`.
  33.  
  34. The three sub sections below are independent of each other, but you are still highly recommended to use `pipewire` to replace all of them if you intend to replace any of it, for the best integration between different applications.
  35.  
  36. ### REPLACE `pulseaudio`
  37.  
  38. After this section is completed `pipewire` will run as audio service and replaces `pulseaudio` completely.
  39.  
  40. Create this empty file:
  41.  
  42. ```
  43. sudo touch /etc/pipewire/media-session.d/with-pulseaudio
  44. ```
  45.  
  46. Create the `pipewire-pulse` service by copying example files:
  47.  
  48. ```
  49. sudo cp /usr/share/doc/pipewire/examples/systemd/user/pipewire-pulse.* /etc/systemd/user/
  50. ```
  51.  
  52. Run these three commands as a regular user *(not as `root`)*:
  53.  
  54. ```
  55. systemctl --user daemon-reload
  56. systemctl --user --now disable pulseaudio.service pulseaudio.socket
  57. systemctl --user --now enable pipewire pipewire-pulse
  58. ```
  59.  
  60. Check which server is in use:
  61.  
  62. ```
  63. pactl info | grep '^Server Name'
  64. ```
  65.  
  66. If it's using `pipewire` the response will be:
  67.  
  68. ```
  69. "PulseAudio (On PipeWire 0.3.19)"
  70. ```
  71.  
  72. Mask the `pulsaudio` service so that it will not start itself again after reboot:
  73.  
  74. ```
  75. systemctl --user mask pulseaudio
  76. ```
  77.  
  78. > **Note:**
  79. > Here we don't use `sudo`.
  80.  
  81. Now reboot:
  82.  
  83. ```
  84. sudo systemctl reboot
  85. ```
  86.  
  87. > **Note:**
  88. > If we want to restore previous functionality i.e. enable `pulseaudio` instead of `pipewire`:
  89. >
  90. > ```
  91. > systemctl --user unmask pulseaudio
  92. > ```
  93.  
  94. > **Attention**:
  95. > I am afraid that `pipewire` must run in order for screen sharing to work, but I am not 100$ sure on this one!
  96.  
  97. ### REROUTE OUTPUTS FROM `alsa` CLIENTS
  98.  
  99. Programs that talk directly with `alsa` i.e. *"`alsa` clients"* can be configured to output via `pipewire`. Install the `pipewire-audio-client-libraries`:
  100.  
  101. ```
  102. sudo apt install pipewire-audio-client-libraries
  103. ```
  104.  
  105. Create an empty file:
  106.  
  107. ```
  108. sudo touch /etc/pipewire/media-session.d/with-alsa
  109. ```
  110.  
  111. Copy configuration file from `pipewire` examples into the `alsa` configuration directory:
  112.  
  113. ```
  114. # cp /usr/share/doc/pipewire/examples/alsa.conf.d/99-pipewire-default.conf /etc/alsa/conf.d/
  115. ```
  116.  
  117. ### REROUTE OUTPUTS FROM `jack` CLIENTS
  118.  
  119. Programs that talk directly with `jack` i.e. *"`jack` clients"* can be configured to output via `pipewire`. Install the `pipewire-audio-client-libraries` and `libspa-0.2-jack`:
  120.  
  121. ```
  122. sudo apt install pipewire-audio-client-libraries libspa-0.2-jack
  123. ```
  124.  
  125. Create an empty file:
  126.  
  127. ```
  128. sudo touch /etc/pipewire/media-session.d/with-jack
  129. ```
  130.  
  131. Copy the configuration files:
  132.  
  133. ```
  134. sudo cp /usr/share/doc/pipewire/examples/ld.so.conf.d/pipewire-jack-*.conf /etc/ld.so.conf.d/
  135. ```
  136.  
  137. Run:
  138.  
  139. ```
  140. sudo ldconfig
  141. ```
  142.  
  143. This will replace `jack` server libraries with `pipewire` replacement libraries at application runtime, by pointing the dynamic linker at the `/usr/lib/x86_64-linux-gnu/pipewire-0.3/jack/` folder.
  144.  
  145. ### USE FOR `bluez` AUDIO DEVICES
  146.  
  147. `pipewire` will generally work fine in conjunction with `bluez` to supply high-quality audio to bluetooth-enabled audio devices when used as a replacement for `pulseaudio` with some caveats.
  148.  
  149. Install one package:
  150.  
  151. ```
  152. sudo apt install libspa-0.2-bluetooth
  153. ```
  154.  
  155. Remove one package:
  156.  
  157. ```
  158. pulseaudio-module-bluetooth
  159. ```
  160.  
  161. Then either reboot your computer or restart the `pipewire` services, otherwise device connections will fail with:
  162.  
  163. > "Protocol not available"
  164.  
  165. `pipewire` will attempt to choose the best possible codecs by default. It is possible to override this and many other related settings globally here:
  166.  
  167. ```
  168. /etc/pipewire/media-session.d/bluez-monitor.conf
  169. ```
  170.  
  171. We can also store per-user configurations by copying the above file to:
  172.  
  173. ```
  174. ~/.config/pipewire/media-session.d/bluez-monitor.conf
  175. ```
  176.  
  177. > **Note:**
  178. > Since release of `pipewire` 0.3.19, there have been numerous bluetooth-related feature additions and bug fixes. The version in Debian 11 is not representative of the current state of `pipewire`.
  179.  
  180. # PIPEWIRE -- screen sharing on browsers using WebRTC
  181.  
  182. ## Browsers
  183.  
  184. Pipewire includes WebRTC protocol which can be used for **comunication between** (!) software that also supports it. One of such software are `firefox`, `chromium`, `skype`.
  185.  
  186. WebRTC is supported on official packages for `firefox` and `chromium` on Debian 11 ([source](https://github.com/emersion/xdg-desktop-portal-wlr/wiki/Screencast-Compatibility#webrtc-aka-firefoxchromium)). But it is much better to upgrade to the newest versions of both browsers which can be installed.
  187.  
  188. WebRTC is enabled by default in the newest `firefox` so we don't have to do anything else except install it.
  189.  
  190. WebRTC is however not enabled by default in the newest `chromium`, but we can easily enable it. What we need to do is just to open the `chromium` browser and insert `chrome://flags/` in the search bar. Then we search for string `WebRTC` and make sure to enable the feature `WebRTC PipeWire support`. Then `chromium` will be restart and everything will also work!Note that this setting is not available on old versions.
  191.  
  192. ## Sway
  193.  
  194. Sway by itself does not integrate WebRTC protocol. It needs `xdg-desktop-portal` and because it is *"Wlroort"* based application it also needs `xdg-desktop-portal-wlr` . After these packages are installed we can reboot the system and we will see that they run as `systemd` *"user"*. If they do not, we can enable and start them like any other `systemd` *"unit"*.
  195.  
  196. ```
  197. ┌───┐
  198. │ $ │ ziga > ziga--workstation > ~
  199. └─┬─┘ /dev/pts/1
  200. └─> systemctl --user status xdg-desktop-portal-wlr.service
  201. ● xdg-desktop-portal-wlr.service - Portal service (wlroots implementation)
  202. Loaded: loaded (/usr/lib/systemd/user/xdg-desktop-portal-wlr.service; static)
  203. Active: active (running) since Wed 2021-12-15 15:17:31 CET; 4min 24s ago
  204. Main PID: 997 (xdg-desktop-por)
  205. Tasks: 2 (limit: 11237)
  206. Memory: 1.0M
  207. CPU: 6ms
  208. CGroup: /user.slice/user-1000.slice/[email protected]/app.slice/xdg-desktop-portal-wlr.service
  209. └─997 /usr/libexec/xdg-desktop-portal-wlr
  210.  
  211. Dec 15 15:17:31 ziga--workstation systemd[840]: Starting Portal service (wlroots implementation)...
  212. Dec 15 15:17:31 ziga--workstation systemd[840]: Started Portal service (wlroots implementation).
  213.  
  214. ┌───┐
  215. │ $ │ ziga > ziga--workstation > ~
  216. └─┬─┘ /dev/pts/1
  217. └─> systemctl --user status xdg-desktop-portal.service
  218. ● xdg-desktop-portal.service - Portal service
  219. Loaded: loaded (/usr/lib/systemd/user/xdg-desktop-portal.service; static)
  220. Active: active (running) since Wed 2021-12-15 15:17:31 CET; 1h 37min ago
  221. Main PID: 972 (xdg-desktop-por)
  222. Tasks: 4 (limit: 11237)
  223. Memory: 4.7M
  224. CPU: 54ms
  225. CGroup: /user.slice/user-1000.slice/[email protected]/app.slice/xdg-desktop-portal.service
  226. └─972 /usr/libexec/xdg-desktop-portal
  227.  
  228. Dec 15 15:17:31 ziga--workstation systemd[840]: Starting Portal service...
  229. Dec 15 15:17:31 ziga--workstation systemd[840]: Started Portal service.
  230. ```
  231.  
  232. Note that these *"units"* are only started for the user and can't be found in the system wide *"units"*:
  233.  
  234. ```
  235. ┌───┐
  236. │ $ │ ziga > ziga--workstation > ~
  237. └─┬─┘ /dev/pts/1
  238. └─> systemctl status xdg-desktop-portal-wlr.service
  239. Unit xdg-desktop-portal-wlr.service could not be found.
  240.  
  241.  
  242. ┌───┐
  243. │ $ │ ziga > ziga--workstation > ~
  244. └─┬─┘ /dev/pts/1
  245. └─> systemctl status xdg-desktop-portal.service
  246. Unit xdg-desktop-portal.service could not be found.
  247. ```
  248.  
  249. ## Sway ⟷ Firefox
  250.  
  251. If we want to use WebRTC between `sway` window manager and `firefox` we have to first make sure that `firefox` uses `sway` and not `xorg`. We can do this by exporting an environmental variable `MOZ_ENABLE_WAYLAND=1` but here is the catch. We must not do this in `/etc/environment`! We will actually leave `/etc/environment` empty!
  252.  
  253. Instead we create file `~/.config/environment.d/10-environental_variables.conf` and define environmental variables inside! Along side mentioned variable we also have to define others that (a) enable styling of `sway` widgets with `qt5ct` & `lxappearance` and (b) define default display server as `wayland`for all applications. In the end this file looks like this:
  254.  
  255. ```
  256. ####################################################################################################
  257. # Force Firefox to use "wayland" graphical server.
  258. ####################################################################################################
  259. MOZ_ENABLE_WAYLAND=1
  260.  
  261.  
  262. ####################################################################################################
  263. # LINK: # https://wiki.archlinux.org/title/PipeWire#WebRTC_screen_sharing
  264. ####################################################################################################
  265. XDG_CURRENT_DESKTOP=sway
  266.  
  267.  
  268. ####################################################################################################
  269. # NOTE: https://github.com/emersion/xdg-desktop-portal-wlr/wiki/Screencast-Compatibility#webrtc-aka-firefoxchromium
  270. ####################################################################################################
  271. XDG_SESSION_TYPE=wayland
  272.  
  273.  
  274. ####################################################################################################
  275. # LINK: https://bbs.archlinux.org/viewtopic.php?id=259721
  276. # LINK: https://github.com/FedoraQt/QGnomePlatform
  277. ####################################################################################################
  278. QT_QPA_PLATFORMTHEME=qt5ct
  279. # QT_QPA_PLATFORMTHEME=gnome
  280.  
  281.  
  282. ####################################################################################################
  283. # NOTE: "xcb" sets "X" graphical server and "wayland" sets "Wayland" graphical server to be used by
  284. # all applications. When there are two options i.e. "xcb;wayland", first one is prefered over
  285. # the second. The last option makes sure that even "X" based native Debain packages run
  286. # smoothly, but it does not work for some flatpaks that come packaged and perfer to use their
  287. # own QT that doesn't yet supporrt Wayland QPA platform plugin.
  288. # LINK: https://stackoverflow.com/questions/49583671/pyqt5-unable-to-find-wayland-plugin
  289. # LINK: https://doc.qt.io/qt-5/qguiapplication.html#platformName-prop
  290. # LINK: https://blog.martin-graesslin.com/blog/2018/03/unsetting-qt_qpa_platform-environment-variable-by-default/
  291. ####################################################################################################
  292. QT_QPA_PLATFORM=wayland
  293. # QT_QPA_PLATFORM=wayland
  294. # QT_QPA_PLATFORM=xcb
  295. # QT_QPA_PLATFORM=wayland;xcb
  296. # QT_QPA_PLATFORM=xcb;wayland
  297.  
  298.  
  299. ####################################################################################################
  300. # LINK: https://github.com/swaywm/sway/wiki#my-favorite-application-isnt-displayed-right-how-can-i-fix-this
  301. ####################################################################################################
  302. # QT_WAYLAND_DISABLE_WINDOWDECORATION=1
  303.  
  304.  
  305. ####################################################################################################
  306. # NOTE: Forcing DPI is not needed as it is set in the sway configuration file.
  307. ####################################################################################################
  308. # QT_WAYLAND_FORCE_DPI=physical
  309.  
  310.  
  311. ####################################################################################################
  312. # NOTE: If I set "QT_QPA_PLATFORM=wayland it will automatically export "WAYLAND_DISPLAY=wayland-0".
  313. # If I set "QT_QPA_PLATFORM=xcb;wayland it will export "WAYLAND_DISPLAY=wayland-0" and
  314. # "DISPLAY=:0".
  315. # LINK: https://wiki.archlinux.org/title/PipeWire#WebRTC_screen_sharing
  316. ####################################################################################################
  317. # DISPLAY=:0
  318. # WAYLAND_DISPLAY=wayland-0
  319.  
  320.  
  321. ####################################################################################################
  322. # LINK: https://github.com/swaywm/wlroots/blob/master/docs/env_vars.md
  323. # LINK: https://github.com/swaywm/sway/issues/6167
  324. ####################################################################################################
  325. # WLR_DRM_NO_MODIFIERS=1
  326. ```
  327.  
  328. > **Note**:
  329. > There is no `export` in front of environmental variables.
  330.  
  331. After this is done we reboot and check that these environmental variables are exported in the `systemd` user session:
  332.  
  333. ```
  334. ┌───┐
  335. │ $ │ ziga > ziga--workstation > ~
  336. └─┬─┘ /dev/pts/1
  337. └─> systemctl --user show-environment
  338. HOME=/home/ziga
  339. LANG=en_US.UTF-8
  340. LANGUAGE=en_US:en
  341. LOGNAME=ziga
  342. PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  343. SHELL=/bin/bash
  344. USER=ziga
  345. XDG_DATA_DIRS=/home/ziga/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share/:/u>
  346. XDG_RUNTIME_DIR=/run/user/1000
  347. MOZ_ENABLE_WAYLAND=1
  348. XDG_CURRENT_DESKTOP=sway
  349. XDG_SESSION_TYPE=wayland
  350. QT_QPA_PLATFORMTHEME=qt5ct
  351. QT_QPA_PLATFORM=wayland
  352. QT_ACCESSIBILITY=1
  353. DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
  354. DISPLAY=:0
  355. SWAYSOCK=/run/user/1000/sway-ipc.1000.901.sock
  356. WAYLAND_DISPLAY=wayland-0
  357. ```
  358.  
  359. These environmental variables are not exported as a standard environmental variables are:
  360.  
  361. ```
  362. ┌───┐
  363. │ $ │ ziga > ziga--workstation > ~
  364. └─┬─┘ /dev/pts/1
  365. └─> printenv
  366. SHELL=/bin/bash
  367. COLORTERM=truecolor
  368. LANGUAGE=en_US:en
  369. I3SOCK=/run/user/1000/sway-ipc.1000.901.sock
  370. XCURSOR_SIZE=24
  371. XDG_SEAT=seat0
  372. PWD=/home/ziga
  373. LOGNAME=ziga
  374. XDG_SESSION_TYPE=tty
  375. MOTD_SHOWN=pam
  376. HOME=/home/ziga
  377. LANG=en_US.UTF-8
  378. SWAYSOCK=/run/user/1000/sway-ipc.1000.901.sock
  379. WAYLAND_DISPLAY=wayland-0
  380. INVOCATION_ID=a9a5056db67b4f53860bebc10877b185
  381. XDG_SESSION_CLASS=user
  382. TERM=foot
  383. USER=ziga
  384. DISPLAY=:0
  385. SHLVL=1
  386. XDG_VTNR=1
  387. XDG_SESSION_ID=1
  388. XDG_RUNTIME_DIR=/run/user/1000
  389. PS1=\n┌───┐\n│ \[\033[1;32m\]$\[\033[0m\] │ \[\033[1;32m\]\u\[\033[0m\] > \033[1m\]\h\033[0m\] > \033[1m\]\W\033[0m\]\n└─┬─┘ \033[37m\]/dev/pts/1\033[0m\]\n └─>
  390. JOURNAL_STREAM=8:18757
  391. XDG_DATA_DIRS=/home/ziga/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share/:/usr/share/
  392. HUSHLOGIN=FALSE
  393. PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
  394. DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
  395. MAIL=/var/mail/ziga
  396. _=/usr/bin/printenv
  397. ```
  398.  
  399. But `xdg-desktop-portal.service` and `xdg-desktop-portal.service-wlr` run in `systemd` user session and they are the ones that need these variables in order to work. Like this, now they can see them!
  400.  
  401. We can now open `firefox` and navigate to it's official website where we can test screen sharing ([source](https://mozilla.github.io/webrtc-landing/gum_test.html)).
  402.  
  403. For some reason this test page will find our *"entire screen"* that it can broadcast but when we press <kbd>Start</kbd> display will be black and mouse cursor will be moving.
  404.  
  405. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement